Why is there a pyramid image on a SQL article ? Haha, good question ! This article is about how to organize a SQL table to represent a tree as a pyramid shape. This technique was explained to me briefly by very skilled SQL programmer. And I must say that I did not understand the interest at first. Only by putting the explanations on paper (and by doing some drawings) I understood all the interest of this clever method.

Continue reading

Pointer or not and mutable or not If you don’t know what’s a pointer or want a reminder you may read the excelent Dave Cheney post : Understand Go pointers in less than 800 words or your money back When should I use pointer, when should I use reference ? TLDR: Methods using receiver pointers are common; the rule of thumb for receivers is, “If in doubt, use a pointer.

Continue reading

Golang and Unicode First what’s a string in go ? In go a string is an immutable slice of byte. In go every string you declare is UTF-8 encoded (but the one you get from user may have different encoding; you must absolutely know the encoding of a string you get). Some definition Unicode define every letter in the world as code points. UTF-8 is a manner to encode all this code point (there is many : UTF-16, UTF-32, UTF-7), UTF-8 is the one used for best space efficiency : a char can be 1 byte (with ASCII table compatibility) or more (up to 4); comparing to UTF-16 where the minimum size is 2 bytes; UTF-32 is best for speed in string manipulation (knowing that every code points is always 4 bytes enable random access : string slicing is O(1) in UTF-32 and O(n) in UTF-8) … and UTF-7 is a bizarre Unicode unofficial encoding used only by imap, let’s not worry about it.

Continue reading

Array or object : how to choose … nail or screw ? TLDR Here is how I choose : Array are not associative in javascript. Array have some facility function (indexOf, foreEach, etc) Note: bonus there is pretty always a Polyfill for them (so don’t hesitate to use them in any browser) Object can be used as associative array. And Object can have function (methods), and constructor (sort of : using function constructor)

Continue reading

False assumption You may have heard : “Like in Python : everything in JavaScript is an Object” → ☹ WRONG ! … for Python it’s true (and for Ruby too), but not for javascript. No it’s a bit more complex for JS. Javascript types There are 7 types, and object has 5 differents kinds : Number ! ATTENTION ! : may be NaN (Not a Number) String Symbol (new in ES6) Boolean Null Undefined Object Function Array Date Error RegExp So Number, String, Symbol, Boolean are not object.

Continue reading

… yes every time a longer title What we want A tidy JS code = clean global scope = well organized functions in boxes (modules) independant. What is Cross-Reference problem ? Cross-reference in JS is when you accidentally override a function or variable ; because there is another function or variable with the same name. Cross-reference can be frequent in javascript, because it just has function isolation. So a variable in global scope is not safe, and you must keep the number of global variable as low as possible.

Continue reading

SQL scan in Go without headache If this is first time you do sql with Go you probably should read this tutorial first, and comme back here to improve scan. TLDR: Use sqlx for doing SQL. sqlx sit on top of standard sql library adding very convenient function especialy to scan result to a struct. SQL scan without sqlx Sql scan is a little bit tedious in Golang : the scan order must match your SQL query order.

Continue reading

Author's picture

Tristan Giovangrandi

Happy Web developper @Content-Square and happy father

Full Stack & Embedded

France - Paris