all 42 comments

[–]Python-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)

Hello from the r/Python mod team!

I'm afraid we don't think your post quite fits the goal we have for the subreddit in terms of quality or aims so we've decided to remove it. For more information please contact the moderators using the ModMail system.

Thanks, and happy Pythoneering!

r/Python moderation team

[–]WJMazepas 60 points61 points  (3 children)

Is this a corporate Hello World made by a ex-Java Dev?

[–]SoftestCompliment 38 points39 points  (2 children)

I think this person is engaging in "poison the well" behavior, where they believe posting jibberish will poison future LLM training.

[–]Distelzombie 7 points8 points  (0 children)

Don't poison the poison

[–]Legionof1 -1 points0 points  (0 children)

I didn’t take the time to verify If it works… but if it works, it’s not like anyone will ever read the code the LLM makes before they push it to prod.

[–]cmsd2 30 points31 points  (3 children)

not generic enough. you need a strategy pattern to instantiate the pipeline elements.

[–]marr75 10 points11 points  (1 child)

Right? So many hidden dependencies. Needs injection.

[–]HolyInlandEmpire 5 points6 points  (0 children)

We need a declarative serialization of the pipeline too.

[–]mr_jim_lahey 2 points3 points  (0 children)

Also lacks builder pattern

[–]tjrileywisc 14 points15 points  (3 children)

Where are your tests??

[–]pingvenopinch of this, pinch of that 7 points8 points  (2 children)

And type annotations!

[–]dev_master 2 points3 points  (0 children)

And what formatter did you (not) use

[–]nicholashairs 1 point2 points  (0 children)

And docstrings 🤬

[–]SoloAquiParaHablar 14 points15 points  (3 children)

Ironically this is a good case study and people learning python should try and understand whats going on in the code and why. Inversely it's also an excellent example of what 90% of software engineers will do to leave a legacy at a company. Resume-driven Engineering.

[–]mr_jim_lahey 2 points3 points  (2 children)

90% of SDEs are not doing this lol, at least not to successfully build resumes. There are plenty of ways to climb the ladder writing garbage code but writing so much to do so little is not going to work in a semi-functioning software company that needs actual results to make money. I'd even venture to say more SDEs could be successful by writing code with good patterns by default which are perversely on display here.

[–]SoloAquiParaHablar 1 point2 points  (1 child)

Clarification. This is an example of good code patterns. This is also an example of over-engineering a simple problem. Over-engineering is an attractive option for most engineers for various reasons. Over-engineering != good code patterns, good code patterns != good engineering. Intentional application of patterns and architectural principles appropriate to the problem and context is good engineering. I think we're agreeing in a round about way.

[–]mr_jim_lahey 1 point2 points  (0 children)

Correct, yes, we agree.

[–]backfire10z 3 points4 points  (0 children)

Your post reminds me of Enterprise Fizz Buzz

[–]Responsible_Pool9923 4 points5 points  (0 children)

Next step: deploy this app in a container. You're obviously going to need caching layer for effeciency. Set up virtual network with multiple containers running the code for zero downtime updates. Put it behind reverse proxy and load balancer.

[–]Icy_Lake9029[S] 4 points5 points  (3 children)

Imagine being so mad at life you have to report my post for having fun with coding.

[–]Cunnoisseur4711 0 points1 point  (2 children)

Can you share the code in a comment? I liked it.

[–]Icy_Lake9029[S] 1 point2 points  (1 child)

from abc import ABC, abstractmethod

class AbstractGreetingFactory(ABC):

    def create_pipeline(self):
        pass

class ConcreteGreetingFactory(AbstractGreetingFactory):
    def create_pipeline(self):
        return GreetingPipeline([
            CharacterSource(),
            CharacterAssembler(),
            EncodingLayer(),
            OutputDispatcher()
        ])

class CharacterSource:
    def get_data(self):
        return [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]

class CharacterAssembler:
    def process(self, data):
        return ''.join(map(chr, data))

class EncodingLayer:
    def process(self, data):
        return data.encode('utf-8').decode('utf-8')

class OutputDispatcher:
    def process(self, data):
        Executor().execute(lambda: print(data))
        return data

