« first day (258 days earlier)      last day (4707 days later) » 

12:03 AM
@LucDanton: That is a minimal test case.
 
Wait. You had the case but then you wrote an example quickly instead of pasting the case?
 
@Luc: I can't paste the minimal case due to licensing restrictions.
 
Got it.
 
Or rather, even the case I tried initially was slightly more complicated than that one
In the real code, the Foo and FooSpecific hierarchy is more complex
 
I guess this is another no sleep night
 
12:13 AM
@BillyONeal Your example compiles on GCC, modulo some warning regarding the empty bodies not returning anything.
 
same here, VS2010 will accept it just fine
actually, I think I've got something
the problem is that ClientFooMerge doesn't have an overload for Foo only
only for SpecificFoo
but you try to call it with a Foo when your dynamic_cast fails
at least, as far as the compiler is concerned, even if that will never happen at run-time
 
Xeo
12:33 AM
Isn't it just that the base class method is hidden, which deals with generic Foo? Shouldn't a using FooMerge::DoMerge solve this?
Oh damn, I just got a boner from the C++ AMP stuff.
@DeadMG, is there a video of the other talk he mentions?
nvm, found it
 
hey guys, I was wondering.. when you are the only one to answer a question that has a bounty, when the bounty expires, do you get 100% or 50% of the prize?
 
you get any of it? it was my understanding that you would get a bounty if and only if the giver awarded it to you
 
aw, that sucks.
and what happens to the points he invested on the bounty?
 
12:48 AM
maybe they're jsut gone forever
I didn't know bounties expired?
 
@Xeo Thanks, this answers my question: If you do not award your bounty within 7 days, the highest voted answer created after the bounty started with at least 2 upvotes will be awarded half the bounty amount.
 
1:05 AM
@DeadMG It's not supposed to have an overload for that. If that fails it's supposed to fall back to the DoMerge defined in the base class.
Which is the most generalized overload available
 
Xeo
@Billy: That doesn't happen, hiding rules n stuff
 
Damnit. Okay, let me see if putting in a base overload works...
 
Xeo
If a function in the derived class has the same name as a function in the base class, the base class function is "hidden", no matter the parameters
it's easy to solve though
using FooMerge::DoMerge; in the public part of the client class
 
@Xeo: Yeah, that fixes it
Damnit! I want to punch myself now
 
Xeo
heh
 
1:09 AM
Been struggling with this for almost 3 hours and it was something that dumb
 
Xeo
Shall I put it as an answer to your question? :P
 
Yes
:sigh:
 
Xeo
Kinda related (last example in the question): stackoverflow.com/questions/5368862/…
 
@Xeo: I didn't think it was supposed to hide that overload from the base class thogh
 
Hello again, Lounge.
 
1:26 AM
hi
 
@Xeo ROFL that's great
 
Makes me dizzy.
 
is c++ hard
 
So there I was, trying to be productive, and then someone posted this: _http://firstpersontetris.com/
 
1:34 AM
can sumone answer me plz
 
@user635064 That's an extremely subjective question.
 
@user635064 c++ is so easy, that we don't even have to talk about it in here. tetris, ugly houses and weight lifting are our favorite subjects
 
What programming experience do you already have?
If any?
 
for someone from objective-c background
and java
im starting cocos2d with box2d framework
 
It shouldn't be too bad.
 
1:35 AM
and it's in c++
 
It's a bit more low-level.
 
i dont understand memory management in it, there's no reference counting and no garbage collection, how can u clean up memroy after ur done with it?
 
and by low level he means no one is there to protect you from yourself
 
With the delete keyword.
For example:
 
delete is like calling dealloc in objective-c, u shud never do it unless ur caling super dealloc
from my understanding
 
1:37 AM
Manual memory management is mandatory in C++, so it probably isn't like dealloc.
I wouldn't know; I've never tried Objective C.
 
ok, well
how would you know wen to dealloc an object?
 
