clarity

Check if variable null before assign to null?

Is variable assignment expensive compared to a null check? For example, is it worth checking that foo is not null before assigning it null? if (foo != null) { foo = null; } Or is this worrying about nothing? ...

General programming - else or else if for clarity

In a situation where a variable could have two different values, and you do something if its one, something differnent if its the other, would you just do: if(myVariable == FIRST_POSSIBLE_VALUE) { ... } else { ... } or would you do: if(myVariable == FIRST_POSSIBLE_VALUE) { ... } else if (myVariable == SECOND_POSSIBLE_VALUE) { ... } ...

iPhone Dev - Where to put lazy loading code

I already had a question like this, but I already deleted it anyway. I have very simple app that has a root view controller and it switches between two other view controller views. So in my root view controller, It lazy loads the instances of the two other view controllers. Each time the switch button in the toolbar is pressed, the curr...

PHP best practices: repass variables from config file when calling functions or use global?

I have a program that I use on several sites. It uses require('config.php'); to set any site dependant variables like mysql connect info, paths, etc. Let's say that I use one of these site-dependant variables in a function, like $backup_path. This variable was initially declared in config.php, and does not appear in the main program fi...

VB.NET Delegate code clarification

I am trying to figure out what this piece of code does. It errors often (not in a system damaging way) but enough that it bothers me. It would be great if I could get some more information on what exactly is going on here and any suggestions on how I might be able to fix/prevent this. Code Public Shared Sub Fire(ByVal thisEvent As [Del...

Java While-Loops

So while rewriting some code, I came across something along the lines of: Method 1 while ( iter.hasNext() ) { Object obj = iter.next(); if ( obj instanceof Something ) { returnValue = (Something) obj; break; } } I re-wrote it as the following without much thought (the actual purpose of the re-write was for...

Naming booleans

If I only want to check if something is impossible or not (i.e., I will not be using something like if(possible)), should I name the boolean notPossible and use if(notPossible) or should I name it possible and use if(!possible) instead? And just to be sure, if I also have to check for whether it is possible, I would name the boolean pos...