I've noticed hackers/self taught prefer functional programming styles and CS degree holders prefer the more common style.
Functional Programming in C++ (2013)
41–50 of 64 posts
Re: Functional Programming in C++ (2013)
#42Earlier quoted context omitted.
It really irks me that the std algorithms library seems to have been designed without any consideration for usability given how much I would love to rely heavily on the generic algorithms it contains. For example consider the simple task of testing to see if an element exists in a container: if (std::find(container.begin(), container.end(), element) != container.end()) My fingers are now cramping and my eyes are cros…
Well the containers that have fast lookup (set, map and their unordered_ and multi_ counterparts), all have efficient .find() member functions. The general philosophy of the idealised STL is not to provide you with anything you can compose efficiently yourself. A 3-4 line template will will give you a terse boolean contains() method, but it won't give you any big-O guarantees, and having such a thing would encourage…
Re: Functional Programming in C++ (2013)
#43I just can't get behind all of this. Sure, its great to be able to reason clearly because you can see your whole state, but its exhausting always carrying your context around like a hobo with a huge backpack full of junk. Am I mistaken?
The monad type-class operations carry the context around for you. You can just write in imperative-seeming do-notation. The difficult part is trying to combine monads.
The 'world' is carried on the back of one parameter, right? So if I want to run a function taking two parameters in a particular 'world', which parameter is the Monad? If both of them are, what if they disagree which world is used?
Perhaps I haven't reached the fabled epiphany of monads, but they seem to be just implicit state attached to a single value, and only a single value. I'm not sure what this implicit stuff is better than a system where you are explicitly passing the 'world' that each function needs.
Why is
roll(dieSides: Random) -> int
Clearer than
roll(random: Random, int dieSides) -> int
I get the passing of a world out of a function with a single value
getNumber() -> IO
or using the extra implicit state to represent other possible values, like
Maybe
but, using it to carry around state? That seems to me to be unnecessarily implicit.
What am I missing?
Re: Functional Programming in C++ (2013)
#44Earlier quoted context omitted.
Well the containers that have fast lookup (set, map and their unordered_ and multi_ counterparts), all have efficient .find() member functions. The general philosophy of the idealised STL is not to provide you with anything you can compose efficiently yourself. A 3-4 line template will will give you a terse boolean contains() method, but it won't give you any big-O guarantees, and having such a thing would encourage…
Holy cow, thank you so much for the lectures!
Re: Functional Programming in C++ (2013)
#45Earlier quoted context omitted.
I thought functional programming[1] was associated with ivory tower CS researchers/enthusiasts? I guess it's been turned on its head for some reason. [1] At least the Haskell/ML kind.
The underlying concept will surface once you've had a chance to debug program states and that you realize you can't keep track of all program states. I had no idea about functional programming but soon realized that I was going for the same thing when trying my best to not keep instance variables in my objects.
Re: Functional Programming in C++ (2013)
#46I just can't get behind all of this. Sure, its great to be able to reason clearly because you can see your whole state, but its exhausting always carrying your context around like a hobo with a huge backpack full of junk. Am I mistaken?
Exhausting is being in this situation: object Foo { var x: Int = 0 def bar(y: Int) = x + y } And trying to figure out what bar will return at any given point.
Re: Functional Programming in C++ (2013)
#47I just can't get behind all of this. Sure, its great to be able to reason clearly because you can see your whole state, but its exhausting always carrying your context around like a hobo with a huge backpack full of junk. Am I mistaken?
Re: Functional Programming in C++ (2013)
#48Earlier quoted context omitted.
Here's the relationship. How can you guarantee your low-level code is correct? Here's one way. You have a language like Idris create a DSL that targets the machine you want. You can model what the set of correct programs in your domain look like, and then produce correct code. That's why functional programming in general, and dependent-type programming in particular, is useful for low-level problem domains.
That's not a problem. The application in question was a redesign of an MPI FORTRAN implementation that can produce the same outputs to within FPRE. To verify the low-level code, we just run in double-precision and make sure it matches to 1 part in 10e-9 so across 200+ daily conformance tests. Production mode runs in single-precision with 64-bit Fixed Point accumulation. And that's also been demonstrated to have numer…
Re: Functional Programming in C++ (2013)
#49This is from 2013, and the original title is "Functional Programming in C++". Moreover, Carmack never makes a statement that functional programming is the future anywhere in this article. The closest he says is "Formal systems and automated reasoning about software will be increasingly important in the future," which is a markedly different sentiment. That said, the problem of not understanding possible code states d…
Thanks re the title. Submitters: the HN guidelines explicitly ask you not to rewrite titles like this, unless they are misleading or linkbait. https://news.ycombinator.com/newsguidelines.html (Submitted title was 'John Carmack: Why functional programming is the future'.)
Re: Functional Programming in C++ (2013)
#50Earlier quoted context omitted.
Exhausting is being in this situation: object Foo { var x: Int = 0 def bar(y: Int) = x + y } And trying to figure out what bar will return at any given point.
Are you somehow not in control of how x is being changed? You seem to have said that literally any statefulness is "exhausting".