« first day (444 days earlier)      last day (4486 days later) » 

6:01 PM
Hmm, cranberry juice.
 
> @LightnessRacesinOrbit: For sto*, C++11 21.5/1: Effects: the first two functions call strtol(str.c_str(), ptr, base), and the last three functions call strtoul(str.c_str(), ptr, base), strtoll(str.c_str(), ptr, base), and strtoull(str.c_str(), ptr, base), respectively. – Mike Seymour ↵ 10 mins ago
Wat.
C++, I'm disappoint.
 
Yes, they use the C lib :(
 
Xeo
It's faster than the iostream lib, and they know it.
 
Why do they prescribe exact implementation all of a sudden?
 
It describes the behaviour easily.
And the as-if rule lets you implement it without actually calling the C lib.
 
6:11 PM
@sehe Thanks. Coco/R seems good.
 
@RMartinhoFernandes is there any way to know where (*this) has some base class or not?
 
@IntermediateHacker I can do you a few samples, time permitting :)
 
@MrAnubis Hmm, if you're using this you can just look at the class definition.
 
@RMartinhoFernandes class is made through recursive inheritance
 
@MrAnubis there is no portable way of doing what you'd like
 
6:15 PM
I'm not sure what that means, but it sounds like it has a base class.
 
unless you feel like trying to cast *this into all possible classes that it could inherit from
 
Xeo
@RMartinhoFernandes Why is expired not a good way to check if the parent is alive?
 
