答:
As both manager and developer:

Yes I believe things can be done more nice. Totally correct. I don't know codebases which can't be better since that would mean there wouldn't have to be made any considerations based on for example budget, time, staffing etcetera.

Developer view

Implementing best practices in your codebase is actually very important. Like implementing correct design patters, code standard, testing. We all know it.

Manager view

The opposite view, of the manager, is actually also not wrong. He cares about keeping the codebase the same way it is, so the newer parts are designed equal to the already existing parts. You can decide that's not the best way but it is following the standard of the codebase.

Example topic

This one is very interesting:

When you find a simple bug in the code, and you can fix it simply, if you are not working on the code where you have found it, never fix it, even if it takes 5 seconds.

You don't post the "why" he decided this. Is your code unit tested with high coverage? If not: This point is actually very valid, you won't be able to find what's broken when you fix this "bug".

See, there is the difference between the developer and manager role. Developer sees bug, fixes it and proceeds. Or developer implements nice new class structure. But the responsibility goes to the manager.

So with the bugfixes or changes done the manager still has to:

Deliver the right features in time

Make sure the system doesn't break (did you test all features when you implemented that new class structure?)

Ensure that if you are gone another developer can proceed on the work

Etcetera

Sometimes nice is not the best solution BUT the manager is there to support the developers. Not to fight them.

Be constructive

So: If there are points in the codebase which should be improved, like the copy-paste area he should at least be listening. You might for example build some demo case on it saying:

We used copy-paste to create 1000 individual copies of this script

Development time on it is: ....

Bug fixes take more time because we have to copy-paste etc.

We could fix this with following classes / code generation tool / whatever you think.

Then you have a project proposal. Now you can discuss with the manager / team whether this project is important, is there budget, time etc. The you are really talking and improving the product and the teamwork.

Saying his view is worse than mine isn't constructive, prepare, decide and act. Together.

Title: What is the best practice, point of view of well experienced developers

Body:
My manager pushes me to use his self defined best practices. All of these practices are based on is own assumptions. I disagree with them and I would like to have some feedback of well experienced people about these practices. I would prefer answers from people involved in the maintenance of huge products and people whom have maintained the product for years. Developers with 15+ years of experience are preferred because my manager has that much experience himself. I have 7 years of experience.

Here are the practices he wants  me to use:

never extends classes, use composition and interface instead because extending classes are unmaintainable and difficult to debug.

What I think about that

Extend when needed, respect "Liskov's Substitution Principle" and you'll never be stuck with a problem, but prefer composition and decoration. I don't know any serious project which has banned inheriting, sometimes it's impossible to not use that, i.e. in a UI framework. Design patterns are just unusable.

In PHP, for simple use cases (for example a user needs a web interface to view a database table), his "best practice" is: copy some random php code wich we own, paste and modify it, put html and php code in same file, never use classes in PHP, it doesn't work well for small jobs, and in fact it doesn't work well at all, there is no good tool to work with. Copy & paste PHP code is good practice for maintenance because scripts are independent, if you have a bug somewhere you can fix it without side effects.

What I think about that:

NEVER EVER COPY code or do it because you have five minutes to deliver something,  you will do some refactoring after that. Copy & paste code is a beginners error, if you have errors you'll have the error everywhere any time you have pasted it's a nightmare to maintain. If you repsect the "Open Close Principle" you'll rarely get edge effects, use unit test if you are afraid of that. For small jobs in PHP use at least something you get or write the HTML separately from the PHP code and reuse it any time you need it. Classes in PHP are mature, not as mature as other languages like python or java, but they are usable. There is tools to work with classes in PHP like Zend Studio that work very well. The use of classes or not depends not on the language you use but the programming paradigm you have choosen. I'm a OOP developer, I use PHP5, why do I have to shoot myself in the foot?

When you find a simple bug in the code, and you can fix it simply, if you are not working on the code where you have found it, never fix it, even if it takes 5 seconds.

He says to me his "best practices" are driven by the fact that he has a lot of experience in maintaining software in production (14 years) and he now knows what works and what doesn't work, what the community says is a fad, and the people advocating such principles as never copy & paste code, are not evolved in maintaining applications.

What I think about that:

If you find a bug fix it if you can do it quickly inform the people who've touched that code before, check if you have not introduced a new bug, ideally add a unit test for it.

I currently work on a web commerce project, which serves 15k unique users per day. The code base has to be maintained and has been maintained this way since 2005.

Ideally you include a short description of your position and experience in terms of years effectively maintaining an application which has been in production for real.


问:
How is the DOM language independent?
Quoting from Wikipedia

The Document Object Model (DOM) is a cross-platform and language-independent convention for representing and interacting with objects in HTML, XHTML and XML documents.

and from wc3

In order to provide a precise, language-independent specification of the DOM interfaces, we have chosen to define the specifications in OMG IDL

Now I have been programming in Java, C# and PHP and in all these languages the keyword interface is provided, but how do you implement a language-independent interface?

How come you can write an interface without a programming language? Moreover how can you interact with the DOM using any programming language?

If someone invented a new programming language, what are the steps he needs to do to be able to interact with the DOM?

答:
How come you can write an interface without a programming language?

You use an interface description language. Those are not programming language because you can't implement anything in them. Of course you could also use a programming language to define the interface (many low-level interfaces are basically defined in C), but this risks tying it too closely to that language through implicit assumptions and features that are not universally supported. IDLs usually represent a smallest common denominator.

Moreover how can you interact with the DOM using any programming language?

Typically by translating the IDL definition to an interface in your language. For many popular IDL/language combinations, there are tools that do this automatically.

If someone invented a new programming language, what are the steps he needs to do to be able to interact with the DOM?

Translate the IDL to his language, either manually or by first writing a converter, then persuade a browser developer to expose the DOM in that language, or write an adapter between existing DOM interfaces and the new language.

ContentLicense: CC BY-SA 3.0

Title: How is the DOM language independent?


问:
How to reduce errors in dynamic language such as python, and improve my code quality
I post the origin question in stackoverflow, some people suggest me to post here

I've always have trouble with dynamic language like Python.

Several problems:

Typo error, I can use pylint to reduce some of these errors. But there's still some errors that pylint can not figure out.

Object type error, I often forgot what type of the parameter is, int? str? some object? Also, forgot the type of some object in my code.

Unit test might help me sometimes, but I'm not always have enough time to do UT. When I need a script to do a small job, the line of code are 100 - 200 lines, not big, but I don't have time to do the unit test, because I need to use the script as soon as possible. So, many errors appear.

So, any idea on how to reduce the number of these problems?

答:
I'm afraid there's nothing better than unit tests in this case. Sometimes extensive comments (for every method, and sometimes even for a given line of code) help, but it only postpones the inevitable doom :)

Of course good comments are always helpful, no matter the unit tests exist or not.


问:
How do you balance between "do it right" and "do it ASAP" in your daily work?
I find myself pondering over this question from time to time, again and again. I want to do things the right way: to write clean, understandable and correct code that is easy to maintain. However, what I end up doing is writing patch upon a patch; just because there is no time, clients are waiting, a bug should be fixed overnight, the company is losing money on this problem, a manager is pressing hard etc., etc.

I know perfectly well that in the long term I am wasting more time on these patches, but as this time spans months of work, nobody cares. Also, as one of my managers used to say: "we don't know if there will be a long term if we don't fix it now."

I am sure I am not the only one entrapped in these endless real/ideal choice cycles. So how do you, my fellow programmers, cope with this?

UPDATE:
Thank you all for this interesting discussion.
It is sad that so many people have to choose daily between a quantity and a quality of their code. Still, surprisingly many, people think it is possible to win this battle, so thank you all for this encouragement.

答:
There is only one solution. Reserve around 10-20% of project/work time for refactoring. If it's difficult to convince the management that it is a justifiable task give them the only real argument: without refactoring the cost of code maintenance will grow exponentially over time. It's good to have a few metrics/articles/research results to back up this thesis during the meeting with the manager :)

Edit: there are a few good resources on "refactoring vs rising costs of maintenance" mentioned in this whitepaper: http://www.omnext.net/downloads/Whitepaper_Omnext.pdf


答:
One thing I've realized in my career is that there is always time to do it right. Yeah, your manager might be pushing. The client might be pissed. But they don't know how long things take to do. If you (your dev team) don't do it, it's not getting done; you hold all of the leverage.

Because you know what will really cause your manager to push you or your client to be pissed off? Poor Quality.

Title: How do you balance between "do it right" and "do it ASAP" in your daily work?

Body:
I find myself pondering over this question from time to time, again and again. I want to do things the right way: to write clean, understandable and correct code that is easy to maintain. However, what I end up doing is writing patch upon a patch; just because there is no time, clients are waiting, a bug should be fixed overnight, the company is losing money on this problem, a manager is pressing hard etc., etc.

I know perfectly well that in the long term I am wasting more time on these patches, but as this time spans months of work, nobody cares. Also, as one of my managers used to say: "we don't know if there will be a long term if we don't fix it now."

I am sure I am not the only one entrapped in these endless real/ideal choice cycles. So how do you, my fellow programmers, cope with this?

