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
The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

Subjunctive posted:

Yes, this lets the compiler catch typos.

Also makes internationialization easier.

Adbot
ADBOT LOVES YOU

darthbob88
Oct 13, 2011

YOSPOS

LeftistMuslimObama posted:

Also makes internationialization easier.
I'd have thought the way to ease internationalization would be to say cons currency = "USD", since that means you only need to change it one place and you can avoid nonsense like cons USD = "GBP".

NiceAaron
Oct 19, 2003

Devote your hearts to the cause~

If you're actually dealing with different currencies then you're probably going to do more than just some simple text replacement, since USD is semantically different than GBP.

Ochowie
Nov 9, 2007

Subjunctive posted:

Yes, this lets the compiler catch typos.

This was actually being done in a type of environment where the typo would have been caught since the compiler (interpreter in this case) would know to check against a predefined set of currency codes so either the compilation or the very first run of the program would have caught the issue.

LeftistMuslimObama posted:

Also makes internationialization easier.

USD (and similar codes) are driven by an ISO standard so internationalization wouldn't be a concern in that case.

Linear Zoetrope
Nov 28, 2011

A hero must cook

TheBlackVegetable posted:

I think this is a good first step towards pulling that magic number out of the code and into config.

Nah, this is the only place it's used in the whole program. It's an environment for Reinforcement Learning with an Atari Emulator and this was from the Space Invaders glue. The class file itself is basically the "config file" for all the RL stuff related to the Space Invaders ROM.

TZer0
Jun 22, 2013
Some variable names replaced (this is Java).
code:
public int[] getSomeIndex(int type) {
  int someCount = someSet.size();
  ArrayList<Integer> indexList = new ArrayList<Integer>();
  int[] indexArray;
  for (int i = 0; i < someCount; i++) {
    if (someSet.get(i).type == type) {
      indexList.add(i);    
    }
  }
    
  if(!indexList.isEmpty()){
    indexArray = new int[indexList.size()];
    for(int i = 0;i<indexArray.length;i++){
      indexArray[i]=indexList.get(i);
    }
    return indexArray;
  }
  return null;
}

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt


My favourite part is where it returns null instead of an empty array.

Tank Boy Ken
Aug 24, 2012
J4G for life
Fallen Rib
Well then you'll like this: https://github.com/KeenSoftwareHouse/SpaceEngineers/blob/master/Sources/Sandbox.Game/Game/GUI/MyGuiBlueprintBase.cs Line 274

code:

        public static MyObjectBuilder_Definitions LoadWorkshopPrefab(string archive, ulong? publishedItemId)
        {
            if (!File.Exists(archive) || publishedItemId == null)
                return null;
            
			// ----- removed stuff
            
            if (subItem == null)
                return null;

            var extracted = MyZipArchive.OpenOnFile(archive);
            if (!extracted.FileExists("bp.sbc"))
                return null;
		
			// ----- removed stuff
            
            if (stream == null)
                return null;
            
           	 // ----- removed stuff
            
            if (success)
            {
               	// ----- removed stuff
                return objectBuilder;
            }
            return null;
        }
// ----- removed stuff represents some other code.
In a not totally unrelated note, Space Engineers made their source code available on Github.

Less Fat Luke
May 23, 2003

Exciting Lemon

NihilCredo posted:

My favourite part is where it returns null instead of an empty array.
The loving bane of my existence.

tyrelhill
Jul 30, 2006
On a project I worked on this guy wrote a "get XML value as Boolean" function that returned null when it didnt exist. I hated that function.

loinburger
Jul 10, 2004
Sweet Sauce Jones
I've got a JobManager object that shouldn't really exist when there isn't a job running, but I don't like nulls so I created an UninitializedJobManager that just executed nops or returned stuff like "IllegalStateException("Job manager is not initialized")" to things like status queries - I documented all of this, assuming that anybody running status queries would just log any exceptions and move on if they got an exception (or, worst case, they'd get something like a 404). One of my co-workers wrote a status monitor that promptly crashed the program when it encountered the IllegalStateException. And he didn't just say "hey can you replace that exception with a string" or whatever, instead he said "AHHHHH THE PROGRAM IS CRASHING."

The same co-worker accidentally (I hope) deleted all of my code a few days ago - he was merging my code onto master, but he used the version of my code that existed four months ago (I have no idea where he even found a branch that old).

Less Fat Luke
May 23, 2003

Exciting Lemon

tyrelhill posted:

On a project I worked on this guy wrote a "get XML value as Boolean" function that returned null when it didnt exist. I hated that function.
I wrote a ton of stuff interacting with ElasticSearch about a year and a half ago (so maybe this is out of date) and the API was full of traps where you'd ask for like a list of indexes for example, and some endpoints would return a 404 and some would return an empty JSON array.

Edit: That also reminds me of a Ruby horror, related to the ES stuff - symbols versus strings. Which will a gem return? Who knows! Gotta read the code, and hope they don't change the contract on version bumps (spoiler: they do). And garbage like that introduces classes like HashWithIndifferentAccess. :(

Less Fat Luke fucked around with this message at 18:04 on Aug 11, 2015

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

Less Fat Luke posted:

Edit: That also reminds me of a Ruby horror, related to the ES stuff - symbols versus strings. Which will a gem return? Who knows! Gotta read the code, and hope they don't change the contract on version bumps (spoiler: they do). And garbage like that introduces classes like HashWithIndifferentAccess. :(

One of the most terrible parts of ruby, for sure.

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)

