News for hackers. Stuff that matters.
Re:Dependency Injection is a Virtue by martinced on Monday January 07, 2013 @09:16AM (#5021007)
"Having hard-coded class-names like in the example Time.now is effectively the same as communicating via global variables."

But having DI is exactly that: DI is about glorified global variables!

I realize most HN participants living in the Java/C# + ORM ([N]Hibernate)) + XML + SQL hell are just loving DI because it's a tad bit less worse then global variables but, dudes, there's another world out there.

A lot of functions can be made idempotent (always returning the same output for a given set of inputs) and also pure (idempotent and without any side-effect) and this facilitates everything: it gets much easier to "recreate the state" and it makes it easier to reason about your programs.

It's sad because HN is a community built by pg, who talked about "beating the average", about using Lisp dialects, about Emacs, etc.

I took all his writing as "thinking outside the box".

And what do I see here? I see that HN is mostly consisting of enterprisey programmers living in the Java/C# + ORM + XML + SQL hell and not even realizing there's another world out there.

It is sadening me.

Re:Dependency Injection is a Virtue by mpweiher on Monday January 07, 2013 @12:33PM (#5022060)
Did you bother to read about Newspeak or click on the links?

Did you see the part about Java "AbstractAbstractFactory" actually being very close to "worse" than global variables?

http://newspeaklanguage.org

But apparently clicking on links is too hard, so I'll quote inline:

"Newspeak is a new programming language in the tradition of Self and Smalltalk. Newspeak is highly dynamic and reflective – but designed to support modularity and security. It supports both object-oriented and functional programming.

Like Self, Newspeak is message-based; all names are dynamically bound. However, like Smalltalk, Newspeak uses classes rather than prototypes. As in Beta, classes may nest. Because class names are late bound, all classes are virtual, every class can act as a mixin, and class hierarchy inheritance falls out automatically. Top level classes are essentially self contained parametric namespaces, and serve to define component style modules, which naturally define sandboxes in an object-capability style. Newspeak was deliberately designed as a principled dynamically typed language. We plan to evolve the language to support pluggable types."

Sheesh.

Update: I know the creators of Newspeak, but am not affiliated in any way.

Re:Dependency Injection is a Virtue by _ikke_ on Monday January 07, 2013 @11:49AM (#5021840)
DI is not about glorified globals at all. Nothing forces you to pass in the same object to all things dependend on it.

It just allows you to pass in anything the situation requires.

It allows your code to depend on an interface, instead of an implementation, even if the language doesn't have explicit interfaces.

Re:Dependency Injection is a Virtue by laureny on Monday January 07, 2013 @10:07AM (#5021258)
> A lot of functions can be made idempotent

Idempotency is completely orthogonal to the problem of functions accepting parameters that are a mix of live parameters and ones that can be injected at start up.

Re:Dependency Injection is a Virtue by brown9-2 on Monday January 07, 2013 @10:36AM (#5021429)
DI is about glorified global variables!

Can you expand on what you mean by this?