答:
I would go back to the real purpose of version numbers: to uniquely identify a particular body of code.  This is important in a lot of places, but there are several cases where I could see forgoing showing them to clients:

They are used by clients who need to update (which you explicitly said you weren't dealing with).  This also includes clients who would need to do comparisons, such as comparing how software works between two clients.

They are useful to developers who have to debug situations with the customer.

If it is easy for the developers to know what version they are working with, such as "there is only one version to work with at any point in time," they don't need numbers.

You are working with software where the version of the software isn't as important as other factors.  For example, if you are working with AIs, the state of the AI is far more meaningful than the version of the code in a lot of situations.

Title: Are version numbers needed


问:
What is meant by “redundant, but not duplicative” in the Steelman language requirements?
The Steelman language requirements have this:

The language shall require some redundant, but not duplicative, specifications in programs.

I think I can see the underlying idea (that re-stating things may lead to fewer errors given the limitations of human cognition), but I would like a more detailed explanation.

What do they mean by “redundant” and by “duplicative”?

答:
They mean that you shall be required to write things that could reasonably be inferred from other things in the code.  But you will not be implementing the same thing twice.

An example of what they mean is type systems.  You might be able to infer the existence and types of variables from their usage, but the redundancy of explicit declaration can catch errors.

If in doubt think about http://en.wikipedia.org/wiki/Ada_%28programming_language%29 because it is what came out of this effort.

ContentLicense: CC BY-SA 3.0


问:
What's the purpose of keeping a changelog if everyone uses their VCS properly?
Every VCS that I've seen includes a means (and sometimes requires you) to make a log of what a particular commit does.  If this history is being properly kept, what is the purpose of manually keeping the same history in a regular file?

Note that I'm not positing the changelog is useless, I just don't see a use for it myself.  Are there other tools that use the changelog?

答:
What's the purpose of keeping a changelog if everyone uses their VCS properly?

  ...

  If this history is being properly kept, what is the purpose of manually keeping the same history in a regular file?

Your question is a good one, but you're making two big assumptions.

Given a team with a disciplined check-in history, you're assuming that the changelog should reflect or be equivalent to the check-in history. This is not the case. Over time, developers make many different types of commits to a project, some of which are technical in nature. These include configuration and installer-related changes. Some of these would be meaningless to someone who isn't intimately familiar with either the application or the code. While some project changelogs include all of the above, some are more focused on meatier items. [Ultimately, it's a judgment call.]

You're assuming that a software team could be disciplined enough so that the check-in history could serve as the changelog. There are two primary limiting factors with this utopian vision: 1.) Spelling mistakes, grammar mistakes, developer apathy, and developer fatigue yield an imperfect check-in history. Typically, development teams don't have either the time, inclination, or permission to go back after the fact and clean up the check-in history. 2.) Even when you consider excellent branching patterns (like GitHub Flow), people will make mistakes, and they'll have to check-in "that one little thing" that they missed after their "big boss" check-in. Again, this is why there are differences between your check-in history and your change log.


问:
Are version numbers needed
We build a system which works as software as a service. Now I am wondering if it is needed to give the version number to the clients. For example Facebook doesn't give a version number neither does Google. My question is basically would one include version numbers in an application where the client cannot change the version themselves?

Update 1

Just a quick update, yes we do offer an API and the API will be versioned in a similar way like Atlassian does api/ and then api/v2/ and so on.

The version number is just about the website the customer sees, not about developers.

Internally we use Jira for project management and there we also use the Jira releases feature. So internally we do have version numbers. Just not for the customers at the moment.

答:
Absolutely use versions for customers. Google and Facebook do this as major versions. Check your facts on that one.

Of course there are internal versions but the outward ones should be stable in terms of the contracts/signatures and responses. Upgrades then don't break customers and newer versions can do away with cruft as needed. You can also announce a time when your legacy versions will no longer be supported and have the ability to specify what version you mean. That's not possible if you don't support versioning customer Apis.

Title: Are version numbers needed


答:
When used properly, VCS has too much detail. Every little change is recorded, when a changelog is generally for the big user-visible changes. In short, the target audience for a changelog is not the same as for the commit messages of the VCS.

If you are disciplined, a changelog can be an auto-generated subset of what is in VCS, though in my experience most teams don't do that.

By hand-editing the changelog, you (hopefully!) end up with something well crafted, easy to read, and with just the right of information for the target audience. Sort-of the "Clif Notes" of what has changed.

Title: What's the purpose of keeping a changelog if everyone uses their VCS properly?

Body:
Every VCS that I've seen includes a means (and sometimes requires you) to make a log of what a particular commit does.  If this history is being properly kept, what is the purpose of manually keeping the same history in a regular file?

Note that I'm not positing the changelog is useless, I just don't see a use for it myself.  Are there other tools that use the changelog?


答: Well, I am a newbie to industry but so far what I have known is versions are always helpful in terms of development and our internal management. User may not be interested in what and how you are working on your version controlling system or whether you are launching alpha, beta versions. But at the same time when we do update a version we want to convey the users that the update is really important, this identifies version and at the same time users can compare two versions. Just as android does, we do compare the OS updates and compare them so it's easier for the users sometimes too.</p>

Title: Are version numbers needed

Body:
We build a system which works as software as a service. Now I am wondering if it is needed to give the version number to the clients. For example Facebook doesn't give a version number neither does Google. My question is basically would one include version numbers in an application where the client cannot change the version themselves?

Update 1

Just a quick update, yes we do offer an API and the API will be versioned in a similar way like Atlassian does api/ and then api/v2/ and so on.

The version number is just about the website the customer sees, not about developers.

Internally we use Jira for project management and there we also use the Jira releases feature. So internally we do have version numbers. Just not for the customers at the moment.


问:
Question about multidimensional arrays
I was wondering something about the multidimensional arrays and then I got a doubt about a concept, specifically about their representation on memory.

For example, an array can be defined as follows.

```<code>int a[3];
</code>```

And this is represented as this.

Where each element is an int and all of them are in a continuous memory space.

Then a multidimensional array can be define as this.

```<code>int a[2][4];
</code>```

Which is typically represented as.

But a more realistic representation of this array in memory wouldn't be something like this? (by analogy with the first image).

Because I was thinking that if, for example, int a[5]; defines 5 integers in a space of continuous memory, then int a[5][10]; defines 10 arrays of ints in a space of continuous memory, where each array define 5 integers, then any N-dimensional static array in C should be represented only as a strip of memory.

答:
You're nearly right, yes. In fact,

```<code>int a[5][10];
</code>```

declares 5 arrays each of which contain 10 integers, rater than the other way round. Other than that you're completely right.

See http://en.m.wikipedia.org/wiki/Row-major_order for a more detailed description and an explanation of why the order is important.

Title: Question about multidimensional arrays

Body:
You're nearly right, yes. In fact,

int a[5][10];

declares 5 arrays each of which contain 10 integers, rater than the other way round. Other than that you're completely right.

See http://en.m.wikipedia.org/wiki/Row-major_order for a more detailed description and an explanation of why the order is important.


答:
In addition to Jules' answer, I would like to add a bit of historical perspective.

The counter-intuitiveness of this in C is due to the simple fact:

In general, int a[] (length unspecified) is some sort of syntactic sugar in place of int* a

Likewise, int a[][] (again, lengths unspecified) is some sort of syntactic sugar in place of int** a.

Because the two-level pointer must be dereferenced in that order, it determines how a int a[M][N] would have to be laid out in memory.

Title: Question about multidimensional arrays

Body:
I was wondering something about the multidimensional arrays and then I got a doubt about a concept, specifically about their representation on memory.

For example, an array can be defined as follows.

```<code>int a[3];
</code>```

And this is represented as this.

Where each element is an int and all of them are in a continuous memory space.

Then a multidimensional array can be define as this.

```<code>int a[2][4];
</code>```

Which is typically represented as.

But a more realistic representation of this array in memory wouldn't be something like this? (by analogy with the first image).

Because I was thinking that if, for example, int a[5]; defines 5 integers in a space of continuous memory, then int a[5][10]; defines 10 arrays of ints in a space of continuous memory, where each array define 5 integers, then any N-dimensional static array in C should be represented only as a strip of memory.


问:
Should I use events or abstract methods?
Lets say I create an abstract class that manages some network functionality for me.

I want to be able to be notified when something changes. For example: OnConnect or OnDisconnect.

Should I create events for those kinds of functions or implement them as abstract methods?

```<code>public event OnConnectDelegate OnConnected;
</code>```

or:

```<code>protected abstract OnConnected(SomeClientObject connectedClient);
</code>```

I prototyped both solutions and both work as expected. But how do I know in general if I should expose functionality as an event or as an abstract method?
Are there any situations where I should clearly prefer one over the other?
Events support multiple receivers but one also has to remove them when the receiver doesn't need to receive them anymore.

答:
Of the now partially outdated but still useful article from MSDN: "When to Use Delegates Instead of Interfaces (C# Programming Guide)", a few of the rules-of-thumb stand out:

Use a delegate in the following circumstances:

(3) The caller has no need to access other properties, methods, or interfaces on the object implementing the method.

My explanation:

The callee (event receiver) can easily get hold of the caller (sender) because by best practice the caller will pass itself as the first argument (aptly named sender) to the callee.

However, trying to navigate in the reverse direction is non-trivial. A delegate could be anything—a static method, or a lambda, or basically anything other than the real object that ultimately processes the event. Thus, one cannot always determine what that real object is.

The latter point could be worked around by using visitor pattern. However, that adds a lot of code and that makes any discussion moot.

Use an interface in the following circumstances:

(1) There is a group of related methods that may be called.

I would add a bit more: "... and that these related methods are to be found on the same object."

This question has been asked many times. Just search for "C#", "delegate", "interface" will yield a lot of results. However, it takes time to examine the numerous pieces of advice from all of the sources to sift out the relevant ones given your situation.


问:
When we say a monad 'encapsulates a computation' - is this just saying 'wraps a functional transformation of data'?
When I think of the word 'computation' - my mind jumps to lambda calculus or operations on a state machine representing a CPU. It is quite a broad definition.

Now some people talk about monads as 'representing a unit of a computation'.

But if we consider the identity monad - this is a 'reference to the computation'. But ultimately we're almost certainly talking about functional programming. We're using functions. We use functions to transform data. So where does this fancy language come from?

My question is: When we say a monad 'encapsulates a computation' - is this just saying 'wraps a functional transformation of data'?

答: Lambda calculus has no "data flow" allegory, but has data transformation. Imperative world hasn't data flow either, but has computation flow. Monadic way combines both of the best of two worlds: data transformation and explicit computation (order). And we can say "given monads encapsulates a computation"</p>


问:
Should I use .ToString() when concatenating string and integer variables in C#?
```<code>int a = 1;
int b = 2;
int sum = a + b;
string expression = "Expression: " + a + " + " + b + " = " + sum;
Console.WriteLine(expression); //displays Expression 1 + 2 = 3
</code>```

Should I use:

```<code>string expression = "Expression: " + a + " + " + b + " = " + sum;
</code>```

or

```<code>string expression = "Expression: " + a.ToString() + " + " + b.ToString() + " = " + result.ToString();
</code>```

Is it recommended to use ToString() when concatenating string and int?

答:
If you use + concatenation, it itself uses String.Concat method. String itself doesn't expose a + operator.

for example:

```<code>int i = 10;
string str = "hello" + i;
</code>```

is compiled into:

```<code>int i = 10;
object o1 = "hello";
object o2 = i; // Note boxing
string str = string.Concat(o1, o2);
</code>```

If you directly call ToString, it will avoid boxing and call the Concat(string, string) overload. Hence the ToString call will be slightly more efficient although not significant enough. You better go with the example you feel is more readable.

Body:
If you use + concatenation, it itself uses String.Concat method. String itself doesn't expose a + operator.

for example:

int i = 10;
string str = "hello" + i;

is compiled into:

int i = 10;
object o1 = "hello";
object o2 = i; // Note boxing
string str = string.Concat(o1, o2);

If you directly call ToString, it will avoid boxing and call the Concat(string, string) overload. Hence the ToString call will be slightly more efficient although not significant enough. You better go with the example you feel is more readable.


问:
When should we work on GC optimization?
So, I've learnt about how GC works and how can I monitor it via VisualVM, but my question is about why we should ever perform GC optimization? In our web project (JSF/Spring/Hibernate) we haven't thought about this kind of optimization. Isn't it important and where such an optimization may be important?

答:
When your project experiences performance problems.
You can fine tune the garbage collection algorithm used, how often to run it - depending on you performance requirements. Let's say you have lots of RAM on your server but not too much CPU power, then you want to delay garbage collector as much as possible to night time for example. And so on.</p>

Title: When should we work on GC optimization?


答:
(Disclaimer: I do not work on server-side backends, and I do not have any IT operational experience. My answer below is only from architectural theory and not from experience.)

If you are unsure of what to do, try the following order of precedence.
(The first two steps has nothing to do with GC, but if those two aren't taken care of, talking about GC optimization is pointless.)

but please do not follow blindly; as I said I have no real experience in this.

First of all, you should find and eliminate memory leaks in your code base.

Next, you should identify wasteful usage of memory in your code base, and improve on that.

Then, you should learn the fundamentals of GC (which you have already accomplished).

Once you've learned it, you should start monitoring those vital statistics, in all environments - development, test, and production.

When those vital statistics indicate that your project could potentially suffer from a GC problem, use the techniques learned to isolate the cause, and/or apply one or more mitigations to keep the problem under control.

What are some of the things that could be tuned?

Just a few examples - pardon if my examples are wrong.

Tune the hardware (RAM sizes)

Tune the OS

Tune the JVM or GC

Tune your project in the way it uses (generating and maintaining) long-living objects, if such objects collectively account for a significant fraction of overall memory usage.

Title: When should we work on GC optimization?

Body: So, I've learnt about how GC works and how can I monitor it via VisualVM, but my question is about why we should ever perform GC optimization? In our web project (JSF/Spring/Hibernate) we haven't thought about this kind of optimization. Isn't it important and where such an optimization may be important?


答:
Here's some code that clearly shows memory layout for arrays. Using a union, for which memory is overlaid for each union member, we can see that values are stored in row-major order.

```<code>#include <stdio.h>

#define N       4*4*4
#define N_2D    8
#define N_3D    4

union multi_d_arrays {
    int one_d[N];
    int two_d[N_2D][N_2D];
    int three_d[N_3D][N_3D][N_3D];
};

int main()
{
    int i, j, k;
    union multi_d_arrays m;

    /* initialise via one_d with sequential ints */
    for (i=0; i<N; i++)
        m.one_d[i] = i+1;

    /* in all cases the output should be sequential */
    printf("------------------------\n");
    for (i=0; i<N; i++)
        printf("m.one_d[%d] = %d\n", i, m.one_d[i]);

    printf("\n------------------------\n");
    for (i=0; i<N_2D; i++)
        for (j=0; j<N_2D; j++)
            printf("m.two_d[%d][%d] = %d\n", i, j, m.two_d[i][j]);

    printf("\n------------------------\n");
    for (i=0; i<N_3D; i++)
        for (j=0; j<N_3D; j++)
            for (k=0; k<N_3D; k++)
                printf("m.three_d[%d][%d][%d] = %d\n", i, j, k, m.three_d[i][j][k]);

    return 0;
}
</code>```

Title: Question about multidimensional arrays

Body:
Here's some code that clearly shows memory layout for arrays. Using a union, for which memory is overlaid for each union member, we can see that values are stored in row-major order.

#include <stdio.h>

#define N       4*4*4
#define N_2D    8
#define N_3D    4

union multi_d_arrays {
    int one_d[N];
    int two_d[N_2D][N_2D];
    int three_d[N_3D][N_3D][N_3D];
};

int main()
{
    int i, j, k;
    union multi_d_arrays m;

    /* initialise via one_d with sequential ints */
    for (i=0; i<N; i++)
        m.one_d[i] = i+1;

    /* in all cases the output should be sequential */
    printf("------------------------\n");
    for (i=0; i<N; i++)
        printf("m.one_d[%d] = %d\n", i, m.one_d[i]);

    printf("\n------------------------\n");
    for (i=0; i<N_2D; i++)
        for (j=0; j<N_2D; j++)
            printf("m.two_d[%d][%d] = %d\n", i, j, m.two_d[i][j]);

    printf("\n------------------------\n");
    for (i=0; i<N_3D; i++)
        for (j=0; j<N_3D; j++)
            for (k=0; k<N_3D; k++)
                printf("m.three_d[%d][%d][%d] = %d\n", i, j, k, m.three_d[i][j][k]);

    return 0;
}


问:
Scrum in combination with ad hoc bug fixes
I worked in a company where they tried to use Scrum but in practice it was hard to create a solid sprint backlog because they had a very active userbase, that used the software 8 hours a day, and because of that, reported many critical bugs that needed immediate attention.

This made me wonder... What is the best way to solve this kind of unplanned workload while using scrum? I saw something about Scrumban and Kanban, but still I do not see how it is possible to give the client a somewhat proper estimate of functionality that will be completed within certain sprint in combination with unplanned work (bugs) that needs immediate attention.

Do I need to search for a methodology that can cope with a unreliable workload or do I need to take a look at other stages within the sotware development process? For example to make sure that the quality process will be improved to reduce the number of bugs and with that the amount of unplanned work?

答:
"[...] reported many critical bugs that needed immediate attention" sounds nasty.

If your team can solve 5 bugs per day and dozens of users reported dozens of bugs which all need immediate attention, there is no way you can do what they want. They simply have to wait, and the higher is their leverage to hurry things, the worse it will be, because rushing will encourage your team to abandon testing, code reviews or pair programming and lead to more bugs.

Moreover, by skipping the backlog and pushing the task directly into the current sprint, you're creating a mess. Developers were working on a task; now they must suspend their work and deal with a new task. This alone is frustrating enough to lower the productivity, but also returning to the previous task a few hours later is painful as well: the person may have forgotten where she was.

Finally, you must be sure to assign priorities in a way that only a small part of the tasks appears to be high priority. I've seen projects where on 100 tasks, 30 were "requiring immediate attention" and 60 were "high priority": in such context, developers are simply considering that there are 30 important tasks, 60 low-priority tasks and 10 which will never be implemented.

If your customer, boss or user is asking to solve a bug right now, the only possible answer is:

We added this task to our backlog and we set it to be a high priority task. We are currently solving 68 other high priority tasks which might take us from four to five weeks. We'll keep you updated.

What if the bug is blocking?

What if the bug should actually be solved right now, because of its severity (such as a user cannot log in)?

If this is an isolated case, then How to account for a bug fixing iteration? mentioned by Gnat is relevant.

If this becomes a pattern (like several right now bugs per day), then there is something completely wrong in a way your team is developing the software product.

If the team is using pair programming or code reviews, if the target code branch coverage is high enough, if everybody on the team understands the requirements, if you do regression testing (through Continuous Integration) and if the deployment is automated (nobody's messing with your servers), this shouldn't happen.

Again, no matter how well your team is doing the job, bad things may happen from time to time. But if this happens regularly, something is out of control.


问:
How should I represent composeable, associative computations to be repeatedly applied to units of data?

Spoiler

My question is the following:  Are there any design patterns for representing chainable functions that are for the problem described below?

High-Level Decription of the Process

I'm currently building an image-processing server, whose functionality is exposed via a web API.

Client Behavior

Clients first authenticate, then request that one or more analyses be performed by the server.  Once a client has authenticated and requested his analysis stack, he streams his video data to the analysis server.

Server Behavior

On the server side, the Stream class is used to represent the flow of data.  It's the first-class object around which the pipeline is built, and it can be thought of as an ordered FIFO queue of sorts.  Frames are pushed, in order of arrival, onto the Stream instance, and each stream may optionally map a function onto its data.  Results from a mapped function are projected onto a new Stream instance.

For example:

```<code># input_stream is asynchronously updated with incoming frames

stream = input_stream.map(do_sobel_filter)  # apply Sobel filter to each incoming frame
stream2 = stream.window(fn, 10)  # apply function to a sliding window of 10 frames
</code>```

An important side-note is that our use of Stream objects allows us to apply functions either to individual frames or to groups of frames.  This is useful as some analyses require context.

Requirements & Constraints

The above bold text is particularly important; A given client will be authorized only to perform a subset of the image analyses offered by our system.  This in turn makes it critical that we be able to dynamically compose the image-processing pipeline -- we don't want to perform expensive computations only to throw away the result.

Further complicating the matter is the fact that almost all of the analyses we offer have some prerequisites, that is, operation Oi may depend on the result of operation Oi-n.  Our system needs to resolve these dependencies and run each operation exactly once.

Finally, the chaining/composition of operations must be associative.  This is because we'd like to be able to compose reusable higher-level computations from lower-level atomic computations.  For instance, consider the sequence of operations x -> y -> z.  We would like to be able to assign the ordered chain x->y->z to a variable, thus CMP1 = x->y->z.  Similarly, CMP2 is the result of chaining operations a->b->c.  Ultimately, we would like to be able to do the equivalent of CMP3 = CMP1 -> CMP2, and have this be strictly equivalent to CMP3 = x->y->z->a->b->c  (associativity).

To summarize, here are the requirements for my image analysis function objects:

Functions must be composeable, meaning that it should be possible to manipulate a first-class object that represents a series of sub-computations.

Ideally, functions should resolve dependencies, meaning that doing A -> B should implicitly evaluate to A -> X -> C if C depends on both A and X.  This may be worthy of it's own question, and so should be treated as a soft requirement.

Chaining of operations should be associative, and composed functions should also be chainable.  The idea is to have a reusable pattern for representing increasingly complex pipelines.

Are there any well-tested patterns for achieving such a result?

Edits:

1)  In response to @Giorgio's questions, my (admittedly ambiguous) notation serves to distinguish between the temporal order of frames and the order of operations.  Below is an example of how an operation can depend on its preceding counterparts:

```<code>FindFace -> FindEyes -> SegmentEye -> MeasurePupilDiameter
</code>```

Here we can see that each function after FindFace depends on the cumulative result of the preceding functions.  Now consider:

```<code>FindFace -> FindEyes -> SegmentEye -> GetIrisColorHistogram
</code>```

This second example demonstrates how there is often a common core of operations that needs to be performed across analyses.  When composing operations, I'd like to do steps 1 - 3 only once, and then apply MeasurePupilDiameter and GetIrisColorHistogram from there.

Intuitively, it seems like the right way to do this would be to assign a dictionary to my Frame object and fill it with features as they're computed -- a memoize pattern, if you will.  From there, however, it's unclear to me how I should go about abstracting all the boilerplate code pertaining to (a) checking if a prerequisite feature has already been computed and (b) automatically calling the appropriate function if it has not.

答:
Your problem has striking parallels to functional programming: Monads, Functors, and composing functions. Your composability requirements essentially states that each operation must be a function that takes a stream and returns a stream:

```<code>operation : Stream -> Stream
</code>```

Most functions will not be expressed in terms of whole streams but rather single frames or windows of frames. You have correctly noted that you can lift these frame-wise operations to stream operations by functions like map.

```<code>class Operation:
    def __init__(self, function, dependencies):
        self.dependencies = dependencies
        self.function = function
    def __call__(self, stream):
        return self.function(stream)

def lift_frame_to_stream(frame_operation, dependencies):
    def stream_operation(stream):
        for frame in stream:
            yield frame_operation(frame)
    return Operation(stream_operation, dependencies)
</code>```

This composability is at odds with the requirement that the operations can have dependencies. We can solve this by handling the dependencies outside of the type system. Given a flat list of operations op1, op2, ..., opn that each have dependencies, then we can iterate through the list to determine whether these dependencies are fulfilled. In the simplest case, this is done by keeping a set of all operations encountered up to that point:

# unsatisfied_dependencies: Iterable[Operation] -> List[(Operation, List[Operation])]
def unsatisfied_dependencies(operations):
    seen = set()
    needed = []
    for op in operations:
        op_needs = []
        for dep in op.dependencies:
            if dep not in seen:
                op_needs.append(dep)
        if op_needs:
            needed.append((op, op_needs))
        seen.add(op)
    return needed
```

<p>I would be wary of automatically fulfilling dependencies. If this would be done, you'd have to iterate the operations by index. If an unmet dependency is discovered, rather than adding it to the list of needed operations you'd insert the dependency before the current operation, then back up one element, and continue checking the dependencies starting with the newly inserted operation.</p>

<p>The problem with automatic dependency insertion is that the order of operations could matter, and this resolution strategy does not account for that. I think it would be better to make users aware of dependencies and require these to be met before processing starts.</p>

<p>Processing the stream is a fairly simple job of taking a pipeline with all dependencies met and applying the operations. Assuming that all operations are lazy (i.e. don't immediately consume the stream but only calculate each frame that is requested; easily implemented using Python's generators), then the composed stream would have to be force-evaluated.</p>

<pre class="lang-py prettyprint-override"><code>stream = input_stream
for op in verified_pipeline:
    stream = op(stream)
# force the stream
</code>```

The pipeline cannot be composed any other way; “associativity” is a misnomer since stream operations are unary and not binary operators. However, your requirement for larger “building blocks“ of operations that contain child operations is understandable, and easy to implement – the object-oriented Composite Pattern makes sense here. The dependencies of the composite are all dependencies of the child operations that are not met inside that composite.

Actually, a pipeline of operations is equivalent to a single operation, so we can use a pipeline as the composite.

class Pipeline:
    def __init__(self, childs, extra_dependencies=[]):
        self.childs = childs
        deps = []
        for (op, dependencies) in unsatisfied_dependencies(childs):
            deps.extend(dependencies)
        deps.extend(extra_dependencies)
        self.dependencies = deps

    def __call__(self, stream):
        for op in self.childs:
            stream = op(stream)
        return stream
```

<p>More important than the specifics of composing operations is how you'll represent each frame. Supposedly, each frame will consist primarily of image data. However, some operations might want to add metadata (e.g. one operation might calculate the colour distribution of a frame). It would therefore make a lot of sense to have each frame contain a dicitionary that can be filled with fairly unstructured data. Since we want the operations to be freely composable, it would not be viable to define multiple frame classes as output of each operation since that way metadata from previous operations would be discarded.</p>

<p>But this permanent metadata has an important problem: it can be invalidated by subsequent operations. E.g. a colour profile would be invalidated by an operation that performs a gamma correction on the image data. One possibility to reconcile this would be to track for each operation which operations it invalidates. When checking for unmet dependencies, such invalidated operations would then be removed from the <code>seen</code> state. However, this requires you to do extensive bookkeeping for each operation. Adding one new operation involves looking through all existing operations to discover potential incompatibilities.</p>

<p>Regarding first-class representation of the operations, I think that representing each operation as a callable object with some metadata such as dependencies tacked on to it makes most sense. As shown above, it's easy to verify dependencies and build composable blocks out of this. It is also fairly easy to turn user input into a pipeline. Assuming you get a list of strings that refer to some operation, you can use a dictionary to map these strings to operations:</p>

<pre class="lang-py prettyprint-override"><code>operations_map = { ... }

chosen_operations = []
for name in input_list:
    chosen_operations.append(operations_map[name]) # TODO error handling
pipeline = Pipeline(chosen_operations)

if pipeline.dependencies:
    # oops

result_stream = pipeline(input_stream)
</code>```

However, it might be good to have each operation contain a name field to ease creation of meaningful error messages etc.

Body:
Your problem has striking parallels to functional programming: Monads, Functors, and composing functions. Your composability requirements essentially states that each operation must be a function that takes a stream and returns a stream:

operation : Stream -> Stream

Most functions will not be expressed in terms of whole streams but rather single frames or windows of frames. You have correctly noted that you can lift these frame-wise operations to stream operations by functions like map.

class Operation:
    def __init__(self, function, dependencies):
        self.dependencies = dependencies
        self.function = function
    def __call__(self, stream):
        return self.function(stream)

def lift_frame_to_stream(frame_operation, dependencies):
    def stream_operation(stream):
        for frame in stream:
            yield frame_operation(frame)
    return Operation(stream_operation, dependencies)

This composability is at odds with the requirement that the operations can have dependencies. We can solve this by handling the dependencies outside of the type system. Given a flat list of operations op1, op2, ..., opn that each have dependencies, then we can iterate through the list to determine whether these dependencies are fulfilled. In the simplest case, this is done by keeping a set of all operations encountered up to that point:

# unsatisfied_dependencies: Iterable[Operation] -> List[(Operation, List[Operation])]
def unsatisfied_dependencies(operations):
    seen = set()
    needed = []
    for op in operations:
        op_needs = []
        for dep in op.dependencies:
            if dep not in seen:
                op_needs.append(dep)
        if op_needs:
            needed.append((op, op_needs))
        seen.add(op)
    return needed

I would be wary of automatically fulfilling dependencies. If this would be done, you'd have to iterate the operations by index. If an unmet dependency is discovered, rather than adding it to the list of needed operations you'd insert the dependency before the current operation, then back up one element, and continue checking the dependencies starting with the newly inserted operation.

The problem with automatic dependency insertion is that the order of operations could matter, and this resolution strategy does not account for that. I think it would be better to make users aware of dependencies and require these to be met before processing starts.

Processing the stream is a fairly simple job of taking a pipeline with all dependencies met and applying the operations. Assuming that all operations are lazy (i.e. don't immediately consume the stream but only calculate each frame that is requested; easily implemented using Python's generators), then the composed stream would have to be force-evaluated.

stream = input_stream
for op in verified_pipeline:
    stream = op(stream)
# force the stream

The pipeline cannot be composed any other way; “associativity” is a misnomer since stream operations are unary and not binary operators. However, your requirement for larger “building blocks“ of operations that contain child operations is understandable, and easy to implement – the object-oriented Composite Pattern makes sense here. The dependencies of the composite are all dependencies of the child operations that are not met inside that composite.

Actually, a pipeline of operations is equivalent to a single operation, so we can use a pipeline as the composite.

class Pipeline:
    def __init__(self, childs, extra_dependencies=[]):
        self.childs = childs
        deps = []
        for (op, dependencies) in unsatisfied_dependencies(childs):
            deps.extend(dependencies)
        deps.extend(extra_dependencies)
        self.dependencies = deps

    def __call__(self, stream):
        for op in self.childs:
            stream = op(stream)
        return stream

More important than the specifics of composing operations is how you'll represent each frame. Supposedly, each frame will consist primarily of image data. However, some operations might want to add metadata (e.g. one operation might calculate the colour distribution of a frame). It would therefore make a lot of sense to have each frame contain a dicitionary that can be filled with fairly unstructured data. Since we want the operations to be freely composable, it would not be viable to define multiple frame classes as output of each operation since that way metadata from previous operations would be discarded.

But this permanent metadata has an important problem: it can be invalidated by subsequent operations. E.g. a colour profile would be invalidated by an operation that performs a gamma correction on the image data. One possibility to reconcile this would be to track for each operation which operations it invalidates. When checking for unmet dependencies, such invalidated operations would then be removed from the seen state. However, this requires you to do extensive bookkeeping for each operation. Adding one new operation involves looking through all existing operations to discover potential incompatibilities.

Regarding first-class representation of the operations, I think that representing each operation as a callable object with some metadata such as dependencies tacked on to it makes most sense. As shown above, it's easy to verify dependencies and build composable blocks out of this. It is also fairly easy to turn user input into a pipeline. Assuming you get a list of strings that refer to some operation, you can use a dictionary to map these strings to operations:

operations_map = { ... }

chosen_operations = []
for name in input_list:
    chosen_operations.append(operations_map[name]) # TODO error handling
pipeline = Pipeline(chosen_operations)

if pipeline.dependencies:
    # oops

result_stream = pipeline(input_stream)

However, it might be good to have each operation contain a name field to ease creation of meaningful error messages etc.


问:
Best practices for serialization of DDD aggregates
According to DDD domain logic should not be polluted with technical concerns like serialization, object-relational mapping, etc.

So how do you serialize or map the aggregates' state without publicly exposing it via getters and setters? I have seen lots of examples for e.g. repository implementations, but practically all of them relied on public accessors on the entities and value objects for mapping.

We could use reflection to avoid public accessors, but IMO these domain objects would still implicitly be dependent on the serialization concern. E.g. you couldn't rename or remove a private field without tweaking your serialization/mapping configuration. So you have to consider serialization where you should instead be focussing on domain logic.

So what's the best compromise to follow here? Live with public accessors, but avoid using them for anything else but mapping code? Or did I just miss something obvious?

I'm explicitly interested in serializing the state of DDD domain objects  (aggregates consisting of entities and value objects). This is NOT about serialization in general or transcation script scenarios where stateless services operate on simple data container objects.

答:
Kinds of objects

For purposes of our discussion, let's separate our objects into three different kinds:

Business Domain logic

These are the objects that get work done.  They move money from one checking account to another, fulfill orders, and all of the other actions that we expect business software to take.

Domain logic objects normally do not require accessors (getters and setters).  Rather, you create the object by handing it dependencies through a constructor, and then manipulate the object through methods (tell, don't ask).

Data Transfer Objects

Data Transfer Objects are pure state; they don't contain any business logic.  They will always have accessors.  They may or may not have setters, depending on whether or not you're writing them in an immutable fashion.  You will either set your fields in the constructor and their values will not change for the lifetime of the object, or your accessors will be read/write.  In practice, these objects are typically mutable, so that a user can edit them.

View Model objects

View Model objects contain a displayable/editable data representation.  They may contain business logic, usually confined to data validation. An example of a View Model object might be an InvoiceViewModel, containing a Customer object, an Invoice Header object, and Invoice Line Items.  View Model objects always contain accessors.

So the only kind of object that will be "pure" in the sense that it doesn't contain field accessors will be the Domain Logic object.  Serializing such an object saves its current "computational state," so that it can be retrieved later to complete processing.  View Models and DTO's can be freely serialized, but in practice their data is normally saved to a database.

Serialization, dependencies and coupling

While it is true that serialization creates dependencies, in the sense that you have to deserialize to a compatible object, it does not necessarily follow that you have to change your serialization configuration. Good serialization mechanisms are general purpose; they don't care if you change the name of a property or member, so long as it can still map values to members.  In practice, this only means that you must re-serialize the object instance to make the serialization representation (xml, json, whatever) compatible with your new object; no configuration changes to the serializer should be necessary.

It is true that objects should not be concerned with how they are serialized.  You've already described one way such concerns can be decoupled from the domain classes: reflection.  But the serializer should be concerned about how it serializes and deserializes objects; that, after all, is its function.  The way you keep your objects decoupled from your serialization process is to make serialization a general-purpose function, able to work across all object types.

One of the things people get confused about is that decoupling has to occur in both directions.  It does not; it only has to work in one direction.  In practice, you can never decouple completely; there is always some coupling.  The goal of loose coupling is to make code maintenance easier, not to remove all dependencies.


问:
"Design patterns", "Reactive programming", etc...How do these terms fit together?
The context: For all intents and purposes, I feel like I'm about the level of a pretty competent second year student at computer science. I have taken all the basic algorithms and systems classes; my C is pretty good, and I can even read disassembly  with a bit of effort. OOP. Algo. P vs NP. Let's call this the "old school stuff".

My specific question is this: I can't figure out what "topic" these terms fall under, and in my mind, I call this the "new school stuff". I'm struggling with terminology here, but for the lack of a better word, what topic do these things fall under?

design patterns

reactive programming

MVC

event-driven programming

the "stack", i.e. a "full-stack" developer

agile development

software as a service

"architecture"

答:
Short answer

There is no single topic where all of these terms fall under.

And no. You probably didn't heard these terms even if you had not skipped any classes. It is quite normal for a student never hearing about them from the mouth of academia.

What you are missing out is an internship. (Also known as apprentice, practical training, co-op, etc.)

There are agencies which claim to teach the skills and manners outside of an employment relationship. (Instead, you pay them to enroll.) This is called "boot-camp". Since there are good, bad, and ugly ones, I will not talk much about this.

Long answer

Design patterns

Recurring class design and interaction patterns observed in many real-world object-oriented programming (OOP) projects sampled from many versatile areas. An augmentation to the practice of OOP.

MVC

An architecture proposed for implementing graphical programming interfaces (GUI)

Event-driven programming

A fundamental control-flow structure that is the basis of all GUI programming. Also refers to languages, frameworks and reusable libraries that are designed specifically to improve upon event-driven programming.

Examples of things which are not event-driven programming:

Command-line interface

Menu-driven programming (a text-based user interface no longer in use)

Batch processing (or unattended processing, and thus do not have any user interfaces at all)

The "stack"

A shorthand of "technology stack". The latter refers to the constituents of a layered architecture of a computing system. The term is used in an attempt to quickly describe a particular combination of technological choices made at every layer of computing in a given system.

In practice, it is a concatenation of buzzwords:

```<code>public override string ToString()
{
    return string.Join(",", new string[] {
        hardware.Name, os.Name, database.Name, webBackendFramework.Name, webFrontendFramework.Name });
}
</code>```

"Full-stack" developer

An emerging employment and career-track pattern among web-facing software development professionals. Refers to professionals who are well equipped to both the web back-ends and web front-ends.

This term gives the impression that a "full-stack developer" has broad knowledge and is capable of building up a whole website (both client-side and server-side) just by oneself.

Agile development

A software development methodology. Refer to Wikipedia article. Also see: "Lean development", "Scrum", and "Kanban".

Historically relevant concepts (but not necessary for understanding this term in its current sense) are: "Toyota Production System", "Agile Manifesto", "Extreme Programming".

Software-as-a-Service (SaaS)

An industry trend in software. This trend affects every aspect of software development:

Monetization (how do you make money)

Pricing and Billing (how and when customers make payments to you)

Development velocity (how much time from coding to making that new feature available to users)

Release cycle (how often is a major revision released)

Infrastructure (where does the "software" runs on; who pays for the hardware; who maintains the machines)

Simply put, it is a revolutionary trend and a disruptive innovation, although it is a gradual change happening over the decades and not an abrupt change.

It is disruptive in the sense that software development companies which do not adopt SaaS will be in a permanent competitive disadvantage and face extinction.

Architecture

See "software architecture" and "software engineering" in Wikipedia. Also look up for "management and information systems (MIS)" in your own school's course offerings.

Body:
Short answer

There is no single topic where all of these terms fall under.

And no. You probably didn't heard these terms even if you had not skipped any classes. It is quite normal for a student never hearing about them from the mouth of academia.

What you are missing out is an internship. (Also known as apprentice, practical training, co-op, etc.)

There are agencies which claim to teach the skills and manners outside of an employment relationship. (Instead, you pay them to enroll.) This is called "boot-camp". Since there are good, bad, and ugly ones, I will not talk much about this.

Long answer

Design patterns

Recurring class design and interaction patterns observed in many real-world object-oriented programming (OOP) projects sampled from many versatile areas. An augmentation to the practice of OOP.

MVC

An architecture proposed for implementing graphical programming interfaces (GUI)

Event-driven programming

A fundamental control-flow structure that is the basis of all GUI programming. Also refers to languages, frameworks and reusable libraries that are designed specifically to improve upon event-driven programming.

Examples of things which are not event-driven programming:

Command-line interface

Menu-driven programming (a text-based user interface no longer in use)

Batch processing (or unattended processing, and thus do not have any user interfaces at all)

The "stack"

A shorthand of "technology stack". The latter refers to the constituents of a layered architecture of a computing system. The term is used in an attempt to quickly describe a particular combination of technological choices made at every layer of computing in a given system.

In practice, it is a concatenation of buzzwords:

public override string ToString()
{
    return string.Join(",", new string[] {
        hardware.Name, os.Name, database.Name, webBackendFramework.Name, webFrontendFramework.Name });
}

"Full-stack" developer

An emerging employment and career-track pattern among web-facing software development professionals. Refers to professionals who are well equipped to both the web back-ends and web front-ends.

This term gives the impression that a "full-stack developer" has broad knowledge and is capable of building up a whole website (both client-side and server-side) just by oneself.

Agile development

A software development methodology. Refer to Wikipedia article. Also see: "Lean development", "Scrum", and "Kanban".

Historically relevant concepts (but not necessary for understanding this term in its current sense) are: "Toyota Production System", "Agile Manifesto", "Extreme Programming".

Software-as-a-Service (SaaS)

An industry trend in software. This trend affects every aspect of software development:

Monetization (how do you make money)

Pricing and Billing (how and when customers make payments to you)

Development velocity (how much time from coding to making that new feature available to users)

Release cycle (how often is a major revision released)

Infrastructure (where does the "software" runs on; who pays for the hardware; who maintains the machines)

Simply put, it is a revolutionary trend and a disruptive innovation, although it is a gradual change happening over the decades and not an abrupt change.

It is disruptive in the sense that software development companies which do not adopt SaaS will be in a permanent competitive disadvantage and face extinction.

Architecture

See "software architecture" and "software engineering" in Wikipedia. Also look up for "management and information systems (MIS)" in your own school's course offerings.


问:
does haskell have dependent types?
I know Haskell already has the ability to parametrise a type over another type (similar to template programming in C++), but I'm wondering whether Haskell can also parametrise a type over values – whether it supports dependent types. With dependent types, you can have a type that's parametrised over integers, for example vectors of size n, matrices of size n×m, etc.

If not, why not? And is there any possibility that it will be supported in the future?

答:
Haskell has traditionally tried to fake it, but the end result is a much larger and seemingly repetitive type system. But this might soon change! See:

https://www.youtube.com/watch?v=O805YjOsQjI

https://ghc.haskell.org/trac/ghc/wiki/DependentHaskell

https://github.com/goldfirere/ghc/

Title: does haskell have dependent types?


问:
can a closed source commercial software make system(3) calls to GPL applications (not libraries)?
The closed source commercial software (CSCS), will just make system(3) calls to GPL applications.

The user machine will run CSCS and it will call these GPL applications, in realtime, in the very same way a user could use the command line and call the very same applications. Even a log of such actions could be provided, and user could replicate these actions manually.

In Java it would be like: Runtime.getRuntime().exec("echo Hello");

In C it would be like: system("echo Hello");

The point is, the CSCS is calling a GPL application to just generate realtime output, and in a predetermined way and hard coded on it, so CSCS depends on GPL app to work.

The GPL application is NOT a library. Is a regular command line application.

And, I am NOT going to distribute any GPL application (neither its sources) packaged together with CSCS. It will just depend that the OS have such GPL apps already installed. Also, CSCS can run with at least the version of the GPL application that was used in the development time (or newer), so it will NOT depend on a specific GPL app version to run.

1) Can the CSCS remain closed source on this sole specific situation?

2) Or should CSCS only use statically generated output from GPL applications, being prevented to use them in realtime, if it wants to remain closed source?

3) Alternatively could be created a LGPL software composed by scripts like ls -l $1 whose parameters would be dynamic data provided by any application including this CSCS. In this case, all the logic of these scripts would be exposed and reusable by anyone, therefore not proprietary. So, such "protocols" would all be LGPL. Can that be done? Or this would simply fall under something like indirect use of GPL sofware, and so GPL would infect every application using it (including this very LGPL software, forcing it to become GPL)?

