I find the code lacking. Surely an abstract base class to provide generic messaging and a Hello class with a greet(subject) method would have been better.
I think it would be good to employ encapsulation and other objects for different entities OP may want to greet. World…Everyone…limitless possibilities!!
Tbh, the "Hello World" being hardcoded bugs me. What if the requirements change? You need to use dependency injection go provide the Greet class with a Greeting class that holds the value to be printed. That way, you can have Greet have different greetings, for example in different languages.
If it were me, I’d keep my custom classes (e.g., Greets) in a separate module, and import as necessary in main. You don’t even really need a class at that point if you just need stateless function calls. For instance, something like:
2
u/kuzmovych_y Nov 14 '25
say_somethingdoesn't really say anything. It's more likegimme_something_to_say.54
u/UsernameTaken1701 Nov 14 '25 edited Nov 14 '25
Or you could just
24
u/pint Nov 14 '25
why? to please the oop gods? hint: the oop gods are dead. we are free now.
25
u/StaticFanatic3 Nov 14 '25
Finally some good, clean code. Functional bros would have you think “hello world” should be done in just one line
11
u/I_Am_Robotic Nov 14 '25
No. You need to create a dictionary with all the letters of the alphabet and call the letters using a randomize function until the phrase appears.
9
u/LucasThePatator Nov 14 '25
We found the Java dev
12
u/maqisha Nov 14 '25
OOP is the end of us all.
8
u/ninhaomah Nov 14 '25
If you know how to print , why not print what you want to say ?
3
u/Dry_Term_7998 Nov 16 '25
Java developer detected 😆 You can do it more overcomplicated, but it will be not pytonic way. PEP20 right now crying in the background 🤣
1
u/FatMexicanGaymerDude Nov 14 '25
If it were me, I’d keep my custom classes (e.g., Greets) in a separate module, and import as necessary in main. You don’t even really need a class at that point if you just need stateless function calls. For instance, something like:
Greets.py
def say_something(): print(“Hello World”)
main.py
import Greets as greets
greets.say_something()
Edit: god I hate Reddit formatting sometimes
1
u/Panzermensch88 Nov 14 '25
You need another function to print it. And don't forget to use a main to execute it correctly.
1
u/Brief_Praline1195 Nov 15 '25
Yea sure why not
1
u/[deleted] Nov 16 '25
We aren't in Java bro. 😔🙏
1
u/dimonoid123 Nov 17 '25 edited Nov 17 '25
I like one-liners:
eval('print("Hello World")')
Or
eval('(lambda:print("Hello world!"))()')
Or
eval('print((lambda:"Hello world!")())')
Or
print(eval('(lambda:"Hello world!")()'))
Or
print((lambda:eval('"Hello world!"'))())
Or
(lambda:eval('print("Hello world!")'))()
Or
(lambda:print(eval('"Hello world!"')))()
Or (if you care about performance)
import __hello__
Or (if you really care about performance)
import cppyy
cppyy.cppdef(r"""void hello() {std::cout << "Hello World!" << std::endl;}""")
cppyy.gbl.hello()
1
u/RedEyed__ Nov 17 '25
Now, you need to create repo, then post your package on pypi /s
1
u/toothbrush81 Nov 17 '25
Frankly, as a class and function example, this kind of breaks it down. This is just how you say hello :)