6 ms·
C and C++ are not the same language.
- swolchok 17y ago"But C++ often hits a sweet-spot between languages where high-level abstractions are available with the raw power of C when you need it." He then goes on to say he uses Ruby and not Python. Is Ruby missing nice C integration? Python is oft-touted as the sweet spot here, although I have to confess I haven't done a whole lot of Python/C or Python/C++ integration.
- noamsml 17y agoMost languages with C integration can be integrated into C++ quite reasonably, if not optimally.
- stcredzero 17y agoIn Smalltalk/X, you can just inline C in a method. There are ways of doing that for Ruby as well. It's also fairly easy in Smalltalk generally to do callouts to a DLL, or to implement your own "primitive" method in C.
- wheels 17y agoI just like Ruby more. You can connect both Python and Ruby to C APIs, and I've done so in the past from Ruby. C++ integration is usually moderately more annoying since once you start moving beyond ordinal types cross-language communication becomes hairier. C ends up being the lingua franca between programming environments a lot of the time.
- kingkongrevenge 17y agoIt is just as easy to extend any of the scripting languages with C++ as it is with C. SWIG and other systems like XS have built-in support for C++. Even if that weren't true, you can just make your interface header files 'extern "C"' yet enjoy the superior power of C++ in your implementation files. There is no reason to favor C over C++ when extending a scripting language.
- wheels 17y agoRight. By "I extended them with C", I meant, "I extended them with a C interface"; the implementation was in C++.
- stonemetal 17y agoI think he meant that if you were going to pick one language that was both high level and perform well it would be C++. To do better you would have to, as you suggest, split it in to two languages.
- davidw 17y agoTcl is actually the sweet spot in terms of its C API - you can do pretty much anything you can do in the language itself, and more. And it's all very nice code to work with.
- kingkongrevenge 17y agoI've rewritten Python programs in C++ and got close to the same line count, yet hugely better resource usage. You can't do that with C. With C++ you often don't need to reach for a heavy and slow language. You'll do just as well for maybe a 2X development speed penalty.
- dmix 17y agoThanks for clarifying this; as someone who didn't take the usual CS in university route this often confused me. I've added C to my list of languages to learn after Python, mostly from recommendation on HN and I want to get into machine learning.
- mahmud 17y agofor M-L, brush up on your basic* math, and jack up on the probability and statistics. an eetsy beetsy volume on numerical computing, just enough to understand machine representation of numbers and enough to understand errors (and their propagation!) should be enough. don't hesitate to read engineering texts. the first few chapters of various DSP texts should give you an idea of what to look for ("oh, so it's loops over real-valued vectors! cool!") but if you read EE texts, feel free to ignore complex variables (unless your earlier math text was good enough to introduce them as vectors of two components :-) An interactive language, preferably Octave/Matlab should come handy. None of this will make sense right now, but hints are supposed by like that ;-) -- [Edit: * basic as in naive set theory, ability to reconstruct and prove properties of Real numbers using Dedekin-cuts, basic proof techniques, sequences, series, limits, functions as sets, basic trigonometric functions, the derivative and the anti-derivative, and most importantly understanding the various type of integrals, specially the Reimann. touching "real analysis" from the standard and Non-Standard angles should be enough. All this could be done in 2-3 months with the right texts. This is the minimal you will need to understand things; the basic properties of the logarithms should come handy, specially converting between logarithms of different bases (you will be working on bases 10 and 2, while the natural number is more prominent in engineering than CS.) ]
- plinkplonk 17y agoI would add Linear Algebra to mahmud's (great) list of mathematical "stuff to learn". A lot of ML needs Linear Algebra . (e.g Neural Networks, SVMs .. )
- deleted 17y ago[deleted]
- plinkplonk 17y agoI am (a little) surprised at how well the C example reads vs the C++ version. I would have thought that an OO design pattern (here, Observer) is where C++ syntax would be a better fit.
- stcredzero 17y agoOne of my professors, Carter Bays saw some C++ and said, "So, is C++ just the new COBOL?" (Dude wrote the world's first implementation of merge sort. It's saved on paper punch-tape! And he has stuff in one of the 1st 3 Knuth books.)
- grandalf 17y agoI think if there were an extension to the STL for unicode, string handling and simple sockets few people would even need ruby :)
- dryicerx 17y agoLook in to Boost http://www.boost.org/doc/libs http://www.boost.org/doc/libs
- old-gregg 17y agoLearning to think in C++ is much closer to learning to think in Java This is where I stopped reading. He mentioned "modern C++" many times, which actually should mean that C++ moved away from rigid pseudo-OO GoF-inspired structures, Java-style. Java itself is a simplified snapshot of much older C++ (circa mid-90s) but equipped with garbage collection. Memory management is an interesting, actually, since C++ doesn't rely on heap allocation nearly as much as Java does. Well, long story short: no, "thinking in Java" is a terrible, terrible way of describing how C++ programming should be done. Thinking in _modern_ C++ is supposed to feel like you're trying to bolt on Haskell's type system on top of C.
- wheels 17y agoI'm not sure that's descriptive so much as an ideal. In practice (mentioned this in the blog comments as well) I've found that the C++ world is somewhat divided between what I'll label the Boost and Qt camps. Boost, as kind of a conceptual child of the STL, has extended more along the axis of exploring what's possible with the language, at times at the cost of pragmatism. The Qt camp, on the other hand, tends to hide most of the heavy use of generic programming in private classes and exposes more simplified APIs, typically with minimal use of templates in public APIs. I personally, as a former long-time KDE developer, fall firmly in the Qt camp and it shows in the way that I write C++. It's also the style that's been preferred in the two companies where I've been employed as a C++ developer. Which is modern is mostly a semantic issue. I'd wager that while advanced template programming is more cutting-edge, it's also not in fact the way that very much C++ today is actually written, which is the definition of modern I was working with.
- timr 17y agoThe book that defines the genre ("Modern C++ Design", by Andrei Alexandrescu), is all about template metaprogramming. I'd say that's the end of the semantic debate. Maybe you could say that I'm in a "camp", but the C++ style that Qt uses is based on the outdated notion that compilers can't keep up with the "modern" features of C++. That style is antiquated.
- 17y ago
- dimitar 17y agoA quick question about c++ in std::cout << "Whoopee." << std::endl; is std::endl putting a newline char after "Whoopee. "? Anyway in the C example it could have been written puts("Whoopee."); instead of printf("Whoopee. \n"); puts() places a \n after the char * it accepts as an argument. I'm sorry for the triviality here :)
- stonemetal 17y agostd::endl will insert a new line, but it also flushes the buffer. So use'\n' when you need a new line and don't want to flush the output buffer.
- deleted 17y ago[deleted]
- DarkShikari 17y agoWhile I don't agree with everything the guy says, this is a huge pet peeve of mine: if someone says "C/C++" all the time, it is likely that they are skilled at neither, because anyone who has done significant programming in both knows quite well that the two are quite different in practice.
- dryicerx 17y agoThe two indeed totally different, but in lot of real world applications, the two are used together, and they are very complementary. For examples, lot of straight C wrapped in Classes, and accessed in a very C++ way. It's appropriate to say C/C++ for these.
- arghnoname 17y agoIt looks to me in the C version, he only frees the first listener. The C++ version also provides the listeners as a set. The C version doesn't mind if you add the same listener multiple times, so to be apples to apples you'd use a vector, but the code wouldn't change otherwise, so no problem there.
- wheels 17y ago- That's an array of pointers; the listeners themselves aren't malloced - The set / list difference is noted just below the code samples