问:
Can observer pattern be represented by cars and traffic lights?
I wanted to verify with all of you, if I have a correct Observer Pattern analogy. The scenario is as follows:
Consider, at a junction, there is a traffic signal, having red, yellow and green lights respectively. There are vehicles facing the traffic signal post. When it shows red, the vehicles stop, when it shows green, the vehicles move on. In case, it is yellow, the driver must decide whether to go or to stop, depending on whether he/she has crossed the stop line or not. At the same time, there are vehicles that do not care about the signal. They would do as they like.

The similarities are that, the Traffic Signal happens to be the subject, notifying its states by glowing the appropriate lights. Those looking at it and following the signal are the ones subscribed to it, and behave according to the state of the subject. Those who do not care about it, are sort-of un-subscribed from the traffic signal.

Please tell me, if you think this is a correct analogy or not?

答:
The analogy will work, but you added more complication such as what to do at yellow light.

A simpler way is to only have green and red light; the traffic light would indicate two state changes:

red to green: traffic can go.

green to red: traffic must stop.

Note that actions that should take place as a result of this state change does not concern the observed subject (i.e. the traffic light doesn't make a car stop).

Without the subscription, interested parties would have to continuously poll the traffic light state. Therefore, those 'who are not interested' can be left out of the analogy as they're not important.

OwnerDisplayName: eeerahul

OwnerDisplayName: Jack


答: The main problem with the observer pattern and a traffic light example, as I see it, is that the observer pattern is for notifying subscribers of state changes.  Theoretically, an observer (a car in traffic) is concerned with the current state of the traffic light, not as much about when it changes.

ContentLicense: CC BY-SA 3.0

Title: Can observer pattern be represented by cars and traffic lights?

Body:
I wanted to verify with all of you, if I have a correct Observer Pattern analogy. The scenario is as follows:
Consider, at a junction, there is a traffic signal, having red, yellow and green lights respectively. There are vehicles facing the traffic signal post. When it shows red, the vehicles stop, when it shows green, the vehicles move on. In case, it is yellow, the driver must decide whether to go or to stop, depending on whether he/she has crossed the stop line or not. At the same time, there are vehicles that do not care about the signal. They would do as they like.

The similarities are that, the Traffic Signal happens to be the subject, notifying its states by glowing the appropriate lights. Those looking at it and following the signal are the ones subscribed to it, and behave according to the state of the subject. Those who do not care about it, are sort-of un-subscribed from the traffic signal.

Please tell me, if you think this is a correct analogy or not?

OwnerDisplayName: Tanzelax


答: I don't think this is a right analogy. Observers register themselves with the Subject initially. In the traffic example, this would get a bit complex because cars would need to register/unregister themselves at every traffic light based on whether the signal is green or not. For me, an appropriate analogy would be multiple threads doing their job and checking their interrupt status periodically. </p>


问:
Am I deluding myself? Business analyst transition to programmer
Current job: Working as the lead business analyst for a Big 4 firm, leading a team of developers and testers working on a large scale re-platforming project (4 onshore dev, 4 offshore devs, several onshore/offshore testers).  Also work in a similar capacity on other smaller scale projects.

Extent of my role: Gathering/writing out requirements, creating functional specifications, designing the UI (basically mapping out all front-end aspects of the system), working closely with devs to communicate/clarify requirements and come up with solutions when we hit roadblocks, writing test cases (and doing much of the testing), working with senior management and key stakeholders, managing beta testers, creating user guides and leading training sessions, providing key technical support.

I also write quite a few macros in Excel using VBA (several of my macros are now used across the entire firm, so there are maybe around 1000 people using them) and use SQL on a daily basis, both on the SQL compact files the program relies on, our SQL Server data and any Access databases I create.  The developers feel that I am quite good in this role because I understand a lot about programming, inherent system limitations, structure of the databases, etc so it's easier for me to communicate ideas and come up with suggestions when we face problems.

What really interests me is developing software.  I do a fair amount of programming in VBA and have been wanting to learn C# for awhile (the dev team uses C# - I review code occasionally for my own sake but have not had any practical experience using it).  I'm interested in not just the business process but also the technical side of things, so the traditional BA role doesn't really whet my appetite for the kind of stuff I want to do.  Right now I have a few small projects that managers have given me and I'm finding new ways to do them (like building custom Access applications), so there's a bit here and there to keep me interested.

My question is this: what I would like to do is create custom Excel or Access applications for small businesses as a freelance business (working as a one-man shop; maybe having an occasional contractor depending on a project's complexity).  This would obviously start out as a part-time venture while I have a day job, but eventually become a full-time job.  Am I deluding myself to thinking I can go from BA/part-time VBA programmer to making a full-time go of a freelance business (where I would be starting out just writing custom Excel/Access apps in VBA)?  Or is this type of thing not usually attempted until someone gains years of full-time programming experience?  And is there even a market for these types of applications amongst small businesses (and maybe medium-sized) businesses?

答:
I think you are in a good position to make a go of this.

Most of my career I have been deeply embedded in the technical side of things, however, over years of observing many projects succeed or fail I have come to the conclusion:-

If you do not understand your business users and thier requirements your project will fail.

I have never seen an exception to this rule and no amount of money, hardware or programming genius seems to make any difference. True projects with a good understanding of the requirements can fail because of badly chosen hardware, software, lack of budget or lack of skills -- but for the most part these projects can or could have been rescued.

So your good grounding in BA and requirements will give you a perspective some of your more gifted techie colleges might lack, the rest you can learn.


问:
Wisdom of using open source code in a commercial software product
I'm looking at using some open source code in my ASP.NET web app (specifically dapper).  Management is not a fan, because open source is seen as a risk that has bitten us before.  Apparently previous developers have had to rewrite things after having open-source components fail.

The pros seem to be:

It does a lot of stuff for me that would otherwise involve either lots of boilerplate code or Microsoft's recommended but slower solution (Entity Framework).

Cons:

It's complex enough that if it were to fail suddenly in production, I would be hard pressed to fix it.  However, it's in use on a much higher-traffic site than mine, so I don't think it'll end up being a high risk portion of the project.

What is the consensus here?  Is it unwise to use open source code in my project that I don't know/understand as well as I do my own code?

答:
I'll go as far as to say that if your initial reaction is to write something yourself instead of seeing if someone else has written it, you're doomed to fail. Don't take lightly all the man hours and bug fixing that has gone into the mainstream open source projects.

Once you start getting into your business domain you'll be more hard pressed to find OSS that meets your needs. But there is no need to re-implement yet another ORM product. If dapper is complex enough that you wouldn't be able to debug and fix their code how would you justify spending all the man hours writing it from scratch? Besides, you could (should?) always look outside the box at NoSQL solutions while your at it.

Even Linus admitted he attempted to find a SCM solution that met all his criteria before developing Git. At least he was able to explain why none of the existing solutions were good enough.

At some point in my life I stopped wanting to rewrite everything myself and wanted to focus on solving real world problems. Most of the problems that need to be solved in a business are domain specific. Find ways to write less code not more.


答:
jquery has the option to use MIT license, so many commercial and government websites also use jquery.
Microsoft's website use jquery too!
So the concern is licensing. Avoid using GPL/LGPL is enough.

"How long to get a fix to a reported defect?"
After reporting the bug, it may get fixed within minutes, hours, or days. For urgent situation, the staff may simply "git pull" to get the source and compile it himself.
He simply report the version like "v1.2.3-101-gd62fdae" to the management, which is traceable.

Title: Wisdom of using open source code in a commercial software product

Body:
I'm looking at using some open source code in my ASP.NET web app (specifically dapper).  Management is not a fan, because open source is seen as a risk that has bitten us before.  Apparently previous developers have had to rewrite things after having open-source components fail.

The pros seem to be:

It does a lot of stuff for me that would otherwise involve either lots of boilerplate code or Microsoft's recommended but slower solution (Entity Framework).

Cons:

It's complex enough that if it were to fail suddenly in production, I would be hard pressed to fix it.  However, it's in use on a much higher-traffic site than mine, so I don't think it'll end up being a high risk portion of the project.

What is the consensus here?  Is it unwise to use open source code in my project that I don't know/understand as well as I do my own code?


答:
Note:
I am not Microsoft employee. The opinion is completely personal. Many thoughts are from last 5-7 years of using both open source in mix with large vendors as developer.

Monoculture is good:
My personal rule for ASP.NET is to give preference to Microsoft and do not choose 3rd party code (open source or not) unless there is no other choice. Monoculture is rewarding, because you are being carried by big vendor, and quantity of users repeating the same experience is any time large enough to get help and find workaround.

Ghost towns:
The problem with open source in 2012 is that it is not 2000 or 2005 anymore. Quantity of projects keeps growing, when quantity of users, adoptions, contributors is about the same as years ago. The audiences are stretched thin. Many interesting projects became stale, abandoned. There is no such thing as open source project budget. So when interest ends, there is nobody to honestly announce that support is over and shut the lights off. The projects never die to leave the public attention focus to something better and new. So open source will always keep growing and fragmenting. Having no feedback in form of monetary reward or financial death they are undying entities, existing for the sake of eternal glory.

20 degrees of separation:
Every your adoption of new library separates you from mainstream, shifts you to minority of edge cases. After having 20 steps like choosing security configuration, using particular version, framework, plugin, etc. Your solution becomes a single globally unique combination of details. Googling will help only to proove how rare or unique the problem is. It is always some self serving problem, purely technical. Never even relevant to real business.

Quality comes from focus, money is irrelevant:
There is no stand off of commercial software vs open source. Whole community of devellopers is just one community as it always was. Large vendors simply have an advantage of aging the code longer, in better conditions, with broader audiences than open source groups.

Consensus: You asking if there is consensus. Possibly not. Unfortunately large amount of open source users are way too politicized. After all the open source is a social movement. Open source is immune to critique, because very often negative opinion will be perceived as anti-technological, personal attack. My personal consensus: stick to Microsoft.


问:
Single Responsibility Principle - How Can I Avoid Code Fragmentation?
I'm working on a team where the team leader is a virulent advocate of SOLID development principles. However, he lacks a lot of experience in getting complex software out of the door.

We have a situation where he has applied SRP to what was already quite a complex code base, which has now become very highly fragmented and difficult to understand and debug.

We now have a problem not only with code fragmentation, but also encapsulation, as methods within a class that may have been private or protected have been judged to represent a 'reason to change' and have been extracted to public or internal classes and interfaces which is not in keeping with the encapsulation goals of the application.

We have some class constructors which take over 20 interface parameters, so our IoC registration and resolution is becoming a monster in its own right.

I want to know if there is any 'refactor away from SRP' approach we could use to help fix some of these issues. I have read that it doesn't violate SOLID if I create a number of empty coarser-grained classes that 'wrap' a number of closely related classes to provide a single-point of access to the sum of their functionality (i.e. mimicking a less overly SRP'd class implementation).

Apart from that, I cannot think of a solution which will allow us to pragmatically continue with our development efforts, while keeping everyone happy.

Any suggestions ?

答:
If your class has 20 parameters in the constructor, it doesn't sound like your team quite knows what SRP is. If you have a class that does only one thing, how does it have 20 dependencies? That's like going on a fishing trip and bringing along a fishing pole, tackle box, quilting supplies, bowling ball, nunchucks, flame thrower, etc.... If you need all that to go fishing, you're not just going fishing.

That said, SRP, like most principles out there, can be over-applied. If you create a new class for incrementing integers, then yeah, that may be a single responsibility, but come on. That's ridiculous. We tend to forget that things like the SOLID principles are there for a purpose. SOLID is a means to an end, not an end in itself. The end is maintainability. If you are going to get that granular with the Single Responsibility Principle, it's an indicator that zeal for SOLID has blinded the team to the goal of SOLID.

So, I guess what I'm saying is... The SRP isn't your problem. It's either a misunderstanding of the SRP, or an incredibly granular application of it. Try to get your team to keep the main thing the main thing. And the main thing is maintainability.

Get people to design modules in a way that encourages ease of use. Think of each class as a mini API. Think first, "How would I like to use this class," and then implement it. Don't just think "What does this class need to do." The SRP does have a great tendency to make classes harder to use, if you don't put much thought into usability.

If you're looking for tips on refactoring, you can start doing what you suggested - create coarser-grained classes to wrap several others. Make sure the coarser-grained class is still adhering to the SRP, but on a higher level. Then you have two alternatives:

If the finer-grained classes are no longer used elsewhere in the system, you can gradually pull their implementation into the coarser-grained class and delete them.

Leave the finer-grained classes alone. Perhaps they were designed well and you just needed the wrapper to make them easier to use. I suspect this is the case for much of your project.

When you're finished refactoring (but before committing to the repository), review your work and ask yourself if your refactoring was actually an improvement to maintainability and ease of use.

OwnerDisplayName: Dean Chalk

ContentLicense: CC BY-SA 4.0


答:
I think it's in Martin Fowler's Refactoring that I once read a counter-rule to SRP, defining where it's going too far. There is a second question, as important as "does every class have only one reason to change?" and that is "does every change only affect one class?"

If the answer to the first question is, in every case, "yes" but the second question is "not even close," then you need to look again at how you're implementing SRP.

For example, if adding one field to a table means you have to change a DTO and a validator class and a persistence class and a view model object and so on then you've created a problem. Maybe you ought to rethink how you've implemented SRP.

Perhaps you've said that adding a field is the reason to change the Customer object, but changing the persistence layer (say from an XML file to a database) is another reason to change the Customer object. So you decide to create a CustomerPersistence object as well. But if you do it such that adding a field STILL requires a change to the CustomerPersisitence object then what was the point? You've still got an object with two reasons to change -- it just isn't Customer any more.

However, if you introduce an ORM, it's quite possible that you can make the classes work such that if you add a field to the DTO, it will automatically change the SQL used to read that data. Then you've got good reason to separate the two concerns.

In summary, here's what I tend to do: if there is a rough balance between the number of times I say "no, there is more than one reason to change this object" and the number of times I say "no, this change will affect more than one object," then I think I have the balance right between SRP and fragmentation. But if both are still high then I start to wonder if there's a different way that I can separate concerns.

Title: Single Responsibility Principle - How Can I Avoid Code Fragmentation?

Body:
I'm working on a team where the team leader is a virulent advocate of SOLID development principles. However, he lacks a lot of experience in getting complex software out of the door.

We have a situation where he has applied SRP to what was already quite a complex code base, which has now become very highly fragmented and difficult to understand and debug.

We now have a problem not only with code fragmentation, but also encapsulation, as methods within a class that may have been private or protected have been judged to represent a 'reason to change' and have been extracted to public or internal classes and interfaces which is not in keeping with the encapsulation goals of the application.

We have some class constructors which take over 20 interface parameters, so our IoC registration and resolution is becoming a monster in its own right.

I want to know if there is any 'refactor away from SRP' approach we could use to help fix some of these issues. I have read that it doesn't violate SOLID if I create a number of empty coarser-grained classes that 'wrap' a number of closely related classes to provide a single-point of access to the sum of their functionality (i.e. mimicking a less overly SRP'd class implementation).