class foo : whatever_goes_here { // has a base class
 
@MrAnubis Rings of CRTP
 
class foo { // doesn't have a base class
 
6:16 PM
@RMartinhoFernandes from inside the class you should know if it has a base or not..
 
@Xeo Because if(!ptr.expired()) assert(ptr.lock()); may fail: think races.
 
@MrAnubis template<unsigned n> struct s; template<> struct s<n> : public s<n-1> {}; struct s<0> {};
 
@refp Exactly! And you can only use this from inside the class.
 
wait.. who's the original author of the question?
 
class foo : T... { // may or may not have a base class
 
6:17 PM
oh.. I thought @RMartinhoFernandes asked what was stated..
 
Xeo
@RMartinhoFernandes Meh, damn concurrency
 
@sehe Rings of CRTP ?(first looked like lord of the ring :D)
 
expired can be used to test if the parent was alive just a moment ago :)
 
The curiously recurring template pattern (CRTP) is a C++ idiom in which a class X derives from a class template instantiation using X itself as template argument. The name of this idiom was coined by Jim Coplien, who had observed it in some of the earliest C++ template code. General form // The Curiously Recurring Template Pattern (CRTP) template struct base { // ... }; struct derived : base { // ... }; Some use cases for this pattern are static polymorphism, and other metaprogramming techniques such as those described by Andrei Alexandrescu in Modern C++ Design. Static po...
 
Multithreading sucks.
 
6:18 PM
@sehe aah, Thanks
 
@CatPlusPlus It feels wrong when compared to multiprocessing.
 
@CatPlusPlus It's a necessary evil
 
Which is preferable for mutators and accessors in a class, the style int Property(); void Property(int newvalue); or int GetProperty(); void SetProperty(int newvalue);?
 
For sane concurrency, you need language designed from ground to be concurrent.
Like Erlang.
 
@SethCarnegie Ask your team.
 
6:20 PM
@SethCarnegie No mutators and accessors.
 
@CatPlusPlus what instead
 
Interface that doesn't suck.
 
@SethCarnegie proper objects that actually do something
 
If you need mutators, then your fields should be public.
And don't start the whole "but I might need to validate" crap.
You can encode that in the type.
 
What about when you need to do something when it's changed
So you should just have proxy objects then
 
6:22 PM
In general case, no.
 
An observer pattern?
 
@CatPlusPlus then what do you do when you need to update something when a value is changed
 
What value in where?
 
When the value of a member variable of an object is changed
 
What member variable?
 
6:24 PM
Any?
An int member variable or something
 
(If you're still missing the point — if you're poking member variables, then you're most likely doing something wrong.)
 
Hello all :)
 
That's why I have setters and getters
 
Same thing.
 
you're saying that you shouldn't have those
then what should take their place
 
6:25 PM
Proper interface.
 
Which is what
 
Unless you really are doing a container of variables.
 
There's an SO question about this somewhere.
Gimme a sec.
 
@RMartinhoFernandes thanks
 
It's impossible to say for a generic non-existent thing.
If you want to play, then show an example where you feel you need setters.
 
6:27 PM
How about a Player class for example, where you need to get and set the position of a Player
 
@SethCarnegie Immutable objects are almost always less error-prone than mutable objects. As a general rule I like to avoid setters unless really needed.
 
@SethCarnegie How about a move method with delta parameters instead of setters?
 
Setting a position by itself is meaningless.
 
Having a setter for the position means that players can beam anywhere.
 
In this game they can
 
6:29 PM
 
Also move is a setter behind a very thin mask, it doesn't provide an advantage worth having
 
Also, you don't strictly need getters if you're in love with lambdas ;)
 
No, it conveys meaning.
 
0
Q: Can lambdas replace getters?

FredOverflowHere is a classic example of a class with two getters for its fields: class point { int x_, y_; public: point(int x, int y) : x_(x), y_(y) {} int x() const { return x_; } int y() const { return y_; } }; int main() { point p(1, 2); std:...

 
@CatPlusPlus then how about the name of the player, if not the position
 
6:30 PM
@SethCarnegie It's a good name (which was your original question), though :)
 
@RMartinhoFernandes kinda
I was really asking if having a function with the same name as both setter and getter is OK
 
@SethCarnegie What game are you programming? Just curious.
 
@FredOverflow it's my hypothetical-game-for-the-sake-of-this-example, I'm not really programming one
 
@SethCarnegie If you must have getters and setters, at least use the established naming conventions.
 
@FredOverflow then that one is as good as any other?
the int X(); void X(int newx);
 
6:33 PM
It's not that you never have member functions that just update an internal variable.
 
@SethCarnegie I start with making objects immutable from the bottom up. I make my Rect, Point, Size, ... -classes immutable and keep postponing mutability while composing higher layer objects. Up until a certain point (probably near the end user interface) where, then there is a thin layer between the ui and the object model where the mutation takes place.
 
But in general case, that's useless, and classes full of them are usually just badly designed
 
@SethCarnegie Conventions are just conventions. Personally, I wouldn't overload the same name for both getting and setting, but that's just my opinion.
 
Arghh, my Internets is having another fit of slowness.
 
@CatPlusPlus setting the name of a player wouldn't just update an internal variable, it would do stuff like send the new name to all the other players, etc
 
6:34 PM
You could also use int& X(); and use the same method for getting and setting, sort of like an operator[].
 
@FredOverflow for non-member variable getters though, you'd have to use a proxy object
 
@SethCarnegie rename!
 
Guys , Is there a cheap way to insert data at random places in a text file ? (one that would not involve buffering everything after the insertion point and then rewriting it)
 
Then you can say std::cout << player.name() (as a getter) and player.name() = "awesome-o"; (as a setter).
 
@RMartinhoFernandes and to get the name?
 
6:34 PM
LOL
 
@SethCarnegie What are non-member variable getters?
 
@FredOverflow But that doesn't allow for the after-set stuff.
 
@CatPlusPlus Why not? Just return a proxy object.
 
6:35 PM
@FredOverflow in my case the value is calculated, not stored
 
Then why bother with a member function? :P
 
@SethCarnegie If it's calculated, it's not a getter, is it?
 
@SethCarnegie You mean it's an implementation of the observer pattern. I generally find that to be among the most error-prone parts of any program.
 
what?
@FredOverflow it's a getter for all intents and purposes of the clients
 
@angryInsomniac erm... no? Unless you count pre-inserted zero-width spaces (UNICODE) that you can replace with the 'actual' text?
 
6:36 PM
If it calculates something unrelated using an object, then it's a candidate of free functioning.
 
@FredOverflow It's not a stupid "pass-through" getter that you usually see in Java code. Still counts as an accessor.
 
> Often a "setter" is accompanied by a "getter" (also known as an accessor), which returns the value of the private member variable.
Sorry, but as soon as a member function does even a tiny bit more than returning a field, it's not a getter anymore.
 
@FredOverflow whose definition is that
 
@TonyTheLion that's a serious WTF. Craziness: amazon.com/review/R16G6MG9QILUDT
 
@SethCarnegie mine and Wikipedia's
In computer science, a mutator method is a method used to control changes to a variable. The mutator method, sometimes called a "setter", is most often used in object-oriented programming, in keeping with the principle of encapsulation. According to this principle, member variables of a class are made private to hide and protect them from other code, and can only be modified by a public member function (the mutator method), which takes the desired new value as a parameter, optionally validates it, and modifies the private member variable. Often a "setter" is accompanied by a "getter" (als...
 
6:38 PM
@TonyTheLion What the fuuuuuck.
 
@FredOverflow I thought the words "getter" and "setter" were related to the interface, not the implementation
if not then sorry for the confusion, but that's what I've been calling getters and setters
 
Well, I'm not an expert on getters and setters, because I avoid them like the plague.
 
You actually believe Amazon reviews?
Lol.
 
@sbi likes to throw this link around: idinews.com/quasiClass.pdf
 
 
6:40 PM
Also amount of people who don't know how to spell "lied".
 
@FredOverflow I don't really see the horrible difference between SetPos(int x, int y) and X(int newx); Y(int newy);
 
@CatPlusPlus Copy cats? Russian copy cats?
 
@sehe According to Poe's Law, he could also be an idiot.
 
@EtiennedeMartel It that the one "never attribute to malice what can be attributed to sheer stupidity"?
 
@SethCarnegie Then simply do whatever works best for you.
 
6:41 PM
> Without a winking smiley or other blatant display of humor, it is impossible to create a parody of fundamentalism that someone won't mistake for the real thing.
 
@FredOverflow Well obviously everyone else is seeing that the first is awesome and the second is death, but I don't see the reason, is it just some personal opinion of what is meaningful?
 
@SethCarnegie Really? I say both are equally horrible. You should not even have int x, y; members, you should have a Position member.
 
@FredOverflow and then have x and y in the Position? That's just one level of indirection that doesn't change what we're discussing that I can see
 
There is no indirection implied in C++.
 
6:44 PM
And yes, getters and setters are still evil. Offer meaningful methods such as move or whatever.
 
Semantics matter.
 
I mean it's just using a container to contain them instead of storing them directly
 
Xeo
template<template<class...> class... VVTT>
Y'know, this looks kinda awesome
 
I thought it's named WTF for a second.
 
I think it was.
 
6:45 PM
It's V V T T.
 
Ok, it's not edited. I really thought it was WTF.
 
@SethCarnegie But that does not imply indirection. An object containing two ints and an object containing an object containing two ints have the exact same memory requirements in C++ (whereas the second version uses more memory and an additional level of indirection in Java).
 
Xeo
Variadic variadic template template parameter
 
The further you are from screen, the more it looks like WTF.
 
@Xeo (Variadic (variadic template) template) or (Variadic (variadic (template)))?
 
Xeo
6:45 PM
They even work like you expect them to!
 
@FredOverflow I'm not talking about an indirection in the code to use them, I mean it's just moving x and y one step away from the class that would hold them but instead holds a Position
 
Now we need a language that parses differently according to the physical position of the user.
 
You still need getters/setters
or the equivalent
 
Let's call it Chair.
 
@CatPlusPlus still can't get the second T to look like an F..... unless you have lexciadysi.
 
6:47 PM
@Xaade It's more of a self-suggestion.
 
Xeo
@StackedCrooked (Variadic (variadic template template))
 
You see "WT" and expect F.
 
@CatPlusPlus I see WTT, as in wanting to trade. Too much mmo.
 
@EtiennedeMartel Comedian. Definitely. Some are quite funny. Some even get rated 'helpful' - go figure. Same guy:
 
Could be related to the the "not seeing double the" thing.
 
6:48 PM
just skip FTW and go with TVVAT.
 
@SethCarnegie Yes, but that's an important concept of object oriented programming. You don't want an x and a y integer inside a Player, you want a Position. If you store ints inside a Player, you mix responsibilities.
 
Generic programming wins anyway.
 
Suppose you want a function that returns a Position. You really want a proper type for that. (Of course technically, you could just return std::pair<int, int>, but that's just a hideous workaround.)
 
I like Factor OO/generic model.
 
@FredOverflow I agree, but then it becomes the Position's responsibility to notify the Player that it's changed
 
6:49 PM
@FredOverflow if the goal is OO, then you should be as OO as possible. Whether that means OO as in physical expectations, or OO as in task oriented objects...
 
@SethCarnegie Depends on how the renderer is done.
 
@CatPlusPlus Which Google terms should I use to learn more about this? (These don't work.).
 
Player::move.
 
@SethCarnegie unless you have a setting in Player that notifies after setting and don't let public access to position.
 
@SethCarnegie How could you possibly change the Position without the Player knowing?
 
6:50 PM
Also, pull model is better than trying to push data around and still remain loosely coupled.
 
@EtiennedeMartel true, but you can think of something else like a the name of the player, or whatever
 
Which also invalidates the need of notifying setters.
 
@FredOverflow if it's just a member variable then how could you know it's changed?
 
@SethCarnegie By not exposing the member variable? The Player is responsible for changing the Position, that's the whole point of OO.
 
6:51 PM
@SethCarnegie because public member variables are evil.
 
@FredOverflow now aren't we back to setters and getters?
or did I miss something way back there
 
But then again I'm the opposite of @Fred. I'm pro getter/setter.
 
Theoretically you could also provide the player object with a callback that returns its current position. So the state is stored outside of the object. (Not saying that this is the best method for you, but it can work well in some situations.)
 
Maybe we should talk about the client. Who calls player.setPosition and why?
 
6:52 PM
However, I've never played a game that needed a real setter. It's always a move to this point relative to current position. The only setter is a spawn point, then it's just set to spawn.
 
The player moves, or the player sets his name (in the case of a name)
 
Maybe we should talk about the client. Who pays for the setters/getters, and why :)
 
@SethCarnegie "The player moves" already implies that the Player class should have a move method, doesn't it?
 
Xeo
I think we should talk about VVTTs. :)
 
6:53 PM
If you have an hour.
 
@Xeo Pervert!
 
@CatPlusPlus Cool, I'll check it out.
 
@FredOverflow yes that's why I mentioned the name
 
Xeo
@sehe Template wankery ftw.
And it even looks like it might be of use
 
Player.Spawn(Position);
Player.Move(Offset);

I still don't see a need to set position. If you're setting to a position, there's always more work to be done than just setting to a position.
 
6:53 PM
I wrote Gray code generator in a notebook in a class today.
 
@Xaade I abandoned the position example, what about the player's name
there might be a problem with that example too, I don't see it yet though
 
@Xeo Certainly does. You can make the compile cycle slow down to lengthen lunch break. Yay
3
 
@Xaade Instead of Player.Spawn, we could just use a constructor, couldn't we?
 
@FredOverflow Player may already exist, unless you're separating the rendered object from the data object.
 
@SethCarnegie If you need to change the name, sure, write a setter. No kitten is going to die.
 
Xeo
6:55 PM
@sehe That, but I rather thought of policies or somesuch stuff
 
:2268076 template <typename T> using bar = foo<T, Something>;?
 
You're changing the name and doing nothing else. Updating the rendering, resorting some list, etc.
 
@CatPlusPlus Is that c++ 98?
 
C++98 is old.
 
6:56 PM
No checks on the name. Maybe you don't want two players named the same, etc?
 
@FredOverflow ok, and to make sure, there is no widely known issue with using the style int X(); void X(int newx);
 
@CatPlusPlus What I was looking for.
 
@Xaade are you talking to me, or someone else, I can never tell in this chat
 
In C++03 you need to write entire new template and lots of boilerplate.
 
@SethCarnegie I can always find reasons why a pure setter/getter should be expanded into a proper method.
 
6:56 PM
@SethCarnegie I have never seen that style before. But that doesn't matter. The important thing is that your team has a common convention that everybody ascribes to.
 
@RMartinhoFernandes Still, I'm new to both 03 and 11. 98 Is in my marrow.
 
Xeo
Holy.. I just got a great idea for VVTTs.
 
@SethCarnegie I've never seen that style either.
 
More invites \o/
 
03 and 98 are more or less the same AFAIR.
 
Xeo
6:57 PM
Let me play around a bit..
 
@Xaade I was never meaning a "pure" getter or setter, see my previous conversation with FredOverflow about the definition of getter and setter
 
@CatPlusPlus 03 has value initialization or something :)
 
@CatPlusPlus true.
 
I've never paid any attention to 98.
 
6:57 PM
@SethCarnegie If you have both a pure getter and pure setter, you have a public variable. You've done something wrong.
 
@CatPlusPlus I'm at least 5 years older than you =)
 
Back in 98 I wasn't programming yet! The world was so much better.
 
@Xaade I just said, it's not a pure getter and setter
 
@CatPlusPlus I think I'm gonna invent my own currency and call it "attention".
 
@FredOverflow Internet karma!
 
6:58 PM
@RMartinhoFernandes I was following an optional Pascal class during lunch breaks at that time.
 
I'm going to determine how to fake bitcoin
 
@Xaade Yes, and I won't tell anyone if you give me 10% of your profits.
 
With aliens.
 

« first day (444 days earlier)      last day (4486 days later) »