1 Problem, 6 Programming Languages (C++ vs Rust vs Haskell vs APL vs Clojure vs Scala)

preview_player
Показать описание
A video taking a look at 6 programming language solutions (C++, Haskell, APL, Rust, Clojure & Scala) to one problem.

Github Links:

Рекомендации по теме
Комментарии
Автор

I love the way you talk about the "beauty" of a solution. It's that sort of thing that reminds me why I love programming. Thank you :)

taylorallred
Автор

i use C++ for high performance code, Python for interfacing and Haskell to keep my ego in check

joshuastein
Автор

As a guy who inherited application support for 500, 000+ line code base of C and a couple 2-3000 line APL applications i can tell you, I'd much rather see the word MAX written out rather than have to look up every single glyph i stumble upon at 3:30am on a Saturday morning.

DanBader
Автор

In the Scala solution, it is recommended to skip the curly braces. What you are doing here is creating a block. Blocks return their last expression. This block only has one line and is thus unnecessary.

holothuroid
Автор

The APL solution seems to be the most straightforward if i figure out where is the max symbol in my keyboard 😁.

khalilzakariazemmoura
Автор

In the Haskell solution you could just do `foldl1' (+)` and `foldl1' max` to make the reductions explicit

clintonmead
Автор

If you don't mind spicing the type signature up you can do this in Rust:

fn maximum_wealth<T: Iterator<Item=impl Iterator<Item=i32>>>(v: T) -> Option<i32> {
v.map(Iterator::sum).max()
}

The code in this one looks a bit nicer but the data type are just crazy and you have to parse the vectors first as an iterator.
Also notice that by returning an Option<i32> you can get rid of .unwrap(). This has also the benefit of returning None when your outer Vec is empty and does not throw an exception like other languages would

whaisonw
Автор

The composition operator is just a function, so that makes 4 functions in the Haskell solution.

bram
Автор

Would be interesting to see benchmark between them. Especially the c++ versions and rust (I work as a c++ developer as well).

TheVralapa
Автор

Python: return max(map(sum, accounts))

ryantjoa
Автор

I've been around a long time, learned COBOL on a Burroughs mainframe in the 80s and do cloud architecture and security now. I knew about APL, Haskell, Scala and Clojure but had never seen a solved problem before. All you hear about these days is JS and Python and maybe Go. Thanks for the video, you presented and explained the material very well. It clicked with me vs. a lot of the other coding channels. New subscriber.

JohnTurner
Автор

The APL solution as someone who doesn't know that language or someone who is new to the language is horrendous. Not to say the C++ solutions are ideal but the for-loop one would be very obvious as to what it's doing for anyone even reasonably familiar with programming. (The rust solution also)

I think the Haskell solution is probably the cleanest as someone who has never even programmed before might be able to figure out what it does somewhat.

But even if you were Dennis Ritchie himself you wouldn't have the slightest clue what the hell the APL solution is doing without already being very familiar with the language. Less lines of code doesn't always mean better code.

NicholasVeselskiy
Автор

I find the python solution for this pretty nice:

def maximumWealth(mtx):
return max(sum(x) for x in mtx)

rban
Автор

For me readability is king, only when performance is an issue I would go with more technical solutions. When working with a team, this kind of fancy code tricks make everyone's life a nightmare debugging. Although it is nice to see the possibilities.

alejandroenriquez
Автор

For me readbility is the king, Haskell, Rust are what I like the most.

For some languages I suppose the programg just crash if the array is empty

neociber
Автор

Cleaner Clojure solutions are available using transducers.

(transduce
(map (partial apply +))
max
input)

Kimbsy
Автор

I watch these so I can get confused, then I can get my brain adjusted to how much I don't know. Lovw the content.

pup
Автор

I'm learning ocaml and here's the solution I would use (with the Batteries library):

let maximumWealth = Array.(map sum %> max)

Without the Batteries library you don't get sum or max, but they're easy enough to define in terms of folds:

let maximumWealth m =
let max arr = Array.fold_left max arr.(0) arr in
let sum = Array.fold_left ( + ) 0 in
m |> Array.map sum |> max

scoreunder
Автор

in c++ with funlib this is just
const auto wealth = stream(accounts) | map( fold( add, 0)) | max();

TheBlenderblob
Автор

more elegant clj:
(->> data
(map (partial apply +))
(apply max))

aLotOfDoubt