@user635064 you should always call delete on c++.
 
lets say there an object
and ur done with it
then u call delete
but what if there another object
holding a reference
 
if you used new to create the object, it's your job to delete it
 
to that object u just deleted
 
1:38 AM
Good design prevents that.
 
in case you are wondering, it's undefined behaviour
 
mexpm
 
In general, objects won't hold references to each other. If they do, the programmer never deletes it manually.
 
Xeo
@BillyONeal Funnily enough, I just made more points in night mode than in normal mode..
4.8k vs 4k
 
Classes are less for organization in C++ than they are in Java and Obj. C.
 
1:40 AM
in obj-c, i can track how many references are there for an object and when there are none dealloc is called. how would i do this in c++
 
Xeo
boost::shared_ptr
 
Shared pointers.
 
@user635064 Usually, by not dynamically allocating your objects.
 
Xeo
Oh yeah, and C++ has Boost.
 
Though, you really shouldn't need to do that.
 
Xeo
1:40 AM
Java/Obj-C don't
 
I can't think of a practical instance where an object would hold a reference to something the programmer could call delete on.
 
@luc, ah yes forgot u can allocate on stack in c++
 
@user635064 The rest of the time (usually involving class hierarchies), use a smart pointer as others have remarked
 
Xeo
@Maxpm Oh, I can think of many. You just wouldn't call delete on that reference, that would be the job of the thing that gave you the reference
 
1:43 AM
@Xeo Such as what?
 
For example, what I was wonder was this

_body = _world->CreateBody(&ballBodyDef);

now, say later on sometime in the program, I call _body again, but only to find out it's been deallocated by _world. How would I prevent this?
wondering*
 
Xeo
@Maxpm dependency injection?
 
@user635064 What does ballBodyDef represent?
 
@Maxpm ballBodyDef is struct (b2BodyDef)
 
@user635064 If _world owns whatever it returns then _body should only be used as long as it is guaranteed to be valid. If you want to use it later, take a copy of it, if applicable. If it's not applicable, this should be a design problem.
 
1:50 AM
To me, it very rarely makes sense to pass a pointer as an argument.
 
@Maxpm Unless of course you're dealing with a C APU
API*
 
Xeo
@Billy: as the newbie hints state, hit the up-key once to edit your last message within two minutes. :)
 
@BillyONeal Yeah, but that's a different matter entirely.
That's not really pertaining to C++ safe memory management, so much as it is compatibility with C.
I'll be right back. Ubuntu likes to forget about my speakers.
Back.
 
2:09 AM
@MaxPM: I've seen pointers used quite often -- so long as ownership of the pointer is clearly defined it's fine
For example, I've seen lots of patterns where there are a bunch of objects in a ptr_vector, and pointers to items get passed around. But since the ptr_vector owns the pointers, it does not lead to issues.
 
@BillyONeal But it's needless cyclomatic complexity whenever a reference could be used instead.
 
@Luc: What do you mean?
 
References can't be 0
 
Ah.. I don't check pointers for that
16
Q: In either C or C++, should I check pointer parameters for NULL?

Billy ONealThis question was inspired by this answer. I've always been of the philosophy that the callee is never responsible when the caller does something stupid, like passing of invalid parameters. I have arrived at this conclusion for several reasons, but perhaps the most important one comes from this ...

 
The complexity is still here, e.g. for reviewing/understanding the code.
I said nothing about checking in the code.
 
2:12 AM
I don't understand his problem
 
@Johanne: What problem?
 
he proses it as a choice between checking for NULL and leaving it undefined
 
"He" in this case is right here <-- :)
 
but the easiest thing to do is just document that NULL is not allowed as argument
 
Xeo
@JohannesSchaublitb And the easiest documentation of that is a reference, huh?
 
2:13 AM
@Xeo no
 
Xeo
Oh? Why not?
 
