s-fcow
Last Updated: February 25, 2016
·
1.77K
· gideon

# why learn new languages? Simple! It gives perspective

###### languages

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 http://learnyouahaskell.com/ 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:
https://github.com/gideondsouza/projecteuler-multilingual

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

In Perl it looks like this

``````#!/usr/bin/perl
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:

``````#!/usr/bin/python3
A = sum([x for x in range(1000) if x % 3 == 0 or x % 5 == 0])
print(A);``````

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

9655

I couldn't agree more. More languages, more perspective.

over 1 year ago ·
9659

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 ·
9673

Perl 6:

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

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

over 1 year ago ·
9679

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

over 1 year ago ·
9684

totaly agree. maybe after python/haskell you can for for this http://www.rust-lang.org/ . 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 ·
9695

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

over 1 year ago ·
9755

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 ·
9758

@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 ·