Wrong order 5 ways : First, there are five ways to pass these in the wrong order, because there are 3! Wrong order 5 ways : As in a , we again have five ways to pass these in the wrong order, all of which compile but only the first is correct:. Wrong value 2 ways : We could pass a first and last that are not a valid range in two ways:. Invalid value 2 ways : And finally, either of first or last could actually be an invalidated iterator e.
So just grouping parameters using a struct eliminates some errors. But really using the type system is even better…. How do we know? But, unlike our helper structs in a , we now get additional safety because the types can express constructor preconditions that move some of those mistakes such as hi,lo misordering to constructors of class abstractions that can then preserve them as invariants [4] — so the mistake can still be made but in fewer places, to where we construct or modify the abstracted object e.
Consider using a class instead. Hiding data members is good dependency management because it limits the code that can depend on the details of the data and is responsible for maintaining the correct relationship among the data members. Consider this code:. But is b always better than c , in other examples?
They are complementary, neither is a substitute for the other. And this is why we want contracts on functions preconditions, postconditions even though we already have types, and why we also want contracts on types invariants. Dos Reis, J. Garcia, J. Lakos, A. Meredith, N. Myers, and B. Stroustrup and H. Sutter eds. How many ways could a caller of each function get the arguments wrong, but that would silently compile without error?
Name as many different ways as you can. In each case, how many of the possible kinds of mistakes for each function can the approach prevent? Consider these three examples, where each shows expressing a boolean condition either as a function precondition or as an encapsulated invariant inside a new type:.
So are preconditions, but that in one important way makes them fundamentally different. What is that? And why would having language support benefit us even more for writing preconditions more than for the other two?
A precondition IS-AN assertion in every way described in GotW 97, with the special addition that whereas a general assertion is always checked where it is written, a precondition is written on the function and conceptually checked at every call site.
In less-ideal implementations, including if we write it as a library today, the precondition check might be in the function body; see Question 2. The above would be roughly equivalent to writing the test before the call at every call site instead.
The language requires the number and types of arguments to match the parameter list. Here, calc must be called with two arguments. The only counterexample I can think of is pathological: void f There are three possible kinds of implied boolean preconditions. All three are present in this example. Each object must meet the invariants of its type. The subexpression x[0] calls x.
If we were to write this all out, the full precondition would be something like this — and note that the order is important! Question: Is globalData! Think about it for a moment before continuing…. For one second I believed he is gonna unveil something "native is coming for wp" right there Oh well, I keep dreaming :. Hi C9, many thanks for this.
I will try and give it a hug every now and and then although it as a habit of biting me. Using code every day myself to solve problems however, there is a subject that this talk completely sidesteps: correctness and knowledge. The other part is knowledge, knowing all about caches and cachelines and prefetching etc is crucial to getting that last drop of speed out of a box. However it takes time to master these concepts and that takes away time from mastering business concepts like finance of math and may actually lead to people that think the world consists solely of registers and cachelines.
Thinking you've mastered these concepts can lead to very nasty bugs that can leave you stumped for weeks, if you notice them. So now to solve an actual problem you need to put a geek and a suit together, that does not always work out too well.
In data centers and mobile devices, Herb is very right, and I am enlightened. You don't get memory leaks if you don't manually manage memory. And there is rarely a need to do that unless you are doing systems programming or writing the standard library yourself.
In the managed world, that would be equated with writing the JIT compiler yourself. And as Benjamin said, there is virtually no need to manage memory manually.
Libraries are for that. And Benjamin C isn't fast enough. Benjamin, hmm.. I always have to remind myself that a flaw in a technology might be fixed since the last time I looked. This stems from a while back indeed of a service a programmer wrote that we just coulnd't get fixed. That one took a while.. When we moved to C all that nonsense went away and we were flying. All that I think is really obselete and should be fixed. Or is it already, then I will have a hard look again.
And, as Parker states, how much of the perf advantage do you keep when you use automated memory management? C is much faster. If you quickly generate and compile a model and then run it, that matters. It doesn't interest me much as long as they are comparable. You are right about compile times. But I'm okay with waiting a bit longer to compile what is, from my perspective and for my purposes, a far superior language.
I'll say one more thing about the performance issue. On top of that, I do have some understanding of how the internals of the facilities provided by the standard library for automatically managing memory work. And I don't see any reason why performance would increase if I managed memory myself. That's a fair enough argument. MS now wants to come back to the party they left and stole the booze from! In this context, Herb's speech is not just a sales pitch.
For me, all of those messages were very important to hear - besides, Herb had to create some free stuff to promote his show so this fits that bill without giving any other of his secret sauce away lol. Lets be reasonable about this. So let's not make this blog all about language wars. Lets make it about letting MS know they should stop trying to pick winners in language wars and just support people in using what they like - there should be room for all.
I hope that is the lesson MS has learned and that appears to be what MS is saying. Compile times? I think you're forgetting that we devs are creating product for users who don't really care what was the time this app was compiled within. All they want is functionality and performance. As simple as that. It also doesn't plan to start using std::thread anytime soon.
So it's kind of annoying. Even for most high-performance applications, in practice, a relatively little share of the codebase is responsible for the actual performance. If you need write a highly efficient application, in C , you can write the majority of the code in high quality, and resort to low-quality, high-performance code in the few critical sections.
Really, both languages have their places. Even in the high-performance world. Charles, Since when, expressing one's opinion even though negative is a trolling? One have to have right and freedom to do it. Dave you have absolutely no idea what you're talking about. You must remember that C is nothing else but java, with the difference that it came out of Microsoft and not from Sun.
C as a language by now is a LOT more than Java. First off, you can use unsafe context in C , which will remove the performance overhead from array-range checks, enables you to use limited- pointers, and —if used correctly- removes most overhead from automatic memory management. If you seriously thought C is just like Java, you should read a bit after how it is way different by now, and how much more it will improve in C 5.
One is free to express themselves here - that's always been the case. It must be done in a respectful manner. It's all we ask. His only purpose here is to non-consructively bash Microsoft. Read his profile and you'll see that clearly. On this thread, he non-sensically states that "w8 is going down the crapper", something he cannot possibly have knowledge about. Hence, Troll. He also speaks of being "force-fed" Microsoft products, as if he doesn't have a choice. When you code you should not be wasting time defining a copy constructor or assignment operator private just so you don't burn your butt accidentally for example.
A language with such kinda bizarre gotchas is a badly designed one and drains energy away from developers. Get rid of the useless language traps and make it at least intellisense-able and refactor-able FGS. Perhaps we need a language D that has the native perf edge while without the juvenile language goofs. The problem is quite simple: given a Chinese-English dictionary file Big5 format , the application should load its content in an appropriate data structure. The dictionary contains a list of entries one per line , each entry consists of the chinese word, the pronounciation and the translation.
Comments starting with the pound sign should be ignored. We want our application to: - execute as fast as possible - consume as little memory private bytes as possible. If you agree to play with me, you are welcome to write a C or with any other managed language version and to compare it with the native version.
Process Explorer will tell us a lot about memory consumption and I think the Visual Studio instrumentation features can be useful to see how long it takes to execute the applications. Larry Ray: What would you suggest, that copying be disabled by default? I'd rather not waste time defining a copy constructor when all of my class' members already know how to copy themselves. I agree. Having native code does not exclude a productive and consistent language.
Stuff like forward declarations or header files IMHO don't belong in a modern language, a compiler should be able to figure that stuff out on it's own. Surely we should be able to have the speed of a compiled native language without all that nonsense? Is that what D is about? The remark about compile times was actually very valid in my case because I wrote a program that built models from a DSL. A user would change something, see the result, change something etc. Then these compile times definitely matter, a pause would let users loose their train of thought.
For most people this is not a issue tho I agree. Glen : I didn't mean to say it's just a sales pitch. I was one of them.
Technically they didn't say "we were wrong " but they should. Pride and denial is in the way as usual. The info was there and clear even back then. So just another business move. It's quite clear. They just say they have aka lies so ppl will buy their product and then they go ahead and makes the same mistakes all over again with a twist.
Charles: So you still haven't looked up the definition of trolling? Why, it's just one google search away, sigh.. You complain about how i express myself but you do not offer up any suggestions or explanations of what erks you. You take the time to complain but not to explain what specifically erks you.
Now how is that really useful to me? If you want me to consider changing my how i express myself then instead of whining about it you can use that time to instead explain what erks you.
It's called constructive -criticism. You and i have different views of what is respectful, it's cultural differences. Not everyone thinks like an american you know Benjamin: "something he cannot possibly have knowledge about. How do you know i do not have this info? Who's trolling now? A business just can't switch like that, it costs more money then to stick with what they have.
Use google to learn more about this. Assumption: Your love to ms is making you blind to their faults. Any good physiologist would say that is most likely be a bad thing. I tell it how i see it and what i see is ms doing a bad job and treating it's user base like garbage and only sucks up to them, even lies, when ms needs their money. I find c to be a nice little interesting language, I like reflection and delegates, I hate garbage collection, lake of near machine options a.
LordKain: "Comparing a few lines of code is meaningless, we should at least compare simple programs as we do not design and write native and managed code the same way" We also design and write code in different ways when we go for performance and when we go for code quality.
Also, writing a simple program will be barely comparable to writing a robust application. Sorry but I don't have that much time for this.
I'm fine with comparing the effectiveness of a simple custom implemented data structure, or file IO, or other light functions, but not a whole program. Way too many hidden aspects that can be optimized there. I'm not familiar at all with the Big5 format neither.
If we compare the effectiveness of the data structure and file IO, we can pretty much deduce from that how the application would perform, written well optimized.
I only said you often CAN achieve high performance with C in the few places you really need it. This is so funny!! I can't help but agree with this statement of Mr Crush: "Yes we can always hope but experience with microsoft tells me they can't learn from their mistakes.
Where is it?. ACG: That interview is fake. Pointing out examples of that to anyone who is as "passionate" as yourself, is, by definition, usually a waste of time, as passionate people usually have to see it for themselves to believe it. He has forgotten more than I ever knew. It can be easier to write good than write what you mean without inflaming good people, but do try as hard for both! Infact, I am struggling not to be a hypocrite here right now!
Charles: you are doing a brave effort of putting lipsick on pigs! I can't believe VS. Stuff like this makes me feel pretty much suckered every time it happens. That's how it looks. These are features other compilers already have, or will have, way way sooner than when Microsoft will now deliver them. Which is when now? If they come at all, they will be very inconveniently timed compared to other vendors and at additional expense beyond that for v.
Not exactly leadership there! This makes a mockery of the renaissance and Microsoft. It invites a cynical perspective that that is exactly what Microsoft plans and wants to happen? So how did Microsoft fail us again in this regard?
It's not about resources, you have the money to pay for those. It's about Will in absense of a resources excuse, surely? I don't appear to be alone in this point of view. But I've yet to assess that topic completely! Your thoughts on all of this, please. I was really optimistic when these videos started appearing on C9. I mean that blog post rather discourages buying the new VS.
This is no longer the case and will continue to no longer be the case. Everybody can talk. It's what you do that is important.
You aren't doing much. I plan to do that indefinitely. The second one, which is larger and still much more experimental and long-term, is the metaclasses work described in my paper P and my CppCon session that you can find on YouTube.
Remember the maxim that people usually overestimate what we can do in two years, and underestimate what we can achieve in 10 years.
Learn everything you need to know about saving time and delivering higher quality software and applications with test automation. Join a community of over , senior developers. View an example. You need to Register an InfoQ account or Login or login to post comments. But there's so much more behind being registered. Your message is awaiting moderation. Thank you for participating in the discussion. Like Print Bookmarks.
Oct 23, 10 min read by Sergio De Simone. Little things, especially ones focused on simplification, really do go a long way. Sutter : It was just a timing issue; to give it adequate bake time. Author Contacted. Related Editorial. Related Sponsor Learn everything you need to know about saving time and delivering higher quality software and applications with test automation.
Hibernate Releases Version 1.
0コメント