126 points · by luu · 10y ago · 121 comments
Hmm? Go has almost none of these features.
The parent also mentions: binary literals, raw string literals, uniform Initialization, standard algorithms like map, filter and any, and parameter packing. All of which Go doesn't have.
Plus, Go range loops are constrained to built-in types (slices, channels, etc.), unlike C++/Python where you can implement begin()/end() or the iterator protocol respectively and get it for any type.
So, from 10 things mentioned, whereas C++ and Python share ALL of them, Go only has 2 of them and sort of has one more (the range-for).
I'd stick with: "almost none of these features".
And it also doesn't have tuples: you can't store tuples in variables or larger data structures, pass them as function arguments, etc.
Go doesn't have local type inference
For loops on ranges are limited to Go built-in types, you can't create your own iterators.
So yes, almost none of these features are available in Go.
I do wish it had support for slice unpacking like it does for return values. The assignment from returns or ranges is one of the things I really ejoy.
Edit: [1] I'll clarify that I define that as an immutable, indexable data structure that you can unpack in to multiple assignments.
Come on, now. D is 15 years old, C# 16.
Python is more than 25 years old.
There's also nothing Pythonic about lambdas. Come on, lisp is ancient and it has lambdas.
This article essentially says C++ got stuff that has been around for decades, and Python has stuff that vaguely resembles them, so C++ is learning from Python.
No type inference: http://ideone.com/fmm92M, http://ideone.com/HzyM2E
Type inference: http://ideone.com/0Gv8fV, http://ideone.com/r9nHUF
One tiny thing that would be cool to see built into C++ would be an equivalent to the Python range function. The boost version is nice for now, though.
Finally, I also see this as a nice compliment to Python and the power that it offers as a language.
I'm curious, what motivated your switch from embedded to web?
Language features are nice to have, but I never really missed any specific feature. Almost every sort of syntactic simplification I wanted to achieve, I could do so with a function, class or a template.
These are symptoms of language issues.
We can't say that (yet) about Swift and Rust. In 3-5 years I think this is going to be a very different conversation, though.
In my mind, C++'s flexibility is both its greatest benefit and its greatest danger. You can do almost anything, and there are so many ways to do it. I agree this is a "problem" that's likely not going to be fixed. You can ask your fellow developers to read Scott Meyer's Effective (Modern) C++, you can go to meetups, listen to the wisdom of the steering committee, etc. but at the end of the day it really boils down to the fact that your team needs to be committed to being resilient and responsible. That's true in any language, but much more so in C++.
Not sure about Swift, I haven't really been paying attention in that space.
Writing proper code in C++ requires, as you say, "your team needs to be committed to being resilient and responsible", which just doesn't happen on my little piece of the world.
So using it in personal projects, yeah. At work, not really.
Even then, in C++ you still need to expose a C interface, so it feels at least on even footing with Rust. But of course, I am biased...
C++ doesn't seem to have a guiding philosophy besides "be a Swiss army knife backwards compatible with C." That's OK but I would argue it prevents C++ from every being "Pythonic."
There is the one that appreciates C++'s abstraction capabilities with ability to go low level when needed. Cares about writing safe code and sees C copy-paste compatibility as a compromise required to get C++ adopted by the industry. Those developers usually appreciate languages like Ada, Modula-3 and Haskell, and would rather kill the pre-processor.
Then there is the culture that somehow had to move from a C compiler into a C++ one, constrain themselves to the C subset of C++ while ignoring the standard library because bloat and write exploit sensitive code as always did in C.
Many on the second culture tend to do micro-benchmark driven development. Each code line is questioned how much fast and memory it takes by gut feeling, without any regard from profiler tools or actual needs from the application users.
The (implied) corollary is that compile time cost, mental cost and social cost of language features do not matter.
As long as there is at least one person on the planet who really understands the ins and outs of a language feature, that is sufficient proof of the language being simple enough. There is no need for anyone to understand the entire language.
I don't know how much of that is due to C++'s historical baggage and how much is due to a greater concern for usability and elegance on the Rust side, with consequent discretion when adding new features. But I don't think it's entirely the former.
So you end up paying for things you didn't intend to use, but used anyways because of some small detail.
Sometimes I feel like the only way to write good C++ is to keep looking at the disassembler output...
C++ is my dayjob.
This got me thinking, what would one call an idiomatic C++ style (which I suppose is part of what the core guidelines are trying to push)? Cppthonic? Bjarnic? Python is 'Pythonic,' I usually hear idiomatic Ruby described as the 'Ruby Way.' Is idiomatic Rust 'Rustic'?
auto triple = std::make_tuple(5, 6, 7);
std::cout << std::get<0>(triple);
Ugh. And don't even get me started on "myList.push_back(5)" . "push" usually means "add to the front"; why not use "append" ?std::get<0>(triple)
It really doesn't look great. It looks like the template syntax using the <>. I'm sure I would get used to it if I were using it every day but from an aesthetic sense it doesn't win me over.
Here is me translating as literally as I could a bit of nontrivial code (which I originally learned from R's C code):
http://inversethought.com/hg/medcouple/file/default/jmedcoup...
http://inversethought.com/hg/medcouple/file/default/medcoupl...
I'm really happy how almost every Python statement has a nearly equivalent C++ statement. The only one I had trouble with was list comprehensions, but they can be very nearly translated with C++ stdlib algorithms and a few lambdas (kind of looks more like map and filter than a list comprehension, though).
The best part is that the C++ code runs as fast and sometimes faster than the original C code I grabbed this from! (The translation path was C -> Python -> C++.)
However, what idea has C++ not accepted? It seems for it to be a "new" language, it should at least say "no" to something.
auto x = new int[64];
harder to read than int* x = malloc(sizeof(int)*64);
?If so, I think it's just a matter of habituation and imprinting. Whatever you learned first is easier and everything else is hard.
((void(*)())exec)();
or template <typename T>
struct value_type {
typedef typename T::value_type type;
};
template <typename T>
struct value_type<T*> {
typedef T type;
};
Six of one, half a dozen of the other.Drop the semi-colons, convert "dict of int to string' to map<int, std:string> etc.
It would be ok if it only did a subset of C++ at first.
Built-in to the language would be nice, but C++ is always extremely spartan with its standard library functionality. Thus:
https://gitlab.com/higan/higan/blob/master/nall/range.hpp
37 lines (without the boilerplate header stuff) and you have:
for(int x : range(20)) ...; //iterate from 0 ... 19
for(int y : rrange(myvector)) ...; //iterate from myvector.size()-1 ... 0
Also supports xrange's offset/stride arguments (it's pretty much exactly Python's xrange object in C++.) And you can add support to do ranges over any class anywhere, eg range(myvector) will pull the length from myvector.size() for you with a simple overloaded function.Timing tests in extremely critical loops (like convolution kernels eating 100% CPU usage) shows no discernable performance impact at -O2 and above over the traditional C++-style for(int x = 0; x < size; x++) style.
Windows APIs have always supported using forward slashes, using "C:\\path\\to\\file" is just an ugly mess.
Yes, yes, the formal definition of type inference as supported by languages like Haskell is not fully supported by C++, or Go, or C#, etc. But that's not the definition of it that anyone else in the comments here seem to be using, so can we drop it?
You seem to be knowledgeable about type theory. Is there a formalized term for the subset of type inference that C++11 supports? If so, can you just assume that others are using that term? Not that the discussion isn't interesting, but you're coming off as needlessly contrarian.
"if (a)", "for (...)" -> "if a", "for ..."
"if ((a > b) && (c > d))" -> "if a > b and c > d" (yes, I know C++ supports "and" if you wish)
Or how about accepting a new-line as a ; at the end of a statement (ie: optional ; at line end)
I also love nested tuple unpacking: "for i, (key, value) in enumerate(dict.items())"
And have to use backslashes or something for multiline statements? Ugh.