« first day (2041 days earlier)      last day (2943 days later) » 

2:00 PM
oddly enough I remember one of my dad's electric shavers having a Java logo on it...
 
my prof has a software suite that lets you compile c++ code and then run it on an embedded system.
I'd probably use that if I was programming something like that
 
usually one would use C for embedded because the overhead of the typical C++ runtimes is so high
 
depending on what embedded means that may demand just plain C
 
compiled into machine
 
but for what I call "pseudo-embedded" that isn't really embedded, like Raspberry Pi, you can just use a bog standard ARM C++ cross-compiler with all the bells and whistles
 
2:01 PM
CBS why u no let me watch Supergirl
 
then put directly onto
 
fix your video player app thing
 
licensing innit
they no let us cos no usa
 
nah I'm VPNing as usual
and it lets me onto the page with the episode
 
Anyways. I don't think there is overhead
 
2:01 PM
it just doesn't load
outside the VPN it correctly shows me an error message
 
There is a fair wait time though I think.
 
@bigcodeszzer well, you're wrong
C++ runtime libraries are quite large
 
It's compiling it into machine code
 
the C++ features that aren't in C definitely have overhead that's noticeable on very resource-constrained systems
 
And the machine code goes on the imbedded system
 
2:02 PM
so? a little microcontroller still doesn't have the space for that
 
especially since C++ requires a runtime
does C require one? I can never remember
 
or the power to run it, most likely
 
Well
 
@Ixrec you can get by without libc but it's often small enough anyway
 
The guy was running it on a miniscule chip
 
2:03 PM
yeah I'd assume libc is much much smaller than libc++
not physical size lol
 
I know
my point is
 
I thought you wanted to talk about exceptions
 
He had the thing working on a small chip
I did.
 
@BarryTheHatchet I'm starting to wonder that myself
 
Anyways. Yes. Exceptions. In C++
Why do you use them
 
2:04 PM
@Ixrec I think perhaps my chatroom spidey sense is more finely honed than yours.
 
because some failures are unavoidable and error codes are often much worse
 
(no offence)
 
@BarryTheHatchet well I was wondering it a looooong time ago
 
But can you demonstrate that with an example?
that's why I was directed here
 
memory allocation failure is by far the most compelling example
if that one doesn't convince you I'm not sure what else to turn to
 
2:05 PM
But why not just use an if()
One we used was opening a file
 
around every single memory allocation call in your entire program?
 
Yes, come to chat as I have a good example that I am too lazy to make into an actual answer. — whatsisname 14 hours ago
but @whatsisname is not here.
 
you know most C++ memory allocations are not explicitly performed by your code like a malloc() call would be, right?
 
Where do you use the try catch?
That is catching those?
 
4265
Q: The Definitive C++ Book Guide and List

grepsedawkThis question attempts to collect the few pearls among the dozens of bad C++ books that are published every year. Unlike many other programming languages, which are often picked up on the go from tutorials found on the Internet, few are able to quickly pick up C++ without studying a well-written...

 
2:06 PM
the norm is that up in the main rendering loop you have a try/catch for everything you had no way of "properly" handling and then show the user an error message instead of outright crashing
 
Well, in the case of file opening
Instead of try catch, I just put if(file.open()){
 
just to save you some time, in many cases file opening works just fine with return codes
 
I feel like there would be an equivalent for memory allocation
 
I'm not saying exceptions are always the right move for that the way they kind of are with memory allocation
 
Is there a flag somewhere that you could test
 
2:08 PM
@bigcodeszzer there is if you're allocation and deallocating manually; iirc malloc() returns a null pointer if it fails
 
I've never done that yet.
 
because you're using C++, not C
 
Ah. That makes sense
 
Handling errors by wrapping everything in if and else is the philosophical cousin of putting all of your code in a single function
 
I only use new though
 
2:08 PM
Don't use new
 
which is correct
 
no it's not
 
well, new is better than malloc
 
but even new you shouldn't need anymore
 
2:09 PM
yep
 
Yeah.
 
which is an entirely separate discussion
 
yeppers
 
2:09 PM
Vector and what not
 
I was thinking more of make_unique
 
I think smart pointers and "STL" containers are a very different subject from exceptions vs return codes
 
That I don't know, but vector handling dynamic memory definately makes sense
assuming the person using it knows how to use it properly.
 
yes I've started saying "STL" in scare quotes just to annoy you
=)
 
2:10 PM
@Ixrec They're highly related because manual memory management produces largely exception-unsafe code
so if for some reason you must use new everywhere, perhaps you're better off with return codes
 
