问:
Are Serverlet Containers' Characteristics Against Scalability and Fault-Tolerance of a Web Application?
We most likely deploy a JVM-based Web application (e.g., Scala) on a container (e.g., TOMCAT, Jetty, etc.). Does the following points about a serverlet container goes against us to create a scalable and fault-tolerance Web application?

Single Point Of Failure: If the container fails the application fails. Also, we can't update the application while it is on the container.

Large Number of Simultaneous Connections: Based on my understanding we can't use a container to deliver the Web application to tens of thousands of users per second.

答:
You should not use a container, but use a containerless framework such as Play instead. Regarding your points:

Single Point Of Failure: This is independent of deploying in a
   container or not. I you just deploy one instance of your app and it
   crashes, it's down. For high availability you'd use multiple running
   instances and load balance between them, with container or without.

Large Number of Simultaneous Connections: The Servlet API is based on a
   thread-per-request model, i.e. each request will take up an entire
   thread. This can be a newly spawned one, or more likely one taken
   from a thread pool. So the maximum number of simultaneous requests is
   determined by your container's thread pool size, or the number of JVM threads
   your hardware can handle well. That number is probably not as high as
   you'd like, as each servlet container thread takes up a lot of
   memory, and switching between threads is a relatively costly
   operation. You'll make much better use of your hardware with an asynchronous
   approach, where each thread handles many requests concurrently, i.e.
   with a framework that is not based on the Java EE Servlet API.

For more details about Play's asynchronous approach I recommend: http://www.slideshare.net/Typesafe_Inc/why-play-framework-is-fast

Maybe try out the "Reactive Scales" app to get an indication how many requests/second Play handles on your machine.

An elaborate view of why "Java Application Servers Are Dead" is given in http://www.slideshare.net/ewolff/java-application-servers-are-dead


问:
Difference between sibling lists, left-child right-sibling binary tree and doubly-chained tree
The Wikipedia page for suffix trees descibes sibling lists as

Each node has a pointer to its first child, and to the next node in the child list it is a part of.

Wikipedia describes left-child right-sibling binary trees in the followeing manner:

Then, starting with the root, each node's leftmost child in the original tree is made its left child in the binary tree, and its nearest sibling to the right in the original tree is made its right child in the binary tree.

Lastly, acoording to Wikipedia, doubly-chained trees have the following property:

In a doubly-chained tree, each node has two pointers, one to the node's first child and one to its next sibling.

To me, these three definitions are exactly the same. Is there a difference?

答:
As far as I can tell, a "sibling list" implementation of a suffix tree, a "left-child right-sibling binary tree" and a "doubly-chained tree" are all exactly the same data structure.

Source 1: The NIST Dictionary of Algorithms and Data Structures entry for "binary tree representation of trees" states that this is

Also known as first child-next sibling binary tree, doubly-chained tree, filial-heir chain.

Source 2: There is actually a Wikipedia book called Data Structures which--at least in the Google books preview--contains the following sentence:

This binary tree representation of a general order tree, is sometimes referred to as a First-Child/Next-Sibling binary tree, or a Double-chained tree, or a Filial-Heir chain.

Source 3: These slides from a university CS course refer to this as a tree's

1st Child / Next Sibling List Representation

So I think it's reasonable to conclude that this is simply one data structure with a lot of different names.

P.S. I couldn't find any sources besides that Wikipedia stub which use a name with "right-sibling", so it's possible that "next-sibling" names are more common/standard (and they do seem more intuitive to me).

ContentLicense: CC BY-SA 3.0


问:
What is Black Box Testing? Are Functional and Usability Testing its types?
I am writing about testing and I am confused about the following:

What exactly is Black-Box testing?

Are functional testing and Usability testing two different types of testing and are they types of Black Box testing?

I have to perform two different types of testing procedures. Is it ok if I do functional and Usability testing?

答:
Black-box testing as opposed to white-box testing is a broad category of testing that includes tests where you do not know, and do not need to know, how the implementation works, you just want to test the outcome.

For example: I click the buy button on a web site and the item I selected is now in my shopping cart. I don't care how the programmer made this happen, just that it did happen and the correct item was put in the shopping cart.

In white box testing you want to peer into the internals of the code and probe implementation details. This is more common at the lower level, unit testing.

Functional testing could be either black box or white box testing, depending on exactly what type of tests you want to perform. The two categorisations are not mutually exclusive, they refer to different aspects of the tests. There are lots of ways of categorising tests and everyone has their own interpretation of which is best, or most appropriate in a given situation.

I would say usability testing is almost certainly going to be black box testing. There are many different kinds of usability testing where you should perform the ones that you think the product would most benefit from. You might be critiquing the user interface design, verifying that a likely customer end to end scenario works, or testing that accessibility statutory requirements are met. I would consider all of these usability testing, although, as I said before about people having different opinions on what to call different types of testing, others may disagree.

It is ok to do both types of testing if you think you are adding value by doing both. Sometimes you are adding value by supporting your team in find bugs, sometimes by critiquing the design with a fresh pair of eyes. Sometimes by creating automated regression tests so that the team don't make common mistakes in the future and can verify easily that they haven't broken anything with a change. If you think you are testing the same thing again you probably aren't adding much value, but you can be adding value without every test you carry out ending in filling a bug report.


问:
Perfect time synchonization betweeen devices
I want to make two devices synchronize metronome over bluetooth/wifi.
However I've got no idea how to make it perfectly synchronized.
There are two possible solutions that I've found out:

Naive -> Send start command to other device then start metronome after fixed time (30ms or so)

Measure mean delay between devices and start master device after timeout

I also thought about Atomic Clock API but I find it to be an overkill.

Any ideas?

答:
There will definitely have to be some sort of mutual delay measurement going on as part of any robust solution. You can also never get perfect synchronization, since clocks can drift apart in addition to starting off slow or fast, and the network performance may be schizophrenic enough to defeat any precise measurement, so aim for a margin of error like 100ms or 50ms.

Some things I can think of which might help:

Send timestamps with each packet. The devices' clocks won't be in perfect sync, but knowing when the other device thinks everything happened can make it easier to work out the mean delay.

Designate one device to be the "authoritative server" with regards to metronome status, and have the two devices continue pinging each other after initial sync so the "client"  device can correct itself if it drifts away over time.

Have both devices measure the mean delay, then check if they agree with each other, then have them "test" that value by sending a start signal and checking if they receive pings from each other at the times and with the timestamps they were expecting.

Try asking an external source for the time, hoping the delay from it to both devices will be similar. This StackOverflow thread suggests GPS and NIST.

The "correct" answer will have to be determined through experimentation. Depending on the nature of your app, you may even want some "manual sync" options for when the network just isn't cooperating.


答:
Black-box testing means that the tester is not familiar with the inner workings of the system, while white-box testing is performed by someone who knows exactly how the program works. Both has advantages and disadvantages.

Functional testing is testing whether or not the software product fulfills functional requirements, like "when loading an incorrectly formated file the program must output an error message" or "when clicking on the X, the program must close". The results of such tests are a binary "works" or "does not work".

Usability, however, is difficult to describe with functional requirements. It is hard to tell in advance if a certain user-interface would be easy to use or not. You have to build it, let people test it, and listen to their subjective feedback. What might be easy to use for one tester might be hard to use for another. That means a simple "is usable" or "is not usable" distinction is not useful in this case. The test results will usually be a lot more free-form and open to interpretation.

Also, usability testing is not useful to systematically find defects like functional testing does, because usability testers are encouraged to use the product how they would use it in the real-world and not intentionally try to perform irrational actions trying to break it. It's not like usability testers are discouraged from filing bug reports when they stumble upon any obvious bugs (they do affect usability, after all), but that's not their primary concern. They are also not expected to file bugs when the product does not behave according to the functional requirements, but the result is actually preferable.

Title: What is Black Box Testing? Are Functional and Usability Testing its types?

Body:
I am writing about testing and I am confused about the following:

What exactly is Black-Box testing?

Are functional testing and Usability testing two different types of testing and are they types of Black Box testing?

I have to perform two different types of testing procedures. Is it ok if I do functional and Usability testing?


答:
White-box and black-box testing are kinds of automated tests, that can be run by a computer and produce a pass or fail result. White-box means tests that require you to "see inside the box" and know how it works (I believe regression tests and boundary tests often count), while black-box means you are testing the external interface without knowing any of the internal details.

Usability testing is NOT automated in any way, since it involves finding a human to try using your program, and watching what happens. This sort of testing usually outputs results like "the user didn't realize this icon meant..." or "only expert users realized that...". You could call it "black-box" in the sense that your test subject doesn't know the code, but that's a little like arguing C++ is a "dynamic" language because it has polymorphism; that's just not the way that word is normally used in my experience.

Functional testing is may or may not be automated, since it's a much vaguer term which simply means testing "Does the software do X when I do Y?" If it's done with automated tests, those automated tests are probably of the black-box variety. If not, it's probably done by a QA team going off a "test script" written in English (which, again, you could call "black-box" testing, but you normally don't).

As is often the case with testing, you want to do at least some of all of these kinds. If for some bizarre reason you really do have to choose exactly two kinds, I would go with usability testing and any kind of automated testing.


答:
Perfection isn't possible. But you can probably get pretty close basing your synchronization on ntp's time synchronization strategy.

Basically, you can designate a master, have the client send a packet, including send time, have the server copy that to a response packet, also recording it's receive time, and time of response. The client issues sync requests until it's satisfied that it's seeing reasonably consistent latency measures, and then adjusts its clock.

More or less.

