Is it really greater or equal?
-
Sometimes, or rather quite often, Bernie fails to understand the winding pathes of the thought patterns of his colleagues. Can someone try to clarify what following code could be expected to do:
if (BufferId >= m_MaxBufferId) { m_MaxBufferId = BufferId; } if (BufferId >= MaxBufferId) { BufferId = 0; m_NextBufferId = MaxCacheId; } BufferId++;
Why do you need to check two times?
Ah, it's just an obfuscation:
private long m_MaxBufferId; internal long MaxBufferId { get; set; } = 4 *86400*200;
Well, we're doing Clean Code. And Clean Code is about readability: "You know you are working on clean code when each routine turns out to be pretty much what you expected." (Robert C. Martin)
Bernie knows he's working on really clean code when each routine turns out to be pretty confusing and obfuscating what it is expected to do.
-
@berniethebernie It looks like something managing a circular collection of buffers?
Admittedly, names like "CurrentlyHighestBufferId" and "BufferIdLimit" might have been better but remember that there are two difficult things in IT: cache invalidation, naming things and off-by-one errors.
-
I stopped reading at
m_
.
-
@topspin said in Is it really greater or equal?:
I stopped reading at
m_
.I’ve never understood why people are so afraid of the
m_
prefix. If you have dumb properties, then just switch to an autoproperty and get rid of the backing variable entirely. And if you have smart properties, surely that extra prefix to make sure you don’t reference the field instead of the property in error is A Good Thing?
-
@jbert Exactly, that's what this SSD (senior software developer with 1 year of experience, and that 20something times) said he wanted to achieve. And yes, there are some difficult things with that - it just fails so often...
-
@unperverted-vixen
The way I've seen it used is people prefix members with m, function arguments with a, statics with s, and locals with l. Which is just as annoying to read as Perl sigils.
Instead ofm_szName
just writename
and be done.
If you have problems telling your locals and members apart, I think that's not your only problems.Filed under: completely off-topic
-
@topspin said in Is it really greater or equal?:
If you have problems telling your locals and members apart, I think that's not your only problems.
If your IDE also can't tell, you're going to want to fix that Sooner Rather Than Later.
-
@topspin said in Is it really greater or equal?:
The way I've seen it used is people prefix members with m, function arguments with a, statics with s, and locals with l. Which is just as annoying to read as Perl sigils.
Instead ofm_szName
just writename
and be done.I tend to agree with the idea that you shouldn't burden the name with stupid and obvious (to the IDE) chars, but I still find some value to some lightweight differences, as it makes obvious when jumping from one class/file to the next that a variable is of a given "type" (as in, member etc., not int/float/...). I find that looking at one file where
name
is a member variable and then moving onto the next one wherename
is a local one can be very very slightly confusing, more than if the first one was calledmName
orname_
or whatever. Not a lot, really, and the different colours style etc. in the IDE make the difference clear, but still. Every little helps.The other thing is that apparently everyone completely mis-understands Hungarian notation in that you're not expected to prefix (postfix, whatever) e.g. all strings by "s", but e.g. all input strings by
i
and output strings byo
or something like that. If used like this, it does make much more sense. But nobody uses it like that, so it's dumb.
-
@unperverted-vixen said in Is it really greater or equal?:
I’ve never understood why people are so afraid of the m_ prefix. If you have dumb properties, then just switch to an autoproperty and get rid of the backing variable entirely. And if you have smart properties, surely that extra prefix to make sure you don’t reference the field instead of the property in error is A Good Thing?
Why not just use an IDE and stop writing code like it's fucking 1983?
-
@blakeyrat Umm... how do you get "not using an IDE" out of that?
-
@masonwheeler Because an IDE makes it simple to look at the variable name and see if it's a local, field or property?
-
@jaloopa ...and using a naming convention makes it even easier.
-
Being colorblind, the IDE approach fucking sucks if I ever have to look at it on someone elses machine.
-
@remi said in Is it really greater or equal?:
The other thing is that apparently everyone completely mis-understands Hungarian notation in that you're not expected to prefix (postfix, whatever) e.g. all strings by "s", but e.g. all input strings by
i
and output strings byo
or something like that. If used like this, it does make much more sense. But nobody uses it like that, so it's dumb.In other words: Hungarian notation has its uses if you add new information.
Wikipedia lists a bunch of examples with differences between Apps Hungarian and Systems Hungarian and if you really can't sleep at night you could try reading Joel Spolsky's (old) love story of Apps Hungarian.
-
@blakeyrat said in Is it really greater or equal?:
@unperverted-vixen said in Is it really greater or equal?:
I’ve never understood why people are so afraid of the m_ prefix. If you have dumb properties, then just switch to an autoproperty and get rid of the backing variable entirely. And if you have smart properties, surely that extra prefix to make sure you don’t reference the field instead of the property in error is A Good Thing?
Why not just use an IDE and stop writing code like it's fucking 1983?
But then in VS you need to hover all those fields to get a popup saying "(field)" or "(local variable)" while using a prefix for members can speed up reading.
-
@jbert I think Joel's blog is indeed where I saw this for the first time.
Interesting thing is that it also shows (somewhat...) how things have evolved. Having the type in the name made sense when using poor IDEs (or languages!) where the type wasn't visible easily. With modern ones, that has become stupid. And now we get the same discussion (about e.g. members/locals...) just one level higher! Maybe in 20 years this will seem similarly outdated and stupid?
-
@remi said in Is it really greater or equal?:
Maybe in 20 years this will seem similarly outdated and stupid?
More likely, it will just have moved up one level, or sideways one step, or whatever.
-
@blakeyrat said in Is it really greater or equal?:
@unperverted-vixen said in Is it really greater or equal?:
I’ve never understood why people are so afraid of the m_ prefix. If you have dumb properties, then just switch to an autoproperty and get rid of the backing variable entirely. And if you have smart properties, surely that extra prefix to make sure you don’t reference the field instead of the property in error is A Good Thing?
Why not just use an IDE and stop writing code like it's fucking 1983?
It's funny because you lecture us about your disability but don't care about anyone else's.
-
@masonwheeler
It decreases the signal to noise ratio. It shifts your attention from "what does this do" to "look, I'm a member, can you believe that?!". At least use a suffix so the important stuff comes first.Filed under: i++; // increase variable i by 1
-
@jbert said in Is it really greater or equal?:
In other words: Hungarian notation has its uses if you add new information.
Wikipedia lists a bunch of examples with differences between Apps Hungarian and Systems Hungarian and if you really can't sleep at night you could try reading Joel Spolsky's (old) love story of Apps Hungarian.
Making wrong code look wrong seems perfectly reasonable if you don't know about the alternative: making wrong code not compile.
-
@antiquarian Many languages don't yet have strong aliases whereby assigning a row number to a column number is an error. You have to manually make wrapper classes and hope the compiler optimizes them to integers in the compiled code.
-
@boomzilla what are you even talking about.
-
@jbert said in Is it really greater or equal?:
@blakeyrat said in Is it really greater or equal?:
@unperverted-vixen said in Is it really greater or equal?:
I’ve never understood why people are so afraid of the m_ prefix. If you have dumb properties, then just switch to an autoproperty and get rid of the backing variable entirely. And if you have smart properties, surely that extra prefix to make sure you don’t reference the field instead of the property in error is A Good Thing?
Why not just use an IDE and stop writing code like it's fucking 1983?
But then in VS you need to hover all those fields to get a popup saying "(field)" or "(local variable)" while using a prefix for members can speed up reading.
Apparently if you want an internal field to be modifiable, but you also want an external accessor that does some work before modifying the internal one, you're
-
@unperverted-vixen said in Is it really greater or equal?:
@topspin said in Is it really greater or equal?:
I stopped reading at
m_
.I’ve never understood why people are so afraid of the
m_
prefix. If you have dumb properties, then just switch to an autoproperty and get rid of the backing variable entirely. And if you have smart properties, surely that extra prefix to make sure you don’t reference the field instead of the property in error is A Good Thing?A lot of it would go away if C# allowed for default accessors, yet also allowed you to do some basic code in the get and set.
Of course, this doesn't help. https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/using-properties
They have the convention of property
Name
and internal membername
. But that isn't any different fromname
andm_name
I mean, they say you have a read only property by using a internal member, and an external property, when it's just better to do
int Count { get; private set; }
But if, say, I could
int Count { get { return [keyword]; } set { NotifyPropertyChanged("Count"); [keyword] = value; }
then I don't need an internal variable.
-
@xaade If you're going to add a new language feature to support that scenario, why not cut to the chase? Rather than exposing autoproperties' internals (and potentially letting developers screw them up!), come up with some way to tell that autoproperty's hidden code to call NotifyPropertyChanged() in the setter. (As simple as an INotifyPropertyChanged interface implemented by the class?)
-
@unperverted-vixen said in Is it really greater or equal?:
@xaade If you're going to add a new language feature to support that scenario, why not cut to the chase? Rather than exposing autoproperties' internals (and potentially letting developers screw them up!), come up with some way to tell that autoproperty's hidden code to call NotifyPropertyChanged() in the setter. (As simple as an INotifyPropertyChanged interface implemented by the class?)
I actually have a base class I wrote that kinda does that.
Behind the scenes it's just setting and getting the field from a dictionary, and then calling the notify code.
It ends up looking like this in code.
void int Something { get { return GetValue<int>(); } set { SetValue(value); }
What it's doing is it has another string argument with the default value set to the caller member name. Mainly used for reflecting and debugging, it works in this case.
It's not something I'd use for a real product, but it makes throwing together a WPF project for fun really quick.
-
@unperverted-vixen said in Is it really greater or equal?:
@xaade If you're going to add a new language feature to support that scenario, why not cut to the chase? Rather than exposing autoproperties' internals (and potentially letting developers screw them up!), come up with some way to tell that autoproperty's hidden code to call NotifyPropertyChanged() in the setter. (As simple as an INotifyPropertyChanged interface implemented by the class?)
But what if you want to do something other than INotifyPropertyChanged?
-
@xaade said in Is it really greater or equal?:
But what if you want to do something other than INotifyPropertyChanged?
Use AOP to wrap interceptors round the setters that call notification methods (or whatever)? It's entirely more general, and while it is a complicated solution, the complication is in generated and library code and not what you write.
Though I don't know if C# has a decent AOP system.
-
@lb_ said in Is it really greater or equal?:
@antiquarian Many languages don't yet have strong aliases whereby assigning a row number to a column number is an error. You have to manually make wrapper classes and hope the compiler optimizes them to integers in the compiled code.
-
@topspin said in Is it really greater or equal?:
The way I've seen it used is people prefix members with m, function arguments with a, statics with s, and locals with l.
I essentially do this, minus the locals part (these are the most common, so no prefix for them). I don't think it introduces that much noise in the code, and although the IDE has this information, mousing over a variable or asking the IDE for a definition slows down reading the code significantly. I also find that it works well with autocompletion: you time 'm' and you're presented with a list of members, 'a' and you get a list of arguments etc. But .
-
@blakeyrat said in Is it really greater or equal?:
@boomzilla what are you even talking about.
Dyslexia vs color blindness.
-
@lb_ said in Is it really greater or equal?:
Many languages don't yet have strong aliases whereby assigning a row number to a column number is an error. You have to manually make wrapper classes and hope the compiler optimizes them to integers in the compiled code.
Hey kid, here's a nickel. Go get yourself a real programming language.
-
@boomzilla When did I talk about color blindness?
You know what? Nevermind. Sure I'm talking about color blindness all the damned time in Boomzilla's head, why not.
-
@blakeyrat said in Is it really greater or equal?:
@boomzilla When did I talk about color blindness?
Your crack about an IDE. I dunno...my IDE colors tokens differently based on their scope. Perhaps you meant something else but that seemed like what you were talking about.
You know what? Nevermind. Sure I'm talking about color blindness all the damned time in Boomzilla's head, why not.
Yes, that's not a moronic take on this at all.
-
@boomzilla said in Is it really greater or equal?:
my IDE colors tokens differently based on their scope.
... therefore Blakeyrat doesn't care about disabled people! YOUR LOGIC IS FLAWLESS!
No doubt I'm the moron for not drawing that incredibly 100% obvious and not at all gibberish nonsense conclusion.
-
@blakeyrat said in Is it really greater or equal?:
@boomzilla said in Is it really greater or equal?:
my IDE colors tokens differently based on their scope.
... therefore Blakeyrat doesn't care about disabled people! YOUR LOGIC IS FLAWLESS!
I see you still have good relations with your shoulder aliens. Good friendships are important.
No doubt I'm the moron for not drawing that incredibly 100% obvious and not at all gibberish nonsense conclusion.
Eh, you've reversed cause and effect, but that's close enough. So what's the non-gibberish sensical conclusion?
-
@boomzilla said in Is it really greater or equal?:
So what's the non-gibberish sensical conclusion?
Conclusion to what? I don't even know what you're talking about.
Literally the only thing I posted in this thread was something like "you should use an IDE so you don't need to use those dumb prefixes", then the next thing I know you're posting about me hating disabled people? It came out of fucking nowhere! Then when I ask you for clarification, you say "well my IDE uses colors", and I'm like "good for you? But what the fuck does that have to do with your assertion that I hate disabled people!?"
I know you're going to say I'm a liar or I'm making this up or whatever, because you're Boomzilla: History's Greatest Monster, but I honestly and truly have no fucking clue what you're talking about.
Of course it doesn't matter because you're just making shit up as an excuse to call me a dumb idiot moron stupid idiot, yes I am, yes I am human garbage, I am awful, we get it already Boomzilla, your message has come across, you can stop repeating it. But next time you make shit up, maybe you could at least put a little effort into connecting A with B so people don't have to guess what's going on in your demented little brain where "you should use an IDE" == "I hate disabled people!"
-
@blakeyrat said in Is it really greater or equal?:
Conclusion to what? I don't even know what you're talking about.
The conclusion to this:
Literally the only thing I posted in this thread was something like "you should use an IDE so you don't need to use those dumb prefixes", then the next thing I know you're posting about me hating disabled people? It came out of fucking nowhere! Then when I ask you for clarification, you say "well my IDE uses colors", and I'm like "good for you? But what the fuck does that have to do with your assertion that I hate disabled people!?"
Please explain how an IDE makes the prefixes obsolete.
@blakeyrat said in Is it really greater or equal?:
Of course it doesn't matter because you're just making shit up as an excuse to call me a dumb idiot moron stupid idiot,
That's too much work. I just use the material you give me, which is plenty.
@blakeyrat said in Is it really greater or equal?:
But next time you make shit up, maybe you could at least put a little effort into connecting A with B so people don't have to guess what's going on in your demented little brain where "you should use an IDE" == "I hate disabled people!"
You're right, it seemed obvious to me, but then the meaning of your message is still completely opaque, so there you go.
-
@boomzilla said in Is it really greater or equal?:
Please explain how an IDE makes the prefixes obsolete.
While this is a reasonable question, I'm not sure why you think I'd want to reply to a person who literally made up shit so he could say I hate disabled people.
The answer is: go fuck yourself.
If you wanted to have a conversation, maybe start from an entry point other than "I said you hated disabled people several times, now I'm going to ask for clarification on what you meant by your first reply."
Of course, you're only asking so you can make up even more stuff and say I'm horrible in some different and novel way. Because why would you ever even care what I think? The only reason I exist on this forum is to be called a moron.
-
@blakeyrat said in Is it really greater or equal?:
The only reason I exist on this forum is to be called a moron.
Isn't calling people morons the only reason this forum exists?
-
@blakeyrat said in Is it really greater or equal?:
Of course, you're only asking so you can make up even more stuff and say I'm horrible in some different and novel way.
Well, I was giving you a chance to explain why we shouldn't think as poorly of you as you want everyone to think poorly of people who, e.g., like CLIs.
@blakeyrat said in Is it really greater or equal?:
The answer is: go fuck yourself.
Yes, well reasoned as always.
-
@dragoon said in Is it really greater or equal?:
Being colorblind, the IDE approach fucking sucks if I ever have to look at it on someone elses machine.
Ah, @boomzilla is misattributing an assertion made by someone else. Gotcha.
-
@tsaukpaetra said in Is it really greater or equal?:
@dragoon said in Is it really greater or equal?:
Being colorblind, the IDE approach fucking sucks if I ever have to look at it on someone elses machine.
Ah, @boomzilla is misattributing an assertion made by someone else. Gotcha.
No, I just came to a similar conclusion regarding IDE use and blakey's statement (I don't think I'd read @Dragoon's post prior to my reply, but even if I did, I know that I drew that conclusion before I read it):
@blakeyrat said in Is it really greater or equal?:
@unperverted-vixen said in Is it really greater or equal?:
I’ve never understood why people are so afraid of the m_ prefix. If you have dumb properties, then just switch to an autoproperty and get rid of the backing variable entirely. And if you have smart properties, surely that extra prefix to make sure you don’t reference the field instead of the property in error is A Good Thing?
Why not just use an IDE and stop writing code like it's fucking 1983?
Perhaps there's some other conclusion to draw here, but I guess we'll never know what he really meant.
-
@boomzilla said in Is it really greater or equal?:
Perhaps there's some other conclusion to draw here, but I guess we'll never know what he really meant.
I read the conclusion that, apparently an IDE magically removes the desire for prefixing your variables. Somehow. I vote using different fonts or styles.
Someone post this in the Bad Ideas thread!
-
@ben_lubar said in Is it really greater or equal?:
@lb_ said in Is it really greater or equal?:
@antiquarian Many languages don't yet have strong aliases whereby assigning a row number to a column number is an error. You have to manually make wrapper classes and hope the compiler optimizes them to integers in the compiled code.
Neat! Now we just need that in many other languages.
@antiquarian said in Is it really greater or equal?:
@lb_ said in Is it really greater or equal?:
Many languages don't yet have strong aliases whereby assigning a row number to a column number is an error. You have to manually make wrapper classes and hope the compiler optimizes them to integers in the compiled code.
Hey kid, here's a nickel. Go get yourself a real programming language.
Got any suggestions for languages with strong type aliases that are also good for building a game from the ground up?
-
@lb_ said in Is it really greater or equal?:
Got any suggestions for languages with strong type aliases that are also good for building a game from the ground up?
Yes, but none that you will like. coughAdacough
-
@lb_ said in Is it really greater or equal?:
@ben_lubar said in Is it really greater or equal?:
@lb_ said in Is it really greater or equal?:
@antiquarian Many languages don't yet have strong aliases whereby assigning a row number to a column number is an error. You have to manually make wrapper classes and hope the compiler optimizes them to integers in the compiled code.
Neat! Now we just need that in many other languages.
@antiquarian said in Is it really greater or equal?:
@lb_ said in Is it really greater or equal?:
Many languages don't yet have strong aliases whereby assigning a row number to a column number is an error. You have to manually make wrapper classes and hope the compiler optimizes them to integers in the compiled code.
Hey kid, here's a nickel. Go get yourself a real programming language.
Got any suggestions for languages with strong type aliases that are also good for building a game from the ground up?
I bet you could set something up with C++, since a struct containing a single property and some operator overloads has no cost at runtime.
-
@ben_lubar said in Is it really greater or equal?:
@lb_ said in Is it really greater or equal?:
@ben_lubar said in Is it really greater or equal?:
@lb_ said in Is it really greater or equal?:
@antiquarian Many languages don't yet have strong aliases whereby assigning a row number to a column number is an error. You have to manually make wrapper classes and hope the compiler optimizes them to integers in the compiled code.
Neat! Now we just need that in many other languages.
@antiquarian said in Is it really greater or equal?:
@lb_ said in Is it really greater or equal?:
Many languages don't yet have strong aliases whereby assigning a row number to a column number is an error. You have to manually make wrapper classes and hope the compiler optimizes them to integers in the compiled code.
Hey kid, here's a nickel. Go get yourself a real programming language.
Got any suggestions for languages with strong type aliases that are also good for building a game from the ground up?
I bet you could set something up with C++, since a struct containing a single property and some operator overloads has no cost at runtime.
Yeah this is what I do already:
@lb_ said in Is it really greater or equal?:
You have to manually make wrapper classes and hope the compiler optimizes them to integers in the compiled code.
-
@topspin said in Is it really greater or equal?:
Filed under: i++; // increase variable i by 1
That's wrong. It must be:
i--; // increase variable i by 1
-
@antiquarian said in Is it really greater or equal?:
@lb_ said in Is it really greater or equal?:
Got any suggestions for languages with strong type aliases that are also good for building a game from the ground up?
Yes, but none that you will like. coughAdacough
Type alias stronk! Type alias is credit to team! Hahaha!