Showing posts with label clojure. Show all posts
Showing posts with label clojure. Show all posts

Friday, December 4, 2015

rosetta-stone

One thing that I've come to realize while being a Software Engineer is that I enjoy learning different programming languages, build tools, frameworks, libraries, etc in programming. Now, almost every language/framework/library has their own "How To" guide, but it's usually very basic - how to setup your environment, how to write your first line of code, how to compile, etc. I thought it would be fun to make a "How To" for programming tasks - print to the user, comparison, sorting, etc. That's when I stumbled up Rosetta Code's Programming Tasks page, which has an enormous list of different tasks done in various languages. Once I found this, I decided to make rosetta-stone.

rosetta-stone is a repository which has examples of various programming tasks done in various languages. The tasks that I have completed so far are:

  • hello-world - Print "Hello World!" to the standard out.
  • command-line-arguments - Print the total number of arguments and each argument to the standard out.
  • integer-comparison - Compare two integers and see if the first one is less than, equal to, or greater than the second.
  • string-comparison - Compare two strings and see if they are equal with and without case and their lexicographical ordering.
For each task, I currently have examples in Java, Scala, and Clojure, however I plan on expanding the number of languages in the future. I also plan on adding new tasks and categories as I progress.

Stay tuned for updates on this repository for new tasks and programming languages.

Saturday, September 19, 2015

The Joy of Clojure

So I recently started to look at the programming language Clojure and picked up a copy of The Joy of Clojure to help me learn. The book is extremely well laid out and easy to follow provided you have some programming knowledge - however knowledge of Clojure itself is not needed to work through the book.

Once I started to wrap my head around how everything is a function in Clojure, I really started to like some of the choices which were made when designing this LISP-style language. One thing that I find very helpful is the fact that we can chain any number of parameters into any function call. One example would be to add multiple numbers:
 // Java  
 1 + 2 + 3 + 4  
 // Clojure  
 (+ 1 2 3 4)  
In this example, '+' is the function we're calling and we're using '1', '2', '3', and '4' as the parameters to the function. Another advantage of the fact that everything is a function is there is no such thing as order of operations:
 // Java  
 1 * 2 + 3 / 4  
 // Clojure  
 (+ (* 1 2) (/ 3 4))  
Even in this trivial example, we can see the power of having each operation be its own function with its own parameters. In the Java code, we need to remember that there are implicit parenthesis around the '1 * 2' and '3 / 4' to make sure they get evaluated BEFORE the addition. In Clojure, we just use parenthesis to ensure each operation has the proper parameters we wanted.

So far I have only worked through the opening few chapters in the book but am already liking how the language works, looks, and interacts with Java. I have a GitHub repo setup where I am working through the examples and writing comments of things I feel are important. I look forward to working through more of this book in the near future.