Quote:Original post by Anonymous Poster
Then again, your compiler may not, this has nothing to do with the language.
Argh, that should of course be "your compiler may.", too many "not"s running loose :)
Quote:Original post by Anonymous Poster
Then again, your compiler may not, this has nothing to do with the language.
Quote:Original post by Anonymous PosterQuote:Original post by MaulingMonkey
With the C style printf/fprintf/snprintf, types must be specified manually in the format string. This means that every time you call these funcitons, you must explicitly tie it to the variable(s) type. All and all, this leads to some very brittle code, as every line that prints that variable breaks every time you change the type.
Ok, how many times do you really change the type, and when writing to file, you sometimes want to know the exact contents of the file that you produce, not "oh, let's get lucky and remember that this variable has to be of this type so that our file meets the standard we're trying to follow with it".
Quote:So that's not always good thing, sometimes you want to be sure that the output_the_file() function/method does exactly what you want and does not depend how you define your struct/class/variables/whatever.
Quote:Quote:Your compiler may not even warn if the types mismatch, the format specifiers mismatches the number of arguments, or if you pass an object, all situations which lead to undefined behavior, the bane of programmers everywhere.
Then again, your compiler may not, this has nothing to do with the language. If your compiler is at fault, it's not the language or the functions. Let's not assume what kind of compiler each uses.
Compiler Quality | printf method | operator chaining methodGood C++ Compiler | will warn if not supressed | will not compile if in errorBad C++ Compiler | will silently compile | will not compile if in errorNot even a C++ Compiler | ??? | might silently compile
Quote:Original post by MaulingMonkey
Which is, among other reasons, the reason read() and write() are uncovered - so you can send the exact binary you want without any formating. Further, the operator chaining mechanism
Quote:
does not in any way interfere with choosing the exact type you want. In fact, quite the opposite - if you realize in retrospect that you've been using the wrong type all along, it's trivial with the operator chaining mechanism to fix the problem, so I'm having a hard time understanding how that's supposed to be a counterpoint.
Quote:Original post by MaulingMonkeyQuote:
Let's not assume what kind of compiler each uses.
I'm doing the very opposite of assuming what kind of compiler is in use. I am quite explicitly not assuming I have a good compiler available to my target platform/OS/twinky (or get to choose to use one). To do otherwise - as you would seem to prefer - is to do the very opposite of what you later suggest - that I rely on there being a good compiler and that I get to choose the compiler! Instead of relying on my compiler warning me in a situation which by no interpretation of the standard is it required to do, I would prefer to rely on the standardized features of the language itself, well defined by the standard itself to not allow compilation of certain methods of shooting yourself in the foot. So again, I'm having a hard time seeing why you consider this a counter point.
Quote:Original post by Anonymous PosterQuote:Original post by MaulingMonkey
Which is, among other reasons, the reason read() and write() are uncovered - so you can send the exact binary you want without any formating. Further, the operator chaining mechanism
Sometimes you want to write in ascii, so how would writing in binary then help :)Quote:
does not in any way interfere with choosing the exact type you want. In fact, quite the opposite - if you realize in retrospect that you've been using the wrong type all along, it's trivial with the operator chaining mechanism to fix the problem, so I'm having a hard time understanding how that's supposed to be a counterpoint.
If if if and if, and some maybes, all I tried to say is that it's not a silver bullet. What you are saying, is not the only truth, it DEPENDS.
Just one example where you want exactly one type of output: think about a situation where you exchange data between two programs via files.
Some of us get to choose what compiler they use, are you saying we should still obey your principles then too?
Quote:Original post by MaulingMonkey
greed. It seems I've already rated medevilenemy down the maximum amount for previous bad advice, unfortunately.
Quote:
1) RAII.
2) Operator chaining.
Quote:Teh AP z0mg
Ok, how many times do you really change the type,
Quote:and when writing to file, you sometimes want to know the exact contents of the file that you produce,
Quote:not "oh, let's get lucky and remember that this variable has to be of this type so that our file meets the standard we're trying to follow with it".
Quote:So that's not always good thing, sometimes you want to be sure that the output_the_file() function/method does exactly what you want and does not depend how you define your struct/class/variables/whatever.
Quote:Original post by Anonymous PosterQuote:Original post by MaulingMonkey
Which is, among other reasons, the reason read() and write() are uncovered - so you can send the exact binary you want without any formating. Further, the operator chaining mechanism
Sometimes you want to write in ascii, so how would writing in binary then help :)
Quote:Quote:
does not in any way interfere with choosing the exact type you want. In fact, quite the opposite - if you realize in retrospect that you've been using the wrong type all along, it's trivial with the operator chaining mechanism to fix the problem, so I'm having a hard time understanding how that's supposed to be a counterpoint.
If if if and if, and some maybes, all I tried to say is that it's not a silver bullet. What you are saying, is not the only truth, it DEPENDS.
Quote:Just one example where you want exactly one type of output: think about a situation where you exchange data between two programs via files.
Quote:Some of us get to choose what compiler they use, are you saying we should still obey your principles then too?
Quote:You can assume whatever you want, but here you are trying to put everyone else in your situation. You are not wrong, in your situation, but to generalize that to everyone else is not very good advice IMHO.
Quote:Original post by MaulingMonkeyQuote:You can assume whatever you want, but here you are trying to put everyone else in your situation. You are not wrong, in your situation, but to generalize that to everyone else is not very good advice IMHO.
Show me the situation in which I am wrong. I covered if you had a good, bad, or non-C++ compiler. What's the situation I'm missing, where the costs outweigh the advantages, however minor those advantages might be.
Quote:Original post by ZahlmanQuote:Teh AP z0mg
Ok, how many times do you really change the type,
Much more often than one ever tends to think one does. I can tell you this from personal experience. Besides which, changing it even once is enough to highlight the clear advantage of the new approach.
Quote:Quote:and when writing to file, you sometimes want to know the exact contents of the file that you produce,
So look at the file, in a text or hex editor as appropriate.
Oh, you meant that you want full control over it? How exactly would you lose any control by using the new functionality?
Quote:
Seriously, try to show a non-trivial example of what you think you can do in the "old ways" that's so wonderful. I can pretty much guarantee it will be torn a new one by the "new ways".