because then it'S not a pointer anymore
also I think sometimes it's obvious that a pointer is not allowed to be NULL and then I omit to document it
 
Generally speaking, if it's not documented to allow NULL, then you can't pass NULL. Period.
Everything not defined is undefined.
 
that makes sense
I think I implicitly follow it in my code, now that you mention it
 
Pointers are not NULL unless explicitly permitted otherwise.
Pointers actually point to what they purport to point to. If a function accepts a pointer to a CRITICAL_SECTION, then you really have to pass pointer to a valid CRITICAL_SECTION.
etc.
 
2:20 AM
I agree
if people say "the benefit of reference parameters is that you don't have to check for NULL" everytime they do that a kitten dies
 
Morning.
 
Xeo
Know what I really like? typedef shared_ptr<void> gc_ptr; :)
 
can you create a shared_ptr<void> without a custom deleter?
 
Xeo
Atleast my compiler says yes
 
what will it mean?
 
Xeo
2:34 AM
Well, you can stuff in whatever you want and it will be correctly deleted
 
Well.. that can't be
How would it know which destructor to call?
 
i always forget it has that nice feature
 
Xeo
default deleter
 
Might work for primitive types but I can't see it working in the general case
 
2:35 AM
@BillyONeal constructor template
 
Hmm?
 
type erasure
 
It encodes the type in the deleter.
 
@BillyONeal shared_ptr uses type erasure to abstract away the deletion so it can be used for incomplete types and void. Note that unlike e.g. std::unique_ptr<T, D> there is no deleter that is part of the type of std::shared_ptr<T>
 
Hmm... I really need to read that C++ templates book
That's the second time today I've been confused lol
 
2:36 AM
so given std::shared_ptr<int> p(new int), q(0, a_custom_deleter); you can still do e.g. p = q;
 
WTH?
Lol
 
man I'm so sick :(
 
@BillyONeal Do you want a quick proof-of-concept?
 
2:40 AM
@Luc: Xeo posted the proof of concept lol. I seriously need to read that book. Just bought it this morning while I was tearing my hair out due to template resolutoin issues
I wish there was a site like that that used MSVC++
Or rather, tried several compilers for you so that you could see if there were any differences
 
Xeo
@LucDanton I knew I had one any_ptr that acted like shared_ptr<void> in my huge unused.h file, where I basically paste everything I do for fun when I don't need it anymore (currently at 1.2k lines). But I don't find it anymore. :(
 
clang has MSVC++ compatibility mode
[js@HOST2 cpp]$ pwd
/home/js/cpp
[js@HOST2 cpp]$ wc -l *.cpp
..
8862 total
much crap in there though, so it doesn't count
 
pevFind (my own crappy little project I used to teach myself C++) clocks in at ~18k lines
Some HORRENDOUSLY WTF Code in there though
Really, everything in that whole file is one giant WTF
 
lol
 
:sigh: -- the things you write in sophomore year of high school
 
2:48 AM
if it's not a WTF after more than a month of not being maintained, you didn't learn enough in the meantime
 
Mmh.
I'd like to think my code is at least somewhat clean, but...
 
Lol -- there are degrees to that though
 
well
 
After a month it might not be the best. But usually it doesn't descend into WTF territory that quickly
 
2:49 AM
especially if it was learning material to begin with
some of the WTFs I wrote when I was learning, that's nothing
I had this idea that I wanted to copy the vtable pointer from the derived class to the base class
 
...
 
why I ever would want to do something so incredibly insane, I don't know
 
Xeo
My most recent WTF is the resource management system I wrote. :)
 
Hmm.. that borders on the insanity of line 62
 
Oh God, what.
 
2:50 AM
lol
 
That's like when I thought it would be a good idea to squeeze loops and if statements on one line if only one function/expression was called inside. For example:
 
@Maxpm That's a compile-time regular expression
Boost::Xpressive
 
@BillyONeal You probably wrote the BNF for that, took a great gulp of air, and just dove right into coding the spec without regard for the future.
 
