Showing posts with label Coding. Show all posts
Showing posts with label Coding. Show all posts

Sunday, May 24, 2015

Studying Notes on Elixir

Elixir is a Erlang VM (BEAM) based language (http://elixir-lang.org/). This post serves as a note and thoughts while exploring this language.

On Installation

  1. It is much easier to install Erlang and Elixir via Homebrew, if you are using Mac, you definitely should consider this route
brew install elixir
brew install erlang

On Syntax

  1. true and :true are the same, same goes to false and :false. These have data type of booleans
  2. Constants, or symbols are called atoms. For example :hello is an atom.
  3.  The atom version of booleans (i.e. :true and :false) are special cases, and will be treated as booleans.  As can be shown below by the interactive output of Elixir. Note :hello is an atom, but not a boolean
  4. iex(7)> is_boolean :true
    true
    iex(8)> is_boolean :false
    true
    iex(9)> is_atom :true
    true
    iex(10)> is_atom :false
    true

    iex(11)> is_boolean :hello
    false
    iex(12)> is_atom :hello 

Friday, October 20, 2006

Optimal Function Size

How big should a function be? Someone has very practical answer, paraphrasing what the author said:

"Once my friend interviewed a candidate for programming job, in the interview my friend casually asked how the candidate tell if a function is too big. 'When it is bigger than my head', the candidate replied. My friend was puzzled, thinking this candidate was referring to his brain capacity. The candidate went on to explain 'I will stick my head on the monitor and if the function is bigger than my head, it is not good'."


This is probably one of the most practical definition for optimal function size I have seen so far, mainly you have something very measureable during formal code reviews. i.e. What? you think your function is all right? You have a 2-feet face?

If I were the interviewer, I would have hired that guy.

So dear reader, do your have bigger-than-your-head functions today?