Last Updated: July 11, 2019
· gideon

why learn new languages? Simple! It gives perspective

I'd been trying to learn haskell for a while, (I have an obsession you see) but it somehow slipped away.

Then, recently I took a coursera course where I had to learn python comprehensions. Yesterday I got back to and it was a breeze! How? Learning Python Comprehensions gave me a new perspective, it got me to think of a problem more functionally.

Different programming languages solve problems with different ideas. So I went back to ProjectEuler, this time trying to solve the problems in a number of languages:

Take Project Euler Problem 1 : Find the sum of all the multiples of 3 or 5 below 1000.

In Perl it looks like this

use Modern::Perl;
my $A = 0;
foreach my $x (1..999)
     $A = $A + $x if ($x % 3 == 0 or $x % 5 == 0);
 say $A;

With a Python comprehension:

A = sum([x for x in range(1000) if x % 3 == 0 or x % 5 == 0])

And With haskell:

main =  print(prob1)
prob1 = sum [x | x <- [1..1000], x `mod` 3 == 0 || x `mod` 5 == 0 ]

So go ye! Learn more languages, even if you won't use it in production, it will give you a new and fresh perspective when writing production code.

9 Responses
Add your response

I wolud write Haskell code some other way:

mod3 :: Int -> Int
mod3 = reverse mod 3

mod5 :: Int -> Int
mod5 = reverse mod 5

select35 :: [Int] -> [Int]
select35 = select mod5 $ select mod3

main :: IO ()
main = print . sum . select35 [1..1000]
over 1 year ago ·

Perl 6:

say [+] grep * %% (3|5), ^1000;
over 1 year ago ·

This is beautiful! :) I still don't understand all the syntax, but I will soon :)

over 1 year ago ·

wow! Sweet. I've been looking to get into perl6 soon.

over 1 year ago ·

totaly agree. maybe after python/haskell you can for for this . i personally come form java and i love python it just gave me a different point of view. especially when you come from a language that doesn't have closures (yet).

over 1 year ago ·

Yeah! I picked up ActionSctipt 3 with little effort after reading through a Java book.

over 1 year ago ·

I completely agree with this post, the more languages you know, typically, the better code you write in every language.

Problems like this are great examples of why I love the syntax of Ruby. The solution is incredibly easy and the code is very readable.

(0..999).select{|value| value % 3 == 0 || value % 5 == 0}.inject(0, :+)
# For the more wordy Rubyists:
(0..999).select{|value| value.modulo(3).zero? or value.modulo(5).zero?}.inject(0, :+)
over 1 year ago ·

@kazw looks beautiful! And after looking at it now looks immediately understandable. I'd given ruby a crack 2 years ago without too much luck. I'm going to have another go at it soon I think!

over 1 year ago ·

A feature that I like in Haskell is the function composition. Understanding how you can apply a function, and then pass the result as the parameter for another function is just awesome. Since I learned this in Haskell I've tried to use it wherever I can, I think that a developer doesn't learn a language, but learns good practices and perspectives as you said.

over 1 year ago ·