UPDATE:
Thank you all for this interesting discussion.
It is sad that so many people have to choose daily between a quantity and a quality of their code. Still, surprisingly many, people think it is possible to win this battle, so thank you all for this encouragement.


问:
What are your thoughts on Periods/Full Stops in code comments?
I saw this asked in the SO Tavern, so I'm posting the question here. I thought it an interesting question. (Of course it doesn't belong on SO, but I think it's OK here.)

Do you add periods (or, as the OP wrote, "full stops") in your code comments?

To keep it relevant, why?

答: Yes i think by this way you create a good coding convention and it also creates a neat readable code for a 3rd person reviewing your code.</p>

ContentLicense: CC BY-SA 2.5

OwnerDisplayName: Aditya


答:
Well, most (but not all) of these problems can and should be managed by the IDE, not by the programmer.

Maybe you are just using an IDE that is not good enough for the task at hand.

Did you try IntelliJ IDEA, for example?

Title: How to reduce errors in dynamic language such as python, and improve my code quality

Body:
I post the origin question in stackoverflow, some people suggest me to post here

I've always have trouble with dynamic language like Python.

Several problems:

Typo error, I can use pylint to reduce some of these errors. But there's still some errors that pylint can not figure out.

Object type error, I often forgot what type of the parameter is, int? str? some object? Also, forgot the type of some object in my code.

Unit test might help me sometimes, but I'm not always have enough time to do UT. When I need a script to do a small job, the line of code are 100 - 200 lines, not big, but I don't have time to do the unit test, because I need to use the script as soon as possible. So, many errors appear.

So, any idea on how to reduce the number of these problems?


问:
Evaluating a product owner
How do you evaluate a product owner? More specifically, how would one conduct a performance review of a product owner? What qualities or characteristics would one look at when reviewing a product owner?</p>

答:
Ask for feedback from the developers which were part of the team developing the product he 'owned'. You could ask questions like:

Was he able to answer requirements related questions in a timely manner?

When presented with multiple alternatives in regards to a feature, was he able to make a clear decision with regard of what he wants?

How often did he change the requirements? This is something that always happens. Being able to cope with this is what it means to be agile. However, if this happens very often, then that's a sign that the product owner has no idea of what he actually wants

Was he able to provide clear feedback during demo sessions?

Title: Evaluating a product owner


问:
How can I better manage far-reaching changes in my code?
In my work (writing scientific software in C++), I often get asked by the people who use the software to get their work done to add some functionality or change the way things are done and organized right now. Most of the time this is just a matter of adding a new class or a function and applying some glue to do the job, but from time to time, a seemingly simple change turns out to have far-reaching consequences that require me to redesign a substantial amount of existing code, which takes a lot of time and effort, and is difficult to evaluate in terms of time required. I don't think it has as much to do with inter-dependence of modules, as with changing requirements (admittedly, on a smaller scale).

To provide an example, I was thinking about the recently-added multi-user functionality in Android. I don't know whether they planned to introduce it from the very beginning, but assuming they didn't, it seems hard to predict all the areas that will be affected by the change (apps preferences, themes, need to store account info somehow, etc...?), even though the concept seems simple enough, and the code is well-organized.

How do you deal with such situations? Do you just jump in to code and then sort out the cruft later like I do? Or do you do a detailed analysis beforehand of what will be affected, what needs to be updated and how, and what has to be rewritten? If so, what tools (if any) and approaches do you use?

答:
Primarily, it is the job of a Business Analyst who seeks and predicts the changes to be incorporated in a business model. Then it is the Software Engineer and the Developer who engineers and implements the solution in coded form.

The Android multi-user functionality you mentioned in your question is first deeply researched and re-researched at Google by Analysts and Engineers before incorporation into the Mobile OS before the final release.

There are 2 factors when it comes to designing a Software Solution:

Code Reusability

Code Maintainability

Code Resuability

This is something exactly what you just mentioned in the first part of your question. This essentially requires a modular approach to coding and a neat OOP design. A Software Engineer well versed to accomplish Code Resubility in the intended solution.

Code Maintainability

Code Maintanability addresses about what will probably happen years after implementing the solution in business terms. This can only be accomplished with thelp of the Business Analyst! BA is someone who is well versed in the business domain(e.g. Healthcare, Aviation, Logistics, Hospitality & Tourism, etc.) of the software and assesses and poposes how the business model should be integrated with Technology.

A well engineered software for critical systems should be tested for future maintanability and felxibility.

For more information, visit the following link:

International Institute Of Business Analysis


答:
"Doing it right" means making the right tradeoffs for a particular situation. Some of them are:

Development time and cost

Ease of reading, debugging, and updating the code later (everything from variable names to architecture)

Thoroughness of the solution (edge cases)

Speed of execution

Obviously, if a piece of code will be used once and thrown away, #2 can be sacrificed for any of the others. (But beware: you may think you're going to throw it away, then find you have to keep using and maintaining it, at which point it will be harder to convince people to give you time to improve something that "works".)

If you and/or your team are going to keep using and updating some code, taking shortcuts now just means slowing yourselves down later.