And then it's just a matter of having one or the other take responsibility for setting start and stop times. And deciding how critical it is that the other app not miss the first beat. (Versus delaying start time to account for network congestion.) E.g., start 70bpm, effective at time. If time is in the past when the slave receives the message, just compute the rate and when the next beat must occur.

Title: Perfect time synchonization betweeen devices

Body:
I want to make two devices synchronize metronome over bluetooth/wifi.
However I've got no idea how to make it perfectly synchronized.
There are two possible solutions that I've found out:

Naive -> Send start command to other device then start metronome after fixed time (30ms or so)

Measure mean delay between devices and start master device after timeout

I also thought about Atomic Clock API but I find it to be an overkill.

Any ideas?


问:
Requirements Gathering in SCRUM. Acceptable to talk about High Level requirements in first sprint?
In Scrum at what stage the requirements are gathered?

I am writing a report about my project but I am having trouble deciding where to put the High Level requirements.

I am thinking of having a section called Sprint 0. Where I have sub headings

Analysis

Design

Implementation

Testing

Evaluation

and in the analysis I talk about all the requirements gathered so far meaning an overview of what the system must do.

The other option is to have a section called product backlog where I analyse the problem and write the requirements that were gathered in the meeting with the client.

What is the ideal approach to this?

答:
In Scrum, requirements go in user stories.  The product owner is responsible for talking to all of the stakeholders and gathering requirements.  There is generally no single requirements document at all, nor any overall project report similar to what you describe.

A user story will describe the requirement at the highest level with a single feature with a regularized format.  "As a $X I want to $Y so I can $Z".  For example:

"As a legally-blind user I can magnify my screen so I can see small
  screen elements"

That's the high level description that goes on your sticky notes (physical, or metaphorical in a tool like Rally.)  After this, you would generally put more detailed descriptions and then finally the "Acceptance Criteria".  The Acceptance Criteria are the actual concrete requirements.  Usually I write this as a bulleted list and these are the things that must be true for the store to be considered complete.

In theory with agile, you don't create reports with "what the system must do".  Instead, you, as the Product Owner, take all stories and put them in priority.  Then, when the sprint starts, the team will point those stories, and take the ones into the sprint that will fit and work at them.

At the end of the sprint, you show the stakeholders what is done, write any new stories that need to be written and repeat.  You release to the public whenever the stakeholders think the software is ready to release.

It is perfectly fine for stakeholders to say they need a certain set of things to release, but that just means those things are on the stake.  The whole point of Agile is that these things can be changed during the process, between sprints.  That means that talking too much about the final project goes against the grain of what Agile as about.  As such, a report you are describing isn't something that would ever been done on an Agile project.

I am product owner a team using Scrum, and what our long-term documents look like are generally lists of stories I describe.  There has never been a single document describing design.  Instead, we have various places where stakeholders list the features they want to see in the next release in both our PM software and a wiki-like system.  These are living documents, often changing up to a sprint before the release.

As a product owner, I am always gathering requirements.  The point of Agile and Scrum is that requirements change.  If you collect requirements at a particular "stage" your requirements will be stale when you release, and it therefore won't meet the needs of the stakeholders.

To summarize, in Scrum:

There is no single document describing the project written at the start.

There are many living documents encapsulating the current requirements

There is no particular stage when requirements are gathered

Requirements are always being gathered for the next sprint's planning

You won't know for sure what the actual requirements to release are until the point where the stake holders say the software is good to release


问:
Is it good practise to have the class name as a prefix in Django model?
I wrote a model in this format in Django:

```<code>class Block(models.Model):
    block_id = models.AutoField(primary_key=True)
    block_name = models.CharField(max_length=200)
    block_code = models.CharField(max_length=200)
    block_content = models.CharField(max_length=200)
    block_change_date = models.DateTimeField(auto_now=True, default=datetime.now())
    block_published_date = models.DateTimeField(auto_now_add=True, default=datetime.now())
</code>```

Is this a useful practise to have block_ (or whatever other model name) for each or does it just add length to the field names?

答:
No, it's not.

Think about it, where would you ever need them?

Not when you create the model: you know what model are you creating.

Not inside the model itself: you know where you are too.

Nor when accessing the model later: you still know the type of the model, unless you don't care about the type, in which case prefixes will be only an annoyance.

Imagine a model such as:

class Person(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)
```

<p>Would <code>person.person_first_name</code> make more sense than <code>person.first_name</code>? Would <code>Person</code> ever contain a <code>first_name</code> which is not the first name of the person, so that you'll end up for example with:</p>

<pre class="lang-python prettyprint-override"><code>class Person(models.Model):
    person_first_name = models.CharField(max_length=30)
    person_last_name = models.CharField(max_length=30)
    persons_husband_first_name = models.CharField(max_length=30)
    persons_first_child_first_name = models.CharField(max_length=30)
    persons_pet_first_name = models.CharField(max_length=30)
    administrator_first_name = models.CharField(max_length=30)
</code>```

You might have already seen such code, but code like this is indicative of a complete misunderstanding of OOP by the author.

Another aspect to consider is inheritance. You may have:

class Person(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)

class Employee(Person):
    pass

class Freelancer(Person):
    pass
```

Following the convention where model members are prefixed with the class name, you'll end up expecting employee.employee_first_name, but finding employee.person_first_name, which is counter-intuitive. If you start overriding members, things become even messier.

Finally, if you need a more authoritative source, more specific to Django models, look at documentation. The example above is copied from it. You'll see that other examples don't have such prefixes either.

Body:
No, it's not.

Think about it, where would you ever need them?

Not when you create the model: you know what model are you creating.

Not inside the model itself: you know where you are too.

Nor when accessing the model later: you still know the type of the model, unless you don't care about the type, in which case prefixes will be only an annoyance.

Imagine a model such as:

class Person(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)

Would person.person_first_name make more sense than person.first_name? Would Person ever contain a first_name which is not the first name of the person, so that you'll end up for example with:

class Person(models.Model):
    person_first_name = models.CharField(max_length=30)
    person_last_name = models.CharField(max_length=30)
    persons_husband_first_name = models.CharField(max_length=30)
    persons_first_child_first_name = models.CharField(max_length=30)
    persons_pet_first_name = models.CharField(max_length=30)
    administrator_first_name = models.CharField(max_length=30)

You might have already seen such code, but code like this is indicative of a complete misunderstanding of OOP by the author.

Another aspect to consider is inheritance. You may have:

class Person(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)

class Employee(Person):
    pass

class Freelancer(Person):
    pass

Following the convention where model members are prefixed with the class name, you'll end up expecting employee.employee_first_name, but finding employee.person_first_name, which is counter-intuitive. If you start overriding members, things become even messier.

Finally, if you need a more authoritative source, more specific to Django models, look at documentation. The example above is copied from it. You'll see that other examples don't have such prefixes either.


问:
Is there a standard terminology for a class that actually does all the heavy work to create a dumb (immutable) related class?
Say that creating/calculating all the properties of fruit needs a lot of logic, and you just want to have a very simple immutable POCO object in the end.

So i.e. it doesn't have any methods, making it really easy to reason about, and also easily and clearly serializable.

Right now I have something names like this:

```<code>class BananaCalulator { public Banana Calculate() }
class Banana {}
class AppleCalulator { public Apple Calculate() }
class Apple {}
</code>```

Is this a common pattern? Is there a more common terminology instead of Calculator?

答:
The Gang of Four knows two patterns which describe objects which do nothing but create other objects.

One is the Factory.

The other is the Builder.

The difference between the two is that a Factory receives all arguments with a single method-call and usually can be reused to create more objects of the same type, a Builder has a number of methods which define the properties of the created object until a build-method is called. The Builder is often (but not necessarily) not reusable afterwards.

```<code>BananaFactory factory = new BananaFactory();
Banana b1 = factory.createBanana(100, 200);
Banana b2 = factory.createBanana(110, 210);

