can be simplified to
def check_hash(s, k) do String.slice(s, 0..k-1) === ref_string(k) end
A good practice is to format your code properly, write documentation for functions, use descriptive names for variables, write tests …
You might want to check for other messages in the
receive blocks, so that the message queue doesn’t grow indefinitely.
The following code at the top of the server file
def parse_args(args) when length(args) == 0 do IO.puts " usage: \n ./project1 k \n or \n ./project1 ip_addr" end def parse_args(args) when length(args) == 1 do a = String.split(hd(args), ".") ...
can be re-written without the guards and
def parse_args() do IO.puts " usage: \n ./project1 k \n or \n ./project1 ip_addr" end def parse_args([arg]) do a = String.split(arg, ".") ...
Also just to second … idiot above writing some tests and running a formatter (like the built in
mix format task in elixir version 1.6-dev) would be an awesome addition and in line with best practices.