Drake's Weblog

3 minute read

I recently started learning Erlang, one of famous functional programming languages, which is also a general-purpose concurrent programming language developed by Joe Armstrong. (I love the name Armstrong. Sounds cool!) And why do I bother to learn another programming language? I think I has been influenced by The Pragmatic Programmer, which suggests programmers to pick up a new programming language once a year to fresh your mind.

Some of my experiences:

  • Compared to C/C++ family’s semicolon “;” in the end of statements, Erlang’s usage of decimal point “.” is kinda interesting. It makes me think of programming as writing an essay.
  • The force of variable’s name to be started with an uppercase letter (ex, “Drake” is a variable name while “drake” is not.) is so tiresome. It might destroy my left little finger one day. But it is, at least, better than using dollar signs :p
  • Preventing double “pattern matching” (or variable bounding) of one variable is new to me and I am getting used to it to figure out what really benefits I can have to this restriction.
  • The built-in data type, integer, is kinda like Big-Num, which I love so much!
  • The meaning of “=” is not assignment but “pattern matching” guides me to the ideas of no-side-effects in FP.
  • Some mathematic or arithmetic operators are so weird:
    • “>=”, but “=<” ?! (not “<=")
    • “=:=” means equality testing.
    • “or” and “orelse” are different.
  • In some context, “;” is semantically equal to OR; while “,” is AND.
  • The braces “{}” are used for data type, Tuple, is not that familiar to me cause I have already used to Python’s way by parenthesis “()”.
  • Making usage of Tuple for record (or struct in C way) is not that cool for Dictionary for that in Python.
  • Claus, the great way to express some function definition in more mathematic way. It somehow looks like polymorphism in OOP and I love this more than OOP way!! Ex.

area({rectangle, Width, Ht}) -> Width * Ht;
area({circle, R}) -> 3.14159 * R * R.

  • The different syntax for “function definition” and “claus definition” troubles me sometimes. (put “end” in the end of fun()…)
  • The Erlang shell’s auto-completion is kinda weak when I am used to ipython’s convenience.
  • The functional way to describe/define the function has so much fun!!!
  • List comprehensions in Erlang seems more powerful than in Python. Check this out:

pythag(N) ->

[ {A,B,C} ||

A <- lists:seq(1,N),

B <- lists:seq(1,N),

C <- lists:seq(1,N),

A+B+C =< N,

AA+BB =:= C*C

].

> lib_misc:pythag(40).

[{3,4,5},

{4,3,5},

{5,12,13},

{6,8,10},

{8,6,10},

{8,15,17},

{9,12,15},

{12,5,13},

{12,9,15},

{15,8,17}]

  • Still, I have to say, “the Erlang shell is so weak!”. I think a powerful shell is the necessary to make a learning programmer happy and easy-life.
    • None
comments powered by Disqus

Recent posts

Categories

About

You're looking at Drake's words or statements. All opinions are my own.