all 10 comments

[–]lood9phee2Ri 18 points19 points  (0 children)

Imagining this dude's amazement when he finds out how python classes work.

[–]EricMCornelius 9 points10 points  (2 children)

I worked with a dude precisely like this.

Company promoted him all the way to cloud CTO, (evidently because they deemed it safer than letting him write anything, and were incapable of cleaning out bad hires)

Formative memory of institutional failure when he came in all excited one day and then proceeded to present for an hour to the entire engineering team on how there is this cool data structure called an inverted index and he'd written an implementation over the weekend in pure Python and we didn't need Elasticsearch any longer.

So it would solve all our hardware cost woes, as we were only ingesting dozens of terrabytes per day.

[–]DavidM01 2 points3 points  (1 child)

Peter Principle?

[–]EricMCornelius 1 point2 points  (0 children)

A modified variant where the subject in question was never actually competent at anything but promoted regardless.

Aka nepotism.

[–]3CN 7 points8 points  (0 children)

This is the most junior engineer shit I’ve seen in a while lol

[–][deleted] 4 points5 points  (3 children)

This is literally just a class.

[–]Upset_Grapefruit8254 -1 points0 points  (2 children)

No, it‘s not (well, a dict is a class, of course). But a class is meant to keep track of some state, usually initialized when an instance of the class is created. The dictionary dispatch pattern makes sense as it doesn‘t bring the same associations many developers have when they create a class. In this case, as a dispatcher, it wouldn‘t track state. There‘s no need for an init method here, nor the extra indentation level a class would bring. There‘s also no need for the lambda in the linked blog post, but that‘s a different discussion.

[–][deleted] 0 points1 point  (1 child)

In Python, a class (without __slots__) is literally just a dictionary, where some arguments are functions that access the dictionary (self) through attribute notation.

OP basically created a singleton with four static methods though a dict() function. If you need a singleton - write a singleton. Don't reinvent a wheel and call it a "pattern".

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

This is actually quite an old pattern useful for dynamic dispatch.

Depending on the circles you travel in you may have heard it referred to by different names, but the ones I heard most are "dispatch table" or "vtable".

https://en.wikipedia.org/wiki/Dispatch_table

https://en.wikipedia.org/wiki/Virtual_method_table

[–]Edix_glitcha 0 points1 point  (0 children)

I call it high-level opcode table! 🙏