Tabs vs spaces for code indentation

One argument which some people might give in favor of using tabs is that it allows the viewer to decide how the code should appear to them. And hence, it separates the logic (indentation) from its appearance. The biggest flaw in that argument is that it renders the concept of line length limits meaningless. Line length limits and the associated rules of wrapping bring a good structure to the code.  Someone looking at a piece of code with 3-levels of nesting and tab-length set to 8 will see a very different line length from someone using a tab-length of 2. Always expand tabs.

File size should always be of “long” type

int getTextFileSize(String fileName) {
  return (int) (new File(BASE_DIR, fileName).length();  // WRONG
}

A 32-bit signed int can deal with ~2GB worth of data. And if your code is not going to deal with files larger than 2GB, why worry? But what if  someone wants to use the same code for a video file some day? Or What if someone writes another code to iterate over all the files in the BASE_DIR directory? Most likely they will be inclined to use int for the final sum as well. Adding integers in most languages results in int and automatic overflows into a negative number (and even worse, back to a positive number). The caller code might think that BASE_DIR does not exist. Therefore, the best future-proofing is to never have file size stored as an integer. Even, Android platform got it wrong with StatFs#getBlockSize and corrected it by adding StatFs#getBlockSizeLong.

FOSS (Free and Open Source Code) Licensing FAQ

There are two choices while writing on this topic. One is to write a detailed and accurate port. The other is to write a short post. I preferred the second approach and had added appropriate links to dig further.

  1. Target Audience?
    • Someone who is planning to use FOSS, free and open-source code, as a building block for their software development.
    • Someone who wants to contribute to FOSS
    • Someone who wants to release source code of their project in public

Read More

Analysis of Facebook Rotating Images worm

If you are looking for how to avoid or recover: read this one instead.

In the past few weeks, a lot of Facebook users have received the following (or similar) messages posted by their friends
Hi Friends see Face-book images rotate 360* see here >> http://SHADYCLOUDS.TK/
Really cool Facebook revolving images. MUST SEE http://rotatingimage2.tk/.

Following are observations and analysis of the same.

Read More

Basic GDB Tutorial

So, you believe there are bugs in your C/C++ code or you have encountered SEGFAULT while executing your code. What will you do?

  1. write a lot of printf statements at various places in your code under suspicion
    OR
  2. use gdb (GNU code debugger)

This article is about Approach 2
Read More

Programming in Linux for newbies

This is meant to be a small guide (though not exhaustive) for students beginning to program on Linux system. Particularly for those, who have done extensive C/C++ programming in Windows, using the Borland/Turbo interface or the Visual C++ interface, and are greatly intimidated by the Linux platform.
Read More

GCC Hacks

A small list of GCC Hacks

  1. g++ -o helloworld helloworld.cc produces helloworld binary from helloworld.cc C++ file.
  2. use -Wall switch turns on all warnings(potential errors) in the code (like unused variables)
  3. g++ -E helloworld.cc generates output code after the pre-processing stage.

Read More

-->