4 ms·
And as a trade off you get a much cleaner and more performant solution to the same contrived problem. This is where Haskell and functional coders tend to break
by dkhenry 13y ago
And as a trade off you get a much cleaner and more performant solution to the same contrived problem. This is where Haskell and functional coders tend to break down. Yes its mutable, but by violating that one rule you gain so much in terms of readability and performance.
- 5hoom 13y agoThat's one thing I've noticed with my C++ code lately is that I'm writing const absolutely everywhere. Having mutability where you need it is awesome but it is interesting to see languages like Rust where immutability is the default.
- jzwinck 13y agoI have done a bit of this too. The main downside in C++ is that you end up writing a few more ternary operators than you otherwise may have. But it is nice to be able to look at the first assignment of a variable and know it is the only one.
- 5hoom 13y agoYeah it kind of feels dirty having all these mutable variables around after doing any functional programming at all. I've found using const a lot also goes hand-in-hand with raii. If a member of a class is const it must be initialized in the constructor, and it just seems to make me code a bit more "hygienically".
- cgh 13y agoYou are right about more performant, but how is it cleaner and more readable than this? pyth x = [(a,b,c) | a<-[1..x], b<-[1..x], c<-[1..x], (a^2)+(b^2) == (c^2)]
- dkhenry 13y agoThats not c++ code. My claim is that if you try to stay pure using C++ you end up with very very ugly code that preforms pretty poorly.