« first day (442 days earlier)      last day (4489 days later) » 

12:09 AM
0
Q: Happy New Year, fellow Software Developers :)

AndreyHappy New Year everybody and let all your dreams come true!

25 seconds and counting
too bad we can't bet rep to see how long it will last
lol
2 min. and gone...
 
Xeo
LOL ->
 
+5/-2, answers gets pwned... lol
 
user142019
haha!
 
user142019
Vote to undelete and reopen.
 
12:28 AM
Good::time_of_day;
if/else/ad/infinitum
 
12:40 AM
0
A: What implementation do you use when dealing with operators in .Net?

DeadMGIt's possible using type tags. Here we "tag" each operation with a specific type which tells the C# compiler that this operation is available. This enables us to add arbitrary operations which do not depend on any casts or conversions. public class Addable<T, U, Result> where T : Num...

opinions?
 
Lol at the ""MyNumber + otherNumber" could be any of half a dozen different things" answer.
 
I know
downvoted that nubborini
 
12:51 AM
I think that question would benefit from some information about Marc Gravell's use of expression trees to handle generic parameters and arithmetic operators.
 
1:33 AM
struct s { };

const s& f()
{
    s obj;
    return obj;
}

int main(int /*argc*/, char* /*argv*/[])
{
    s o;
    o = f();
    return 0;
}
why do i get a warning about the returned reference?
gcc461
 
Xeo
Because references in return values don't extend the lifetime of anything?
it refers to an object that dies at the return statement
It's like asking someone for their phone number and shooting them directly after obtaining it. If you call now, noone will answer.
 
it's a const reference, may i point out.
 
Xeo
doesn't matter
 
so it does extend the lifetime of the object.
 
Xeo
no it does not
First, only the lifetime of temporaries is extendable through references
Second, even that only in some special circumstances
namely, function parameters and local variables
 
Xeo
...
> Normally, a temporary object lasts only until the end of the full expression in which it appears. However, C++ deliberately specifies that binding a temporary object to a reference to const on the stack lengthens the lifetime of the temporary to the lifetime of the reference itself
 
c++ does not define who puts the object on the stack, the caller or the function body.
 
It doesn't matter, obj is not temporary.
 
i'm getting the same warning wether i use a temp or not.
 
You can't return a reference to a local automatic variable, const or not.
Even if const T& foo() { return T(); } worked, it's overcomplicating the code. T foo() { return T(); } is an RVO candidate.
 
1:56 AM
this is not a performance thing i'm trying to achieve.
i'm writing an input iterator's operator*() const
T const& oeprator*() const
 
Xeo
There are two contexts in which temporaries are destroyed at a different point than the end of the fullexpression. The first context [...]
The second context is when a reference is bound to a temporary. The temporary to which the reference is bound or the temporary that is the complete object of a subobject to which the reference is bound persists for the lifetime of the reference except:
— A temporary bound to a reference member in a constructor’s ctor-initializer (12.6.2) persists until the constructor exits.
§12.2 [class.temporary] p4 & 5
 
