5 ms·
"Design patterns implemented in Java" I'd argue that Design Patterns mostly appeared because of Java. Because of people hitting the wall with Java; Java does n
by flavio81 9y ago
"Design patterns implemented in Java"
I'd argue that Design Patterns mostly appeared because of Java. Because of people hitting the wall with Java; Java does not allow metaprogramming; Java did not allow class members (it allows instance members); Java does not allow multiple inheritance; Java has a cumbersome and underpowered exception handling system; Java's OOP is really strict and limited; no real functions that can be passed around (not even in Java 8); recursion can't use tail call optimization... etc etc
because of ALL this, then developers had to resort to applying the same workarounds. And such workarounds were collected, tagged, and proposed as
Design Patterns
by the gang of four.
But seriously, if the authors write,
"All designs should be as simple as possible. You should start with KISS, YAGNI (...)"
Then they should be looking at alternatives to Java in the first place. It's 2017 and there are other alternatives that even run in the JVM (if this is a requirement).
- evanspa 9y agoJava has always allowed for class members using the "static" keyword. The GoF book predates the public release of Java. The code samples in GoF are in C++ and Smalltalk. Correct me if I'm wrong, but Java 8 does allow functions to be passed around. E.g., if a function takes as input a Runnable, I can pass a no arg lambda expression as input.
- gozur88 9y agoThere are actually a bunch of different kinds of functions you can use in lambda expressions in Java 8 (43, to be exact). https://www.tutorialspoint.com/java8/java8_functional_interfaces.htm https://www.tutorialspoint.com/java8/java8_functional_interf... Beyond that, by at least 1.4 you could pass methods using the reflections API, though that was kludgy in a lot of ways.
- TremendousJudge 9y agoYou realize that Design Patterns: Elements of Reusable Object-Oriented Software was published in 1994 while Java 1.0 was published in 1996 right?
- jasode 9y ago>I'd argue that Design Patterns mostly appeared because of Java. [...] And such workarounds were collected, tagged, and proposed as Design Patterns Fyi... "Design Patterns" in 1994 predates Java 1995. Design patterns in some form have been around as long as computers have been around. Independent teams of programmers notice a repetition of code or a higher-level idea and they make it a convention. E.g. the "observer" pattern was something Smalltalk and Objective-C programmers did more than a decade before Java. Before "Design Patterns" became a meme/book, different teams used different vocabulary. Maybe they'd call it the "event watcher code convention" instead of "observer pattern". DP was a book of past practices gathered from the real world and it got everyone to converge on the same vocabulary to label what they were already doing.
- deleted 9y ago[deleted]
- twblalock 9y agoThe Gang of Four book was written in 1994, and Java was released to the public in 1995. The patterns were actually developed by C++ programmers, and the authors sought to categorize and formalize them. The patterns are useful in the context of object-oriented programming in general, not just Java. The language most of the examples are written in, C++, does allow multiple inheritance and metaprogramming, and a bunch of other stuff Java does not allow. The patterns are still useful in C++ despite those features, which is why C++ developers came up with them in the first place.
- flavio81 9y agoI realize i made an anachronical mistake. However the Design Patterns book and the 'design patterns' mindset is most popular with Java developers. Sorry but I do stand on my criticism of Design Patterns as applied today. > The language most of the examples are written in, C++, does allow multiple inheritance and metaprogramming, You're being very generous with C++ if you consider it does allow metaprogramming. It does not, if we compare it with the languages that make good use of metaprogramming: Lisp, Scheme, Racket, and now Julia.
- chii 9y agoYou cant move the goal post! C++ template is meta programming, as it's Turing complete. It's ugly and messy, but usable enough.
- flavio81 9y agoThere is a ton of usability, scope, and power difference between the metaprogramming of C++ templates versus the metaprogramming of the Lisp family of languages (and Julia), which is what is usually considered as metaprogramming in the practical sense, languages that are arguably designed around metaprogramming as a fundamental feature. Just as assembly language is also turing complete, but there is also a ton of usability difference between it versus C/C++, in favor of C/C++ and with little performance penalty.
- 9y ago
- ivan_gammel 9y agoTail call optimization is a way for compiler to align functional recursive algorithm with stack-based procedural reality. Since Java is not a functional language and has sufficient expressive power to write iterations as... iterations, good programmer will just write a for loop and will not bother about a feature that is basically unnecessary in multi-paradigm language. Oh, by the way, recursion is a functional design pattern, isn't it?
- flavio81 9y ago> Since Java is not a functional language and has sufficient expressive power to write iterations as... iterations, good programmer will just write a for loop and will not bother about a feature that is basically unnecessary in multi-paradigm language. Ok, so you think recursion is unnecessary in a multi-paradigm language. Which implies also that multi-paradigm languages shouldn't be really multi-paradigm languages... Java, by the way, is hardly a multi-paradigm language. And you imply that the reason one uses recursion is because one can't "write iterations as ... iterations". You should realize that recursion is used whenever expressing the problem in a recursive way would make the problem easier to program and/or clearer to express, etc. Not because of recursion being fancy or fashionable. Recursion is a computer science technique, not a "Design Pattern".
- sorokod 9y agoKotlin is also a "non functional language" but does tail recursion optimization via tailrec keyword
- everheardofc 9y agoBetter tell all those haskell developers to stop stealing the monad pattern from java. https://github.com/iluwatar/java-design-patterns/tree/master/monad https://github.com/iluwatar/java-design-patterns/tree/master... And here is a second source if you don't believe me or iluwatar >In functional programming, a monad is a design pattern that defines how functions, actions, inputs, and outputs can be used >together to build generic types,[1] with the following organization: > > Define a data type, and how values of that data type are combined. > Create functions that use the data type, and compose them together into actions, following the rules defined in the first >step. https://en.wikipedia.org/wiki/Monad_(functional_programming) https://en.wikipedia.org/wiki/Monad_(functional_programming)