If you are currently delivering buggy code (weak on #4) and taking a long time to do it (weak on #1), and it's because you're trying to update code that was weak on #2, well, you've got a solid, pragmatic argument for changing your practices.


答:
The other answers and their popularity have made it clear that full stops are well appreciated in longer comments, and probably can be avoided in one-liners.

Another point that might be relevant is to avoid exclamation marks, especially multiples. Example:

```<code>    // Though loop is labor-intensive, performance is fine with with 95K cases!!!
</code>```

and

```<code>    // This code really sucks!
</code>```

On the other hand, question marks are quite useful sometimes:

```<code>    // TODO: What does Crojpler.bway() actually do?
</code>```

Title: What are your thoughts on Periods/Full Stops in code comments?

Body:
I saw this asked in the SO Tavern, so I'm posting the question here. I thought it an interesting question. (Of course it doesn't belong on SO, but I think it's OK here.)

Do you add periods (or, as the OP wrote, "full stops") in your code comments?

To keep it relevant, why?

Body:
The other answers and their popularity have made it clear that full stops are well appreciated in longer comments, and probably can be avoided in one-liners.

Another point that might be relevant is to avoid exclamation marks, especially multiples. Example:

    // Though loop is labor-intensive, performance is fine with with 95K cases!!!

and

    // This code really sucks!

On the other hand, question marks are quite useful sometimes:

    // TODO: What does Crojpler.bway() actually do?


答:
The short answer is that it is difficult, but not completely impossible to manage changes. You have to realize though that changes always happen and they're most likely new ideas that have never been considered in scope before.

Now onto the long answer: there are many different strategies you can consider to manage changes all with pros and cons.

Below is a short list from the viewpoint of a programmer to handle changes in their code:

First of all do not commit to a change request until you fully understand it and have it planned. You may be ordered to do it anyway, but at least in such situation you have the option of pointing a finger at your superior if the blame game comes.

When you happen upon some code that gets changed a lot, refactor it in such a way so that the same kinds of changes are easier to implement in the future. Sometimes refactoring to design patterns will help.

Refactoring takes time, so always make sure you plan and estimate your times for this. Also whenever you feel you need to refactor then it is most likely time to consider writing tests. A test suite always helps out refactoring job by pointing out regression bugs. If you're doing Test Driven Development (TDD) right you should be able to refactor easily.

Always stick with the simplest solution. This is to avoid over-engineering, i.e. painting yourself into a corner. It is always easier said than done, but doing TDD helps out with that as you should resolve the tests by making the simplest possible solution for them.

You know you have either an under-engineered or an over-engineered system when changes are hard to test and implement, the sweet spot in the middle is usually simple to test and implement. Difficult tests usually characterized in difficult to understand set-up/tear-down code; usually due to all the dependencies that need to be initialized. In such cases you can utilize a mock test framework to ease things out and refactor the class to use less dependencies (moving some functionality to other classes).

Consider implementing some meta-functionality (such as configuration file, designer, scripting, Domain-specific language, or plug-in functionality) to your app. Meta-functionalities makes some kinds of changes easier to handle or implement than writing new source code.

Make your program smart enough to handle changes. The obvious drawback is the time it takes to implement meta-functionality but the benefit is that you'll avoid "monkey work" in the future.

Read up on the SOLID principles (by Uncle Bob). If you're doing your tests "right", you will end up following the SOLID principles on your code anyway. I've written this in a Stackoverflow answer about following principles over design.

The only drawback with SOLID code, by following it to the letter, is that you'll end up with a lot of classes (ravioli code) and some developers find this problematic and do god-object code instead which is a very lucurative anti-pattern. Given the project is large enough I personally use IoC frameworks for handling class initialization (with complex object graph hierarchies). Finding the balanced sweet spot between ravioli and god-object is usually solved by writing tests as the class dependencies are blatantly noticeable in unit-tests.

It's worth mentioning Michael C. Feathers' book "Working Effectively with Legacy Code". There are a lot of great tips and hints on how to manage changes on old code or code written by someone else. Most of them boil down to writing tests to find out how existing code works and proceed to refactor it, which is something I mentioned in the second point above. He is actually quite specific about it and made an process algorithm on how to implement changes on legacy code:

Identify change points

Find test points

Break dependencies

Write tests

Make changes and refactor

Anecdotally this is a process I've successfully used as well when working with legacy code... with some legacy code being; as recent as in I haven't touched it for a month or so, to code I've never worked with before and has been built up for years.

Most of these strategies are something that formal roles such as business analyst or a software architect cannot predict as they're usually not "in the code". It is up to us developers to see the changes coming, plan accordingly and start refactoring mercilessly (with the safety harness of version control so you can roll-back/revert in case you do mistakes).

You can practically boil down the strategies to the following principles about change management:

Don't fool yourself; changes always happen even in fixed projects. Period.

Deal with it. Make changes easy to implement.

Find difficult dependencies. Break them and rebuild them into something simpler.

Tests are more useful than you think. Testing usefulness is proportional to the size of project. The more changes you stuff in, the more you'll need a test harness to make sure things don't break (i.e. stumble upon regression bugs).

Good luck, handling those change requests!

Title: How can I better manage far-reaching changes in my code?

Body:
In my work (writing scientific software in C++), I often get asked by the people who use the software to get their work done to add some functionality or change the way things are done and organized right now. Most of the time this is just a matter of adding a new class or a function and applying some glue to do the job, but from time to time, a seemingly simple change turns out to have far-reaching consequences that require me to redesign a substantial amount of existing code, which takes a lot of time and effort, and is difficult to evaluate in terms of time required. I don't think it has as much to do with inter-dependence of modules, as with changing requirements (admittedly, on a smaller scale).

To provide an example, I was thinking about the recently-added multi-user functionality in Android. I don't know whether they planned to introduce it from the very beginning, but assuming they didn't, it seems hard to predict all the areas that will be affected by the change (apps preferences, themes, need to store account info somehow, etc...?), even though the concept seems simple enough, and the code is well-organized.

How do you deal with such situations? Do you just jump in to code and then sort out the cruft later like I do? Or do you do a detailed analysis beforehand of what will be affected, what needs to be updated and how, and what has to be rewritten? If so, what tools (if any) and approaches do you use?


答:
Congratulations! You have ascended from programmer/hacker/coder to software engineer, the advanced level at which architecture is a concern. Many professionals in coding never advance that far and never ask this question, so you should be justifiably proud of yourself.

Architecture is precisely what you crave: it is all about observing principles that make it easier to maintain code in the future, whether in the obvious direction or a totally different one. This is the reason that all old hands will advise you to keep modules small, to avoid unnecessary dependencies, to do one thing and do it well, to separate mechanism from policy, etc. etc. All these are principles that allow different parts of a system to change independently of another, and often at very different speeds, and they become increasingly more important the larger your system is.

The bad news is that there is no generally accepted set of principles that will guarantee to remove future effort from your project. (If there were, software engineering could be accurately described as a craft or even a process, while the tendency now, after generations of bad experiences, is to view it as something of a mixture of a craft and an art.) The most encouraging thing I can tell you is that many of the principles that successful architects promote and describe in their books really do remove work for you (although not usually in the small example code bases described in such books).

Personally, I process change requests as they come in, but if I see an opportunity to improve the overall organization of a code base, I relentlessly do it, no matter whether that takes ten or even a hundred times as long as actually changing things. My belief is that you know good architecture when you see it, and initially this will be a rare and precious occasion that you must take in order to advance your own understanding.

As you gather even more experience, you will be able to anticipate some things better and avoid refactorings later, but it's a step-by-step process. If your job doesn't allow you the opportunity to improve architecture because there never is any time, consider changing jobs if possible. Coding according to good practices is just sp much more satisfying that I consider it worth the risk.


答: This won't work in every case, but I have had some luck using this strategy if the problem is a broken production problem that must be urgently fixed. Estimate the time to do a quick fix to get  production running and the time to do the quality fix for the future. Present the estimates to your boss/client and get the time approved for both. Then you do the quick fix to get production runnning and a long term fix immediately therafter when the urgent time pressure is off. I find that if I present it as I need this time to get the job done right, but I can put a temporary fix in place until I can do that, that my clients seem to like that approach. It gets prod running again and it gets the long term need taken care of.


问:
Commenting regular expressions
Are there any common practises for commenting the regular expressions: inline comments referring different part of RegEx or general comment for all expression?</p>

答: In my view, a good practice is to concisely state in comments what the general idea of the regular expression is.  This saves other developers (or sometimes yourself) the hassle of copy-pasting the regex in a parser like RegExr, only to understand what it does.</p>

Title: Commenting regular expressions


答:
One thing to do is to try to be forward looking and design your data structures to be able to handle a change, even if you don't put the algorithms and user interface around it yet.  Take your Android multi-user functionality as an example.  When designing the single user API, ask yourself if you ever have more than one user, if your design will make it easy or difficult to account for that.

Don't just go ahead and put in multiple users while you're at it, if you don't need it yet.  However, going through the mental exercise can lead to a design like creating a single User object with relevant fields that you pass via dependency injection where needed.  That is barely any more work than another solution, it will make adding multiple users later much easier, and usually even makes the single-user implementation more clear.

This is where a lot of design patterns came from, a recognition of what historically has made the system more maintainable down the road.


问:
Good practices when writing a parser for a standard file format (such as ePub)
I am considering writing an Android reader software that can read ePubs and display them.  I checked the ePub standard documents.  However, these contain a lot of information.  So I am wondering what is the process of implementing a standard for a file format.  What are the steps to get a working implementation without passing by parts of the standard?  Are there any best practices?

Also, is it even possible to program this alone in a reasonable time?

From what I have already found out, ePub is basically a zip archive.  That means I could probably use zlib to decompress it.  The content is in XHTML and CSS, so I believe it should be possible to display it in a WebView.  The parts that are missing are writing the code that can read the metadata and manage the non-standard XHTML extensions.

答:
Let's try to answer your question a point at a time.

I'm note sure to understand your question (I'm not an english mothertongue speaker...). If you are asking what is the process used to define a new file format like ePub, then the answer is: gather a few seasoned specialists around a table, feed them with hamburgers and problems and wait for a document. If you are asking how a working ePub reader is developed to serve as a reference implementation, then the answer is: have the specialists write one together with the reference document. Most of times, this implementation actually comes sooner than the reference document. If you are asking how to implement your own reader, see below.

Yes, there are Best Practices for developing tools for XML/HTML and ePub. They are mostly the same used to develop any other kind of software. Any good book describing the BPs used in your preferred language (Java on Android) can give you all the info you need. To see which BPs are actually used in this specific field, you have to explore the world of XML and XML tools (parsers, converters and so on).

Yes, it is surely possible to write an ePub reader by yourself in a reasonable amount of time. As you have already seen by yourself, a ePub reader is actually just a program that decompresses a zip file in a temporary storage area (in memory or on disk) and shows the pages in a web browser (WebView in Android) starting from index.html. Just do not try to (re)write the web browser yourself... Writing an ePub editor would be a completely different story.

Well, XHTML is actually an "application" of XML. There is nothing into XHTML that is "non-standard". There could not even be. XML is extensible by definition. It can accomodate every new tag or structure. Sure, there is a part of the ePub document that is not strictly related to XML and does not comply with XML standard but it is not actually non-standard. It is just another type of data. As a consequence, you can use any standard XML tool to deal with the XML/XHTML part of ePub.

By far, the best way to write your own ePub reader is:

Find some high-level description of the file format (even the ePub wikipedia page should be enough)

Study some existing, open source reader's code. Just Google around for "java or android open source epub reader".

Try to reimplement the program functionalities one at a time (and keep asking for help/info).

Good luck.


答:
I guess it really depends on how you're putting the regex together.  Generally speaking I think it would be a bad idea to put comments within the actual regex string itself (not possible in most scenarios, as far as I know).  If you really need to comment specific portions of a regular expression (are you trying to teach someone?), then break each chunk into separate strings on their own lines, and comment each line using the normal commenting process for your programming language.  Otherwise, pleinolijf's answer is pretty good.

example:

```<code>string myregex = "\s" // Match any whitespace once
+ "\n"  // Match one newline character
+ "[a-zA-Z]";  // Match any letter
</code>```

Title: Commenting regular expressions

Body: Are there any common practises for commenting the regular expressions: inline comments referring different part of RegEx or general comment for all expression?</p>

Body:
I guess it really depends on how you're putting the regex together.  Generally speaking I think it would be a bad idea to put comments within the actual regex string itself (not possible in most scenarios, as far as I know).  If you really need to comment specific portions of a regular expression (are you trying to teach someone?), then break each chunk into separate strings on their own lines, and comment each line using the normal commenting process for your programming language.  Otherwise, pleinolijf's answer is pretty good.

example:

string myregex = "\s" // Match any whitespace once
+ "\n"  // Match one newline character
+ "[a-zA-Z]";  // Match any letter


问:
What's the most absurd myth about programming issues?
To put it another way... What is the most commonly held and frustrating misunderstanding about programming, you have encountered?

Which widespread and longstanding myths/misconceptions do you find hard for programmers to dispel/correct.

Please, explain why this is a myth.

答: Bug free software. Later I came to know that every program would still run with Bugs and whole play was about accomplishing customer Requirements. </p>


