Showing posts with label Stupid programming practices. Show all posts
Showing posts with label Stupid programming practices. Show all posts

27 October, 2008

Calling JavaScript functions from C#

There is perhaps no way available to do this, nor should there ever be one. This is because your C# code runs in the code behind, a repository of code to handle post backs, while your JavaScript is executing on the client side. If at all client side javascript was let to be executed from C# code, then it would be similar to AJAX RPC's! A better way to call Javascript functions is by using hidden fields. The following logic demonstrates how:


|
|-->set a hidden field


|
|-->check the value of the hidden fields for changes, if any write logic which has to execute.

Reverse the above logic, and put the javascript hidden field check so that it executes when the page gets loaded, and VOILA, you have an answer to your solution.

10 October, 2008

i = i + 1 : A ridiculous way to say increment I !

How many of you have coded in C, C#, Java or even JavaScript for that matter? If you have, then you'd probably know i=i+1 as one of your best companion when dealing with loops. Yet, I call the practice ridiculous...Why do you think that is?

For one, any programmer with a basic understanding of math would have puzzled over this question: isnt i->i+1 more meaningful than i=i+1 in a programming context? Why then do all programming languages follow the pattern of variable = variable +1?? I have no clue whatso ever, but I would reckon it is a reminiscent of the age when there were no standardized charecter sets for various programming languages and all vendors defined their own charecter sets, and standards.

And, to add to this mess, every programmer, no matter how experienced uses the counter variable named i, instinctively. Of course, he'd have to use an alternate variable to nest loops within other loops, he'd have to use another variable, and the second variable would instinctively be named j. I do not know if the collective conciousness of all programmers is at play here, for I have seen the same pattern repeating with every coder I have met over the past decade or so.. Even with me ! As we all pave way for new programming languages and techniques, I also hope that this hideous practice will be stopped, for all our sakes.