Posts

Showing posts with the label Programming tips

How to round the number up to 2 digits in Javascript

Sometimes you need to round up the number up to 2 digits. For example, you calculation has to show a result in currency. There are two solutions to use on internet: 1) Use Math.random function. var a=123.4567; Math.random(a*100)/100 However, this is not really good, as for example in case of var a=1.005; Math.random(a*100)/100 results into 1 instead of 1.01. 2) use toFixed(2) However, it is more secure option to use a.toFixed(2), which would return element as fixed 2 decimal value
Today I listened a really nice clean-code google talk about bad practice of using IFs, and how much polymorphism helps out there. It is amazing to see how nicer code becomes, and how easy it is for a programmers to go into routine of making if/switch statements for no reason. All methods mentioned there are not new at all, but having it here shown reminds you on what and how should you think when programming.

Seven habits of highly effective programmers

Very interesting article http://drupal.technicat.com/writing/programming.html

"Reverse Engineering" in different programming languages?

A lot of engineers in one point of another needs to look through usually undocumented open source code, in order to modify/implement additional features. Using editor for bigger projects built in C/C++ (without OOP) can be unbelievably painful (my own experience). Two software that helped me a lot to reverse engineer my any source code are: 1) Doxygen : Creates nice documentation of all the functions in the project. It gives links to definition of each function, but more interesting is also can create call/caller graphs (for each function it gives graph of functions which it calls, and another graph of the function which call that function). It is completely a freeware, and the graphs are done using the dot program. 2) Understand : the free trial version of this application (14 days) is very handy, and is a bit more powerful comparing to Doxygen.