Category Archives: technology

WTF/Minute : code quality measure unit

 Some day your code will be reviewed, modified or even just read to understand the underlying algorithm by someone else that is not you that wrote the code….

My point here is that readability/maintainability of code is by far the biggest quality of a piece of software. Being able to read the code and understand it rapidly makes everything easier, either bugfixing or modifying/enhancing the code. Think that the next one that might be reading the code might not be as experienced as you with that language so

  • avoid using  unnecessarily complicated constructs that feed you coder ego but slow down the maintenance activity. You are a good coder, no doubt, but if your code is not readable by the average coder that will have to then you are not making a good service to your colleagues
  • Make clear what your code is doing and, if necessary use a comment to clarify what is not evident from the code (I’m not a huge fan of comments because most of them don’t tell anything more than the code). Use comments to refer to a requirement/user-story that is being implemented.
  • Stick to the language style guidelines that were set for your team/company
  • Tests are code too and often are read/reviewed more than real code : don’t fuck up in tests code just because “this is just a test, this code will not run in production”

Discussion on code quality is huge of course and these are simple rules that will impact on maintainability of your code (since a reviewer is doing the same activity of the next coder which will have to work on your code : read it). If you want to dig deeper into code quality measurement I’ll suggest this work from Idan Amit and Dror G. Feitelson really interesting : https://arxiv.org/pdf/2007.10912.pdf

Comic comes from here

Milan skies after fires in the alps, 2018

Hash functions – efficency and speed

hash function is any function that can be used to map data of arbitrary size to data of a fixed size. The values returned by a hash function are called hash valueshash codesdigests, or simply hashes. Hash functions are often used in combination with a hash table, a common data structure used in computer software for rapid data lookup.

If you happen to need a non cryptographic hash function (and you might need it even if your are using languages that have builtin hashtables like java or c++ ) here are some references taken from various parts:

Interesting comparison of different hash tables :

http://www.eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx

Some more hash functions here :

http://www.cse.yorku.ca/~oz/hash.html

Some really interesting benchmarks strchr.com/hash_functions by Peter Kankowsky.

And again hash benchmarks sanmayce.com/Fastest_Hash/.

Hash benchmarks in Rust by https://medium.com/@tprodanov/benchmarking-non-cryptographic-hash-functions-in-rust-2e6091077d11

And more benchmarks : https://medium.com/logos-network/benchmarking-hash-and-signature-algorithms-6079735ce05

Some (a mininum set) benchmarks ran using random keys of random len, 1.5 multiply factor on hash size, next power of 2 hash sizes :

Tests are run on random keys
--- hash_function speed on random long (100-350) keys
Keys    HashFunc         HashSize AvgTime(ns) Collisions LongestChain DimFactor
1000000 djb_hash         4194304    191.03      110620    6            1.500000
1000000 murmur64a_hash   4194304    60.87       110830    7            1.500000
1000000 wyhash_hash      4194304    36.69       110170    5            1.500000
1000000 elf_hash         4194304    444.25      110488    5            1.500000
1000000 jen_hash         4194304    143.90      110471    5            1.500000
1000000 djb2_hash        4194304    189.63      111048    6            1.500000
1000000 sdbm_hash        4194304    247.92      110087    6            1.500000
1000000 fnv_hash         4194304    247.87      110170    6            1.500000
1000000 oat_hash         4194304    309.55      110538    6            1.500000

--- hash_function speed on short keys (10 to 45 char len)
Keys    HashFunc        HashSize AvgTime(ns) Collisions LongestChain DimFactor
1000000 djb_hash         4194304    31.14       110363    6            1.500000
1000000 murmur64a_hash   4194304    28.24       110264    6            1.500000
1000000 wyhash_hash      4194304    21.84       109798    5            1.500000
1000000 elf_hash         4194304    49.88       110845    5            1.500000
1000000 jen_hash         4194304    33.28       110541    5            1.500000
1000000 djb2_hash        4194304    31.21       110664    6            1.500000
1000000 sdbm_hash        4194304    35.60       109906    6            1.500000
1000000 fnv_hash         4194304    35.59       109940    6            1.500000
1000000 oat_hash         4194304    43.28       110123    6            1.500000

Tests done with the hash table code you can find github.com/paulborile/clibs

And last a research study for SIMD optimized hash functions : arxiv.org/pdf/1612.06257.pdf  some theory and code github.com/google/highwayhash/blob/master/c/highwayhash.c. The all use the vector extensions present in gcc.

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.

 

Self driving is the next big thing

Just a few years ago the idea of a self driving car was seen as a futuristic technology that would take decades to arrive. Now it is only a matter of when it will be available and this thanks to startups that are shaping this segment. Here’s  a list (incomplete) of autonomous driving related companies, hardware, software and services, some of which have recently raised money from vc and investors :

  • lvl5 : computer vision software to crowdsource high-accuracy maps for self-driving cars.
  • starsky robotics , embark : self driving trucks
  • ouster (raised 27M$ ) : best lidar to date
  • AIMotive (raised 38M$ ) : full stack autonomous driving software
  • Nauto (raised 159M$ ) : self driving safety
  • drive.ai (raised 50M$ ) : self driving full stack
  • cruise ( GM bought for 1B$) : self driving full stack
  • pony.ai (raised 112M$ ) : claim safest self driving full stack
  • zoox.com raised 250M$ ) : self driving automaker

Driving a Tesla Model S in Paris

My brother in law owns a Tesla model S in Paris and I had a chance to try it out last week. One of the most exciting experiences (Miles Davis would have added “with my pants on”) of the last times. You are driving with almost no noise ( I know Jeremy Clarkson will hate this but I like it so much) in total comfort on a car that comes from another planet : this is what it looks like.

First of all I must say that I hate cars and what they represent : I’ve always considered them a necessary evil. I spent tons of money around my cars (smashing them so many times when I was in my twenties), doing maintenance and repairing them that I developed what is my personal requirements list for a car :

  1. accident prevention : a car that foresees a potentially dangerous situation and takes control to avoid an accident/crash. With a car like this I would have saved tons of money and a couple of broken ribs
  2. no maintenance or lowest possible : if I have to use a car I want to have the lowest possible maintenance. Brakes, oil and filters, clutch, distribution belts, sparks …. There is always something to do with your car
  3. do not contribute to city air pollution or do it the less possible

Tesla ( and probably other electric cars in the future will )  is matching exactly my requirements for what I want in a car.  Autonomous driving with all the available variants which range from lane/speed/front car distance control to full autonomous driving would make driving safer and reduce accidents and damage to the car.

And electric traction will make maintenance a distant memory : with the Tesla I tried which was set at maximum engine brake I barely never had to use the brake pedal; the cars brakes by using the electric motors as generators so you recharge you battery just by using the engine break

And performance comes last in the sense that I’m not a super car fan but pulling the gas to the floor on the Model S is a breathtaking experience. The picture on the left shows you the warp effect 🙂