this post was submitted on 15 Apr 2024
396 points (91.8% liked)

Programmer Humor

19551 readers
1014 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 
all 46 comments
sorted by: hot top controversial new old
[–] victorz@lemmy.world 83 points 7 months ago (2 children)

Ha. Cause there's no getter. I get it. I think?

[–] dohpaz42@lemmy.world 66 points 7 months ago (1 children)

I get it.

No you don’t; there’s no getter.

[–] victorz@lemmy.world 29 points 7 months ago (1 children)
[–] Batman@lemmy.world 6 points 7 months ago (1 children)

You don't get the context of this joke

[–] fsxylo@sh.itjust.works 6 points 7 months ago (1 children)

var context = getContext();

[–] lightnegative@lemmy.world 3 points 7 months ago

var context = RuntimeSingletonFactory.getCurrentFactory().getCurrentRuntimeSingleton().getContext()

[–] 4am@lemm.ee 23 points 7 months ago (1 children)

It’s also an inside Joke

[–] intensely_human@lemm.ee 2 points 7 months ago

And the Joker gets it, but you don’t.

[–] sik0fewl@lemmy.ca 69 points 7 months ago (1 children)

Upon reflection, I do get the joke now.

[–] rimjob_rainer@discuss.tchncs.de 6 points 7 months ago

This one gets it

[–] JustBrian7872@feddit.de 47 points 7 months ago

They don't call me AbstractJokerAdapterFactoryProxy for nothin'

[–] hydroptic@sopuli.xyz 34 points 7 months ago (1 children)

Where are your gods now?

public static Joke getTheJoke(Meme yourMeme) {
  Field jokeField = Meme.class.getDeclaredField("joke");
  jokeField.setAccessible(true);
  return (Joke) jokeField.get(yourMeme);
}
[–] RonSijm@programming.dev 16 points 7 months ago* (last edited 7 months ago) (5 children)

Is it Java? It looked like ~~Microsoft Java~~ C# to me...

    public static void Main(string[] args)
    {
        var meme = new Meme();
        var joke = GetTheJoke(meme);
    }
    
    public static Joke GetTheJoke(Meme theMeme)
    {
        var memeType = typeof(Meme);
        var jokeField = memeType.GetField("Joke", BindingFlags.NonPublic | BindingFlags.Instance);
        return (Joke)jokeField.GetValue(theMeme);
    }
[–] PoolloverNathan@programming.dev 4 points 7 months ago

There isn't an unnecessary level of capitalization; seems to be regular Java with Allman braces.

[–] hydroptic@sopuli.xyz 3 points 7 months ago

Frankly it's been a while since I wrote either one. I just assumed Java because of the naming convention, and I didn't see anything I took as obviously un-Java in the class definition

[–] rimjob_rainer@discuss.tchncs.de 2 points 7 months ago

Because C# is a Java clone

[–] noproblemmy@programming.dev 1 points 7 months ago (1 children)

If you have to cast your joke it isn't funny?

[–] Karyoplasma@discuss.tchncs.de 1 points 7 months ago

Could just change it to public static Object GetTheJoke, no?

[–] BassaForte@lemmy.world 32 points 7 months ago

public Joke Joke { private get; set; }

[–] Xylight@lemdro.id 18 points 7 months ago (2 children)

i hate this programming pattern with a passion.

[–] someonesmall@lemmy.ml 26 points 7 months ago (2 children)
[–] Xylight@lemdro.id 5 points 7 months ago (1 children)
[–] someonesmall@lemmy.ml 7 points 7 months ago (2 children)

So what is a better paradigm in your opinion?

[–] Xylight@lemdro.id 8 points 7 months ago

immutable objects, i like functional programming

[–] sudo@programming.dev 4 points 7 months ago (2 children)

Immutable members. Set in constructor then read only. The Builder pattern is acceptable if you're language is an obstacle.

[–] AVincentInSpace@pawb.social 7 points 7 months ago (1 children)

found the functional programming purist

[–] sudo@programming.dev 1 points 7 months ago
[–] Piafraus@lemmy.world 3 points 7 months ago (1 children)

So do you create new objects every time you need to change state?

[–] sudo@programming.dev 3 points 7 months ago (1 children)

You avoid having mutable state as much as possible. This is a pretty standard concept these days.

[–] Piafraus@lemmy.world 2 points 7 months ago (1 children)

Can you please give me an example - let's say I have a big list of numbers and I need to find how many times each number is there.

I would expect a mutable dictionary/map and a single pass through. How would you do that without mutable datastructure?

[–] sudo@programming.dev 2 points 7 months ago* (last edited 7 months ago) (1 children)

Very standard use case for a fold or reduce function with an immutable Map as the accumulator

val ints = List(1, 2, 2, 3, 3, 3)
val sum = ints.foldLeft(0)(_ + _) // 14
val counts = ints.foldLeft(Map.empty[Int, Int])((c, x) => {
  c.updated(x , c.getOrElse(x, 0) + 1)
})

foldLeft is a classic higher order function. Every functional programming language will have this plus multiple variants of it in their standard library. Newer non-functional programing languages will have it too. Writing implementations of foldLeft and foldRight is standard for learning recursive functions.

The lambda is applied to the initial value (0 or Map.empty[Int, Int]) and the first item in the list. The return type of the lambda must be the same type as the initial value. It then repeats the processes on the second value in the list, but using the previous result, and so on until theres no more items.

In the example above, c will change like you'd expect a mutable solution would but its a new Map each time. This might sound inefficient but its not really. Because each Map is immutable it can be optimized to share memory of the past Maps it was constructed from. Thats something you absolutely cannot do if your structures are mutable.

[–] Piafraus@lemmy.world 2 points 7 months ago (1 children)

So you have memory space which is reused... Which essentially makes it a mutable memory structure, where you update or add with new data keys... No?

[–] sudo@programming.dev 2 points 6 months ago

No. Persistent Data Structures are not mutable. The memory space of an older version is not rewritten, it is referenced by the newer version as a part of its definition. ie via composition. It can only safely do this if the data it references is guaranteed to not change.

x = 2 :: 1 :: Nil -- [2, 1]
y = 3 :: x -- [3, 2, 1]

In this example both x and y are single linked lists. y is a node with value 3 and a pointer to x. If x was mutable then changing x would change y. That's bad™ so its not allowed.

If you want to learn more about functional programming I suggest reading Structures and Interpretation of Computer Programs or Learn You a Haskell for Great Good

[–] purplemonkeymad@programming.dev 3 points 7 months ago (1 children)
[–] mexicancartel@lemmy.dbzer0.com 5 points 7 months ago

Well you wouldn't get it

[–] intensely_human@lemm.ee 4 points 7 months ago
[–] JayDee@lemmy.ml 14 points 7 months ago (1 children)

Is it possible to get the joke at runtime using the spectre exploit?

[–] coloredgrayscale@programming.dev 5 points 7 months ago

Not required. Looks like Java, just use reflection.

[–] Kolanaki@yiffit.net 7 points 7 months ago

Stop making private jokes and start posting them publicly. We wanna laugh too, ya selfish bastid.

[–] reverendsteveii@lemm.ee 5 points 7 months ago

throw new SameJokeException();

[–] LinearArray@programming.dev 1 points 7 months ago

now i get it, do i?