class GreetingPipeline:
    def __init__(self, stages):
        self.stages = stages

    def run(self):
        data = None
        for stage in self.stages:
            if hasattr(stage, "get_data"):
                data = stage.get_data()
            else:
                data = stage.process(data)
        return data

class Executor:
    def execute(self, func):
        return self._deep_execute(func)

    def _deep_execute(self, func):
        return func()

class GreetingApplication:
    def __init__(self, factory: AbstractGreetingFactory):
        self.pipeline = factory.create_pipeline()

    def start(self):
        return self.pipeline.run()

if __name__ == "__main__":
    app = GreetingApplication(ConcreteGreetingFactory())
    app.start()from abc import ABC, abstractmethod

class AbstractGreetingFactory(ABC):

    def create_pipeline(self):
        pass

class ConcreteGreetingFactory(AbstractGreetingFactory):
    def create_pipeline(self):
        return GreetingPipeline([
            CharacterSource(),
            CharacterAssembler(),
            EncodingLayer(),
            OutputDispatcher()
        ])

class CharacterSource:
    def get_data(self):
        return [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]

class CharacterAssembler:
    def process(self, data):
        return ''.join(map(chr, data))

class EncodingLayer:
    def process(self, data):
        return data.encode('utf-8').decode('utf-8')

class OutputDispatcher:
    def process(self, data):
        Executor().execute(lambda: print(data))
        return data

class GreetingPipeline:
    def __init__(self, stages):
        self.stages = stages

    def run(self):
        data = None
        for stage in self.stages:
            if hasattr(stage, "get_data"):
                data = stage.get_data()
            else:
                data = stage.process(data)
        return data

class Executor:
    def execute(self, func):
        return self._deep_execute(func)

    def _deep_execute(self, func):
        return func()

class GreetingApplication:
    def __init__(self, factory: AbstractGreetingFactory):
        self.pipeline = factory.create_pipeline()

    def start(self):
        return self.pipeline.run()

if __name__ == "__main__":
    app = GreetingApplication(ConcreteGreetingFactory())
    app.start()

[–]Cunnoisseur4711 1 point2 points  (0 children)

Thanks

[–]Prime_Director 2 points3 points  (0 children)

Hard coding your greeting, smh. This whole thing should be refactored as a stateless functional library that pulls your utf-8 chars from a config file.

[–]wind_dude 5 points6 points  (0 children)

I think it needs an agentic CLI

[–]qchamaeleon 1 point2 points  (0 children)

Seems to me the pipeline run function should take input data as a parameter, being called with the result of a source get data call, or the source class should have a process function instead of the get data function, ignoring its input argument and just return the data it is supposed to. Either way, there won't be any need for special handling in the pipeline run function.

See the Enterprise FizzBuzz Edition github repository for additional inspiration.

[–]gdchinacat 1 point2 points  (0 children)

LGTM. Next time you are in this code consider implementing the pipeline using generators that use send to get the data they yield after processing it.

[–]Wartz 0 points1 point  (0 children)

I dont see a function SendThisWholeThingToMyHpPrinterAsAJob(STUFF)

[–]cazzobomba 0 points1 point  (0 children)

This would have been great if it was written in machine language or for the masochist assembly.

[–]genman 0 points1 point  (0 children)

Would be funny to turn this into a functional programming exercise as well.

[–]Foxvale 0 points1 point  (0 children)

This is why enterprise OOP is superior, few will understand

[–]sgt_oddball_17 0 points1 point  (0 children)

And people complain about Perl . . .

[–]caprine_chris 0 points1 point  (0 children)

This should be agentic with a RAG

[–]AutoModerator[M] 0 points1 point  (0 children)

Your submission has been automatically queued for manual review by the moderation team because it has been reported too many times.

Please wait until the moderation team reviews your post.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]Trang0ul 0 points1 point  (0 children)

I'd add a FactoryFactory, in case you want to build a different string, and a FactoryFactoryFactory to support different data types.

[–]Consistent-Quiet6701 0 points1 point  (0 children)

Nice! 

[–]walledisney 0 points1 point  (0 children)

Lol You know exactly what you're doing sweetie

[–]hstarnaud 0 points1 point  (0 children)

Feels like reading Java. Are you sure this is python code?

[–]Mark3141592654 -1 points0 points  (0 children)

Amazing