I know what STL is
 
bet you don't
 
@bigcodeszzer that was directed at Barry
 
@Ixrec the quotes sanitise it ;p
 
Barry dislikes it when people use "STL" to mean things that aren't actually the STL, which everyone does
 
2:10 PM
its the library that contains shit like vector
beyond that I don't care
 
well said
"shit like vector" wow
 
hey, std::vector is what separates us from the animals
 
I had an assigment that supposedly was teaching stl algorithms. But it was very poorly written
 
where do you work, @bigcodeszzer?
 
I'm in school
 
2:12 PM
so...let's get back to exceptions
 
@enderland um, no, that was about someone marching in and calling everyone (well, in this case, calling gnat) "rude" and "snobby". read more carefully before attacking me please. use your moderator brain!
 
Separates us from the annimals is a bit of a stretch. Everyone should know /how/ to use raw pointers
 
yes all that stuff is relevant to exception safety but I think we have to convince @bigcodeszzer that exceptions have a point before talking about exception safety makes any sense
 
It's ugly.
try catch throw is damn ugly.
 
@bigcodeszzer oh I wouldn't have thought that okay
 
2:13 PM
if you're using it for control flow it's ugly
 
Exactly. ixrec
 
if you use error codes to handle all possible memory allocation failures that's also super ugly
 
try {
   this->conversation.have();
}
catch (std::logic_error&) {
   # Debugger currently breaking on this line
   exit(-1);
}
 
Which is why, what I've gathered, is my prof is teaching it wrong.
 
@BarryTheHatchet You missed a curly bra--oh.
 
2:14 PM
I can imagine uni assignments fail to fully motivate exceptions as they tend to be completely unnecessary in 100-line programs
 
Makes sense
 
those who can't, teach, etc
@Ixrec yeah that's true and tough
 
my uni made me write 1000-line programs where they did just barely have a point =D
 
exceptions, like a properly structured program design, may be the sort of thing that's hard to grok the purpose of until you actually write a full-scale, uncontrived program for the first time
 
I've learned more dicking around in java on my own time
 
2:15 PM
many people report that to some degree
 
But being forced to use c++ (Cause otherwise I Would never have learned it at all) definately made me better at doing things that would have otherwise never practiced
 
Would you please cut out the endless swearing?
It's BEEEEEEEP annoying.
 
that's hardly swearing
hahaha
swearing is good for you
 
the uni stuff is valuable not for the actual languages you learn but for the computer science background stuff on language design and compiler implementations and algorithm analysis and whatnot
 
Not when my boss sees it on my screen, it isn't
 
2:16 PM
Your boss probably doesn't know what he's talking about
 
@bigcodeszzer I find it's a cop-out when I'm too lazy to think of a properly expressive word that conveys my real feelings
 
because the biz is designed to make money, not good code.
 
I'd rather pause for a second and call something "exceptionally harmful and unacceptable" than "f---ing stupid"
 
That's a good point xrec, but limiting your vocabulary is better?
 
that's the exact opposite of what I was arguing lol
 
2:17 PM
effing stupid adds the 'and annoying, and makes me frustrated, and I want to stab people who do said thing'
in one word!
 
@enderland Actually, on reading your message again, I'm very annoyed by it. I haven't "trolled" anyone. Actionless? Why would I start moderating a site whose moderation rules I disagree with? I've said that before, too. Though I do help you close and delete obviously bad questions. So what's your problem? Why do you feel the need to "come at me" like this? You're a moderator; you should know better. Please delete your remarks or at the least refrain from making them in the future. Thanks.
That's three times now. Next time I'll be forced to flag.
 
Anyways, I think my understanding of exceptions is half complete.
 
so...exceptions
 
Exceptions seem to be the exception to this conversation
 
I know how/where you should /not/ use them
But I don't know how/where you should use them.
 
2:19 PM
this conversation is a good example of what happens when you use error codes instead of exceptions; all the code is about propagating codes instead of doing anything useful
 
You will find out as you grow in start your career
Best not to judge them until that day comes
 
@bigcodeszzer is the question where a language should use them or when you should throw exceptions yourself?
 
If you can't give me an example, I would almost make the stipulation you don't understand the topic properly.
 
we did...
 
You ask me about something I know, I can explain it very simply, and very quickly. Probably with a swear word even.
 
2:20 PM
I gave you a great example
 
Dynamic memory?
 
@bigcodeszzer And they wonder why I suspected you of trolling. :smh:
 
I've been sticking to just one example but mostly because it's so much more convincing than all the other examples
 
I do troll, but not on programming forums.
programming is serious
 
