5 ms·
Lambda functions and closures added to C++
- timr 19y ago'Bout time. The need to declare functor objects out-of-line to use the STL algorithms is a huge contributor to code clutter in C++. The addition of inheriting constructors is also a good thing -- I wish I could have back some of the hours I've spent re-writing default constructors for deep class hierarchies.
- cheponis 19y agoDoes anybody use C++ anymore? I use Python and, when doing embedded programming, C (and maybe a pinch of assembly). I'm playing with Arc. I suppose people who write Microsoft apps may still write C++ but most of them have moved to C#.
- cheponis 19y agoWould the person who down-modded me please drop me email to yc@culver.net and explain, in detail, WHY they did this? Presumably, the "in-crowd" who can downmod is telling me that, somehow, my question should NOT be on hacker news. Or something. I'm terribly perplexed. Thank you for your response (if, indeed, you are man enough to respond!)
- reitzensteinm 19y agoI didn't downmod you, but I imagine someone had a problem with the question "Does anybody use C++ anymore?". Around here, probably not that many, but there is both a mountain of legacy code, and a good many domains where it's still appropriate (game development being a big one). And, I guess, even more domains where it's not still appropriate, but where it's still used anyway. :)
- deleted 19y ago[deleted]
- cheponis 19y agoThanks - very much. It is an honest question - if this is a "community", wouldn't you think community members would give me the benefit of the doubt? I have never seen C++ used in my entire career. I'm MIT 6-3A '76 - maybe I'm sheltered in only hanging out with excellent programmers. (aside: the gutless wonders who downvoted my original question did not respond to me directly at yc@culver.net - I suppose those folks are having their teenage fun trying to destroy this community? I have a proposal: whenever any of the "anointed " members of this community downmod anybody, they should be <b>required</b> to provide to the original poster a) their EMAIL ADDRESS so that the poster could respond, and b) their REASON for their action. In addition, I believe that NOBODY should be allowed more downmodding than upmodding - that is, you have to have "upmod points" before you're allowed to downmod - even if you are a Chosen One in the Secret Handshake Society of the YC Cult.)
- trevelyan 19y agoI use C++. Garbage collection is nice, but slow. The language is not suitable for web development, or for GUI development, but it's great for backend enterprise software/libraries that need to be fast and stable and compile across most architectures out there.
- kingkongrevenge 19y ago> The language is not suitable for web development, or for GUI development WTF? Are you aware of the ridiculous number of examples in both?
- trevelyan 19y agoIf you want to do web development or develop a GUI it's easier and faster to work with another language.
- Erf 19y agoThe video game industry is built on C++.
- qwph 19y agoI can vouch for that too, and I think it'll probably be another 4 or 5 years before any other language starts to make significant inroads into game code. I've worked with people in games who simply don't know any other languages. (You can be a perfectly solid C++ programmer without needing to know anything about, say, Ruby or Scheme, but in my opinion, the more you learn about programming in general, the better programmer you will be.)
- tjr 19y agoA good number of avionics software teams are moving from Ada to C and/or C++.
- aggieben 19y agoEmbedded programmers only code in C because they haven't yet discovered C++ (seriously...embedded programming is like living in the 70s). C++ will be all the rage in embedded circles in the 2020 decade.
- aggieben 19y agook, ok, vendors are at fault too.
- uuilly 19y agoC++ is like French. There are lots of idiosychrasies. Bad syntax leads to an inexplicable reaction (from the complier or Frenchman.) For the first few years you'll sound like a buffoon. But once you get the hang of it, it rolls off the tongue. And once you master the slang, you can say things REALLY fast and very few will understand you. I for one welcome this awkward new grammar and its unforgiving compiler errors. Vive Le C++0x!
- pmjordan 19y agoI don't know, a lot of the stuff they are doing in C++0x seems to be of the "throw more syntax at the problem" kind. This is probably one of the better changes (along with the "auto" type inference and a bunch of library stuff) but I can't help but think they're at a bit of a lost cause. If I was to try and "save" C++, I'd probably start from scratch on the template system. Really though, then I'd just end up with a idiosyncratic though type-safe implementation of Lisp macros. Don't get me wrong: I've invested so much time in learning C++ and perfecting my skills in it that it makes me wish that I wouldn't be saying this, but every time I have to touch C++ I get "that sinking feeling". (languages I'm spending more time with these days: various Lisp dialects including Clojure; Ruby; Java/C# if I have to) Oh, and live.com doesn't seem to work properly on Opera. Nice.
- DanielBMarkham 19y agoLambda functions and closures in C++. E-gads man! Wasn't the language complex enough already! I have to say: I love it. C++ has always been my favorite language that I don't program in. It's like kung-fu for programmers. You can attack any problem. But most times we don't need kung-fu. There's nothing like "getting in the zone" with a good C++ program. It's a thing of beauty. And if you're doing stuff that you have to use the tool, like writing drivers, low-level stuff, doing some "break the rules" programming, it's the best there is. I wrote a shell extender for windows many years ago in C++. I got to change the desktop and file system to work the way I wanted it to. Very neat stuff. The sad fact is that most of the time you can make more money writing something with a much higher level language. And you can make it faster and adapt to the market faster. So C++ is a tougher language to use for startups, in my opinion (although it is still my favorite) Can you imagine the trouble you can get into with macros, lambda functions, and unsafe pointers? How about throwing i some operator overloading? It's like a playground for nuclear weapons.
- mynameishere 19y agoC++ is a pita and it's no surprise that it's actually the highest compensated language to work in, at least here: http://www.indeed.com/salary?q1=lisp&l1=&q2=c%2B%2B&l2=&q3=java&l3=&q4=c%23&l4=&q5=python&l5=&q6=ruby&l6=&q7=smalltalk&l7=&q8=php&l8=&q9=cobol&l9=&q10=perl&l10=&q11=haskell&l11= http://www.indeed.com/salary?q1=lisp&l1=&q2=c%2B%2B&... I suppose the reason is that it can only realistically justify its existence at the bleeding edge (eg, with graphic engines, drivers, etc) where the work is inherently difficult as well.
- PieSquared 19y agoWhoa. Is this a good thing... or a really bad one? Not sure. C++ is complicated enough. Then again, CL is pretty complicated too, yet it's what I would qualify as a beautiful language. I personally feel that C++ is a language that doesn't truly belong anywhere - it isn't pure, clean, and low-level, like C, and it isn't completely high-level. Somehow, I don't think that you can easily 'mix' these two. I'm mildly surprised that they haven't added an optional GC yet - I seem to remember reading somewhere that even Bjarne Stourstrop advocated one. Maybe, instead of making "C++0x", they should just make D an ISO standard... From what I've seen, D is basically C++ cleaned up, and every time I look at it, I want to use it instead even more. Check it out if you haven't already. And it deals flawlessly with legacy C++ and C code, too, so there's really not many reasons to avoid it. Oh, and C++ templates are just ugly. I'm reminded of them whenever I see Java generics too, and let's just say those aren't too nice on the eyes either. Maybe they should add programmatic macros too. And a pinch of Perl's default variables!
- xirium 19y agoC++0x ? This must be an April Fool. Edit: No, the truth is stranger than fiction. Gads!
- msg 19y agoC++ here reminds me of Perl, the postmodern language. There are tradeoffs between legibility and power, but never for the sake of safety or artificial consistency. "How does Perl [C++] put the focus onto the creativity of the programmer? Very simple. Perl [C++] is humble. It doesn't try to tell the programmer how to program. It lets the programmer decide what rules today, and what sucks. It doesn't have any theoretical axes to grind. And where it has theoretical axes, it doesn't grind them. Perl [C++] doesn't have any agenda at all, other than to be maximally useful to the maximal number of people. ... Many modern computer languages aspire to be minimalistic. They either succeed in being minimalistic, in which case they're relatively useless, or they don't succeed in being truly minimalistic, in which case you can actually solve real problems with them. A number of languages give lip service to the idea of minimalism, but merely sweep the complexity of the problem under the carpet of the programmer. C is a minimalistic language, but only if you don't count all the libraries that are necessary to use it usefully. C++ is obviously not trying to be minimalistic. Unix is considered by some to be a minimalistic operating system, but the fact of the matter is that if you think of Unix as a programming language, it's far richer than even Perl. Perl is, by and large, a digested and simplified version of Unix. Perl is the Cliff Notes of Unix." http://www.wall.org/~larry/pm.html http://www.wall.org/~larry/pm.html
- icky 19y ago> C++ here reminds me of Perl I agree with you at least that far! ;)
- mleonhard 19y agoPerl needs to go back to 1995 and stay out of my century. It's good to let computers do what computers are good at: repetitive, boring tasks. That's why modern languages detect typos and report them to the user. Perl accepts most typos as valid and makes the programmer do the boring work of analyzing the syntax for correctness. I'm bitter about wasting 30 minutes tracking down a bug because perl accepted 'if(!$string_generator1-() || !$string_generator2->()) {...}' as valid syntax. This kind of thing happens to me very often when writing Perl programs. I think that C++ and Perl are very different. Perhaps their most important similarity is that they're both older languages. At least C++ is making progress, while Perl seems to be embracing its backwardness.
- BrandonM 19y agoWithout proper garbage collection, aren't closures just another memory leak headache?
- pg 19y agoThey should just use the closed form solution.
- huhtenberg 19y agofor_each( w.begin(), w.end(), []( const Widget& w ) { cout << w << " "; } ); It's lovely to know that this is possible, but if anyone who ever writes a production code like this needs to be shot on a spot. Some of the Brainfuck programs are easier to read than this ... and, yes, I have been using C++ as a primary development language for over 10 years.