BananaBuilder builder = new BananaBuilder();
builder.setLength(100);
builder.setWeight(200),
Banana b3 = builder.build();
</code>```

Body:
The Gang of Four knows two patterns which describe objects which do nothing but create other objects.

One is the Factory.

The other is the Builder.

The difference between the two is that a Factory receives all arguments with a single method-call and usually can be reused to create more objects of the same type, a Builder has a number of methods which define the properties of the created object until a build-method is called. The Builder is often (but not necessarily) not reusable afterwards.

BananaFactory factory = new BananaFactory();
Banana b1 = factory.createBanana(100, 200);
Banana b2 = factory.createBanana(110, 210);

BananaBuilder builder = new BananaBuilder();
builder.setLength(100);
builder.setWeight(200),
Banana b3 = builder.build();


问:
What is a good speed for a webscraper?
I'm currently working on a webscraper that is going to be processing about 2 million pages in total. But I'm not entirely sure how to benchmark it.

Currently it processes about 100,000 pages in an hour at about 2mb/s.
It isn't saturating the the bandwidth of the server but I've tried a lot of ways to make it quicker but to no avail. CPU is running 50% or so on average.

答:
Seems like you need to go to the next level and do "Distributed" scraping.

You are going to need to build your application to be able to scale out to multiple servers.

The challenge will be somehow managing the the separate notes in your scraping "Grid".

You could look at centralised head server that dispatches work out to the nodes.

Other things to avoid would be two or more servers scraping the same site (this is duplication that is simply not needed).

OwnerDisplayName: Fredrik

ContentLicense: CC BY-SA 2.5

Title: What is a good speed for a webscraper?


问:
Better to write your .NET library with COM limitations in mind, or separate your .NET library from Interop?
I came across this interesting article: How I Came to Love COM Interoperability on CodeProject, which got me thinking...

The author argues that they do not want any COM-ities in their .NET library because it takes away from the beauty of their .NET library. Instead, they'd rather write a separate Interop library that exposes their .NET library to COM. This Interop library would handle the fact that COM doesn't support Constructors with Parameters, Overloaded Methods, Generics, Inheritance, Static Methods, etc.

And while I think that is very novel, doesn't it just complect the project?

Now you need to unit test your .NET library AND an Interop library.

Now you need to spend time figuring out how to work around your beautiful .NET library and expose it to COM.

You need to, effectively, double or triple your class count.

I can certainly understand if you need your library to support both COM and non-COM. However, if you only intend to use COM does this sort of design bring any benefits that I don't see? Do you only gain the benefits of the C# language?

Or, does it make versioning your library easier by providing you a wrapper? Does it make your Unit Tests run faster by not requiring the use of COM?

答:
However, if you only intend to use COM does this sort of design bring any benefits that I don't see?

This snippet of your question is the most important part of your design decision here, and the answer is (as always) it depends.

If you only intend to use the library via COM Interop, then you should design the entire system with this in mind. There is no reason to triple the line count. The more LoC in the system, the more defects it will have. You should therefore design your system to only use COM compatible functionality.

However, I can't think of a good reason to restrict the use of a .Net library to COM. Why wouldn't you want to be able to use the assembly in other .Net code? It makes little sense to limit yourself this way.

I have some experience with this, so I will share how I have handled it. Its certainly not ideal. I have made some trade offs. I only use a facade for COM classes (interfaces really) that are incompatible with the newer .Net idioms, otherwise, I directly expose the .Net interface to COM. This basically means that I use a facade for any interface that uses generics. Generics are the only thing I've come across that are just simply incompatible. Unfortunately, this means a facade for anything that returns an IEnumerable<T>, which is fairly common.

However, this isn't nearly as bad as it seems to be, because your facade class inherits from your .Net class and implements a specific Interop interface. Something like this.

```<code>namespace Company.Product.Feature
{
    public class MyClass : INetInterface
    {
        // lots of code
    }
}

namespace Company.Product.Interop
{
    public class MyClass : Feature.MyClass, IComInterface
    {
        // over ride only the  incompatible properties/methods
    }
}
</code>```

This keeps your duplicate code to an absolute minimum and protects your COM interface from "unintentional" changes. As your core class/interface change, your adapter class has to over ride more methods (or break the interface and bump the major version number). On the other hand, not all of your Interop code is stored in the Interop namespace, which can lead to a confusing file organization. Like I said, it's a trade off.

For a full blown example of this, you can browse through the SourceControl and Interop folders of my repo. ISourceControlProvider and GitProvider will be of particular interest.

Body:
However, if you only intend to use COM does this sort of design bring any benefits that I don't see?

This snippet of your question is the most important part of your design decision here, and the answer is (as always) it depends.

If you only intend to use the library via COM Interop, then you should design the entire system with this in mind. There is no reason to triple the line count. The more LoC in the system, the more defects it will have. You should therefore design your system to only use COM compatible functionality.

However, I can't think of a good reason to restrict the use of a .Net library to COM. Why wouldn't you want to be able to use the assembly in other .Net code? It makes little sense to limit yourself this way.

I have some experience with this, so I will share how I have handled it. Its certainly not ideal. I have made some trade offs. I only use a facade for COM classes (interfaces really) that are incompatible with the newer .Net idioms, otherwise, I directly expose the .Net interface to COM. This basically means that I use a facade for any interface that uses generics. Generics are the only thing I've come across that are just simply incompatible. Unfortunately, this means a facade for anything that returns an IEnumerable<T>, which is fairly common.

However, this isn't nearly as bad as it seems to be, because your facade class inherits from your .Net class and implements a specific Interop interface. Something like this.

namespace Company.Product.Feature
{
    public class MyClass : INetInterface
    {
        // lots of code
    }
}

namespace Company.Product.Interop
{
    public class MyClass : Feature.MyClass, IComInterface
    {
        // over ride only the  incompatible properties/methods
    }
}

This keeps your duplicate code to an absolute minimum and protects your COM interface from "unintentional" changes. As your core class/interface change, your adapter class has to over ride more methods (or break the interface and bump the major version number). On the other hand, not all of your Interop code is stored in the Interop namespace, which can lead to a confusing file organization. Like I said, it's a trade off.

For a full blown example of this, you can browse through the SourceControl and Interop folders of my repo. ISourceControlProvider and GitProvider will be of particular interest.


问:
Reading Element Names vs Reading Element Attributes: Speed
I am working on a project where there are a whole bunch of strings being stored in an XML file for later retrieval. Stored with each string are between 0-10 tags that a user can use to access and sort these strings.

The general use case that I am working towards is the user entering a "to find" tag and the app using the XMLREADER functionality to run through and identify all those strings with matching tags.

My Question: as I design the XML Schema, are there any known performance differences between reading an Element's name vs its attribute? For example if I design my Schema like this:

<requirement>
  <string>Here is the string text</string>
  <tags>
    <tag id='technology' />
    <tag id='users' />
  </tags>
</requirement>
```

<p>versus</p>

<pre class="lang-xml prettyprint-override"><code><requirement>
  <string>Here is the string text</string>
  <tags>
    <technology />
    <users />
  </tags>
