答:
It's usually a matter of page limitations. If the algorithm is exceedingly short, it oftentimes is represented, at least as pseudocode, in the paper. On the other hand, if the printed version of the underlying code is even a handful of pages long, printing the code would leave no room for the meat of the article. A journal article that is ten pages long is a long article.

Not making the source available creates a potential for fraud. Because of this potential, many journals now require that authors submit their source code as supplemental information (which is obtainable from the journal if you have access; a a hefty subscription fee may be involved). Some others journal requires the authors to release their source code to anyone who asks for it. Yet other journals are still in the dark ages; the source code isn't required for submission and the authors aren't required to release it.

The easiest thing to do is to ask the authors if they can supply the source code to you. The authors' email addresses are typically listed in most journal papers nowadays.


问:
Why don't research papers that mention custom software release the source code?
Is there a reason why the source code of software mentioned in research papers is not released? I understand that research papers are more about the general idea of accomplishing something than implementation details, but I don't get why they don't release the code.

For example, this paper ends with:

Results

The human line drawing system is implemented through the Qt framework in C++ using OpenGL, and runs on a 2.00 GHz Intel dual core processor workstation without any additional hardware assistance. We can interactively draw lines while the system synthesizes the new path and texture.

Do they keep the source code closed intentionally because of a monetization they intend to make with it, or because of copyright ?

答:
Several reasons come to mind.

Code is too big for article.  For a short period of time, interesting projects were short enough to be published with the paper that described them.  This can still happen, but many projects of sufficiently large size to be interesting have grown too big to be published with the papers that describe them.

Public hosts not free or durable.  Until recently, cheap, durable, easy to access public hosts were not available.

Publishing a paper is easier than publishing a project.  Some people have time to publish a paper or a project, but not both.

Incentives tied to role.  Many years ago I asked a colleague about product development and patents and got the word that most people there pretty much did one or the other.  As with paper writers (think academia) and open source developers, rewards are geared toward one work product or the other.

Self motivation.  The desire to describe ideas or to implement code is not always present in equal parts in the same person.  Many of my professors openly admitted that they either never coded very much, or were many years away from having coded fluently.  Similarly, many developers barely want to write comments in their code or when they commit to source control.

Durability of project hosting and work product is also an issue.  Who wants to link somewhere that might be gone a few years from now and as a result, diminish the value of the paper.

Tradition.  Publishers are oriented toward reviewing and publishing papers, but might not be ready to take on the same evaluation for projects.

Also the traditional views on what is a sensible level of reproducibility varies among fields. A chemist publishing a paper about a new synthesis method is expected to write down enough detail for another chemist to perform the synthesis. She'd not be expected to ship the educts and product to the journal. Readers who want to use/reproduce the paper are expected to buy their own educts and do the synthesis themselves in their lab (though they may ask to come and visit the lab to see how it is done in practice). Neither would a biologist be expected to attach his new transgenic mice to the paper. This view on reproducibility corresponds to e.g. giving a (pseudo-code) description of the algorithm as opposed to shipping the actual implementation.

Naked code can be shocking.  It takes a lot less polishing to proof-read a paper length document than to code inspect, code review, and quality assure a project.  I have a lot of code I would be more comfortable telling you about than showing you.  Hopefully things are moving forward to a point where we will all write beautiful code, but if your code was rushed, barely or doesn't completely work, you might be more comfortable not sharing the executables or the source.

Closed source.  Not everyone has embraced open source.  Many papers are written about work for DoD, commercial projects, or privately funded projects where there are benefits from exposure of the project to the public, but there are still trade secrets or first to market advantages that could be eroded by open sourcing the code or other work products.

Publish further work based on this code. If the code is not published it may give the author an advantage in publishing followup work. Other competing researchers may need to reimplement the work which may take precious time.

ContentLicense: CC BY-SA 3.0


问:
How important is using the same language for client and server?
I have been evaluating architecture solutions for a mobile project that will have a web-service/app in addition to native apps and have been looking at various libraries, frameworks, and stacks like Meteor, this being a sort of "open stack package framework", is tightly bound with Node.js.

There is a lot of talk about the benefits of using the same language both client and server side, and I'm not getting it. I could understand if you want to mirror the entire state of a web application on both client and server but struggling to find other wins... Workflow efficiency?

I'm trying to understand why client/server language parity is considered to be a holy grail.  Why does client/server language parity matter in software development?

答:
Presumably the perceived benefit are:

you only need to hire developers that know language x rather than x + y (this is probably not really a good idea though if they only know one language)

it is easier to move developers between server and client development (this can be quite a good thing).

i.e. it makes resource management easier for project managers and has little or no technical benefit (possibly even negative technical benefit if you are hiring a bunch of one trick ponies)


问:
Clarify the Single Responsibility Principle
The Single Responsibility Principle states that a class should do one and only one thing.  Some cases are pretty clear cut.  Others, though, are difficult because what looks like "one thing" when viewed at a given level of abstraction may be multiple things when viewed at a lower level.  I also fear that if the Single Responsibility Principle is honored at the lower levels, excessively decoupled, verbose ravioli code, where more lines are spent creating tiny classes for everything and plumbing information around than actually solving the problem at hand, can result.

How would you describe what "one thing" means?  What are some concrete signs that a class really does more than "one thing"?

答:
It's about having one unique rôle.

Each class should be resumed by a role name.
A role is in fact a (set of) verb(s) associated with a context.

For example :

File provide a file's access.
FileManager manage File objects.

Resource hold data for one resource from a File.
ResourceManager hold and provide all Resources.

Here you can see that some verbs like "manage" imply a set of other verbs. Verbs alone are better thought as functions than classes, most of the time. If the verb imply too much actions that have their own common context, then it should be a class in itself.

So, the idea is only to let you have a simple idea of what does the class by defining a unique role, that might be the agregate of several sub-role (performed by member objects or other objects).

I often build Manager classes that have several different other classes in it. Like a Factory, a Registry, etc.
See a Manager class like some kind of group chief, a orchestra chief that guide other peoples to work together to achieve a high level idea. He have one role, but imply working with other unique roles inside.
You can also see it like how a company is organized : a CEO isn't a productive one on the pure productivity level, but if he is not there, then nothing can work correctly together. That's his role.

When you design, identify unique roles. And for each role, again see if it can't be cut in several other roles. That way, if you need to simlpy change the way your Manager build objects, simply change the Factory and go with peace in mind.

ContentLicense: CC BY-SA 2.5


问:
Should an image be able to resize itself in OOP?
I'm writing an app that will have an Image entity, and I'm already having trouble deciding whose responsibility each task should be.

First I have the Image class. It has a path, width, and other attributes.

Then I created an ImageRepository class, for retrieving images with a single and tested method, eg: findAllImagesWithoutThumbnail().

