« first day (184 days earlier)      last day (4766 days later) » 

12:07 AM
Hi everybody, how would you write these functions:
bool writesomething(const Something& something);
or
bool writesomething(int somethingid, const Something& something);

bool readsomething(const Something& something);
or
bool readsomething(int somethingid, Something& something);

notice that Something has a public field named id
 
 
1 hour later…
1:33 AM
@arthurprs: Why would you want to add a parameter which may contribute nothing but errors? Use the former options.
 
1:46 AM
I know C, and I know OOP. I've also done some C-with-classes stuff in the past. But now I want to learn C++ for real. I got Bjarn's book. How far can I safely skip?
 
@MartinhoFernandes He's written a few books. Which book did you get?
 
"The C++ Programming Language".
 
I wouldn't skip any of the book. I often find that I can learn things or gain new insights even from "beginner" chapters.
4
 
I think I'm going to find chapters like Pointers, Arrays and Structures rather boring. Is there a book better suited for someone that already knows C?
 
what does mean by this line" The human eye is markedly less sensitive to light above 700 nm wavelength, "
 
2:00 AM
@Miss I don't think that's on topic here, but that means that the range of light the human eye can see stops near red light (~630nm-740nm).
 
hmm ok thanks
 
2:13 AM
@JamesMcNellis Looking at it, that seems like a good idea. I know most of the stuff on that Pointers, Arrays and Structures chapter, but I just noticed it talks about references, which I only have a vague idea of. I guess I'll start at the beginning. Thanks for the advice.
 
Sure thing.
 
2:30 AM
Hello.
I'd appreciate an opinion. :)
 
HELLO!
 
Oh yes. In bold. I ment HELLO, absolutely.
 
command* create_command(const std::string& name)
 
hahaha
 
2:31 AM
i record the commands for undo for later.
so anything the factory returns goes onto a stack for undo.
the issue is, what to return when the name is invalid.
 
What would cause the name to be invalid?
 
i could return a null but then i'd need to check for it. which is ok. then, i could return a null object, but then i'd still need to check for it somehow so i don't record it for undo.
i'm reading the name from a file.
i can return return a noop command when the name is not valid, and the do and undo methods would do nothing. but pushing it onto the undo stack makes the stack grow by one, implying there's something to undo. which is not right. even if undoing it does (undoes) nothing.
it looks to me like whether i return null or a null object i still need to check for it. i wonder if you have another idea so i can treat regular commands and null command uniformly..
 
Is it expected that the file will would contain invalid names? Or does an invalid name indicate that the file is corrupted or otherwise invalid as a whole?
 
no no. it's perfectly feasible. it's a file coming from the user.
?
 
2:46 AM
Is it an error, though? I'd lean toward throwing an exception if you try to create a command from invalid input.
 
3:08 AM
it's an error, but it's not exceptional. i take input from the user, who may well be human, so i sort of expect erroneous command names.
 
I've never bought the "exceptions should only be used for exceptional circumstances" argument.
 
you'd throw an exception?
:-S
 
Maybe. I don't know enough about the problem. I just think an exception might be worth considering.
 
i imagine wearing a helmet, putting on ear plugs, and wearing a protective vest before calling a function "because it might throw at me in fury everything it's got"
if i use exceptions then i need to try. which is not much different than checking for null. what does it give me over a null ... ?
i'd really use a null object if it wasn't for the undo stack. so essentially i need to treat a null object different from all other commands.
 
Do you want to report the error to the user?
 
3:14 AM
mm. maybe. didn't think about that. i was just about to swallow it.
but i might.
 
Eeeewwwwww
 
yeah i suppose, give a warning.
oh yeah that's an error. definitely.
you know what, i think you just triggerred the answer for me.
:)
with the "are you going to report it to the user"
 
I'm glad I was able to do something useful today. :-)
 
i have to. i have to report it as an error. if the user gives me a sequence of commands and somewhere among them is an erroneous command then i shouldn't proceed, i should abort. so in fact i shouldn't execute anything before i know all command names are valid. so if i do two passes then i can guarantee that create_command() gets a valid command name!
i'll still have to eliminate the compiler warning though, so i'll return a null as a last resort and i can assert on that. it should never return null in production.
 
3:43 AM
is this wrong question..?
 
hey need
a help in c++
can anyone help
 
4:16 AM
Does anyone know what font(s) is used in the C++0x FDIS?
 
 
1 hour later…
5:17 AM
The latin modern variant of the computer modern familly by Knuth.
(Acrobat reader has a properties entry in the file menu which opens a form with a font pane.)
 