</requirement>
</code>```

And I am scanning through looking for all matching "technology" tags. Based on how the XMLREADER class works in C# is one going to give me a significant performance benefit over the other (all other variables being equal)?

答:
In the first case, you'll have to either create a lookup or to loop through the tags to find a specific tag. In the second case, .NET Framework does that for you when processing the XML file.

For instance, if you want to find multiple times (and by multiple, I mean a lot) whether a requirement has a specific tag, the second case usage will be straightforward; the first one will require additional work of creating the lookup in the first place.

Of course, the difference in performance will start to be noticeable when you work with hundreds of thousands of requirements, containing each hundreds of thousands of tags. At this scale, you'll be able to implement both solutions, do the benchmarks and determine which one is faster, eventually profiling both and removing the bottlenecks before choosing the one you want to keep.

Until then, what you are doing is premature optimization. Based on speculative assertions, you'll probably end up writing more code and making it difficult to read and maintain, in the name of a few microseconds of runtime eventually saved (but never actually measured).

The reasons to chose the XML structure is usually based on how well this structure represents the data. In your case, both are quite representative, since in both cases, we understand well that a requirement contains tags technology and users. As for the tools, most will be able to handle both equally well. Think about using XSLT to get a list of tags, or CSS to style tags on a page: you can do it in both cases easily.

One benefit of the first approach may be when used with statically-typed languages. But even then, most frameworks will let you manipulate the second structure without having to use Reflection.


问:
How to perform MoSCoW prioritization in Scrum?
In Scrum, if the requirements are gather throughout the software development life cycle (SDLC), then when and how can you perform MoSCoW prioritization?</p>

答:
Scrum asks for an ordered backlog, not just a prioritized one.

MoSCow can help you to do a course grain prioritization, but you need an ordering for a Scrum backlog. You could use MoSCoW to help you define an MVP but you will ultimately need to sort your backlog as Scrum would suggest.

Using MoSCoW long term in Scrum doesn't make sense because the scope is constantly adjusted. For example, yesterday's shoulds will become today's musts.

How you define the categories/prioritization levels is difficult; you don't truly know what a must actually is until you try it on your customer.


问:
Advice for volunteer developers learning large codebases
Working in an open source project has the result that sometimes developers with no experience in the codebase attempt to "learn the code" on their own.

There is a reccurring trap I've seen, where new developers try to:

understand everything before doing anything.

These tend to be developers who only ever worked on their own projects, or at least smaller codebases, where this may work out OK.

My impression is that they try to read the code a bit like it's a book, hoping that somewhere near the end they will have an "ahah" moment where they will understand it and start writing new code and being productive.

(I'm simplifying a bit here).

This always seems to end badly.

Rather than questioning their approach, they complain the code is confusing and needs more comments.
(Whether or not to include comments is a big topic. For purpose of discussion we can assume the code is reasonably well-commented.)

Not to suggest the code is perfect either, but some developers manage to learn it and become productive.

To me the approach is flawed to begin with, but asking since this is such a common assumption/mistake.

When developers have already tried and failed to enter a large codebase by reading over the code:

What are some better alternative approaches to suggest?

Note on the "volunteers for open source" aspect (added for clarification)

It's come up in replies to this topic that the part about volunteers isn't important and that any new developer on a large codebase would run into these problems.

While this may be true in some cases, there is a difference that volunteers aren't employed by the organization, they can do what they like, how they like - and may do a significant amount of work on their own without asking for guidance, further, they are free to ignore all advice too. Even if their work is rejected for example, they may continue to develop it, start a fork etc....

This typically isn't the case a developer employed to work on closed source software.

答:
After writing the original version of this answer (see remark below), I came to the realization that instead of analyzing the mental gap present in new developers, I should have instead explored what is the single most important thing that new developers need to do to close the mental gap. Here is my assertion.

The best thing new developers in this situation can do, is to receive a comprehensive training on using every piece and bit of functionality that this software has to offer.

Assuming the new developer has no obvious adequacy in understanding code, what other inadequacy may that person has? It is the user's perspective that the new developer is lacking.

Put in another way. Suppose the new developer need to somehow "cause a certain specific piece of code inside the library to be executed". No matter what. How does the developer do that? To do this-and-that on the application, which internally triggers this-and-that piece of code.

This is the up-to-date onboarding principle in quite some leading software companies. In fact, anyone reading "trendy" industry websites should have had mentioned this approach. There is nothing remarkable or ingenious about that. It's just hindsight.

Bonus: an analogy.

To help hit the nail on the head, here is one:

How do you learn to write a novel? Do you begin by memorizing the dictionary?

Trying to read and fully understand the source code is somewhat like learning vocabulary with the help of the dictionary. However, without actually using the newly learned vocabulary, the meaning and definitions probably meant very little to you, and your command of those words will soon fade away.

To truly learn something, one has to learn it from the various perspectives according to how it is used by the people.

To a lesser extent, being able to execute a single modularized piece of code taken out of the library in a test environment is also a bonus. It helps a new developer affirm one's understanding about how that piece of code execute.

This need is partially fulfilled by having a unit testing suite. However, it should be pointed out that a new developer will also need a "messy experimentation environment" for testing out both production-ready and novel code. Thus, the new developer will typically need both.

Below is my earlier answer (now deprecated), kept here for reference.

Overall view

When discussing about this issue, one must make distinction between amateur-usage and production-usage of an open-source library.

The distinction does not lie in whether the programmer-user is hired, paid or making revenue.

The distinction lies in: Whether the programmer-user are intimately aware of tens or hundreds of different use cases that the library is currently capable of.

The problem is that if the programmer-user lacks awareness, the contributed code changes are quite likely to be rejected for being inadequate in handling.

Any failure of even a single use case, caused by any code change, is called a "regression".

This is discouraging, but shouldn't be seen as a signal to discourage or stop one from learning. One must accept the learning curve and press on.

Opportunities to contributed locally-scoped or modular changes

Sometimes, it is possible to identify some locally-scoped improvements in an open-source library. Small enough that one does not need the aforementioned broad awareness to being working on.

Sometimes, some libraries are designed (architecturally) in a way that new functionality can be "bolted on" elegantly. If that functionality succumbs to quality issues, it is trivial to be taken out by its maintainers.

When those opportunities arise, it would be possible for new programmers to contribute.

Identifying such opportunities is not easy task. Sometimes, it takes an expert member of the maintainers to do it.

The whole premise of, say, Google Summer of Code (GSoC), as well as similar initiatives from other companies or organizations, is based on having an army of mentors (the expert members among maintainers) to identify such opportunities, and for the financial sponsor (Google) to reimburse both the mentors and the fresh programmers in education to work together.

Opportunities that arise due to a "bullet-tracing" event

This situation is actually the most common in the commercial-usage of open-source libraries.

A software company makes use of open-source libraries for production purposes (those that are revenue-generating, or necessary for the company or organization's day-to-day operations).

One day, a programmer identifies a defect in the library. The programmer has professional knowledge in the trade, and has been making knowledge gains on that library due to the everyday usage of that library.

The programmer conducts an intense effort (in terms of time, money as in wages, technical support contacts, and bug tracking database searches) to identify the root cause of the defect, and to try to come up with an acceptable code fix for that.

Now, because of this intensive collaborative effort, the programmer may be able to make a contribution to this open-source library, despite not being well aware of other unrelated aspects of the library's functionality or use cases.

Thus, this is an exception to the overall view mentioned in the beginning.

"Handholding", "onboarding", and other activities that can bring new developers up to speed.

Handholding refers to project mentors patiently giving (sometimes prescribing, or even spoon-feeding) baby-steps to a programming-person who is completely new to the library, or about the application domain.

Onboarding refers to giving someone an organization overview of the library, assuming that:

The person has some knowledge of the application domain, and is capable of learning more of it on one's own effort

The person has some knowledge of the software architecture, and is capable of learning more of it

The person already has good programming skills and do not need any handholding in that aspect.

The person will being using that library everyday, therefore it is expected that learning progress will be fast.

In a commercial setting, only programmers who are eligible for "onboarding" will be given consideration for joining a software project. Programmers who need "handholding" will never be given a chance.

The caveat: Most library's developer documentation is written for adequate onboarding, but not for handholding.

An example of handholding documentation is:

OpenCV Tutorials

HIPR2 - Image Processing Learning Resources,
though this is not a software library but rather an educational material.

Compare that to the onboarding documentation of comparable libraries:

OpenCV - How to contribute

The reality is that: unless your library has become so prominently featured in the STEM education as part of the national STEM initiative, it is unlikely that many many books and beginner tutorials will be developed for it.

Search for "OpenCV" on Amazon

Similar can be said of: MATLAB, R, Octave, etc. (Though MATLAB is a proprietary software package, and thus one would not find open-source contribution opportunities there.)

Doctrine (organization of software projects), and indoctrination.

It appears that traditional open-source libraries (those that began their roots in the 1990s or earlier) do not use handholding or onboarding. Instead, they maintain an authoritative document saying what the library should do.

I call this indoctrination. Neither the library code nor the maintainers are perfect; but everything is moving towards perfection according to the doctrine.

Examples of open-source library "doctrines":

zlib

libtiff

This is jokingly referred to as "RTFM" (*), but amid the hundreds of pages of documentation, most open-source libraries will have a single prominently featured page of inerrancy. Sometimes it is simply called "README" (without a file extension) at the root of the package. This is the doctrine of that library.

It specifies a lot of "specification" or "behavior contract" for the library.

(Note) For decency, let's say RTFM is an acronym for "read the founders' manuscripts."

A final irrelevant rant - to any online people elsewhere who said college doesn't seem that critically important.

The economic importance of a proper college education should become apparent, if one manages to read through all of the above.

It saves a fresh graduate from being in need of handholding for an opportunity, period.

Otherwise, the fresh graduate would have trouble finding the first employment.

Mandatory disclaimer: not directly employed by any companies named above.


问:
What algorithm can I use to find the biggest subarray within a 2d array with only n different numbers?
Let's say I have a 2d array 100x100 in size, each cell in that array has a number from 1 to 50 randomly.

How do I find the biggest subarray in a rectangle size in that array that has only n different numbers?

Small example:

```<code>array: 1 2 3 3 3 2 2
       7 4 3 3 4 9 8
       1 2 3 3 3 4 2
       7 6 1 9 9 4 2
In this case the biggest sub rectangle with only 1 number allowed would be
       3 3
       3 3
With 2 numbers allowed it would be
       3 3 3
       3 3 4
       3 3 3
</code>```

Does something for this exist?

答:
If the array has a size of n x m, then there are roughly n^2 m^2 / 4 subarrays. If there are k different values, then we can represent each as a bit array with k bits. This takes for example k' := ceil (k / 64) 64 bit words.

It's quite easy to calculate each of the sets of values for n^2 m^2 / 4 subarray in a total of n^2 m^2 k' / 4 steps. The number of bits can be counted in log2 (k) steps, so we have a total of n^2 m^2 k' log2 (k) / 4 operations. In this case, 10,000 * 10,000 * 1 * 6 / 4 = 150 million steps. So no big deal. It gets more interesting if the values are larger.

However, this brute force search would be quite inefficient in this case (where each cell contains a random number). We can reasonably easy calculate the probabibility that a rectangle of n numbers contains k or fewer different numbers, and that probability will go down rapidly if n gets larger than k. So we would want to avoid checking really large rectangles. Here's how I would suggest to proceed, for an array of n rows and m columns, looking for the largest rectangle with at most k different numbers:

We handle trivial cases: k ≤ 0 means no solution, k ≥ number of different numbers means (1:n, 1:m) is the solution. Then find the largest trivial solution, which is just the largest rectangle with an area ≤ k. (For example, if the array is 5x5 and k = 7, we can trivially find a rectangle of size 6 but not of size 7). Let the size of the rectangle be s ≤ k. Let maxc (r) = "largest c where we haven't proved that a rectangle with r rows and c columns and less than k different numbers cannot exist".

Given a record s, we then need to find a rectangle which is larger or prove that it doesn't exist. We find a pair (r, c) with the smallest product rc such that c ≤ maxc (r) and rc > s. If such a pair doesn't exist then we have the optimal solution. Otherwise, we look for a rectangle of size r x c with k or fewer different numbers. If none is found, then we set maxc (i) = min (maxc (i), c - 1) for all i ≥ r (there cannot be a rectangle with r rows or more, and with c-1 columns or more) and try again. If a rectangle is found, then we record it, increase s, and also try again.


答:
From my experience diving into large, unfamiliar code bases, I would say the key thing is to understand how the program is split up, and then focus only on the piece you're changing. This is just as true of codebases I work on every day as it is of codebases I've never seen before.

If the program is well-designed, the modules/components/pieces/whatever will have clear boundaries between them, and clear black-box expectations for each other's behavior, which make it very easy to work within one of them with little to no detailed knowledge of the others. Even programs with questionable design usually have plenty of modularization, but merely fail to make it obvious where the boundaries between modules are (typically through what you might call "excess coupling"). If for some bizarre reason nobody can tell the new guy how the program is organized, he may be able to very slowly piece it together by looking at main() or stepping through things with a debugger, while resisting the temptation to dig too deep into any one function or class.

The new developer instinct that they must "understand everything before doing anything" is actually true within a single module. For someone relatively new, an appropriate "module" may be a single .cpp file implementing one class, or it might be 5-10 files implementing some thread pool scheduling black magic. It's only the "cross-cutting changes" affecting several modules that truly need someone familiar with the whole codebase.

Edit: ideasman42 has clarified that "volunteer"ness is relevant to the question because volunteers on open-source projects don't get tutorials/walkthroughs like employees normally do. To that, I would say: If it's a remotely decent open-source project, there should be lots of public, browsable discussions about past and present issues which ought to provide lots of high-level insight into how the code is structured (and why it's structured that particular way). Platforms like Github make this exceptionally straightforward.

Title: Advice for volunteer developers learning large codebases

Body:
Working in an open source project has the result that sometimes developers with no experience in the codebase attempt to "learn the code" on their own.

There is a reccurring trap I've seen, where new developers try to:

understand everything before doing anything.

These tend to be developers who only ever worked on their own projects, or at least smaller codebases, where this may work out OK.

My impression is that they try to read the code a bit like it's a book, hoping that somewhere near the end they will have an "ahah" moment where they will understand it and start writing new code and being productive.

(I'm simplifying a bit here).

This always seems to end badly.

Rather than questioning their approach, they complain the code is confusing and needs more comments.
(Whether or not to include comments is a big topic. For purpose of discussion we can assume the code is reasonably well-commented.)

Not to suggest the code is perfect either, but some developers manage to learn it and become productive.

To me the approach is flawed to begin with, but asking since this is such a common assumption/mistake.

When developers have already tried and failed to enter a large codebase by reading over the code:

What are some better alternative approaches to suggest?

Note on the "volunteers for open source" aspect (added for clarification)

It's come up in replies to this topic that the part about volunteers isn't important and that any new developer on a large codebase would run into these problems.

While this may be true in some cases, there is a difference that volunteers aren't employed by the organization, they can do what they like, how they like - and may do a significant amount of work on their own without asking for guidance, further, they are free to ignore all advice too. Even if their work is rejected for example, they may continue to develop it, start a fork etc....

This typically isn't the case a developer employed to work on closed source software.


问:
User sessions in a web server; speed or persistence?
I'm looking to implement sessions for a web server that I'm developing in my free time. Currently, it had cookie support, so users could implement their own session management, but this is something that should be handled by the web server. I'm faced with two secure options:

Store it in memory, and expire the session if the user does not make a request over a certain amount of time. This has the advantage of speed; accessing the memory is fast. It's also easier to implement, but this is a non-concern.

or

Store it in a database of some sort, and expire the session if the last_access time is over a certain amount of time. This has the advantage of persistence; a server shutdown, restart, etc. will not impact this. It would also be possible to use a database on another server for this purpose, allowing multiple servers to share sessions (e.g. for load balancing).

I'm trying to decide whether keeping sessions over a restart or shutdown is important enough to sacrifice the speed of storing it in memory, or whether I should simply cache sessions and store them in a database of some sort as a "backup", e.g. in the event of a crash or a restart, I would restore sessions (if they're not expired) from the database. Edit: This is in a single-threaded environment. It's not an option to multithread it.

From the perspective of the user of the web server, which is more important? Speed, or persistence?

答:
Why not both?

I suppose you want a quick turnaround, without waiting for the session to get stored in the database. But this does not prevent you from putting the data into the database eventually, because probably users do not register a new session at every request for prolonged periods.

I'd have an in-memory cache of a limited size, a queue, and a database. When a new session is registered, it stays in the cache and is put into the queue. A background thread keeps reading the queue and putting the new sessions into the database. (Another background process would periodically expire them.)

Session creation and reuse stays instant: immediately following requests find the session in the cache and don't hit the database at all. Requests for the same session a week later probably will not find it in the cache, and will hit the database once, populating the cache.

Of course it is possible to overpower this scheme by registering so many sessions so fast that most requests will be unable to find recently-created sessions in the cache, and won't find the data in the database, because the database will not keep up with the queue. But without the cache + queue, even a smaller amount of request would kneel the server.


问:
No exceptions C++ and partially constructed objects
Looking over Joint Strike Fighter Air Vehicle C++ Coding Standard, rule AV 73 states something on the lines: Default c++ constructors should be avoided if that means leaving object in a partially constructed place. This is obvious a good advice but things get complicated when you also disallow exceptions (as it does)

I wonder if they also try to give something else in return to make it practical. E.g. following example needs 2 faze construction if OUT_OF_MEMORY has to be handled (but the problem is more general of course)

```<code>class A {
    A() = default; // no way to report construction of B and C
    int Init(); // allocation failure of B/C can be reported only here
    private:
    B* b;
    C* c
}
</code>```

One way to handle the problem is to have a A* Create() static member but in this case A has to free store allocated or keep an non-fully initialized state inside A and check it inside every member access, which seems not better at all than using a C style

```<code>int Initialize(A& out) // stack allocation
int Initialize(unique_ptr<A>& out) // free store allocation
</code>```

EDIT I posted one possible approach bellow also. I took under consideration that dynamic memory allocation is necessary and the fact that any errors can happen while fully constructing an object. This is a scenario that is plausible for any driver development work.

答:
Mandatory disclaimers

(1) Because people who have seen the code can't say anything about it, and people who can freely comment on it have never seen the actual code, all we can do here is to speculate, speculate, and to speculate. Therefore, here is not an answer, just a speculation.

(2) This is not the typical way I write C++ because most of the projects I work on allows exceptions, at least on a local basis (i.e. not crossing application boundaries), and the coding standard ensures that there are always appropriate exception catchers in the right place. This answer was written as if it is an interesting thought, not as a sharing of experience.

My opinion is that to avoid the issue of partially constructed object (or, "state"), one must first fundamentally change the way parameter (precondition) validation is performed.

The change is this: instead of validating and assigning parameters one-by-one, one must perform the complete validation of all parameters together, in a side-effect-free manner.

In addition to that change, the role of class constructor is also changed. Instead of handling both precondition validation and state initialization, it will "outsource" both to someone else; it will only retain the part of responsibilities that are "failproof" (not capable of failing).

For example, assigning a primitive value (e.g. integer) to a primitive variable is failproof, provided that the primitive variable has valid storage. Another example is the ownership-transfer of a pointer from one smart variable to another.

Some of the biggest advances of C++11 is that smart pointers (and many other things) are moving toward making at least some of the operations "failproof", by giving the option of isolating those "failable" (having the potential of failing) operations into separate methods.

Ultimately, however I must say, the "no exceptions" rule is sometimes impractical for at least some types of application development. How else would one prevent std::bad_alloc without exceptions? Should the system crash-and-burn?

Mission-critical systems prevent out-of-memory issues by ensuring system-wide determinism in memory usage. Everything is preallocated; objects are merely placement-newed on allocators. There is a maximum number of instances prescribed for each type of objects; attempt to exceed the maximum will either be rejected, or result in the yanking of another less-important, not-actively-in-use object.

This, may be why we keep hearing those memes about "this enemy tracking system is capable of simultaneously tracking 256 different objects." When a 257th object wants to be added to the system, one of the least-important object must go. Since none of us commenting here have seen any of the code, this is just a speculation.


问:
Why are people making tables with divs?
In modern web development I'm coming across this pattern ever more often. It looks like this:

```<code><div class="table">
    <div class="row">
        <div class="cell"></div>
        <div class="cell"></div>
        <div class="cell"></div>
    </div>
</div>
</code>```

And in CSS there is something like:

```<code>.table { display: table; }
.row { display: table-row; }
.cell { display: table-cell; }
</code>```

* (Class name are illustrative only; in real life those are normal class names reflecting what the element is about)

I even recently tried doing this myself because... you know, everyone's doing it.

But I still don't get it. Why are we doing this? If you need a table, then just make a blasted
 and be done with it. Yes, even if it's for layout. That's what tables are for - laying out stuff in tabular fashion.

The best explanation that I have is that by now everyone has heard the mantra of "don't use tables for layout", so they follow it blindly. But they still need a table for layout (because nothing else has the expanding capabilities of a table), so they make a
 (because it's not a table!) and then add CSS that makes it a table anyway.

For all the world this looks to me like putting arbitrary unnecessary obstacles in your way and then doing extra work to circumvent them.

The original argument for moving away from tables for layout was that it's hard to modify a tabular layout afterwards. But modifying a "faux-table" layout is just as hard, and for the same reasons. In fact, in practice modifying a layout is always hard, and it's almost never enough to just change the CSS, if you want to do something more serious than minor tweaks. You will need to understand and change HTML structure for serious design changes. And tables don't make the job any harder or easier than divs.

In fact, the only way I see that tables could make a layout difficult to modify, is if you abused them and created an ungodly mess. You can do that with divs too.

So... in an attempt to change this from a rant into a coherent question: what am I missing? What are the actual benefits of using a "faux-table" over a real one?

About the duplicate link: This isn't a suggestion to use another tag or something. This is a question about using a
 vs display:table.

答:
Use cases matter. There is a big difference between layout/presentation in a content page and in an application. In content, semantics matter a great deal for SEO-awareness and usability. In these cases, using tables to present tabular data is in general the right thing to do. As others have noted, search engines will penalize you and you may even run afoul of usability laws if you are required by statute to conform to govt usability guidelines.

In a web application, developers may opt to create entirely separate views for SEO and usability purposes. Responsive design has led people to build views that can handle desktop and mobile layouts, and divs are better than tables in those use cases.

Take ecommerce sites, for example. Viewing a list of products in a browse or search result shows, in general, a list of products in tabular format, but those views may well be generated using divs (which provide more generic and flexible layout and styling options) rather than tables. Amazon and eBay are good examples of this approach. Inspect a search result on either site and you will see a deeply nested set of divs.

Title: Why are people making tables with divs?


问:
What is proven as a good maximum length of a function?
Does function length affect the productivity of a programmer? If so, what is a good maximum number of lines to avoid productivity loss?

Since this is a highly opinionated topic please back up the claim with some data.

答:
The question should be how many things should a function do. And usually, it's rare that you need a 100 lines to do "one" thing. Again that depends on the level from which you are looking at the code: Is hashing a password one thing? Or is hashing and saving the password one thing?

I would say, start with saving password as one function. When you feel that hashing is different, and you refactor the code. I am no expert programmer by any means, but IMHO, the whole idea of functions begin small is that the more atomic your functions are, the higher the chance of code re-use, never having to make the same change in more than one place, etc.

I have seen SQL stored procedures that run over 1000 lines. Does the number of lines of stored procedures also be less than 50? I don't know, but it makes reading the code, hell. Not only do you have to keep scrolling up and down, you need to give a few lines of code a name like "this does validation1", "this updates in the database", etc. - a work that the programmer should have done.

ContentLicense: CC BY-SA 4.0


答: To improve performance and simulate multiple nodes with regardless of its XML size, you can use  XSLT with XML and then use xpath to retrieve nodes. This would be much better.</p>

Title: Reading Element Names vs Reading Element Attributes: Speed

Body:
I am working on a project where there are a whole bunch of strings being stored in an XML file for later retrieval. Stored with each string are between 0-10 tags that a user can use to access and sort these strings.

The general use case that I am working towards is the user entering a "to find" tag and the app using the XMLREADER functionality to run through and identify all those strings with matching tags.

My Question: as I design the XML Schema, are there any known performance differences between reading an Element's name vs its attribute? For example if I design my Schema like this:

<requirement>
  <string>Here is the string text</string>
  <tags>
    <tag id='technology' />
    <tag id='users' />
  </tags>
</requirement>
```

<p>versus</p>

<pre class="lang-xml prettyprint-override"><code><requirement>
  <string>Here is the string text</string>
  <tags>
    <technology />
    <users />
  </tags>
</requirement>
</code>```

And I am scanning through looking for all matching "technology" tags. Based on how the XMLREADER class works in C# is one going to give me a significant performance benefit over the other (all other variables being equal)?


问:
Client wants source code, but it contains a lot of shared code I reuse with other projects
I have a client who would like me to deliver the source code with a developed application binary. They originally said nothing about source code, but they recently said they need it. The contract is not finalized. They agreed to the work, did not sign, and then came back with this clause.

The issue is: I have a code base I've created over the years and used as a template for most of the applications I write. It is far larger than the scope of the project.

I also intend to use it for a product, so I really don't wish to provide it for a relatively small project.

I'm guessing this is not the first time that this has happened in this industry. What is the best way to circumvent this issue? I'm guessing things like shared libraries could help.

答:
The first thing to keep in mind is that source code has value separate from the binaries.  It is perfectly reasonable to either refuse to sign a contract that requires source code delivery, or to insist on extra payments for source code delivery.  Contracts are two-way documents.  Do not let the other part dictate what is required just because they are "big companies" and "do this all the time".  First, decide what you are willing to deliver and how you want to be compensated.  Then take their contract to a lawyer and work out what needs to change.  Then, you negotiate.

Don't do what a lot of young people do when they start contracting.  Don't just sign because it seems like they have lots of experience and you don't.  That's a good way to get ripped off.

Look into why they want the source.  They may want it so they have the option of using another developer later on.  Or they may want it just because they are afraid you might get hit by a bus and suddenly they'll be left with binaries that they cannot improve.  If it is this second case, look into a Software Code Escrow Service.  These services hold the source code in case you go bankrupt or otherwise are unable to maintain the software.  This may satisfy both your desire to keep your code proprietary to service other customers and their desire not to be left holding the bag with an unmaintainable set of binaries if something bad happens.


问:
More idiomatic syntax for 2nd level vector value update
I'm pretty sure there has to be a more idiomatic way of writing this:

```<code>(defn update-2nd-level-vector
  [map index value]
  (assoc map :key1 (assoc (get map :key1) :key2 (-> map (get-in [:key1 :key2]) (assoc index value)))))
</code>```

Example of its working:

```<code>=> (update-2nd-level-vector {:key1 {:key2 [0 1]}} 0 1)
{:key1 {:key2 [1 1]}}
</code>```

答:
you must use update-in..also your function is not enough flexible, you're restricted to use it only in maps with those keys..

this is a bit more practical

```<code>(defn update-level [keyspos mapp index value]
  (assoc-in mapp keyspos (assoc (get-in mapp keyspos) index value)))
</code>```

you can use it

```<code>(update-level [:key1 :key2] {:key1 {:key2 [0 1]}}  0 3)
</code>```

or similar to your function

```<code>(def update-2nd-level-vector2  (partial update-level [:key1 :key2]))

(update-2nd-level-vector2 {:key1 {:key2 [0 1]}} 0 3)
</code>```

Body:
you must use update-in..also your function is not enough flexible, you're restricted to use it only in maps with those keys..

this is a bit more practical

(defn update-level [keyspos mapp index value]
  (assoc-in mapp keyspos (assoc (get-in mapp keyspos) index value)))

you can use it

(update-level [:key1 :key2] {:key1 {:key2 [0 1]}}  0 3)

or similar to your function

(def update-2nd-level-vector2  (partial update-level [:key1 :key2]))

(update-2nd-level-vector2 {:key1 {:key2 [0 1]}} 0 3)


问:
Licensing of content created by licensed code
So I had been using trianglify, and I was thinking about using an image that it had created. Trianglify is licensed under GPLv3, however, (as I understand it,) it creates unique svg files. The author has not included any instructions as to how to source/license these images, so I was thinking about sourcing the image in my GitHub .readme file for my project.

My question is, would I have to also change the licensing of my code to be under the GPLv3 if I am only using an image derived from the licensed product? What should I do? I'm not using any of the code, just its (unique) product (an image). Or would this be on a case by case basis where I would have to contact the author (if so, for each usage or just once)?

答:
No a piece of work created by a GPL piece of software is not generally a derived work.

There are exeptions, where for example, the GPL app is a code generator which produces source code containing significant bits of the original app. But producing an image, or any other piece of creative work with a GPL tool is not itself GPL.


答:
The GPL describes rules about the use of the source code, not rules about the use of products of the application itself.  The most obvious example is the GNU compiler.  The compiler is released under the GPL.  It is perfectly fine to use that to compile programs that are not released under the GPL.  What you are restricted from is modifying the GNU compiler itself and not putting those modifications under the GPL.  Lots of very proprietary code is compiled with the GNU compiler.

This is generally true of most open source licenses, however, I suppose it might not be the case for every single one.  If you run into some weird license, read the license and perhaps consult a lawyer.  But for the GPL and trianglify, you would not be restricted from using generated svg files in any way.

That said, pointing to the code that generated the file in your own .readme is a nice thing to do, and has no real downsides, so you might as well do it.  But you aren't required to.

Title: Licensing of content created by licensed code

Body:
So I had been using trianglify, and I was thinking about using an image that it had created. Trianglify is licensed under GPLv3, however, (as I understand it,) it creates unique svg files. The author has not included any instructions as to how to source/license these images, so I was thinking about sourcing the image in my GitHub .readme file for my project.

My question is, would I have to also change the licensing of my code to be under the GPLv3 if I am only using an image derived from the licensed product? What should I do? I'm not using any of the code, just its (unique) product (an image). Or would this be on a case by case basis where I would have to contact the author (if so, for each usage or just once)?


答:
The way to deal with this is to negotiate.

If they want source code, then they should be prepared to pay for it, and it is up to you to decide how much that should be.

On the other hand ... if they are not prepared to pay what you want, they may decide to "take their business elsewhere".

Welcome to the world of business :-)

And when you talk to prospective customers in the future, be sure to mention this issue early on ... to avoid wasting everyones' time.

It is also worth noting that what you are doing is anathema for open source developers, and for (educated) customers who are looking for open source solutions.

Title: Client wants source code, but it contains a lot of shared code I reuse with other projects

Body:
I have a client who would like me to deliver the source code with a developed application binary. They originally said nothing about source code, but they recently said they need it. The contract is not finalized. They agreed to the work, did not sign, and then came back with this clause.

The issue is: I have a code base I've created over the years and used as a template for most of the applications I write. It is far larger than the scope of the project.

I also intend to use it for a product, so I really don't wish to provide it for a relatively small project.

I'm guessing this is not the first time that this has happened in this industry. What is the best way to circumvent this issue? I'm guessing things like shared libraries could help.


答:
Your question is, "what is the best way to circumvent this issue?" But what do you see as the issue? Others have correctly pointed out that it's a matter of negotiation: everything has a value, and it's up to you give the client a price for providing what's asked for.

But you must also carefully consider—and write into the contract—the implications of providing the code. Is it just so the client can see it? Can the client modify it? And in particular, would you consider giving your client exclusive rights to the code base you have created over the years and is used as a template for most applications so that you can never again use it yourself in the future?

You need to ensure the contract explicitly states who has rights to use the code, and in what ways.


答:
Remember that any source code requires a license. If you hand over source code, the company can use the source code to do anything that the license allows, and anything beyond that is copyright infringement. So if you hand over source code, you would have a contract that makes absolutely clear that you retain the exclusive copyright of the source code, and exactly what uses of the source code are allowed. And of course source code + license wouldn't come for free.

A major company would be unlikely to infringe your copyright, because being caught would cause a major damage to their reputation, apart from financial damage. On the other hand, paying out for software with no guarantee that any problems can be fixed in the future, might be unacceptable for the client.


问:
Line intersection detection algorithm
I'm trying to detect if a line drawn by the user intersects itself. I'm using a line intersection detection algorithm that goes through each waypoint of the line and checks if intersects with any other point in the line.

This is a costly method and has started to produce performance problems. What would be the recommended algorithm for this problem? Is there a code example of it?

The line is represented with wayPoints which are coordinates that have been gathered by users movement on screen.

Thanks a lot for just reading this far! All help Appreciated!

```<code>    for i in 1 ..<(wayPoints.count-1) {
            for j in 0 ..< i-1 {
                   if let intersection = intersectionBetweenSegments(wayPoints[i], wayPoints[i+1], wayPoints[j], wayPoints[j+1]){
  ...}
   }
  }

    func intersectionBetweenSegments(p0: CGPoint, _ p1: CGPoint, _ p2: CGPoint, _ p3: CGPoint) -> CGPoint? {
        var denominator = (p3.y - p2.y) * (p1.x - p0.x) - (p3.x - p2.x) * (p1.y - p0.y)
        var ua = (p3.x - p2.x) * (p0.y - p2.y) - (p3.y - p2.y) * (p0.x - p2.x)
        var ub = (p1.x - p0.x) * (p0.y - p2.y) - (p1.y - p0.y) * (p0.x - p2.x)
        if (denominator < 0) {
            ua = -ua; ub = -ub; denominator = -denominator
        }

        if ua >= 0.0 && ua <= denominator && ub >= 0.0 && ub <= denominator && denominator != 0 {
            return CGPoint(x: p0.x + ua / denominator * (p1.x - p0.x), y: p0.y + ua / denominator * (p1.y - p0.y))
        }

        return nil
    }
</code>```

答:
This is originally a comment seeking clarifications, but is too long to fit. So I posted each question here, along with my "what-if" answers for each question based on possible responses.

Before seeking clarifications, everyone should see that the current implementation has time complexity that is quadratic in the number of waypoints. The notation is O(N^2).

To put it simply, if the number of waypoints are doubled (increased to twice), the execution time will approximately be quadrupled (increased to fourfold).

(1) What is the typical number of waypoints you need to handle? If there is no typical number, state the maximum possible number of waypoints that your code needs to support.

For example, if you find that the performance issue do not occur when N (number of waypoints) is below several hundreds, you may impose a software restriction that the mouse movement cannot be longer than that number of pixels. Whether this is acceptable or not depends on your software's purpose.

(2) Are you allowed to use line simplification techniques to reduce the number of waypoints before checking for intersections?

Line simplification technique can cut down the number of waypoints by tenfold (one-tenth) or more (less), when mouse movement is used as input. The user will have to move the mouse very frantically to cause this reduction to fail.

(3) Do you know how to implement and use QuadTree by yourself?

A quadtree allows average case O(log N) query into a collection (tree) of bounding boxes that overlap with the query bounding box. To find all pairwise overlapping bounding boxes, one would first add all bounding boxes to it, and then make query on each bounding box. This gives a total that is average case O(N log N), which is better than the original implementation that is O(N^2).

(4) What is the width and height of the movement area, measured in pixels, that you need to support?

If total movement area (in squared pixels, that is, the product of width and height) is less than a few million, and if one is allowed to allocate an array that can hold a few million bytes (or bits - we only need each element to be true or false), then one can allocate such an array to act as a bitmap (literally a map of bits).

The bitmap will be initialized with false. Then, as the user "paints" with mouse movement, the corresponding pixels in the bitmap will be set to true.

Caveat. Note that if the user's pixel trail is only a single pixel (1 by 1) wide, the following edge case will happen:

Suppose the trace goes from (10, 10) to (11, 11). Later in the trace, it crosses that segment by going (10, 11) to (11, 10). Since the pixels themselves do not overlap, this bitmap-based scheme will fail to detect an intersection of this kind.

The solution to the caveat is that one has to check a 3-by-3 neighborhood for pixels that had been painted before. While doing this, one also has to remember to ignore pixels that have just been painted freshly. It is possible that one may have to use one byte per pixel (as opposed to one bit per pixel) in order to store additional information to help workaround this caveat.

Title: Line intersection detection algorithm


答:
"No" is a perfectly fine answer, actually it's an incredibly useful answer which for some reason I can't understand is very underrated.

"Hi, we have suddently decided we just want source code too, free of charge."

"Hi, no."

It's not that difficult, really.

Then, if they wish to pay egregious amounts of money over what they already owe you, you might give them a trimmed version of your application, which includes only the sources they actually need, and taking care they get absolutely non-exclusive rights.

Don't complicate simple things.


问:
How long do I have to provide the source code for a LGPL-library?
In case I would dynamically link to a LGPL-licensed library (in this case Qt) in a commercial application: Which way do I have to provide the library's source code?

Is a link to the project homepage sufficient? Or would I need to host the source code on our servers? For which period of time after distribution of the software would this website need to be kept up? (or would "on request" be also compliant with the LGPL?)

Is it still necessary to offer the source code in a physical way (e.g. on CD via snail mail) for 3 years (any difference between LGPL 2.1 and LGPL 3 here?)?

I've found this in the GNU FAQ:

Can I put the binaries on my Internet server and put the source on a
different Internet site?

Yes. Section 6(d) allows this. However, you must provide clear instructions people can follow to obtain the source, and you must take
care to make sure that the source remains available for as long as you
distribute the object code.

I've highlighted the relevant part as bold text. However, I cannot believe, that this is the complete truth. If I distribute an application only once, then I could put the source code online and take it down a day later. So this still doesn't answer my question...

There is another question with a related topic here, but it has a different attempt than mine. It only asks for alternatives to shipping the source code directly with the binaries, while my question aims to clarify which circumstances and conditions I would have to consider / respect when sharing the LGPL library source code.

答:
If you distribute it only once, just distribute it together the binaries and you're done.

If you are not sure, upload it to a public free repository (bitbucket, github) and it's no longer your responsability (as long as you actually stopped distributing the binaries anyway).


问:
End-to-end tests versus unit tests, should tests be decoupled?
At our company we typically make sure that we write an end-to-end test for our websites/web apps. That means we access a URL, fill in a form, submit the form to another URL and check the results of the page. We do this to test form validation, test that the HTML templates have the correct context variables, etc.

We also use it to indirectly test the underlying logic.

I was told by a co-worker that the reason for this is that we can rip out and change the underlying implementation at any point as long as the end-to-end tests pass.

I'm wondering if this sort of decoupling makes sense or if it's just a way to avoid writing tests for smaller units of code?

答:
After a few more years of coding and working on projects I'll provide an answer to my own question.

Yes, you should write unit tests. End to end tests are harder to write and brittle especially if they're relying on UI components.

If you're using a framework like Django or Rails (or your own custom classes) you should have a form class that will handle validation of the form. You'll also have view classes that display rendered templates and the form and handle GET and POST requests.

In an end to end test you would:

get the url

fill in the form with valid data

post the form to the url

check to make sure the database has been updated or some action has been executed as a result of the valid form

You're testing a lot of code and your coverage will be pretty good but you're only testing the happy path when everything goes right. How do you ensure that the form has the right validation in it? What if that form is used on multiple pages? Do you write yet another end to end test?

Let's try this again with unit tests:

test the view GET method

test the view POST method with a fake/mock form

test the form with valid data

test the form with invalid data

test the form's side-effects

By using unit tests, you're testing smaller pieces of code and the tests are specific and easier to write. When you combine this with TDD (Test Driven Development) you get higher quality code.

The ease of writing unit tests shouldn't be dismissed because when you're on a project that has no automated testing, you have to start somewhere. Starting with unit tests is easier and faster and lets you immediately start testing for bugs rather than only for the happy path.


问:
What does "Increment" mean in agile software development?
In Software Requirements by Karl Wiegers:

Project  teams that  build products incrementally  by  following  an  agile development process also need to understand the requirements that go into each increment.

What does "increment" and "incrementally" mean here?

答:
I have not read this title, but usually when someone says build software incrementally they're referring to delivering more and more functionality in iterations. There are different approaches to this, but a lot of them mean starting by developing a minimum set of features/functionality, delivering this to the customer, and responding to feedback/refining the deliverable/adding more functionality. Repeat until project competition.

The idea with this type of approach is that you're doing small bursts of work and then reevaluating to make sure you're still moving in the best direction. This allows development teams to respond to changes better.


答:
In this context, "increment" or "iteration" refer to making relatively small changes to a program before rebuilding or redeploying it. One of the core ideas of agile is that you want to aim for frequent, rapid iterations.

In agile you typically want the program to be buildable and shippable at all times. It may not be terribly useful or feature-complete for a while, but you always want it to be a thing you can actually build and ship right away so that people can start testing it and giving feedback (as opposed to the "waterfall" approach where no one can really try it out until the whole thing is finished). Then you add features to it one at a time, though each one may take anywhere from a day to a couple of weeks or maybe even months.

In many places each increment/iteration is the release made at the end of a "sprint", i.e. a period of 1-2 weeks associated with a short list of tasks the team aims to get done in that time.

Title: What does "Increment" mean in agile software development?

Body:
In Software Requirements by Karl Wiegers:

Project  teams that  build products incrementally  by  following  an  agile development process also need to understand the requirements that go into each increment.

What does "increment" and "incrementally" mean here?


问:
Why do we have to use divs?
This morning, as I was writing some html and haml, it occurred to me that the way divs are used is ridiculous.
Why are divs not implied? Imagine if this:

```<code><div class="hero-img">
   <img src="http://whatever.com/this.jpg">