But now I also need to be able to createThumbnail(). Who should deal with that? I was thinking about having an ImageManager class, which would be an app-specific class (there would also be a third party image manipulation reusable component of choice, I'm not reinventing the wheel).

Or maybe it would be 0K to let the Image resize itself? Or let the ImageRepository and ImageManager be the same class?

What do you think?

答:
I think in the "Image Domain", you just have the Image object which is immutable and monadic. You ask the image for a resized version and it returns a resized version of itself. Then you can decide whether you want to get rid of the original or keep both.

Now the thumbnail, avatar, etc versions of the Image is another Domain entirely, which can ask the Image domain for different versions of a certain image to give to a user. Usually this domain is also not so huge or generic, so you can probably keep this in application logic.

In a small scale app, I would resize the images at read time. For example I could have a apache rewrite rule that delegates to php a script if the image 'http://my.site.com/images/thumbnails/image1.png', where the file will be retrieved using the name image1.png and resized and stored in 'thumbnails/image1.png'. Then on the next request to this same image, apache will serve the image directly without running the php script. Your question of findAllImagesWithoutThumbnails is automatically answered by apache, unless you need to do statistics?

In a large scale app, I would send the all new images to a background job, which takes care of generating the different versions of the image and saves it in appropriate places. I wouldn't bother creating a whole domain or class as this domain is very unlikely to grow into a terrible mess of spaghetti and bad sauce.


答:
A lot depends on the purpose for which the code was written. If it was to demonstrate a point, it may well be that it is not optimised, and therefore not ideal that it get released. If the underlying concepts and methodology are valid, then it should be possible to recreate the outcome of the code from scratch. There may be issues of copyright and ownership as well. </p>

<p>In principle, it is not technically impossible to release the code but the reasons for which it might not be released are varied. There probably isn't a simple answer to this question for that reason. In specific cases maybe you could ask the researchers concerned. </p>

Title: Why don't research papers that mention custom software release the source code?

Body:
Is there a reason why the source code of software mentioned in research papers is not released? I understand that research papers are more about the general idea of accomplishing something than implementation details, but I don't get why they don't release the code.

For example, this paper ends with:

Results

The human line drawing system is implemented through the Qt framework in C++ using OpenGL, and runs on a 2.00 GHz Intel dual core processor workstation without any additional hardware assistance. We can interactively draw lines while the system synthesizes the new path and texture.

Do they keep the source code closed intentionally because of a monetization they intend to make with it, or because of copyright ?

Body:
A lot depends on the purpose for which the code was written. If it was to demonstrate a point, it may well be that it is not optimised, and therefore not ideal that it get released. If the underlying concepts and methodology are valid, then it should be possible to recreate the outcome of the code from scratch. There may be issues of copyright and ownership as well.

In principle, it is not technically impossible to release the code but the reasons for which it might not be released are varied. There probably isn't a simple answer to this question for that reason. In specific cases maybe you could ask the researchers concerned.


答:
On the PRO side:

If schemas and code can be reused by both sides, there is a lot of efficiency in implementing similar logic and data just once.

On the CON side:

The client may be primarily a view that is well suited for a mark up or script language, while the server may be primarily business logic that is better suited to a different language.

In web development, languages have proliferated, creating powerful tools for specific parts of the system as well as the need for many specialties to be learned by developers or teams of developers.  In other areas like transaction processing or embedded systems that follow a systems of systems design approach, there may be savings from a common language.

New Javascript frameworks seem to come at us very fast, and some work is done to bundle APIs for the back end and tools for the front end.  It might be smart to keep flexibility and separation of concerns between client and server side code so that you are free to float between them without being too stuck for too long with a particular tool.

Title: How important is using the same language for client and server?

Body:
I have been evaluating architecture solutions for a mobile project that will have a web-service/app in addition to native apps and have been looking at various libraries, frameworks, and stacks like Meteor, this being a sort of "open stack package framework", is tightly bound with Node.js.

There is a lot of talk about the benefits of using the same language both client and server side, and I'm not getting it. I could understand if you want to mirror the entire state of a web application on both client and server but struggling to find other wins... Workflow efficiency?

I'm trying to understand why client/server language parity is considered to be a holy grail.  Why does client/server language parity matter in software development?


问:
Syncing objects to a remote server, and caching on local storage
What's the best method of sycing objects (as JSON) to a remote server, with local caching?

I have some objects that will pretty much just be plain-text with some extra meta-data. I was thinking of perhaps including a "last modified date" for both Local storage and Remote storage. This could then be used to determine which object is the most recent.

For example, even though objects will be saved to both local and remote when they are saved, sometimes the user may not have internet access, or the server may be down, or any other number of things. In this case, the last modified date for remote storage would be reverted to its previous date. Local storage would remain as it is. At this point, the user could exit the application, and when they reload the application would then look at the last modified dates of the local and remote storages, and decide.

Is there anything I'm missing with this? Is there a better method that I could use?

答:
For some good ideas, check out how Microsoft Sync Framework works.

You have the right idea.  You need a last modified time, but you also need to think about deleting data.  You need a tombstone table for that.  Plus you then have to write some custom logic on how to deal with conflicts (what if two clients updated the same record?).

One thing is make sure you're using UUID (Guid) for your IDs, that way they can be created in multiple locations simultaneously without collisions.


答: You may want to look at some pre-built document storage solutions such as CouchDB that are optimized for replication. It speaks natively in JSON which is a plus for your needs.  MongoDB is another possibility but CouchDB has been more optimized for peer-to-peer replication in the past for this scenario, although MongoDB is catching up in that area.</p>

Title: Syncing objects to a remote server, and caching on local storage

Body:
What's the best method of sycing objects (as JSON) to a remote server, with local caching?

I have some objects that will pretty much just be plain-text with some extra meta-data. I was thinking of perhaps including a "last modified date" for both Local storage and Remote storage. This could then be used to determine which object is the most recent.

For example, even though objects will be saved to both local and remote when they are saved, sometimes the user may not have internet access, or the server may be down, or any other number of things. In this case, the last modified date for remote storage would be reverted to its previous date. Local storage would remain as it is. At this point, the user could exit the application, and when they reload the application would then look at the last modified dates of the local and remote storages, and decide.

Is there anything I'm missing with this? Is there a better method that I could use?


答:
My experience as a scientist (5 papers published) is that often times it is not required by the journal to release the code which was used to create the results. That is not saying that journals would not accept the scripts. Many journals allow online supplementary material. Some journals geared towards algorithms and such (e.g. Computers and Geosciences) require you to add the source of an algorithm, but this is more an exception than a rule. </p>

<p>In addition to the culture at the journals, for scientists code is just a means to an end. Many are not professional software developers. Because many regard the code as just a tool to express science, they do not feel the urgency to also publish the code. In addition, polishing your code to the point where it could be published takes a lot of work. A scientist is paid to do science, not write software. </p>

Body:
My experience as a scientist (5 papers published) is that often times it is not required by the journal to release the code which was used to create the results. That is not saying that journals would not accept the scripts. Many journals allow online supplementary material. Some journals geared towards algorithms and such (e.g. Computers and Geosciences) require you to add the source of an algorithm, but this is more an exception than a rule.

In addition to the culture at the journals, for scientists code is just a means to an end. Many are not professional software developers. Because many regard the code as just a tool to express science, they do not feel the urgency to also publish the code. In addition, polishing your code to the point where it could be published takes a lot of work. A scientist is paid to do science, not write software.


问:
Making sure users have a modern web browser
We have several users running on old hardware and old browsers.

What would be the best way to get them to upgrade to a newer web browser, without nagging users with a newer web browser.

答:
I don't think you can - look at Microsoft's attempts to get Silverlight pushed out to everyone, even as a plugin it failed to get more than 60% or so. If they cannot persuade everyone (via marketing, hype, and web pages with "you must install to see this" then I'm not sure you're going to have much success.

I think the best way is to let the natural evolution take its course, one day all the old browsers will have enough of a market share that you can safely ignore them - and keep an eye on your log statistics to see which browsers people are using when they visit your sites. Choose a percentage below which you will no longer support that browser. For these people you can display a "you need to upgrade" page. Alternatively, provide them with a very basic functionality page containing no advanced features, so they can work with a subset of functionality and put your nag reminder at the top of it.

The rest of the time, just remember that you will always be chasing a older version, if a new browser technology appears today, it won't have critical mass to be usable in production for a good couple of years.


问:
What does "Human Readable" mean? Is it a misnomer?
Two examples spring to mind:

One of the reasons that .Net programmers are encouraged to use .config files instead of the Windows Registry is that .config files are XML and therefore human-readable.

Similarly, JSON is sometimes considered human-readable compared with a proprietary format.

Are human-readable formats actually readable by humans? In the example of configuration data:

The format doesn't change the underlying meaning of the information - in both cases, the data represents the same thing.

Both registry and .config file are stored internally as a series 0s and 1s. To that extent, the underlying representaion is equally unreadable by humans.

Both registry and .config file require a tool to read, format and display those 0s and 1s and convert them into a format that humans can read. In the case of configuration stored in the Windows Registry, this is a Registry Editor. In the case of XML it could be a text editor or XML reader. Either way, the tool makes the data readable, not the data format.

So, what is the difference between human-readable data formats and non-human-readable formats?

答:
It's all about ease of understanding (and likely changing).  So "Is X human readable?" shouldn't be answered with a "yes" or a "no".  Rather, the answer should be along some sort of sliding scale.

Potential examples:

90% of programmers could read and change the file with any common text editor.

60% of English speakers could read the file with any common text editor.

80% of XYZ developers could read and change the file, but only using tool ZYX.

10% of YZX developers could read and change this file with a common text editor.

Outside of a context that explains what "human readable" really means, the phrase doesn't help all that much.  (Some human somewhere can probably read any of the formats, if you don't count trying to look at the magnetic polarity of the hardware bits themselves...)


答:
The benefit is that you can reuse (to some extend) people's expertise and code on both sides.

People

The developers need to master a single language and form a single pool. Rather than two pools of expertise. This makes it easier to transfer knowledge among them, and also to allow them switching their work between client and server side more easily. Lastly, it facilitates communication with team members of the "other side" when discussing technical issues because they share the same technical background.

Code

Sometimes it is useful to have some state on the client side, or algorithms, or both. Sometimes, the same is done on both sides. Let's take the example of a multiplayer game:
you need to represent the game state on both client and server. Also, you need to implement the rules on client side (for responsiveness) and also on server side (to validate a player's actions). Being able to reuse code for these things can be a great advantage. ...in some other applications, you wouldn't need this at all ...it all depends on the case.

...of course there are also downsides, but that's for another post ;)


问:
@staticmethod vs module-level function
This is not about @staticmethod and @classmethod!  I know how staticmethod works.  What I want to know is the proper use cases for @staticmethod vs. a module-level function.

I've googled this question, and it seems there's some general agreement that module-level functions are preferred over static methods because it's more pythonic.  Static methods have the advantage of being bound to its class, which may make sense if only that class uses it.  However, in Python functionality is usually organized by module not class, so usually making it a module function makes sense too.

Static methods can also be overridden by subclasses, which is an advantage or disadvantage depending on how you look at it.  Although, static methods are usually "functionally pure" so overriding it may not be smart, but it may be convenient sometimes (though this may be one of those "convenient, but NEVER DO IT" kind of things only experience can teach you).

Are there any general rule-of-thumbs for using either staticmethod or module-level functions?  What concrete advantages or disadvantages do they have (e.g. future extension, external extension, readability)?  If possible, also provide a case example.

答:
A program is a simulation of a piece of reality. This way, it depends on how you perceive the reality.

A function represents some activity. The more the activity is general, the bigger is the tendency to simulate the activity with a function. Methods are bound to classes. The more the activity is specific to the class, the more it tends to be simulated by a method.

Think about the trigonometric functions. Say, the sin() is so well known that you know it fits with angles. You know that it wants a float number as input and returns the float. Anyway, there can be an angle datatype represented by a class and the .sin() without argument could be a normal method that works with the angle object, and .sin(x) with a single argument could be a static method of the class. I could bet that more people think that it is better to make sin() a plain function. They are more used to.

Another viewpoint: A module resembles a class instance. It has its own member variables and member functions. In some sense, it implements a singleton pattern. Whenever you import it from another module of the application, you get the access to exactly the same variables and functions.

Title: @staticmethod vs module-level function


问:
Which web framework to use under Backbonejs?
For a previous project, I was using Backbonejs alongside Django, but I found out that I didn't use many features from Django. So, I am looking for a lighter framework to use underneath a Backbonejs web app.

I never used Django built in templates. When I did, it was to set up the initial index page, but that's all.

I did use the user management system that Django provided.

I used the models.py, but never views.py.

I used urls.py to set up which template the user would hit upon visiting the site.

I noticed that the two features that I used most from Django was South and Tastypie, and they aren't even included with Django.

Particularly, django-tastypie made it easy for me to link up my frontend models to my backend models. It made it easy to JSONify my front end models and send them to Tastypie.
Although, I found myself overriding a lot of tastypie's methods for GET, PUT, POST requests, so it became useless.

South made it easy to migrate new changes to the database. Although, I had so much trouble with South. Is there a framework with an easier way of handling database modifications than using South? When using South with multiple people, we had the worse time keeping our databases synced. When someone added a new table and pushed their migration to git, the other two people would spend days trying to use South's automatic migration, but it never worked. I liked how Rails had a manual way of migrating databases.

Even though I used Tastypie and South a lot, I found myself not actually liking them because I ended up overriding most Tastypie methods for each Resource, and I also had the worst trouble migrating new tables and columns with South. So, I would like a framework that makes that process easier. Part of my problem was that they are too "magical".

Which framework should I use? Nodejs or a lighter Python framework? Which works best with my above criteria?

答:
I would consider using Flask for the backend and SQLAlchemy for database abstraction. It's lightweight, plays nice nice with backbone.js and allows you to use appropriate patterns.

More info regarding how to implement some typical patterns using Flask can be found here: http://flask.pocoo.org/docs/patterns/


问:
Map Library: Client-side or Server-side?
As I have already asked here, I have to implement a Multi-Platform Map application. Now I have Mapstraction as an option which uses Javascript to implement the desired functionality. My question is, "Is there any reason/benefit to implement such a library (let say, Adapters) in Server-side (in my case, PHP)?"

As these maps are all based on Javascript, there is a big reason to use Javascript again to make the adapter also, so it would not be dependent to PHP, Java, or .NET for example. But is that all?

答:
As far as I can see, there are no benefits to implementing your adapters on the server-side rather than in JavaScript. In fact you would be better off with JavaScript because it is the ubiquitous language of the web; if in the future you decide to re-write your backend using another technology, you wouldn't have to re-write the adapters.

If you're hesitant to go with JavaScript because you don't have enough experience with it, even then my suggestion would remain unchanged, because every modern, client-heavy web application demands that you be comfortable with it.

Besides, you're getting a mature, tested JavaScript adapter library - with a fairly permissive BSD license - in the form of Mapstraction, which I mentioned in my answer to your linked question, so that's a very good option if you can use it. Either way, I think JavaScript is the way to go for you.


问:
How do operating systems… run… without having an OS to run in?
I'm really curious right now. I'm a Python programmer, and this question just boggled me: You write an OS. How do you run it? It has to be run somehow, and that way is within another OS?

How can an application run without being in an OS? How do you tell the computer to run, say, C, and execute these commands to the screen, if it doesn't have an OS to run in?

Does it have to do with a UNIX kernel? If so, what is a Unix kernel, or a kernel in general?

I'm sure OSes are more complicated than that, but how does it work?

答:
You ask "How can an application run without being in an OS". The easy answer is "an OS is not an application". While an OS can be created with the same tools as an application, and made out of the same raw material, they are not the same thing. An OS doesn't have to play by the same rules as an application.

OTOH, you can think of the actual hardware and firmware as the "OS" in which the OS "application" runs. The hardware is a very simple OS -- it knows how to run instructions written in machine code, and it knows that when it starts up it should look at a very specific memory address for its first instruction. So, it starts up and then immediately runs that very first instruction, followed by the second, and so on.

So, the OS is simply machine code that exists at a known location, and which can directly interact with the hardware.


问:
Large enterprise application - clients wish to use duplicate e-mails addresses?
I'd like to know people's opinions, reactions to clients and technical work arounds (if applicable), to the issue of an enterprise application where a client wishes to use duplicate e-mail addresses?

To clarify, when I say duplicate e-mail addresses I mean within the same client system, having multiple users that have the same e-mail address. So not just using generic e-mail addresses but using the e-mail address of another user.

e.g.

Bob Jenkins: bjenkins@myorg.com

James Jeffery: bjenkins@myorg.com

Context

To give this some further context, in the e-learning sector it is common that although all staff in an organisation must complete e-learning - they may not have their own e-mail address so they choose to use their managers e-mail address.

Albeit against good practice in public sites... it's a requirement we've over and over again where an organisation is split between office based staff and perhaps e.g. staff in a warehouse.

Where problem lies

Mr Steak, good point, the problem lies in password resets and perhaps in situations where semi-personal information could be sent (not confidential enough to worry about the insecurities of email). Perhaps reminders for specific system actions, which would be confusing for the unintended party to see (if perhaps misreading the e-mail's intended recipient)

Possible solutions

System knowing the difference between a "for the attention of" and direct to the person e-mails, including this in the body text.

Using alternative communication such as SMS

Simply not having e-mails sent to people who are not the intended recipient.

Providing an e-mail service ourselfs (not really viable for a corporate IT dept)

Thoughts?

答:
Email adresses should really be unique within a database. Creating an email adress is so trivial these days that every one should have its own. You stated all the reasons yourself to require a unique email adress per person :

Confidentiality

Just look at every possible website that requires registration. If you try to register with an adress that is already used, they don't let you create your account. Just do the same thing and everything will be fine.

Sure it also depends on the kind of information that your application will send by email. If you don't send any sensitive information, confidentiality will not be an issue. However, if you use it for logging in, then you cannot have multiple people with the same email.

But even if you don't send anything sensitive, I strongly advise you to require unique email adress. You don't know how your application is going to evolve and you might want to send such information in the future. Just take that precaution right at the start and it might save you lots of headaches later.


答:
If you have some people who are not allowed to have e-mail addresses, let them all share common ones. For instance:

shipping@yoursite.com

Or similar general addresses.

It still seems weird that you cant create e-mail addresses for people though, but I can see how some mobile people might not be able to log in and out of accounts constantly.

Title: Large enterprise application - clients wish to use duplicate e-mails addresses?

Body:
I'd like to know people's opinions, reactions to clients and technical work arounds (if applicable), to the issue of an enterprise application where a client wishes to use duplicate e-mail addresses?

To clarify, when I say duplicate e-mail addresses I mean within the same client system, having multiple users that have the same e-mail address. So not just using generic e-mail addresses but using the e-mail address of another user.

e.g.

Bob Jenkins: bjenkins@myorg.com

James Jeffery: bjenkins@myorg.com

Context

To give this some further context, in the e-learning sector it is common that although all staff in an organisation must complete e-learning - they may not have their own e-mail address so they choose to use their managers e-mail address.

Albeit against good practice in public sites... it's a requirement we've over and over again where an organisation is split between office based staff and perhaps e.g. staff in a warehouse.

Where problem lies

Mr Steak, good point, the problem lies in password resets and perhaps in situations where semi-personal information could be sent (not confidential enough to worry about the insecurities of email). Perhaps reminders for specific system actions, which would be confusing for the unintended party to see (if perhaps misreading the e-mail's intended recipient)

Possible solutions

System knowing the difference between a "for the attention of" and direct to the person e-mails, including this in the body text.

Using alternative communication such as SMS

Simply not having e-mails sent to people who are not the intended recipient.

Providing an e-mail service ourselfs (not really viable for a corporate IT dept)

Thoughts?


问:
How is your working time distributed between coding and thinking?
...in percentage. For example 60/40 or 90/10 or 100/0.

My hypothesis is that the bigger the proportion of time you spend thinking the smaller your code can be as a result (and the less time will be needed to write it down). Think more, write less, in other words. Do you think it is true?

As a side note, I think in typical software companies thinking is not part of the culture anyway: you are usually supposed to be sitting there at your computer typing something. You will almost definitely be noticed by your managers if you wander about with a blank look thinking over your next steps with your code. Too bad.

答:
As with anything else, it depends

At the beginning of something, the majority of time is spent thinking and planning how to code it. Once you have the plan in place, most of the time is spent coding.


答:
I'd suggest this is a bit of a non-issue for the scenario you describe.

My answer will stay within the realm of your scenario of an e-learning site, supervisors who have access to corp email, and workers who neither access nor need corp email.

If the stickler is password resets, provide additional mechanisms to reset their password other than email.  Challenge / response systems are a convenient way to do this.  Allow the end users to pick from a large set of questions to where they would be the only ones (in that environment) who should know the answer.

If training reminders are an issue, then gear the reminders towards the supervisor.  Provide the reminders in the form of a report.  "These users are X days from being delinquent on training" or "These users are Y days from needing a refresher" or similar.  Part of the supervisor's duties are to make sure their employees stay current on training.  Make the reminder a report that simplifies their responsibilities.

Adding in the ability to receive text messages would be a bonus.  Keep that as an opt-in only since most workers will not be issued corporate phones.  Otherwise they will resent being forced to use personal property for company work.

Providing alternate email systems ignores the fact that the workers don't check email at work.  If they did, they would have corp email accounts.  The challenge to solve here isn't providing them with corp email accounts.  The challenge is to provide some measure of authentication where email is not available for password changes and reminders.


问:
What exactly is the build number in MAJOR.MINOR.BUILDNUMBER.REVISION
What I think about Build Numbers is that whenever a new nightly build is created, a new BUILDNUMBER is generated and assigned to that build. So for my 7.0 version application the nightly builds will be 7.0.1, 7.0.2 and so on. Is it so? Then what is the use of a REVISION after the build number? Or is the REVISION part being incremented after each nightly build? I am a little confused here... do we refer to each nightly build as a BUILD?

The format is mentioned here: AssemblyVersion - MSDN

答:
Microsoft describes the purpose of each component of a .NET version number in their MSDN documentation for the Version class.  Here is the relevant portion:

major.minor[.build[.revision]]

The components are used by convention as follows:

Major: Assemblies with the same name but different major versions are
  not interchangeable. A higher version number might indicate a major
  rewrite of a product where backward compatibility cannot be assumed.

Minor: If the name and major version number on two assemblies are the
  same, but the minor version number is different, this indicates
  significant enhancement with the intention of backward compatibility.
  This higher minor version number might indicate a point release of a
  product or a fully backward-compatible new version of a product.

Build: A difference in build number represents a recompilation of the
  same source. Different build numbers might be used when the processor,
  platform, or compiler changes.

Revision: Assemblies with the same name, major, and minor version
  numbers but different revisions are intended to be fully
  interchangeable. A higher revision number might be used in a build
  that fixes a security hole in a previously released assembly.

http://msdn.microsoft.com/en-us/library/system.version.aspx


答:
Not having a unique e-mail address for each registrant effectively eliminates e-mail as a an option of communication and as an option of identification. However, this is not the end of the world:

If you cannot use e-mail for communication or identification, don't ask for it at all

That's right, just skip e-mail altogether: as far as your application is concerned, it is perfectly useless.

Lack of an e-mail requires you to make two decisions:

How do you identify a registrant, and

How do you communicate with a registrant

The first question requires a registrant to provide something unique that is also external to your application. You may not ask for government-issued identification number, but an employee identification number issued by the corporation should be perfectly valid. This number can be used for password resets and other situations when unique identification is essential. Using a phone number should be another option, assuming that the corporation has the record of the phone number of each employee. Sending an SMS with a unique registration number to a phone number provided by the employee is yet another way of establishing the unique identity. If everything else fails, you can print a letter with a unique number for each employee, and send it to their home address or distribute them to employees through their supervisors.

Communicating back to the employee becomes slightly more problematic, because the "push" model of the e-mail no longer works. You can take the SMS route again, but you can also switch to the "pull" model, when you ask the employee to log back in after a certain period of time to check for communications intended for her or him. This is similar to the strategy that some tax preparation programs adopted, when users must check after 24 hours to see if their returns have been accepted.


答: Aside from the intent to monetize, I do not see a good reason for leaving the source code out of research papers.  There is a small movement starting that proposes supplying the source code as a rule to publishing any research that depends on software in some way, shape, or form.  You can read more about it, it's called the Science Code Manifesto.</p>


答:
The paper you cited is already 28 pages, and most of the content is about the design decisions that are related to solving the problem (stated in the title).

The code is the final step to validate the design. It is not trivial, but it is not the part that adds value in the results of the paper, especially if you were to consider the space it would take up.

Not every case is the same. Some papers do give source code, or at least pseudo code. Some editors don't allow it. Some allow it, but because of space, the authors don't include it. One journal where I published source code formatted it as "figures" and the electronic version has it as image data, even though I submitted it as text.

ContentLicense: CC BY-SA 4.0


问:
Should HTTP Verbs Be Used Semantically?
If I'm making a web application which integrates with a server-side backend, would it be considered best practice to use HTTP methods semantically? That is, for example, if I'm fetching data (e.g., to populate a menu, etc.), I would use GET, but to update data (e.g., save a record), I would use POST. (I realise there are other methods that may be even more appropriate, but we need to consider browser support.)

I can see the benefits of this in the sense that it's effectively a RESTful API, but at a slightly increased development cost. In my previous projects, I've POST'd everything: Is it worth switching to a RESTful mindset simply for the sake of best practice?

答:
Another advantage: Using GET (instead of POST for retrieval style requests) means caching is possible.

Also, a down side that might cause problems: Some proxies have patchy DELETE and PUT method support.

Title: Should HTTP Verbs Be Used Semantically?


答: When I plan out a problem in detail before starting to code it, I find that I make way fewer revisions. I think it takes a lot of discipline to not go straight into the code, but is worthwhile. Unfortunately, as you have noted, most non programmers do not understand that time away from a computer to plan and think first might actually speed up and improve a task.</p>

Title: How is your working time distributed between coding and thinking?

Body:
...in percentage. For example 60/40 or 90/10 or 100/0.

My hypothesis is that the bigger the proportion of time you spend thinking the smaller your code can be as a result (and the less time will be needed to write it down). Think more, write less, in other words. Do you think it is true?

As a side note, I think in typical software companies thinking is not part of the culture anyway: you are usually supposed to be sitting there at your computer typing something. You will almost definitely be noticed by your managers if you wander about with a blank look thinking over your next steps with your code. Too bad.


答:
Assuming that we're talking about internal applications where having users register for a free email account is inappropriate, if not every user of your application will have a corporate email address, I would simply make the email address optional.  If a user has a corporate email address, they can enter that address.  If the user doesn't have a corporate email address, they won't.

You can deal with password resets in a number of different ways without requiring an email address.  You can allow a user's manager or an administrator (i.e. helpdesk) to reset a user's password.  The user would, presumably, need to call their manager or the helpdesk to get their password reset.  You can let the user reset their own password online without email by answering some questions.  This can be the standard "security questions" that you'll find at various sites, it can be things like an employee number that is likely to be assigned whether or not the user gets an email address, it can be information about the account's activity.  Which options you use will, of course, depend on the sensitivity of the information stored in the system-- in the context of required e-learning, I'm guessing that the risk of allowing someone to compromise my account so that they can sit through a required corporate ethics training class is relatively low so the bar doesn't need to be set particularly high.

Reminders and other emails can be sent to the user if they have an email address and/or to their supervisor depending on the specific nature of the email.  That lets you suppress unnecessary emails with personal information if the user doesn't have an email address but lets you alert the supervisor if an employee is overdue for a particular training class.


答:
Read Randall LeVeque's presentation on "Top 10 Reasons to Not Share Your Code (and why you should anyway)" http://faculty.washington.edu/rjl/talks/LeVeque_CSE2011.pdf

He argues compellingly that code is analogous to proofs in Mathematics, and invites us to consider a world where proofs aren't published, because they are too long, or too ugly, or don't work in the edge cases, or might be worth money, or someone might steal it...

Basically, if you are doing science, then you should publish your code. Otherwise, you are doing alchemy and you can fly right back to the dark ages and die of plague as far as I'm concerned.


问:
Can data classes contain methods for validation?
OK, say I have a data class for a user:

```<code>public class User {
private String firstName;
private String lastName;
private long personCode;
private Date birthDate;
private Gender gender;
private String email;
private String password;
</code>```

Now let's say I want to validate email, whether names are not empty, whether birth date is in normal range, etc. Can I put that validation method in this class together with data? Or should it be in UserManager which in my case handles the lists of these users?

答: Don't put the code that actually does the validation logic in with the class itself - see SRP principle.  And what if you were to code some validation for something that might be useful to another class (for example email validation)?  Extract each type of validation logic out to its own separate class.  </p>


问:
What did programmers do before variable scope, where everything is global?
So, I am having to deal with seemingly archiac language (called PowerOn) where I have a main method, a few datatypes to define variables with, and has the ability to have sub-procedures (essentially void methods) that does not return a type nor accepts any arguements.  The problem here is that EVERYTHING is global.  I've read of these type of languages, but most books take the aproach "Ok, we use to use a horse and cariage, but now, here's a car so let's learn how to work on THAT!" We will NEVER relive those days".  I have to admit, the mind is struggling to think outside of scope and extent.

Well here I am.  I am trying to figure out how to best manage nothing but global variables across several open methods.  Yep, even iterators for for loops have to be defined globaly, which I find myself recycling in different parts of my code.

My Question:  for those that have this type experience, how did programmers deal with a large amount of variables in a global playing field?  I have feeling it just became a mental juggling trick, but I would be interested to know if there were any known aproaches.

答: In languages were all variables are global (I have used a couple) we used to use a variable naming convention.  For example: if I actually wanted to use a variable as global I might use "m_" or "_" prefix.  Of course this still relies on the developers to have this discipline</p>


问:
Classless tables possible with Datamapper?
I have an Item class with the following attributes:

itemId,name,weight,volume,price,required_skills,required_items.

Since the last two attributes are going to be multivalued, I  removed them and create new schemes like:

itemID,required_skill (itemID is foreign key, itemID and required_skill is primary key.)

Now, I'm confused how to create/use this new table. Here are the options that came to my mind:

1) The relationship between Items and Required_skills is one-to-many, so I may create a RequiredSkill class, which belongs_to Item, which in turn has n RequiredSkills. Then I can do Item.get(1).requiredskills. This sounds most logical to me and provides me methods and queries like:

```<code>sugar.components.create :raw_material => water.name
sugar.components.create :raw_material => sugarcane.name
sugar.components
sugar.components.count
</code>```

2) Since required_skills may well be thought of as constants (since they resemble rules), I may put them into a hash or gdbm database or another sql table and query from there, which I don't prefer.

My question is: is there something like a modelless table in datamapper, where datamapper is responsible from the creation and integrity of the table and allows me to query it in datamapper way, but does not require a class, like I may do it in sql?

I solved my problem by using the first way: I created a new class for each normalization process (which appears as one-to-many association above). However, I am new to object oriented programming and I don't know if creating a new class for each such normalization is the usual way to do it in datamapper, or rather a hack? This, and whether there is a better way to do this, is what I would like to know.

@JustinC

Rereading the datamapper.org Associations several times, now I see that datamapper certainly requires separate classes for joins. So you answered my question. However, since Robert Harvey placed the bounty, I feel the responsibility to wait a little more for a response about a dynamic way.

Your code complained with Cannot find the child_model Container for Item in containers. I managed to get it work with the second example of self referential association like below (putting here as a reference to others):

```<code>class Item
  class Link
    include DataMapper::Resource
    storage_names[:default] = "requirement_links"

    belongs_to :require, "Item", :key => true
    belongs_to :required, "Item", :key => true
  end

  include DataMapper::Resource

  property :id, Serial
  property :name, String, :required => true

  has n, :links_to_required_items, "Item::Link", :child_key => [:require_id]
  has n, :links_to_requiring_items, "Item::Link", :child_key => [:required_id]

  has n, :required_items, self,
    :through => :links_to_required_items,
    :via => :required
  has n, :requiring_items, self,
    :through => :links_to_requiring_items,
    :via => :require

 def require(others)
    required_items.concat(Array(others))
    save
    self
  end

  def unrequire(others)
    links_to_required_items.all(:required => Array(others)).destroy!
    reload
    self
  end
end
</code>```

So I can do:

```<code>jelly = Item.get :name => "Jelly"
sugar = Item.get :name => "Sugar"
jelly.require sugar
</code>```

to require items and:

```<code>jelly.required_items.each { |i|; puts i.name }
</code>```

to list requirements, which are really great.

After reading your answer, I see that I am yet to normalize my database schema further. To be honest, I don't see the point of defining the relationship between rawmaterials and products as self referential. I mean, if that would be a small program, I certainly would use a hash like {:jelly => ":sugar => 3, :water => 5"} to reflect required items and amounts, according to YAGNI principle. Doing it as in the 1st option already provides me queries and methods as simple as the ones provided by the self referential association. (However, I must admit that it looks more like a stored procedure rather than a method call to an object.)

So, could you very mind to explain the benefits of using a self referential association, which is difficult to understand/implement for me, compared to my simpler approach? I am new to OOP and wonder if I'm sort of undermodelling.

答:
I think what you are looking for at a SQL conceptual level is a junction table (map, link, resolver, pivot are also common names for handling many to many relationships). These junction tables are generally intermediary tables; however, additional attributes can and are often added to them.

The intention of the stated pseudo schema is a bit murky, but I think what you intended is that items can require multiple skills; items can also require other items, each with their own required skills, possibly own requisite items, and so and so forth, to many levels deep.  Beware of circular references in your [many-to-many] self-referencing relationships, such as what could happen in 'containerItemMaps'.  The following pseudo schema reflects how I envision the OP intent:

```<code>items (itemId PK, itemName, weight, volume, price)

skillMaps ( (itemId, skillId) PK)

skills (skillId PK, skillName)

containerItemMaps ( (containerItemId, componentItemId) PK)
    -- containerItemId is the parent/requiring item id
    -- componentItemId is the child/required item id
</code>```

ActiveRecord terminology suggests 'has_and_belongs_to_many' as the type of association a relationship in a data model to use in this situation.  For more information you may want to look at the page at datamapper.org Associations.  Specifically the sections titled 'Has, and belongs to many (Or Many-To-Many)' and 'Self referential many to many relationships'

Because I am not a ruby guy at this point, I can only muddle with ruby code to give an example, but this is my best approximation of what your item class would look like:

```<code># revised
class Item
   include DataMapper::Resource

   property :id, Serial

   property :name, String, :required => true
   property :weight, Float
   property :volume, Float
   property :price, Float

   has n, :componentMaps, :child_key => [:container_id]
   has n, :components, self, :through => :componentMaps, :via => :component

   has n, :skillMaps, :child_key => [:skill_id]
   has n, :skills, :through => :skillMaps, :via => :skill
end
</code>```

And the map table for self-referencing many to many items, eg.. required items:

```<code>#revised
class ComponentMap
  include DataMapper::Resource

  belongs_to :container, 'Item', :key => true
  belongs_to :component, 'Item', :key => true

  property :quantity, Integer, :default => 1
end
</code>```

For completeness:

```<code>class SkillMap
  include DataMapper::Resource

  belongs_to :item, 'Item', :key => true
  belongs_to :skill, 'Skill', :key => true

  property :mastery, Enum[:none, :aprentice, :journeyman, :craftsman, :master ], :default => :none

end

class Skill
    include DataMapper::Resource

    property :id, Serial
    property :name, String, :required => true

    has n, :skillMap, :child_key =>[:skill_id]
end
</code>```

Revisions:

Noting your concerns, I went and installed an interpruter and debugger to verify the code compiled and the emitted sql was more ideal.  Originally,  I only was going off cursory examination of documentation.  The structures above should produce generally well-structured sql from the mappings.

No matter which fields and structures you use, and no matter which ORM you pick (datamapper or some other provider), you will want to run the code through the debugger and pay attention to the sql it emits as sometimes the mappings aren't necessarily what you might first expect.

A second note about the junction tables (skillMap and componentMap): note my inclusion of additional fields (quantity and mastery).  These seem to be a natural fit for the kind of application originally described, even though not originally specified.  In a recipe, some ingredients are common among many different combinations, however the quantity from recipe to recipe varies.  For skills, like ingredients, the skill level needed to perform certain activities varies, and thus I added a mastery field to the junction table skillMap.

Of course, you probably want to add appropriate business rules and helper functions (for accessing the composition of collections programmattically such as adding and removing elements, adding and removing groups of elements, and so on).

Hopefully this demonstrates a bit better a reason why you may want to consider and use the junction table over a straight hash.  Of course each specific application is different, and perhaps the ability to specify additional aspects of the relationship between items and skill and items and other items isnt needed in your case.

Having and utilizing the extra control in defining the relationships explicitly has many advantages over relying on a dynamic/magic mapping.  In some cases, I feel it is really needed, and I think in the case of a many-to-many, this is demonstrated.  For one-to-many, the relationship is easier to infer, and using a more dynamic method of generating the mappings (eg.  has n, : <attribute group>, :through => Resource) would be acceptable.

Body:
I think what you are looking for at a SQL conceptual level is a junction table (map, link, resolver, pivot are also common names for handling many to many relationships). These junction tables are generally intermediary tables; however, additional attributes can and are often added to them.

The intention of the stated pseudo schema is a bit murky, but I think what you intended is that items can require multiple skills; items can also require other items, each with their own required skills, possibly own requisite items, and so and so forth, to many levels deep.  Beware of circular references in your [many-to-many] self-referencing relationships, such as what could happen in 'containerItemMaps'.  The following pseudo schema reflects how I envision the OP intent:

items (itemId PK, itemName, weight, volume, price)

skillMaps ( (itemId, skillId) PK)

skills (skillId PK, skillName)

containerItemMaps ( (containerItemId, componentItemId) PK)
    -- containerItemId is the parent/requiring item id
    -- componentItemId is the child/required item id

ActiveRecord terminology suggests 'has_and_belongs_to_many' as the type of association a relationship in a data model to use in this situation.  For more information you may want to look at the page at datamapper.org Associations.  Specifically the sections titled 'Has, and belongs to many (Or Many-To-Many)' and 'Self referential many to many relationships'

Because I am not a ruby guy at this point, I can only muddle with ruby code to give an example, but this is my best approximation of what your item class would look like:

# revised
class Item
   include DataMapper::Resource

   property :id, Serial

   property :name, String, :required => true
   property :weight, Float
   property :volume, Float
   property :price, Float

   has n, :componentMaps, :child_key => [:container_id]
   has n, :components, self, :through => :componentMaps, :via => :component

   has n, :skillMaps, :child_key => [:skill_id]
   has n, :skills, :through => :skillMaps, :via => :skill
end

And the map table for self-referencing many to many items, eg.. required items:

#revised
class ComponentMap
  include DataMapper::Resource

  belongs_to :container, 'Item', :key => true
  belongs_to :component, 'Item', :key => true

  property :quantity, Integer, :default => 1
end

For completeness:

class SkillMap
  include DataMapper::Resource

  belongs_to :item, 'Item', :key => true
  belongs_to :skill, 'Skill', :key => true

  property :mastery, Enum[:none, :aprentice, :journeyman, :craftsman, :master ], :default => :none

end

class Skill
    include DataMapper::Resource

    property :id, Serial
    property :name, String, :required => true

    has n, :skillMap, :child_key =>[:skill_id]
end

Revisions:

Noting your concerns, I went and installed an interpruter and debugger to verify the code compiled and the emitted sql was more ideal.  Originally,  I only was going off cursory examination of documentation.  The structures above should produce generally well-structured sql from the mappings.

No matter which fields and structures you use, and no matter which ORM you pick (datamapper or some other provider), you will want to run the code through the debugger and pay attention to the sql it emits as sometimes the mappings aren't necessarily what you might first expect.

A second note about the junction tables (skillMap and componentMap): note my inclusion of additional fields (quantity and mastery).  These seem to be a natural fit for the kind of application originally described, even though not originally specified.  In a recipe, some ingredients are common among many different combinations, however the quantity from recipe to recipe varies.  For skills, like ingredients, the skill level needed to perform certain activities varies, and thus I added a mastery field to the junction table skillMap.

Of course, you probably want to add appropriate business rules and helper functions (for accessing the composition of collections programmattically such as adding and removing elements, adding and removing groups of elements, and so on).

Hopefully this demonstrates a bit better a reason why you may want to consider and use the junction table over a straight hash.  Of course each specific application is different, and perhaps the ability to specify additional aspects of the relationship between items and skill and items and other items isnt needed in your case.

Having and utilizing the extra control in defining the relationships explicitly has many advantages over relying on a dynamic/magic mapping.  In some cases, I feel it is really needed, and I think in the case of a many-to-many, this is demonstrated.  For one-to-many, the relationship is easier to infer, and using a more dynamic method of generating the mappings (eg.  has n, : <attribute group>, :through => Resource) would be acceptable.


问:
Why don't research papers that mention custom software release the source code?
Is there a reason why the source code of software mentioned in research papers is not released? I understand that research papers are more about the general idea of accomplishing something than implementation details, but I don't get why they don't release the code.

For example, this paper ends with:

Results

The human line drawing system is implemented through the Qt framework in C++ using OpenGL, and runs on a 2.00 GHz Intel dual core processor workstation without any additional hardware assistance. We can interactively draw lines while the system synthesizes the new path and texture.

Do they keep the source code closed intentionally because of a monetization they intend to make with it, or because of copyright ?

答:
Many times the implementation (i.e. the software doesn't matter) but increasingly the implementation DOES affect the results.

Anytime the implementation matters... the source code should definitely be made available! The more that the results depend on the implementation or computational methods the more important  it becomes to post the source code.


问:
Is it dangerous to substitute unit tests for user testing?
Is it dangerous to substitute unit tests for user testing?

A co-worker believes we can reduce the manual user testing we need to do by adding more unit tests.  Is this dangerous?

Unit tests seem to have a very different purpose than user testing.  Aren't unit tests to inform design and allow breaking changes to be caught early?  Isn't that fundamentally different than determining if an aspect of the system is correct as a whole of the system?  Is this a case of substituting apples for oranges?

答:
Manual tests and unit tests are designed for different purposes*, so the answer is "yes" - substituting one for the other is a dangerous practice.

Unit tests pin down your assumptions about your code in the form of assertions that you make throughout your tests. Along with automated integration tests, unit tests help ensure that your software does what you think it should do. When done correctly, they should give you a high level of confidence in the correctness of your software. Automated testing is not as time-consuming, and much less error-prone.

However, it is often impractical to eliminate all manual testing. Specific areas of concern include integration with other products that you must use, such as installers, web browsers, and operating systems. At the minimum, someone needs to install your product before shipping, and see if it starts up, or open your product in the browser to see if the visuals remain in the right places. All of that can be automated, but the effort to make it happen does not make it worth the trouble, especially since we are talking about running through a ten-minute checklist.

If we are talking about the specific "manual tests vs. unit tests" distinction, the two concepts do not slice the space of software testing in the same dimension: in addition to unit tests, you need integration tests, regression tests, and stress tests. These are usually automated, but they can be done manually. Moreover, even the unit testing can be done manually with a small help of a software driver. That's why substituting one for the other is not a good comparison: if your manual testing covers unit testing, regression testing, stress testing, and integration testing, then replacing it with automated unit testing is not a fair exchange. If the gap is filled with some other mean of automated testing, then you can shift some burden from the manual testing to unit testing, but you would not be able to eliminate manual testing completely.

* As Jimmy Hoffa correctly notes, there are companies who (mis)use manual testing in the areas where unit testing is a lot more appropriate. In cases like that, switching to unit tests is not dangerous - in fact, it is highly desirable.


答:
Unit tests are important, not the be-all and end-all of testing. The primary purpose is not to find bugs as you write and run the test, but to highlight when expected behaviour changes in the future (and consequently regression bugs).

They certainly don't serve the same purpose that testing with users does.

Body:
Is it dangerous to substitute unit tests for user testing?

A co-worker believes we can reduce the manual user testing we need to do by adding more unit tests.  Is this dangerous?

Unit tests seem to have a very different purpose than user testing.  Aren't unit tests to inform design and allow breaking changes to be caught early?  Isn't that fundamentally different than determining if an aspect of the system is correct as a whole of the system?  Is this a case of substituting apples for oranges?


答:
Automated unit tests answer the question 'Does it do what I thought I asked it to do?' while manual testing answers the question 'Does it do something that seems sensible to a user?'.

Different questions. And if you substitute the methods for testing one for the other, you'll tend to get sub-optimal results.

Title: Is it dangerous to substitute unit tests for user testing?


问:
Suggestions for Programs to develop for learning
i wonder apart from those very simple hello world apps, what other programs should i try developing for learning. i am entering uni next year and wonder what kind of programs will be developed in that environment.

this is not really a language specific thing, but if you want to know what i use currently mainly

windows: C#/WPF - i studied java/vb etc in poly but i think C# is the way to go, maybe even F#

web: PHP/MySQL, Zend Framework/Doctrine, + HTML/CSS/JS(jQuery) of course. looking to try google app engine with python too.

for now, i am thinking of

todo lists

apps that integrate with api eg. twitter/tumblr which i use

text editor - i am currently trying to develop a text editor that uses markdown and generates html files for viewing (link to blog entry). not very pratical after i started developing it. cos when editing theres no formatting and in HTML format, i cannot edit directly

blog software (for web)

答:
(This is mostly a mata answer, rather than a project list.)

Think about why you are writing the program: Will it be useful in its own right, or is it purely to learn an aspect of a tool/API/language?

In the latter case there is a benefit to the resulting program being as short as possible, and then just kept for reference.

In the former case why not extend the learning to good practice in all respects: assume you will need to maintain and extend it. Therefore use source control, issue tracking, refactoring, unit testing, ... as all of these things are at least as important for a developer as knowing another API.

How about a feed integrator:

RSS/Atom sources

Handle twitter using its API (and do link un-shortening)

Based on source allow pluggable post processing (e.g. downloading mp3s from a podcast feed)

(The idea is to focus on integrating different implementations of the same paradigm: scheduled HTTP get of an RSS feed vs. Twitter API vs. ... all of which are underneath a stream of entries with time stamp, source and content.


问:
Do non-manager coders in their forties or older out there sometimes regret about not being managers?
And why do most programmers quit coding and become managers so early compared to other areas? You can work as a construction worker, a lawyer, researcher, writer, architect, movie director for decades if not your whole life, without quitting the favorite thing you are doing. And yet most programmers think being a manager, or better, a non-coding manager is a cool thing and the ultimate goal of the software career. It's so rare to see an ordinary coder in his 40s or 50s (or 60s!) in a typical software company. Why?

(And I am for being a coder for as long as you love doing it.)

答:
I think that the programmers who turn into mangager are simply those who are not that good at programming anyway.

If you are stuck with writing code without any intellectual level, programming quickly becomes boring, you end up doing repetitive tasks. Such programmers usually are more productive when they use tools that generates the code.

Good programmers usually advance from that point sooner or later, but bad programmers will always see coding as adding more lines to a source file. Like building a brickwall. Sooner or later they want to become managers so they can manage other "programmers" to do the boring work.

If you are a good programmer, you never get bored with programming.


问:
Are There Other Use Cases For F# Type Providers?
So I think I know the main use case for F# 3.0's Type Providers, i. e. better Intellisense when working with data stores that use them.  Are there other use cases for Type Providers or is that pretty much it? </p>

答:
I think you'll find that  there is really only 1 use case for F# Type Providers - that is, getting strongly typed data from data sources.

What I think you might be asking is what good is getting that kind of type information? Well, as you mentioned, it allows you to use intellisense better, but I think that's actually a side effect or more of a happy coincidence.

I think you'll find that the benefits of having strongly typed data available are inline with the benefits of having a strongly typed language to begin with.

Interestingly, if you take a look at the page that has (what I believe to be) the original spec/proposal/design document for type providers, you'll find:

Providing strongly typed access to these sources is a key consideration for strongly-typed programming languages, to insure low impedance mismatch in information access. At this scale, [current methods] are manual, clumsy, and do not handle the internet-scale information sources...

(emphasis and edits mine)


答:
When you say "Manual testing" I take it you mean an entire system/program?  If so this is not the same as unit testing and is more akin to user testing.  Unit tests (should) target a very specific piece of code (a method/property on a class) and test it in isolation.  Unit tests are also tests written by developers for developers.  Manual testing (I will assume you mean user based testing) is for the users of the system often done (if your lucky) by testers for the product owner/sponsor.  You should end up with a lot more unit tests than user tests because they are testing a smaller degree of scenario.  So, I would say yes it is dangerous to substitute unit tests for manual testing because in doing so you probably will end up testing less specific things which could lead to more bugs slipping through.

Its also worth noting that unit tests are quick.  Do you have time to run 1000's of manual tests everytime you make code changes?


问:
Pair programming and unit testing
My team follows the Scrum development cycle. We have received feedback that our unit testing coverage is not very good.

A team member is suggesting the addition of an external testing team to assist the core team, but I feel this will backfire in a bad way.

I am thinking of suggesting pair programming approach. I have a feeling that this should help the code be more "test-worthy" and soon the team can move to test driven development!

What are the potential problems that might arise out of pair programming??

答: If you know your unit test coverage is low you must be be using a coverage tool in the first place.  Why don't you just target the pieces of code it hightlights and write unit tests for them?</p>

Title: Pair programming and unit testing


问:
What Are Some Tips For Writing A Large Number of Unit Tests?
I've recently been tasked with testing some COM objects of the desktop app I work on. What this means in practice is writing a large number (>100) unit tests to test different but related methods and objects. While the unit tests themselves are fairly straight forward (usually one or two Assert()-type checks per test), I'm struggling to figure out the best way to write these tests in a coherent, organized manner. What I have found is that copy and Paste coding should be avoided. It creates more problems than it's worth, and it's even worse than copy-and-paste code in production code because test code has to be more frequently updated and modified.

I'm leaning toward trying an OO-approach using but again, the sheer number makes even this approach daunting from an organizational standpoint due to concern with maintenance. It also doesn't help that the tests are currently written in C++, which adds some complexity with memory management issues.

Any thoughts or suggestions?

答: Extract all setup code to "helper" classes.  This will help avoid copy/paste situations (I see devs copy/paste setup code for the test a lot).</p>


问:
Best Creational Pattern for loggers in a multi-threaded system?
This is a follow up question on my past questions :
Concurrency pattern of logger in multithreaded application

As suggested by others, I am putting this question separately.

As the learning from the last question. In a multi-threaded environment, the logger should be made thread safe and probably asynchronous (where in messages are queued while a background thread does writing releasing the requesting object thread). The logger could be signleton or it can be a per-group logger which is a generalization of the above.

Now, the question that arise is how does logger should be assigned to the object? There are two options I can think of:

1. Object requesting for the logger:

Should each of the object call some global API such as get_logger()? Such an API returns "the" singleton or the group logger. However, I feel this involves assumption about the Application environment to implement the logger -which I think is some kind of coupling. If the same object needs to be used by other application - this new application also need to implement such a method.

2. Assign logger through some known API
The other alternative approach is to create a kind of virtual class which is implemented by application based on App's own structure and assign the object sometime in the constructor.

This is more generalized method. Unfortunately, when there are so many objects - and rather a tree of objects passing on the logger objects to each level is quite messy.

My question is there a better way to do this? If you need to pick any
  one of the above, which approach is would you pick and why?

Other questions remain open about how to configure them:

How do objects' names or ID are assigned so that will be used for printing on the log messages (as the module names)

How do these objects find the appropriate properties (such as log levels, and other such parameters)

In the first approach, the central API needs to deal with all this varieties.
In the second approach - there needs to be additional work.

Hence, I want to understand from the real experience of people, as to how to write logger effectively in such an environment.

答:
This is not an easy question to answer succinctly.

First, the approach you choose depends on your very specific goals and constraints.  To what degree will you log object messages or activities?  And is logging an intrinsic activity (something that is a key, integral responsibility of the objects, or is it a secondary, really nice to have, book-keeping activity)?

There are situations where logging is intrinsic, and pervasive, but often it is a secondary concern (a book-keeping activity).  This suggests that you do not want to strongly couple the logger to each object that you are tracking.

One approach to consider is something along the lines of an application global message queue, or enterprise service bus.  Something that is closer to the first alternative rather than the second alternative you suggested.

Each object that you are interested in tracking with a logger would produce object or activity specific messages that each implement a common message interface that supports the common properties you are interested in each object recording in the log for identification.  In each object or activity specific message, define and add the specific details to that message structure.  Finally, send the message to the application's message listener queue.  If acknowledgement of receipt is required, give it to the sender, so it may continue.  Generally in a closed, single-host system, explicit acknowledgement of message receipt is not required.

In the application scoped message processor (globally available within your application), you would 'register' message handlers.  This could be done 'lazily', as needed, or pre-emptively at start up, as part of 'bootstrapping'.  Perhaps it would include a generic handler that works on any message that it receives.  It may have a handler for that common logger message.  It may also have a handler for several or all specific logger messages, if other activities need to occur in conjunction with that message.  In any regard, the message processor would successively dequeue messages, handle messages with the registered message handlers, appropriately discard them, and then grab the next message.

Part of the implication of an application scoped message processor in a multi-threaded application is that the only guarantee to message order is that the order the message enters the message queue will play a large role in the order that it appears in a particular log.

There are strategies for making message order more deterministic, but none will be perfect in all cases.  One way is to add a global message sequencer, and 'get_next' from the sequencer when crafting each and every message, then insert into an indexed queue, and wait to dequeue until the next message in the sequence arrives.  This too has implications, most notably lost or discarded messages blocking the message queue.


答:
Shorter code is generally better but not always.

Why punish a developer who has increased fluency through experience and knows exactly what they are doing? Every line of code doesn't have to be your first rodeo.

Don't assume because I'm typing that I'm not thinking. Typing doesn't take that much mental effort.

Planning is very important, but not to be confused with thinking about your code.


问:
Approach for developing software that will need to be ported to multiple mobile platforms in the future
I am currently doing the preliminary design for a new product my company will be pushing out soon. We will start on Android, but then we will need to quickly develop the IPhone, IPad.... and then the Windows 8 ports of the application.

Basically the only code that wouldn't be reusable is the view specific code and the multimedia functions. This will be an SIP client (of course the user of the app will not know this) with several bells and whistles for our own business specific purposes.

My initial thought is to develop all of the engine in C and provide a nice API for the C library since JAVA and .NET will allow native invoking, and I should just be able to directly link to the C lib in objective-C.

Is there a better approach for vast code reuse which also remains close to the native platform? I.e. I don't want dependencies such as Mono-droid and the like or complicated interpreter/translator schemes.

I don't mind re-coding the view(s) for each platform, but I do not want to have multiple versions of the main engine. Also, if I want to have some good abstraction mechanisms (like I would in say, C++) is this possible? I have read that C++ is not allowed for the IPad and Iphone devices.

I would love to handle the media decoding in the C library, but I assume that this will be platform dependent so that probably will not be an option either. Any ideas here?

答:
Since you are approaching for SIP client, and for the same PJSIP is providing a great library for using SIP feature at client end.

I have also implemented similar application, and for the same, I have create a C code which was handling all my objectives. And then as per iOS and Android platform for background tasks handling and for providing all the native UI implementation, I have done native app development in Objective-C and Java respectively.

Then in iOS, there is no problem for using C code, and for Android I have used JNI-integration.


答:
I would look into Apache Cordova (was phonegap) which allows you a cross-platform HTML5/js based GUI. The interesting part to me was that all the code is packaged into the client rather than be run as a client/webserver model (though, obviously you can still talk to a network server for data).
I know a HTML5 gui isn't going to be quite as snappy as a native one, but performance isn't a major concern for most GUIs unless you have specific requirements like gaming.

For access to your crosss-platform C API, Cordova allows you to write a plugin to call the native code.

Title: Approach for developing software that will need to be ported to multiple mobile platforms in the future

Body:
I am currently doing the preliminary design for a new product my company will be pushing out soon. We will start on Android, but then we will need to quickly develop the IPhone, IPad.... and then the Windows 8 ports of the application.

Basically the only code that wouldn't be reusable is the view specific code and the multimedia functions. This will be an SIP client (of course the user of the app will not know this) with several bells and whistles for our own business specific purposes.

My initial thought is to develop all of the engine in C and provide a nice API for the C library since JAVA and .NET will allow native invoking, and I should just be able to directly link to the C lib in objective-C.

Is there a better approach for vast code reuse which also remains close to the native platform? I.e. I don't want dependencies such as Mono-droid and the like or complicated interpreter/translator schemes.

I don't mind re-coding the view(s) for each platform, but I do not want to have multiple versions of the main engine. Also, if I want to have some good abstraction mechanisms (like I would in say, C++) is this possible? I have read that C++ is not allowed for the IPad and Iphone devices.

I would love to handle the media decoding in the C library, but I assume that this will be platform dependent so that probably will not be an option either. Any ideas here?


问:
Contract / Project / Line-Item hierarchy design considerations
We currently have an application that allows users to create a Contract. A contract can have 1 or more Project. A project can have 0 or more sub-projects (which can have their own sub-projects, and so on) as well as 1 or more Line. Lines can have any number of sub-lines (which can have their own sub-lines, and so on).

Currently, our design contains circular references, and I'd like to get away from that. Currently, it looks a bit like this:

```<code>public class Contract
{
    public List<Project> Projects { get; set; }
}

public class Project
{
    public Contract OwningContract { get; set; }
    public Project ParentProject { get; set; }
    public List<Project> SubProjects { get; set; }
    public List<Line> Lines { get; set; }
}

public class Line
{
    public Project OwningProject { get; set; }
    public List ParentLine { get; set; }
    public List<Line> SubLines { get; set; }
}
</code>```

We're using the M-V-VM "pattern" and use these Models (and their associated view models) to populate a large "edit" screen where users can modify their contracts and the properties on all of the objects. Where things start to get confusing for me is when we add, for example, a Cost property to the Line. The issue is reflecting at the highest level (the contract) changes made to the lowest level.

Looking for some thoughts as to how to change this design to remove the circular references. One thought I had was that the contract would have a Dictionary<Guid, Project> which would contain ALL projects (regardless of their level in hierarchy). The Project would then have a Guid property called "Parent" which could be used to search the contract's dictionary for the parent object. THe same logic could be applied at the Line level.

Thanks! Any help is appreciated.

答:
Here are some thoughts:

What you've described is your Model, not your ViewModel.  I've done MVVM on a tree structure before and it gets ugly fast.  Your ViewModel needs to mimic this structure, but it should use ObservableCollection instead of List, and it can be more accepting of invalid data because the data's in transition while they're editing it.

Create code that will convert from your Model to your ViewModel when you load the screen.  That allows you to implement a Cancel button that just does nothing.

I used events to propagate changes at lower levels in the tree up to higher nodes, and I would recommend not doing that.  It would be better if the child node just called a method on the parent node, like PriceChanged(decimal oldPrice, decimal newPrice)

Consider all the actions that have to propagate: new children, re-ordering children, deleting children.

Decide up front if you want to implement Undo functionality because it's extremely hard to shoehorn it in afterwards.  If you do want to have Undo, I suggest designing the tree such that every action has an easy and obvious reverse action, and then push that reverse action onto a Stack<Action>.  You might want to pass a reference to that Stack to every node in the tree so you don't have to pass the undo actions up the tree for storage.  Remember that in making every action have a reverse action, you have to think about PropertyChanged events too, so your View stays in sync.

You'll need code that validates the ViewModel before committing the changes to the Model, and you'll need code that commits the changes.

Think of the whole task as a data structure problem.  Pre-conditions, actions, post-conditions.  If you haven't used test driven development before, I suggest this would be an excellent place to start using it.


答:
Adobe's been doing work in cross-compiling ActionScript for different phone platforms. I'm Pretty sure Flash can compile down to Android and iOS now, as well as AIR (which might get you Windows Phone); I'm not sure how well this will work for SIP protocol-wise, but I'd think it'd support media pretty well. (But then I've not done any development in this area.) The Flash player has limited system access but I hear AIR's support is a lot better, so you might be able to use some decent libs.

Edit:

AIR app for Android

AIR app for iOS


答:
I'm pretty sure I understand your distinction between thinking and coding.  But, why stop thinking when you start coding?   Hopefully, typing doesn't take so much effort that you can't think at the same time.

I find that it works well to think for a while about the direction I should head, then start coding while I think about more of the less significant details.


问:
Why make the login page to a single page application a separate page?
I am wondering why it seems to be popular to have the login page of an SPA be a separate page that is not part of the SPA (as in loaded and send data through ajax requests)?

The only thing I can think of is security, but I can't think a specific security reason.  I mean the only thing that comes to mind is that if your login page is part of the SPA, it sends the username/password through ajax which can be seen by such tools like firebug or web inspector; however, even if you send it as a normal POST request, there are other tools that can easily capture this data (like fiddler, httpscoop, etc.).

Is there something I am missing?

答:
Presumably it's to save loading a bunch of client-side assets (like heavy JavaScript frameworks, images, etc) that are only required by the application.

There are more sophisticated means of achieving a similar performance goal (see "Malte Ubl & John Hjelmstad: A novel, efficient approach to JavaScript loading -- JSConf EU 2012") but this is pretty fast to implement and arguably just as efficient, especially if your web app uses almost all of your assets anyway.

You can see this in the wild in a site like the http://infogr.am beta:

http://infogr.am/login/ loads jquery, raphael, custom js and 3 css files.

http://infogr.am/beta/ (the main SPI page for the application) loads 10 javascript frameworks, 5 external css files and around 60 images.


问:
How to turn on/off code modules?
I am trying to run multiple sites using single code base and code base consist of the following module (i.e. classes)

User module

Q & A module

Faq module

and each class works on MVC pattern i.e. it consist of

Entity class

Helper class (i.e. static class)

View (i.e. pages and controls)

and let's say I have 2 sites site1.com and site2.com. And I am trying to achieve following functionality

site1.com can have User, Q & A and Faq module up and running

site2.com can have User and Q & A module live while Faq module is switched off but it can be turned-on if needed, so my query here is what is the best way to achieve such functionality

Do I introduce a flag bit that I check on every page and control belonging to that module? It's more like CMS where you can turn on/off different features. I am trying to get my head around it, please provide me with an example or point out if I am taking the wrong approach.

答:
OP has answered his own question in a way.  In many multi-homed CMS's, each 'Site' has associated 'Features'.  Some features are 'enabled'.  Some require individual settings through 'featureConfiguration'.

Checks for use, and individual 'featureConfiguration' settings, of these 'features', because they happen sitewide, only need to happen once: on app startup; thus, can be cached either to disk or to memory as part of the 'appSettings'.  They can be forced to refresh if changes in the settings would invalidate them.

Each controller or page or user control would be adorned with an attribute or property declaring itself as a member of a particular 'feature', regardless of what part of that particular piece played.  When any piece adorned with a 'feature' is requested, simply check if they are enabled, allowed, and configured before continuing to load normally.  If not, then redirect when appropriate with notification, or in the case of a control, leave the placeholder blank/empty, or add an abbreviated notification about the unavailable feature that would otherwise be there -- depending on what is ideal for that particular piece.

Some parts (controller, page, or control) might be part of multiple features, a 'shared-feature'.  Those would require additional care in determining whether the context and configuration permitted loading.

If the features were dependant on user or role, they would only need to be loaded once per session, and only need to change if during the session the settings changed to again invalidate and require a forced refresh.

Title: How to turn on/off code modules?


答:
It is not closed source. The software simply hasn't been published at all.

Short answer:

There are several reasons not to publish the software, but it's uncommon to publish the software in a closed-source manner.

Long answer:

Closed source means that the software has been published and the source-code has not. But the common case is that neither the software nor the source-code has been published.

In my experience (I work in atmospheric science), authors are very happy if you contact them and ask if you can get their software (including source-code, of course) for doing research. If I'm going to write a paper with a project based on theirs, they will at least get a citation out of it (good!), but probably get a co-authored paper out of it (because of course, they didn't document their software so that someone can use it without their help). A relatively cheap co-author paper, so that's even better.

The real question is:

Why don't they publish the software?

There are several reasons for this:

Published software needs documentation. Usually, people don't like to write documentation.

Published software may attract users. Users may have questions. This takes time (but see above).

Published software may require non-trivial maintenance.

Publishing software requires hosting.

People may feel embarrassed about the poor quality of their source code.

The list could be made longer. It deserves to be a separate question, over at Academia.SE, not here.

(Note that in my group, we do publish our software — licensed under GPL)


答: One reason to do this is because you can then use normal cookie based sessions.  User logs in, response sends cookie along with initial main page... and then all subsequent ajax calls send the cookie back to the server.  </p>

Title: Why make the login page to a single page application a separate page?

Body:
I am wondering why it seems to be popular to have the login page of an SPA be a separate page that is not part of the SPA (as in loaded and send data through ajax requests)?

The only thing I can think of is security, but I can't think a specific security reason.  I mean the only thing that comes to mind is that if your login page is part of the SPA, it sends the username/password through ajax which can be seen by such tools like firebug or web inspector; however, even if you send it as a normal POST request, there are other tools that can easily capture this data (like fiddler, httpscoop, etc.).

Is there something I am missing?