Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Amarkov
Jun 21, 2010

..btt posted:

Every time I read that there's a part of me that believes it's not really true, nobody could design a database that isn't null aware and have, of all people, financial institutions adopt it as their standard RDBMS. It's some in-joke among Oracle-types... right guys? :ohdear:

We live in a world where MongoDB is seeing widespread market adoption, specifically because it is incapable of enforcing any constraints. I'll accept NULL decaying to empty string as an alternative.

Adbot
ADBOT LOVES YOU

..btt
Mar 26, 2008
Yeah, I don't get that at all. I really like Mongo's API, but I haven't used it for anything I'd want an RDBMS for. Because it isn't an RDBMS.

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer

SavageMessiah posted:

All this is moot on ~*Oracle*~ because '' IS NULL there...

I've actually come to appreciate this about Oracle. 9 out of 10 times the distinction between null and '' is of no interest to my business logic anyway, so I like not having to worry about which one I put in the database. The only thing I hate is when I forget that col = '' doesn't work (you have to do col IS NULL). Even '' = '' returns false.

Captain Capacitor
Jan 21, 2008

The code you say?

..btt posted:

Yeah, I don't get that at all. I really like Mongo's API, but I haven't used it for anything I'd want an RDBMS for. Because it isn't an RDBMS.

The aggregation framework is really nice. Being able to project and rebuild documents on the fly is really handy. Then again, it's supposed to be used for document-type records.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Houston Rockets posted:

code:
# need to skip the first two lines

first_line = True
second_line = False

for line in data:

    if first_line:
        first_line = False
        second_line = True
        continue
    if second_line:
        second_line = False
        continue

    do_stuff(line)

:doh:

What type is data? Could they have just used for line in data[2:]: ?

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug

Bognar posted:

:doh:

What type is data? Could they have just used for line in data[2:]: ?
You can't slice a file object or a generator; so please tell us that it was replaced with something like
Python code:
LINES_TO_SKIP = 2
for _ in range(LINES_TO_SKIP):
    next(data)

for line in data:
    do_stuff(line)

breaks
May 12, 2001

Just use itertools.islice, that's what it's for!

SavageMessiah
Jan 28, 2009

Emotionally drained and spookified

Toilet Rascal

LOOK I AM A TURTLE posted:

I've actually come to appreciate this about Oracle. 9 out of 10 times the distinction between null and '' is of no interest to my business logic anyway, so I like not having to worry about which one I put in the database. The only thing I hate is when I forget that col = '' doesn't work (you have to do col IS NULL). Even '' = '' returns false.

It's a lot more likely to bite you if you're writing poo poo tons of PL/SQL code.

raminasi
Jan 25, 2005

a last drink with no ice
code:
double[] lengths_ = new double[streets.Count];
Curve[] streets_ = new Curve[streets.Count];

for (int i = 0; i < streets.Count; i++)
{
    lengths_[i] = streets[i].GetLength();
    streets_[i] = streets[i];
}

Array.Sort(lengths_, streets_);

for (int i = 0; i < streets.Count; i++)
{
    streets[i] = streets_[i];
}
Hmmm... :raise:

code:
streets.Sort((a, b) => a.GetLength().CompareTo(b.GetLength()));
Much better!

..btt
Mar 26, 2008
I'm no expert on the lambda internals, but doesn't that result in more evaluations of "GetLength" than the original? Might not be a concern in that context, dependant on array size or implementation, of course.

raminasi
Jan 25, 2005

a last drink with no ice
Possibly, but I'm 100% certain that performance considerations did not cause the original version.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

..btt posted:

I'm no expert on the lambda internals, but doesn't that result in more evaluations of "GetLength" than the original? Might not be a concern in that context, dependant on array size or implementation, of course.

streets = streets.OrderBy(s => s.GetLength()).ToArray(); would get you down to O(N) calls to GetLength() if the sort doesn't specifically need to be in-place.

If it does need to be in-place, the number of calls to GetLength did matter, and I'm not just forgetting about an existing in-place version, then I would still want to just write the in-place version.

pigdog
Apr 23, 2004

by Smythe

SavageMessiah posted:

It's a lot more likely to bite you if you're writing poo poo tons of PL/SQL code.

Oracle doesn't even index null fields*, so that's always fun when you have them all over the legacy schema. :negative:



* without trickery like indexing on (column, someconstant) and even so it works better in 11g+.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Plorkyeran posted:

streets = streets.OrderBy(s => s.GetLength()).ToArray();

I would prefer that code to the .Sort() implementation even if it was less performant. It just reads a lot better.

Woodsy Owl
Oct 27, 2004

GrumpyDoctor posted:

code:
lengths_
streets_

Is this a half-baked attempt at snake_case?

raminasi
Jan 25, 2005

a last drink with no ice

Woodsy Owl posted:

Is this a half-baked attempt at snake_case?

It's what you do when your algorithm is implemented as a single 1000-line long function and you want a way to kind of indicate that some variables are more "temporary" than others. I guess.