I would appreciate also excerpts confirming the answer, thanks!

PS.: I have read this Can I use GPL software in a commercial application, and it doesnt seem to answer my specific question.

And, I need to know this before I can consider any kind of realtime GPL application usage on my software.

Linking: https://softwareengineering.stackexchange.com/a/161938/112610

I was unable to avoid linking this: https://meta.stackexchange.com/a/91116/222324

Another Link: https://softwareengineering.stackexchange.com/a/211357/112610

Obs.: (2 days after, considering all commented tips and answers) These may contain the answer:

A) I think this very question could actually be "What is a GPL derived work?" considering the "Networked Systems" section.

B) See "Mere Aggregation" in the GPL FAQ "pipes, sockets and command-line arguments are communication mechanisms".

PS.2: just as a final disclaimer, we all here seem to not be lawyers, and even if you do it all correct in this line, and even if you are sure of your license interpretations, something you do not expect may happen, https://softwareengineering.stackexchange.com/a/158925/112610

答:
This situation is covered in the GNU GPL FAQ, in the section "I'd like to incorporate GPL-covered software in my proprietary system. Can I do this?"

in many cases you can distribute the GPL-covered software alongside your proprietary system. To do this validly, you must make sure that the free and non-free programs communicate at arms length, that they are not combined in a way that would make them effectively a single program.