答:
Typically, I will write a regex and not explain the individual pieces of the regex, but rather what it's purpose is. That is that what and why. This is a bit like asking "What should my comments look like?" to which one would say "Don't write what the code is doing, write why the code is doing what it does"

```<code>// Strip the leading "?" and remove the query parameters "offset=<integer>" & "count=<integer> so we have a pattern of the request"
var search = location.search.substring(1).replace(/offset=[0-9]+?&/g, "").replace(/count=[0-9]+?&/g, "");
</code>```

Unless you are trying to teach someone about regexes via comments in code, I don't think explaining what each individual piece will do. When working with other programmers, you can safely assume that one would know something as global regular expressions.

Title: Commenting regular expressions

Body:
Typically, I will write a regex and not explain the individual pieces of the regex, but rather what it's purpose is. That is that what and why. This is a bit like asking "What should my comments look like?" to which one would say "Don't write what the code is doing, write why the code is doing what it does"

// Strip the leading "?" and remove the query parameters "offset=<integer>" & "count=<integer> so we have a pattern of the request"
var search = location.search.substring(1).replace(/offset=[0-9]+?&/g, "").replace(/count=[0-9]+?&/g, "");

Unless you are trying to teach someone about regexes via comments in code, I don't think explaining what each individual piece will do. When working with other programmers, you can safely assume that one would know something as global regular expressions.


问:
Is there a purpose for using pull requests on my own repo if I am the only developer?
So I got started with a real project of mine on GitHub and things are going pretty well and ideas are flowing a lot faster than I initially thought. In order to keep things organized, I setup some branches so I can develop different features separately.

Now when I push my branch to GitHub, I have that section where I have two buttons : Pull Request and Compare with the name of the branch I recently pushed to. I understand the purpose of the Compare button but I don't get why I would want to create a pull request on my own repo.

Can someone explain me why I would do that? Is it useful to make pull request on my own repo if I am the only developer?

答:
It sounds like you have remote branches as well as local branches. If you're finding the overhead of that workflow too much, then you can always work on different features using local branches without pushing them.

It basically comes down to doing what works for you. Working with branches is a huge benefit to git, and github makes that really easy, but as a lone developer there isn't a great need to use the pull request model and committing directly to master should work just fine. When your project eventually becomes incredibly successful and tens or hundreds of developers are working on it, you'll find getting pull requests from their forks is a great way of keeping track of the project.


问:
What is the standard term for my role?
I'm doing work that involves writing code and managing developers in a "special projects" division of a large company.  I'd like to define my role better and figure out if there's an industry standard term for what I do, so that it will be easier for me to research best practices and work on a career path

What I do all day:

A macro that connects an Excel sheet to an Access database is acting funny; I get called in to figure out what's happening and debug it.

Someone needs data extracted from a bunch of files on Sharepoint.  I figure out a client-side solution because I'm not authorized to do anything server-side and getting IT to do anything would take several months and need a business case.

A manager wants a new data entry tool for their team.  I interview the manager and team members to work out the functional requirements, then design/develop/test the application.

Someone needs a VBA script to crunch some data for their presentation that's due in two hours.  I drop everything I'm doing to hack out a quick script and run the analysis, without much in the way of testing.

A developer has been hired to build a database for one of the teams, since I'm working on too many different things and don't have time to take this project on in the timeframe required.  I direct his work and push him to meet certain deadlines, interview stakeholders to get more info that will help him figure out how to build the necessary forms, and modify the functional requirements of the database to fit in the timeframe.

Someone wants to load a set of data into a GIS system and set up an ongoing refresh and reporting of this data set.  I facilitate the conversation between the GIS developers and the owners of this data set, and design a demo application as proof of concept.

It's kind of an "all-purpose programming and IT management" position, but it's not officially IT because the company has an actual IT department with a rigorously defined system of submitting requests, developing code, and managing projects.  What I do, I guess, is more of a handyman job, where stuff falls to me because I'm the geekiest one in the room.  Is there a standard term in the software world for what I do?

答:
Sounds like support engineer to me. Granted you're an internal corporate developer getting tossed halfway between IT tasks and projects, but using code as your go-to tool for solving problems makes your job one as a programmer/developer/engineer regardless of everything else.

I would call it support engineer or even something like internal professional services engineer in this case because those are developers who typically do one-offs like you're constantly talking about. They're the developers that get stuff up and keep things running, not the ones whiteboarding in the back room while banging out something enterprisey for months on end.

At least that's what I've seen, others may have seen professional services and support engineers doing different things.

That said, I do think there is a wealth of best-practices and industry knowledge for how to do professional services engineering and support engineering well that could definitely benefit you given the work you're doing.

Title: What is the standard term for my role?


问:
What is the need for 'discoverability' in a REST API when the clients are not advanced enough to make use of it anyway?
The various talks I have watched and tutorials I scanned on REST seem to stress something called 'discoverability'. To my limited understanding, the term seems to mean that a client should be able to go to http://URL - and automatically get a list of things it can do.

What I am having trouble understanding - is that 'software clients' are not human beings. They are just programs that do not have the intuitive knowledge to understand what exactly to do with the links provided. Only people can go to a website and make sense of the text and links presented and act on it.

So what is the point of discoverability, when the client code that accesses such discoverable URLs cannot actually do anything with  it, unless the human developer of the client actually experiments with the resources presented? This looks like the exact same thing as defining the set of available functions in a Documentation manual, just from a different direction and actually involving more work for the developer. Why is this second approach of pre-defining what can be done in a document external to the actual REST resources, considered inferior?

答:
NOTE: I'm no expert on the subject, but I went through a similar process of trying to reconcile the different nuances of people's interpretations of "REST" a few years ago, and this is the takeaway I got from looking into it at the time.

To my understanding, this stems from Roy Fielding's Hypermedia as the Engine of Application State aka "HATEOAS", which then becomes an enabler of the idea of a "semantic web".

So...basically, and again as I understand it, you make your RESTful application basically self describing such that the consumer does not have to have prior knowledge of a formal contract to consume your content / functionality. They are able to engage from some defaulted root endpoint and then walk contextually relevant links that your app provides as the consumer interacts. The consumer, of course, can be a person or a systemic agent.

If you are just using "REST" for pretty urls mapped to CRUD operations that a consumer must have prior knowledge of and calls according to a well known contract, Roy Fielding would deem it not truly RESTful.

That's not to say that a REST flavored RPC service set up can't be useful / an improvement over a more elaborate RPC model and suitable for limited / controlled usage, but the hardliners will look down their noses at it and consider it to be degenerate / not really REST.


问:
Advantages and disadvantages to using XAML/C# or HTML5/JavaScipt for Metro apps?
I was just wondering if there are any major advantages or disadvantages to using either XAML/C# or HTML5/JavaScript for Metro Apps.</p>

答:
Yes, in most cases, JavaScript is a native language. Depending on where it's running, its compiled (JIT Style) into machine code.

For example, if you're running the Chrome browser, the V8 engine does just that which is mentioned above. It's my understanding that IE 10 is doing the same, as with the other prevalent browsers which support the ECMAScript 262 standard.

Entou, in most cases JavaScript is no longer an interpreted language. It's a full-fledged, Object-Oriented, Prototypal-based, client/ server-side, ubiquitous programming language.


答:
"Clients" may not be advanced enough to make use of it, but the users of clients can. A client can be something as simple as a web browser, after all. The discoverability is all about enabling people to learn and use the API.

For example, Jenkins (the CI server) has a REST-like interface. Go to any page, postfix the URL with "/api", and you get a page describing everything you can do. It makes learning the API trivial. For example, http://ci.jruby.org takes you to the jenkins server for jruby, and http://ci.jruby.org/api takes you to the api for that specific page.

Title: What is the need for 'discoverability' in a REST API when the clients are not advanced enough to make use of it anyway?

Body:
The various talks I have watched and tutorials I scanned on REST seem to stress something called 'discoverability'. To my limited understanding, the term seems to mean that a client should be able to go to http://URL - and automatically get a list of things it can do.

What I am having trouble understanding - is that 'software clients' are not human beings. They are just programs that do not have the intuitive knowledge to understand what exactly to do with the links provided. Only people can go to a website and make sense of the text and links presented and act on it.

So what is the point of discoverability, when the client code that accesses such discoverable URLs cannot actually do anything with  it, unless the human developer of the client actually experiments with the resources presented? This looks like the exact same thing as defining the set of available functions in a Documentation manual, just from a different direction and actually involving more work for the developer. Why is this second approach of pre-defining what can be done in a document external to the actual REST resources, considered inferior?


问:
On Developing Web Services with Global State
I'm new to web programming. I'm more experienced and comfortable with client-side code. Recently, I've been dabbling in web programming through Python's Google App Engine. I ran into some difficulty while trying to write some simple apps for the purposes of learning, mainly involving how to maintain some kind of consistent universally-accessible state for the application.

I tried to write a simple queueing management system, the kind you would expect to be used in a small clinic, or at a cafeteria. Typically, this is done with hardware. You take a number from a ticketing machine, and when your number is displayed or called you approach the counter for service. Alternatively, you could be given a small pager, which will beep or vibrate when it is your turn to receive service. The former is somewhat better in that you have an idea of how many people are still ahead of you in the queue.