I (don't think) I can have the T object a member because at the point of construction I still don't know what it's going to be.
 
Input iterator doesn't have to return a reference in *a.
 
Xeo
^this
 
that paragraph agrees with what i was saying.
well it's a big paragraph.
 
Xeo
2:06 AM
No it does not oO
 
the example.
C const& cr = C(16)+C(23);
is well defined
 
Xeo
Sure, that's what I was saying all along
C const& foo(){ return C(); }
however is not
> — The lifetime of a temporary bound to the returned value in a function return statement (6.6.3) is not extended; the temporary is destroyed at the end of the full-expression in the return statement.
If I may quote again
 
ok.
so my error is that i have to return by value, and only then i can capture with a const ref.
 
Xeo
correct
 
why do standard input iterators return by const reference?
i guess it's because they have the data as a member so they might as well.
 
Xeo
2:12 AM
Seems like a good rationale
 
Because they can.
 
yeah. i was following blindly the implementation istream_iterator in implementing a custom input iterator that behave somewhat analogically. i'll just return by value here.
it's an input iterator so *i = x; isn't allowed anyway.
 
Xeo
In C++03, it's still possible for user-defined types
 
for performance if i can add a move ctor to the return type then that'll get me totally covered. but i'm not worried about it now.
mm?
 
Xeo
In C++11, that can be disabled with T& operator=(T const& t) &; to only overload for lvalues
struct X{ X& operator=(X const&){ return *this; } };

X foo(){ return X(); }

int main(){
  X x;
  foo() = x; // valid, but useless
}
In C++11, we can do X& operator=(X const&) &{ return *this; } to only enable assignment on lvalues
 
2:19 AM
you can return by const value
 
That's meaningless.
 
@Xeo that would also take rvalues unless you have a move ctor or move assignment
 
Xeo
@wilhelmtell No, that will not take rvalues as the lhs
 
no, for the rhs
 
Xeo
Well, who cares about that?
 
2:20 AM
oh i see what you mean
but const X foo() forbids foo() = x
 
Xeo
Yeah
 
but it's pointless to go this way, nobody does that. it's as pointless as foo()=x;
so yeah.
 
What's the point of that const?
 
only to forbid the return value being on the lhs. but it's stupid, yeag.
 
Xeo
Not only that
But it would also disable move construction
X&& won't bind to X const
 
2:27 AM
i don't feel yet i have a full grasp of rvalues, so i never wrote a move ctor. i feel different people give different rules of thumb on how to use these. some say there's no rule of four or rule of five, that it's a hopeless attempt at over-simplifying things.
 
sbi
@Xeo Oh. My. God. Am I really that old?! Is this already the age where programmers have never even heard of Uncle Bob? What about Verity Stob, do you young folks have heard of her? Margaret Ellis? Barbara Liskov? James Coplien? This is depressing.
@DeadMG "Flying fuck", eh? Yawn.
 
so for now i keep with the rule of three, knowing my code is correct if not entirely ideal in terms of performance (but fast nonethless), and wait until there's a simple rule to follow.
 
I've heard Barbara Moo was invented by cows.
Or the other way around.
 
Barbara Liskov is a fine lady. It's still a good mental excercise for me to find violations of the Liskove principle, and it's still fun to point them out.
 
Xeo
@sbi No, no, no, no.
 
2:30 AM
On a related note, few things irritate me more than inheritance for reuse.
 
Xeo
I know that Liskov principle thingy though
 
maybe radio ads do. but little else.
 
I wouldn't remember these people even if I had heard of them.
But then again, both my long- and short-term memory seems to be malfunctioning at times, so there's that.
 
sbi
@Xeo You have much to learn about, young acolyte.
 
I forgot where I was going with that, for example.
 
Xeo
2:33 AM
@sbi It's great to be young, isn't it?
Oh, wait...
 
The computer industry history is kind of reversed, in that it starts with old people having thoughtful and deep ideas, and ends with young kids doing dumb, superficial, meaningless things.
 
They weren't all that old when they had these ideas.
 
sbi
@wilhelmtell No, that's wrong.
At any time there's always only been a few people who will be remembered when they are old. Of course they were old when they were remembered. However, that doesn't mean it's only been old people who had good ideas.
 
then s/old/bearded/g
 
Programmers are lazy, and when you're lazy, you're bearded.
That's how this works.
 
sbi
2:36 AM
@wilhelmtell Doesn't work. Many never had a beard.
 
name one.
 
Any female? :P
 
torvalds doesn't count. he's an exception to the rule.
 
sbi
@wilhelmtell Barbara Liskov? :)
 
ok liskov, and lovelace. that's it.
@sbi remember lovelace?
 
sbi
2:37 AM
Off the top of my head? I don't think Stroustrup had a beard.
@wilhelmtell I'm not that old. (I had to learn Ada, though, as a student.)
 
lol
so you know ada? biblically? there's a double meaning in that.
k sry that was wrong.
 
sbi
@wilhelmtell I know this Ada. I also knew a little girl named Ada once. That was in the 90s, though. And her last name was not Lovelace.
@wilhelmtell Oh, Scott Meyers doesn't have a beard either. Not sure whether you'd count him as having "had thoughtful and deep ideas", though.
 
Is Ada as painful to write as it looks?
 
