5 ms·
What does "Procedural" vs "Functional" have to do with this? It's a choice in data type. If by procedural you mean, nonsense, then sure... I agree that a funct
by nixpulvis 7y ago
What does "Procedural" vs "Functional" have to do with this? It's a choice in data type.
If by procedural you mean, nonsense, then sure... I agree that a function named `getchar` returning an `int` is procedural. :P
- chrisseaton 7y ago> If by procedural you mean, nonsense, then sure Why are you being snarky? They clearly mean the issue of modelling partial functions which would normally be done by a side-effect in a procedural language but can’t in a functional language.
- nixpulvis 7y agoNo, they imply that the handling is done by returning a negative number. I'm being snarky, as is my nature, to highlight the madness of a function called `getchar` returning anything but a `char`.
- samatman 7y agoIt's not a great snark given that the C standard considers the signedness of char to be implementation defined, making -1 a valid option, sometimes.
- nixpulvis 7y agoI'm sorry you don't find it great (I still do). Integers are not characters. Integers are numbers like -1337, 0, and 42. Characters are things that compose strings of text. These are not the same kind of thing at all. Just because APIs may be leaky, and some of these APIs are held in very high regard doesn't change that fact.
- samatman 7y agoa char isn't a character, though. you can't add two characters together and get another character. it's a number. getchar() gets a char. not a character.
- nixpulvis 7y agoAll you've convinced me of is that the + operator isn't defined for characters. Which makes sense. Trying to tell me that something called char is really just a byte in disguise (while true in some popular languages) is just irritating and misleading to me.
- astrobe_ 7y agoIn the end, integers, floating point numbers, "text\n", emojis etc. are just sequences of bytes. You choose to acknowledge it and take advantage of it, or you don't.
- nixpulvis 7y agoBy that argument, why even have types... and what makes bytes so special? Perhaps you'd like to work with bitstreams, (or qbitstreams)?
- astrobe_ 7y agoA bit late, but bytes are very often the smallest addressable unit. That's why they are "special". Which answers your second question: "bitstreams" would be terrible because they are not well connected with a hardware reality. Unless you have bitstream-oriented CPU, it is a bad idea for a basic type to go against the hardware. Why even have types... Well, yes, there are languages without type checking where the notion still exists. For instance Forth has no type checking but two types are implied: the "byte" type and the "machine word size" type, maybe three if you count strings.
- chrisseaton 7y ago> the madness of a function called `getchar` returning anything but a `char` It’s effectively returning a Maybe(char).
- nixpulvis 7y agoBut it's not. A `Maybe<char>` has exactly one `None` variant. While an `int` has many, many negative values. Also, just calling it `None` (or similar) makes clear what is meant, while `-1` is some magic value.
- chrisseaton 7y ago> while `-1` is some magic value It's a documented return value. Nothing magic about it.
- eyegor 7y agoWhat they mean to say is: when I was working with a language that enforced pure functions, I had to actually consider purity. It's rare to see a way to enforce purity in procedural languages, whereas most fp langs support it.
- nixpulvis 7y agoAre we talking about even roughly the same concept of functional purity [1]? Nothing is stopping a pure function from representing EOF as -1. Implementing IO in a "pure" way, is however another discussion. [1]: https://en.wikipedia.org/wiki/Pure_function https://en.wikipedia.org/wiki/Pure_function
- eyegor 7y agoMostly, do you know of a single procedural language with a concept of IO monads in its stdlibs?
- mikekchar 7y agoI suspect it was a product of the OP's musing about errors. Side effects are common in programming languages outside of pure functional languages. When you have a pure functional language, what do you do if the type you are returning can't represent an error? You also can't have side effects (for example throw an exception), so it's doubly important that you make sure your return type can encode errors. I suspect that's all they meant. The choice of wording was just unfortunate (especially the use of "procedural" -- what do I do if I can't return values??? ;-) ).
- pwdisswordfish2 7y agoNothing, apart from the fact that languages with type systems designed more carefully than C happen to be functional languages, to one extent or another. (Though by the way: having functions that evaluate to a value when executed is itself a feature that belongs to the functional paradigm, although one so trivial and common that it’s not usually thought as such. But a purely imperative/procedural way of returning values would be via out parameters or global variables.)
- jfdhvdybc 7y agoThe simple answer to this is that these days "functional programming" doesn't just mean the absence of side effects. It means strong type systems, algebraic data types, list comprehensions, etc. It is a distinct cultural stream in the development of programming languages. Of course "functional" has an original narrow meaning, but so do "Republican" and "Democrat". When Rust introduced ADTs they were recognizably a concept from functional programming. It's a place or community of practice, not a purely descriptive adjective.