In this situation, the global state is the last number in queue, which needs to be updated whenever a request is made to the server. I'm not sure how to best to store and maintain this value in a GAE context.

The solution I thought of was to keep the value in the Datastore, attempt to query it during a ticket request, update the value, and then re-store it with put. My problem is that I haven't figured out how to lock the resource so that other requests do not check the value while it is in the middle of being updated. I am concerned that I may end up ticket requests that have the same queue number. Also, the whole solution feels awkward to me. I was wondering if there was a more natural way to accomplish this without having to go through the Datastore.

Can anyone with more experience in this domain provide some advice on how to approach the design of the above application?

答:
Each ticket request is logged in a ticket database table that stores the unique ID of the request and the time on which the request was made.

Whenever it is time to service a new request, fetch the first row from the ticket database table, ordered by request time.

Delete the row from the database.

If the last two steps are run as a single transaction, you'll be able to have multiple agents servicing requests simultaneously without treading on each others' toes.

I'm not sure how Google AppEngine's data store works, but any decent database should give you:

Automatic IDs that are guaranteed to be unique;

Transactional queries that can lock rows required by that transaction.


问:
Implementation ideas to store multiple files within a single file for faster access?
My requirement is to store a large number of files within a single file.The files stored could be anything like images, videos or simple text files as well. I want some ideas to implement the same. I am thinking of implementing a file system within a file, but am not sure if its a good idea.

Adding in more details as requested : Platform to be developed on is Android. The idea initially was to store all the data using sqlite and provide encryption on it, but I think it will eventually lead to a slow down as the file size increases. The file is going to increase in size with time.

The main area of concern here is the access time. Also I want to provide encryption for this single file.
Any suggestions are welcome.

答:
but am not sure if its a good idea.

It seems to be! You don't say what operating system you're working with. In Unix-based operating systems, a directory already is a kind of file. So, two things to consider:

You may be able to just mark this requirement 'done' and move on.

If you decide to go ahead with the project, you'll need to think carefully about how your implementation can be faster than existing ones.


答: I think I do what everybody who is stuck working in this industry does.  I get it done as fast as I can and if I have to leave out some of the nice things that would help prevent problems in the future, or make problem-solving easier in the future, I do.  It is not an optimal situation but when you are stuck with deadlines based on estimates based on estimates, based on a lot of unknown variables, it is pretty much the best you can do.</p>


答:
This boils down to what I've started thinking of as "The Eternal Conflict" (between business and engineering). I don't have the solution as it's a problem that never goes away but you can do stuff to help mitigate.

Communicate Value

What people often don't realize is that as engineers we're just assuming the problem of "successful business" is always a given. We want our code to be nice and neat and maintainable so that we can add new features and tweak existing ones rapidly and with a minimum of customers doing QA for us by discovering bizarre fringe cases that would have been thwarted by better code. Keeping customers and maintaining a competitive edge with features and finesse nobody else can produce fast enough are both business wins that good code directly contributes to and inform much of the reason we want better code in the first place.

So spell it out. "We want to do X in our codebase because if we don't it will impact business negatively due to Y" or " ...because it will enhance our ability to stay competitive by improving our ability to turn new improvements and features around faster."

And do your best to try and get tangible evidence that improvements are working. If improving some subset of an app resulted in faster feature/improvement, check whatever backlog tool you might be using for evidence thereof and point it out at appropriate meetings.

Get the Team on the Same Damn Page

Egos are often a problem. One thing engineering teams need very badly is to establish the value of having some kind of agreed upon consistent approach to solving certain types of problems over everybody doing their own cup of Kool Aid d'jour because they know better. It's okay to believe the other guy's preference is worse than yours but value consistency over being more right if his approach is workable and it's an argument you can't win. Compromise for the sake of consistency is key. When things are consistent it's harder to do them wrong since the consistent established way will usually also be the fastest way.

Pick the Right Tools

There are two schools of frameworks/toolsets/libraries/whatever. "Set 99% of it up for me so I have to know/do very little" vs. "stay out of my way when I don't want you there, but help me DIY very rapidly and consistently with stuff that I actually want to use on the carrot rather than stick principle." Favor the second one. Flexibility and granular control should never be sacrificed at the altar of rapid turnaround because to biz, "we can't do this because our own tools won't let us" is never an acceptable answer and the question will always come up for non-trivial/disposable product engineering. In my experience, inflexible tools almost always get busted wide open or worked around inelegantly and make a big giant unmaintainable mess. More often than not, the flexible/easier to modify solutions are just as or very nearly as fast in the short term, regardless. Fast, flexible, and maintainable are possible with the right tools.

FFS, If Engineers Don't Decide, at Least Get Engineer Input on Picking the Tools

I get the sense this is a developer-perspective question but I've been in far too many situations where technology decisions were made with zero engineer input. What the Hell is that? Yes, somebody ultimately has to make the final call, but get some qualified opinions if you're a non-technical manager, not what some sales guy or demo site says about its own products. Anything promising to save you money because people don't need to be as smart or because it protects developers from themselves is a filthy, dirty lie. Hire talent you can trust. Spell out to them what you want from a stack or other tech solution and take their input seriously before deciding what tech bandwagon to jump on.

Focus on Design Over Implementation

Tools are for implementation and as such they can help you, but first priority has to be the architecture regardless of whatever set of toys you have for building that architecture. At the end of the day KISS and DRY and all excellent philosophies that extend from those matter more than whether it's in .NET or Java or perhaps something that's both free AND doesn't suck.

Log Your Concerns

When the biz-side insists you do it the bad way, save that e-mail, especially the part where you said why it would cost you. When all of your predictions come true and serious business-damaging problems result, that's when you've got a big pile of arguments for taking engineer concerns more seriously. But time things carefully. In the middle of the blazing inferno is a bad time for an "I-told-you-so" on following fire code. Put the fire out, and bring your list of previously ignored concerns to a retrospective meeting/conversation, and try to keep the focus on engineering concerns expressed and ignored and the reasoning you understood why they were being ignored, not the names of the actual people making the decision to ignore. You're an engineer. Stay on the problems, not the people. "We expressed concern over X because we were afraid it would lead to Y problems. We were told Z and to put off dealing with it."


问:
What is the best practice, point of view of well experienced developers
My manager pushes me to use his self defined best practices. All of these practices are based on is own assumptions. I disagree with them and I would like to have some feedback of well experienced people about these practices. I would prefer answers from people involved in the maintenance of huge products and people whom have maintained the product for years. Developers with 15+ years of experience are preferred because my manager has that much experience himself. I have 7 years of experience.

Here are the practices he wants  me to use:

never extends classes, use composition and interface instead because extending classes are unmaintainable and difficult to debug.

What I think about that

Extend when needed, respect "Liskov's Substitution Principle" and you'll never be stuck with a problem, but prefer composition and decoration. I don't know any serious project which has banned inheriting, sometimes it's impossible to not use that, i.e. in a UI framework. Design patterns are just unusable.

In PHP, for simple use cases (for example a user needs a web interface to view a database table), his "best practice" is: copy some random php code wich we own, paste and modify it, put html and php code in same file, never use classes in PHP, it doesn't work well for small jobs, and in fact it doesn't work well at all, there is no good tool to work with. Copy & paste PHP code is good practice for maintenance because scripts are independent, if you have a bug somewhere you can fix it without side effects.

What I think about that:

NEVER EVER COPY code or do it because you have five minutes to deliver something,  you will do some refactoring after that. Copy & paste code is a beginners error, if you have errors you'll have the error everywhere any time you have pasted it's a nightmare to maintain. If you repsect the "Open Close Principle" you'll rarely get edge effects, use unit test if you are afraid of that. For small jobs in PHP use at least something you get or write the HTML separately from the PHP code and reuse it any time you need it. Classes in PHP are mature, not as mature as other languages like python or java, but they are usable. There is tools to work with classes in PHP like Zend Studio that work very well. The use of classes or not depends not on the language you use but the programming paradigm you have choosen. I'm a OOP developer, I use PHP5, why do I have to shoot myself in the foot?

When you find a simple bug in the code, and you can fix it simply, if you are not working on the code where you have found it, never fix it, even if it takes 5 seconds.

He says to me his "best practices" are driven by the fact that he has a lot of experience in maintaining software in production (14 years) and he now knows what works and what doesn't work, what the community says is a fad, and the people advocating such principles as never copy & paste code, are not evolved in maintaining applications.

What I think about that:

If you find a bug fix it if you can do it quickly inform the people who've touched that code before, check if you have not introduced a new bug, ideally add a unit test for it.

I currently work on a web commerce project, which serves 15k unique users per day. The code base has to be maintained and has been maintained this way since 2005.

Ideally you include a short description of your position and experience in terms of years effectively maintaining an application which has been in production for real.

答:
Is your manager familiar with an object oriented programming?
Objects were introduced into the PHP not so long time ago and at the beginning it was rather "lets make some libraries as objects, add class statement and we have object oriented programming language"  - very similar to the situation with VB v4

What you describe as practices is at least strange and in some places plainly wrong from the programmer's point of view.
But it seems that those practices work and it may be hard for your manager to become accustomed with something new. Your CEO is concerned with the customers paying for your work and "proper OO practicies" are completely irrelevant for him.