Apart from that, I cannot think of a solution which will allow us to pragmatically continue with our development efforts, while keeping everyone happy.

Any suggestions ?


答:
I think the analogy is not the best one. When you drive a car you really don't care about EVERY traffic lights state changes, you only care about the CURRENT state of the next traffic light you will encounter.
A better one, in my opinion, would be economic tv channels and Stock Exchange. Stock Exchange would be your subject and tv channels your observers. They actually NEED to be noticed at every state change of your subject, in real time. </p>


问:
Is learning how to use C (or C++) a requirement in order to be a good (excellent) programmer?
When I first started to learn how to program, real programmers could write assembly in their sleep. Any serious schooling in computer science would include a hefty bit of training and practice in programming using assembly. That has since changed, to the point where I see Computer Science degrees with assembly, if included at all, is relegated to one assignment, and one chapter, for a total of two weeks' work out of 4 years' schooling.

C/C++ programming seems to have followed a similar path. I'm no longer surprised to interview university graduates who have not spent more than two weeks programming in C++, and have only read of C in a book somewhere. While the most serious CS degrees still seem to include significant time learning and using one or both of the languages, the trend is clearly towards less enforced C/C++ in school.

It's clearly possible to make a career producing good work without ever reading or writing a single line of C or C++ code.

Given all of that, is learning the two languages worth the effort? Are they at all required to excel? (beyond the obvious, non-language specific advice, such as "a good selection of languages is probably important for a comprehensive education", and "it's probably a good idea to keep trying out and learning new languages throughout a programmers' career, just to stretch the gray cells")

答: Having proficiently used c,c++,assembly, and Lisp I would say it doesn't make sense to have to learn any particular language at all to be a good programmer.  My experiences with what makes a good programmer is being able to think in a way that solve problems.  Languages just allow you to express your problem solving skills.  For example the simplicity of C allows you to easily express algorithms, while Lisp allows you to solve problems recursively.  So a language doesn't make you a programmer.  You have to be a problem solver first before you become a good programmer.  Languages are just tools you use to solve problems.  For example I almost applied for a patent on a logical programming implementation I thought of where the only way to express that implementation was through the use of assembly language since no compilers existed that could implement it.  </p>

ContentLicense: CC BY-SA 2.5


问:
Is it a bad practice to store large files (10 MB) in a database?
I am currently creating a web application that allows users to store and share files, 1 MB - 10 MB in size.

It seems to me that storing the files in a database will significantly slow down database access.

Is this a valid concern? Is it better to store the files in the file system and save the file name and path in the database? Are there any best practices related to storing files when working with a database?

I am working in PHP and MySQL for this project, but is the issue the same for most environments (Ruby on Rails, PHP, .NET) and databases (MySQL, PostgreSQL).

答:
Reasons in favor of storing files in the database:

ACID consistency including a rollback of an update which is complicated when the files are stored outside the database. This isn't to be glossed over lightly. Having the files and database in sync and able to participate in transactions can be very useful.

Files go with the database and cannot be orphaned from it.

Backups automatically include the file binaries.

Reason against storing files in the database:

The size of a binary file differs amongst databases. On SQL Server, when not using the FILESTREAM object, for example, it is 2 GB. If users need to store files larger (like say a movie), you have to jump through hoops to make that magic happen.

Increases the size of the database. One general concept you should take to heart: The level of knowledge required to maintain a database goes up in proportion to the size of the database. I.e., large databases are more complicated to maintain than small databases. Storing the files in the database can make the database much larger. Even if say a daily full backup would have sufficed, with a larger database size, you may no longer be able to do that. You may have to consider putting the files on a different file group (if the database supports that), tweak the backups to separate the backup of the data from the backup of the files etc. None of these things are impossible to learn, but do add complexity to maintenance which means cost to the business. Larger databases also consume more memory as they try to stuff as much data into memory as possible.