Right well since this is not a programming forum, you're in the clear to troll away
 
2:21 PM
whatever
 
I feel like we didn't do April Fools' properly in this room
 
you guys need to stop throwing so many checked ConversationExceptions so we can start ignoring them and staying on point
 
okay so your example code was
 
there is no small example code that'll convince you that exceptions are needed
 
(no idea if @bigcodeszzer knows about checked exceptions)
 
2:21 PM
Ixrec explained that already
 
try{ this->conversation.have() } ....
how is is your exception handling any different from an if() check
 
have fun @Ixrec
I'm going to do something more productive, like weeing all over the wall
 
You say, you would have to have error codes everywhere, while it seems you would have to similiarly have try/catch blocks everywhere
 
@bigcodeszzer because the try can be placed higher up the call stack if we want, and the actual throw inside have() might be much farther down the call stack than it looks
obviously in the one-line psuedocode it's not, as previously mentioned
 
if(file.isopen()){
lowerstackfunction()
}
 
2:23 PM
no, you only need one try/catch block instead of zillions of error code returns, that's the whole point
 
If the code is going to fail and you have no reasonable way to handle it in that method, let it fail, and the caller can sort it out.
 
Is that not what I wrote?
 
You would rather have it fail in lowerstackfunction()
 
@bigcodeszzer if you mean me, I was responding to your claim that using exceptions means "try/catch blocks everywhere" which as I just said is not at all true
 
2:24 PM
no.
if file cannot be opened then it should already have thrown an exception. you don't even get to lowerstackfunction()
the caller can then handle that exception, potentially with the same code that handles other exceptions, some of which may come from within lowerstackfunction
 
bool higherstackfucntion(ifstream myfile)
 
instead of needing thirty if statements, unclear object lifetime semantics, and a contaminated API
 
return true/false
 
ok just do that then
 
But they are the same?
 
2:26 PM
yep sure okay
 
notice the question mark
 
notice the answer
 
then explain?
 
no thanks
 
	fooWithExceptions() {
		try {
			doWorkWithExceptions();
		} catch(WorkException e) {
			std::cout << "Failed to do work: " << e.what() << std::endl;
		}
	}

	doWorkWithExceptions() {
		a();
		b();
		c();
		d();
	}

	fooWithErrorCodes() {
		int rc = doWorkWithErrorCodes();
		if(rc != 0) {
			std::cout << "Failed to do work: rc=" << rc << std::endl;
		}
	}

	doWorkWithErrorCodes() {
		int rc = a();
		if(rc != 0) {
			return rc;
		}
		rc = b();
		if(rc != 0) {
			return rc;
		}
		rc = c();
		if(rc != 0) {
does that help at all?
in spite of SE chat hating indentation
 
2:27 PM
and that's the short version
assumes all your functions use the same error code set
 
hold on
 
:28768936 huh, I thought that just added an indentation level, thanks
 
@Ixrec it does
that indentation level makes it code-markdown
 
oh I was missing indentation on the blank lines, right
 
2:29 PM
@BarryTheHatchet *n00b
 
Okay. I see what you're getting at
But why not:
 
@bigcodeszzer progress! \o/
 
reminds me very much of this (~1:10)
 
rc = a();
rc = b(rc);
rc = c(rc);
with rc as a bool
 
why would b want to know the return value of an unrelated function?
designing b() that way effectively makes it so b() can only ever be correctly called immediately after a()
 
2:31 PM
Cause then you just put an at the top of all the functions
prolly just be one function, with different params each time
Um. Hold on.
 
I have no idea what those last two statements mean
 
"um" means "I have no idea what to say"
 
a few implicit assumptions I'm making in that example code:
 
"hold on" means "brb going to find out what to say"
 
1) a, b, c, d have absolutely nothing to do with each other in principle
 
2:32 PM
Well, what is wrong with the error codes example?
It's ugly, yes? Too many if() calls?
 
2) continuing program execution after a, b, c, or d has failed is undefined behavior
 
Well, I assumed you wanted it to stop
 
@bigcodeszzer half of the code in doWorkWithErrorCodes() is taken up by properly propagating the error codes, instead of doing real work
that's the problem
 
a bit like this room
 
now imagine if these were functions that actually acquired resources which later have to be freed
 
2:34 PM
half of the day in the Whiteboard is taken up by properly trolling each other, instead of doing real work
not sure it's a problem though
 
Well, I'm suggesting that with a little re-organization, namely, functional paradigm style, it would be shorter
 
in C++ with exceptions you get the RAII guarantee that exceptions unwind the stack and call everybody's destructors
 