The difference between this and “incorporating” the GPL-covered software is partly a matter of substance and partly form. The substantive part is this: if the two programs are combined so that they become effectively two parts of one program, then you can't treat them as two separate programs. So the GPL has to cover the whole thing.

If the two programs remain well separated, like the compiler and the kernel, or like an editor and a shell, then you can treat them as two separate programs—but you have to do it properly. The issue is simply one of form: how you describe what you are doing. Why do we care about this? Because we want to make sure the users clearly understand the free status of the GPL-covered software in the collection.


问:
What are technologies like XML, JSON, and YAML classified under?
What are technologies like XML, JSON, and YAML classified as?

I already looked at

Query Language

Data-structured Language

But neither appeared accurate...  None of them are really meant for creating queries.  And JSON isn't a language, so DSL doesn't apply.

I see those technologies used a lot with configuration files and passing data between web services and web clients.  Is there a general category or term to describe them?

答:
XML = "eXstensible Markup Language"

YAML = "YAML Ain't Markup Language"  (Though it was originally "Yet Another Markup Language".)

Though in truth people think of them more like data formats (which JSON is) rather than languages partly because people assume "Language" == "Turing Complete".


问:
Cache concurrency: ensuring latest version in cache
We have a data service app working on object graphs. We place some complex graphs in a (memory) caching tier as a single data item, so as to avoid the length of time to retrieve every individual data item in disk storage in order to build the entire hierarchy.

