86 points · by adamnemecek · 10y ago · 124 comments
Well, I am dismayed that one may consider prioritising selfishness and immediate interest as rational and prioritising global thinking as emotional, and not the opposite. And that is supposed to serve as an anchor to the following points. Well...
Now at 30 minutes and the subject of the talk was barely tackled. I am not sure I have the strength to inflict myself the remaining hour.
People will say "Oh just don't use that feature" but that's not how this works. If something is there it is used. In reference to C, I don't think I know of a single feature or release that had major changes in how I wrote C. Maybe C99 and allowing me to declare in a for loop.
I've been using C++ for class this semester and the only thing I like is reference types. Makes pointers much more concise. Other then that it can all go in the bin. In order to keep my C++ project clean I've needed to avoid a huge set of features and keep it in a data-oriented design.
The fact that a language is terrible for newcomers is a real problem, and a newcomer is a very good judge of that even if they aren't a very good judge of other aspects.
Especially loathsome are those people who teach, say, undergraduates majoring in physics some C++ as a way to introduce them to programming. You might think that someone who manages to deal with the math needed to do physics would be able to absorb C++, and often you'd think wrong; one physics undergrad told an experienced programmer after trying to understand what the fuck cout<<x actually does, "your head is full of garbage!", by which he meant that the amount of completely arbitrary rules that you need to memorize was not something that dealing with math and science prepared him for.
From the above I conclude that people who have a semester's worth of experience in C++ might not be C++ experts but they certainly know enough to burn the instructor who chose C++ in the first place at the stake.
It may sound strange, but I find assembly to be an appropriate language to learn programming. Not only your focus will be on what you are doing rather than on the language itself, you will get a feeling of what is really going on, and you will quickly appreciate - and fully understand - the the reason why C is useful and that it is a good, well designed programming language. (In the same way, with enough experience using C, one comes to appreciate C++.)
I'm not sure where that conversation would go. It prints to stdout. Would the student say the same thing about printf("%d", x)? How far down the rabbit hole did he want to go?
Stream insertion syntax os pretty bad, though, I'll agree with that. Especially when you want to print floating point.
You can always do fprintf instead of that; i almost never do C++ streams for io - there is always a way to avoid them.
The majority of them surely were able to get shit done in C++ at the end of the semester.
Bravo.
My problem is not with what I think you are attributing to me but rather other issues with the language and tool chain. There seems to me very little that can be done in C++ that can't be done cleaner in C.
It's evident that most people who use a language aren't going to have time to spend years becoming a master at it. They are going to join a team and say "So to do my assigned task I need to do X, what features let me to X the cleanest" and this is how I've taken on learning C++.
Sadly, no features that are new have yielded themselves to any problem I've seen. I haven't encountered it.
Your solution to rebut my argument is that "you need to be at least 10 years into the language to know anything kid!" yet you provide no rebuttal.
Please do provide an argument not an insult at my age the next time you'd like to raise a disagreement with my ideas.
C++ isn't a great choice for many purposes, but for some purposes it is the go-to language - and for good reasons, not just because of inertia as some like to suggest.
As with all forms of craftsmanship, you need to choose the right tool for what you're trying to accomplish.
It can be complicated, for sure. But there is a certain plesantness that comes with letting the compiler do a lot of work for you. It can almost be like the switch to python - just let the compiler figure stuff out.
This results in a lot less duplicate code, etc. The cost is some pretty bad syntax and compile time, though.
Try to keep an open mind
Speaking from a very strong Java background after Jigsaw I think Java will outdo the generics capabilities present in C++ in every way. Java 9 is bringing some crazy features to the mix. From what I understand they are getting rid of the boxing to object from generics to keep types static through lists and other generic elements. That's amazing and something C++ still does as templates are basically massively duplicated code in your binary while the JVM will get this for free at runtime.
Rust is also just out of left field as they are doing amazing things with their "cost-free abstraction"
If I say:
int i;
I don't expect that to create an integer. I expect that to reserve memory in the program's space for an integer.In the same way I don't expect this to call malloc:
int *i;
I just expect that to hold the space in the program data where and int pointer can be stored.Furthermore I don't expect this to run any code (just as the other two).
string s;
I don't expect that to construct anything, that's just a place for me to put data. This way, we know not to use data before it's initialized.In C++:
int i;
if (i > 10) printf("Greater then 10\n");
Is that going to always work how we expect it?How about:
string s;
if (s.length() > 10) printf("Len is greater then 10\n");
That is going to always work how we expect it since it was constructed.This is fundamentally different then uninitialized integers or primitives so I dislike it's use.
I strongly dislike the use of this term but it in my mind is an "Anti-pattern" as it promotes two separate ways of thinking about variables that are fundamentally completely different.
Info taken from:
http://www.cplusplus.com/reference/string/string/string/ http://www.cplusplus.com/forum/general/67249/
Now I'm no expert in education but this knowledge has taken me years to learn through my life and I don't think I'd have been able to do it if I didn't LOVE computers and programming.
I don't know how someone would think that this is good behavior because of it's inconsistencies between two outwardly similar cases.
It depends. Oh I hate that word.
When I see int i; without context I don't know anything about where memory is allocated.
It can either be the following. 1) Stack allocated 2) Heap allocated 3) Is in the read only data segment.
Just starting with a int, it can be any of the above three, two that reserve the memory on the heap/stack and another that is only a read only part of memory. The heap is the only place where I would need to call malloc/free.
Though for most common libraries when I see string s; They mostly
have a pointer null terminated string in memory, and the primitive data types residing as the member's of string.RAII helps in the situation where instead of having to do tedious code such as.
String s; allocate_string(&s);
// do something with string. free_string(&s);
It can all be done via a standard convention of calling the deconstructor or constructor to initialise and free itself.
For the sake of syntactic consistency, one could argue that C++ should mandate "()" as a suffix to declarations to invoke the default constructor. However, what good is an allocated object that's _not_ constructed? For many classes, of course, the default constructor is trivial, but for others it isn't. The purpose of the constructor is to provide invariants that the code can rely on--it isn't obvious to me what common use case you could consider for an object that's allocated on the stack but not constructed, and it seems like it's asking for trouble.
Also, since C++ inherits C's syntax and semantics for fundamental types, "int i;" must be legal. So we cannot abolish the form.
I've had some good/bad experiences with garbage collectors. They do help improve productivity and ROI within the enterprise space where memory isn't too much of of issue. Then when memory does become a issue within smaller memory footprint environments they can be a real pain in the ass.
I also don't like default constructors see my other post as to why I think they are not reliable behavior to the programmer if they don't have experience in the language.
Again I didn't lie when I said "I am using C in C++" as I am using C in C++.
When someone claims to know C++, especially in a recruitment context, I tend to challenge that, since it's really hard to actually believe these days. Some people claim to know C++, but basically just write everything as if it was C.
The reality of C++ is you know what is needed for the problem you need to solve. As people mostly work in the same (broad) areas for their day to day work it is unlikely you need to know outside of that scope regularly. At least not in my personal experience.
Also I strongly believe nobody truly understands C++ streams :)
I can count:
* language basics (variables, structural statements, functions, error handling, preprocessor, how compilation works)
* OOP
* functional programming (which is not that complicated at all in C++)
* generic programming
* advanced generic programming and metaprogramming
* the C standard library
* the C++ standard library basics (containers, algorithms, smart pointers, cout << "foo")
* more advanced c++ standard library (maths stuff, threading(?), chrono, advanced streams (not needed))
I think most C++ programmers have a reasonable command of all of these except the metaprogramming and advanced standard library.
> I think most C++ programmers have a reasonable command of all of these
These gave me a bit of a chuckle. It's true only if you've never done proper functional programming using a genuinely functional language.
It's true that you can now pass lambdas around as first-class values easily, store and manipulate them as you might in a functional language, and that's a fantastic convenience.
But that's not what functional programming is. None of the idioms you'd use in Clojure or Haskell are wise to use (yet) in C++ (although Niebler's Range library will make a big step in the right direction... in C++20, where it's currently slated for specification).
If you try to do real functional programming in C++, you'll end up with a very inefficient program that pales to writing an algorithm with a more procedural or OO idiom.
And, in my experience interacting with lots of C++ developers, most do not know what actual functional programming is all about.
C++ OOP is an endless tire fire. I now have 7 years experience writing C++ "OOP" on the job and I still run into surprises when I try to do things that are easy in other languages but unnecessarily hard in C++. Plenty of examples in the C++ FQA[1].
[1] http://yosefk.com/c++fqa/inheritance-mother.html#fqa-23.5
- 'C with objects'.
- 'Everything is a template'.
- 'Embedded C++' (its a real standard, google it).
- functional.
- 'modern'.
(thats not a complete list either).
Each one of those is technically the same language, but they're all using a different subset of features and are almost unrecognisable from the rest.
Regardless of what your preference is, if you claim to know C++ you need to at least know some of its basic features, such as references, streams, templates, STL, etc. (features that have been around for a long time).
And if you claim expertise, to at least be familiar with basic features from the new standards.
The point being that the way you structure your software in each of those styles is very, very different.
They're all idiomatic C++.... just different idioms.
In fact, thinking about it, thats what it is...
C++ is a multi-idiom language.
Do you believe anyone knows Perl, Python, Ruby, Java, C#, Ada, Haskell, OCaml, VB.NET, F#, ... across all language versions, the whole standard library, and most used third party libraries?
One always need to focus on a specific domain.
I don't miss the days in the late 90's, early 2000, writing portable C code across multiple compilers from each OS vendor, across all major UNIX flavours and Windows.
Many that think to master C, actually master C in compiler X targeting OS Y.
Nothing wrong with that; that's not uncommon in embedded systems development.
How do you handle types which need to free memory without destructors? Manually loop over the vector and free stuff every time one goes out of scope? That doesn't seem safer to me.
Separate libraries, without "macro hell".
>>How do you handle types which need to free memory without destructors? Manually loop over the vector and free stuff every time one goes out of scope? That doesn't seem safer to me.
Providing both heap and stack based allocation. E.g. allocating a vector in the stack would require no explicit de-allocation (example: https://github.com/faragon/libsrt). For heap allocation, you would need to call some sometype_free(&a) function, obviously (there is no RAII in C).
i find '__attribute__((cleanup (fn)))' fascinating in C, need to try it in some production code though.
You're library does look nice for what it does, and may have to look into it for some projects (I do have some C projects). Thanks!
http://antirez.com/picol/picol.c.txt
I have been programming in C++ for over 20 years and my version is bigger :-( Its nice not having to malloc/free but the moment I turned the structs to classes I was battling the bloat.I still enjoy programming in C++ but there is a lot of truth in the criticism that programs written in C are simpler.
BTW, Salvatore Sanfilippo (antirez) is a very sharp programmer, able to write programs without redundancy and look easy (which is very difficult to achieve).
The complicated features are all there to support simple library use. On a day-to-day basis, the complicated features are hidden behind a library, and are rarely seen. When you need them to write the library, they are available.
From the paper, "In other words, the correction backfired – conservatives who received a correction telling them that Iraq did not have WMD were more likely to believe that Iraq had WMD than those in the control condition." (https://www.dartmouth.edu/~nyhan/nyhan-reifler.pdf)
I don't think that connection flows. Rather, I see this: when you take people who have developed political opinions, and act in a way that suggests insult to their world-view, some will react with defiance/sabotage.
The study identifies the pre-existing political leanings of the subjects. Hence, background work has been done to understand a subject's political persuasion, and the subject knows they have been profiled for this.
Then they isolate an issue which some subjects will know to be contentious across liberal/conservative lines, and present the subject with a position. This act (focusing on a vulnerable issue and then preventing evidence that indicates a clear conclusion) alienates the project from the subject, and sets them up to be from a rival worldview. Some subjects, particularly the more politically-aware subjects, will be speculating on the purpose of the study. Then the study asks the subject to - essentially - calculate one plus one one on the issue, towards a conclusion that supports the rival worldview.
The people running these studies will be identified by the participants as members of the intelligentsia. That will have a bearing on subject behavior, and will further encourage defiance in some subjects. In my scan, I didn't see signs of effort made to disguise or water down the focus of the study.
To me, data-oriented design is more interesting: https://www.youtube.com/watch?v=rX0ItVEVjHc