actually that's not quite true
it's only so if you catch the exception somewhere
 
I feel like if you need to be calling the destructors the scopes are managed poorly.
 
true, but we're assuming the goal is not to outright crash the program on these failures
 
2:35 PM
Well I would have if() at the front of each function
 
@bigcodeszzer you don't need to call them, that's something C++ does for you
 
firstfunction(rc){

if(!rc){
return false

else{

...

}
 
@bigcodeszzer no, it's the opposite. having destructors is the very definition of managing scopes properly
@bigcodeszzer that violates SRP and introduces a massive coupling between your functions
 
that's the whole point of new, delete, constructors, and destructors, almost all allocation/deallocation code gets called for you by the language when it should be called so you don't have to waste time figuring it out
 
Yes.
 
2:36 PM
5 mins ago, by Ixrec
designing b() that way effectively makes it so b() can only ever be correctly called immediately after a()
 
Then why does RAII need to do that?
Oh
 
I don't understand the question
 
neither do I
 
nvm its not important
 
but you're so close to a breakthrough
 
2:37 PM
the whole point of objects having destructors is so that their cleanup code gets called automatically when needed, so you don't have to keep track of when you need to call it
 
Yes. Which happens when they go out of scope
You said: in C++ with exceptions you get the RAII guarantee that exceptions unwind the stack and call everybody's destructors
What does that mean?
Destructors are supposed to be automatic, no?
 
that means that everybody's destructors get called whether the function exits normally or whether the function exits prematurely due to an exception getting thrown
roughly speaking don't nitpick that please
 
Which leads me back to stipulation a) something is wrong with your code
 
why?
 
Well I would use a temporary variable
 
2:40 PM
wtf
 
and put an if somewher
and if that if doesn't pass, I don't insert the dynamic memory
 
"insert the dynamic memory"?
 
It gets deleted immediately.
vector.push_back(tempvariable)
 
that's what your destructor should be doing
 
Well yeah
 
2:41 PM
why are you trying to make life harder for yourself
 
doWorkWithErrorCodes() {
	int rc = a();
	if(rc != 0) {
		freeAllResourcesCreatedByA();
		return rc;
	}
	rc = b();
	if(rc != 0) {
		freeAllResourcesCreatedByB();
		freeAllResourcesCreatedByA();
		return rc;
	}
	rc = c();
	if(rc != 0) {
		freeAllResourcesCreatedByC();
		freeAllResourcesCreatedByB();
		freeAllResourcesCreatedByA();
		return rc;
	}
	rc = d();
	freeAllResourcesCreatedByD();
	freeAllResourcesCreatedByC();
	freeAllResourcesCreatedByB();
	freeAllResourcesCreatedByA();
	return rc;
}
2
 
fn_allocate(){

sometype tempvariable = new sometype();

if(condition){

somevector.push_back(tempvar)
 
You mean sometype*
 
@BarryTheHatchet grabs wrist and forces hand into face why are you punching yourself? ;)
 
2:42 PM
Uh. Probably
 
and if you'd written auto tempvariable = std::make_unique<sometype>() instead then you wouldn't need to worry about that variable any more, whether you get an exception or not. as it is now, you're leaking that memory because you didn't delete it. so even with this trivial example, you've already got a terrible bug caused by your most-effort approach.
 
so you're just letting the memory leak?
 
also, why are you creating an object outside of the conditional if you only need it inside the conditional?
 
At least put some towels down.
 
as Barry said, using RAII classes like smart pointers ensures everything would get cleaned up properly without you even having to think about these things
 
2:43 PM
Hmmm
Well what I'm saying is, the sometype would be an object.
 
if you new it, it's a pointer
 
And therefore, if it doesn't get push_back, the function just ends
 
well no the sometype is still an object
 
and then it goes out of scope
 
mind you, the pointer is an object too :)
 
2:44 PM
and calls destructor
 
@bigcodeszzer no it doesn't. you dynamically allocated it
 
raw pointers don't have destructors
that's the whole reason smart pointers exist
 
it's like you're taking all the benefits of doing things our way, and attributing them to doing things your way instead
 
If I allocate something with new.
 
if you do type* = new ... and never call delete on that pointer later, you've leaked whatever it points to
 
2:45 PM
It doesn't get destroyed when the pointer goes out of scope?
 
59 secs ago, by Ixrec
raw pointers don't have destructors
 
otherwise your vector would contain a dangling pointer wouldn't it
 
What if I don't use new?
 
then it will
that's RAII
 
2:46 PM
So object = object();
 
that's silly
 
or if you use things like std::make_unique that give you a proper smart pointer
 
That would work?
 
or just object();
 
just type object; please
yes
 
2:46 PM
or object;
 
@Ixrec that's not valid
 
Okay, well barring that mistake.
 
the extra copy whatever is unnecessary
@BarryTheHatchet Object object; is not valid?
 
@Ixrec it's not copy-assignment. it's copy-initialisation.
@Ixrec that's not what you wrote :P
 
you were omitting the Object part too
 
2:47 PM
@Ixrec no I wasn't
although I called it type
 
ok never mind conversation moving too fast
 
fn_allocate(){

sometype tempvariable = sometype();

if(condition){

somevector.push_back(tempvar)

}

}
 
whooshhhhhhh
 
yeah
 
I'm in desperate need of some calming music
 
2:48 PM
Listen to tom waits
It will also make you more insane
 
Small Change got rained on with his own .38.
 
admittedly, destructors get called whether you return error codes or throw exceptions
 
30 aught 6
 
No. It's .38.
 
2:48 PM
okay
so have we trumped the dynamic allocation issue?
 
but a failure inside a constructor is a classic example of an error where exceptions really are your only option
 
trumped?
 
18 hours ago, by Aaron Hall
♪ "Barry in charge, of our days, and our nights. (Barry in charge) Barry in charge, of our wrongs, and our rights..." ♪
 
I might argue that you shouldn't be allocating in a constructor
 
what do you think the std::vector constructor does?
 
Well, that's them
 
there we go
@bigcodeszzer it's best practice. it's literally the appropriate place for allocations
 
I used to date a guy who looked like Tom Waits.
 
and they probably used a try catch I guess, to make that work
 
doubtful
 
2:50 PM
most classes shouldn't allocate memory directly only because standard containers and smart pointers can be used for that stuff
 
you're supposed to handle the exception further down the call stack
 
what if you call a function in the constructor?
 
that handles that
 
then what
 
2:50 PM
I've completely lost you again
 
Then returns an error code
 
what can you do with an object that failed to initialise
 
if you try to construct a std::vector and there's no memory left to allocate, what alternative is there to throwing a std::bad_alloc?
 
I don't know.
There must be a fail flag or something
to test
 
on what?
 
2:51 PM
He should learn Python, that's easier.
 
dude. he's trolling. I'm now 80% sure of it.
 
there is no std::vector, it couldn't be constructed
 
you've had the same discussion four times
 
this isn't like C where you allocate a blob of memory and then build an object in that memory as a separate step
 
Okay. Situation is, you called a constructor, the constructor couldn't allocate the memory
 
2:52 PM
the whole idea of new was to combine those steps into one
 
a vector lets say
 
mm-hmm
 
Someone should star that comment. It's pure gold.
 
which one?
^ applies to half of what's been said in this convo
 
Mine, about Python.
:D
 
2:53 PM
ssh Aaron
 
Weak
Anyways.
So you have

try{

new object()

}catch{

...
}
 
shoot me
 
lol
 
bang
 
yay guaranteed memory leaks
 
2:55 PM
do you call that insignifigant white-space?
 
im here now
 
it's not even valid syntax
 
right on time
 
@whatsisname RUN AWAY REALLY QUICKLY
 
That's hot
 
2:55 PM
rly?
 
@whatsisname unless you're here for the schadenfreude
 
Hey, I got Spacemacs installed on my host/laptop last night at the emacs hack night.
 
not really
i just saw there was a chat notification for me
 
considering none of us know what the convo is supposed to be about it's probably a good idea to ignore it
 
2:57 PM
whatsisname you said you could demonstrate a case where try/catch would be a better option than error codes
ixrec and barry are saying that the case is initializing with a constructor inside a try/catch block?
 
there's a ton of examples
 
and catching out of memory exception
Well the main point, as I see it, is that try/catch shouldn't be used in flow control.
 
This account is scheduled to be deleted in 23 hours. To cancel deletion, click here.

IMPORTANT: If you've requested deletion on other Stack Exchange sites, you'll need to cancel those separately by visiting each site's profile.
 
Which was my main issue.
 
we all agree on that
none of our examples have been advocating exceptions as flow control
 
2:59 PM
now, before i even bother, is it even possible to convince you of their value?
because obviously anything with exceptions can be implemented without them, because at the end of the day every boils down to conditional jumps
 
Of course.
thank you
thank youuuuuu
 
so as an example, sometimes I have to talk to a USB device
 
Well, if you can demonstrate how it is cleaner or simpler, then yes
 

« first day (2041 days earlier)      last day (2943 days later) »