That means whenever any of the data items change, a re-cache event is triggered - reloading everything in the hierarchy and storing the newer version to cache.

Recently we made tweaks to the service to increase its concurrency of asynchronous operations (mostly network I/O), and observed contention behaviour if multiple incoming requests made updates to items in essentially the same object graph.

Each update operation is unaware of other concurrent updates. At the storage persistence level, the infrastructure has timestamps on the data rows; allowing us to apply optimistic concurrency techniques, ensuring nobody is writing an outdated version back to storage.

A change in any child object causes the root object to increment a version number, thus the re-cache. During such an event, other concurrent updates may happen for any other child object (or even the same), which makes it difficult to tell what a particular version of the root object is supposed to really have (at point of update time). What is worse, and the main concern here, is that due to concurrent thread contention for processor attention, the caching attempt of an older version can happen after the caching attempt of a newer version.

Right now we have minimised this behaviour by verifying that the root object's version during a re-cache event still matches the version saved during its own update operation. If the version number is not the same, it means another concurrent update has since changed it further and the re-cache should not proceed - let the last update operation perform the re-cache.

That of course minimises the chances but not eliminate outright; it can still be possible for the root object to retain its original version number on re-fetch, and while re-fetching all the children objects, another update happens and by stroke of (ill) luck manages to complete and re-cache before this ongoing re-caching attempt has completed its round.