Portability can be a concern if you use system specific features like SQL Server's FILESTREAM object and need to migrate to a different database system.

The code that writes the files to the database can be a problem. One company for whom I consulted not so many moons ago at some point connected a Microsoft Access frontend to their database server and used Access' ability to upload "anything" using its Ole Object control. Later they changed to use a different control which still relied on Ole. Much later someone changed the interface to store the raw binary. Extracting those Ole Object's was a new level of hell. When you store files on the file system, there isn't an additional layer involved to wrap/tweak/alter the source file.

It is more complicated to serve up the files to a website. In order to do it with binary columns, you have to write a handler to stream the file binary from the database. You can also do this even if you store file paths but you don't have to do this. Again, adding a handler is not impossible but adds complexity and is another point of failure.

You cannot take advantage of cloud storage. Suppose one day you want to store your files in an Amazon S3 bucket. If what you store in the database are file paths, you are afforded the ability to change those to paths at S3. As far as I'm aware, that's not possible in any scenario with any DBMS.

IMO, deeming the storage of files in the database or not as "bad" requires more information about the circumstances and requirements. Are the size and/or number of files always going to be small? Are there no plans to use cloud storage? Will the files be served up on a website or a binary executable like a Windows application?

In general, my experience has found that storing paths is less expensive to the business even accounting for the lack of ACID and the possibility of orphans. However, that does not mean that the internet is not legion with stories of lack of ACID control going wrong with file storage but it does mean that in general that solution is easier to build, understand and maintain.


答:
Assumed the licensing issues are no problem here: having a quick look at Dapper, I noticed it had just 2255 line of well-documented, readable code. That is

big enough that you can invest several days or weeks to produce code of comparable quality doing the same

small enough that you can understand what it does and fix any bugs in that code if they appear in production

If you are going to write something like that on your own and "reinvent the wheel", you have a much higher risk that your own code will show up bugs in production, and you will be really "hard pressed to fix them" either.

What you have to do here, however, if you introduce such a piece of open source into your project, then you have to take the full responsibility for that code, just as if you had written it by yourself. Make sure the code is in a state you can maintain it, if necessary. Don't blame "the authors" of that code if something does not work as expected.

In one of our projects, we, too, introduced some open source components, from sizes small as Dapper to libraries which had around 20K to 30K lines of code. We had always to make some changes, fix some bugs, downsize something etc., but that was ok, since we expected that. Even the time for the debugging included, using open source saved us a lot of work.

One thing to think about here: in your case you mention that there is a broadly accepted alternative from a big vendor available (MS Entity Framework, for which you don't have to pay any extra license fees!). You don't want to use it because of performance considerations. I seriously recommend not to let performance be the only or primary point to be considered. The questions you should ask here: has Dapper all the functionality you need now and for the expected lifetime of your software? Or can you foresee that you will reach the limits of Dapper quickly, and you will have to add a lot of missing functionality around it, what you probably would not have to if you had decided to use EF in the first place? If the latter is the case, I would recommend not to use Dapper. Also ask yourself: is EF really not fast enough for your application, whilst Dapper is?


问:
Are there any statistics that show the popularity of Git versus SVN?
I'm writing an essay, and would like to have some empiric evidence, perhaps longitudinal data where the popularity of these technologies is compared over a period of some years.

Are there any statistics that show the popularity of Git versus SVN?

答:
Sites such as Ohloh and Github only give you an indication of what's going on in the open source world, and take no account of the (much larger) commercial/industrial/closed source side of things; Google Trends gives all sorts of other hits for "subversion" and "git" (both of which have other meanings outside the SCM world).

The best indicator you're likely to get at the moment is the Eclipse Community Survey. This is conducted every year by the Eclipse Foundation and since Eclipse users tend to be Java developers of all shapes and sizes, it targets a fairly representative cross-section of the software development community as a whole. The only problem is that Windows developers are probably under-represented, but nevertheless, it still gives a reasonable guide as to where things are at, and since it's been going for a few years now, you can start to see what trends are beginning to emerge.

Their figures for Git are:

2009: 2.4%

2010: 6.8%

2011: 12.8%

2012: 27.6%

2013: 30.3%

2014: 33.3%

For Subversion:

2009: 57.5%

2010: 58.3%

2011: 51.3%

2012: 46.0%

2013: 37.8%

2014: 30.7%

The 2012 survey report is due out in the next couple of weeks. In the meantime, another data point we can consider is the growth of Github. Back in August, I observed that it had just under a million users, though I didn't record the exact figure. This has grown to 1,654,419 users as of the time of writing: an increase of at least 66% in 288 days, or about 90% a year. If we assume that the growth of Github is indicative of the rate of increase of Git usage industry-wide (a potentially dubious assumption: see comments below), that would suggest that Git adoption is currently somewhere between 20% and 25% industry-wide, and on course to overtake Subversion to the number 1 slot sometime in the next 12-18 months or so.

Update: the results of the 2012 Eclipse Community Survey give Git/Github a total market share of 27.6%. This is much more than I was expecting (I thought it would be low 20s at best) and means that it now almost certainly has significant penetration into corporate and enterprise environments. Subversion is still in the number 1 slot for now, but given these figures, I would be very surprised indeed if this remains the case this time next year.

Update: results have been added for the 2013 Eclipse Community Survey. Git is now at about equal usage with subversion (36.3% vs 37.8% respectively), and if the trend continues it will easily be in first place next year's survey results.

Update: The results of the 2014 Eclipse Community Survey show Git (33.3%) surpassing Subversion (30.7%) as expected from the trend in the previous year.

Sources:

http://www.eclipse.org/org/press-release/Eclipse_Survey_2009_final.pdf

http://www.eclipse.org/org/community_survey/Eclipse_Survey_2010_Report.pdf

http://www.eclipse.org/org/community_survey/Eclipse_Survey_2011_Report.pdf

http://ianskerrett.wordpress.com/2012/06/08/eclipse-community-survey-result-for-2012/

http://www.slideshare.net/IanSkerrett/eclipse-survey-2013-report-final/14

http://eclipse.dzone.com/articles/eclipse-community-survey-2014


问:
Bug fixing approach
I have been working on a database project, and I recently received a bug report for the remote execution of some queries.

Usually, you try to find out the actual cause for the bug to occur and then fix it.

But sometimes what I do when I'm fed up of doing some research (and can't find suitable information on the internet) is just change the logic, which takes me much less time compared to the other option.

Is this approach correct, or should I try to fix the original bug involving more R&D?

答:
Your approach is valuable as long as you can justify why it works. You seem to be unsure enough to ask here.

You performed one part of the justification: check that the buggy query (failing test) is no longer buggy (test passes).

The other part of the justification is to check that no other query (every test) becomes buggy (all tests pass).

Only then you can trust your approach.

Title: Bug fixing approach


问:
On what name should I claim copyright in open source software?
When I want to use the Apache 2.0 licence in my project, I should include this in the comments of my source code:

```<code>Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
</code>```

What name should I fill in for [name of copyright owner]? I am currently working alone on this project, but I'm going to release the source code so there might be other contributors in the near future.

答:
As long as you have written the code, and you don't work for anyone else, insert "your name" - you have the copyright as long as you don't give it to someone else. When others contribute, you can still change it later and add their names, too (or let them add their names by themselves).

Disclaimer: I am not a lawyer.


问:
Why is the "kill" command called so?
Why was it decided to call the kill command "kill"?

I mean, yes, this utility is often used to terminate processes, but it can actually be used to send any signal.

Isn't it slightly confusing? Maybe there are some historical reasons.

All I know from man kill that this command appeared in Version 3 AT&T UNIX.

答:
This is Unix.

kill is able not to kill a process.

mv is able to rename and not only move files from one place to another.

touch is able to create a file and not only change its last modification time.

od means Octal Dump, but is able to perform many more kinds of dumps.

yes is able to output no.

More exotic:

grep is named after the ed command that perform the same operation: g/re/p

awk is named after its authors: Aho, Weinberger and Kernighan.

yacc means Yet Another Compiler Compiler. Note that bison is the GNU yacc.

Title: Why is the "kill" command called so?


答:
Unix version 7 kill manual page states:

```<code>kill - terminate a process with extreme prejudice
</code>```

and

```<code>This will kill processes that do not catch the signal; in particular `kill -9 ...'  is a sure kill.
</code>```

There would be good no reason not to call that command kill which is certainly the best metaphor available.

Title: Why is the "kill" command called so?

Body:
Why was it decided to call the kill command "kill"?

I mean, yes, this utility is often used to terminate processes, but it can actually be used to send any signal.

Isn't it slightly confusing? Maybe there are some historical reasons.

All I know from man kill that this command appeared in Version 3 AT&T UNIX.

Body:
Unix version 7 kill manual page states:

kill - terminate a process with extreme prejudice

and

This will kill processes that do not catch the signal; in particular `kill -9 ...'  is a sure kill.

There would be good no reason not to call that command kill which is certainly the best metaphor available.


问:
Separate Pages Separate Loads?
Working on two formats throughout our website - PC and mobile. Each request will have a check who the client is. Then, two methods seem optional:

Render the page accordingly.

Redirect to a parallel site

Is there a difference in server load (i.e. maybe 2 has less load because requests are actually pointed at different pages)? Whereas, it seems having a single page would be easier to maintain.

