6 ms·
Admittedly I'm somewhat of a FP fanboy, but I seriously cannot disagree with you more on this. Functional Programming (and Logic Programming) are better than o
by tombert 8y ago
Admittedly I'm somewhat of a FP fanboy, but I seriously cannot disagree with you more on this.
Functional Programming (and Logic Programming) are better than other paradigms because, unlike Java (or C++, or C#...) there is an emphasis on correctness, and the people working on FP compilers (like Haskell and Idris) are utilizing mathematics to do this.
No idea on your opinion on mathematics, but to me Math/Logic reign supreme; the more mathematically-bound your program is, the less likely it is to do something you don't want later.
Compare this to Java. It's 2019, and we're still doing `if (x==null) return null` all over the place (I'm aware that the option type exists but that doesn't really help when it's not enforced and none of my coworkers use it). How about having to create six different files for something that I could have written in 20 lines in Haskell? Or how about the fact that the type system exists to help with optimizations, and due to a lack of support for structured typing, it can only be useful for that.
I realize that I'm picking on Java, but Java is the biggest target when it comes with OOP as the industry understands it. I personally cannot stand having to create fifty files do to something like a database wrapper, and in Java that's effectively the only way to program.
- libria 8y ago> How about having to create six different files Took me a few reads but it's better stated "six different classes". At first I was confused about why you rely on `java.io.File` for business logic. So, if I'm stuck on JVM, what's my FP alternative that compiles and runs comparatively? Clojure? Scala?
- bsder 8y agoClojure. If I'm stuck in JVM-land, Clojure followed by straight, modern Java would be my choices.
- pkolaczk 8y agoScala. Particularly Scala 3. Because it is principled but also very pragmatic.
- hota_mazi 8y agoScala failed because it's the opposite of pragmatic. If you're looking for pragmatic, take a look at Kotlin. As for Scala 3, it's still years away, if it ever comes out. And when it does, there's little reason to think its goals will be different from what Scala 2 was (an academic language) since it's the same team as Scala 2 writing it.
- jhomedall 8y agoIn what way is Scala not pragmatic?
- hota_mazi 8y agoIt's a language that's aimed more at research, producing papers for conferences, and financing the EPFL and its PhD students than at users in the real world. There's absolutely nothing wrong with that, by the way, I love studying all the advanced concepts that Scala has pioneered over the years. But it's also the reason why it's largely in decline and why Kotlin has taken the industrial world by storm: because it is a pragmatic language.
- jhomedall 8y agoI've used Scala in production environments, and we never had any problems with it being too academic. SBT sucks, but that's another issue. Kotlin doesn't have typeclasses (something you get as a side effect of Scala implicits), ADTs, or true pattern matching (along with exhaustivity checks). In combination, all of those allow for expressive, easy-to-read code that, in my experience, tends to have few bugs. Kotlin is a step backwards from that. It's still a significant step up from Java, however. F# is the only other language I've used that I've found comes close. However it lacks typeclasses, and the large Java ecosystem.
- hota_mazi 8y agoA step backward to you is a step forward in pragmatism for the rest of the world. I understand the value of higher kinds and I'm comfortable with Haskell, but it's pretty obvious to me why Kotlin is succeeding where Scala failed. Sometimes, improvements in programming languages are reached by having fewer features, but Scala is a kitchen sink that was always unable to turn down features, just because their implementation would lead to more research papers to submit to conferences. As a result, we ended up with a monster language that contains every single feature even invented under the sun.
- LandR 8y agoYes, clojure
- stickfigure 8y agonone of my coworkers use it This sounds like the root of your problem. If you want to do FP, and none of your coworkers want to do FP, then your problem isn't really the language. If you're in a Java shop, maybe start by evangelizing FP rather than a totally different language/platform? It's possible to do FP in Java, and (IMO) it ends up pretty reasonable. But it's not the default habit for J Random Java Programmer, so they need training.
- tombert 8y agoSure, but as John Carmack has said, if the compiler allows something, it will end up in the codebase once it gets sufficiently large. I work for a brand-name big company (I won't mention it here but I'll tell you if you email me) that hires incredibly talented engineers that are a lot smarter than me. The codebase I work on is around ~20 million lines of Java, and I've seen stuff in there that is so incredibly gross that a compsci professor would write "see me after class" if you submitted it. Example: I once saw a piece of code doing this: do { // doing stuff } while (false) It took me about 10 minutes of digging into the code to realize that the person who wrote this was doing this so that they could add a `break` in there as sort of a makeshift `goto` so they could early-exit and skip all the rest of the stuff in the block. Needless to say, I was horrified. Why is it that incredibly talented engineers are writing awful code like that? It's certainly not incompetence; what almost certainly happened was that there was some kind of time-crunch, and the dev (understandably) felt the need to cheat. This is a direct consequence of the compiler allowing a bad design.
- Const-me 8y agoThat loop is totally fine. I wrote it many times in C#, C and C++, and I saw it many more times in other people’s code. Microsoft DDK sample: https://github.com/Microsoft/Windows-driver-samples/blob/master/avstream/samplemft0/Mft0.cpp https://github.com/Microsoft/Windows-driver-samples/blob/mas... Microsoft MediaFoundation sample: https://github.com/Microsoft/Windows-classic-samples/blob/master/Samples/DX11VideoRenderer/cpp/MediaSink.cpp https://github.com/Microsoft/Windows-classic-samples/blob/ma... OpenSSL: https://github.com/openssl/openssl/blob/master/crypto/sha/sha256.c https://github.com/openssl/openssl/blob/master/crypto/sha/sh... And many others. Just because code looks unfamiliar doesn’t mean it’s something wrong with the code.
- revvx 8y ago> I realize that I'm picking on Java, but Java is the biggest target when it comes with OOP as the industry understands it. I personally cannot stand having to create fifty files do to something like a database wrapper, and in Java that's effectively the only way to program. I had this experience once in a Rails shop. A simple database table mapped to a CRUD API endpoint would take from five to ten files. That amounted to about 500 lines, plus a lot of tests for each class. I never really understood why programming became so verbose. In an ideal world I'd have a declarative API that mapped the table to the API for me automatically. In a realistic timeline I'd just use the traditional Rails approach and be happy. But the people working there preferred to use complicated patterns and a lot of boilerplate before they were needed, even though the project was perpetually late and riddled with bugs. I wish we could give a chance to simpler ways of solving problems.
- andybak 8y agoWe are currently in a swing back in favour of statically typed languages. People seem to have forgotten why we previously had a huge trend towards more expressive, less strict, dynamically typed languages. Maybe we learn something each time the pendulum swings but as someone knee deep in C# at the moment, the quality of the APIs I have to deal with are far below those I was used to in Python (at least in terms of elegance and usability). I'm not sure whether these flaws are inherent or whether it's possible to have one's cake and eat it.
- revvx 8y agoI don't think it has anything to do with dynamic or static typing, but more to do with teams, libraries and program design. I've had terrible experiences with complexity and verbosity in Ruby and Python codebases, which are dynamically typed. On the other hand, I worked with super expressive and simple to work codebases in C# and Haskell. And I had the opposite experience as well in other times. It is absolutely possible to have the cake and eat it in this regard. In fact I'd consider Haskell way more expressive than any dynamic language I ever worked with.
- 8y ago
- yxhuvud 8y agoHaving proper support for option or sum types is an orthogonal question to if it is object oriented or not. Crystal is an OO language that have sum types, for example (and yes, nil is separated from other types, so a method returning a Duck will really do that, and it won't return nil unless the signature would be Duck | Nil).
- pjmlp 8y agoYou could be doing instead ((if (null? x) ;..... ))
- blub 8y agoFunctional programming has no relevance to the correctness of code. You'll notice that it's virtually unheard of to use any FP languages in critical software. Instead they use languages that lend themselves well to code reviews, static and dynamic analysis, model-based design and proofs, etc. Like C, Ada and some domain-specific stuff. The kind of "correctness in the small" offered by Haskel through its type system can be obtain also in languages like C++, Swift and others. With the additional benefit of massive market share, teaching resources, mature tooling and so on.
- tombert 8y ago>You'll notice that it's virtually unheard of to use any FP languages in critical software. Erlang powers around 40% of the world's phone networks; and if it's not mission-critical I'm not entirely sure what is. For that matter, Whatsapp is also written in Erlang and Jane Street does trading applications in OCaml. Without making a judgement on whether or not they should, both Whatsapp and Jane Street create very large apps and have created successful businesses with FP. > Instead they use languages that lend themselves well to code reviews, static and dynamic analysis, model-based design and proofs, etc I can't tell if you're being serious; are you suggesting that Functional Programming doesn't lend itself to proofs? Really? Have you ever heard of Coq or Idris or Agda? They literally have modes to prove the correctness of your code. What about functional programming doesn't lend itself to code reviews? I did F# for a living for two years and we had regular code reviews. I also used the .NET performance profiling tools which worked fine for F#. > The kind of "correctness in the small" offered by Haskel through its type system can be obtain also in languages like C++, Swift and others. Uh, no. Sorry, that's just flatly wrong. Yes, static analysis tools are awesome, but you will never get the same level of compile-time safety from C++ that you will from Haskell or Rust or any number of functional languages. The type systems offer very little information, making it impossible for the compiler to shield anything.
- blub 8y agoTLA+, SPARK, Frama-C, PROMELA, Astree, even plain C or C++ and a heavily safety-oriented process are used when correctness is important more than any of the FP languages you've mentioned. In fact, by mentioning Erlang and Ericsson, you exhausted the only case supporting your point. Maybe if you tried hard, you could come up with a couple more. Now let's do the same exercise for the languages and tools I enumerated and it will take a long time until one runs out of examples. WhatsApp is another perennial example in these discussions. I can accept it although there's nothing critical about a chat app - and once again it's rather an exception instead of the rule. Most chat applications are written in "not FP" programming languages and work just as reliably as WhatsApp. In case it's not yet clear from the above, I believe that only tools which are used heavily in the industry deserve our attention, not obscure languages which haven't been put to the test and one off projects. The oldest trick in the FP argument book is finding some minor FP language to match any requirements put together by critics. So yes, I've heard of Idris and Agda - on HN - because barely anyone else uses them or talks about them. Coq is perhaps the outlier, because it was used to verify CompCert, but then again CompCert itself is used to implement a lot more things. But Coq, Idris, Agda and so on are actually red herrings, because when people praise FP's correctness benefits, they refer to standard languages like Haskell, F# or OCaml for which there is in fact little proof that they have a significant effect on program correctness. Obsessively encoding information in the type system will reduce or eliminate some types of errors, but that's far from proving a program correct and really not that far at all from what's available in other standard, mainstream languages, for less effort, better support and a great ecosystem.
- hota_mazi 8y agoOOP has evolved. If you want to get a clearer idea of where it's at, look at Kotlin instead of a twenty-five year old language.
- tombert 8y agoSure, Scala has some neat features too (though I'm not 100% sold on the language). That said, and I addressed this specifically, when I say "OOP" in the software world, people typically think of Java, C++, or C#, and those are what I'm addressing specifically. I suppose in the most technical sense of the word, you could argue that Erlang is OOP at some level, and Erlang is awesome, so if we want to play with definitions then sure, I'll concede that OOP is good, but until the industry as a whole agrees on these terms, and doesn't treat OOP as a synonym for "Java/C++/C#", I'm still going to say that I hate OOP.