I have seen lot of badly written code but at the same time everyone was happy as this badly written code was doing it's job at least from the user point of view.
In different companies you can see different approach to the programming process if you care about proper practices and want to be what we could call "a good programmer" then you should find a company which cares about such stuff.


答: Have you considered jar format?  It's java-specific but then it would easily port to multiple operating systems. Drawback is your users would need to have java on their machines to do anything with the files after downloading and you would probably have to do work to make that automatic/transparent to them.  You would also have to handle the encryption/decryption in some way.</p>

Title: Implementation ideas to store multiple files within a single file for faster access?

Body:
My requirement is to store a large number of files within a single file.The files stored could be anything like images, videos or simple text files as well. I want some ideas to implement the same. I am thinking of implementing a file system within a file, but am not sure if its a good idea.

Adding in more details as requested : Platform to be developed on is Android. The idea initially was to store all the data using sqlite and provide encryption on it, but I think it will eventually lead to a slow down as the file size increases. The file is going to increase in size with time.

The main area of concern here is the access time. Also I want to provide encryption for this single file.
Any suggestions are welcome.


答:
Note: if you stated the purpose of your file container more clearly, describing access patterns, desired platforms, and the problem you're solving in general, the answers might be better.

Your description looks awfully similar to a game resource file, a renowned file type. These files are not intended to be updated frequently (if ever), but are optimized for fast seeking and reading.

There are several known implementations: for instance, iD Software used WAD files and PAK files, but finally came to use ZIP files.

Many applications use various derivatives of IFF format, built from self-describing chunks, and, with some care, efficiently updatable.

In a chunked file, or a zip file (consider zero compression), you can encrypt each entry independently, before writing it into the file. Provided that you use a block cipher like AES256, your data does not change size, except for aligning it to block boundary. You definitely want your decryption key stored somewhere else :)

Writing a file system to provide encryption is not only possible, but has actually been done many times. For instance, Linux has encfs, and Windows has encrypted folders. TrueCrypt is an advanced virtual encrypted FS available on many platforms.

Please note that while zip files provide for a sort of native encryption, this encryption is relatively weak. Same applies to rar files, for all I know.


答:
As questions I'd consider useful:

When there is a new story created, how much work is being done to make sure of its quality?  Is there a lot of work for developers to do before working on something or is it good to go once the PO has written the request?

How available for questions and clarification has the PO been over the course of the evaluation period?

How receptive to feedback has the PO been in terms of the evolution of the process and team over the course of several sprints?

From a higher level, here's what I'd be watching:

Decision-making.  From prioritizing the backlog to clarifying the requirements on a story, there are lots of decisions that may fall to the PO to handle.  Was this an issue for the team in terms of delivering work?  Were there frequent delays in getting things done?

Communication.  How well were the priorities communicated?  Were there demonstrations of functionality where the PO provided either feedback directly or brought in customers to review new functionality to ensure that it was the desired results?

Vision.  This goes a bit in hand with communication but the idea here is to know what big dates are coming up, how is the work being reviewed and what direction is the team being driven.

Title: Evaluating a product owner

Body: How do you evaluate a product owner? More specifically, how would one conduct a performance review of a product owner? What qualities or characteristics would one look at when reviewing a product owner?</p>


问:
How is Agile different from XP?
I read few articles on web to find out how Agile, XP, Scrum, pair programming are different from each other / related to each other and I derived the following line:

Scrum and XP are almost same. XP has shorter period of releases than Scrum

Pair programming is employed in both Agile and XP methodologies

But I was unable to identify how Agile is different from XP.

More than providing a URL, I would be happy to read your experience and thoughts on this.

答:
Agile is the generic term for the methodology.

XP and Scrum are the specific names for different implementations of that methodology.

The Wikipedia pages are probably good starting points for further reading- check the "References" and "Further Reading" sections at the bottom of each page, but you should look into each and other implementations further before deciding on the one that works for you, or (as others have pointed out) the bits of each implementation that work for you.

Title: How is Agile different from XP?


问:
Is there tool agnostic terminology for source control activities?
My team is entering into some discussions on source control (process and possibly tools) and we would like a tool agnostic terminology for the various activities. The environment does have multiple (old) VCS's, and multiple desired (new) VCS's. Is there a standard definition of activities, or at least some commonly accepted set?

Example activities (in CVS terminology):

Branch

Check out

Update

Merge

答:
As said by @pdr - I am not aware of a set of formally recognized terms. Those used by commonly SVN/CVS are universally understood - repo/checkout/commit etc. Personally I would use this Wikipedia Page.

You should do is create a glossary of terms, based on Wikipedia, and within your team, ensure that you use those terms in all documents. Once complete - consider updating the Wikipedia page.

Edit : -From a comment I made....
In most real world cases I have seen, there is not a lot of difference between how DVCS and centralized ones are used on a daily bases. Even where the power of DVCS is utilized, it's through a set of recipe commands. As such - although conceptually different, to all practical purposes it is theoretical for most developers - therefore common terminology for the daily workflow performed by developers is quite easy.

For instance, @Kaz argues that a Git Clone is a repository- which technically is correct. Practically for most developers it is not treated as anything other than a local copy of a master repository and the actions the perform on it are essentially the same as they do on a CVS checkout - Clone / branch / check in / merge / update push (Git) or "Merge into master branch" (CVS/SVN etc). Litmus test - do you backup the clone every night. If not, it's not a repository, it's a working copy.

Yes - the recipe is different, but the cake tastes surprisingly similar in typical cases.


问:
What sources of sample work should be used in a job interview?
One of my friends has been laid off. When I talked to him, he said they didn't let him take a copy of anything he worked on. When he asked how to show what he worked on to another employer in an interview, he was told that he will have some explaining to do.

Should we, as programmers, be allowed to take samples of our previous work former employers? What sources of code should we be expected to show off in an interview? When almost every employer asks for sample work, how are we to justify what can be sent? Is it our responsibility to maintain after-work projects for our entire life so we have code we can legally show to our next employer?

答:
Recently I started a blog recording my experiences in tackling the challenge of learning to program. As I'm quite a late starter, I don't have a wealth of prior projects so this is also a way to document my progression.This blog would also be a viable online public portfolio of my skills. Nothing in it is built in work time, or relies on work libraries or proprietory concepts that may be covered by confidentiality.

This site is possibly the only code I'd have already to hand-if asked for it at interview; it's public and has a track history-though it would be better if the whole source of such projects were hosted on GitHub or similar.

If I couldn't hand write the basic syntax and concepts for an interview question in the chosen language, I probably wouldn't be good enough for them.


答:
Since each source control tool IS so different, I don't think you will be able to find this vendor-agnostic list of terms that you seek; especially since some of the same words are used for different things between source control tools.

These source control tools all work very differently; some are decentralized, some are not.  Some are based on changesets, others are based on snapshots.  So you should base your terminology on the tool you will be using.

Title: Is there tool agnostic terminology for source control activities?

Body:
My team is entering into some discussions on source control (process and possibly tools) and we would like a tool agnostic terminology for the various activities. The environment does have multiple (old) VCS's, and multiple desired (new) VCS's. Is there a standard definition of activities, or at least some commonly accepted set?

Example activities (in CVS terminology):

Branch

Check out

Update

Merge


答:
Well, to some degree "lingua franca" in SCM exist now, if we'll ignore the extremes of old and new school:

Checkout

Commit

Update

Repository

Working Copy

Merge

have common sense in all (with notes above) first-class citizens in SCM-world


答:
Google confirms it is good idea in some cases: https://www.google.ru/images/nav_logo114.png

In this example Google optimises with reducing http requests number. User downloads one image file containing few navigation sprites and then browser splits  and places it with CSS and JS.


答:
Unfortunately, there is no international system of weights and measures for IT jobs. However, from what you describe, and from experience in dealing with other people in similar positions, I've seen these job titles:

Technical specialist

Technical consultant

Support Analyst Programmer

Title: What is the standard term for my role?

Body:
I'm doing work that involves writing code and managing developers in a "special projects" division of a large company.  I'd like to define my role better and figure out if there's an industry standard term for what I do, so that it will be easier for me to research best practices and work on a career path

What I do all day:

A macro that connects an Excel sheet to an Access database is acting funny; I get called in to figure out what's happening and debug it.

Someone needs data extracted from a bunch of files on Sharepoint.  I figure out a client-side solution because I'm not authorized to do anything server-side and getting IT to do anything would take several months and need a business case.

A manager wants a new data entry tool for their team.  I interview the manager and team members to work out the functional requirements, then design/develop/test the application.

Someone needs a VBA script to crunch some data for their presentation that's due in two hours.  I drop everything I'm doing to hack out a quick script and run the analysis, without much in the way of testing.

A developer has been hired to build a database for one of the teams, since I'm working on too many different things and don't have time to take this project on in the timeframe required.  I direct his work and push him to meet certain deadlines, interview stakeholders to get more info that will help him figure out how to build the necessary forms, and modify the functional requirements of the database to fit in the timeframe.

Someone wants to load a set of data into a GIS system and set up an ongoing refresh and reporting of this data set.  I facilitate the conversation between the GIS developers and the owners of this data set, and design a demo application as proof of concept.

