5 ms·
This is probably the best summary of functional programming, written by the best "pragmatical" programmer of the world. I wonder how much Haskell code Carmack m
by lolcraft 14y ago
This is probably the best summary of functional programming, written by the best "pragmatical" programmer of the world. I wonder how much Haskell code Carmack must have written to reach this kind of knowledge... and whether it is open source. It would be a good read for the weekends.
BTW, I think the pure keyword in C++ would be great. I wrote some C++ in school, and even I can tell that const, as applied to functions, could use some retirement. It's nonsense to keep this unmodified, stateless so to speak, but allow global variable assignation, and so on.
- evincarofautumn 14y agoNot entirely nonsense—immutability is helpful even in the absence of referential transparency—but still, a “pure” keyword would be great. Now, what I’d really like is for the type system to be flipped on its head with respect to immutability: make “const” the default and explicitly qualify mutable types with “mutable”. A guy can dream…
- kibwen 14y agoPerhaps you should take a look at Rust.[1] It's a pretty compelling union of functional and procedural paradigms, plus: immutability by default, the ability to annotate functions as pure, pattern matching, option types, good C compatibility, strong support for concurrency, high-level memory management that guarantees memory safety and that doesn't require tedious memory micromanagement (while retaining the option to just GC everything and forget about it), and a lot more. Still alpha software at the moment, though. [1] http://www.rust-lang.org/ http://www.rust-lang.org/
- evincarofautumn 14y agoI’ve looked into it. Seems like a promising language, and it does quite a few things right. Still, I feel a bit uncomfortable endorsing it wholesale while I work on my own linguistic magnum opus. ;)
- zem 14y agoyeah, i'm excited about rust. i'm currently diving into d, and while it is a lot nicer than c++ (and i've barely started discovering all its features), i really miss pattern matching, option types and everything-is-an-expression, which i've gotten used to from other languages. it looks like rust supports all three of those features, which already puts it closer to my sweet spot.
- heretohelp 14y agoconst has legacy reasons for its behavior, some of them relating to DMA and embedded environments.
- el_presidente 14y agoGCC has a 'pure' attribute. I don't know if it's only used for optimization, but it also serves as a kind of comment for whoever looks at the function in the future.
- copx 14y ago"pure" and "const" are GCC function attributes which are supposed to help the optimizer. Confusingly enough "const" demands a higher level of purity than "pure".. I would never use those attributes except - maybe - in the most critical loops and then only with a big "WARNING!!!" sign. Why? GCC does not / cannot enforce the guarantees given by "const" and "pure" yet the optimizer always assumes they are true. I.e. accidentally reduce the purity of a function decorated in this way.. and you might create very hard to find bugs. This is a general problem in C and C++, those languages simply weren't designed to enforce such contracts. C99's "restrict" has the same problem.