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
Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug
Fwiw in Python it's the double underscore that's reserved and do not touch territory, not single.

Adbot
ADBOT LOVES YOU

FlapYoJacks
Feb 12, 2009
_ == protected
__ == private

Afaik.

Loezi
Dec 18, 2012

Never buy the cheap stuff

FlapYoJacks posted:

_ == protected
__ == private

Afaik.

Single underscore as a prefix indicates "internal use" by convention only, double causes name mangling. Neither is "private" in the sense that you wouldn't be able to access them if you wanted to.

Python code:
>>> class Butt:
...   def __init__(self, fart):
...     self._lol = fart
...     self.__lmao = fart
...
>>>
>>> my_butt = Butt("pffft")
>>> my_butt._lol
'pffft'
>>> my_butt.__lmao
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Butt' object has no attribute '__lmao'
>>> my_butt._Butt__lmao
'pffft'

MrMoo
Sep 14, 2000

leper khan posted:

C has static for TR-scoped things, it doesn't need dumb underscore rules for fake static.

I think it refers to modules not files, i.e. you want a library to call functions in other files, but the linker was so utterly inept it cannot hide internal APIs to users of the library.

Carbon dioxide
Oct 9, 2012

Volmarias posted:

Variable names should not start with underscore _ or dollar sign $ characters, even though both are allowed.

In Java, if you have an inner class (a class defined within the scope of another class), it will get compiled into OuterClass$InnerClass.

The $ is an allowed symbol for names in Java.

I once tried manually defining a class called Foo$Bar and also an inner class Bar inside Foo, and if you do that and have one reference the other the compiler will fail with a weird and unclear error.

And that's why you should never actually use the $ for names in your own code. Let it be reserved for the compiler.

QuarkJets
Sep 8, 2008

Carbon dioxide posted:

And that's why you should never actually use Java

Soricidus
Oct 21, 2010
freedom-hating statist shill

Falcon2001 posted:

I mean the one class per file is a Java thing though right? And in Java you can't have just a function hanging out by itself, it has to be contained within a class, so probably that's where that particular brainworm comes from.

One public top-level class per file. You can have any number of nested classes, and any number of non-public top-level classes.

In a year or so you’ll also be able to define the main() function without needing a class at all, thanks to the magic of JEP 445! There’s amazing innovation going on in the Java community, idk why people think it’s oldfashioned

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
counting on my fingers, a confused expression on my face

Only registered members can see post attachments!

QuarkJets
Sep 8, 2008

Beef posted:

Another cargo cult Java dev brain damage story:

I was told once that I should put each of my python functions in a separate file, because that's more modular.

That may have been a Matlab developer

Beef
Jul 26, 2004
Is that enforced or self inflicted in Matlab? I haven't touched it since uni.

IIRC the one class per file in Java came out of the early compiler and class loader implementation and they just stuck with it.

QuarkJets
Sep 8, 2008

Beef posted:

Is that enforced or self inflicted in Matlab? I haven't touched it since uni.

IIRC the one class per file in Java came out of the early compiler and class loader implementation and they just stuck with it.

It's sort of enforced through matlab's export system. You can write as many functions as you want in a file, but only the function that has the same name as the file can be seen by functions in other files. There are ways around this but that's how people are told to implement their projects: 1 file per function

DELETE CASCADE
Oct 25, 2017

i haven't washed my penis since i jerked it to a phtotograph of george w. bush in 2003
if you're writing python, and you use the keyword "class", you hosed up

FlapYoJacks
Feb 12, 2009

DELETE CASCADE posted:

if you're writing python, and you use the keyword "class", you hosed up

:wrong:

neosloth
Sep 5, 2013

Professional Procrastinator
what if there's an @dataclass above it

Canine Blues Arooo
Jan 7, 2008

when you think about it...i'm the first girl you ever spent the night with

Grimey Drawer

DELETE CASCADE posted:

if you're writing python, and you use the keyword "class", you hosed up

FlapYoJacks
Feb 12, 2009
As a python toucher, that is extremely correct.

Loezi
Dec 18, 2012

Never buy the cheap stuff

DELETE CASCADE posted:

if you're writing python, and you use the keyword "class" writing code, you hosed up

FlapYoJacks
Feb 12, 2009
Should have been a farmer. :smith:

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆

Loezi posted:

DELETE CASCADE posted:

if you're writing python, and you use the keyword "class" writing code touching computer, you hosed up

