
Takes: Java web framework without static methods or annotations - yegor256a
https://github.com/yegor256/takes
======
saagarjha
I was reading through one of the linked articles of why the author doesn't
like using null or static objects:

[https://www.yegor256.com/2014/05/13/why-null-is-
bad.html](https://www.yegor256.com/2014/05/13/why-null-is-bad.html)

[https://www.yegor256.com/2014/05/05/oop-alternative-to-
utili...](https://www.yegor256.com/2014/05/05/oop-alternative-to-utility-
classes.html)

Apparently he replaces null with null objects or throwing exceptions, and
creates objects for every static method. Go figure.

Actually, there are a few gems:

> The Map interface (no offense to its authors) has a design flaw.

> It is a good practice to make your code as fragile as possible, letting it
> break when necessary.

> The method is basically asking the object about its… race. Black objects go
> right while white objects go left. That’s what this instanceof is doing, and
> that’s what discrimination is all about.

~~~
this_user
> Apparently he replaces null with null objects

That's what Optional was introduced for in Java 8. If you want to be
absolutely null-safe, using it makes sense. But if you want to optimise
performance, going with the slightly more risky route is still the better
choice.

~~~
kjeetgill
That's not really "why" it was introduced. Optional is used as a null wrapper
in other JVM languages so that idiom bled over pretty naturally.

Here's a talk "Optional - Mother of all Bikesheds" by Stuart Marks, the guy
who added it to OpenJDK:
[https://m.youtube.com/watch?v=Ej0sss6cq14](https://m.youtube.com/watch?v=Ej0sss6cq14)

It was mostly just meant to cover the zero or one case on fluent-style
interfaces like the Streams API, so check as getFirst() or getAny(). In
hindsight, the name Optional was a poor choice if they didn't want the idiom
coming over.

------
fwilhe
I don't understand why the names are so bad. FtFoo, TkBar, XyBaz. Not
pronounceable, meaning not inferable. I like Yegor's stuff mostly, but the
naming just kills me.

~~~
xg15
I can get the reasoning. I think after enough InstanceManagerStrategyContexts
you want short names more than inferable names.

------
Xorlev
Not trying to knock the work, but why is no static methods a selling point?
How does one do utility classes instead? And do you eschew static factory
methods entirely?

~~~
vbezhenar
Yegor has quite orthodox view on Java development. You might want to read his
blog to get better understanding on his position. While I don't agree with
many of his points, it's a very interesting and refreshing perspective that is
useful to learn IMO.

~~~
saagarjha
_Un_ orthodox?

~~~
jayd16
I think orthodox works here as its a more strict reading of the "everything is
an object" dogma.

------
kasperni
So from the OOP Alternative to Utility Classes on the site

int max = new Max(10, 5).intValue();

over

int max = Math.max(10, 5)

Yeah, think I am going to pass.

~~~
jforberg
Gotta get rid of all those nasty pure functions. Can't have any of that cruft
in muh object oriented language.

~~~
smt88
Constructing an immutable object/value isn't any different than a pure
function that outputs that object/value. The difference is just syntax.

That said, I don't know if this library uses the practice of immutable-only
objects.

------
jbverschoor
So instead of static, you’re using fixed classes. No difference there. What’s
next, a classfactory? One inner platform effect coming up!

It’s a good exercise though!

------
lalaithion
I write very annotation/static method heavy Java at work, and I write Haskell
for fun at home, and my kneejerk reaction to seeing this code in the "Why are
static methods bad" link:

    
    
        void transform(File in, File out) {
          Collection<String> src = new Trimmed(
            new FileLines(new UnicodeFile(in))
          );
          Collection<String> dest = new FileLines(
            new UnicodeFile(out)
          );
          dest.addAll(src);
        }
    

was "That looks just like Haskell".

~~~
LoSboccacc
and from that link

> public class Max implements Number

uhm

------
gerbilly
Ok, so we know the framework does not contain all these supposedly bad
things¹, but what does the framework _do_ exactly?

1: Reminds me of Golang, which likes to define itself as a set of 'negative
liberties' (No exceptions, no inheritance, no polymorphism, no ...).

~~~
tetha
I was reminded of golang as well. I kind of like this framework, because I
dislike the overly magic dispatch mechanisms of annotation-driven java. Basic
request dispatching in golang can look and be clunky, but that one clunky
place tells you where to look.

------
saagarjha
> Not a single public static method

main?

~~~
mdaniel
Unknown if this framework adheres to it, but the JavaEE standard allows one to
deploy apps that don't contain a main method, and in fact can run in a
security restricted environment that prohibits reading properties, environment
variables, and a lot more. So that's a long way of saying that if it doesn't
need a main method unless they're trying to deploy their own webserver, too

------
ribtoks
Given style of the code, what Yegor needs is Lisp, but not OOP.

