Live data from Hacker News

Practicing Elixir or any programming language

ericdouglas.github.io

41–50 of 59 posts

Re: Practicing Elixir or any programming language

#41

I would like to mention http://exercism.io . It has unit tests written also

Yes, I've used exercism to broaden my knowledge and I've recommended the site to friends and colleagues who wanted to learn programming. You mentioned tests: on exercism you don't write unit tests by yourself, the tests are only for you to check your solution. It certainly helps to see how tests can be written in any language, but you aren't forced into a strict TDD style. The best feature on exercism for me is to be…

In HR you can see other solutions as well

Re: Practicing Elixir or any programming language

#42

Great article, thanks! I'm not an expert Alchemist by any means, but whenever I see a `cond`, I try to see if it can be refactored out using pattern matching (after I was picked up on the same thing during an interview!) defp formatted_hour("AM", "12"), do: "00" defp formatted_hour("AM", hours), do: hours defp formatted_hour("PM", "12"), do: "12" defp formatted_hour("PM", hours), do: 12 + String.to_integer(hours)

Awesome! Many thanks for the tip. I'll refactor the code :)

Re: Practicing Elixir or any programming language

#43
post #12
post #2

> Why algorithms? > Because this kind of problem is an interesting way to put yourself searching all the API of the language in order to solve the challenge in the more elegant/concise way you currently can. Bullcrap. APIs are either going to be irrelevant for solving an algorithm, or will simply do the job for you. "Implementing an algorithm" usually means writing it from scratch using simple data structures, primit…

It's important to be able to look at a problem and think "i bet I could find a function in the standard library that could help me solve this problem" or "I should just solve this from scratch with the basic functions I know, like map/filter/reduce/etc. So I disagree somewhat here.

Yeah, that's the point: "i bet I could find a function in the standard library that could help me solve this problem"

Re: Practicing Elixir or any programming language

#44

Great article, thanks! I'm not an expert Alchemist by any means, but whenever I see a `cond`, I try to see if it can be refactored out using pattern matching (after I was picked up on the same thing during an interview!) defp formatted_hour("AM", "12"), do: "00" defp formatted_hour("AM", hours), do: hours defp formatted_hour("PM", "12"), do: "12" defp formatted_hour("PM", hours), do: 12 + String.to_integer(hours)

I personally like recursive pattern matching

    defp formatted_hour("AM", hours), do: rem(hours, 12)
    defp formatted_hour("PM", hours), do: 12 + formatted_hour("AM", hours)

Re: Practicing Elixir or any programming language

#45
I don't practice nor learn languages. I prefer concepts. I get "the book", skip the very first chapters that only talk about syntax, go straight for the unique features that make the language interesting (for a Clojure book, I'd go straight to protocols, agents, etc.), wrap my head around them and then maybe skim a popular repo hoping to read some idiomatic code.

Re: Practicing Elixir or any programming language

#46
I am a fan of http://www.rubykoans.com for Ruby. I am thinking about developing something similar using the Go playground for that language, and maybe an alternative for Rust.

Where I'd want to stretch it is some data structure and algorithm exercises, maybe even some design patterns. I'd love to be able to have a common environment where I can start to learn any one of multiple languages using similar exercises.

Re: Practicing Elixir or any programming language

#47

So his approach is to go through hackerrank exercises to learn the language. Anyone familiar with hackerrank able to comment on that vs say project Euler?

I would say that Hacker Rank helps with learning syntax of a language. I'm not sure if it helps greatly with learning how to implement framework type ideas or large programs. Hacker Rank is best at teaching algorithms & problem solving. I did a couple the other day & at first I thought they looked difficult. After breaking them down & thinking about them, they surprisingly weren't all that hard.

The very definition of software :-)

Re: Practicing Elixir or any programming language

#48

Great article, thanks! I'm not an expert Alchemist by any means, but whenever I see a `cond`, I try to see if it can be refactored out using pattern matching (after I was picked up on the same thing during an interview!) defp formatted_hour("AM", "12"), do: "00" defp formatted_hour("AM", hours), do: hours defp formatted_hour("PM", "12"), do: "12" defp formatted_hour("PM", hours), do: 12 + String.to_integer(hours)

I agree though one thing I would caution is it is good practice to always return the same type from a function even though it is an untyped language. The whole thing can be boiled down even more if pattern matching is used in parsing the initial string.

  def convert(>  ":" 
              >  ":" 
              >  >) do
   "#{formatted_hour(h,period)}:#{m}:#{s}"
  end

  defp formatted_hour(hours,"PM"), do: "#{String.to_integer(hours) + 12}"
  defp formatted_hour("12","AM"), do: "00"
  defp formatted_hour(hours, "AM"), do: hours

Re: Practicing Elixir or any programming language

#50
post #44

Great article, thanks! I'm not an expert Alchemist by any means, but whenever I see a `cond`, I try to see if it can be refactored out using pattern matching (after I was picked up on the same thing during an interview!) defp formatted_hour("AM", "12"), do: "00" defp formatted_hour("AM", hours), do: hours defp formatted_hour("PM", "12"), do: "12" defp formatted_hour("PM", hours), do: 12 + String.to_integer(hours)

I personally like recursive pattern matching defp formatted_hour("AM", hours), do: rem(hours, 12) defp formatted_hour("PM", hours), do: 12 + formatted_hour("AM", hours)

Nice!
Post reply on HN