Bjarne Stroustrup Answers C++ Questions
news.codecademy.com
news.codecademy.com
Also check out the first response for a nice explanation and an optimization to eliminate the branch. The author replaced it with a bit twiddling solution to either store the current element or zero if it is less than 128 in a temporary variable and then always add that to the sum.
It's not obviously easy either. You won't know if an arbitrary collection is already sorted unless you check each element.
The middle (median) element in a sorted array has only less elements on the left and greater elements on the right, so the first pass of the quicksort would do nothing and not recurse further.
Or am I missing something?
4 3 2 1 5 9 8 7 6Still, probably faster to incorporate a monotonic check in a quicksort first pass, than run a bubble-sort pass which probably won't help much anyway?
edit: which means it does not need a do nothing first pass and takes mitigating actions only in the worst case.
This blog post literally adds nothing.
> port the compiler to an early 640MB Windows machine.
Probably meaning a 640 kB MS-DOS machine - the first C++ 'cfront' tapes were going out by 1986, if memory serves.
"The most important single aspect of software development is to be clear about what you are trying to build."
"There are no 'cookbook' methods that can replace intelligence, experience and good taste in design and programming."
"Design and programming are human activities; forget that and all is lost."
So true, so important, and so universally applicable.
I would argue, however, that more people have used C++ than have used those pieces of advice...
> If you could go back in time and change one thing about the original implementation of C++, what would it be?
> I don’t have a time machine and I shouldn’t try to second-guess 1983-vintage Bjarne—he knew the conditions at the time better than I do now, and any significant change probably wouldn’t have fitted in the 1MB memory I had to work with, and if it had maybe I wouldn’t have been able to port the compiler to an early 640MB Windows machine.
He created a great language though
--
And agreed on the linking: every snippet on stackoverflow is effectively gpl
Requiring attribution/license change --- Unless you've already hyperlinked every author name, stackoverflow, + the page it came from, AND those links are not nofollow
https://stackoverflow.blog/2009/06/25/attribution-required/
""Stack Exchange Inc; user contributions licensed under cc by-sa 4.0 with attribution required.""
EDIT: see cc by-sa text. It considers itself gpl equivalent
The concern is if Stack Exchange Inc has the right to unilaterally and retroactively relicense the content.
[1] https://meta.stackexchange.com/questions/333615/will-concern...
> All materials displayed or performed on the public Network, including but not limited to text, graphics, logos, tools, photographs, images, illustrations, software or source code, audio and video, and animations (collectively “Network Content”) (other than Network Content posted by individual “Subscriber Content”) are the property of Stack Overflow and/or third parties and are protected by United States and international copyright laws (“Stack Overflow Content”).
https://stackoverflow.com/legal/terms-of-service#licensing
of course, if your answer replicates content from another source that you link to in your answer, that other source still owns the content. so perhaps if you self-publish first and then replicate and link to your original source, you might be able to side-step this and license the original source as you like.
You license the content you create to them:
> any and all content [...] that you provide to the public Network (collectively, “Subscriber Content”) is perpetually and irrevocably licensed to Stack Overflow
You still own the copyright to what you've written.
> [...]
> ""Stack Exchange Inc; user contributions licensed under cc by-sa 4.0 with attribution required.""
You literally said it isn't two sentences later!
So your code must become gpl, or something equivalent
Sorry for not being clearer, you are right to question. May I make that prior post explicit?
[1]: https://stackoverflow.com/questions/tagged/language-design?t... [2]: https://cs.stackexchange.com/questions/tagged/language-desig...
Not even Bjarne is safe from interview hell.
---
What’s your perfect Saturday?
Have a slow breakfast, do a bit of work – maybe writing. Maybe visit the grandchildren. Run a few miles. Eat a good dinner out with friends. Settle in for the evening with a good book.
---
How was the 2019 C++ Standards meeting in Germany?
It was a rather good meeting. The venue was great and we voted out a “Committee Draft” for review by the national standards bodies. There is now a feature freeze.
In February 2020, we’ll have the final vote C++20. It was a lot of work and there were 220 attendees – a new record.
C++ is going to be great!
---
What are some of the C++20 updates that you are especially excited about?
- Modules – to improve code hygiene and significantly speed up compilation.
- Concepts – to simplify generic programming by allowing precise specification of a template’s requirements on its arguments.
- Ranges – to finally be able to write sort(v) rather than sort(v.begin(), v.end()), to get more general sequences, and more flexibility and better error messages through the use of concepts.
- Coroutines – to get simpler and faster generators and pipelines, simplifying asynchronous programming.
- Dates – being able to efficiently and elegantly manipulate calendars; e.g., weekday{August/1/20/2019}==Thursday.
- jthreads and stop tokens – threads that joins on scope exit (doing proper RAII) and a mechanism for terminating them if their result is no longer needed.
These changes – and many smaller ones supporting them – are major in the sense that they will fundamentally change the way we program and think about our designs.
C++20 will be as big an improvement over C++11 as C++11 was over C++98. It will change the way we think about writing our code. I said “C++11 feels like a new language.” I will be able to say the same about C++20.
Our code will become smaller, simpler, run faster, and compile faster.
---
What newer languages or language paradigms are exciting to you?
I don’t easily get excited and the field of languages doesn’t really develop all that fast when you keep an eye on it.
Most changes are incremental and re-emerge repeatedly in different languages with minor differences. I think the word “paradigm” is overused and misused. If it means any more than “my latest bright new idea”, we don’t see a new paradigm every decade. Maybe object-oriented programming, generic programming, functional programming, and machine learning. That took 50+ years.
I tend to look for techniques that can be widely used. Over the last decade or so, my main work has focused on generic programming and compile-time evaluation. Maybe this will feed into a static reflection mechanism for C++ over the next few years. I like the idea of functional-programming-style pattern matching and did a bit of research on that in the previous decade.
In the face of more competition, e. g. python, Rust, Go etc.., what is the future of/for C++?
Many project leaders/creators position themselve "authoritative god" on their project, and finished often disconnected from their community taking arbitrary wrong decisions.
Bjarne has been smarter than that, giving the community (a very diversified community ) the opportunity to drive the language together.
And it worked, C++ survived 40 years, stronger than ever, evolving from a primitive "C with class" to a modern language present in almost every electronic device nowadays.
It might not be "perfect", "pure", but it does not matter. It fucking work... and evolve in the right direction... That's the C++ way.
Briefly, the C++ standard defined three classes of stuff that isn't covered by the standard:
Implementation-defined behavior - "behavior, for a well-formed program construct and correct data, that depends on the implementation and that each implementation documents".
Unspecified behavior - "behavior, for a well-formed program construct and correct data, that depends on the implementation".
Undefined behavior - "behavior for which this document imposes no requirements".
So 'undefined behavior' is stuff that isn't mandated by the standard and also may or may not be an error.
Some UB stuff is bugs (like accessing arrays out of bounds), some isn't bugs but just processor/OS dependent stuff that is out of scope of the C++ standard. (Like what happens when integers overflow.)
In short, the existence of UB is a good thing; having a standard that clearly states what is part of it and what isn't is vastly better than a standard that mandates too much or is too vague.
(And it goes without saying that having no standard at all, like is usual for other programming languages in 2019, is worse in every way.)
The thing is, by the very nature of UB, it could have been (and still could be) patched out in a backwards-compatible way. At the very least, catching UB before the nasal demons get out would allow a bit more confidence in C++ code.
So not only undefined behavior has not hindered the success of C++, it's probably one of the things contributing to its success, in particular its success in developing embedded and safety-critical systems.
If you write a program for which correctness is particularly important (e.g. a safety-critical program), you must ensure, through tests, proofs, magic, etc. that you don't have any incorrect behavior. Which might be undefined, but again the problem is that it's incorrect, not that it's undefined. If you're flying at Mach 2 and an out-of-bounds read or write happens in your flight control software, it doesn't really matter that much whether you get "undefined behavior" (i.e. read or write "random" address), a panic, a log message, a popup window, etc. The safety is compromised by the fact that you did an incorrect operation, not that the operation is undefined.
Now, if you want to write a music player or something like that, it does make sense to use a language like Python, Go, or whatever might give you more guarantees than C++, because realistically you're not going to write a proper test suite for it.