Blog
Why not to initialize your local variables at declaration
Try to initialize local variables where they're declared. The only reason not to initialize a variable where it's declared is if the initial value depends on some computation occurring first.Sounds all nice and dandy. What could be wrong with that? Well, the result of this guideline is that a lot of developers who can't think of a useful value to initialize their variable with decide to initialize it with null instead of leaving it unitialized. This has the nasty property of not catching a lot of NullPointerExceptions that would have resulted in a compile time error along the lines of "The local variable x may not have been initialized" if the developer had just left that variable uninitialized instead. It's a pity Sun recommends such silly things which were probably inspired by the C/C++ era when uninitialized variables would contain garbage. Then again, Core J2EE Patterns is still in print while nearly all of the patterns described in it are either outdated or wholly inappropiate by now. But more on that later...
Written by
Our Ideas
Explore More Blogs

Using OutSystems UI Components in the right way
Using OutSystems UI Components in the right way Using OutSystems UI Components in the right way can be a game-changer for developers who want...
Vanessa William

OutSystems – Versioning Control
OutSystems – Versioning Control There are two widely used methodologies for versioning code: the traditional Branching methodology, and the...
Vanessa William
Contact












