diff --git a/content/books/things-i-learnt/_index.md b/content/books/things-i-learnt/_index.md index b7692ba..7eeb593 100644 --- a/content/books/things-i-learnt/_index.md +++ b/content/books/things-i-learnt/_index.md @@ -30,5 +30,6 @@ template = "section-contentless.html" * [Beware of Interface Changes](interface-changes) * [It's Better To Let The Application Crash Than Do Nothing](crash-it) * [If You Know How To Handle It, Handle It](handle-it) + * [Types Say What You Data Is](data-types) * Community/Teams * [A Language Is Much More Than A Language](languages-are-more) diff --git a/content/books/things-i-learnt/data-types/index.md b/content/books/things-i-learnt/data-types/index.md new file mode 100644 index 0000000..8994c85 --- /dev/null +++ b/content/books/things-i-learnt/data-types/index.md @@ -0,0 +1,40 @@ ++++ +title = "Things I Learnt The Hard Way - Types Say What You Data Is" +date = 2019-06-24 + +[taxonomies] +tags = ["en-au", "books", "things i learnt", "types"] ++++ + +Memory is just a sequence of bytes; bytes are just numbers from 0 to 255; what +those numbers mean is described on the language type system. + + + +For example, in C, a `char` type of value 65 is most probably the letter "A", +which an `int` of value is 65 is the number 65. + +Remember this when dealing with your data. + +And it doesn't matter of your language of choice uses dynamic typing or static +typing. The same still applies. + +One classic example of misusing types is adding booleans. Booleans are either +`true` or `false`, but because most languages follow C, which doesn't have a +boolean type and uses compiler pre-processors to define `TRUE` as an integer +with the value `1` and `FALSE` with another integer with the value `0`. And +so, the build on top of what older developers knew, other languages use the +same concepts. And so, you have a list of booleans and want to know how many +true values are in the list, you can simply add them all. + +Let me point that again: You're adding booleans and expecting a number. + +No, you're counting the number of elements in the list 'cause that would see +the whole list. You're not even filtering the false values over and counting +the resulting list size. You're jumping the underlying type to get a bit of +performance out. + +Fortunately, new languages are based on ML, which wouldn't allow this kind of +stuff. + +{{ chapters(prev_chapter_link="/books/things-i-learnt/handle-it", prev_chapter_title="If You Know How To Handle It, Handle It", next_chapter_link="/books/things-i-learnt/languages-are-more", next_chapter_title="A Language Is Much More Than A Language") }} diff --git a/content/books/things-i-learnt/handle-it/index.md b/content/books/things-i-learnt/handle-it/index.md index 2bc74c5..87f7a25 100644 --- a/content/books/things-i-learnt/handle-it/index.md +++ b/content/books/things-i-learnt/handle-it/index.md @@ -27,4 +27,4 @@ occur, _deal with it_. If you have to save the save the content of the user somewhere else, log it to be reprocessed later or even just show an error message, do it. -{{ chapters(prev_chapter_link="/books/things-i-learnt/crash-it", prev_chapter_title="It's Better To Let The Application Crash Than Do Nothing", next_chapter_link="/books/things-i-learnt/languages-are-more", next_chapter_title="A Language Is Much More Than A Language") }} +{{ chapters(prev_chapter_link="/books/things-i-learnt/crash-it", prev_chapter_title="It's Better To Let The Application Crash Than Do Nothing", next_chapter_link="/books/things-i-learnt/data-types", next_chapter_title="Types Say What You Data Is") }} diff --git a/content/books/things-i-learnt/languages-are-more/index.md b/content/books/things-i-learnt/languages-are-more/index.md index 7559ef9..8a3404d 100644 --- a/content/books/things-i-learnt/languages-are-more/index.md +++ b/content/books/things-i-learnt/languages-are-more/index.md @@ -39,4 +39,4 @@ surface of what the whole of a language encapsulates and if you ignore the other elements in it, you may find yourself with a cute language in a community that is always fighting and never going forward. -{{ chapters(prev_chapter_link="/books/things-i-learnt/handle-it", prev_chapter_title="If You Know How To Handle It, Handle It") }} +{{ chapters(prev_chapter_link="/books/things-i-learnt/data-types", prev_chapter_title="Types Say What You Data Is") }}