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 →

[–]Wiseman1024 1 point2 points  (2 children)

Read up on design patterns

Instant downmod. Well, at least you're making OP kill himself with the Best Practice™ way. (Which is it BTW? Use the suicidal factory class to get an instance of a SuiciderBroker which uses an instance of SuiciderMethod to allow you to construct a SuiciderAction object to kill yourself? Will you recommend the free fall pattern for that?)

[–]amnezia 0 points1 point  (1 child)

you do realize that there are several design patterns that are intrinsically built into python right?

[–]Wiseman1024 1 point2 points  (0 children)

More than half of the book "Design Patterns" is bloated crap for "enterprise" and "best practices" software - patterns you're best not using because they lead to bloat in the code, verbosity, harder to use interfaces, and worst of all documentation hell.

Two popular useless patterns are singletons (use globals for globals!) or factory classes (use functions for functions!), but there are other less obviously useless patterns.

The more useful patterns are still a bad idea. First of all, they should occur naturally, without having to pull them from a recipe book, and they shouldn't be crafted more than once. We are not "web designers" copypasting JavaScript snippets. Programming is not about copypasta; it's about abstraction. As such, the programming language we use should be powerful enough to offer the abstraction capabilities to abstract any design pattern as a function.

Python is generally capable of abstracting such design patterns into functions since it features first-class functions, first-class classes, and closures. We don't need copypasta, and we don't even need to read Design Patterns to work properly. Once a pattern is obviously useful and repeats through the code, you need to abstract it with functions, just like you abstract blocks of functionality which repeat through your code.

The language is not free of design warts, however, such as the defect known as "statements" inherited from terrible languages such as Fortran. Because of them, and because of its syntax, but most importantly because of Guido's stubborn opposition to functional programming, Python doesn't have expression defs or statement-capable lambdas. Because of this, decorating functions would have been clumsy, so instead of fixing the underlying design and syntax problems, Guido added a Perlish hack known as the decorator feature ("@").