Category Archives: coding

gcc/clang -fsanitize is saving lifes

 There where times when you had to write C/C++ code and find all the bounds errors and memory leaks by hand or with ancient tools (who remembers Purify?). Valgrind introduced a lot of features but sanitize features added in gcc/clang are just awesome (thanks google guys for this). Just add -fsanitize=address both to compilation and link of your unit tests (we use google test framework), execute the test and get valuable info on memory leaks and out of bounds access to data. In detail :

Testing and inclusion of sanitize is under way in our lab : more info on this in a future post. Work from this team led to the inclusion in Golang of the Data Race detector.

 

Creating logstash development environment for core or plugins

I had to develop a ruby logstash plugin recently and I going to recap all necessary steps to create a clean jruby env for development :

  • i had to uninstall ruby and install a clean jruby only stack. Not saying that this is necessary but in my case it only worked this way
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
curl -sSL https://get.rvm.io | bash -s stable --ruby=jruby-9.1.10.0
rvm alias create default jruby-9.1.10.0
source $HOME/.rvm/scripts/rvm
ruby -v
jruby 9.1.10.0 (2.3.3) 2017-05-25 b09c48a OpenJDK 64-Bit Server VM 25.151-b12 on 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12 +jit [linux-x86_64]
  • Install and compile logstash just to see if everything works. Check out logstash and from inside the directory :
jruby -S gem install rake bundler
rake bootstrap
rake plugin:install-default
bin/logstash -e 'input { stdin { } } output { stdout {} }'

  • Now compile the plugin from the plugin folder
bundle install
bundle exec rspec # test it
gem build logstash-filter-<yourplugin>.gemspec
  • Install the plugin gem and test it
bin/logstash-plugin install logstash-filter-<yourplugin>-1.0.0.gem

 

C++

Google C++ style guide : something every C++ coder out there should read or ““Within C++, there is a much smaller and cleaner language struggling to get out.” — Bjarne Stroustrup”

Having over 100 million lines of C++ code, google took the C++ problem (language with so many features, different ways of doing the same things, dangerous constructs, some pointers to the problems with c++ can be found on wikipedia, and here for an authoritative opinion)  seriously and this is what came out.

Some interesting decisions taken :

“We do not use C++ exceptions.” from here

“Avoid defining macros, especially in headers; prefer inline functions, enums, and const variables. Name macros with a project-specific prefix. Do not use macros to define pieces of a C++ API.” from here.

“Avoid complicated template programming” from here

“Within C++, there is a much smaller and cleaner language struggling to get out.” — Bjarne Stroustrup

REST API Server and Windows : ASP.NET Core kestrel, OWIN or plain old IIS + ASP.NET Framework ?

If you are planning to build API and make them available as micro services and your code assets are C#/.NET Framework/Windows then you have some choices :

  1. ASP.NET Core comes with an internal  web server called Kestrel : kestrel claims to be a light and fast web framework which runs ASP.NET Core applications without the need for IIS in front (you might decide that IIS is usefull for other things). Kestrel allows for middleware modules (like IIS ISAPI filters) that allow for adding features to the basic server.
  2. Katana (OWIN Microsoft implementation) is a collection of NuGET packages for building OWIN applications.
  3. Plain old IIS + ASP.NET REST API code

Some good information can be found here from uShip guys
I’m basically writing this for myself as a reminder for the new .NET Core Microsoft environment.

On the importance of having a second head to test code and TDD ( Coders just don’t want to break their code )

Good Coders don’t want to break their code because their code is like a creature and nobody wants to harm a creature. Take a note, this is how it is. Good Coders tests are just ‘combing’ the code they should test. But this creature has bugs, no matter how good the Coder is, so good Coders are bad at writing tests on their own code.

A good test tries to tear code apart, to abuse it doing the nastiest things, at the maximum possible speed, in the worst possible way : this is why you should consider making another set of tests by another coder which has not written the code itself.

But with TDD this is difficult : I like the idea that a Coder writes it’s software use cases before writing the software itself but I’m missing how to include in this process a second head to develop some really nasty tests on that piece of code and I’m not a great fan of pair programming (for many reasons).

So open issue for me here : how to include development by a second head of integration tests.

(In the picture : good coders and good testers 🙂 )