6 ms·
Fun to ask these questions of different languages. Here's two I've been using recently: - C++: What they got right? RAII, ability to code "close to the metal"
by api 13y ago
Fun to ask these questions of different languages. Here's two I've been using recently:
- C++:
What they got right? RAII, ability to code "close to the metal" if you want or highly abstractly if you don't, templates for powerful code re-use, and a long-term stable ABI on most platforms. The latter is huge-- it means you can write code in C++ and actually ship it.
What they got wrong? Variations in syntax between headers and code files (e.g. ~Destructor() vs. Destructor::~Destructor()), weird template edge case hell that requires 'typename' and 'template' keyword use in unpredictable places, too much symbol re-use (&, <>, asterisk, etc.) that makes code hard to read and parse in a misguided effort to not break 0.000001% of existing code. Pointers are unsafe since you don't know whether something was allocated on the stack or you should delete it.
What's confusing? A lot, unfortunately. :) Templates are the primary source of this.
- JavaScript:
What they got right? It's functional. Really. It's basically a lite weakly-typed Scheme shoehorned into a Java-like syntax. The language is easy to parse and simple enough that JITS can be made that run it fast. Functions are first-class citizens and you can sling them around like any other variable.
What they got wrong? Numeric types are poorly implemented, making the language unsuitable for "serious algorithm" type stuff. There is no canonical way to define and extend objects, resulting in conflicting styles across projects. There is also no builtin way to do sane async code without the "pyramid of doom" (20-level deep indents). Libraries like async or underscore help, but in a language that wants to be async as bad as JS this should be core. Finally, the fact that it's a functional language shoehorned into looking like Java means there are all kinds of confusing syntactic variations that arise when it's used functionally. function() {} vs x = function() {}; -- note the extra semi.
What's confusing? Type promotion, weird rules around true/false evaluation, the == vs === mess, what 'this' means.
- ExpiredLink 13y ago"I’m convinced that you could design a language about a tenth of the size of C++ (whichever way you measure size) providing roughly what C++ does." B. Stroustrup http://www.stroustrup.com/masterminds_chapter_1.pdf http://www.stroustrup.com/masterminds_chapter_1.pdf
- dbaupp 13y agoD and/or Rust?
- ExpiredLink 13y ago"Within C++, there is a much smaller and cleaner language struggling to get out ... And no, that smaller and cleaner language is not Java or C#. " B. Stroustrup D or Rust? D and Rust can hardly be considered small and clean languages. D is syntactically close to C++. Rust has 4 pointer types ( http://static.rust-lang.org/doc/rust.html#pointer-types http://static.rust-lang.org/doc/rust.html#pointer-types ).
- Fistandantilus 13y agoI would say that they're still smaller than C++, which has syntactical and semantic corners that very few people even know about.
- zxcdw 13y agoThe fact that very few people know about them speaks for them being rare and intuitively not as big of a problem in the real world than people make it seem like.
- gnuvince 13y agoD is syntactically close to C++, but not C++; Walter Bright made some very judicious choices to make parsing unambiguous and fast. Rust has 4 pointer types, three of which you will use regulary. This design decision is in perfect accordance with the goals of the language, offering a language with safety and performance in mind. It takes a while to get used to, but I don't think that makes the language any less clean.
- steveklabnik 13y agoNot just that, but C++ has one pointer type. Oh, and if you're building a big app, you will probably use and have to learn about shared_ptr, uniq_ptr... and then you're right back to Rust with more typing and less guarantees. There are good arguments not to use Rust today, but I think the 'it has four pointers' complaint is a cop-out, personally.
- antimagic 13y agoI was going to argue with you about your comments about Javascript and callback hell, because a while back I figured out a nice, efficient pattern that pretty much removed it as an issue for me. But then I remembered reading somewhere that patterns are a code smell for a problem in a language. So yes, you're absolutely right that callbacks would have benefited from in-language support, especially considering the mono-threaded nature of JS. Interestingly enough, my solution was very similar to the prototype chain of JS, which makes me think that a more generalised prototype chain concept, allowing multiple chains for an object, would have made a much stronger language.
- drieddust 13y agoI have struggled with this aspect of js. Would yoy mind sharing it.
- Fistandantilus 13y ago"[Javascript] is functional. Really." I don't really agree; just because a language has first-class functions and closures, that doesn't make it a functional language. Sure, you can write functional-style code in Javascript, but you can do that in almost any language, many of which don't have first-class functions and closures.
- freyrs3 13y ago> JavaScript: What they got right? It's functional. Really. It's really not, it's a language that encourages unrestricted mutable state which is very not functional.
- lambdasquirrel 13y agoIt's hard to agree or disagree with that. Javascript, by iyself, yes, you're right, but everyone codes with either coffeescript and/or underscore, so it's possible to do most of your work in a functional manner. jquery's selectors can be used in a fairly declarative manner when you do have to manipulate existing DOM elements, so in practice, it's not that bad.
- tmhedberg 13y agoScheme (and FP in general) is much more than just first-class functions. If that's all that is required for a language to be considered functional, then nearly every modern programming language is a functional language, and the term becomes essentially meaningless. First-class functions are nothing special or unique anymore. FP is also about frictionless composition of functions, declarative rather than imperative style, use of expressions instead of statements, and very critically, emphasis on statelessness and immutable data. JavaScript is anything but stateless--it is extremely awkward, if not impossible, to avoid mutation in idiomatic JS code. Imperative statements abound, and everything is a reference, there are really no pure values to be found. Functions can be composed, but the syntax makes it unintuitive and ugly. And though it is probably not a hard requirement for FP, most FP languages at least make an attempt to distinguish pure functions from stateful procedures, e.g. via types in Haskell, or just naming conventions, as with Scheme's `set!`, but JS does not really facilitate this in any way. Functions and lexical closures are undoubtedly some of "the Good Parts" of JavaScript, but these alone are not sufficient for functional programming. JS is fundamentally an imperative, OO language which happens to have a very light dusting of FP flavor on top.
- Locke1689 13y agoScheme (and FP in general) is much more than just first-class functions. If that's all that is required for a language to be considered functional, then nearly every modern programming language is a functional language, and the term becomes essentially meaningless. First-class functions are nothing special or unique anymore. If you'd like to express this simply, I've been trying to get people to explain functional programming as programming where the idiomatic method of computation uses the lambda calculus as a base model. When it comes to mainstream programming languages it's often easy to "see" the lambda calculus or a Turing machine behind the computation.
- rauljara 13y agoIf you grok the lambda calculus, this is indeed a simple explanation. In my experience, most people who don't know what functional programming is also don't understand what lambda calculus is. In that case, all you've done is substituted one unknown bit of vocabulary for another. I've also noticed that when I use unknown vocabulary in my explanations, it sometimes intimidates people away from asking more questions. E.g. "What is <some term I really don't understand>?" "Oh, it's just <another term, that the person you're asking seems to expect you to understand, but you really don't>". So I would avoid the term "lambda calculus" for the uninitiated. I seem to have pretty good luck explaining what a pure function is (no side effects, same input always produces same output, referential transparency[1]) and going from there. [1] Which, in turn, requires its own mini-explanation.
- jfb 13y agoI think what's interesting is looking at the constraints around which a language evolves. A lot of the deep nastiness of C++ is related to C compatibility; but C++ without C (++?) wouldn't have had even the awful tool support that it did; it would never, ever have taken off to the same degree. I'm not a C++ jock -- when I was getting started (1992), the pain/pleasure threshold was very different than it is today.
- silverlake 13y ago> JavaScript: ... It's functional. Really. Functional programming is a style. You can do it in nearly any PL, but some make it easier than others. JS's prototype object system is there for a reason, and it ain't FP.