答:
Althoug I'm no expert on the subject, I guess I'd go with a single page, and only switch the css used by the page. First reason is that you will have less work to do to maintain your website, compared to having two parallel sites. Second reason is better explain with this XKCD comic. Having one website with different css means that users will always have the same experience.

And using this technique, you can still have desktop only features by hiding/not loading the content if the user has a smartphone.

In term of server load, the CSS should get cached (depending on the browser) so there won't be any server overload.

Title: Separate Pages Separate Loads?


答:
Microsoft released a white paper about this a few years back. It concentrates on SqlServer, but you may find some interesting information in there:

To BLOB or not to BLOB? Large Object Storage in a Database or a Filesystem?

A very concise version of their conclusion is:

When comparing the NTFS file system and SQL Server 2005, BLOBS smaller than 256KB are more efficiently handled by SQL Server, while NTFS is more efficient for BLOBS larger than 1MB.

I would recommend that you write some small tests for your particular use case. Bear in mind that you have to beware of caching effects. (I was amazed the first time I got save-to-disk speeds that seemed to have higher throughputs than was physically possible!)

Title: Is it a bad practice to store large files (10 MB) in a database?

Body:
I am currently creating a web application that allows users to store and share files, 1 MB - 10 MB in size.

It seems to me that storing the files in a database will significantly slow down database access.

Is this a valid concern? Is it better to store the files in the file system and save the file name and path in the database? Are there any best practices related to storing files when working with a database?

I am working in PHP and MySQL for this project, but is the issue the same for most environments (Ruby on Rails, PHP, .NET) and databases (MySQL, PostgreSQL).


答:
"Fixing" a bug by fiddling with things and changing them so that the non-understood problem goes away is a terrible strategy.

It is bad because:

a) you've learned nothing about a potential weakness in your system or the software/frameworks/resources you're using

b) by swapping things around you might just introduce new issues

If you're on a really tight deadline and your approach is your best hope in the time available, then it can get you out of a tight spot (possibly). But I'd only do that as a last chance option, and then go back and find out what the problem is after the deadline.

This actually remind me of an ex-colleague who didn't quite understand boolean logic (yes, really). He'd jigger around with his boolean expressions (nesting ands and ors) until something worked. Even if you can get something working by doing such things, you've not understood the problem, and you're also relying to a certain degree on luck.

Title: Bug fixing approach

Body:
I have been working on a database project, and I recently received a bug report for the remote execution of some queries.

Usually, you try to find out the actual cause for the bug to occur and then fix it.

But sometimes what I do when I'm fed up of doing some research (and can't find suitable information on the internet) is just change the logic, which takes me much less time compared to the other option.

Is this approach correct, or should I try to fix the original bug involving more R&D?


问:
How to store cache?
The data in my website is stored in many different tables(friends,relatives,etc) and every-time I have to query each and every table. But all this data is subject centric. E.g. data for a person is of the form

```<code>data[301]={
        "pid"=>301,
        "friends"=>array(),
        "relatives"=>array(),
        "interests"=>array()
        }
</code>```

So I want to store it in a cache in the db (and hence query only one table). But how do I store such data? should I be using blobs?

答:
I don't suggest you to use another table as a cache.

If you want to cache data, It's more appropriate use a technology like memcached (http://memcached.org/).
This specialized storage should operate near your data access layer.

In addition I'll use a IoC/DI framework to integrate the code devoted to manage caching into the existing data layer.
In this way the code used to manipulate data should not change at all.

Title: How to store cache?


答:
You could store is in any serialized form, json or PHP serialize() when you are using PHP.

I think you always need the whole blob of data when reading and using the cache so it does not care if you store it this way. Also it is fast accessible when you have a good primary key.

You could also consider using memcache which stores it in memory and autoexpires the cache if needed. It uses the same key / value solution.

Title: How to store cache?

Body:
The data in my website is stored in many different tables(friends,relatives,etc) and every-time I have to query each and every table. But all this data is subject centric. E.g. data for a person is of the form

```<code>data[301]={
        "pid"=>301,
        "friends"=>array(),
        "relatives"=>array(),
        "interests"=>array()
        }
</code>```

So I want to store it in a cache in the db (and hence query only one table). But how do I store such data? should I be using blobs?