Ah; so it does. Latin Modern Regular and Typewriter. For shame; I was hoping it was something preinstalled on Windows so I could use it as my e-mail font.
Thanks for the tip on having the PDF reader tell me.
 
It's a nice font.
 
@JamesMcNellis pretty sure there are free .ott version of Latin Modern available online
and who cares if it doesn't look as nice on the other end, your emails will look good when you send them! ;)
 
@jalf I found a bunch of OTFs. I tried the Typewriter variant as an editor font but I don't like it as much as my current font, Anonymous; it's too wide.
 
5:35 AM
oh yeah, and by .ott I obviously meant .otf :)
 
6:12 AM
Hello all
 
hi
 
hello @GMan
 
6:35 AM
@jalf Look on ctan
 
7:10 AM
@JamesMcNellis Ive never bought the exceptions should be used, even in exceptional circumstances argument.
I feel they are more akin to raw arrays in c++. Something thats necessary under the covers, but should never be part of a user interface.
 
@ChrisBecke that can't come as a surprise. You've never bought that any part of C++ should be used
 
@jalf Thats a fib. Ive bought into a lot of C++.
 
@ChrisBecke What's an equivalent that's just as powerful?
 
@ChrisBecke What kind of user are your speaking about? Obviously I don't mention exception to my end users...
 
handling the error where it happens (if needed). Its called cohesion and they teach it in comp sci 101. Not apparently to c++ students howevr
 
7:13 AM
@ChrisBecke What's "handling the error"? This is hand-waving.
 
@AProgrammer I refer to the user of the specific c++ framework that abstracts the concept.
 
What mechanism do you use to report errors that's as powerful as excpetions?
 
@GMan handling the error means ensuring the state of the software is logically consistent, such that further calls can be made and expected to work.
 
@ChrisBecke that's a strawman argument
 
@ChrisBecke Right...but this doesn't specify anything about a mechanism.
 
7:15 AM
@ChrisBecke that sounds like what the rest of us calls "exception safety"
 
You can "handle the error" with exceptions.
 
