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
evensevenone
May 12, 2001
Glass is a solid.

spitefulcrow posted:

Even the example of a testing framework probably doesn't need this — since object attributes are mutable by default, mock.patch achieves the same goal in most cases without overwriting the innards of the actual function. It's conceptually cleaner to monkey-patch the entire function rather than violating the abstraction boundary. Yes, I know Python doesn't have real encapsulation because everything's mutable and this is just another case of that, but why break the conventions when you don't need to?

It looks like you can't do it to methods of classes, so things aren't quite as nuts as they might look:
Python code:
funcB.__code__ = funcA.__code___   # ok
import moduleA, moduleB
moduleB.funcB.__code__ = moduleA.funcA.__code__ #ok

instA = classA()
instB = classB()
instB.methodB.__code__ = instA.methodA.__code__ 
# raises AttributeError: 'instancemethod' object has no attribute '__code__'

classB.methodB.__code__ = classA.methodA.__code__ 
# same here, which is a little surprising

Adbot
ADBOT LOVES YOU

Amarkov
Jun 21, 2010

shrughes posted:

Because of obviosity? Why would you ever change a function body via spooky action at a distance? Maybe if you wanted to confuse everybody or had some other malicious goal in mind.

Any language with reasonable reflection capability will be capable of modifying behavior with spooky action at a distance. You can only choose how verbose the syntax is.

Lysidas
Jul 26, 2002

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

evensevenone posted:

It looks like you can't do it to methods of classes, so things aren't quite as nuts as they might look:
Python code:
funcB.__code__ = funcA.__code___   # ok
import moduleA, moduleB
moduleB.funcB.__code__ = moduleA.funcA.__code__ #ok

instA = classA()
instB = classB()
instB.methodB.__code__ = instA.methodA.__code__ 
# raises AttributeError: 'instancemethod' object has no attribute '__code__'

classB.methodB.__code__ = classA.methodA.__code__ 
# same here, which is a little surprising

:ssh:

Python code:
>>> class ClassA:
...   def f(self):
...     return 'A'
... 
>>> class ClassB:
...   def f(self):
...     return 'B'
... 
>>> instA = ClassA()
>>> instB = ClassB()
>>> instA.f.__func__.__code__ = instB.f.__func__.__code__
>>> instA.f()
'B'
>>> ClassA.f.__code__ is ClassB.f.__code__
True

Doctor w-rw-rw-
Jun 24, 2008

pokeyman posted:

KVO uses isa-swizzling, not method swizzling. (That is, it dynamically changes your object's class.)

And for what it's worth, both kinds of swizzling are generally considered "horrors" in Objective-C land right up until the minute you need them, at which point they're very handy.

Oh - did not realize that! The more you know. Thanks.

ExcessBLarg!
Sep 1, 2001

UraniumAnchor posted:

I think the eventual consensus was that the assignment in the non-executing block still causes the interpreter to make "what" a local variable from that point on, instead of a function. So I guess Ruby functions aren't truly first class?
As already stated, Ruby methods are not first-class. However, Ruby lambdas are. Had the first stanza been defined as:
code:
what = labmda do
    return 'the'
end
The result would've been entirely reasonable. Although it prints the string representation of the lambda object, "what.call" would actually have to be used to invoke it.

Thing is, it's pretty rare to define global methods in anything but short scripts and tutorials. If I'm going to write a script that does stuff mostly in the top-level anyways, I'd probably be using lambdas.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Doctor w-rw-rw- posted:

Oh - did not realize that! The more you know. Thanks.

It's actually pretty cool. Apple has a very tiny bit of info on the implementation, and the fabulous Mike Ash wrote it up in considerably more detail.

Beef
Jul 26, 2004

spitefulcrow posted:

Thanks for talking down to me

Chill, that was meant to be tongue in cheek. This is still a comedy forum.


shrughes posted:

Because of obviosity? Why would you ever change a function body via spooky action at a distance? Maybe if you wanted to confuse everybody or had some other malicious goal in mind.

A concrete example from the top of my head: Swapping an interpreted function body with a (byte-)compiled version.

It's indeed not something you want to do, unless you really are hacking at the language level. Ruby and Python are lovely languages for meta-programming, but coupled with their popularity it enabled a bunch of domain-specific languages and framework interfaces that would otherwise not be possible in, say, C.

JakeLiebenow
Apr 21, 2013
I don't really have any specific code to share, but I've recently been learning assembly as per a requirement for this embedded systems course I had to take. Microcontrollers, gotta love 'em. But really, I think that language really makes any coding a horror story in and of itself.

The memory management... Oh god, the memory management...

Wardende
Apr 27, 2013
No code here but I just got something from a Java dev and the directory structure is like this:

code:
C:\Project\project-common\src\main\java\com\host\project\common\foo\ASingleFooClass.java
Repeat for like a dozen "foo" directories. Why why why?! Where do people learn to do this? The directory structure in the FizzBuzz for Enterprise is starting to look like a case of Poe's Law!

JingleBells
Jan 7, 2007

Oh what fun it is to see the Harriers win away!

Wardende posted:

No code here but I just got something from a Java dev and the directory structure is like this:

code:
C:\Project\project-common\src\main\java\com\host\project\common\foo\ASingleFooClass.java
Repeat for like a dozen "foo" directories. Why why why?! Where do people learn to do this? The directory structure in the FizzBuzz for Enterprise is starting to look like a case of Poe's Law!

That's from Apache Maven, it handles all dependency management, running of unit & integration tests on build and packaging into an actual artifact. It does lead to problems on Windows when you have path lengths longer than 256 characters, especially if you have classes like AbstractSingletonProxyFactoryBean.

As for foo - that's because the class will be in the com.host.project.common.foo package, and package declarations have to be the same as on the file system, so you end up with pointless com\host\project folders with nothing but a subfolder in them.

Beef
Jul 26, 2004

JakeLiebenow posted:

I don't really have any specific code to share, but I've recently been learning assembly as per a requirement for this embedded systems course I had to take. Microcontrollers, gotta love 'em. But really, I think that language really makes any coding a horror story in and of itself.

The memory management... Oh god, the memory management...

And then you will come to the insight that C is a high-level programming language :p
The loops you have to jump through, eldritch incantations and litres of chicken blood to get the C runtime working with a simple usb or ethernet stack ...

Had any fun with the interrupt vectors yet?

Dren
Jan 5, 2001

Pillbug

Wardende posted:

No code here but I just got something from a Java dev and the directory structure is like this:

code:
C:\Project\project-common\src\main\java\com\host\project\common\foo\ASingleFooClass.java
Repeat for like a dozen "foo" directories. Why why why?! Where do people learn to do this? The directory structure in the FizzBuzz for Enterprise is starting to look like a case of Poe's Law!

Personally, I hate it. The workaround is to never ever look at a java project without an IDE.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Dren posted:

Personally, I hate it. The workaround is to never ever look at a java project without an IDE.

It's not a workaround, it's a requirement. Don't go against the grain, you'll only hate yourself even more.

1337JiveTurkey
Feb 17, 2005

Also make sure that your version control system is included as part of your FIGNORE environment variable so you can tab complete through the empty directories more quickly.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Strong Sauce posted:

Apparently ruby's parser/lexer is a horror.

http://programmingisterrible.com/post/42432568185/how-to-parse-ruby

Also tried to help out on topaz project, I know a goon works on that right?

I got through the first two sentences and immediately thought "Oh gently caress, this is sounding a lot like... PHP :stare:"

Dren posted:

Personally, I hate it. The workaround is to never ever look at a java project without an IDE.

Stare into the abyss

Foiltha
Jun 12, 2008

This is magnificent.

Dren
Jan 5, 2001

Pillbug
We have some code where the author kind of jammed all behavior into a single class hierarchy. One of the not so nice things that resulted was overuse of member variables. Like any time the author thought something might be needed he squirreled it away in a base class protected rather than scoping it to the functions that used it. So anytime you see a variable anywhere it's effectively a global and you (the reader) have no clue where or when it is modified without tracing the whole program. Can people give me some language to help talk about this? When I phrased it the way I just did the author didn't seem to understand the issue. I want to be sure I have my language right before I talk about this again so I can hopefully communicate more effectively.

b0lt
Apr 29, 2005

Dren posted:

We have some code where the author kind of jammed all behavior into a single class hierarchy. One of the not so nice things that resulted was overuse of member variables. Like any time the author thought something might be needed he squirreled it away in a base class protected rather than scoping it to the functions that used it. So anytime you see a variable anywhere it's effectively a global and you (the reader) have no clue where or when it is modified without tracing the whole program. Can people give me some language to help talk about this? When I phrased it the way I just did the author didn't seem to understand the issue. I want to be sure I have my language right before I talk about this again so I can hopefully communicate more effectively.

God class?

Dren
Jan 5, 2001

Pillbug

b0lt posted:

God class?

That's pretty good. I'd also really like a way to invert the phrase "don't make the scope of a variable larger than it needs to be" and turn it into something like "Scope variables to the top-level function that uses them, then pass them to helper functions".

nielsm
Jun 1, 2009



b0lt posted:

God class?

Bad encapsulation, poor separation of concerns, spaghetti in the making. I think also cyclomatic complexity refers to stuff like this, for something that can be measured. More class members increases the amount of state contained by the class, making it harder to reason about its correctness, if you want more of a "hard CS" argument.

And Google for "big ball of mud".

Dren
Jan 5, 2001

Pillbug
I guess this is ironic but I found the BBoM paper to be kind of unfocused so I stopped reading it after a bit. Still, it's a nice name. Thankfully our problem isn't there yet.

I've been thinking on a more specific way to phrase the concept "don't scope a variable larger than you need to". How's "Identify the scope of the first function where the variable is needed, then scope the variable below that function." If followed, it forces authors to pass state to helper functions rather than hold onto it as a pseudo-global class member or something. I like it because it applies to constructs like classes and modules where people who have been told that globals are bad will happily create pseudo-globals.

NFX
Jun 2, 2008

Fun Shoe

Hammerite posted:

always use the braces even when they are not needed. prevents accidental "oh I'll just add another line of code to this block. welp something is wrong" bugs
Or the more exotic ones. I ran into this thing a few days ago at work:
C++ code:
if (x == 0)
	if (foo)
		bar();
else if (x > 0)
	if (foo2)
		bar2();
else // x < 0
	bar3();
Gee coworker, maybe you should have tested that. According to the version control it's been in there since at least 2003. I guess it's not a very important piece of code.

Zorro KingOfEngland
May 7, 2008

We had a bug that was caused when one of our contractors did a mass replace of System.out.println with //System.out.println

Java code:
if(butts)
    //System.out.println("butts!")

doImportantBusinessThing(butts)
That was a fun one to debug.

Zorro KingOfEngland fucked around with this message at 22:46 on Jul 16, 2013

QuarkJets
Sep 8, 2008

NFX posted:

Or the more exotic ones. I ran into this thing a few days ago at work:
C++ code:
if (x == 0)
	if (foo)
		bar();
else if (x > 0)
	if (foo2)
		bar2();
else // x < 0
	bar3();
Gee coworker, maybe you should have tested that. According to the version control it's been in there since at least 2003. I guess it's not a very important piece of code.

But I de-indented the else if statement so it'll go with the first if statement right? :downs:

(although that is actually how it works in Python)

Suspicious Dish
Sep 24, 2011

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

NFX posted:

Or the more exotic ones. I ran into this thing a few days ago at work:
C++ code:
if (x == 0)
	if (foo)
		bar();
else if (x > 0)
	if (foo2)
		bar2();
else // x < 0
	bar3();
Gee coworker, maybe you should have tested that. According to the version control it's been in there since at least 2003. I guess it's not a very important piece of code.

http://en.wikipedia.org/wiki/Dangling_else

It's apparently a big debate in language design. I just always loved the straightforward answer "throw an error if it's ambiguous"

PrBacterio
Jul 19, 2000

NFX posted:

Or the more exotic ones. I ran into this thing a few days ago at work:
C++ code:
if (x == 0)
	if (foo)
		bar();
else if (x > 0)
	if (foo2)
		bar2();
else // x < 0
	bar3();
Gee coworker, maybe you should have tested that. According to the version control it's been in there since at least 2003. I guess it's not a very important piece of code.
This is why I always like to put braces around the body of any if and while statements, without exception, even when it is only a single line/statement. While it's true that most discussions about coding and indentation styles are mere bikeshedding, there's a small number of issues where there's a fairly clear-cut advantage to one way of doing it over the other.

Zorro KingOfEngland posted:

We had a bug that was caused when one of our contractors did a mass replace of System.out.println with //System.out.println

Java code:
if(butts)
    //System.out.println("butts!")

doImportantBusinessThing(butts)
That was a fun one to debug.
Here, this is another example of this same effect that can be entirely bypassed that way.

Suspicious Dish
Sep 24, 2011

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

Zorro KingOfEngland posted:

We had a bug that was caused when one of our contractors did a mass replace of System.out.println with //System.out.println

Java code:
if(butts)
    //System.out.println("butts!")

doImportantBusinessThing(butts)
That was a fun one to debug.

The real horror is that doImportantBusinessThing(null); does something important.

Sinestro
Oct 31, 2010

The perfect day needs the perfect set of wheels.
butts could be some sort of state object, and passing it a null generates state0.

Goat Bastard
Oct 20, 2004

Suspicious Dish posted:

The real horror is that doImportantBusinessThing(null); does something important.

It's java according to the code tag, so the if would try and cast null to a boolean primitive and throw a NullPointerException. So no worries on that front.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
I thought if (foo) was the same as if (foo != null) in Java.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

You're all wrong.



edit: That code would still be valid if it were a boolean, which in Java is a primitive so can't be null.

carry on then fucked around with this message at 04:33 on Jul 17, 2013

Sedro
Dec 31, 2008

carry on then posted:

edit: That code would still be valid if it were a boolean, which in Java is a primitive so can't be null.

It could also be a Boolean, which works as a boolean expression because it implicitly unboxes to a boolean (and naturally throws a NPE for null)

Java code:
Boolean butts = null;
if (butts) // NPE

Goat Bastard
Oct 20, 2004

Suspicious Dish posted:

I thought if (foo) was the same as if (foo != null) in Java.

Nope, boolean or not null Boolean only.

Amarkov
Jun 21, 2010
The default user password is the same as a full access database password.

The password contains the username of that database account.

There is a user account with the same credentials as that database account.

The user password database is not salted.


pls


e: It won't build when I try to use our framework's salting option, what's going wrong?
code:
switch (saltType) {
    case NO_SALT:
        password = getUserPassword(connection, username);
        break;
    case SINGLE_COLUMN:
        TODO: implement salting!
        throw new UnsupportedOperationException("Not implemented yet");
    [...]
}

Amarkov fucked around with this message at 01:05 on Jul 18, 2013

SavageMessiah
Jan 28, 2009

Emotionally drained and spookified

Toilet Rascal

csammis posted:

We once had a minidump faxed to us for debugging purposes. It ended up being 84 pages long. When we asked why they had to fax it the answer was "in case it needs redaction" :psypop:

edit: in case this sounds like I'm recalling a distant memory this happened in March of 2013.

Heh, I get logs, xml files, stack traces and all kinds of other crap faxed to me all the time. A hazard of having your software running in secure facilities with ironclad policies about moving electronic info out.

Call it an Occupational Horror.

Amarkov
Jun 21, 2010

Amarkov posted:

The default user password is the same as a full access database password.

The password contains the username of that database account.

There is a user account with the same credentials as that database account.

The user password database is not salted.

Amarkov's coworker posted:

No, see, it's okay to just use an MD5 hash, because we're using AWS! I'm pretty sure Amazon isn't going to get hacked bro.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Amarkov posted:

[quote="Amarkov's coworker"]
No, see, it's okay to just use an MD5 hash, because we're using AWS! I'm pretty sure Amazon isn't going to get hacked bro.

:eyepop:

Semi-related note: a developer once told me with a straight face that a bunch of admin controllers without permission checks were safe because "they were only accessed through AJAX."

Amarkov
Jun 21, 2010
It turns out my assumptions were fatally flawed. What I thought was the production database was actually a secondary database, used for stuff we haven't ported off of MySQL yet.

The actual production database, of course, is configured not to accept direct requests from anywhere except localhost. As such, it does not require a password.

(On the plus side, they've agreed to let me actually fix this now.)

Wardende
Apr 27, 2013

Amarkov posted:

The actual production database, of course, is configured not to accept direct requests from anywhere except localhost. As such, it does not require a password.

That's fine because it means that a hacker would have to physically be at the machine which hosts the database to hack it. *takes a monster glue huff* wooooooooooooooooooooooooooooooh. Anyway, we use keycards, so we're covered.

Adbot
ADBOT LOVES YOU

QuarkJets
Sep 8, 2008

Wardende posted:

That's fine because it means that a hacker would have to physically be at the machine which hosts the database to hack it. *takes a monster glue huff* wooooooooooooooooooooooooooooooh. Anyway, we use keycards, so we're covered.

But then there's no reason to not have a password, right? So you may as well have one in case, heaven forbid, a hacker gets to the physical machine and has someone's keycard + pin?

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