3 karma · joined Nov 28, 2017 (8y ago) · 13 submissions
comment 8y ago · link · parent
comment 8y ago · link · parent
comment 8y ago · link · parent
comment 8y ago · link · parent
comment 8y ago · link · parent
Regarding the beauty of DI, let me provide an example of a typical large application. Such an application may need a UserInfo class to model a user's information in the app. This user info class will likely have many dependencies: it needs a way to persist itself to disk, to make network calls for server syncs, and any other ancillary components. As an app component, I don't need to understand any of this. I just add a component to my constructor and I immediately have access to any functionality I may need. Using DI in this way also has a nice side effect: classes can be stateless singletons and still be easily testable with mocks. And the best part is none of this is magical. All of it is governed by a few simple rules.
comment 8y ago · link · parent
comment 8y ago · link · parent
class Answer {
getAnswer(input: number) { return (input * 6 + 4) / 2; }
}
All joking aside, you would achieve composition the same way, except using interfaces. interface Operation<T> {
apply(input: T);
}
class Addition implements Operation<Number> {
}
class Multiplication implements Operation<Number> {
}
class Division implements Operation<Number> {
}
function compose(Operation<T>... operation, T input) {
T last = input;
for (Operation<T> op : operations) {
last = op.apply(last);
}
return last;
}
Of course, the above code is slightly verbose, but even if you could remove all the boiler plate it still doesn't look like good imperative code. This is what confuses me about currying: when translated to the imperative equivalent, it looks terrible.comment 8y ago · link · parent
class Adder {
base: number;
constructor(base: number) { this.base = base; }
add(o: number): number { return this.base + o; }
}
While slightly more verbose, I believe this form to be the more powerful of the two because one has access to all of the features of imperative programming and is easier to compose with other objects.comment 8y ago · link · parent
Still, some clever people have figured out how to exploit this to achieve polynomial speedup on problems where certain properties of the problem are exploited to get around the limitation of measurement in a quantum system.
comment 8y ago · link · parent
A good place to start might be this paper by Mermin, which defines classical computing bits (Cbits) in a specific mathematical framework and then expands that definition to define Qbits and their states: https://arxiv.org/pdf/quant-ph/0207118.pdf