wolfman101
Feb 8, 2004

PCXL Fanboy
In Rails land the Rails loading/reloading system assumes one top level class or namespace per file named the same as the file.

Dirty Frank
Jul 8, 2004

FlapYoJacks posted:

Should have been a farmer. :smith:

Train Driver, toot toot!

QuarkJets
Sep 8, 2008

As soon as you touch a keyboard for the first time god sighs and writes your name on the hell list, but you can redeem your immortal soul by using Vigil, the eternal morally vigilant programming language

Volmarias
Dec 31, 2002

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

Dirty Frank posted:

Train Driver, toot toot!

The only good kind of engineer

Breetai
Nov 6, 2005

🥄Mah spoon is too big!🍌
Line 100 of the program:
Data ping
Set *some landing table
*Other conditionals*
Run;

Line 900:
Data ping
Set ping
Merge pong
Run;

Line 1400:
Proc sort
Data= ping
By *couple of variables*
Run;

Line 3000:
Data ping
Set ping
*Fuckton of conditionals*
Run;

Line 3500:
Dara final_ping
Set ping
Merge ding
Run;

Line 3900
Proc sort final_ping nodupkey
By *esoterica*
Run;

Line 4300:
Data final_ping
Set final_ping
Merge 20+ other datasets
Run;


...

My job is to locate the source of nondeterministic row selection in this program.

gently caress you.

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

Falcon2001 posted:

Bunch of angry words about getter/setter

Just dropping in to say I merged a PR today that removed (almost) all this bullshit and it was a net removal of 1533 lines of code. It's the best.

I think in terms of actual code base it was probably like...around 10% of our total lines of code. It is crazy.

Volmarias
Dec 31, 2002

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

Falcon2001 posted:

A giant code dump

I am glad that you were able to have a satisfying code movement

Blue Footed Booby
Oct 4, 2006

got those happy feet

FlapYoJacks posted:

Should have been a farmer. :smith:

Depending on where you farm, you may still have to deal with pythons

FlapYoJacks
Feb 12, 2009

Blue Footed Booby posted:

Depending on where you farm, you may still have to deal with pythons

And Rust.

OddObserver
Apr 3, 2009

Volmarias posted:

I am glad that you were able to have a satisfying code movement

Well, that puts a new spin on the concept of a version control system.

Beef
Jul 26, 2004

And you will still be sued by Apple.

Tann
Apr 1, 2009

I have an enum with 13 constructors and 141 entries. It's a bit of a disaster but enum does fit the type very well.
(like Magic the Gathering keywords - flying, vigilance...)

Volmarias
Dec 31, 2002

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

Tann posted:

I have an enum with 13 constructors and 141 entries. It's a bit of a disaster but enum does fit the type very well.
(like Magic the Gathering keywords - flying, vigilance...)

Not sure how much I would agree with that...

brap
Aug 23, 2004

Grimey Drawer
It’s normal and fine for enums to have a ton of cases.

Bongo Bill
Jan 17, 2012

If it's possible to enumerate all the cases, that's exactly what an enum is for.

QuarkJets
Sep 8, 2008

141 entries and 13 constructors sounds suspiciously like it's several enums stuffed into one definition

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


I've seen something like that, where the enum was designed to capture everything that could go wrong in establishing and maintaining a dialup connection. poo poo's complicated.

1337JiveTurkey
Feb 17, 2005

At least in Java it's possible to have enumerations implement an interface. I'd recommend at least considering that sort of thing although I know many people consider elaborate object oriented domain modeling its own sort of horror.

Kazinsal
Dec 13, 2011


Enums for complicated finite state machines tend to get real messy real quick.

Surprise T Rex
Apr 9, 2008

Dinosaur Gum

1337JiveTurkey posted:

At least in Java it's possible to have enumerations implement an interface. I'd recommend at least considering that sort of thing although I know many people consider elaborate object oriented domain modeling its own sort of horror.

Are Java enums sort of like Union types? From a C# perspective they’re confusing since in C# it’s just a strongly typed list of name-to-Integer mappings.

Adbot
ADBOT LOVES YOU

OddObserver
Apr 3, 2009

Surprise T Rex posted:

Are Java enums sort of like Union types? From a C# perspective they’re confusing since in C# it’s just a strongly typed list of name-to-Integer mappings.

IIRC they are classes that exist in a small named number of instances.

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