Hacker News new | ask | show | jobs
Takes: Java web framework without static methods or annotations (github.com)
40 points by yegor256a 2556 days ago
9 comments

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/05/oop-alternative-to-utili...

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.

> 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.

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

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.

Passing optional objects as method params is bad. The trouble is that an Optional<T> can still be null itself.
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.
I can get the reasoning. I think after enough InstanceManagerStrategyContexts you want short names more than inferable names.
You will get used to them. Just ignore the prefix and read the body of the name.
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?
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.
Unorthodox?
I think orthodox works here as its a more strict reading of the "everything is an object" dogma.
"Native"? "At home"? "Happy Commoner in the Kingdom of Nouns[0]"? Or stockholm syndrome... I kind of get on "no static methods! 'util' and 'helper' are smells!" bends myself from time to time in order to make designs clearer and unit testing somewhat saner (because the even more sane approach of writing or refactoring to smaller pure functions and keeping them that way is too much to ask for sometimes) but it's all just because I spend too much time working in an insane language with a broken idea of what OOP is. Still, I appreciate write-ups like the author's, and at least he's right about immutability being good in general.

[0] http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom...

I didn't know the context, so thanks! I'll take a look. :)
Because static methods/variables/things are hard to test code with because they're hard to replace. IME getting rid of static is the wrong solution though, the difficulty is only because of a limitation of current languages, unit test frameworks and build systems. If you can inject your substitutes at compile time (which I think you should be able to do at the test link step with java) then static isn't a problem.

There's also the issue of people seeing OO as the goal not the tool, which I think might be the case here too.

and don't like 3/4 of the library within have static methods?

that's just adding sequential coupling for no good reason

i'm going to guess this was an exercise to try to do this, not to be effective as a tool :)
You can see how many products already use this framework. So, yes, it was an exercise at the beginning. Now it's a fully functioning web framework.
Interfaces with defaults.
Testing.
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.

Gotta get rid of all those nasty pure functions. Can't have any of that cruft in muh object oriented language.
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.

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!

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".
and from that link

> public class Max implements Number

uhm

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 ...).

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.
It is a web framework. It helps you create a web app. Similar to what other frameworks do, like Spring, Spark, Play, Struts, etc.
> Not a single public static method

main?

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
I think it's safe to assume "no public static interface to the framework". The rest are hidden implementation details.

It's like saying that a program in Java can be completely object oriented. Of course it can't because the innards still contain pieces of procedural code and they still use primitives which may not be actual instances of objects. What counts is how it presents itself on the outside.

It looks like the framework user or the servlet engine provides the main method.
I think this is the doesn't-need-to-be-said exception.
Given style of the code, what Yegor needs is Lisp, but not OOP.