Tank Boy Ken posted:

Well then you'll like this: https://github.com/KeenSoftwareHouse/SpaceEngineers/blob/master/Sources/Sandbox.Game/Game/GUI/MyGuiBlueprintBase.cs Line 274
code:
//
// ----- removed stuff represents some other code.
In a not totally unrelated note, Space Engineers made their source code available on Github.

This is actually the code I was referring to when I brought up the "my" prefix thing. I tried making mods for it one day, but it's such a trainwreck.

code:
    class MyProgrammableBlock : MyFunctionalBlock, IMyProgrammableBlock, IMyPowerConsumer { ... }
    
Literally every class is like this.

dougdrums fucked around with this message at 15:02 on Aug 12, 2015

Tank Boy Ken
Aug 24, 2012
J4G for life
Fallen Rib
Yeah as beginning hobby coder this is something you see people use in a lot of tutorials to explain things. Which is bad since it wouldn't hurt to start off with "good" naming conventions. Though I personally do use "my....." too. Usually in constructors:
code:
        public EngineGameData(int rating, EngineType type, int heatsinks, ItemBuildData myStats)
        {
            engineRating = rating;
            engType = type;
            engineHeatSinks = heatsinks;
            Stats = myStats;
        }
I really ought to be more consistent with my naming "conventions". At least nobody except me has to deal with my code.

KernelSlanders
May 27, 2013

Rogue operating systems on occasion spread lies and rumors about me.
Is "my" just a vestige of perl's silly way of declaring local variables or was it around before that?

loinburger
Jul 10, 2004
Sweet Sauce Jones
I've never touched perl and I've seen it in a lot of Java code

You've created, I dunno, a Queue, but there's already a Queue. What distinguishes your Queue from the existing Queue that you can use to give it a good name? gently caress that, call it MyQueue

I ran into one guy who made JohnQueue, JohnArray, etc. In a lot of cases there was already a MyQueue and MyArray, so he took it a step further.

Tank Boy Ken
Aug 24, 2012
J4G for life
Fallen Rib
I've seen it in some books on "How to learn to code in XXX". Most of the time in abstract simple and short code examples. And the msdn also loves it (C#): https://msdn.microsoft.com/de-de/library/w5zay9db%28v=VS.120%29.aspx

code:
	int[] myIntArray = { 5, 6, 7, 8, 9 };
        UseParams(myIntArray);

        object[] myObjArray = { 2, 'b', "test", "again" };
        UseParams2(myObjArray);

ErIog
Jul 11, 2001

:nsacloud:

KernelSlanders posted:

Is "my" just a vestige of perl's silly way of declaring local variables or was it around before that?

I always thought it was a vestige of tutorials that were trying to reinforce the difference between an instance of a class and the class itself.

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)
I remembered this too: https://msdn.microsoft.com/en-us/library/20fy88e0.aspx (Me, My, MyBase, and MyClass in Visual Basic)

loinburger posted:

I ran into one guy who made JohnQueue, JohnArray, etc. In a lot of cases there was already a MyQueue and MyArray, so he took it a step further.

I name some of my libraries like this, like dougmem.h but with my last name.

dougdrums fucked around with this message at 17:34 on Aug 12, 2015

KICK BAMA KICK
Mar 2, 2009

Common in Python tutorials too to teach you to avoid overwriting the lowercase builtin names like dict and list.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender
I once shipped some code that connected to a postgres database through a handle named mySQL.

loinburger
Jul 10, 2004
Sweet Sauce Jones
I worked for a Swedish company that used a mixture of Swedish and English (often in the same variable/class name), which was confusing as hell until I got the hang of it. The worst example was "minHeap", which was actually a max heap, were "min" means "my." I'm pretty sure that was done just to gently caress with the American programmers.

Soricidus
Oct 21, 2010
freedom-hating statist shill

ShoulderDaemon posted:

I once shipped some code

you monster

KernelSlanders
May 27, 2013

Rogue operating systems on occasion spread lies and rumors about me.

ShoulderDaemon posted:

I once shipped some code that connected to a postgres database through a handle named mySQL.

I assume Oracle was involved somewhere.

ErIog
Jul 11, 2001

:nsacloud:

ShoulderDaemon posted:

I once shipped some code that connected to a postgres database through a handle named mySQL.

Shoulda been called myMySQL.

Space Kablooey
May 6, 2009


loinburger posted:

I worked for a Swedish company that used a mixture of Swedish and English (often in the same variable/class name), which was confusing as hell until I got the hang of it. The worst example was "minHeap", which was actually a max heap, were "min" means "my." I'm pretty sure that was done just to gently caress with the American programmers.

In my company all the programmers are Brazilian. Until we started one of the latest projects, all the class names and variable names were in English, as the style guide dictated.

Nowadays, it's a horrible mismatch between Portuguese and English without any rhyme or reason to it. :v:

Amberskin
Dec 22, 2013

We come in peace! Legit!

dougdrums posted:

I remembered this too: https://msdn.microsoft.com/en-us/library/20fy88e0.aspx (Me, My, MyBase, and MyClass in Visual Basic)


I name some of my libraries like this, like dougmem.h but with my last name.

I had to maintain several huge pieces of code full of variables named ABCflag1, ABCnum3, ABCpic5 where ABC are the initials of the guy who created the software years before that. Then I enjoyed trying to understand what the gently caress code like this does:

code:
IF ABCswitch1 & ¬ABCswitch3 THEN ABCpic1=8;
Did I say that guy is in the "comments are for sissies" school?

That guy is now an uberboss in the company.

qntm
Jun 17, 2009

loinburger posted:

I worked for a Swedish company that used a mixture of Swedish and English (often in the same variable/class name), which was confusing as hell until I got the hang of it. The worst example was "minHeap", which was actually a max heap, were "min" means "my." I'm pretty sure that was done just to gently caress with the American programmers.

That's great. I've run into code where the variable $noRetries apparently meant "number of retries" rather than, as I originally read it, "disable retries", but yours is better.

YO MAMA HEAD
Sep 11, 2007

I got really excited to write a line of PHP code that looked for misspellings of "pregnant" (pregnet, pregant, pregnent, etc.) using preg_match()

o.m. 94
Nov 23, 2009

how is T_PAAMAYIM_NEKUDOTAYIM formed. how girl get preg_match()

Sinestro
Oct 31, 2010

The perfect day needs the perfect set of wheels.
The Something Awful Forums > Discussion > Serious Hardware / Software Crap > The Cavern of COBOL > Coding horrors: how is T_PAAMAYIM_NEKUDOTAYIM formed. how girl get preg_match()

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

Sinestro posted:

The Something Awful Forums > Discussion > Serious Hardware / Software Crap > The Cavern of COBOL > Coding horrors: how is T_PAAMAYIM_NEKUDOTAYIM formed. how girl get preg_match()

not emptyquoting.

omeg
Sep 3, 2012

More of a security horror but still

http://www.theregister.co.uk/2015/08/12/lenovo_firmware_nasty/

:lolnovo:

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Those are some brazen fuckers right there.

dis astranagant
Dec 14, 2006

Well, that's basically what WPBT is designed to do. It's a pretty stupid feature that's just waiting for all kinds of hilarious exploits when someone finds a way to write to it from the OS.

ultramiraculous
Nov 12, 2003

"No..."
Grimey Drawer

Subjunctive posted:

Those are some brazen fuckers right there.

Superfish 2: Electric Boogaloo

"Seriously what if we just stopped giving a gently caress?"

ultramiraculous
Nov 12, 2003

"No..."
Grimey Drawer
Oh yeah, so the Android StageFright patch didn't really work because integers are hard and untyped macros are bad.

vOv
Feb 8, 2014

Sinestro posted:

The Something Awful Forums > Discussion > Serious Hardware / Software Crap > The Cavern of COBOL > Coding horrors: how is T_PAAMAYIM_NEKUDOTAYIM formed. how girl get preg_match()

it was on haker news this mroing

Adbot
ADBOT LOVES YOU

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

ultramiraculous posted:

Superfish 2: Electric Boogaloo

"Seriously what if we just stopped giving a gently caress?"

I'm having lunch with some other Superfish-excitement people next week and I think it's going to be like Requiem for a Dream.

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