(It's also how you name class data members according to the Google C++ style guide :ssh:)

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

GrumpyDoctor posted:

It's also how you name class data members according to the Google C++ style guide :ssh:
The Google C++ style guide telling you to do something is a pretty good sign that you shouldn't do it.

Sockser
Jun 28, 2007

This world only remembers the results!




Am I a bad person for using the half-assed p_, m_, _ Hungarian notation :ohdear:

Woodsy Owl
Oct 27, 2004

Sockser posted:

Am I a bad person for using the half-assed p_, m_, _ Hungarian notation :ohdear:

Everyone has the right to use whatever notation they want. The case I was talking about just looked strange to me from my notation and readability point of view. Maybe I was too critical, and it isn't really my place to judge others' notation choice unless it's absolutely horrible.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Sockser posted:

Am I a bad person for using the half-assed p_, m_, _ Hungarian notation :ohdear:

Yes. Hungarian notation is a concept whose time has passed.

raminasi
Jan 25, 2005

a last drink with no ice

Plorkyeran posted:

The Google C++ style guide telling you to do something is a pretty good sign that you shouldn't do it.

Which style guidelines would you recommend?

Rottbott
Jul 27, 2006
DMC
I don't think of m_ as being Hungarian notation as such. It's more so you can have public members with the same name (e.g. accessors). I would just use _Name (I do in C#), but in C++ you aren't supposed to start names with underscores, it's reserved for the implementation or something.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Using any sort of programmer-enforced convention of prefixes or suffixes in identifier names to convey semantic meaning is a form of hungarian notation. It's not a very good idea.

Rottbott
Jul 27, 2006
DMC
That's why I said it's not for semantic meaning, it's to prevent name collisions - at least for me.

Sockser
Jun 28, 2007

This world only remembers the results!




I mostly use it just to keep track of variables easier, insofar as "oh poo poo what is foo" is reduced to "oh poo poo what is p_foo oh well it's a parameter so that's something"

and now I don't think I can ever stop doing it :smith:

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Sockser posted:

I mostly use it just to keep track of variables easier, insofar as "oh poo poo what is foo" is reduced to "oh poo poo what is p_foo oh well it's a parameter so that's something"

and now I don't think I can ever stop doing it :smith:

You aren't using an IDE that can provide that information to you so you don't have to encode it into your variable names by convention?

FamDav
Mar 29, 2008

Rottbott posted:

I don't think of m_ as being Hungarian notation as such. It's more so you can have public members with the same name (e.g. accessors). I would just use _Name (I do in C#), but in C++ you aren't supposed to start names with underscores, it's reserved for the implementation or something.

At global scope this is correct, but otherwise only double underscore in a variable and a prefix of underscore followed by a capital letter are reserved. _member is perfectly okay.

EDIT: Of course, then you have POSIX whose rules end up reserving things like "tolerance" and "isomorphism"

FamDav fucked around with this message at 19:04 on Nov 17, 2013

Happy Big Fun
Jul 23, 2004
Yay!
Modified Hungarian is great for several things. The one that comes up all the time in my work is storing the same data 2 different ways. For example, you ask the user for their date of birth in a text box, so you get it as a string, but you need it as a DateTime. sDateOfBirth and dtDateOfBirth.

Also, sometimes an object being a certain class is everything you need to know about that variable. If I'm making an ASP.NET TableHeaderRow, I am almost always going to name it thr. I'm going to name the header cells thcName, thcIdNumber, etc. Then, in the loop that makes the table, I'm going to name the regular cells things like tcName and tcIdNumber.

Sometimes, the class names tell you tons about the object's intended uses. Hungarian warts make variable names almost automatic.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Happy Big Fun posted:

Modified Hungarian is great for several things. The one that comes up all the time in my work is storing the same data 2 different ways. For example, you ask the user for their date of birth in a text box, so you get it as a string, but you need it as a DateTime. sDateOfBirth and dtDateOfBirth.

Also, sometimes an object being a certain class is everything you need to know about that variable. If I'm making an ASP.NET TableHeaderRow, I am almost always going to name it thr. I'm going to name the header cells thcName, thcIdNumber, etc. Then, in the loop that makes the table, I'm going to name the regular cells things like tcName and tcIdNumber.

Sometimes, the class names tell you tons about the object's intended uses. Hungarian warts make variable names almost automatic.

"sDateOfBirth" and "dtDateOfBirth" don't tell me anything about the variables other than what type they are. I have an IDE that can tell me which type they are, so what do I get out of naming them after what type of data they contain? Nothing. This sounds like a job for Actual Descriptive Names! In the example you provided, I have the date the user is providing, and the parsed version of that date. So I'd call them inputDateOfBirth and parsedDateOfBirth. Now I look at those variables and I know which one is from user input and which one is the parsed version.

For your table example, you should be naming it after what the table is actually going to contain. "thr" tells me nothing other than the type, which is just not useful for writing readable, maintainable code. It might not matter much in specific cases, but it's easier to just be consistent and always be descriptive.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Once we're finished today's bikeshedding session, I think we'll all agree that proper names should be dateOfBirthAsInputByUser and dateOfBirthForOperatingOnByProgram

raminasi
Jan 25, 2005

a last drink with no ice
Also it's important to remember that while having good tooling is nice, if you're working with C++, your IDE isn't guaranteed to know what's going on with any particular identifier. And it will take five seconds to admit failure. (And this is not a weird edge case, it happens pretty frequently.)

the littlest prince
Sep 23, 2006


Ithaqua posted:

"sDateOfBirth" and "dtDateOfBirth" don't tell me anything about the variables other than what type they are. I have an IDE that can tell me which type they are, so what do I get out of naming them after what type of data they contain? Nothing. This sounds like a job for Actual Descriptive Names! In the example you provided, I have the date the user is providing, and the parsed version of that date. So I'd call them inputDateOfBirth and parsedDateOfBirth. Now I look at those variables and I know which one is from user input and which one is the parsed version.

For your table example, you should be naming it after what the table is actually going to contain. "thr" tells me nothing other than the type, which is just not useful for writing readable, maintainable code. It might not matter much in specific cases, but it's easier to just be consistent and always be descriptive.

Frankly, inputWhatever and parsedWhatever don't tell you anything about it either, aside from them being different somehow.

Both methods are pretty much equivalent. You can look at sDOB and dtDOB once and then it will be more obvious next time you see sWhatever and dtWhatever and maybe even lWhatever (long), etc. You can also look at inputDOB and parsedDOB once and remember whatever pattern they use for inputWhatever and parsedWhatever.

They both give you a slightly lower mental hurdle to jump though, theoretically. But both also rely on consistency throughout the codebase.

carry on then posted:

bikeshedding

:golfclap:

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

FamDav posted:

EDIT: Of course, then you have POSIX whose rules end up reserving things like "tolerance" and "isomorphism"

Don't POSIXshame. isomorphism and tolerance for all

Hughlander
May 11, 2005

Ithaqua posted:

You aren't using an IDE that can provide that information to you so you don't have to encode it into your variable names by convention?

Honest question, are you always in your IDE? I do a lot of cross mobile app development, one code base for Android and iOS. If I'm looking at code it could be in:

  • Chrome with github's integrated diff because a HipChat announcement just went off that someone pushed something interesting and I clicked the link
  • git diff console output
  • git difftool set to Kaleidoscope
  • Xcode
  • AppCode
  • Sublime Text
  • vim

(Maybe the list of tooling is the horror?)

So while we don't do any Hungarian here there's sure times I wish we did. I fixed a bug yesterday that probably existed for several years before I started where someone put an NSInvocation into an NSMutableDictionary and tried to remove it by referencing it's (id)Target. IDE didn't help and the app has been leaking memory since before release.

Look Around You
Jan 19, 2009

Ithaqua posted:

You aren't using an IDE that can provide that information to you so you don't have to encode it into your variable names by convention?

Not defending hungarian, but I mostly just use vim to develop, and I'm sure I'm not alone in using just a text editor (emacs, sublime text, textmate, etc) to write code. I hate having to start up a heavy program to write code, and knowing vim (or emacs) makes it easier to work on code over ssh or whatever too.

That being said, I don't usually mark variables as anything; I tend to prefer using self or this explicitly, and in any case, if you have so many variables in your function that you can't tell which one is local or class or global, you probably have some issues w/r/t your codebase. It shouldn't be that hard to look up in your function to see if something is declared as a local inside the function or in the parameter list, and if you don't see it there, chances are it's either a member variable, class variable or global, or a syntax error*.

*dynamic langauges are a little different with this, but a lot of dynamic languages require some form of explicit self for member reference anyway.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Hughlander posted:

Honest question, are you always in your IDE?

When I'm writing code? The vast majority of the time (>99%), the answer is "Yes". I code almost exclusively in a Microsoft bubble, though.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

GrumpyDoctor posted:

Also it's important to remember that while having good tooling is nice, if you're working with C++, your IDE isn't guaranteed to know what's going on with any particular identifier. And it will take five seconds to admit failure. (And this is not a weird edge case, it happens pretty frequently.)

This. Plus, having g_ helps a lot, too. (please don't ask :cry: )

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Hughlander posted:

Honest question, are you always in your IDE?

The only time that I'm not is when I'm using a code review tool like reviewboard or gerrit. Realistically, the only time I'm not using an IDE to do actual development is when I'm editing a config file or something similar.

Spatial
Nov 15, 2007

GrumpyDoctor posted:

Also it's important to remember that while having good tooling is nice, if you're working with C++, your IDE isn't guaranteed to know what's going on with any particular identifier. And it will take five seconds to admit failure. (And this is not a weird edge case, it happens pretty frequently.)
Haha. Buy an SSD already.

Adbot
ADBOT LOVES YOU

Pollyanna
Mar 5, 2005

Milk's on them.


Lol @ u if you're using an IDE, clearly you're a subpar coder and also a nooblet. Seriously, what's wrong with IDEs? They're incredibly helpful and make organizing a project a lot easier.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply