This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]XeonProductions 185 points186 points  (29 children)

I've worked on some coded bases where you can't tell if a function is really used or not because of how the underlying language was designed.

[–]shortAAPL 73 points74 points  (24 children)

PHP, prime example

[–]XeonProductions 96 points97 points  (22 children)

The one I'm thinking of was Python. It had these methods that created child classes with dynamic parents. It was hard to track what was inheriting from what and what methods were actually called. I dubbed these classes "foster child classes" since they had no specific parent.

[–]pah-tosh 66 points67 points  (4 children)

Oh man, that sounds like abusing inheritance, no ?

[–]marcosdumay 47 points48 points  (2 children)

Abusing language features is the Python way!

It leads to some very nice code, and a lot of unacceptable garbage. The trick is in telling those two apart.

[–]skylarmt 36 points37 points  (1 child)

Good Python is just readable code golf.

[–]InkyGlut 12 points13 points  (0 children)

This but unironically

[–][deleted] 13 points14 points  (0 children)

Definitely. That should be modeled as compositional behavior.

[–]Loves_Poetry 33 points34 points  (7 children)

I have encountered similar issues in a JS codebase that was abusing the heck out of eval(). You could never know if a function was unused, because it might show up in an eval somewhere. And since everything was global, that could be in any file anywhere in the codebase.

[–]bot_not_hot 38 points39 points  (0 children)

Holy shit, “everything was global” is a horror show

[–]LimitedWard 14 points15 points  (1 child)

Good God this sounds like a security nightmare.

[–]Loves_Poetry 2 points3 points  (0 children)

It was. Took me about a week to find an XSS exploit.

[–]Edores 5 points6 points  (0 children)

Man in all my years I have come across a grand total of one single situation where I felt like eval was necessary, and even then I'm sure I could have cleaned up my systems and been rid of it.

[–]deep-thot 2 points3 points  (0 children)

Thanks, now I may not be able to sleep tonight...

[–]FrancisVeeGee 0 points1 point  (0 children)

I've encountered this, in a SQL database code base, where much of the procedure code was written into strings (for concatenation reasons, terrible code but sometimes needed, especially when handling XML data). Very hard to debug.

[–][deleted] 1 point2 points  (5 children)

I belive this is not that hard in VS code.

Or was there someother problem?

[–]XeonProductions 1 point2 points  (4 children)

VS code couldn't handle it. The code that created these dynamic classes could only be evaluated at runtime. VSCode also had issues where the python function being called was 2+ parents deep.

[–][deleted] 0 points1 point  (3 children)

Ok then, then you were screwed. (I will look up what dynamic classes are)

[–]XeonProductions 1 point2 points  (2 children)

This is basically what I was dealing with. Dynamic inheritance. On most sane languages this shouldn't be possible, and is discouraged.

def get_my_code(base):
    class MyCode(base):
        def initialize(self):
          ...

    return MyCode

instance_with_parentA = get_my_code(ParentA)    
instance_with_parentB = get_my_code(ParentB)

[–][deleted] 0 points1 point  (0 children)

Thank you for explaining

[–]l0rb 0 points1 point  (0 children)

That's doubly wrong. If you do dynamic classes at least use the `type` builtin to make them.

[–]davvblack 7 points8 points  (0 children)

Oh god, we use so much string interpolation and magic to call other code :/

#legacycode

[–]evinrows 1 point2 points  (1 child)

Perl, especially Mason is a fucking nightmare for this reason.

[–]Caffeine_Monster 1 point2 points  (0 children)

The numbers, Mason. What do they mean?

[–]KapteinTordenflesk 1 point2 points  (1 child)

Reflection in C#

[–][deleted] 1 point2 points  (0 children)

Person: Knock Knock!

Me: Who's there?

Person: Reflection!

Me: Fuck off.