Compiler compiler = new Compiler(inFile, outFile);
compiler.compile();

I don't think I'll ever understand why people insist on writing it like that instead of `Compiler.compile(inFile, outFile)`.

@mort Looks like the builder pattern to me. I'm not the biggest fan of it, but it has its reasons for existence 😆

@Matter It's not a builder pattern thing, it's literally just a function accepting its arguments through a constructor. The ctor, the 'compile' method and the inFile/outFile properties are the only contents of the class.

Follow

@mort

It's basically a closure or "context" state, I guess. If you need to call compile() a lot, in many different places with same parameters, you worry about passing 1 parameter around not 2(or N).
Perhaps something like

Compiler.Context ctx = new Compiler.Context(in,out);
Compiler.compile(ctx);

would have been more clear/direct, but it's pretty much just a syntax preference.

Could be more than just preference though, in a specific case, cause the language might give special privileges to a one or the other.

@Matter

Sign in to participate in the conversation
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.