February 21, 2001

Seven Techniques for Better, Faster Development

hen AT&T assessed the performance of their engineering teams, they discovered that their top-ranking software developers were as much as 10 times more productive than their colleagues. There are several reasons behind this astounding range in performance. Besides intelligence and aptitude, of course, basic work patterns make a huge difference.

If Your Compiler Doesn’t Support snprintf() Yet

Sometimes, sprintf() is unavoidable. For example, when compatibility with C is paramount, Sprintf() has a safer version called snprintf(), which doesn’t write past its buffer’s limits. However, because snprintf() was added to the ANSI standard only recently, many compilers, including Visual C++ 6.0 and C++ Builder 4.0 still don’t support

Avoid This Common ASSERT(…) Mistake

ASSERT is a very helpful macro for debugging, because it helps root out false assumptions. However, many programmers make the mistake of putting actual assignments inside the macro. Consider the following: a = GetA();ASSERT(a != NULL); It is tempting to collapse this code into a single line: ASSERT((a = GetA())

Using const_cast

If you want to convert from a const to a nonconst or from a volatile to a nonvolatile, you can use const_cast. This is the only conversion allowed with const_cast. If any other conversion is attempted, it must be done using a separate expression or you

Porting Code With Unix File I/O

In pre-standard C, I/O operations were based on the Unix APIs. Instead of FILE pointers and functions such as fopen(), fread(), and fclose() that are defined in the header, Unix uses file descriptors and proprietary functions such as open(), read(), and close(). Here’s a code sample that uses Unix I/O

Rounding a Number

The Standard Library doesn’t have a function for rounding floating point variables. However, you can easily round numbers as follows: double d=42.666;int rounded=d+0.5; // rounded = 43d=rounded; // d is now 43.0 In other words, adding 0.5 to a floating point value and then converting the result to int has

JToolTip in a JTable Column

Tool tips are handy for providing explanations for buttons and other fixed components in a panel. Sometimes, it

Middle Tier Code Optimization With Java Reflection Package

In Web based programming, we usually check querystring parameters in middle tier java objects and do tedious, if not long, checks via if/else, to perform appropriate action or instantiate classes. A good workaround is to use Java reflection (java.lang.reflect). Class methods, like getMethods[] or getFields[], invoke particular methods based on

Execute an External Program Without Using JNI

The secret lies in the Runtime class. Runtime contains the methodexec, which takes the basic form of: Process exec(String command) orProcess exec(String[] comdarray) orProcess exec(String[] cmdarray, String[] envp, File dir) Where command is the name of the executable, comdarray contains the exe name and arguments, envp contains the environment variables,

No more posts to show