To further complicate the issue, this data service is deployed as a cluster of servers with no knowledge about each other's siblings.

Was wondering if there is any effective way to manage the concurrent updates across multiple threads and servers to ensure the cached copy is indeed always the latest copy?

答:
At the end it seems necessary that the cache service also needs some optimistic concurrency implementation.

Instead of blindly writing whatever "new" version the application has to the cache tier, it must first retrieve a copy (if cached) to determine the cached version and current optimistic concurrency key.

E.g. Couchbase Server provides CAS values; Azure blob storage provides ETag.

If the current cached version is newer than the attempted version, the attempt will abort since it has been superceded.

If the current cached version is older, the cache attempt will proceed with the last-known optimistic concurrency key value. If another separate thread/operation had re-cached in between, then the optimistic concurrency key would have changed and the current cache attempt would fail. Under such an event, it would have to re-fetch the new item version and optimistic concurrency key, and repeat the cycle.

This of course comes at the cost of having to waste at least one read operation simply to determine whether it is safe to write a new version. But given that data consistency is paramount I guess that is a price that has to be paid.


问:
Maintain ordered collection by updating as few `order` fields as possible
I'm working on integrating a reorderable lists UI widget with a Meteor.js (MongoDB, in effect) collection:

```<code>{
  order: ???,  // what type to use here?
  property1: ...,
  ...
  propertyN: ...
}
</code>```