@ChrisBecke Assuming that exceptions should be used only for errors (I don't agree, but that can be another discussion), all libraries that I know of are able to report errors at time. So they aren't handled when they are detected...
 
whether or not you handle errors is completely orthogonal to whether you express errors as exceptions or return codes
 
nope. but using error codes to handle errors is just as capable of ensuring consistent state.
 
@ChrisBecke Nope.
 
7:16 AM
um, yep.
 
If my class fails to construct, how should I report that?
Even if constructors could return values, the return value can simply be ignored.
Exceptions must be handled.
 
I like the way that neither of us failed to provide any actual facts for those assertions.
 
Exceptions is just another mean of reporting the error. And it is more adequate when the direct caller isn't the one which will handle it.
(I've sometimes even provided 2 interfaces for the same functionnality, one with another error report mecanism and one with exception as the choice wasn't clearcut)
 
When classes cannot construct, then the software has in fact entered an invalid state where the state of things cannot be constructed.
Note that I did mention that exceptions are like raw arrays. Things that should not be used in application domain problems.
 
@ChrisBecke You end up with far more repetitive, boring and error prone code which distract of the true issue.
 
7:18 AM
@AProgrammer You might.
 
@ChrisBecke Yes, and it's better that the program forcibly handle that, than ignore it to do much damage down the line.
 
But you dont actually need to test error codes to ensure that the software's state doesn't become inconsistent.
 
@ChrisBecke Bullocks. If I don't test something, I can't know.
 
@ChrisBecke huh? Then how do you propose to handle errors?
 
@GMan You can't know what?
 
7:20 AM
you try to open a file, the operation fails, and you can't be bothered to test the error code. How then do you avoid your software's state becoming inconsistent?
 
@ChrisBecke See jalf's response, above this one.
 
with an exception it's trivial, because the app terminates unless you write code to recover from the error.
 
@jalf If the file fails to load, then the object that represents the file will report that there is no data.
 
@ChrisBecke how does the object that represents the file do that, if it didn't check the error code?
and how does it report anything, if you don't check the error code you get from that object?
 
depending on how severe that is, the program can decide wether to proceed regardless, or not.
 
7:21 AM
@ChrisBecke Decide with what? You said we don't need to test anything. Branching depends on testing.
Or do your programs operate by magic?
 
are you sure you want an answer to that?
 
I do recall saying you do need to test - just not always
 
:3
3 mins ago, by Chris Becke
But you dont actually need to test error codes to ensure that the software's state doesn't become inconsistent.
 
@ChrisBecke but if you ignore just one single error code, how can you ensure a consistent state?
 
This says, in English, you don't need to test anything to ensure consistent state. Now you're saying some checks can be omitted. Moving the goal post?
 
7:23 AM
Hmm...
 
@jalf There are lots of potential errors that have nothing to do with the persistent state of the software.
 
I disagree, if you do not use exceptions, then you should check all return codes/error codes all the time.
 
@ChrisBecke name one
 
If you do not do that then you will either end up breaking your data/application or you will be reporting different errors than those that actually happened.
E.g., missing file versus error reading a file.
 
If I read a file in, its not necessary to check if (a) the file handle was created, (b) the contents were read, (c) the file closed, (d) the file was parsed.
 
7:25 AM
It is not?
 
if an error occurs, it, by definition, means that something has happened which you didn't anticipate. If you don't detect this, then it practically sounds like the definition of "inconsistent state" to me
 
The only thing the rest of the system depends on is, was the config data (in this case) loaded or not? And if there are sensible defaults, even the lack of loaded config data can be ingored.
 
@ChrisBecke how do you fall back to the default, if you don't test whether the data was loaded correctly from the file?
 
Beat me by 2 seconds.
 
@jalf Oh ffs. are you seriously so unimaginative that thats hard? Get out of programming if thats the case.
 
7:26 AM
@ChrisBecke Haha, wow. Answer the question.
"Chris: XYZ. jalf: Why XYZ?. Chris: YOU CAN'T THINK OF IT SO I'M RIGHT."
 
Just preload the defaults. Any failure to load and parse settings won't effect the defaults.
 
@ChrisBecke how do you I am so unimaginative that I want you to defend your own argument, yes
I have no interest in discussing with you, if it means I have to present both sides of teh argument
 
@ChrisBecke Sure it will. If I cannot read the first value (to overwrite the preloaded default), an error occurs and the stream needs to be reset (i.e., skip the read). Therefore, I cannot read the second without handling the error.
 
@ChrisBecke what if you read half the file, and then it fails (harddrive failure, perhaps)? How do you detect this and fall back to the default, rather than relying on half-corrupted data?
 
@ChrisBecke And nobody said that exception should be the only error reporting method.
 
7:29 AM
remind me not to let you write any error-handling codefor me
by the way, getting back to exceptions, they're a really lousy mechanism for error handling, no doubt about that. it's just that I'm not really aware of any significantly better alternative, and error codes certainly aren't it
 
@jalf hardware failures, by definition, are exceptional. 2. transactional processing means that even a half processed file can either be unwound, or applied in a way that does not have to result in inconsistent stata (and thats assuming the convoluted case where the settings being discussed do depend on each other to be consistent)
 
@ChrisBecke how do you propose to implement transactional processing without detecting errors?
 
@ChrisBecke Exceptional or not, it's still an error that you need to correctly identify if you want your program to function correctly. You think Google just says "Oh, well, shit happens?"; hell no.
 
and I wasn't aware that you didn't care about "exceptional" errors. So they're allowed to bring you into an inconsistent state then?
 
@jalf Again, we are detecting errors, just, only the necessary errors.
 
7:32 AM
@ChrisBecke but then explain to me how file I/O errors aren't necessary
 
My claim is that the set of errors that need to be handled is smaller than the set of errors thats technically possible
 
and yes, I am unimaginative. My imagination is every bit as bad as your debating skills
@ChrisBecke yes, and then you fail to provide a single example of an error that doesn't need to be handled
 
I am not debating. I'm saying that I prefer to handle errors with explicit error handling
 
Chris's argument basically boils down to arguing obscure and vapid definitions for "error", "handling", and "consistent", until he's right.
 
because the code is not much larger than code with exceptions
and easier to audit
and understand.
 
7:34 AM
No, you didn't state a preference to begin with, you stated a "fact".
Exceptions are easy to understand.
 
@ChrisBecke no, you were saying that you prefer not to handle errors with explicit error handling
 
But don't change the topic.
 
because it's not necessary
 
I was responding to an earlier erroneous statement of "fact"
 
I'm also not sure why exception handling does not qualify as "explicit error handling"
it looks fairly explicit when I do it. I have to write code and stuff, doesn't get much more explicit than that
 
7:35 AM
lol
 
in fact, if I fail to explicitly handle an exception, my app dies.
 
@ChrisBecke I remember a war story where someone forgot to test the result of close. It end up in a emergency visit to a very angry customer...
 
In my experience, implicit error handling occurs when I deal with return codes, because I forget to check them, implicitly relying on them to "probably be ok"
 
In my experience, implicit error handling occours when I see code that was written with exceptions, because programmers always put the throws in, and decide to puth the catches in later.
With the error handling decoupled from the error sites, no code audit can detect that.
But, perhaps code reviews are an artifact of the dark ages of software development
 
so you're saying you prefer correct error handling over incorrect error handling now?
that seems like a different argument than the one you started out with
 
7:38 AM
Better to say "this error needs to be handled" forcibly, have it not so my program closes, than say "this error needs to be handled...but it's up to you" and have my program corrupt randomly?
 
because you clearly don't adhere to them as a means of maintaining software quality.
 
@ChrisBecke Clearly? Do go on.
 
@ChrisBecke says Mr. "I don't need to check error codes"
 
Given that my position is that exceptions are incompatible with code reviews.
 
How so?
 
7:39 AM
@ChrisBecke your position is also that actually checking errors is unnecessary, which also seems incompatible with code reviews, if you ask me
 
My code reviews handle them quite well.
 
@GMan so you claim.
 
lul
 
@ChrisBecke Yes...
Chris, please explain why code reviews and exceptions are incompatible.
 
exceptions, decouple the site where errors are handled, from the site where errors are generated.
 
7:41 AM
So, basically, what you are saying, Chris, is that you do not do error handling or exceptions because it would be undue burdeon on reviewers?
 
meaning that code reviewers now need to cross reference multiple files to audit a piece offunctionality.
 
@ChrisBecke So does error handling! You cannot always handle all error codes and you have to propagate the error to different site.
Exceptions are nothing but such error propagation but implicit. IMHO
 
When you call fopen() it returns an error code to the caller, rather than handling the error where it is generated. How is that better?
 
@wilx Error handling is far more unit testable - each layer can be tested to respond correctly to correct input, and return an error code when things fail.
So, when functionality is changed, its easy to see wether the correct new cases have been handled at the current abstraction level or not.
 
Far more? Last time I checked CPPUnit's test cases had the capability to test for exceptions, too.
 
7:44 AM
@ChrisBecke why couldn't the same tests be written to check for exceptions?
 
Changing the topic again...
 
----^
 
btw, now we've changed from "exceptions can't be code reviewed" over "detecting errors isn't necessary", over "get out of programming, you n00b", to "exceptions can't be unit tested"
 
Acknowledge the points that were just made. Exceptions and error codes both necessarily have to propagate in many cases.
 
could you make up your mind about what it is you're trying to teach us?
 
7:45 AM
Of course unit tests can check for exceptions. The problem is that exceptions, by design, violate abstraction by bubbling out of objects to be handled at some other level.
 
@ChrisBecke just like an error code does
 
As soon as your design does that, it means that testing the software units does not represent the overall state of the software.
 
it is something you return from a function. It bubbles out from the function that generated the error
 
With error codes, if A calls B, calls C, which fails and returns an error code to B, B can in turn fail (or gracefully handle the error) - and return a code to A.
With exceptions, someone can add a new error to C, causing it to bypass B's catch clauses, and get handled at A.
Which is far harder to verify by code review as perhaps there are errors that are designed to bypass B.
 
@ChrisBecke Right, which is perfect, because B cannot possibly correctly handle the error.
With exceptions, the flow jumps exactly to whoever can handle the error first.
 
7:49 AM
And when C communicates errors directly with A, without going via the B abstraction, thats abstraction leakage.
With error codes, B is forced to handle A's errors, which makes for a more cohesive design, that preserves abstraction
thats my opinion of course.
 
Actually, that's just nonsense. You've thrown in the word "abstraction" into your conclusion, which is a word not present in your premises. Syllogism fail.
Let's try it this way: exceptions are just error codes with explicit checks at every single expression, that automatically propogate to the error code check that would return true. Do you agree with this isomorphism?
 
Its way to early in the morning to be throwing words like isomorphism about.
 
Do you agree exceptions can be said to be automated error codes?
 
and "automatically propogate to the error code check that would return true" is true, when the error code is a bool, true for success, false for error. but ok.
 
Well no, the error code could be any integer.
 
7:56 AM
or complex type, or combination of success and error codes.
 
Right.
 
but yes, error codes and exceptions are isomorphic.
 
So then, if you agree with error codes, and exceptions are automated error codes, then how can you disagree with exceptions? It seems to be an objection to automation.
(And on top of that, you can't forget to check an error code if it's being automated.)
 
@GMan I think I have been quite clear, it IS the automation aspect that forms the basis of my objection.
Because theyre automated they can happen when they don't need to, and theyre invisible to code reviews.
 
What can happen when they don't need to?
 
7:59 AM
@ChrisBecke the error handling can happen when it doesn't need to?
 

« first day (184 days earlier)      last day (4766 days later) »