Thursday, July 31, 2014

Refactoring/Optimization trivial trick

The program is working, no it's time to profile and optimize it or do some refactoring.
So, I just need to change logic1 to logic2 in some part of a program. I do so, and the program works differently. OK, let get previous version from git and compare code in some merging program. No ideas? OK, lets put more logging into both versions to see what is the difference. Mmm, still no ideas?

The solution is simple: add implementation of logic2 to the existing program and put bunch of assertions, that the results are equivalent to logic1. Like this:

foo(logic1_params, logic2_param){
// old code for logic1
logic1 res = ...

//new code for logic2
logic2_res = ...

assert(logic1_res == logic2_res);
return logic1_res;
}

If assertion fails, at least you know where he problem is.
 After all assertion are fine, step by step replace return logic1_res; by return logic2_res;
and see what happens)

Important: I don't have unit tests (too expensive for research programs), but I have tests for the system and big modules to warn me if I screw up.


Wednesday, July 30, 2014

Lifechanging Password

This guy makes a password from his life goals: 
Quit@smoking4ever

Tuesday, July 29, 2014

Five Languages of Love

  1. Words of Affirmation/Prise
  2. Acts of Service/Help/Care
  3. Physical touch
  4. Quality time spent together
  5. Gifts
Usually one or two of them are more important. To feel content, the demand of each of them should be met. 

Monday, July 28, 2014

C++, Cygwin, Netbeans: tools

Problem 1. Breakpoints don't work.
Solution: run Netbeans with this command
"C:\Program Files\NetBeans 8.0\bin\netbeans.exe" -J-Dgdb.breakpoints.shortpaths=true

Problem 2. Profiling tool?
Solution: gprof
  1. Compile and link with the -pg option.
  2. Run your program normally
  3. Type gprof mysuperprogram > outputfile
  4. look description of the tables AFTER the table
Problem 3. Where from the function was called?

gprof output:
                                                 <spontaneous>
[5]     11.9    4.69    0.00                 std::string::assign(std::string const&) [5]

solution: use gdb with this nice cheat sheet
set breakpoint by name and then call where