Designed to recognize arguments like
-Something# some extra stuff with ## literal hash marks#
 
man
The Pirate Bay is down
 
2:52 AM
for (unsigned int Row = 0; Row < MaxRows; Row++) for (unsigned int Column = 0; Column < MaxColumns; Column++) if (Matrix[Row][Column] == 123) Foo(Row, Column);
 
Xeo
lol
 
At the time I wrote that I had not heard of state machines
 
Xeo
I once thought of doing if(bad_condition) return (optional_arg);
 
"Because inheritance is so important in object-oriented
programming it is often highly emphasized, and the new
programmer can get the idea that inheritance should be used
everywhere. This can result in awkward and overly-complicated
designs. Instead, you should first look to composition when
creating new classes, since it is simpler and more flexible. If you
take this approach, your designs will stay cleaner. Once you’ve had
some experience, it will be reasonably obvious when you need
inheritance."
 
Xeo
but I decided to split even that in two lines
 
2:53 AM
Actually, that solution is better than the one before it, which was a maze of loops and flag variables.
 
is this good advice?
 
@hexa: Yes
Inheritance is fragile and should be avoided wherever possible
 
A good point I came across a while ago was the square-rectangle inheritance problem.
 
I do think it's kind of funny that inheritance is all most OO textbooks talk about, and it's almost always the wrong tool to use
 
do not use inheritance, except in the case where references between two classes must be interchangable at run-time, do not do it just because you can and they might have some vaguely similar interface elements
 
2:54 AM
@Maxpm: Well, in that case you're just violating LSP
 
A square is a rectangle geometrically, so it's tempting to have a Square class inherit from a Rectangle class.
 
Xeo
Hah
 
@BillyONeal Yep, I was just about to say: Squares aren't like rectangles behaviorally, so inheriting would violate the Liskov substitution principle.
 
Xeo
prime example, even stated by Bjarne, that that is totally wrong. :)
 
how do they not behave like rectangles?
squares behave exactly like rectangles - they are rectangles - and then some more, maybe
 
Xeo
2:55 AM
invariants
 
Nope.
Consider the following function:
 
@DeadMG: setwidth on a square changes the height. setwidth on a rectangle does not.
 
@Billy: Yeah, I don't really see that as a big deal
the invariant of setwidth is that you changed the width
 
Maybe, but it should really not be called SetWidth though on a square
More something like SetSideLenght
 
well, it's true that you might be in for a surprise if you assumed that setting the width did not change the height
 
2:57 AM
Anything common between a rectangle and a square could be factored into a common ancecstor for the two
 
Xeo
@DeadMG principle of least surprice
 
But they aren't really interchangable
 
void Foo(Rectangle* MyRectangle)
{
    MyRectangle->Width = MyRectangle->Length * 2;
    assert(MyRectangle->Width > MyRectangle->Length);
}
 
but that's your own dumb fault
 
No, it's the fault of whoever keeps coming up with such toy examples of 'reification', as if software development were a kind of modeling.
 
2:58 AM
lol
 
@DeadMG: Not really. If you make a method that accepts rectangles, you're thinking about the interface of a rectangle. Not of a sequare
square*
 
Don't write a class hierarchy because there is a preexisting biological taxonomy or mathematical organisation.
5
 
Yep.
 
@Billy: The only thing guaranteed by SetWidth is that the width is increased
 
This stuff makes me foam at the mouth.
 
2:59 AM
if you assume that the height is constant, then you did it wrong
 
That's not true at all.
 
Why would the caller expect SetWidth to change the height on a rectangle?
 
@DeadMG What if you set a smaller width, or the same width as it previously had?
 
Something that sets the width should set the width, no more and no less.
 
Xeo
@LucDanton Wait, I shouldn't write class Human : Monkey? :P
 
2:59 AM
A function has every right to assume that.
 

« first day (258 days earlier)      last day (4707 days later) »