May I ask what is the utility of Haskell? Or rather, in what field it has one? Functional programming as a shortcut is great, but Python has that covered. Even C# LINQ has that covered, for most pragmatic functional programming is about writing domain-specific query languages, as a lot of complicated programming can be reduced to input—massage the data—output. The rest often just library-juggling. As opposed to this pragmatically functional stuff, purely functional programming is largely about avoiding bugs of certain types, but in my experience 95% of bugs come from not of those types, but from misunderstanding requirements or requirements themselves being sloppy and chaotic. Pure functionality is largely about programming like a mathemathician, strictly formal and everything the result of reasoning instead of just cobbling things together by trial and error which tends to characterize most programming, but the kind of bugs this formalist attitude cuts down on is not really the kinds of bugs that actually annoy users. So I wonder what utility you found to Haskell.
I do not have much experience with functional programming, but I’ll try to answer anyway:
There is a huge difference between programming as an academical discipline, and programming as in “what 99% of programmers in private sector do”. The former is like painting portraits that will survive centuries, the latter is like painting walls. Both kinds of “painters” use colors, although the wall painters are usually okay with using only white color and the most experienced of them are really proud to use a paint roller with the great skill that only comes from years of experience. The portait painters usually have extremely low square-meters-per-hour productivity.
Programming as a science is about writing effective and provably correct algorithms, and designing abstract tools to make writing and proving of the algorithms easier. There is often a lot of math involved. Here are some random keywords: Turing completeness, Computational complexity, Formal languages, Lambda calculus...
Programming as a craft is about using existing tools (programming languages and libraries) and solving real-life problems with them. Also about developing practical skills that make cooperation and maintenance of larger projects easier.
So, if programming as a craft is what 99% of programmers do, why do we even need the science? It’s because without the science we wouldn’t have the tools. At some point of history, procedural programming was an academic toy, and all commercial programmers were happy to use GOTO all the time. At some other point, object-oriented programming was an academic toy that didn’t seem to bring any improvement to real-life problems. Today, procedures and objects are our daily bread, at least in Java/C# development, although most “object-oriented” developers don’t really understand Liskov substitution principle and couldn’t solve the circle-ellipse problem properly. I’ve met people who had years of experience in JavaScript, who were surprised to hear that you can use obejcts in JavaScript. But if someone does not understand the nature of objects in JavaScript, they would never be able to create JQuery.
in my experience 95% of bugs come from not of those types, but from misunderstanding requirements or requirements themselves being sloppy and chaotic
Yes, this is because in real life, most people are idiots. Of course when people who are paid for writing requirements can’t do it well, most problems will be related to the requirements. But if you manage to fix this problem (for example, if you would cooperate with smart people, or write the requirements for yourself), then most of the remaining bugs will come from somewhere else.
There is a kind of improvements that comes strictly in a form of limitations. Such as “thou shalt not use GOTO”. Or think about declaring variables and functions as “public” and “private”; all this does is forbidding you to do something what you would be able to do in a different language. And yet somehow these limitations make programming easier. Programs without GOTO commands are on average much easier to read, although there are specific situations where the specific algorithm could have been easier with some GOTO. (Also we have the “break” and “continue” commands to create so-called one-and-half loops that some purists frown upon.) Declaring a variable or method private allows you to change it without having to read the rest of the program. And these limitations work much better when supported by the IDE. You want your IDE to declare an edit-time error when a private variable is used from a different class, because then you have an immediate feedback.
Functional programming, as I understand it (and I am not an expert), seems like two related concepts: First, you can use functions as values. (You could simulate it in Java by various anynomous Runnable classes and adapters, but that would be a lot of boilerplate code, at least before Java 8.) Second, you have immutable objects, and functions without side-effects. The first thing is a syntactic sugar, but the second thing is the limitation that can make programming easier. Yes, you can have immutable objects in Java, but the compiler will not check this property for you. (There is no such thing as telling your standard Java IDE: “this class is supposed to be immutable; if there is some way I didn’t notice that could actually mutate its values, please underline the code using red color”.) So it is like a language that allows you to create your own convention about which variables and methods can be used only within the class that declared them, but does not provide any edit-time support for the “private” keyword.
Checking the immutability of an object in compile time is important, because when you decide you use this trait heavily (analogically to when you decide to use object-oriented programming heavily, as opposed to only having a class or two in an otherwise procedural code), and you make a mistake and one of those classes actually happens to be mutable, the whole concept falls apart. What is the advantage of using almost exclusively immutable objects? It makes multi-threaded development and caching values much easier. If you are going to develop an application that heavily uses multiple processors, or even multiple computers, for doing one computation, you will want to use immutable objects. Otherwise you will have to do a lot of thread-related micromanagement, and most likely you will produce a lot of bugs. On the other hand, if you add a few exceptions from the immutability rule (called monads) to otherwise functional code, you can still write the usual kind of applications. So, functional programming seems superior, because it expands your abilities.
Unfortunately, the more powerful programming concepts require better abstract thinking, and most people, including most professional programmers, are not good at it. They have to be dragged screaming to using new concepts, and even there they will stubbornly try to write the old code using the new syntax. (Just like many people write C++ code with Java syntax and call it “Java programming”; which usually means they treat interfaces as some inferior form of abstract classes, and complain about Java not having multiple inheritance. Also, their methods have hundreds of lines.) And because the worse programmers are more frequent in the job market, it actually makes sense for companies to use inferior technologies. (For example, this is why PHP still exists despite having no advantage over Python.)
Thanks, this is an excellent explanation. Let me add something. You say you need OOP in JavaScript or else you cannot make jQuery. But what is jQuery needed for? Largely to fix what sucks with JavaScript. Why does JavaScript suck? Partially browser issues but largely because it is used far beyond its intended purposes. Software companies were ignoring all the time that HTML is for documents meant for reading, and based on the puny HTML forms that were originally just meant to do stuff like post a comment or register your address for purchasing from a webshop, built whole CRM and accounting and whatnot systems. They treated HTML and JavaScript as a General Client for doing any client-server app.There is even an online version of PhotoShop and similar crazy things. Meanwhile, everybody else who used the proper tools for the job and used desktop software for things where it makes sense and so on, so basically who did not try to force a tool into something it was not meant to did not have the whole problem to begin with. Of course in a sense it meant a competitive disadvantage but that does not always matter so much.
My point is simply that it is not really just stupidity. It is not needing to go out on the edge. It is about not needing to build a query language into one that was totally not meant to because not needing to massage an XHTML document into a GUI because they use documents for documents and GUIs for GUIs.
But you are right, programming science is great. Just… don’t expect to use it if you work for people who don’t need to do almost-impossible things :)
JavaScript is probably the most underestimated programming language ever. I am not going into technical details here, but here are the keywords: prototypes, first-class functions. It is a language designed to be embedded in an application; and web browsers are just one of the possibilities—ActionScript in Flash programming is almost the same language; you can use JavaScript in your own applications; you can develop websites in JavaScript.
What people perceive as “JavaScript sucks” almost always means “web browsers suck”. If you would write web browser scripts in Java or C++, you would get into exactly the same kind of problems if each browser (and each version of the browser) would provide you different objects, with different method and variable names, or even with the same methods and variables which would do different things. (Actually, this is how Microsoft tried to destroy Java once, by providing a widely used but slightly different version, to make Java programs behave differently in different environments.)
I’m a professional programmer and I know Haskell, but I’ve only ever written one real Haskell program (an AI for double-move chess). Nevertheless I recommend it. All I can tell you is that if you master it—I mean really master it, not learn to write Python in Haskell—then your Python programming will reach a new level as well. You will be able to solve problems that once seemed intractable, which you’d persuade your product manager to scope out.
It used to be that you could get this effect by learning Lisp, but I don’t think that works anymore; too many of Lisp’s good ideas have since been taken up by more ordinary languages.
I’m taking a class in Haskell, and I’d really like to know this too. Haskell is annoying. It’s billed as “not verbose”, but it’s so terse that reading other people’s code and learning from it is difficult. (Note: the person I’m on a project with likes one-letter variable names, so that’s a bit of a confounder.)
That sounds like math! :) I suck at math precisely due to lack of verbosity, as I am more used to reading essays than equations my brain is used to reading fast and filtering out large chunks of what I read. This shallowness works very well for reviewing philosophy, but in math just missing one letter leads to not understanding it.
This is, weirdly, how I know that much of programming is applied math it does not feel so to me. In programming, it is a taboo to call some variable a Greek letter instead of calling it UnitPriceIncludingTax. This leads to me reading code easy and reading math badly.
I did not go very far in haskell, I was in a exploratory phase, the lack of libraries for haskell, make go to java, having being my only experienced with progaming the creation of map and mods with WarCraft 3 graphical Interface I took online courses and books on Python becouse was easy, and then Hakell just because is from another paradigm and it helped me understand more deeply recursion, types and many basic stuff than was hidden in Python( being a high level language).
I finally settle in Java because for its support, libraries and compatibility with Android, I’m not triying to “know it all” of computer science or programing not for lack of curiosity but for opportunity cost, I’m learning what I need to learn, and dedicate a fraction of my focus to learn seemingly unrelated thing to take care of the unknown unknowns.
Java as platform or as language? The platform is great but why use the language when the platform also offers Clojure or Scala? While I complained elsewhere about the lack of verbosity makes math hard to read for me, Java is the opposite, the boilerplate verbosity pisses me off i.e. that after reading SomeWhateverFactory someWhatEverFactory = new SomeWhateverFactory() after processing that line mentally I have learned nothing about what a program actually does, it convey precisely zero information about the actual human utility it delivers. Writing this bullshit may be made easier by tools, but reading is not.
May I ask what is the utility of Haskell? Or rather, in what field it has one? Functional programming as a shortcut is great, but Python has that covered. Even C# LINQ has that covered, for most pragmatic functional programming is about writing domain-specific query languages, as a lot of complicated programming can be reduced to input—massage the data—output. The rest often just library-juggling. As opposed to this pragmatically functional stuff, purely functional programming is largely about avoiding bugs of certain types, but in my experience 95% of bugs come from not of those types, but from misunderstanding requirements or requirements themselves being sloppy and chaotic. Pure functionality is largely about programming like a mathemathician, strictly formal and everything the result of reasoning instead of just cobbling things together by trial and error which tends to characterize most programming, but the kind of bugs this formalist attitude cuts down on is not really the kinds of bugs that actually annoy users. So I wonder what utility you found to Haskell.
I do not have much experience with functional programming, but I’ll try to answer anyway:
There is a huge difference between programming as an academical discipline, and programming as in “what 99% of programmers in private sector do”. The former is like painting portraits that will survive centuries, the latter is like painting walls. Both kinds of “painters” use colors, although the wall painters are usually okay with using only white color and the most experienced of them are really proud to use a paint roller with the great skill that only comes from years of experience. The portait painters usually have extremely low square-meters-per-hour productivity.
Programming as a science is about writing effective and provably correct algorithms, and designing abstract tools to make writing and proving of the algorithms easier. There is often a lot of math involved. Here are some random keywords: Turing completeness, Computational complexity, Formal languages, Lambda calculus...
Programming as a craft is about using existing tools (programming languages and libraries) and solving real-life problems with them. Also about developing practical skills that make cooperation and maintenance of larger projects easier.
So, if programming as a craft is what 99% of programmers do, why do we even need the science? It’s because without the science we wouldn’t have the tools. At some point of history, procedural programming was an academic toy, and all commercial programmers were happy to use GOTO all the time. At some other point, object-oriented programming was an academic toy that didn’t seem to bring any improvement to real-life problems. Today, procedures and objects are our daily bread, at least in Java/C# development, although most “object-oriented” developers don’t really understand Liskov substitution principle and couldn’t solve the circle-ellipse problem properly. I’ve met people who had years of experience in JavaScript, who were surprised to hear that you can use obejcts in JavaScript. But if someone does not understand the nature of objects in JavaScript, they would never be able to create JQuery.
Yes, this is because in real life, most people are idiots. Of course when people who are paid for writing requirements can’t do it well, most problems will be related to the requirements. But if you manage to fix this problem (for example, if you would cooperate with smart people, or write the requirements for yourself), then most of the remaining bugs will come from somewhere else.
There is a kind of improvements that comes strictly in a form of limitations. Such as “thou shalt not use GOTO”. Or think about declaring variables and functions as “public” and “private”; all this does is forbidding you to do something what you would be able to do in a different language. And yet somehow these limitations make programming easier. Programs without GOTO commands are on average much easier to read, although there are specific situations where the specific algorithm could have been easier with some GOTO. (Also we have the “break” and “continue” commands to create so-called one-and-half loops that some purists frown upon.) Declaring a variable or method private allows you to change it without having to read the rest of the program. And these limitations work much better when supported by the IDE. You want your IDE to declare an edit-time error when a private variable is used from a different class, because then you have an immediate feedback.
Functional programming, as I understand it (and I am not an expert), seems like two related concepts: First, you can use functions as values. (You could simulate it in Java by various anynomous Runnable classes and adapters, but that would be a lot of boilerplate code, at least before Java 8.) Second, you have immutable objects, and functions without side-effects. The first thing is a syntactic sugar, but the second thing is the limitation that can make programming easier. Yes, you can have immutable objects in Java, but the compiler will not check this property for you. (There is no such thing as telling your standard Java IDE: “this class is supposed to be immutable; if there is some way I didn’t notice that could actually mutate its values, please underline the code using red color”.) So it is like a language that allows you to create your own convention about which variables and methods can be used only within the class that declared them, but does not provide any edit-time support for the “private” keyword.
Checking the immutability of an object in compile time is important, because when you decide you use this trait heavily (analogically to when you decide to use object-oriented programming heavily, as opposed to only having a class or two in an otherwise procedural code), and you make a mistake and one of those classes actually happens to be mutable, the whole concept falls apart. What is the advantage of using almost exclusively immutable objects? It makes multi-threaded development and caching values much easier. If you are going to develop an application that heavily uses multiple processors, or even multiple computers, for doing one computation, you will want to use immutable objects. Otherwise you will have to do a lot of thread-related micromanagement, and most likely you will produce a lot of bugs. On the other hand, if you add a few exceptions from the immutability rule (called monads) to otherwise functional code, you can still write the usual kind of applications. So, functional programming seems superior, because it expands your abilities.
Unfortunately, the more powerful programming concepts require better abstract thinking, and most people, including most professional programmers, are not good at it. They have to be dragged screaming to using new concepts, and even there they will stubbornly try to write the old code using the new syntax. (Just like many people write C++ code with Java syntax and call it “Java programming”; which usually means they treat interfaces as some inferior form of abstract classes, and complain about Java not having multiple inheritance. Also, their methods have hundreds of lines.) And because the worse programmers are more frequent in the job market, it actually makes sense for companies to use inferior technologies. (For example, this is why PHP still exists despite having no advantage over Python.)
Thanks, this is an excellent explanation. Let me add something. You say you need OOP in JavaScript or else you cannot make jQuery. But what is jQuery needed for? Largely to fix what sucks with JavaScript. Why does JavaScript suck? Partially browser issues but largely because it is used far beyond its intended purposes. Software companies were ignoring all the time that HTML is for documents meant for reading, and based on the puny HTML forms that were originally just meant to do stuff like post a comment or register your address for purchasing from a webshop, built whole CRM and accounting and whatnot systems. They treated HTML and JavaScript as a General Client for doing any client-server app.There is even an online version of PhotoShop and similar crazy things. Meanwhile, everybody else who used the proper tools for the job and used desktop software for things where it makes sense and so on, so basically who did not try to force a tool into something it was not meant to did not have the whole problem to begin with. Of course in a sense it meant a competitive disadvantage but that does not always matter so much.
My point is simply that it is not really just stupidity. It is not needing to go out on the edge. It is about not needing to build a query language into one that was totally not meant to because not needing to massage an XHTML document into a GUI because they use documents for documents and GUIs for GUIs.
But you are right, programming science is great. Just… don’t expect to use it if you work for people who don’t need to do almost-impossible things :)
JavaScript is probably the most underestimated programming language ever. I am not going into technical details here, but here are the keywords: prototypes, first-class functions. It is a language designed to be embedded in an application; and web browsers are just one of the possibilities—ActionScript in Flash programming is almost the same language; you can use JavaScript in your own applications; you can develop websites in JavaScript.
What people perceive as “JavaScript sucks” almost always means “web browsers suck”. If you would write web browser scripts in Java or C++, you would get into exactly the same kind of problems if each browser (and each version of the browser) would provide you different objects, with different method and variable names, or even with the same methods and variables which would do different things. (Actually, this is how Microsoft tried to destroy Java once, by providing a widely used but slightly different version, to make Java programs behave differently in different environments.)
I’m a professional programmer and I know Haskell, but I’ve only ever written one real Haskell program (an AI for double-move chess). Nevertheless I recommend it. All I can tell you is that if you master it—I mean really master it, not learn to write Python in Haskell—then your Python programming will reach a new level as well. You will be able to solve problems that once seemed intractable, which you’d persuade your product manager to scope out.
It used to be that you could get this effect by learning Lisp, but I don’t think that works anymore; too many of Lisp’s good ideas have since been taken up by more ordinary languages.
I’m taking a class in Haskell, and I’d really like to know this too. Haskell is annoying. It’s billed as “not verbose”, but it’s so terse that reading other people’s code and learning from it is difficult. (Note: the person I’m on a project with likes one-letter variable names, so that’s a bit of a confounder.)
That sounds like math! :) I suck at math precisely due to lack of verbosity, as I am more used to reading essays than equations my brain is used to reading fast and filtering out large chunks of what I read. This shallowness works very well for reviewing philosophy, but in math just missing one letter leads to not understanding it.
This is, weirdly, how I know that much of programming is applied math it does not feel so to me. In programming, it is a taboo to call some variable a Greek letter instead of calling it UnitPriceIncludingTax. This leads to me reading code easy and reading math badly.
I did not go very far in haskell, I was in a exploratory phase, the lack of libraries for haskell, make go to java, having being my only experienced with progaming the creation of map and mods with WarCraft 3 graphical Interface I took online courses and books on Python becouse was easy, and then Hakell just because is from another paradigm and it helped me understand more deeply recursion, types and many basic stuff than was hidden in Python( being a high level language).
I finally settle in Java because for its support, libraries and compatibility with Android, I’m not triying to “know it all” of computer science or programing not for lack of curiosity but for opportunity cost, I’m learning what I need to learn, and dedicate a fraction of my focus to learn seemingly unrelated thing to take care of the unknown unknowns.
Java as platform or as language? The platform is great but why use the language when the platform also offers Clojure or Scala? While I complained elsewhere about the lack of verbosity makes math hard to read for me, Java is the opposite, the boilerplate verbosity pisses me off i.e. that after reading SomeWhateverFactory someWhatEverFactory = new SomeWhateverFactory() after processing that line mentally I have learned nothing about what a program actually does, it convey precisely zero information about the actual human utility it delivers. Writing this bullshit may be made easier by tools, but reading is not.
I’m working with the java languague right now, but it’s true I’m considered using scala after I finished my current project.