no, but he's very good at expressing existing ideas.
stepanov had marvelous ideas and had no beard.
my thesis is collapsing. but i will not shed a tear. i am a dignified scientist who will jump ship when necessary.
 
sbi
@CatPlusPlus It's, um, let's say: wordy. It's rather strict, though, from my memory. However, I had to learn it >20 years ago, I was an unexperienced student back then, and it was before Ada95 (OOP), so take my opinions with a pitcher of salt.
@wilhelmtell Your so-called "thesis" never had the chance to develop into something that could collapse.
 
Xeo
2:44 AM
*pinch of salt
 
sbi
@Xeo No, I was referring to a pitcher on purpose.
 
Xeo
lol
 
i always say "a bucket of salt". sounds funnier to me, donno.
 
Xeo
Oh btw, @Stacked said he'd like to come to a meetup in january if possible. @DeadMG muttered something like that too
 
where?
 
2:46 AM
I don't have to say that, because nobody takes my opinions seriously, anyway.
 
aren't they australian? :(
 
Xeo
@wilhelmtell IIRC @DeadMG is britain, and for @StackedCrooked ... it's somewhere 10hours by car away from berlin
 
@Xeo It's true that I'd like to come. But don't take that as a promise.
 
Belgium, AFAIR.
 
Xeo
@StackedCrooked I didn't :)
 
2:47 AM
yeah the german guys here could easily make a proper meetup, there are lots of smart germans on so. not so many from canada :(
 
@CatPlusPlus Ghent, Belgium to be precise.
 
Xeo
@wilhelmtell We're spread far and wide throughout Germany though
 
sbi
@wilhelmtell Now now, a bucket would be overdoing it.
@Xeo When looked at from a Canadian POV, this might seem pathetic.
 
Xeo
True enough
 
lol
 
sbi
2:54 AM
Well, I'm all in favor of a Berlin meetup. @Björn said he'd also be interested.
Maybe @Tony would also like to come once more? (He was at a meeting of @Konrad, @Björn, and me, once.)
Konrad is now with Uncle Karl, I think, so he probably wouldn't attend a Berlin meetup.
 
Xeo
@Tony said that he won't be able to come if it's in January
 
sbi
@Xeo Ah, Ok.
@wilhelmtell You could meet with Kate Gregory and Anna Lear. :)
If we meet in January, for me the weekend 20th/21st/22nd would be best. On that weekend I could also house one guest again. That person should be willing to be content with sub-hotel standards (this is a household fully of kids, and @Stacked with his allergy might have no chance to wake up in the morning), though, and shouldn't mind to be given breakfast by a grumpy old man in the morning. :)
 
Yeah I saw a tweet of @Konrad about a video, tried to click the link and got an error for being in the wrong country. I did learn @Konrad was in the UK at the moment, but wasn't so happy with my choice of country at the moment.
 
Xeo
Fuck YouTube.
 
sbi
@Xeo Flying?
 
Xeo
3:02 AM
Seriously, in Germany every second Video gets blocked because it might feature music content that might not be licensed by the all-mighty GEMA.
Now that I think about it...
Fuck GEMA.
 
i hate those.
 
You'd just fuck everything.
 
the UK does this all the time.
it's like the inverse of the new govermental propositions of the canadians and americans. but it's as bad.
i mean, blocking incoming content and blocking content from outsiders is as evil and stupid. and ugly.
 
Any national restrictions on the Internet are stupid.
 
granted, proxies fix that. but still.
just goes to show how stupid they are.
i don't make decisions about the government's military. i wish the government would refrain from making decisions about my internet.
</rant>
 
3:07 AM
Factor has an interesting Unicode implementation. With 21-bit characters.
 
the programming language?
 
@sbi Anything in your house that I might be allergic to?
 
Well, the implementation of it.
 
sbi
Booking flights to Cambridge … one way! No return. Huh :)
 
first learnt about factor from zed shaw
in 2006
oh
really
 
Xeo
3:08 AM
@StackedCrooked Children?
 
sbi
@StackedCrooked Dust. This is a household full of kids. There's lots of dust.
@Xeo Not on that weekend.
 
