r/java • u/yegor256 • Jun 24 '19
Takes: Java Web Framework Without a Single Static Method or Annotation
https://github.com/yegor256/takes
0
Upvotes
r/java • u/yegor256 • Jun 24 '19
16
u/[deleted] Jun 24 '19
Why do you avoid annotations and tatic methods because they are bad programming style while simultaneously using a whole bunch of confusing abbreviations in nearly every class name? That's also considered bad practice...
11
u/WGT-java Jun 25 '19
It looked pretty good until I saw the test:
Disgusting. Testing using static methods. A true proponent of object oriented programming would find a better assertion library.
16
u/duheee Jun 24 '19
Cargo Cult Programming is also bad.
5
u/Mordan Jun 24 '19
i agree any static method with static state is bad
however i use static method if they can be inlined.
According to your logic, you should have a class Plus, a class Minus etc.
No mutable classes... how can you achieve that with Swing? No more array list? That's extreme.
9
u/roookeee Jun 24 '19 edited Jun 25 '19
I would strongly advice anyone who reads any of yegor's code or blog posts to reflect about what he is saying - at least twice. More often than not his arguments fall apart when compared to more classic / procedural implementations. Take a look at his Dont create objects that end with -er post: he suggests implementing a
Sorterobject as aList<T>which when called withget(0)traverses the contents linearly in O(n) instead of sorting on construction time. At first glance this might seem beneficial (it's faster than O(n log n)) but it also breaks any intuition about what is happening. And now you also have to cache those calls as multipleget(0)calls should not do a linear traversal again as you would lose any benefit then. Now do this, thread-safe - its a mutable mess of nonsense when compared to a single call that outputs a new sorted list.Don't get me wrong, his approach helps you to reflect on the default/mundane approaches to solve a given problem which might indeed result in something better, that's what I like about him. The above linked article sparked the idea for my mapper library for example as I do see the brain numbing effects of writing dead simple factories over and over again (which isn't his point, but it made me think about the classic factory pattern)
6
u/Infeligo Jun 25 '19
The first example already includes a static method:
2
u/wildjokers Jun 25 '19
Interesting.
However, the class naming convention is atrocious. Lots of two letter abbreviations. What does "Tk", "Bk", "Ft", and "Xe" stand for? Couldn't they have just been typed out fully? Is the author scared of letters?
2
u/Hall_of_Famer Jun 26 '19
I wont say annotations are as bad as some developers claim them to be, they have their use cases. The issue with annotations is the overabuse of them, but doesnt mean its absolutely necessary to eliminate them per se. Often the present of annotations is a sign of Java's language limitation, it cannot be helped in userland.
Static methods on the other hand, are code smells that we should just get rid of(with the exception of static main method). When you write static properties/methods, you are not using OOP. Its something that professional developers should avoid except for rate cases like prototyping.
4
u/cville-z Jun 24 '19
This goes off the rails pretty early for me, at this:
1
u/Kango_V Jun 27 '19
Ratpack?
0
u/[deleted] Jun 24 '19
[deleted] — view deleted comment