问:
How would you represent an object that can be of multiple types, when storing it as a document in MongoDB?
Somewhat related to this question, say that I have an object category which, depending on which type of object I have, has different restrictions on what it contains.  (if you can reword the previous sentence to make more sense I'd appreciate it)

For example

```<code>var SomeSchema = new Schema({
  _id: ObjectID,
  [... large number of common fields ...]
  type: //Restricted somehow to members of a fixed array
  data: //depending on type, this might be restricted - sometimes an integer, sometimes array, etc...
});
</code>```

What's the idiosyncratic method for defining this type of schema? Is it appropriate to define a single schema, and handle the types inside of it's members, or am I better off with separate schema for each type?

答:
I think it is difficult to do that in mongodb, mongodb is more a 'dumb' storage of objects and does no interpretation of what it is storing. (Of course is does some smart things needed for indexing etc. but not on the domain model level)

You need to save a type field into the object and write code that reads the object from mongo and does some special things based on the type value. So the domain model should handle all special restrictions that are needed and throws an exception when something is wrong.


答:
I would be pragmatic about it, and follow the "don't optimize yet" principle. Make the solution that makes sense at the moment, and one that you have the development resources to properly implement. There are plenty of potential problems. But those do not necessarily become real problems. E.g. It would probably not be a problem if you have 100 users. It might be a problem if you have 100,000 or 10,000,000 users. But in the latter case, there should be a basis for more development resources to deal with all the issues.

But storing the data in the database does relieve you from dealing with other problems, e.g. where should the files be stored, how should they be backed up, etc. Since you are writing a web application it would be a very good idea for security reasons to make sure that the process hosting the application does not have write access to the file system, so you need to configure the server so that process has read/write access to the folder where data is stored.

I would personally choose to store the data in the database, but make sure that the BLOBS are not read until they are really needed, i.e. no "SELECT * FROM ..." executed on those tables containing blogs. And I would make sure that the design makes it easy to move the data out of the database, into the filesystem, if you do get performance problems. For example store the file information in a separate File table, thus keeping the file information away from other business entities.

Assuming that you have a File class for representing a file read in the database, then the coding impact of later moving it out will be minimal.


问:
What is the algorithm for expiring items in key-value storage?
I was thinking on how current key-value storages implement "expire date" for items. Currently I have 2 variants for that in my mind:

they don't do anything (keep expired data), and only do check when you do, for example, GET by some key. The problem here is that if you are limited in memory, expired items won't be deleted.

they keep additional data structures to be able to get "earliest to expire". I see it can be done with something like this:

```<code>storage_data = dict(key -> [value, expire_timestamp])
expire_tree = SomeBinaryLikeTree(expire_timestamp -> [keys])
</code>```

答:
I assume the key-value storage is too large to just iterate over all k-v-pairs to find out which can be expired. I also assume that each read access refreshes the expiry timestamp, so only items which haven't been accessed for some time are expired.

The challenge is to efficiently find all records which can be expired (whenever cleanup is due), but also efficiently refresh the expiry timestamp on every read access (so we must find the key in the structure used for expiration).

My proposal: group expiry_timestamps into buckets; for example, if items
live for 8 hours, make one bucket per hour. Those buckets are kept in a linked list; when expiration happens, the first bucket is emptied and the list reduced. The number of buckets is lifespan/cleanup interval.
Each bucket contains a hashSet of all keys that should be expired. Iteration over all keys in a hashset is efficient enough.

During read access, the program checks which bucket the key currently is in and which bucket it now belongs to. In most cases, it's the same bucket, so no further action is necessary. Otherwise, remove the key from the old bucket (removing from a hash set is efficient) and insert it into the new bucket.

```<code>   +--------------+   +--------------+   +--------------+
-->+ Expiry 08:00 +-->+ Expiry 09:00 +-->+ Expiry 10:00 +
   | KeySet       |   | KeySet       |   | KeySet       |
   +--------------+   +--------------+   +--------------+
</code>```

Body:
I assume the key-value storage is too large to just iterate over all k-v-pairs to find out which can be expired. I also assume that each read access refreshes the expiry timestamp, so only items which haven't been accessed for some time are expired.

The challenge is to efficiently find all records which can be expired (whenever cleanup is due), but also efficiently refresh the expiry timestamp on every read access (so we must find the key in the structure used for expiration).

My proposal: group expiry_timestamps into buckets; for example, if items
live for 8 hours, make one bucket per hour. Those buckets are kept in a linked list; when expiration happens, the first bucket is emptied and the list reduced. The number of buckets is lifespan/cleanup interval.
Each bucket contains a hashSet of all keys that should be expired. Iteration over all keys in a hashset is efficient enough.

During read access, the program checks which bucket the key currently is in and which bucket it now belongs to. In most cases, it's the same bucket, so no further action is necessary. Otherwise, remove the key from the old bucket (removing from a hash set is efficient) and insert it into the new bucket.

   +--------------+   +--------------+   +--------------+
-->+ Expiry 08:00 +-->+ Expiry 09:00 +-->+ Expiry 10:00 +
   | KeySet       |   | KeySet       |   | KeySet       |
   +--------------+   +--------------+   +--------------+


答:
The problem of deleting expired entries in cache is very much an equivalent of garbage collection, minus whole complexity of reference counting.

People at Nasza-Klasa have proposed O(1) algorithm for Memcache as follows:

It seems that many people believed for some reason that freeing
  expired entries can not be performed in O(1), or even that it requires
  Omega(N) operations. Using a heap, or other priority queue data
  structures can obviously give you O(log N), but the patch below aims
  at O(1).  This is achieved by having one bucket for each second, and
  by putting  each entry in a proper bucket by looking at the expiration
  time. Then  at each second we just free elements from the next bucket.
  This is obviously O(1) amortized time, but it can happen that you have
  a lot of elements that expire at the very same moment, so the patch
  offers a fixed limit for number of operations that you are willing to
  perform per one request, to make the garbage collection run smoother.

See whole proposal with attached code.

Title: What is the algorithm for expiring items in key-value storage?

Body:
I was thinking on how current key-value storages implement "expire date" for items. Currently I have 2 variants for that in my mind:

they don't do anything (keep expired data), and only do check when you do, for example, GET by some key. The problem here is that if you are limited in memory, expired items won't be deleted.

they keep additional data structures to be able to get "earliest to expire". I see it can be done with something like this:

```<code>storage_data = dict(key -> [value, expire_timestamp])
expire_tree = SomeBinaryLikeTree(expire_timestamp -> [keys])
</code>```


问:
Is the puts function of ruby a method of an object?
I'm trying to understand how the puts function fits in Ruby's "Everything is an object" stance.

Is puts is the method of a somehow hidden class/object? Or is it a free-floating method, with no underlying object?

答:
I'm trying to understand how the puts function fits in Ruby's "Everything is an object" stance.

First off, puts is not a function. It's sole purpose is to have a side-effect (printing something to the console), whereas functions cannot have side-effects … that's the definition of "function", after all.

Ruby doesn't have functions. It only has methods. Thus, puts is a method.

Is puts is the method of a somehow hidden class/object?

No, it's just a boring old instance method of a boring old class. (Well, a boring old instance method of a boring old mixin, actually, but a mixin is just a class which abstracts over its superclass.)

Kernel is mixed into Object, which is the (default) superclass of all objects (modulo BasicObject, of course), thus, Kernel is a common superclass (or "supermixin", if you prefer) of (almost) all objects in Ruby.

Or is it a free-floating method, with no underlying object?

There is no such thing. A method is always associated with an object (the receiver of the message), that's what makes it a "method". (At least in OO parlance. In ADT-oriented languages, the word "method" means something slightly different.)

By the way, the easiest option is always to just ask Ruby herself:

```<code>method(:puts).owner
# => Kernel
</code>```

Body:
I'm trying to understand how the puts function fits in Ruby's "Everything is an object" stance.

First off, puts is not a function. It's sole purpose is to have a side-effect (printing something to the console), whereas functions cannot have side-effects … that's the definition of "function", after all.

Ruby doesn't have functions. It only has methods. Thus, puts is a method.

Is puts is the method of a somehow hidden class/object?

No, it's just a boring old instance method of a boring old class. (Well, a boring old instance method of a boring old mixin, actually, but a mixin is just a class which abstracts over its superclass.)

Kernel is mixed into Object, which is the (default) superclass of all objects (modulo BasicObject, of course), thus, Kernel is a common superclass (or "supermixin", if you prefer) of (almost) all objects in Ruby.

Or is it a free-floating method, with no underlying object?

There is no such thing. A method is always associated with an object (the receiver of the message), that's what makes it a "method". (At least in OO parlance. In ADT-oriented languages, the word "method" means something slightly different.)

By the way, the easiest option is always to just ask Ruby herself:

method(:puts).owner
# => Kernel


问:
Web Service - SOAP
My experience with web services is slim and I'm trying to understand this a little bit more.
I have done for instance a web service using visual studio. In order to use it, I add a web service reference in my projects and this creates a proxy and the use is pretty simple. Does this use SOAP?

I ask this because i will be now facing a web service that i must communicate using SOAP with attachements and i'm trying to understand the concept behind this and the difference to what i have done so far. Will the proxy still be viable or do i need to create the XML by hand and post it to the web service?

This concepts still confuse and so any help is appreciated.

EDIT: I'm not developing the service, i will be just using it.

答:
The "Add web service reference" was a feature included in the first Visual Studio.NET (2002). As far as I recall, this default way of consuming web services does not deal with attachments. I think that you can create extensions that can handle attachments, but I think it gets a little hairy.

Since then a new communication framework, WCF, has been included in the .NET framework. This is a lot better at consuming a range of different types of services. I would suggest that you start by investigating this framework, and learn how you can consume a SOAP web service using this framework. I don't know how this copes with attachments in SOAP, but I think that it can handle them.

Title: Web Service - SOAP


答:
Just because a system is complex doesn't mean that you have to make it complicated. If you have a class that has too many dependencies (or Collaborators) like this:

```<code>public class MyAwesomeClass {
    public class MyAwesomeClass(IDependency1 _d1, IDependency2 _d2, ... , IDependency20 _d20) {
      // Assign it all
    }
}
</code>```

...then it got way too complicated and you're not really following SRP, are you? I'd bet if you wrote down what MyAwesomeClass does on a CRC card it wouldn't fit on an index card or you have to write in really tiny illegible letters.

What you have here is that your guys only followed the Interface Segregation Principle instead and may have taken it to an extreme but that is a whole other story. You could argue that the dependencies are domain objects (which happens) however having a class that handles 20 domain objects at the same time is stretching it a bit too far.

TDD will provide you a good indicator of how much a class does. Bluntly put; if a test method has setup code that takes forever to write (even if you refactor the tests) then your MyAwesomeClassprobably has too much things to do.

So how do you solve this conundrum? You move the responsibilities to other classes. There are some steps you can take on a class that has this problem:

Identify all the actions (or responsibilities) that your class does with it's dependencies.

Group the actions according to closely related dependencies.

Redelegate! I.e. refactor each of the identified actions to either new or (more importantly) other classes.

An abstract example on refactoring responsibilities

Let C be a class that has several dependencies D1, D2, D3, D4 that you need to refactor to use less. When we identify what methods that C calls on the dependencies we can make a simple list of it:

D1 - performA(D2), performB()

D2 - performD(D1)

D3 - performE()

D4 - performF(D3)

Looking at the list we can see that D1 and D2 are related to each other as the class need them together somehow. We can also see that D4 needs D3. So we have two groupings:

Group 1 - D1 <-> D2

Group 2 - D4 -> D3

The groupings are an indicator that the class now has two responsibilities.

Group 1 - One for handling the calling two objects that need each other. Maybe you can let your class C eliminate the need of handling both dependencies and leave one of them handling those calls instead. In this grouping, it is obvious that D1 could have a reference to D2.

Group 2 - The other responsibility needs one object to call another. Can't D4 handle D3 instead of your class? Then we probably can eliminate D3 from the class C by letting D4 do the calls instead.

Don't take my answer as set in stone as the example is very abstract and makes a lot of assumptions. I'm pretty sure there are more ways to refactor this, but at least the steps might help you get some kind of a process to move responsibilities around instead of splitting classes up.

Edit:

Among the comments @Emmad Karem says:

"If your class has 20 parameters in the constructor, it doesn't sound like your team quite knows what SRP is. If you have a class that does only one thing, how does it have 20 dependencies? " - I think that If you have a Customer class, it is not strange to have 20 parameters in the constructor.

It is true that DAO objects tend to have a lot of parameters, which you have to set in your constructor, and the parameters are usually are simple types such as string. However in the example of a Customer class, you can still group it's properties inside other classes to make things simpler. Such as having an Address class with streets and a Zipcode class that contains the zipcode and will handle business logic such as data validation as well:

```<code>public class Address {
    private String street1;
    //...

    private Zipcode zipcode;

    // easy to extend
    public bool isValid() {
        return zipcode.isValid();
    }
}

public class Zipcode {
    private string zipcode;
    public bool isValid() {
        // return regex match that zipcode contains numbers
    }
}
</code>```

This thing is discussed further in the blog post "Never, never, never use String in Java (or atleast often)". As an alternative of using constructors or static methods to make the sub objects easier to create you could use a fluid builder pattern.

Body:
Just because a system is complex doesn't mean that you have to make it complicated. If you have a class that has too many dependencies (or Collaborators) like this:

public class MyAwesomeClass {
    public class MyAwesomeClass(IDependency1 _d1, IDependency2 _d2, ... , IDependency20 _d20) {
      // Assign it all
    }
}

...then it got way too complicated and you're not really following SRP, are you? I'd bet if you wrote down what MyAwesomeClass does on a CRC card it wouldn't fit on an index card or you have to write in really tiny illegible letters.

What you have here is that your guys only followed the Interface Segregation Principle instead and may have taken it to an extreme but that is a whole other story. You could argue that the dependencies are domain objects (which happens) however having a class that handles 20 domain objects at the same time is stretching it a bit too far.

TDD will provide you a good indicator of how much a class does. Bluntly put; if a test method has setup code that takes forever to write (even if you refactor the tests) then your MyAwesomeClassprobably has too much things to do.

So how do you solve this conundrum? You move the responsibilities to other classes. There are some steps you can take on a class that has this problem:

Identify all the actions (or responsibilities) that your class does with it's dependencies.

Group the actions according to closely related dependencies.

Redelegate! I.e. refactor each of the identified actions to either new or (more importantly) other classes.

An abstract example on refactoring responsibilities

Let C be a class that has several dependencies D1, D2, D3, D4 that you need to refactor to use less. When we identify what methods that C calls on the dependencies we can make a simple list of it:

D1 - performA(D2), performB()

D2 - performD(D1)

D3 - performE()

D4 - performF(D3)

Looking at the list we can see that D1 and D2 are related to each other as the class need them together somehow. We can also see that D4 needs D3. So we have two groupings:

Group 1 - D1 <-> D2

Group 2 - D4 -> D3

The groupings are an indicator that the class now has two responsibilities.

Group 1 - One for handling the calling two objects that need each other. Maybe you can let your class C eliminate the need of handling both dependencies and leave one of them handling those calls instead. In this grouping, it is obvious that D1 could have a reference to D2.

Group 2 - The other responsibility needs one object to call another. Can't D4 handle D3 instead of your class? Then we probably can eliminate D3 from the class C by letting D4 do the calls instead.

Don't take my answer as set in stone as the example is very abstract and makes a lot of assumptions. I'm pretty sure there are more ways to refactor this, but at least the steps might help you get some kind of a process to move responsibilities around instead of splitting classes up.

Edit:

Among the comments @Emmad Karem says:

"If your class has 20 parameters in the constructor, it doesn't sound like your team quite knows what SRP is. If you have a class that does only one thing, how does it have 20 dependencies? " - I think that If you have a Customer class, it is not strange to have 20 parameters in the constructor.

It is true that DAO objects tend to have a lot of parameters, which you have to set in your constructor, and the parameters are usually are simple types such as string. However in the example of a Customer class, you can still group it's properties inside other classes to make things simpler. Such as having an Address class with streets and a Zipcode class that contains the zipcode and will handle business logic such as data validation as well:

public class Address {
    private String street1;
    //...

    private Zipcode zipcode;

    // easy to extend
    public bool isValid() {
        return zipcode.isValid();
    }
}

public class Zipcode {
    private string zipcode;
    public bool isValid() {
        // return regex match that zipcode contains numbers
    }
}

This thing is discussed further in the blog post "Never, never, never use String in Java (or atleast often)". As an alternative of using constructors or static methods to make the sub objects easier to create you could use a fluid builder pattern.


答:
Haven't you ever had proprietary components fail before? I've encountered plenty of bugs in software from companies big and small. This issue is not a problem with open source per se, rather it is more about project maturity.

It sounds like you want to use mature projects that offer support. Some open source projects offer paid support, or have a large enough community that you can get answers in a public forum. Maybe you should make maturity and support criteria priorities when choosing a library, whether it is closed or open source.

You need to acknowledge that you're taking on more risk if you decide to use an immature project, or one with limited support. As such you need to determine what your risk mitigation plan is. You might perform more testing on the third-party software, for example.


答:
As I see it, it's a balancing act.

If you make yourself dependent on a vendor, it's almost certain that support will disappear before long

Because they have programmers to pay, so they need to keep making new versions and making sure the old ones are impossible to get and no longer work (on newer platforms) so the new ones will have a market.

If they can't sell enough to justify a business model, they pass it off from company A to company B to C, each of which changes it enough so again, you can't use the new one without reprogramming, and you can't get the old one that works.

They just decide they will no longer support it because it's too much trouble and there's no money in it. All the money's in new apps.

So if you want to build something that doesn't have to be continually rewritten every few years, open source can be your friend.


答:
Originally, the kill command could only kill a process, only later was kill enhanced to allow you to send any signal.

Since version 7 of Unix (1979) the default has been to signal the process in a way which can be caught and either handled gracefully or ignored (by sending a SIGTERM signal), but it can also be used to pull the rug out from under a process (a kill -9 sends a SIGKILL signal which cannot be caught and thus cannot be ignored).

Background

Computing, and Unix in particular, is rife with metaphor.

The main metaphor for processes is that of a living thing which is born, lives and dies.

In Unix all processes except init have parents, and any process which spawns other processes has children. Processes may become orphaned (if their parent dies) and can even become zombies, if they hang around after their death.

Thus, the kill command fits in with this metaphor.

Unix Archaeology

From the manual page from version 4 of Unix (the version where kill was introduced, along with ps) we find:

```<code>NAME
        kill - do in an unwanted process
SYNOPSIS
        kill processid ...
DESCRIPTION
        Kills the specified processes.
        The processid of each asynchronous process
        started with `&' is reported by the shell.
        Processid's can also be found by using ps (I).

        The killed process must have
        been started from the same typewriter
        as the current user, unless
        he is the superuser.
SEE ALSO
        ps(I), sh(I)
</code>```

I particularly like the final section of this man page:

```<code>BUGS
        Clearly people should only be allowed to kill
        processes owned by them, and having the same typewriter
        is neither necessary nor sufficient.
</code>```

By the time fifth edition had come around, the kill command had already been overloaded to allow any signal to be sent.

From the Unix Programmers Manual, Fifth Edition (p70):

```<code>If a signal number preceded by "-" is given
as an argument, that signal is sent instead of
kill (see signal (II)).
</code>```

The default though was to send a signal 9, as signal 15 did not yet exist (see p150).

With version 6 the kill man page no longer mentioned the same typewriter bug.

It was only with version 7 of Unix that signal 15 was introduced (see see the signal(2) and kill(1) man pages for v7) and kill switched to that rather than using signal 9.

Title: Why is the "kill" command called so?

Body:
Originally, the kill command could only kill a process, only later was kill enhanced to allow you to send any signal.

Since version 7 of Unix (1979) the default has been to signal the process in a way which can be caught and either handled gracefully or ignored (by sending a SIGTERM signal), but it can also be used to pull the rug out from under a process (a kill -9 sends a SIGKILL signal which cannot be caught and thus cannot be ignored).

Background

Computing, and Unix in particular, is rife with metaphor.

The main metaphor for processes is that of a living thing which is born, lives and dies.

In Unix all processes except init have parents, and any process which spawns other processes has children. Processes may become orphaned (if their parent dies) and can even become zombies, if they hang around after their death.

Thus, the kill command fits in with this metaphor.

Unix Archaeology

From the manual page from version 4 of Unix (the version where kill was introduced, along with ps) we find:

NAME
        kill - do in an unwanted process
SYNOPSIS
        kill processid ...
DESCRIPTION
        Kills the specified processes.
        The processid of each asynchronous process
        started with `&' is reported by the shell.
        Processid's can also be found by using ps (I).

        The killed process must have
        been started from the same typewriter
        as the current user, unless
        he is the superuser.
SEE ALSO
        ps(I), sh(I)

I particularly like the final section of this man page:

BUGS
        Clearly people should only be allowed to kill
        processes owned by them, and having the same typewriter
        is neither necessary nor sufficient.

By the time fifth edition had come around, the kill command had already been overloaded to allow any signal to be sent.

From the Unix Programmers Manual, Fifth Edition (p70):

If a signal number preceded by "-" is given
as an argument, that signal is sent instead of
kill (see signal (II)).

The default though was to send a signal 9, as signal 15 did not yet exist (see p150).

With version 6 the kill man page no longer mentioned the same typewriter bug.

It was only with version 7 of Unix that signal 15 was introduced (see see the signal(2) and kill(1) man pages for v7) and kill switched to that rather than using signal 9.


答: Open source is really about legalities, not code quality. There are good and bad open source products, just as there are good and bad closed source ones. I believe your dilemma is whether to use a project developed by a community of volunteers.</p>


问:
Review quality of code
I have been asked to quality review two code bases. I've never done anything like that, and need advice on how to perform it and report it.

Background

There are two providers of code, one in VB and one in C (ISO 9899:1999 (C99)). These two programs do not work so well together, and of course, the two suppliers blames  each other. I will therefore as a independent person review both codes, on a comprehensive level review the quality of the codes to find out where it is most likely that the problem lies. I will not try to find problems, but simply review the quality and how simple it is to manage and understand the code.

Edit:
I have yet not received much information about what the problem consists of. I've just been told that I will examine the code in terms of quality. Not so much more. I do not know the background to why they took this decision.

答:
(Regarding the code, just dive in - it is the only way to learn it).

I would suggest you look into having an API for the two parties to work across (a contract essentially).  If they conform to the API then the code should work together.

Very much like how it is done with a WSDL in the Web Service world.

If at all possible then have a test suite on the API so you can see that stuff works.  Otherwise you can play the blame tag game for years.

OwnerDisplayName: magol

Title: Review quality of code


问:
Do people in non-English-speaking countries code in English?
I've heard it said (by coworkers) that everyone "codes in English" regardless of where they're from. I find that difficult to believe, however I wouldn't be surprised if, for most programming languages, the supported character set is relatively narrow.

Have you ever worked in a country where English is not the primary language?

If so, what did their code look like?

答: I'am from indonesia, and english is not our primary language, but all of programmers that i know is coding in english including the code comments.</p>


问:
Maybe monad vs exceptions
I wonder what are the advantages of Maybe monad over exceptions? It looks like Maybe is just explicit (and rather space-consuming) way of try..catch syntax.

update Please note that I'm intentionally not mentioning Haskell.

答: The maybe monad is basically the same as most mainstream language's use of "null means error" checking (except it requires the null to be checked), and has largely the same advantages and disadvantages. </p>

Title: Maybe monad vs exceptions


答: The Haskell type system will require the user to acknowledge the possibility of a Nothing, whereas programming languages often don't require that an exception be caught. That means that we'll know, at compile-time, that the user has checked for an error.

Title: Maybe monad vs exceptions

Body:
I wonder what are the advantages of Maybe monad over exceptions? It looks like Maybe is just explicit (and rather space-consuming) way of try..catch syntax.

update Please note that I'm intentionally not mentioning Haskell.


问:
What ASP.NET MVC can do and Ruby on Rails can't?
ASP.NET MVC and Rails have similar area of use, are built around same architecture, both frameworks are relatively new and open source.

So as a Rails programmer I'd like to know, what ASP.NET MVC can do and Ruby on Rails can't, and visa versa?

答:
My major problem with Microsoft's MVC 3 and Entity Framework are their staggeringly bad design principles.

One of the very first issues I ran into was when using another class as a property and trying to create a dropdown list for the possible values.

To illustrate my point say you have two model classes like this:

```<code>public class Color
{
    public int ID { get; set; }
    public string Name { get; set; }
}

public class Thing
{
    public int ID { get; set; }
    public string Name { get; set; }
    public virtual Color Color { get; set; }
}
</code>```

Creating the Color property would be sufficient for a real ORM but not EF. You have to add a redundant ID for the Color property in the Thing class like so:

```<code>public class Thing
{
    public int ID { get; set; }
    public string Name { get; set; }
    public int ColorID { get; set; }
    public virtual Color Color { get; set; }
}
</code>```

If you don't add the redundant ID field for a foreign object reference you can't easily create dropdown lists with all of the possible options from the linked class.

This is really terrible design as it strongly couples the internal workings of one class to another. Thing shouldn't know anything about ColorID, the Color class should handle its own equality checks without exposing that it even has an ID.

This is best practices 101 stuff but apparently Microsoft is totally unaware of basic principles of computer science and object oriented programming.[/rant]

Body:
My major problem with Microsoft's MVC 3 and Entity Framework are their staggeringly bad design principles.

One of the very first issues I ran into was when using another class as a property and trying to create a dropdown list for the possible values.

To illustrate my point say you have two model classes like this:

public class Color
{
    public int ID { get; set; }
    public string Name { get; set; }
}

public class Thing
{
    public int ID { get; set; }
    public string Name { get; set; }
    public virtual Color Color { get; set; }
}

Creating the Color property would be sufficient for a real ORM but not EF. You have to add a redundant ID for the Color property in the Thing class like so:

public class Thing
{
    public int ID { get; set; }
    public string Name { get; set; }
    public int ColorID { get; set; }
    public virtual Color Color { get; set; }
}

If you don't add the redundant ID field for a foreign object reference you can't easily create dropdown lists with all of the possible options from the linked class.

This is really terrible design as it strongly couples the internal workings of one class to another. Thing shouldn't know anything about ColorID, the Color class should handle its own equality checks without exposing that it even has an ID.

This is best practices 101 stuff but apparently Microsoft is totally unaware of basic principles of computer science and object oriented programming.[/rant]


问:
Can observer pattern be represented by cars and traffic lights?
I wanted to verify with all of you, if I have a correct Observer Pattern analogy. The scenario is as follows:
Consider, at a junction, there is a traffic signal, having red, yellow and green lights respectively. There are vehicles facing the traffic signal post. When it shows red, the vehicles stop, when it shows green, the vehicles move on. In case, it is yellow, the driver must decide whether to go or to stop, depending on whether he/she has crossed the stop line or not. At the same time, there are vehicles that do not care about the signal. They would do as they like.

The similarities are that, the Traffic Signal happens to be the subject, notifying its states by glowing the appropriate lights. Those looking at it and following the signal are the ones subscribed to it, and behave according to the state of the subject. Those who do not care about it, are sort-of un-subscribed from the traffic signal.

Please tell me, if you think this is a correct analogy or not?

答:
I think your analogy is wrong, depending on how technically correct you want the analogy to be.

Although the car "observes" the traffic light, the observer pattern is about the subject actively notifies its observers about a change in state.

If the traffic light analogy should apply, then the traffic light should actively send out a message directed at each car approaching the traffic light when it changes. That is a bit off IMHO.


问:
practical way to learn C?
I want to dig into C and normally when I want to learn a new language I think of a simple/attainable project goal that has some practical purpose (make use of an api, automate a task, etc...)

I'm having a harder time coming up with one for C mainly because everything I read points to the fact that C's primary use currently is in embedded systems and more complex software projects like operating systems.

Does this point me to the fact that I don't need to learn it or that I just need to be a bit more convoluted in my learning strategy?

References to practical learning resources? (tutorial/how to that produces an end result that has some purpose/benifit)

答:
You're going to want to do something that can work from the command line.  GUI programming in C is a major pain in the ass, even with a good GUI framework.

My usual suggestion for a practical C learning experience has been a contact list or other simple data management app.  That will cover most of the important bits (I/O, memory management, text processing, etc.), and you won't have to use anything outside of the standard C library to accomplish it.  C doesn't have any built-in support for graphics, networking, sound, or much else1, so for your first foray into C programming it's best to avoid anything that relies on those sorts of things.

C can be used for general-purpose programming; you just have to ratchet down your expectations somewhat (imagine it's 1983 and you're sitting in front of a VT52 attached to a VAX 11/750, and you'll be in the right mindset).

Just remember, C has no blade guards, and won't prevent you from doing something stupid.  The language definition is a little loose in places, and there are some operations that aren't illegal as such, but aren't well-defined either.

1 - The latest (2011) revision of the language standard has added built-in threading support

Title: practical way to learn C?


答: "Maybe" is not a replacement for exceptions. Exceptions are meant to be used in exceptional cases (for instance: opening a db connection and the db server is not there although it should be). "Maybe" is for modeling a situation when you may or may not have a valid value; say you are getting a value from a dictionary for a key: it may be there or may be not - there is nothing "exceptional" about any of these outcomes.</p>

Title: Maybe monad vs exceptions


答:
An exception can carry more information about the source of a problem. OpenFile() can throw FileNotFound or NoPermission or TooManyDescriptors etc. A None does not carry this information.

Exceptions can be used in contexts that lack return values (e.g. with constructors in languages that have them).

An exception allows you to very easily send the information up the stack, without a lot of if None return None-style statements.

Exception handling almost always carries higher performance impact than just returning a value.

Most importantly of all, an exception and a Maybe monad have different purposes - an exception is used to signify a problem, while a Maybe isn't.

"Nurse, if there's a patient in room 5, can you ask him to wait?"

Maybe monad: "Doctor, there is no patient in room 5."

Exception: "Doctor, there is no room 5!"

(notice the "if" - this means the doctor is expecting a Maybe monad)

Title: Maybe monad vs exceptions


问:
Why is quicksort better than other sorting algorithms in practice?
This is a repost of a question on cs.SE by Janoma. Full credits and spoils to him or cs.SE.

In a standard algorithms course we are taught that quicksort is O(n log n) on average and O(n²) in the worst case. At the same time, other sorting algorithms are studied which are O(n log n) in the worst case (like mergesort and heapsort), and even linear time in the best case (like bubblesort) but with some additional needs of memory.

After a quick glance at some more running times it is natural to say that quicksort should not be as efficient as others.

Also, consider that students learn in basic programming courses that recursion is not really good in general because it could use too much memory, etc. Therefore (and even though this is not a real argument), this gives the idea that quicksort might not be really good because it is a recursive algorithm.

Why, then, does quicksort outperform other sorting algorithms in practice? Does it have to do with the structure of real-world data? Does it have to do with the way memory works in computers? I know that some memories are way faster than others, but I don't know if that's the real reason for this counter-intuitive performance (when compared to theoretical estimates).

答:
I wouldn't agree that quicksort is better than other sorting algorithms in practice.

For most purposes, Timsort - the hybrid between mergesort/insertion sort which exploits the fact that the data you sort often starts out nearly sorted or reverse sorted.

The simplest quicksort (no random pivot) treats this potentially common case as O(N^2) (reducing to O(N lg N) with random pivots), while TimSort can handle these cases in O(N).

According to these benchmarks in C# comparing the built-in quicksort to TimSort, Timsort is significantly faster in the mostly sorted cases, and slightly faster in the random data case and TimSort gets better if the comparison function is particularly slow.  I haven't repeated these benchmarks and would not be surprised if quicksort slightly beat TimSort for some combination of random data or if there is something quirky in C#'s builtin sort (based on quicksort) that is slowing it down.  However, TimSort has distinct advantages when data may be partially sorted, and is roughly equal to quicksort in terms of speed when the data is not partially sorted.

TimSort also has an added bonus of being a stable sort, unlike quicksort.  The only disadvantage of TimSort uses O(N) versus O(lg N) memory in the usual (fast) implementation.


答:
In my limited experience, the main advantage to ASP.NET MVC is that it is a compiled language. This allows you to detect some programming bugs already at compilation, where Ruby has to rely on detecting then during unit testing.

Also the fact that it is compiled makes it possible to have advanced refactoring tools, e.g. change the name of a property in one place, and all references to the property is changed. This at least cannot be done in TextMate, which many Rails developers use.

On the other hand, the main advantage of Ruby on Rails is that it is an interpreted language ;) The nature of Ruby, how you can modify any object in memory, or monkey patch a class, can lead to some very elegant solutions; check out the book Eloquent Ruby for some examples. And a great deal of the Rails framework itself is based on this ability.

The ability to replace any method at any object at any time has also helped me greatly in writing unit tests. In .NET, Dependency Injection and IOC containers are virtually requirements for creating testable code. That is not necessary in Ruby.

Edit:

After thinking about it, probably the killer feature of Rails is database migration. The ASP.NET MVC framework does not in itself provide any database support. The .NET framework does have some data access components/ORM, e.g. Entity Framework and Linq to Sql. But it does not have any tools for designing the database structure.

If you pay for one of the more expensive versions of VS, you can get the Data Dude, which lets you design a database schema, and have some tools for deploying the schema to a database. But as far as I can tell, support for handling migrations from earlier versions of the application is very limited.

Some claim that ASP.NET MVC is not really an MVC framework, merely a VC framework, due to the lack of support for database migration.

Edit (again):

Changes to the Visual Studio toolchain/EF have introduced code based migrations since my last edit. (but also check out FluentMigrator if you are going down that path)

Title: What ASP.NET MVC can do and Ruby on Rails can't?

Body:
ASP.NET MVC and Rails have similar area of use, are built around same architecture, both frameworks are relatively new and open source.

So as a Rails programmer I'd like to know, what ASP.NET MVC can do and Ruby on Rails can't, and visa versa?


答:
You can release new versions under different licenses or with new ownership attributions, which is easy-ish to manage, or you can retrospectively sign older versions over to new owners, which is more of a pain.

Personally I favour an approach whereby once a version is released under a given license, that's final. Later versions may have new author attributions or switch licenses entirely.

Title: On what name should I claim copyright in open source software?

Body:
When I want to use the Apache 2.0 licence in my project, I should include this in the comments of my source code:

```<code>Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
</code>```

What name should I fill in for [name of copyright owner]? I am currently working alone on this project, but I'm going to release the source code so there might be other contributors in the near future.


问:
Am I deluding myself? Business analyst transition to programmer
Current job: Working as the lead business analyst for a Big 4 firm, leading a team of developers and testers working on a large scale re-platforming project (4 onshore dev, 4 offshore devs, several onshore/offshore testers).  Also work in a similar capacity on other smaller scale projects.

Extent of my role: Gathering/writing out requirements, creating functional specifications, designing the UI (basically mapping out all front-end aspects of the system), working closely with devs to communicate/clarify requirements and come up with solutions when we hit roadblocks, writing test cases (and doing much of the testing), working with senior management and key stakeholders, managing beta testers, creating user guides and leading training sessions, providing key technical support.

I also write quite a few macros in Excel using VBA (several of my macros are now used across the entire firm, so there are maybe around 1000 people using them) and use SQL on a daily basis, both on the SQL compact files the program relies on, our SQL Server data and any Access databases I create.  The developers feel that I am quite good in this role because I understand a lot about programming, inherent system limitations, structure of the databases, etc so it's easier for me to communicate ideas and come up with suggestions when we face problems.

What really interests me is developing software.  I do a fair amount of programming in VBA and have been wanting to learn C# for awhile (the dev team uses C# - I review code occasionally for my own sake but have not had any practical experience using it).  I'm interested in not just the business process but also the technical side of things, so the traditional BA role doesn't really whet my appetite for the kind of stuff I want to do.  Right now I have a few small projects that managers have given me and I'm finding new ways to do them (like building custom Access applications), so there's a bit here and there to keep me interested.

My question is this: what I would like to do is create custom Excel or Access applications for small businesses as a freelance business (working as a one-man shop; maybe having an occasional contractor depending on a project's complexity).  This would obviously start out as a part-time venture while I have a day job, but eventually become a full-time job.  Am I deluding myself to thinking I can go from BA/part-time VBA programmer to making a full-time go of a freelance business (where I would be starting out just writing custom Excel/Access apps in VBA)?  Or is this type of thing not usually attempted until someone gains years of full-time programming experience?  And is there even a market for these types of applications amongst small businesses (and maybe medium-sized) businesses?

答: VBA and Access is the bottom of the programming ladder. If I were you I would shoot higher since you have SQL skills. Consider learning SQL Server Reporting Services and creating reports or SSIS and doing ETL processing. Those are skills in fairly high demand right now and you are well placed to do them as they can be relatively easy to get into while in a corporate environment especially if you have no one else currently handling those roles for your company. I would see business analyst experience as a huge plus for a report writer.</p>


问:
What is a widely accepted term for a string variable that would probably contain a file path and file name?
For functions that need to index files in a directory and rename them FileName0001, FileName0002, etc... I often need to write a function that splits the file name from the file path and rename the file.  When I put the file name and file path back together, I don't have a very good name for the variable that contains both of them and I usually just wind up concatenating them every time I want to use them (usually using them as parameters for functions labeled either filename or filepath) so I never really know what I'm doing until I notice a lot of files being written in the same directory as my binaries.

Anyway, what do I call a file name and a file path?  I don't want to call it File, because that usually means the binary information behind the file.  I don't want to call it URI because that usually means I've got some sort of protocol, which I don't.  I just want a good way to denote "c:\somedir\somedir\somedir\somefile.txt" so as to deconfuse this mess I've just realized I'm in.

Please don't just list your personal preference.  I think an excellent answer should "'site its sources". (as in, provide a link to a repository with a good example of the code being used as I described)

答:
Why not call it 'Path'? From Wikipedia:

A path, the general form of a filename or of a directory name,
  specifies a unique location in a file system


答: I use fileWithPath. It's clunky but explicit.

Title: What is a widely accepted term for a string variable that would probably contain a file path and file name?

Body:
For functions that need to index files in a directory and rename them FileName0001, FileName0002, etc... I often need to write a function that splits the file name from the file path and rename the file.  When I put the file name and file path back together, I don't have a very good name for the variable that contains both of them and I usually just wind up concatenating them every time I want to use them (usually using them as parameters for functions labeled either filename or filepath) so I never really know what I'm doing until I notice a lot of files being written in the same directory as my binaries.

Anyway, what do I call a file name and a file path?  I don't want to call it File, because that usually means the binary information behind the file.  I don't want to call it URI because that usually means I've got some sort of protocol, which I don't.  I just want a good way to denote "c:\somedir\somedir\somedir\somefile.txt" so as to deconfuse this mess I've just realized I'm in.

Please don't just list your personal preference.  I think an excellent answer should "'site its sources". (as in, provide a link to a repository with a good example of the code being used as I described)


问:
Javascript MVC in principle
Suppose I want to implement MVC in JavaScript. I am not asking about MVC frameworks. I am asking how to build it in principle.

Let's consider a search page of an e-commerce site, which works s follows:

User chooses a product and its attributes and press a "search" button.

Application sends the search request to the server, receives a list of products.

Application displays the list in the web page.

I think the Model holds a Query and list of Product objects and "publishes" such events as "query updated", "list of products updated", etc. The Model is not aware of DOM and server, or course.

View holds the entire DOM tree and "subscribes" to the Model events to update the DOM. Besides, it "publishes" such events as "user chose a product", "user pressed the search button" etc.

Controller does not hold any data. It "subscribes" to the View events, calls the server and updates the Model.

Does it make sense?

答:
What you say make sense and it's the approach used in HTML5 frameworks like Sencha Touch 2 (http://www.sencha.com/products/touch/).

MVC is a pattern and is not tied to any specific language, framework or class library. So it is possibile to use it with Javascript also, regardless of specific technology employed.

OwnerDisplayName: Michael

Title: Javascript MVC in principle


答:
I recommend Project Euler. I used it to improve my C++ and it is awesome. It's great because each problem is a small task that might take less than an hour to complete (at least the first ones).

You'll need a profiler and a book about optimizing code for speed. Be sure to stick to the 1 minute rule: You have to get the answer within 1 minute.

Title: practical way to learn C?

Body:
I want to dig into C and normally when I want to learn a new language I think of a simple/attainable project goal that has some practical purpose (make use of an api, automate a task, etc...)

I'm having a harder time coming up with one for C mainly because everything I read points to the fact that C's primary use currently is in embedded systems and more complex software projects like operating systems.

Does this point me to the fact that I don't need to learn it or that I just need to be a bit more convoluted in my learning strategy?

References to practical learning resources? (tutorial/how to that produces an end result that has some purpose/benifit)


问:
Approach on working with many programmers on one module/feature
How can 2 or more developers code a certain feature/module of a software?  Let's assume that the module is big and feature rich.  How would they prevent each other from overlapping their code?  Say, we have the same method but is implemented in a different way.  Do you think it might be better to have one focused at a specific feature only?

Is a version control system like Git would help solve the problem?  Is it correct that it allows developers to have these "branches" and then merge it later on?

What's your take on this?

答:
One approach would be to break down the functionality within the module into more than one feature and have the programmers focus on features or sets of features that are as isolated from each other as possible. This can help having too many situations where they step on each others' toes. If there's some parts of common functionality that crosses many boundaries or is used by all other features, you will probably want to do that piece first and any dependent features can try to use local placeholder code to work around the incomplete common functionality, until it's complete.

Having source control will also help. Giving each programmer a separate branch could be a good way to do it, though I've also done this on projects where branches only existed at the project level so we all had to work on the same branch and merge pretty regularly (usually once per day, sometimes more).


答:
What is a widely accepted term

There is nothing like that. Choose the name you like best (my personal favorite is fullFileName).


答: A path from the root of the file system to the file, including the file name, is usually called a full path. If the path doesn't go all the way back to the root, it's a relative path. If it doesn't include the file name, it's a directory path.