Happy Life with Intuitive API in Smart Controls

Filed Under (Development) by Emad Alashi on 15-06-2010

Tagged Under : , , ,

In this post I will show you an example of how smartly built controls and API’s can make the developers programming life extremely enjoyable, hopefully this example will urge you in giving such a smart effort when you build your own control or API.

Lately I have been playing around with a very nice tree control based on jQuery called jsTree. One of the nice features is that it allows populating the tree through asynchronous calls with JSON data representation. In order to achieve that, you needed to provide the data by JSON special format suitable to the tree. This format, regrettably, is open to the JSON vulnerability Phil Haack talked about in his two posts here and here.
So to avoid this vulnerability I had to change this default data format of the tree, at least until the very end of the data flow just before the tree populates the data, only then I can change it back to the default format, like the following:

The format I need to send from server to avoid the vulnerability, but the tree wouldn’t understand:

 { "d" : [ { attributes : { id : "2", balance : "0.00000" },  data : "Child",  state : "closed" }  , { attributes : { id : "3", balance : "0.00000" },  data : "AnotherChild",  state : "closed" }  ] }

The format the tree accepts, to which I should change back before populating:

[ { attributes : { id : "2", balance : "0.00000" },  data : "Child",  state : "closed" }  , { attributes : { id : "3", balance : "0.00000" },  data : "AnotherChild",  state : "closed" }  ]