It's kind of an "all-purpose programming and IT management" position, but it's not officially IT because the company has an actual IT department with a rigorously defined system of submitting requests, developing code, and managing projects.  What I do, I guess, is more of a handyman job, where stuff falls to me because I'm the geekiest one in the room.  Is there a standard term in the software world for what I do?


答: It varies a lot from company to company, but a lot of your duties sound like short-term or ad-hoc solutions to business problems. Business Analyst, Business Intelligence, or Systems Analyst seem like the best tags (the last one being the least probable). I would really go with Business Analyst, myself.</p>

Title: What is the standard term for my role?


问:
What do you optimize for?
Generally speaking, what type of optimizations do you typically slant yourself towards when designing software?

Are you the type that prefers to optimize your design for

Development time (i.e., quick to write and/or easier to maintain)?

Processing time

Storage (either RAM, DB, Disc, etc) space

Of course this is highly subjective to the type of problems being solved, and the deadlines involved, so I'd like to hear about the reasons that would make you choose one form of optimization over another.

答:
I would say I optimise toward efficiency, with efficiency being defined as a compromise between development time, future maintainability, user-experience and resources consumed. As a developer you need to juggle all of these to maintain some kind of balance.

How do you achieve that balance? Well, first you need to establish a few constants, such as what the deadline is, what hardware your application will be running on and what type of person will be using it. Without knowing these you cannot establish the correct balance and prioritise where it is needed.

For instance, if you are developing a server application on a powerful machine you might want to trade-off performance efficiency to ensure you hit an immoveable deadline. However, if your developer an application that needs to respond quickly to user input (think a video game) then you need to prioritise your input routine to ensure it is not laggy.

Title: What do you optimize for?


问:
Correct way to sell commercial product with small scripts in it that are GPL?
I'm developing a commercial CMS, which I'm going to sell. I use jQuery, also I use date and time picker jQuery plugin in it, I can say this is just a 1% of my big script.

I don't want sell my whole program as GPL because of these two small integrations (jQuery and DateTime picker).

My questions:

I'm worried about the license issue. What is the best way to sell my  product (what should be the licensing type)?

Is there any way to provide some partial licenses? I mean just add small notification in my license that the jQuery and The DateTime picker is still in GPL, but for the other part of this CMS a commercial license?

If there isn't any way to sell commercial product as close source with GPL small parts, what is the most strong license for selling my product to keep it safe?

答:
In short: no, you cannot include GPL and non-GPL code in the same script.

The long answer: yes, but only if you know exactly what you are doing and aren't breaking the spirit of the GPL. My understanding is:

If you incorporate GPL licensed things into your software, those pieces must stay licensed under the GPL. The means: you must provide copies of those "modules" to anyone who asks for them. If you modified them, you must provide the modified copies.  Finally, you have to include a copy of the GPL for those parts of your application when distributing your application. There is a minor misunderstanding among some people I've talked to that if you use GPL licensed software, your entire application defaults to a GPL license. This is not true.

The GPL makes a few notable exceptions. If you run software in a separate process it constitutes a separate program. The implication here is that you may interface with GPL software free from the binds of the GPL so long as the exchange is limited to message passing (IPC) and not direct linking (updating the PC and jumping into GPL land). A client to a server running GPL software is not bound by the GPL. Generally, a copyright (not EULA) license pertaining to a software work itself does/can not cover the output of the program to which it applies.

Additionally, the GPL allows for aggregate works.  Aggregate works are covered in section 5 of the GPL-v3:

A compilation of a covered work with other separate and independent
  works, which are not by their nature extensions of the covered work,
  and which are not combined with it such as to form a larger program,
  in or on a volume of a storage or distribution medium, is called an
  “aggregate” if the compilation and its resulting copyright are not
  used to limit the access or legal rights of the compilation's users
  beyond what the individual works permit. Inclusion of a covered work
  in an aggregate does not cause this License to apply to the other
  parts of the aggregate.

Note that an aggregate work does not refer to a software that's linked against a GPL component. As the GPL explicitly states, if any linking occurs (unless excepted either by the LGPL or explicitly such as with the system library exception) to software covered by the GPL, then the client work becomes GPL. So if the code ends up in the same binary or runs in the same process such that functions exposed are invoked directly, it generally must follow the GPL.

This is where it gets interesting. I have no idea if this would hold up in court, but based on my reading, it seems plausible that a GPL component and a non-GPL component could execute within the same process so long as one does not directly invoke the other. In other words, if they only share a data model, I believe they can coexist. In any event, drawing a hard process boundary between two such components is never a bad idea.

For example, Viscosity is a VPN application that provides a configuration interface for an aggregate OpenVPN client. Viscosity's user interface is not covered by the GPL as it simply generates configuration data for OpenVPN and does not link against OpenVPN or do anything other than (instruct the system to) invoke the binary in its entirety. However, in order to make the integration more smooth, Viscosity also ships a patched version of OpenVPN. The patches they apply and resulting binary work derived from OpenVPN is covered under the GPL.

The other route is a SAAS model.  Don't even sell the software but sell the services it provides (and related support for those services).  This is, in my opinion, the most popular model currently.  In this model, your intellectual property (often, business model) is not the software (IP is irrelevant).  You write the software, and then you become the best provider of its services to your customers.  This is how Github, Bitbucket, etc. work.


问:
Do there exist programming languages where a variable can truly know its own name?
In PHP and Python one can iterate over the local variables and, if there is only once choice where the value matches, you could say that you know what the variable's name is, but this does not always work. Machine code does not have variable names. C compiles to assembly and does not have any native reflection capabilities, so it would not know it's name. (Edit: per Anton's answer the pre-processor can know the variable's name).

Do there exist programming languages where a variable would know it's name?

It gets tricky if you do something like b = a and b does not become a copy of a but a reference to the same place.

EDIT: Why in the world would you want this? I can think of one example: error checking that can survive automatic refactoring. Consider this C# snippet:

```<code>private void CheckEnumStr(string paramName, string paramValue)
{
    if (paramName != "pony" && paramName != "horse")
    {
        string exceptionMessage = String.Format(
            "Unexpected value '{0}' of the parameter named '{1}'.",
            paramValue,
            paramName);
        throw new ArgumentException(exceptionMessage);
    }
}
...
CheckEnumStr("a", a); // Var 'a' does not know its name - this will not survive naive auto-refactoring
</code>```

There are other libraries provided by Microsoft and others that allow to check for errors (sorry the names have escaped me). I have seen one library which with the help of closures/lambdas can accomplish error checking that can survive refactoring, but it does not feel idiomatic. This would be one reason why I might want a language where a variable knows its name.

答:
It depends on what you mean by name.  If we rephrase the question as "can we extract, from any variable, a unique identifier for that variable" then in C the answer is a definite yes: the address-of operator will give us that.  In code:

```<code>int x;
// &x now uniquely identifies x (while it is valid).
</code>```

If we rephrase it as "given an identifier, can we apply an operation to it to get a string containing it", then the answer in C is once again yes: we can make a macro which, applied to the identifier, will stringify it.  Once more in code:

```<code>#define str(s) str2(s)
#define str2(s) #s

int x;
// str(x) will now be "x"
</code>```

If we look in the context and C++, and ask "given an lvalue reference, can we get a textual representation with which this reference was first defined", the answer is no.  In fact, there need not be such a variable: we may have a reference to const which was initialised with an rvalue.

It would definitely be possible to create a language similar to C++, but where this information can be found.  Thus, theoretically, such a language exists.  I am unaware of any that support this in practice; the question as phrased above is mostly meaningful in a language where things are indeed declared, and such languages tend to shy away from the runtime overhead that this would require.

Reaction to edit:  this depends on how the auto-refactoring tool works.  With the macro solution, the call would be CheckEnumStr(STR(a), a);.  The tool could decide to treat the macro invocation as a function call and rename the a, or expand the macro and not modify the "a".

Body:
It depends on what you mean by name.  If we rephrase the question as "can we extract, from any variable, a unique identifier for that variable" then in C the answer is a definite yes: the address-of operator will give us that.  In code:

int x;
// &x now uniquely identifies x (while it is valid).

If we rephrase it as "given an identifier, can we apply an operation to it to get a string containing it", then the answer in C is once again yes: we can make a macro which, applied to the identifier, will stringify it.  Once more in code:

#define str(s) str2(s)
#define str2(s) #s

int x;
// str(x) will now be "x"

If we look in the context and C++, and ask "given an lvalue reference, can we get a textual representation with which this reference was first defined", the answer is no.  In fact, there need not be such a variable: we may have a reference to const which was initialised with an rvalue.

It would definitely be possible to create a language similar to C++, but where this information can be found.  Thus, theoretically, such a language exists.  I am unaware of any that support this in practice; the question as phrased above is mostly meaningful in a language where things are indeed declared, and such languages tend to shy away from the runtime overhead that this would require.

Reaction to edit:  this depends on how the auto-refactoring tool works.  With the macro solution, the call would be CheckEnumStr(STR(a), a);.  The tool could decide to treat the macro invocation as a function call and rename the a, or expand the macro and not modify the "a".