A character is 8-bit with MSB cleared if it's ASCII, but for > 127 the highest bit is set to 1 and the rest is stored in another vector.
 
Xeo
@sbi Ah, that's why?
 
@Xeo Perhaps. I haven't been tested for child allergies. :D
 
sbi
@Xeo It's not about my flat being empty, it's more about me not needing to worry who would watch over the littler ones. I hate to bother the older kids with their siblings when they had no saying in their making.
 
3:09 AM
why does operator->() return a pointer?
 
Because it's weird.
 
sbi
@wilhelmtell It only does so for user-defined types. :)
 
operator*() returns by value now, but then ... what about operator->() which returns a pointer?
udt?
user data type
k
 
User-defined type.
 
sbi
No closures in Java 7? (sigh). Time to change the name to JOBOL.
 
3:11 AM
but why?
 
sbi
Finally found that tweet.
 
but why is it that it returns a pointer?
 
Xeo
@wilhelmtell It's just specified like that in the standard. operator-> must return a pointer or an object that is convertible to a pointer or overloads operator->
 
sbi
@wilhelmtell What else would you propose?
 
Xeo
So that ultimately the member of something can be accessed
 
3:13 AM
right now i have const T* operator->() const { return &(operator*()); } and that's... a problem.
 
@sbi What is the difference between a closure and lambda again?
 
Xeo
@wilhelmtell Input iterators don't need to provide operator-> IIRC
 
lambdas are an implementation of the closure idea
iirc
 
Xeo
Because they're one-pass iterators, calling operator*() a second time would already be problematic
 
Closure captures its surroundings. Lambda can be just an unnamed function.
 
3:14 AM
or, that closure is the type, and lambda the object. or something to this extent.
 
: pile-of-poo ( -- ch ) CHAR: \u01F4A9 ;
I'm so proficient in this language.
 
@CatPlusPlus So in C++11 [&](){} is a closure? (Because it captures its surroundings.)
 
@Xeo huh? are you sure about this? i don't think.
 
Xeo
@StackedCrooked a lambda expression is always a closure object. And the type of it is the closure type
no matter what you capture
Atleast in standardese
But yes, that's what would be called a closure
@wilhelmtell Lemme check
 
@StackedCrooked Yeah. Though it doesn't extend the lifetime of captured variables, which is, well, bad.
 
3:15 AM
istream_iteartor has it
 
Xeo
Only because they have it doesn't mean it's required.
 
if you have operator*() for reading then it only makes sense to also give operator->()
i'm sure it is
 
It is.
 
the stadard gives a table of the requirement of iterator concepts. it's there.
 
Xeo
> a->m (*a).m pre: a is dereferenceable.
Yeah
 
3:17 AM
so, this means that operator*() of an input iterator must return a (const) reference.
 
Xeo
not necessarily.
 
because of opeerator->()
then how would i fix operator->() to return a pointer, pardon me asking?
 
You can return a proxy.
 
Xeo
proxy operator->(){ return **this; } where proxy overloads operator-> too and contains a copy
 
Xeo
3:19 AM
The operator-> return rules are applied recursively to the return type
 
**this?
 
*(*this).
 
you mean return proxy() ?
 
Xeo
so that you ultimately end up with a pointer.
 
Well, you'd return a proxy from operator*, too.
Code reuse.
 
sbi
3:19 AM
Note to self: It's not enough to plug the power cord into the laptop, it must be plugged into the wall, too. Or it gets dark very suddenly.
:(
 
Xeo
@wilhelmtell *(*this), *this makes a reference out of the pointer, and then operator*() is called on that. :)
 
and that proxy implements operator->()
?
 
Xeo
Correct
 
And is convertible to T.
If you're returning it from *.
 
sbi
Haha, I like that:
My new year's resolution is 1920x1080.
2
 
3:21 AM
That's so last year.
 
Xeo
struct proxy{
  X _x;
  proxy(X const& x) : _x(x) {}
  X* operator->(){ return &_x; }
  operator X&(){ return _x; }
};
As an example
 
_x lol
 
Xeo
That's my convention for private member variables
 
no it's your standard library's :p
 
Xeo
> *a convertible to T
 
3:22 AM
k
 
Only _Foo and __foo are reserved.
 