Each document in the collection has an order field. The UI gets the collection from the server, sorts it by the order field, and displays it in a list. When the user drags an element into a new position in the list, I get the oldIndex of the document and the newIndex relative to the beginning of the list (where it was dropped). Now, I need to update the order field and save the affected document(s) back into the collection.

What should be the nature of the order field to minimize the number of updates, yet not limit the number of times a document can be reordered?

A naive implementation uses integers and sets the order of the dropped item to the arithmetic mean of the documents before an after. Of course, this will run into floating point precision limits (50 reorders in JavaScript if you start with consecutive integers).

Another implementation (also suggested in this question would change the order of all the intervening documents between the oldIndex and the newIndex of the dropped document, or between the start/end of the list and the dropped item (whichever involves fewer elements). Of course, this is less efficient, particularly for larger lists.

Anything smarter? Using a string or object of some sort for the order field?

答:
One obvious solution is to use arbitrary precision arithmetic.

As an implementation with big.js:

```<code>var Big = require('./big.js');

function average(x, y) {
  // exact result; .div(2) requires specifying .DP
  return Big(x).plus(y).times(0.5);
}

var x = new Big(1);
var y = new Big(2);

for (i = 0; i <= 10; i++) {
  x = average(x, y);
  console.log(x.toString());
}
</code>```

The disadvantage, of course, is that each reordering will add one byte to the order field. A normalize method could parse the orders and convert them to 0..N.

Body:
One obvious solution is to use arbitrary precision arithmetic.

As an implementation with big.js:

var Big = require('./big.js');

function average(x, y) {
  // exact result; .div(2) requires specifying .DP
  return Big(x).plus(y).times(0.5);
}

var x = new Big(1);
var y = new Big(2);

for (i = 0; i <= 10; i++) {
  x = average(x, y);
  console.log(x.toString());
}

The disadvantage, of course, is that each reordering will add one byte to the order field. A normalize method could parse the orders and convert them to 0..N.


答:
Despite having the word language in them, I would not consider them programming languages, but rather data formats.  I know that XML has been used as the format for some DSLs, probably likewise for YML.

A language does not have to be Turing complete to be a programming language, but it does need to be active -- without exceeding the standard definition, these "languages" do not include meanings that act upon the data.

XSLT is a language that uses XML, but XSLT is more than just XML --it attaches meanings beyond the DTD it attaches meaning that includes actions to be taken on the data.  While not mentioned, HTML, like XSLT, is a programming language.  XSLT is Turing complete while HTML is not. HTML is a declarative language -- it says to emphasis some content or that some content is a heading or to be bolded.

The whole point of XML is for it to NOT include actions -- it is data.  What that data means, whether it is a todo list or a program for calculating Fibonacci sequences is inconsequential -- XML is data and the related DTD describes its format, the MEANING of the data is determined by the consumer.  XML does this because HTML mixed the data and the meaning, which proved somewhat, uhm, fragile.

In short, just accept it as sloppy terminology, and move on.

Title: What are technologies like XML, JSON, and YAML classified under?

Body:
What are technologies like XML, JSON, and YAML classified as?

I already looked at

Query Language

Data-structured Language

But neither appeared accurate...  None of them are really meant for creating queries.  And JSON isn't a language, so DSL doesn't apply.

I see those technologies used a lot with configuration files and passing data between web services and web clients.  Is there a general category or term to describe them?


答:
The underlying purpose of serialization is to ensure that data produced by one system is able to be consumed by one or more compatible systems.

The easiest and most robust approach to serialization is to translate the data into a type agnostic format that maintains the structure in a simple and easy-to-consume format. For instance the most ubiquitous serialization formats (ie JSON, XML) use a well-defined text-based format. Text is simple to produce, transmit, and consume.

There are 2 reasons why using one of these formats may not be ideal.

Efficiency

There is an inherent cost involved in translating all of the data into their text-based equivalents. Data types wouldn't exist if text was the most efficient way to express all the different forms of data. In addition, the structure of these formats is not ideal for retrieving subsets of data asynchronously or in parts.

For instance, XML and JSON assume that the data being used will be written and read from start to finish. For processing very large data sets where memory is scarce, the system consuming the data may require the ability to process the data in parts. In that case, a special purpose serialization/deserialization implementation may be required to handle the data.

Precision

The casting required to serialize/deserialize the data from it's intended type to data agnostic type result in a loss of precision.

One could argue that producing a binary representation of the objects and data is clearly the most efficient and accurate solution. The major drawback is that the implementation of all systems that both consume and produce data need to remain compatible. It's a simple constraint in theory but it's a nightmare to maintain in practice as production systems tend to change/evolve over time.

With that said. Decoupling serialization/deserialization from the domain-specific details makes sense as a general rule because general purpose formats are more robust, better supported across diverse systems, and require little-to-no increased maintenance overhead to use.

Title: Best practices for serialization of DDD aggregates

Body:
According to DDD domain logic should not be polluted with technical concerns like serialization, object-relational mapping, etc.

So how do you serialize or map the aggregates' state without publicly exposing it via getters and setters? I have seen lots of examples for e.g. repository implementations, but practically all of them relied on public accessors on the entities and value objects for mapping.

We could use reflection to avoid public accessors, but IMO these domain objects would still implicitly be dependent on the serialization concern. E.g. you couldn't rename or remove a private field without tweaking your serialization/mapping configuration. So you have to consider serialization where you should instead be focussing on domain logic.

So what's the best compromise to follow here? Live with public accessors, but avoid using them for anything else but mapping code? Or did I just miss something obvious?

I'm explicitly interested in serializing the state of DDD domain objects  (aggregates consisting of entities and value objects). This is NOT about serialization in general or transcation script scenarios where stateless services operate on simple data container objects.


答:
Declarative Languages

Declarative programming is often defined as any style of programming that is not imperative. A number of other common definitions exist that attempt to give the term a definition other than simply contrasting it with imperative programming.

For example:

A program that describes what computation should be performed and not how to compute it

Any programming language that lacks side effects (or more specifically, is referentially transparent)

A language with a clear correspondence to mathematical logic.[4]

Source: Wikipedia

Declarative languages are intended to express what -- not how -- a program should accomplish.

Web based design (ie HTML/CSS) are both good examples. They describe instructions for the browser on how a webpage should be structured and represented visually but possess no ability of their own to produce the output. How browsers/clients consume their code can be wildly different as long as the output produces the intended result as per the W3C/WHATWG specify.

Serialization/deserialization and DSLs (Domain Specific Languages) like SQL are another good example. They are designed and intended to follow a strict standard of functionality regardless of what language/platform they are run on.

The key to a good declarative language is that it does a good job of describing a data/process in simple, finite terms with little room for subjective variation.

The key to a good implementation of a system that consumes/produces declarative code is consistency with any/all other systems that consume it.

Markdown is a good example of a useful declarative language that suffers from a poor initial specification/design. Markdown evolved organically in the wild because of its usefulness. Unfortunately, in the absence of a well defined specification, there are now a lot of different variations when it comes to implementation. Many notable developers have taken the standardization of Markdown as a personal mission but -- at best -- an official standard will only be accepted through the slow/painful process of survival of the fittest. Even then, variations will always exist to some extent.

Technically, there is a formal system for classifying languages called the Chomsky Hierarchy. It describes is mathematical terms the different types of programming grammars based on how they're parsed.

XML, JSON, and YAML generally fall under context-free or context-sensitive languages depending on how they're used.

Considering usage, I think Declarative is a better term to describe what you're looking for.


问:
PirateBrowser Licensing
I am sorry if this question isn't appropriate here, but this made me confused.

But what I read in MPL 2.0, any software derivated from a existing one with this license should keep it under such license.

Then my question is:

Is the PirateBrowser violating mozilla's license since there is no indication of the source anywhere?

What could a user do to enforce such license ? (i.e request the source-code)

答:
Section 3.2 of the MPL 2.0 says:

If You distribute Covered Software in Executable Form then such Covered Software must also be made available in Source Code Form, as described in Section 3.1, and You must inform recipients of the Executable Form how they can obtain a copy of such Source Code Form by reasonable means in a timely manner, at a charge no more than the cost of distribution to the recipient

When they make any modifications to Firefox, they must publish the sourcecode. However, when they don't modify it and only bundle it with a custom configuration and some other software under different license terms (as they claim: "There have been no modifications to any of the packages used"), it is sufficient to point out that the sourcecode can be downloaded for free from Mozilla.

Title: PirateBrowser Licensing


问:
Using audit trail as time machine?
I would like to do

```<code>SELECT * TABLE t (using data from 1st of march 2012)
</code>```

I already have a nice audit trail of all tables in the database. It basically makes a copy of all rows that change, storing all columns of the changed row in an hstore column. This means that we have the data available, but I am unsure of whether it is the best way to store the data for a database time machine.

To give you more context, we are creating accounting software. This means that we need to be able to recreate all reports which we have offered to the customer (they can see them on our website and get updated continuously).

What sorts of problems do you anticipate that I will run into with this approach? Is there a better approach?

Some facts

Each row in the main table gets edited 5 times on average.

The main table has 32 columns (could get reduced to only 7 that need to have an audit trail)

We will only ever have 1 million users on our software, each will have ~700 rows in the main table.

答:
Here is my favorite approach:

Each table has a corresponding history table

Write stored procedures (or triggers) to make sure that all actions are logged to the history tables

On insert, add a row to the history table with start = now() and end = 31.12.2999

On update, first update the most recent history record to end = now(). Then insert a new row with start = now() and end = 31.12.2999

On delete, update the most recent history record to end = now().

Now you can write a point-in-time query, even with joins:

```<code>select g.groupname, p.productname, p.price
from products_hist p, product_groups_hist g
where p.id = g.id
and p.start <= now() and now() < p.end
and g.start <= now() and now() < g.end
</code>```

Title: Using audit trail as time machine?

Body:
Here is my favorite approach:

Each table has a corresponding history table

Write stored procedures (or triggers) to make sure that all actions are logged to the history tables

On insert, add a row to the history table with start = now() and end = 31.12.2999

On update, first update the most recent history record to end = now(). Then insert a new row with start = now() and end = 31.12.2999

On delete, update the most recent history record to end = now().

Now you can write a point-in-time query, even with joins:

select g.groupname, p.productname, p.price
from products_hist p, product_groups_hist g
where p.id = g.id
and p.start <= now() and now() < p.end
and g.start <= now() and now() < g.end


问:
Coerce bad input or always crash early
The general consensus seems to favor the Crash Early approach, the most reputable source being the acclaimed Pragmatic Programmer book.

And while I understand and agree with the advice in many situations, I wonder if once the program is deployed in production, isn't it also valid to simply log a warning and proceed the execution?

In many cases might be best to show a partial or empty response than no response at all. Imagine the stack exchange module to fetch similar questions, isn't it best to show some results than no results at all?

Could a method that iterates over a collection, when passed a null value coerce it into an empty collection and effectively skip execution, instead of crashing? Or a method that receives a negative number coerce it into the minimum/maximum applicable value, instead of crashing?

答:
As usual, there are obvious upsides and downsides to coercing. It will let your program run on in production, when it is weak and alone and has no one to hold its hand; it must manage whatever conditions it is put into all by itself, and warping to the minimum value is the obvious thing to do. If crashing or skipping a task altogether would be very expensive or catastrophic to your business, then there's a good case to be made for making software robust.

But that's only one side of the coin. In the long run, programing like this makes your code unreadable, long, ugly and unmaintainable. If a negative value comes in, you should be asking yourself: why? If it's from direct user input, why did your front-end allow the minus sign in the first place? If it's from an internal value, was that supposed to happen? If not, why did it happen? Is there a completely different defect in your program that allowed this? Pursuing and correcting such errors will improve the quality of your code base much more than adding yet another patch for yet another special condition that might cause an exception.

Unfortunately, these two approaches are hard to combine. The point of testing software is to try it out in the situations that it will actually be in, so writing finicky, error-sensitive code in development and then deploying robust code isn't possible at the same time. Therefore it is important that you are aware of such trade-offs so that you can make the correct judgement call whether robust processing no matter what is more valuable to you than having a well-designed code base that reduces the number of systemic problems. This is something that no runtime, no coding policy and not even the best online programmer's forum can decide for you.

Title: Coerce bad input or always crash early


问:
(HTML) Form structure storage
In the context of a single-purpose website/application (for instance, based on Symfony2), I wish to have a set of forms fillable by users which then will be sent out as a formatted email (with the same labels as the forms on the website.) It is unlikely that they would need to be updated, although new ones may be created in the future.

Would it be wise to just have a set of configuration files based in YAML or JSON (which then would be loaded on-the-fly or cached by the application,) or should they be stored in a database (either as a JSON/YAML blob, or as forms/fieldsets/fields/*sub-fields? (* in the case of dynamically added sets of fields.)

答:
My experience in this sort of thing is to prefer to stay consistent within my program.  In other words, you feel you can't do without a database, then your program would likely be more robust if it depended only on that database rather than also on the file system.  The more components your program depends on, the more problematic it becomes in terms of maintenance and installation.

However, I suppose it also depends on your application.  Configurations that are specific to your installation have no place on a database which may be potentially shared.  The information contained within may also present security risks in that case.  However, again, it depends on your application.  If you intend to have one database per installation and this database is accessed locally (not a public database), this is no longer important, however should you find yourself in that position, you should probably use both a local file-based configuration (JSON, YAML, XML, whatever your preference is) for the information specific to that particular installation, as well as a database for everything else.

Otherwise, I would stick with the database.  Then, if your application does not require a database, there is no need to add a dependency to a database simply to place your configuration.  It would make sense to strictly use only a local configuration on the file system at that point.

Hope that helps!

Title: (HTML) Form structure storage


问:
Implementing "Trending Items" using linear regression in SQL Server
I'm building an MVC .NET website where people can rate and review movies (similar to IMDb). I'm using SQL Server for the back-end.

I'll be implementing a feature where the homepage displays trending movies, i.e. movies which have been positively rated within a particular time-period (let's say last 7 days).

I'll be using a stored procedure which implements linear regression to accomplish that.
My relevant SQL tables are the following:

Movie - PK Movie_ID, stores movie information

User - PK User_ID, stores user information

Rating - stores rating instances in the form of:

PK Rating_ID | FK Movie_ID | FK User_ID | RatingNo | Updated_Dt

```<code>  1             5            10          7     15/12/2014 16:04:24
</code>```

The above row would translate to "User with ID 10 gave movie with ID 5 a rating of 7/10 on 15/12/2014 16:04:24".

I also have a function to calculate the average score of a movie in the form of AVG_Rate = sum of all ratings (for a given movie) / count of ratings (for a given movie).

My question is this: Given the provided table structure above, what would be the best way to implement "movies trending this week"? I can think of two ways at the moment:

Create a permanent table to run linear regression on:

Movie_ID | AVG_Rate | Updated_Dt

Whenever a new rating row is added in Rating, also insert a new row in the new table, but instead of storing the actual rating, store the new calculated AVG_Rate instead:

Movie_ID | AVG_Rate | Updated_Dt

```<code>1           7.8    15/12/14 17:00:00
1           7.6    15/12/14 17:01:00
1           7.9    15/12/14 17:03:00
</code>```

...And so on. I can then use the new table to check for linear regression of a given movie. In terms of the table becoming too large over a period of time, I can have the table only hold 7 days worth of data at any given time (by e.g. backing up every 7 days and deleting data older than a week).

Create a temporary table to run linear regression on:

Same logic as above, except that the table is created temporarily on the fly whenever the stored procedure for getting trending movies is invoked. The AVG_Rate changes for each movie can be calculated directly from the Rating table.

I'm skeptical about which approach would work the best (I'm not advanced in SQL) and also not sure whether any of these two solutions are the way to go.

Any help & guidance would be greatly appreciated. Thanks!

答:
I would probably do this a third way, which is by adding a column to your rating table whose value is the average rating after that rating is applied. This means that this stage of the calculation will only need to be preformed once rather than every time your stored procedure is executed, resulting in somewhat better performance. Technically this results in your database not being entirely normalized, but as it is only historical data that should not be changing that is denormalized I wouldn't consider that huge issue.

This is similar to your first suggestion, of course, but avoids the duplication of information to a separate table.


答:
In your examples you are not talking about failing early but rather about how to handle expected failure cases.

Handling expected failure cases

You gave the similar questions module as example. It can be aware, that one of its submodules may not be able to deliver and then just shows the rest of the questions that it got by its submodules. A counterexample would be a medical software for finding patients with similar symptoms. It would not just show the rest, but rather print a warning that some patients could not be listed because of some error, but still continues to work and fulfill its job, which would be "print all patients, or an error message if you can't print all the patients". This is a important difference, but has nothing to do with failing early. It is about handling expected failures because the modules are aware of this specific possibly occuring failure. Note that this has only to do with business logics, nothing with the technical handling.

Handling unexpected failure cases (or rather, not doing so...)

The submodule for delivering (part of) the similar questions could fail because it for example may expect, that there is a network connection available. If there is none, it could go on and and continue working with an emtpy question list but that is not reasonable - it just makes no sense. So, as it does not know how to handle this situation, it is considered as an unexpected error and so it throws an exception, therefore stopping its work immediatly, telling its caller that it cannot fulfill its contract and deliver the expected results. So, instead of pretending to be able to fulfill its contract (and in the worst case produce business logic errors somewhen later) it fails early.

So, to answer your question: yes, you can have your similar questions module to print just some of the questions if it cannot fetch all and still following the guideline for failing as early as possible, because they do not contracit each other.

Could a method that iterates over a collection, when passed a null value coerce it into an empty collection and effectively skip execution, instead of crashing?

However, if the method contract says "I expect a collection and then do something" and it then receives a null value, it should fail early, because it cannot fullfill its contract. If it does not fail early and continue doing stuff, then bad things may happen and I cannot see any advantages of it. Unless the whole software blows up because of one low level exception - but then it is poorly designed anyways and the - correctly failing fast - function is not the root of the problem.

Title: Coerce bad input or always crash early

Body:
The general consensus seems to favor the Crash Early approach, the most reputable source being the acclaimed Pragmatic Programmer book.

And while I understand and agree with the advice in many situations, I wonder if once the program is deployed in production, isn't it also valid to simply log a warning and proceed the execution?

In many cases might be best to show a partial or empty response than no response at all. Imagine the stack exchange module to fetch similar questions, isn't it best to show some results than no results at all?

Could a method that iterates over a collection, when passed a null value coerce it into an empty collection and effectively skip execution, instead of crashing? Or a method that receives a negative number coerce it into the minimum/maximum applicable value, instead of crashing?


问:
Should I use events or abstract methods?
Lets say I create an abstract class that manages some network functionality for me.

I want to be able to be notified when something changes. For example: OnConnect or OnDisconnect.

Should I create events for those kinds of functions or implement them as abstract methods?

```<code>public event OnConnectDelegate OnConnected;
</code>```

or:

```<code>protected abstract OnConnected(SomeClientObject connectedClient);
</code>```

I prototyped both solutions and both work as expected. But how do I know in general if I should expose functionality as an event or as an abstract method?
Are there any situations where I should clearly prefer one over the other?
Events support multiple receivers but one also has to remove them when the receiver doesn't need to receive them anymore.

答:
I'd suggest doing both!

Those on* methods are the ideal place from which to raise those events.  (Well, it must have some merit; that's the way most, if not all, of the .Net Windows Controls work).

```<code>internal class Button2 : System.Windows.Forms.Button
   {
      protected overrides void onClick( EventArgs e )
      {
         if ( ! this.AmIgnoringTheUser() )
         }
            // Ask the base Button control to raise the Click event
            base.onClick( e );
         }
      }
   }
</code>```

If your class is declared as "sealed" (/ "notinheritable" / "final"), then the above is probably the only reason to have the on* methods.  You consumers can only attach event delegates.

This protects your class, in that people can't muck about with its innards, but it reduces its useability if its, say, a visible Control.  Visual Inheritance makes extensive use of these overridable on* methods for the simple reason that you cannot guarantee the order in which event delegates are invoked.  You can guarantee the order that the on* methods are called in.

Body:
I'd suggest doing both!

Those on* methods are the ideal place from which to raise those events.  (Well, it must have some merit; that's the way most, if not all, of the .Net Windows Controls work).

internal class Button2 : System.Windows.Forms.Button
   {
      protected overrides void onClick( EventArgs e )
      {
         if ( ! this.AmIgnoringTheUser() )
         }
            // Ask the base Button control to raise the Click event
            base.onClick( e );
         }
      }
   }

If your class is declared as "sealed" (/ "notinheritable" / "final"), then the above is probably the only reason to have the on* methods.  You consumers can only attach event delegates.

This protects your class, in that people can't muck about with its innards, but it reduces its useability if its, say, a visible Control.  Visual Inheritance makes extensive use of these overridable on* methods for the simple reason that you cannot guarantee the order in which event delegates are invoked.  You can guarantee the order that the on* methods are called in.


答:
I would like to offer a different approach than the accepted answer based on event sourcing + cqrs.

Event sourcing is a different approach than nor relational design. You basically have only one table lets call it events. An event Is something that happened in the past tense. I.e AccountCreated MoneyDeposited. These events are classes that you serialize to text with your favorite serializer. The events have a defined ordering which means we can build something on top.

CQRS means command query resposibility segregation. It means we have two models. One for writing and one for reading. Lets focus on the write model. Every time you want to change your object you save an event to the stream. Lets say we save a MoneyDeposited event. We make an event handler inside our class. A ultra simple example could look like this(some infrastructure missing).

```<code>class BankAccount{
    long Balance{get;set;}
    void Deposit(long amount){SaveEvent(new MoneyDeposited(AccountId,amount); }
    void Apply(MoneyDeposited m){balance += m.Amount; }
}
</code>```

Since we now have split the apply method out we can read an entire stream from db which just calls Apply().

This means we can easily check the consistency rules. Lets say the WithDraw() method has insuffficent funds. It will throw before publishing the event. We can also easily use optimistic concurrency to check that two objects are being modified concurrently leading to inconsistencies since we read row n from db we increment row in memory to n+1 and thus a simple unique index will fail if some other thread wrote that row before us.

This is all simplified quite a bit, but your goal was to use a time machine and with the streams you just choose the row number you want to read and ignore anything newer.

I haven't event touched the read models yet but a long store short is that in some other storage you build a number of representations based on the events ready to eat.

Some keyworks to get you started on this. CQRS event sourcing. Try to find presentations from Gregg Young, Udi Dahan and Rinat Abdullin. Some useful frameworks: NEventStore(.NET) or Cirqus(.NET) even if it is quite young.

Title: Using audit trail as time machine?

Body:
I would like to do

```<code>SELECT * TABLE t (using data from 1st of march 2012)
</code>```

I already have a nice audit trail of all tables in the database. It basically makes a copy of all rows that change, storing all columns of the changed row in an hstore column. This means that we have the data available, but I am unsure of whether it is the best way to store the data for a database time machine.

To give you more context, we are creating accounting software. This means that we need to be able to recreate all reports which we have offered to the customer (they can see them on our website and get updated continuously).

What sorts of problems do you anticipate that I will run into with this approach? Is there a better approach?

Some facts

Each row in the main table gets edited 5 times on average.

The main table has 32 columns (could get reduced to only 7 that need to have an audit trail)

We will only ever have 1 million users on our software, each will have ~700 rows in the main table.

Body:
I would like to offer a different approach than the accepted answer based on event sourcing + cqrs.

Event sourcing is a different approach than nor relational design. You basically have only one table lets call it events. An event Is something that happened in the past tense. I.e AccountCreated MoneyDeposited. These events are classes that you serialize to text with your favorite serializer. The events have a defined ordering which means we can build something on top.

CQRS means command query resposibility segregation. It means we have two models. One for writing and one for reading. Lets focus on the write model. Every time you want to change your object you save an event to the stream. Lets say we save a MoneyDeposited event. We make an event handler inside our class. A ultra simple example could look like this(some infrastructure missing).

class BankAccount{
    long Balance{get;set;}
    void Deposit(long amount){SaveEvent(new MoneyDeposited(AccountId,amount); }
    void Apply(MoneyDeposited m){balance += m.Amount; }
}

Since we now have split the apply method out we can read an entire stream from db which just calls Apply().

This means we can easily check the consistency rules. Lets say the WithDraw() method has insuffficent funds. It will throw before publishing the event. We can also easily use optimistic concurrency to check that two objects are being modified concurrently leading to inconsistencies since we read row n from db we increment row in memory to n+1 and thus a simple unique index will fail if some other thread wrote that row before us.

This is all simplified quite a bit, but your goal was to use a time machine and with the streams you just choose the row number you want to read and ignore anything newer.

I haven't event touched the read models yet but a long store short is that in some other storage you build a number of representations based on the events ready to eat.

Some keyworks to get you started on this. CQRS event sourcing. Try to find presentations from Gregg Young, Udi Dahan and Rinat Abdullin. Some useful frameworks: NEventStore(.NET) or Cirqus(.NET) even if it is quite young.


答:
... I wonder if once the program is deployed in production, isn't it also valid to simply log a warning and proceed the execution?

Short answer: No.

Every function you write runs in its only tiny little world that only knows about the argument values passed to it.  It can only change or reinterpret the intention of those values if it understands the world "outside" of itself better than the code that's actually "out there", passing those dodgy values in. (hint: that's unlikely)

... isn't it best to show some results than no results at all?

"Are there any indications that this nuclear reactor core has gone runaway and is about to start melting its way through the floor?  Hmm; this is taking too long; I'll just return 'OK'. "

OK, slightly facetious example, but in this particular case, then yes, it really does matter that you bring back all the right results.  It comes down what's considered "good enough"?

Could a method that iterates over a collection, when passed a null value coerce it into an empty collection and effectively skip execution, instead of crashing?

And do what?

A box of chocolates is a set of zero or more confectioneries; given a box and a big enough appetite, you can "iterate" through all of them.  How can you do that if you're not even given the box?

Your function has been told to expect a collection but it's been passed nothing.  That's a really good time to let an Exception get thrown; that way, the calling code becomes responsible for handling the mess that it just created, passing you bad (missing) data.

Or a method that receives a negative number coerce it into the minimum/maximum applicable value, instead of crashing?

Why would a negative number cause a crash?  Perhaps it's an indexer into an Array or List?  Unless there's a business reason to allow negative values (and, admittedly, there could be) then here's another good reason to "pass the buck" upwards, back to the calling code, courtesy of another Exception.

Title: Coerce bad input or always crash early