</div>
</code>```

was this:

```<code><hero-img>
   <img src="http://whatever.com/this.jpg">
</hero-img>
</code>```

If the "div class" portion of the element was assumed, HTML would be more semantic, and infinitely more readable with the matching closing tags!

This is similar to HAML, where we have:

```<code>.content Hello, World!
</code>```

Which becomes:

```<code><div class='content'>Hello, World!</div>
</code>```

It seems to me the only thing that would have to happen for this to work in browsers is that the browsers could start interpreting every element without an existing html element definition as implying <div class="<element name>">.

This could be completely backward compatible; for CSS and jQuery selectors etc, "div.hero-img" could still work, and be the required syntax to select the elements.

I know about the new web components specification, but that is significantly more complicated than what is suggested here. Can you imagine how pleasant it would be to look at a website's source and see html that looked like that?!

So why do we have to use divs?

If you look at Mozilla's html5 element list, every element has a semantic meaning, and then we get to
 and it says:

"Represents a generic container with no special meaning."

..and then they list the arbitrary elements they are adding to html5 like .

Of course, if this concept of implied divs was added to the html spec, it would take ten years to become standard, which is a million years in web time.

So I figure there must be a good reason this hasn't happened yet. Please, explain it to me!

答:
You are suggesting allowing web authors to add arbitrary element names to HTML for private (non-standardized) purposes. This has a big problem: It will make it dangerous to add new elements to the HTML standard, because various authors might already be using the the same element name for private purposes - thereby retroactively changing the semantics of the page. People don't get happy when new versions of browsers break existing web pages, so this is a no-go.

The same problem is with using arbitrary attribute names for private purposes. This is why HTML5 mandates the prefix "data-" for private use attributes, so they wont collide with new attributes in the standard.

Div and span are defined as semantically neutral elements, which means you can use them for private purposes without fear that the semantics will change in future browsers. Sure, it requires a few more characters to add a class name, but forward compatibility makes it worth it.

Title: Why do we have to use divs?


问:
What's the best way to handle Windows API errors in response to system messages or when I have nowhere to return them to?
This is going to be a really stupid question and I hope it's fine for Stack Exchange at all, let alone just this part of it...

Right now, my custom Table control uses panic() functions that print an error on screen and DebugBreak() when a Windows API error occurs.

This is obviously an issue, but I'm not completely sure how to go about fixing it without effectively ignoring errors entirely. Keyword "effectively": even if I catch errors, if I can't do anything with them (be it forward the error to the user or to something else) it doesn't really count if I check for them.

Now for user-initiated functions (like tableAddColumn in my control) this isn't really an issue: just return the error information as a return value to the function.

My question is: what's the best way to handle Windows API errors in response to things where I can't obviously just return error information somehow. For instance, what if one of the drawing functions that I call in response to WM_PAINT fails? None of the system-provided messages provide functionality to return the API error to the system; they all just tell you to return zero if you handled the message.

I was thinking of creating a WM_NOTIFY notification tableErrorOccurred that gets sent to the control's parent when an API error occurs. However, I'm not sure how that would interact with the accessibility code. Windows accessible code is all COM, so I can freely return API errors via the HRESULT returns. Should those count toward the notification, or not? (Especially since the notification can and will return more information than just the HRESULT.)

I'm not sure whatever options there are, other than discounting the possibility of an error when all error conditions are made impossible. My current policy is to only check for an error when a function explicitly says it returns an error and how (for example, SendMessage(), EndPaint(), and SetScrollInfo() don't), and to ignore any commentary on which errors can be returned, in case the list of possible errors for whatever reason changes in the future. Am I wrong in this particular scenario: that is, would the error returns be guaranteed to never change and thus functions that only return errors on invalid parameters guaranteed to never fail with known valid parameters?

Some people have told me or talked about another Raymond Chen adage, "don't check for errors you don't know how to handle". Maybe someone can tell me that I'm misinterpreting this statement or something to that extent? Especially after the second link: it asks about what you would do with the error. I know what I want to do with these API errors: send them up to the thing that issued my own API request, just like every other API request in (almost) every other API ever! Is there a difference between doing this and "handling" the error? (You can tell that as I write more and more of this question, I am getting less and less sure of what my own opinion is, or whether any of this even IS a problem...)

The most common cases are calling GetClientRect(), which I could just save in my data structure if I can guarantee there are no cases in which the return value can change without a WM_WINDOWPOSCHANGED, and getting the height of the currently selected text font, which I can't save without sacrificing DPI independence (I deliberately get it every time to avoid the risk of crossing a DPI change boundary should a user program enable DPI awareness). The files util.h and coord.h have more info, but scroll.h and draw.h have the most API calls as far as I know.

The bits of the wine source code that I've seen don't check for errors. That's the only bit of information I have to say at this point. I'm not going to doubt that wine is a quality piece of software with a lot of effort put into it, but it seems odd to me that it does work well without explicit error checks on every API call...

I really don't want to rant about things here, so apologies in advance if this paragraph (and the previous) doesn't seem to go anywhere: It would be easier if I could return errors up to the system, or from SendMessage() (with the LRESULT as an out parameter, like COM method calls do). I don't really know. My experience with other GUI toolkits is that in most cases the only errors are incorrect parameters, but that really seems suspiciously optimistic to me. My main programming language for non-GUI stuff right now is Go, where errors are so fundamental that they're handled throughout both the standard library and user libraries (and have always been this way, without changes over time), and thus we know to carry errors up through the call chain; this reflects my own idea of error handling (and vice versa, to some extent).

So if anyone has any advice from the real world, that would be great, especially as I am close to finishing this and splitting out from the github project linked into something general purpose. Thanks.

EDIT 1 March 2015

I don't know why I forgot to paste this earlier but this is what some people on IRC said the day I posted this

```<code>[Sunday, February 15, 2015] [06:09:44 PM] <Rena>        andlabs, I think by "don't check for errors you can't handle" they mean just ignore them entirely.
[Sunday, February 15, 2015] [06:09:59 PM] <Rena>        I mean I can't really think of a sane thing to do if WM_PAINT is failing
[Sunday, February 15, 2015] [06:10:39 PM] <Rena>        sometimes there's nothing you can do but let it break
[Sunday, February 15, 2015] [06:19:17 PM] <andlabs>     Rena: yes, and that just goes against /everyhting/ I've been taugh tand everyone has been teaching everytone else!
[Sunday, February 15, 2015] [06:19:23 PM] <andlabs>     that's why I'm [expletive] confused!
[Sunday, February 15, 2015] [06:20:54 PM] <andlabs>     Rena: point that out anyway :S
[Sunday, February 15, 2015] [06:21:09 PM] <devin>       nobody ever tries to catch std::bad_alloc in C++ because if you've even reached the point where that's being thrown under normal circumstances then you're probably [expletive] and should just let the ship sink anyway
[Sunday, February 15, 2015] [06:21:37 PM] <Rena>        well things like, what are you even going to do if drawing something fails? it's not a huge issue and there's probably nothing you can do about it.
[Sunday, February 15, 2015] [06:21:49 PM] <Rena>        probably it means the system is running out of GDI memory or something
[Sunday, February 15, 2015] [06:22:47 PM] <andlabs>     Rena: right, at least in the case of WM_PAINT
[Sunday, February 15, 2015] [06:23:09 PM] <Rena>        if it's like memory allocation failed in some tool, it'd be a good idea to handle that by throwing up an "out of memory" message and/or trying to save the current file to a scratch file somewhere, instead of just crashing and losing work
[Sunday, February 15, 2015] [06:23:43 PM] <andlabs>     right
[Sunday, February 15, 2015] [06:23:59 PM] <andlabs>     ...actually I'll have to keep a note of that
[Sunday, February 15, 2015] [06:24:23 PM] <andlabs>     the other situations in which a reallocation would fail is
[Sunday, February 15, 2015] [06:24:25 PM] <andlabs>     a) heap corruption
[Sunday, February 15, 2015] [06:24:30 PM] <andlabs>     in which case you actually ARE [expletive]
[Sunday, February 15, 2015] [06:24:40 PM] <andlabs>     b) passing a pointer to something that isn't part of the realloc heap
[Sunday, February 15, 2015] [06:24:51 PM] <andlabs>     c) passing an obviously bad size like -4
[Sunday, February 15, 2015] [06:38:02 PM] <andlabs>     Rena, devin - yeah :/
[Sunday, February 15, 2015] [06:38:07 PM] <andlabs>     I figure that much :S
</code>```

This comment on a pseudo-related question I posted on Stack Overflow (about a specific scenario) explains my state of mind as well.

答:
Whenever an error happens one of the following scenarios must be true:

You have checked for that error

You have not checked for that error

In case of #2 your application will crash and it's your job to make sure it crashes gracefully (nice message to user, logs and so on). In order to do that you need to check for errors which means #2 is something you should never do.

All errors must be checked.  No errors should be ignored.

Now there could be different interpretations of the term 'handle' when people say 'you should handle the error'. You can interpret as:

Check for errors

Do 'something' with them

This 'something' can be:

Recover so the application continues running

Fail gracefully.

When you decide to fail you have also to decide if the application will continue so the user can simply acknowledge the error and retry (maybe) or you decided the error is too serious and you better force the user to quit and start over.

You could intentionally decide to ignore errors as long as you have some sort of 'global-catch-all-errors' mechanism. If you don't then it's your job to check for every possible error and do something about it. Even if this something means just showing a message writing a log and quitting.