Xeo
@CatPlusPlus or fo__o
 
i can have T implement operator->(), but have operator->() private and the iterator a friend of T. so operator->() doesn't pollute T.
 
sbi
@Xeo While it's allowed for member variables, it's not allowed in other contexts, and hence not recommended. (Just switch to x_. Same difference.)
 
Which is a silly and unnecessarily complex rule ("identifiers starting with an underscore are reserved" was apparently not confusing enough).
 
Xeo
3:23 AM
@sbi It's only disallowed in global namespace
And really, who puts their stuff there?
 
sbi
@CatPlusPlus _foo is also reserved in global namespace. #
 
no it's dissallowed in any scope, to allow for macros.
 
My point stands.
 
Xeo
no
 
sbi
@Xeo Do you apply this convention to all private members, or just to data?
 
Xeo
3:24 AM
only data
I didn't like the m in m_foo, so I dropped it
 
I just name it foo.
 
Xeo
Now I only have to type _, hit ctrl-space and have all my private members presented to me
@CatPlusPlus foo is reserved for local variables and parameters
 
sbi
@Xeo I used to do this to everything private, which, after refactoring, made functions and types end up at namespace scope. So I switched to x_ instead. Nowadays I just use x. If this is too confusing, then the code is smelly and needs refactoring.
 
Xeo
@sbi namespace scope allows _x
Only global scope does not
 
sbi
@Xeo Except for the global namespace.
 
Xeo
3:26 AM
Yeah, but like I said, who puts their stuff their?
 
Less rules to remember the better.
 
How bout anonymous namespace in the global scope?
 
sbi
@Xeo Have you ever maintained a several MLoC codebase? With some of the code from before C++98?
 
Xeo
@sbi You know I don't
@StackedCrooked That's an interesting question.
Theoretically it should be allowed
 
@Xeo I believe boost bind's _1, _2, etc... are defined like that.
 
3:28 AM
Oh, look, yet another corner case in C++.
 
Xeo
@StackedCrooked Yep
 
sbi
@Xeo Nobody is going to refactor 3 million lines of working code just because there's a new C++ standard released bringing in new features.
 
@Xeo operatorX&() ? you mean operator*()
 
No, it must be convertible to X.
It's already a result of operator*.
 
Xeo
@wilhelmtell No, conversion operator
 
3:30 AM
what a post is flagged here and popup asks me if "it's valid or not", do they as if the post is valid or if the flag is valid?
 
Xeo
Oh, @DeadMG is just 6 points short of 50k!
 
Flag.
 
well i made X itself the proxy of itself
so X defines operator*() and oeprator->()
 
Xeo
@wilhelmtell You shouldn't do that
 
because it's already a proxy of sorts.
 
3:31 AM
ProxyProxy.
 
Xeo
A proxy to itself is just... wrong.
I mean, c'mon, it would allow stuff like this:
 
So meta.
 
Xeo
X& x = *it; x->member = foo;
Ah, no, wait, you talked about making it private, right? That won't work though, since operator-> won't be called from the iterator, but from the user
 
was thinking
right now it's not
 
Xeo
see the edit
 
3:33 AM
no the user calls the iterator's ->
 
Xeo
yes, which returns the proxy, on which operator-> gets called
 
yeah. and the iterator would be a friend of the proxy.
i thought.
but didn't do it yet.
it's public right now.
 
Xeo
It won't work
 
well actually
umm
 
I'm beginning to like Factor very much.
 
Xeo
3:35 AM
You can't make it private
 
what about
 
Xeo
Also, it would tightly couple X and your iterator class
which is always bad
Just make a damn proxy
 
posted on January 01, 2012 by Alf P. Steinbach

The WordPress.com stats helper monkeys prepared a 2011 annual report for this blog. Here’s an excerpt: A New York City subway train holds 1,200 people. This blog was viewed about 5,500 times in 2011. If it were a NYC subway … Continue reading →

 
3:57 AM
Getting a bunch of new code to compile cleanly the first time is scarier than when it doesn't.
i should compile more often in between just to get the errors i expect to get and know i'm on the right track.
 

« first day (442 days earlier)      last day (4489 days later) »