That would not have been possible if the tree control wasn’t smart enough to provide the developer with the “ondata” event (line 45) that happens exactly before the binding to the tree, in which you can manipulate the data; in my case I am eliciting the data out by returning the “content” of the wrapper object “d” rather than the whole thing.

   31 <script type="text/javascript">

   32     var initialData = <%= ViewData["InitialList"].ToString() %>

   33 $(function () {

   34     $("#MyTree").tree({

   35         data : {

   36             type : "json",

   37             async : true,

   38             opts : {

   39                 async : true,

   40                 method : "GET",

   41                 url : "GetNodesOfParent"

   42 

   43                 }

   44             },

   45           ondata: function (data, tree_obj) {

   51                     return data.d;

   52                 },…..

Such flexibility and clean structure in controls and API’s is one of the very important aspects a control-developer should keep in mind.

Stressful Situations Make You Stupid

Filed Under (Development, software management) by Emad Alashi on 12-05-2010

Tagged Under : , , ,

Today we came across an interesting issue at work: we have two teams A and B who interchange API calls. Team A needed an API from team B to process a business that is owned by team B of course. The signature was like the following:

public OutputEntity MyMethod(List listOfIds);

It appeared afterward that this method was very slow, and the client was already very upset about the low performance, which consequently caused big pressure on the teams by the superiors to enhance the performance.
After investigating the issue, it appeared that the list of ID’s sent as input consists of some ID’s that do not need to be processed, this criteria of “not need to be processed” is a business owned by team B, done by using properties of the entities these ID’s represent. So the  solution to this issue was one of the following:

  1. Moving the business out of the API to the client application to do the filtering, since the calling method already has the entities themselves (not so good to move business out of scope!)
  2. Let the API do the filtering, but this will worsen the performance because the API will have to retrieve these entities from the database in order to use its’ properties!

So is that a dead end? actually that was stupid! the situation was stressful enough and pressured by our superiors to enhance the performance that we missed a very simple fact: pass the list of entities themselves!

Stressful situations make us stupid, so make as less stress as possible on your team, help them to be smarter.

Exposing DotNetArabi for OData

Filed Under (Development, DotNetArabi) by Emad Alashi on 10-04-2010

Tagged Under : , ,

www.DotNetArabi.com www.odata.org

Lately OData (Open Data protocol) is gaining a great momentum, everybody is talking about, and in fact it deserves all this fuss. OData is a protocol through which you can share data provided as ATOM or JSON formats by exposing URI’s to be invoked via HTTP, check the FAQ for fast information.

One of the interesting things is that the protocol provides various options through the URI to query all sort data; conditions, ordering, filtering, smart selection, …etc, in addition to very smart linking between exposed entities.

So hereby I provide the data of DotNetArabi through OData on the link http://odata.dotnetarabi.com/odata.svc for the sake of fun and for anyone who might find it useful. I used the Entity Framework for this purpose since it was the easiest, you can find a very helpful information here.

To start playing around check:

http://odata.dotnetarabi.com/odata.svc/Guests
http://odata.dotnetarabi.com/odata.svc/Episodes?$filter=AudioFileLength gt 40

I hope you find it interesting.

If Crashing Gracefully Is Nice, Recovering From It Is Awesome

Filed Under (Development, DotNetArabi, Misc, software management) by Emad Alashi on 02-03-2010

Tagged Under : , ,

Last Saturday we had a SharePointSaturday event here in Jordan, in which I had the pleasure of interviewing Joel Oleson and Michael Noel for DotNetArabi.

At the end of Joel’s valuable interview, which can happen only in a life time, I stopped the recording by hitting the “Stop” button, simple. Surprisingly, instead of stopping the recording, Audacity just froze! I could hear myself screaming inside “NOOO!!!”, I guess even Joel heard that! the whole machine stuck that I had to force it to a Hard Shut down.

But knowing Audacity as a great piece of software, which really is, I hoped that I could still retrieve the recording. I rebooted and started Audacity again, and here comes the so refreshing alert at the start:

CrashRecovery

Some projects were not saved properly the last time Audacity was run. Fortunately, the following projects can automatically be recovered

THAT is a successful software! of course I lost portions of the recording still, but I can’t complain; I have most of the interview. So, When you design your software, DO make sure you don’t crash gracefully only, but yet to recover correctly from the crash.

Communication Skills Session at MSP – Jordev

Filed Under (Development, Misc, software management) by Emad Alashi on 21-11-2009

Tagged Under : , ,

I just finished a session about Communication Skills one-to-one for the MSP program with Microsoft and Jordev. As I promised the audience, here are the slides shared on the very good site SlideShare:

“Growing Software” book review

Filed Under (Development, software management) by Emad Alashi on 05-10-2009

Tagged Under :

growingsoftware

I have been reading this book Growing Software by Louis Testa, and I consider it the book of the year for me.

The book is a about how to create a robust successful software; starting from assembling your engineering team, to having a flourishing company with successful software product/services and happy customers.
If you are a new Development Manager, or already a Dev. manager who is in a small company growing fast, this book is for you.

There are many reasons why I find this book so valuable, here is a list of them:

  1. Scope: I haven’t come across any book that covers this scope of what should be done to create successful software; usually books would talk about the SDLC, Development Methodology and Process, engineering techniques…etc, and if you are lucky maybe about some of the best practices around that.
    This book, on the other hand, covers a lot more; it starts from the real beginning of understanding the environment around you, creating an effective engineering team and growing it, defining your product, defining releases, project estimation, project execution, choosing a process, enhancing the process, communicating with other departments, handling customers… and it even covers the future by setting directions, product roadmap and strategy. You can check the main table of contents here
  2. Practical: the book is obviously coming from a practical background, it tackles details that won’t be found unless the author really KNOWS what he is talking about, and that he actually lived that experience.
    This is especially obvious when the author talks about the wrong way of doing things. for example, I have always thought adding an unplanned extra feature to a release is a good thing, in fact that was a NO in Growing Software with enough good reasons.
    The real life examples of real instances took place (shown in grey boxes) added a great value; you will always stay skeptical about a theory until you hear someone who had lived it.
    Another part of the practical side is the auxiliary spreadsheets the book provides to tackle certain decision-making situations. No Starch Press provide them for download from their site here.
  3. Realistic: The book doesn’t promise you with a sliver bullet, instead it puts the various options on the table and show you why/when you would choose one over the other depending on the situation, injecting this with the experience Mr. Louis Testa has.
    It doesn’t tell you use Agile methodologies, RUP, or Waterfall…it helps you how to choose a process, how to customize it to fit your organization, and how to improve it.
  4. For Humans: actually this is one of the best things I liked about the book; I have always believed that we can’t separate business, process, establishments, or evolution without considering the emotions, the culture, and the mentality of the humans involved.
    Reading throughout the book, you can see that this was kept between the eyes all along when it talks about engineers, fellow executives, or customers. Tackling emotions, behavior, expectations and negotiation. Politics was significantly considered in the book when taking decisions or dealing with the different parties
  5. Simple: It’s simple; the language is easy to understand, and the structure and sequence of the book is logical. I had no interpretation burden while reading it.

Though, the addressed character in the book is a development manager or a CTO strictly; I’d have really loved if it had shed more light on the Business side of the story, I know it would have widened the scope even more but I believe this is becoming a large need in the Software Industry in general, maybe in another book.
Another thing is that sometimes the book digs little bit too deep in the self-management advices, to extent that intelligent people might want to skip it whole together.

I’d definitely recommend this book for everyone who is interested in Growing his Software house, or being part of it.

Nice Development Tools

Filed Under (Development, software management) by Emad Alashi on 19-09-2009

Tagged Under :

tool-kit Sometimes development tools can be very tempting to a degree that you just want to open the IDE and start hitting those keys. Though it’s not always within the IDE; here is a list of development tools, without specific order, that are just so sweet and pretty crucial to teams opt for best development environment!

  1. MSBuild or NAnt
    Build automation tools by which a developers can use XML scripts to automate all the hassle tasks of creating a build: retrieving code from the source control (SC), labeling the source code, building it, zipping it, emailing info, and many other tasks. Both tools are free.
  2. CruiseControl or TeamCity
    Continuous Integration servers that utilize the build automation tools to add extra slick functionalities like monitoring the SC, issuing specific commands on specific actions done on the SC. CruiseControl is free while TeamCity is not.
    I once heard a really interesting utilization of such servers; the dev team had red and green bulbs placed in a noticeable area where everybody could see them. On each code check-in action the servers would initiate a build on the server, so if the code builds successfully the green bulb would light up, if the build fails the red bulb lights up instead. nice ha! :D
  3. Tarantino
    I still haven’t got the chance to work on this tool, but it says it does the thing I really wish more companies start to embrace; which is having a separate database instance for each developer instead of shared databases.
    This tool would let the database changes to be incorporated into the SC as easy as code check-in’s (including Schema changes). So in any instance of time, the developer will be able to get latest version of code and sequence of scripts and work on clean ready environment where code and database schema is 100% compatible.
  4. RedGate Sql Compare
    It enables you to compare two database instances and to elicit a change script from this comparison. One of the many features, by which it supersedes its free counter part SQLCompare, is that it can be initiated from Command Prompt. costs at least $390.
  5. TortoiseSVN
    SVN(SubVersion) is an open source SC. TortiseSVN is an SVN client that integrates with the Windows shell. Lovely, robust and free.
  6. AnkhSVN
    it’s an SVN client too, but integrates with Visual Studio so you don’t have to leave the IDE to manage versions, indispensable. It’s free.
  7. TFS sidekicks
    if you have ever dealt with TFS administration, you’d know how cumbersome it is. TFS SideKicks is the solutions, period!
  8. NUnit or xUnit
    For the ones who haven’t heard of Unit Testing tools (I hope you are few!), you will be able to write code to test your code; and with nice GUI which tells which part of your code fails. Both are free.
  9. IE8 Developers tools, Firebug for Firefox
    These are awesome client side environment tools; Debug Javascript, Profile Javascript, and manipulate CSS on the fly. web devs can’t live without it really. both are free.
  10. Fiddler
    inspects http requests made from your browser, with details to the smallest bit came into your machine through http. It’s free
  11. WinMerge
    The best diff tool out there, I wish I could replace it with every IDE Source Control plugins, it compares folders too. It’s free.
  12. BugTracker.Net
    If you have a small team of devs who work on low cost and tight budget project where you can’t use Jira? this is THE bug tracker software I choose. I love their new feature integrating with SVN. And it’s free.
  13. DPack
    Code navigation tool; light, handy, free.
  14. CodeRush or Resharper
    code assistant and enhancement tools, makes you create, change, refactor code in couple of key strokes. They are both not free except CodeRush has an Xpress version

I am sure there are others slipped out of my mind, but I believe those are fun enough to play around with. enjoy :)

DotNetArabi Episode 5 دوت نت عربي الحلقة الخامسة

Filed Under (Development, DotNetArabi) by Emad Alashi on 29-08-2009

Tagged Under :

   

Episode 5 of DotNetArabi podcast is published on www.dotnetarabi.com

Mohamad Meligy talked in this episode about ORM (Object Relational Mapping), he explained in details how they work, why we need them, their advantages and disadvantages, and listed some of the known ORM engines.

لقد تم نشر الحلقة الخامسة من دوت نت عربي على www.dotnetarabi.com. تحدث فيها محمد مليجي بإسهاب عن
الـ ORM (Object Relational Mapping). مفصلا ماهيتها، و كيف تعمل، و حسناتها و سيئاتها، و ذكر كذلك بعضا من المكتبات البرمجية  منها و حسناتها.

DotNetArabi Episode 4 دوت نت عربي الحلقة الرابعة

Filed Under (Development, Misc) by Emad Alashi on 19-08-2009

Tagged Under :

  

I just published episode 4 of the DotNetArabi podcast on www.dotnetarabi.com.

This episode was with guest Mohammad Zayed, he works as Strategic Technology Specialist in Microsoft Jordan. he worked on different Microsoft technologies ranging from Windows Forms applications, Web Forms and Mobile.
Mohammad talks in this episode about Sharepoint, the in’s and out’s, the benefits and the challenges.

لقد تم نشر الحلقة الرابعة من دوت نت عربي على www.dotnetarabi.com ، التي كان الضيف فيها محمد زايد. يعمل محمد زايد حاليا كمتخصص تقنيات استراتيجي لكبار العملاء في مايكروسوفت الأردن. و تكلم في هذه الحلقة عن الـ Sharepoint: ماهيته، و ما يلزم لتثبيته، و تراخيصه، و نقاط قوته، و نقاط التحدي فيه، و الكثير من المعلومات القيمة. 

JIT compiler and "Method Not Found" error

Filed Under (Development, Misc) by Emad Alashi on 11-08-2009

Tagged Under :

CropperCapture[20]

Actually it can be “Could Not Load Type” too, but the reason is the same: you are referencing the wrong DLL version.

well, this is totally understandable; of course you are going to get this exception when you use an outdated DLL that lacks the new extra parameter to THAT certain method. But the interesting part is it will not happen when you first run your application, and neither when execution reaches the changed method; it will happen when code-execution reaches a place that REFERENCES that changed method.

lets look at the following example.

I have created two projects: Windows Forms project called “HostDLL”, and a Class Library project called “BadDLL”.
The HostDLL references the BadDLL; upon clicking a button in the form, the HostDLL will create an instance of class “BadClass” and call the method “DoStuff” which takes two integer parameters.
everything goes fine:

   20 private void button1_Click(object sender, EventArgs e)

   21         {

   22             BadClass bc = new BadClass();

   23             int x = 3, y = 10;

   24 

   25             bool never = false;

   26             if (never)

   27             {

   28                 bc.DoStuff(x, y);

   29             }

   30             MessageBox.Show(“Done successfully”);

   31         }

Notice the IF clause in line 26, and notice that calling the method “bc.DoStuff” will never take place because the “never” variable is always false.

Now, intentionally, we will make a breaking change in the BadDLL; adding a new integer parameter z to the DoStuff method (we will make this change AFTER we have compiled the HostDLL so we don’t get compile-time correction).

Run the applicaion HostDLL to show the form, you will notice that there is no error, even when the BadDLL has been changed. Now hit the button… you will get a run-time error that says “Method Not Found”. The interesting part of the story is that even though DoStuff will never get called, yet we will still get this run-time error.
The reason is that the JIT compiler does what it’s called after: “Just-In-Time Compiler“; using help from the “CLR via C#” book authored by Jeffery Richter, specifically in “Executing Your Assembly’s Code” section, the explanation is that:

To execute a method, its Intermediate Language must first be converted to native CPU instructions. This is the job of the CLR’s JIT (just-in-time) compiler…Just before the method executes, the CLR detects all of the types that are referenced by the method’s
code (in our case it’s the BadClass). This causes the CLR to allocate an internal data structure that is used to manage access to the referenced types.

The author continues in a graph in which he explains the process:

1. In the assembly that implements the type, look up the method being called in the metadata
2. From the metadata, get the IL for this method
3. Allocate a block of memory
4. Compile the IL into native CPU instructions

So it is at that point the code is compiled, and at that point the JIT discovers that there is a type (which is BadClass in our case) is referenced having an invalid method with one extra parameter.

So always be careful when you reference other DLL’s, if you don’t make sure you have the right version, you will be subject to a potential lovely RTE message :)