问:
What is the best practice for website design and markup now that mobile browsers are common?
Back in 2008, smartphones were a small market and it was commonplace for sites to be designed for a fixed width - say, 900px or 960px - with the page centered if the browser window was larger. Many designers said fluid width was better, but since user screens typically varied between 1024x768 and 1920x1080, fluid width allowed longer line length than is optimal for ease of reading, and so many sites (including Stack Exchange) use fixed width.

Now that mobile devices are common, what is the the best approach to support both desktop and mobile browsers?

Establish a separate mobile site (e.g: mobile.example.com)

Serve a different CSS to mobile devices; if so how? Server-side browser sniffing, or a @media rule?

Use Javascript or something to adapt the website dynamically to the client? Should all websites be expected to be responsive?

Some kind of fluid layout

Something else?

答:
I think the answer depends on the nature of the project you have. I had the same question yesterday and for my project the best answer was to create a different mobile website. It was however very close to add responsive css to it.

My reasons for doing another website:
1) My design was not built to be responsive. To turn it into responsive would take a while.
2) The website design was considerably different then the mobile design. It would have been a challenge to make the change, I would have to load things just for the mobile version (and hide them on the full page website) and the other way around.
3) my mobile website is a lot simpler then the full website, if I use responsive design then on the mobile website a lot more code would be loaded that would be just hidden. This will make the pages work a lot slower then on a dedicated website.

In short, I was concerned about turning the design into a responsive one and about the speed of the application on mobile devices.

To create the mobile website will not be so hard, I can reuse the same models/controllers and just change the views.

However, if my design was built to be responsive from the start then i would have probably chosen to make it responsive.


问:
Should I use a parser generator or should I roll my own custom lexer and parser code?
What specific advantages and disadvantages of each way to working on a programming language grammar?

Why/When should I roll my own? Why/When should I use a generator?

答:
Have you considered Martin Fowlers language workbench approach? Quoting from the article

The most obvious change that a
  language workbench makes to the
  equation is the ease of creating
  external DSLs. You no longer have to
  write a parser. You do have to define
  abstract syntax - but that's actually
  a pretty straightforward data modeling
  step. In addition your DSL gets a
  powerful IDE - although you do have to
  spend some time defining that editor.
  The generator is still something you
  have to do, and my sense is that it
  isn't much easier than it ever was.
  But then building a generator for a
  good and simple DSL is one of the
  easiest parts of the exercise.

Reading that, I would say that the days of writing your own parser are over and it's better to use one of the libraries that are available. Once you've mastered the library then all DSLs that you create in the future benefit from that knowledge. Also, others don't have to learn your approach to parsing.

Edit to cover comment (and revised question)

Advantages of rolling your own

You'll own the parser and gain all that lovely experience of thinking through a intricate series of problems

You may come up with something special that no-one else has thought of (unlikely but you seem like a clever chap)

It'll keep you occupied with an interesting problem

So in short, you should roll your own when you want to really hack deep into the bowels of a seriously difficult problem that you feel strongly motivated to master.

Advantages of using someone else's library

You'll avoid re-inventing the wheel (a common problem in programming you'll agree)

You can focus on the end result (you shiny new language) and not worry too much about how it's parsed etc

You'll see your language in action much faster (but your reward will be less 'cos it wasn't all you)

Therefore, if you want a quick end result use someone else's library.

Overall, this comes down to a choice of how much you want to own the problem, and thus the solution. If you want it all then roll your own.


问:
How can I track programming productivity on a daily basis?
How can I track that I'm developing software more or less productive than the previous days? </p>

答:
Counting lines of code is an imperfect measurement as it offers no insight into the quality of the code but can be used to determine general productivity. Depending on what language you use there are different tools that will count lines of code for you but I've requested that BitBucket, a Git Repository, add productivity related statistics.

https://bitbucket.org/site/master/issue/4307/feature-request-contributor-statistics


问:
How do you balance between "do it right" and "do it ASAP" in your daily work?
I find myself pondering over this question from time to time, again and again. I want to do things the right way: to write clean, understandable and correct code that is easy to maintain. However, what I end up doing is writing patch upon a patch; just because there is no time, clients are waiting, a bug should be fixed overnight, the company is losing money on this problem, a manager is pressing hard etc., etc.

I know perfectly well that in the long term I am wasting more time on these patches, but as this time spans months of work, nobody cares. Also, as one of my managers used to say: "we don't know if there will be a long term if we don't fix it now."

I am sure I am not the only one entrapped in these endless real/ideal choice cycles. So how do you, my fellow programmers, cope with this?

UPDATE:
Thank you all for this interesting discussion.
It is sad that so many people have to choose daily between a quantity and a quality of their code. Still, surprisingly many, people think it is possible to win this battle, so thank you all for this encouragement.

答:
The optimal balance may be to spend as much extra time doing it right as you would waste fixing the bugs you eliminate by doing it right.  Avoid gold-plating the solution.  In most cases the Volkswagen solution done right is as good as the Cadillac solution.  You can usually upgrade later when it is proven you need the Cadillac.

Fixing code that hasn't followed best practices often take much longer. Trying to find where the null is coming from when the call looks like a.b.c.d.e(), can take a long time.

Applying DRY and reusing existing code is usually much faster than coding and testing yet another solution. It also makes it easier to apply changes when they do occur. You only need to change and test one set of code, not two, three, or twenty.

Aim for solid basic code. A lot of time can be wasted trying to make it perfect.  There are best practices that lead to code which is fast, but not necessarily the fastest it could be.  Beyond that, trying to anticipate bottlenecks and optimize the code as it is built can be wasted time. Even worse, the optimization may slow the code down.

Whenever possible, provide the minimal working solution. I have seen weeks wasted gold plating solutions. Be extremely careful about scope.

I spent some time working on project that should have taken six months. When I joined it had been in progress for a year-and-a-half. The project lead had asked the project manager one question at the start: "Do you want me to do it right or be responsive?" In one week, a feature was implemented Monday, Wednesday, and Friday; Tuesday and Thursday the feature was removed.

EDIT: When the code is done to a satisfactory level, leave it.  Don't go back to fix it if you come up with a better way to do it.  If you must make yourself a note.  If changes are required, review your idea and implement it then if it still makes sense.

If there are places where you would implement extensions for upcoming features, don't implement the extensions.  You could leave a marker comment to remind you where to make the changes.


问:
KISS principle applied to programming language design?
KISS ("keep it simple, stupid" or "keep it simple stupid", see e.g. here) is an important principle in software development, even though it apparently originated in engineering. Citing from the wikipedia article:

The principle is best exemplified by the story of Johnson handing a team of design engineers a handful of tools, with the challenge that the jet aircraft they were designing must be repairable by an average mechanic in the field under combat conditions with only these tools. Hence, the 'stupid' refers to the relationship between the way things break and the sophistication available to fix them.

If I wanted to apply this to the field of software development I would replace "jet aircraft" with "piece of software", "average mechanic" with "average developer" and "under combat conditions" with "under the expected software development / maintenance conditions" (deadlines, time constraints, meetings / interruptions, available tools, and so on).

So it is a commonly accepted idea that one should try to keep a piece of software simple (or simple stupid, in case you omit the comma) so that it easy to work on it later.

But can the KISS principle be applied also to programming language design? Do you know of any programming languages that have been designed specifically with this principle in mind, i.e. to "allow an average programmer under average working conditions to write and maintain as much code as possible with the least cognitive effort"?

If you cite any specific language it would be great if you could add a link to some document in which this intent is clearly expressed by the language designers. In any case, I would be interested to learn about the designers' (documented) intentions rather than your personal opinion about a particular programming language.

答:
If a language is fixed in its design because of KISS, it cannot grow. A language that cannot grow will die.

In the following video Guy Steele cleverly explains that a programing language must be allowed to grow and why. If you apply KISS, then how can a langauge grow because once released, it's set of tools is fixed and never allowed to change.

Guy Steele's keynote at the 1998 ACM OOPSLA conference on "Growing a
  Language" discusses the importance of and issues associated with
  designing a programming language that can be grown by its users.

It is an hour long video but worth watching. If you don't know who Guy Steele is you really should when talking about language design.

I choose this video as the answer because I believe that applying KISS to language design in general is wrong, and hope that seeing a speech from a noted person of language design will help to expand your understanding of the future of language design.

Since you came here to learn about language design and I gave you a reason not to use KISS it is only fair that I point out something that I find of help in language design. Cognitive dimensions of notations

EDIT

When I wrote the above answer it is was based on the reasoning of: if an engine can be only maintained with a fixed set of tools then my reformulation of that meaning with respect to language design is that a language cannot change once released. The comments are indicating that that was not what was meant. So let me put forth this modified answer that will be more in-line with the revised understanding.

If one takes a look at Cognitive dimensions of notations then one learns that there are many competing dimensions associated with language design than just simplicity and if you focus too heavily on one, you will suffer in others. With the question of is focusing heavily on simplicity (KISS) good, and backed up by noted people of language design, I submitted the speech by Guy Steele to show that trying to keep a design solely simple will impact other dimensions. More importantly I am trying to convey that you need to look at many dimensions and weigh the pros and cons of them, not just simplicity.