问:
Problems (such as maintenance) in development with unpopular language
I'm developing some application with clojure(lisp) alone in my team. It starts as small application. No problem. But as it's having features and extending the area, it's becoming important program.

I worried about maintenance or something. No one in my team knows clojure or lisp nor is interested in languages such as them.

So, isn't it wrong to do programming in unpopular languages? (for my own fun?) Should I use more popular languages? (at least such as python)

I'm sure if I leave the team, --not saying I'm leaving. :)-- no one would maintain it. This program will be destroyed and some will develop with other language.

I'm very enjoying developing with clojure though, I came across with that this might be not for my team.

What do you think about this? I think many programmers loving unpopular languages have been concerning similar issue.

答:
Clojure might have a small installed base at present (it appeared in 2007) but it's hardly unpopular - in fact it's possibly the "hottest" new language around. I'd be surprised if you couldn't find other people interested in learning it.

Anyway, whether to adopt a new language however should always be a decision based on value to the business. You might discuss with your manager along the following lines:

Advantages of adopting Clojure:

More productive than other languages used - as evidenced by the amount of useful functionality you have delivered in a small amount of time and with fewer lines of code

We already have one important app (yours) written in Clojure so it is worth building Clojure skills to maintain it (rather than doing an expensive rewrite)

Use of Clojure will be seen as innovative and may be a good way to motivate talented developers to join / stay at the company.

Disadvantages of adopting Clojure

One extra language to support

Developers may need more training and time to get up to speed

If I was a manager evaluating this decision, I'd probably like the idea of higher productivity from Clojure enough to allow some limited experiments, and defer the decision until it was clear how well the team were taking to it. In that case, you would probably need to be an advocate, act as a good teacher and help bring the others on board.


问:
Why is CS taught to be memorized?
I have been taking Advanced Placement Computer Science for this past year in high school. It seems as though we are taught simply to memorize code and functions and not how to be resourceful and efficient in using documentation and the like.

Practically, I imagine many (if not all) programming jobs would allow you to flip through documentation, review past code and the code of others, essentially doing what my teacher would consider "cheating."

While I do agree core concepts are essential to memorize (in any subject matter), it seems superfluous and impractical to me to give a pen-and-paper exam for a CS class, especially when practically you would have a compiler, debugger, reference manuals, and the entire internet to refer to in any real-world work situation.

Why is CS taught focusing on the memorization of code and functions as opposed to teaching useful skills including how to use and interpret documentation, sample code, the debugger and such?

答:
Pen and paper exams actually do make sense if the goal is to test a complete understanding of the subject at hand.  I did take the Computer Science AB exam almost a decade ago and I agree with the pen and paper method.

You should know enough of any algorithm you learn in the lower levels of Computer Science to be able to reason out how to write the implementation code in your target language.  Students should also be able to write code by hand with mostly correct syntax.  We all miss a semicolon or parenthesis sometimes :).  Also debugging and design skills can be tested without inference from a helpful IDE.

If a student cannot do this, then they do not possess mastery of that topic, just perhaps a passing familiarity.

ContentLicense: CC BY-SA 3.0

Title: Why is CS taught to be memorized?


问:
Why don't mobile platforms support generational garbage collection?
Both Windows Phone/Xbox and Android lack support for generational garbage collection. This is frustrating for a lot of programmers. There seems to be a legitimate engineering reason to it, but I can't figure it out.

Current phones have more memory and probably better CPUs than the desktops/laptops running .NET 1.1 with generational GC back in 2001, and I can't think of any reasons that ARM processors would be worse at generational GC than x86 would. There's also less need for multitasking on phones and consoles, so there's relatively more free heap space.

So what gives?

Edit: A few points to clarify:

These platforms use garbage collection for apps exclusively, so my question isn't about why GC isn't supported; my question is about why generational garbage collection isn't.

The reason that people are frustrated about the lack of generational GC is that non-genrational GC is extremely inefficient. (That means that battery life isn't the reason.)

I do believe that there's an honest technical reason for the lack of generational GC support. This isn't a rhetorical question.

答:
There is some additional cost to generational garbage collection.

The generational collector needs to be able to find out when older objects point to newer objects. We can't trace through the older object to find these cases because that would defeat the purpose of generational collection. Instead, we somehow need to detect when this happens and make note of it for the collection phase. Regardless of how you are going to do that, it'll add some overhead to the collection process.

On a desktop system, your operating system is busily doing all kinds of things with memory behind the scenes. It supports features like sharing pages between processes, writing unused pages to disk, providing memory mapping between processes, etc. My understanding is that some of the functionality used there makes it possible to more efficiently track pointers being changed. The operation is already worrying about what you are changing in memory, so using that information for new purposes isn't a problem.

I suspect that mobile systems aren't doing all the same stuff behind the scenes. As a result, they don't have the same level of information that a desktop would have. In consequence, the overhead involved in implementing a general collection is higher and less likely to be worth it.


答:
"Why is CS taught focusing on the memorization ... as opposed to teaching useful skills" - I think you are discounting memorization a bit too much.  Just as you should practice writing code, interpreting documentation, using debugger, you should also practice memorization.

You may be surprised how much more efficient you can become if you don't have to go to API reference as often or look up as many debugger commands.

One of the best things I learned in highschool was by observing a friend who never took any notes in class. His argument was that he could remember what's important. I started doing the same thing and do think that it improved my memorization skills which I find very useful on daily basis even with all those API references handily available.

Title: Why is CS taught to be memorized?

Body:
I have been taking Advanced Placement Computer Science for this past year in high school. It seems as though we are taught simply to memorize code and functions and not how to be resourceful and efficient in using documentation and the like.

Practically, I imagine many (if not all) programming jobs would allow you to flip through documentation, review past code and the code of others, essentially doing what my teacher would consider "cheating."

While I do agree core concepts are essential to memorize (in any subject matter), it seems superfluous and impractical to me to give a pen-and-paper exam for a CS class, especially when practically you would have a compiler, debugger, reference manuals, and the entire internet to refer to in any real-world work situation.

Why is CS taught focusing on the memorization of code and functions as opposed to teaching useful skills including how to use and interpret documentation, sample code, the debugger and such?


问:
Implementing Scheduling Within an Application
I'm building an app and the end user will be using an Admin screen to schedule content on the front page. They will be choosing two dates, a start date and an end date.

Obviously I don't want to cycle through the entire collection to see if todays date is between any of the start or end dates every time the front page loads.

Also, don't want the user to be able to schedule two things that overlap each other. There should be a better way than checking for conflicts with each record before saving.

Using Node/Socketio/Express/Mongoose

I could index the collection in Mongo then sort accordingly to test for today's date and make sure there aren't conflicting schedules. Also, I could have a flag that is set once the day changes that signifies current content. I thought there might be a better way.

Does anyone have any thoughts?

答: It sounds like you can solve this problem with caching. In other words, go ahead and cycle through the whole collection, but only do it when the cache is invalid. Obviously it would depend on the details of your requirements, but something to look at if you can get away with it.</p>


问:
What should a tester (Quality Assurance) person do on a scrum team?
Coming from a scrum environment with no integrated testing support and an independent minded QA staff, how is a tester (QA person) best integrated with a scrum team? What should they do?

For reference some test functions are:

Unit Testing

Integration Testing

Functional Testing

Performance Testing

Acceptance Testing

答:
If they're in the code--have them do standard code-reviews before a task is completed.  Their review can encompass a review of the functionality as well as a code-guideline review (if they have enough experience as a developer or in code to get by).

Basically, when someone reports a "done" then it becomes a QA todo.  It's actually a very good idea to integrate this quick-QA approach, provided they can keep up--it's always best to catch issues sooner rather than later, so even if it's not comprehensive it can have the effect of accelerating the formal/full QA cycle.

ContentLicense: CC BY-SA 2.5


答:
Obviously I don't want to cycle through the entire collection

It's not obvious to me.  How big is this collection?

Anyway, why would you have to cycle through the entire collection?  Put them in a list ordered by expiration time.  Since time moves forward, you can discard everything that has expired.  So you only have to check if the first element is current.  When it expires, discard it and use the next one.

Title: Implementing Scheduling Within an Application

Body:
I'm building an app and the end user will be using an Admin screen to schedule content on the front page. They will be choosing two dates, a start date and an end date.

Obviously I don't want to cycle through the entire collection to see if todays date is between any of the start or end dates every time the front page loads.

Also, don't want the user to be able to schedule two things that overlap each other. There should be a better way than checking for conflicts with each record before saving.

Using Node/Socketio/Express/Mongoose

I could index the collection in Mongo then sort accordingly to test for today's date and make sure there aren't conflicting schedules. Also, I could have a flag that is set once the day changes that signifies current content. I thought there might be a better way.

Does anyone have any thoughts?


问:
Is it significantly costlier to fix a bug at the end of the project?
In a blog post by Andrew Hay, the following axiom was posited:

It costs significantly more to fix a bug at the end of the project that it does to fix the same bug earlier in the project.

However, this doesn't seem certain, especially after reading a blog post on Less Wrong, and the data I've seen to back it up is extremely old.

Is this still axiom accurate today?

答:
Ask Intel how much the Pentium Bug cost them, The Ariane 5 Rocket is another good example. These bugs were fixed at the end oft he project. I have worked on a system where an "attempt" at a software release has a budget of 6 figures. In these extreme cases, it's easy to see the cost. In other (most?) cases, the cost gets hidden by the noise, but it is still there.

There is no doubt that bugs cost money while they exist. One item, Defect reports, take time to compile, triage and close as dup, time is money- therefore an open bug creates ongoing cost. therefore, it must be that deferring bug fixes costs more than fixing them sooner.

If a bug escapes into the wild, the cost has a step wise jump...... Is "The end of the project" before or after the release of the software?


问:
Worst coding standard you've ever had to follow?
Have you ever had to work to coding standards that:

Greatly decreased your productivity?

Were originally included for good reasons but were kept long after the original concern became irrelevant?

Were in a list so long that it was impossible to remember them all?

Made you think the author was just trying to leave their mark rather than encouraging good coding practice?

You had no idea why they were included?

If so, what is your least favorite rule and why?

Some examples here

答:
```<code>#define AND  &&
#define OR   ||
#define EQ   ==
</code>```

<p>'nuff said.</p>

Body:
#define AND  &&
#define OR   ||
#define EQ   ==

'nuff said.


答:
This is basic accepted stuff from the systems engineering - and it applies to any form of technical development (be that building bridges, missiles, battleships or software).

Essentially, the cost of things goes up approximately an order of magnitude as you move through stages of development.

Something that costs $10 to fix at the point of conceiving the idea...

Will cost about  $100 if you need to go an update the specification....

Or cost about $1000 if something was implemented and you need to make changes at that point (and update the spec, and get the approvals and so on) but it had not gone through some kind of formal acceptance / sell off test

Or cost about $10000 if something was implemented and customer accepted, and you need to make changes at that point (and update the spec, and get the approvals, and re-test and re-run customer acceptance and qualification, and so on)

And the cost after deployment / roll out / putting in service is even more again.

Examples abound and its easy to understand them: a banking system with a serious scope change made after you have 25,000 employees using it will cost a packet in re-training time... before you even consider the scoping, coding, test, regression, etc etc etc.

OBVIOUSLY your mileage will vary: the costs and impacts of changing Fred Nurke's electronic sock warming e-commerce web site are somewhat different to the costs of changing software on an aircraft flight control computer.

Title: Is it significantly costlier to fix a bug at the end of the project?

Body:
In a blog post by Andrew Hay, the following axiom was posited:

It costs significantly more to fix a bug at the end of the project that it does to fix the same bug earlier in the project.

However, this doesn't seem certain, especially after reading a blog post on Less Wrong, and the data I've seen to back it up is extremely old.

Is this still axiom accurate today?


问:
How to let teammates know what changes I made to an object?
Suppose I have a PHP object, let's say: companyObj.

```<code>class companyObj
{
  private company_name;
  private company_address;

  public function print_contact()
  {
    //logic
  }
}
</code>```

This is the object I wrote, and shared with the teammates. Now I would like to make it more powerful, like this:

```<code>class companyObj
{
  private company_name;
  private company_address;
  private company_contact_person;

  public function print_contact()
  {
    //logic updated
  }
}
</code>```

Now, how can I notify my teammates that my object had more attributes that they can set?

Instead of sending e-mail to everyone in the development team, how do I make the team know what's going on, when I don't want my teammates to waste their time to look at what is changed at the source code level?

答: If you have a team you probably also have a design document. If not. get started on it. And use some UML tool to map your designs.</p>


问:
A decent git branching model for products that should accompany the version of another, third-party product (and pros and cons of one proposal)
Note: My question is focused in my specific problem (which involves Liferay) but I hope it can be useful for anyone who needs to maintain various versions of a same project on git.

I work on a company which writes a lot of plugins for Liferay Portal. These plugins (portlets, themes etc.) are usually reusable and, of course, should be updated for new versions of the portal.

However, it is usual to have to migrate, let us say, a portlet to a new version of Liferay and to maintain its previous version. Also, frequently we have to create very specific customizations for some clients, which does not make sense to be added to the "main version".

These requisites complicate our work but, fortunately, we can assume some simplifications. For example, the plugins are frequently updated by only one programmer at a time. It is very rare to have two or more features being added to a plugin at the same time.

Now, we are migrating to Gitorious. We are trying to conceive a branching model for such a scenario.

My model

What I proposed was:

Each plugin would have its own repository in Gitorious inside a project. For example, a portlet for displaying kittens would have a kittens-portlet repository inside the liferay-portlets project.

When creating a new plugin, create it at a branch named according to the Liferay version (for example, lf5.2).

Each time a update is made on the plugin, the update is approved and deployed in production, tag the plugin with a version (for example, lf5.2v1, lf5.2v2 etc.)*

Every time a plugin should be ported to a new version of Liferay, we branch the most recent version (creating, for example, the branch lf6.0).

Once in production, the head of the new branch will receive a tag such as lf6.0v1.

Every time we have to customize a plugin in a client-specific way, we create a branch with the name of the client (for example, we would create a branch lf5.2clientcorp for our client "ClientCorp Inc.")

This is an unusual model: it would have no master and a lot of not-merging branches. This is how I suppose a repository with such model would look like:

A friend found this system rather complex and error-prone. He suggested the excellent and popular Vincent Driessen model, which I found still harder to manage and discipline-demander. It is great (and tested!) of course but seems too complex to our situation.

My friend's model

Then he suggested another model: we would have a repository for each plugin in a Liferay version (so we would start creating a kittens-lf5.2-portlet and then a kittens-lf6.0-portlet), each one with a master branch and a develop branch. The master would be always ready for deployment. (Or it could be the other way around, master and stable, as suggested by Steve Losh).

This is very simple, but I did not like this system:

it could result in an awful lot of repositories in a project, making Gitorious hard to browse.

The name of the directory of the project is relevant. If someone clone the repository to a kittens-lf6.0-portlet dir and generate the WAR with ant (as usual), the WAR name will be kittens-lf6.0-portlet as well. Old versions of this portlet (named kittens-portlet for example) would be considered as different (and probably missing) portlets in a upgraded portal. A bit of care can avoid it but I would prefer to avoid it.

The different versions of the same plugin would be maintained apart. I break my heart :(

kittens-lf6.0-portlet is a ugly name for a repository, I think.

I suspect the two last points - which are the two more subjective ones, too - are the main reason for my unwillingness. Nonetheless, all four objections stand.

OTOH, my own proposal seems strange to myself and I wonder if there is hidden bugs on it. OT3rdH git is so powerful and flexible that I think I should feel no shame on exploring its possibilities.

So, I ask:

What would be the best model? My proposal? My friend's model? The now traditional Vincent Driessen system?

What other branching model would you suggest?

If you think my model is bad, why do you think so? I would love to learn what are the drawbacks and blind spots.

* Actually, I would prefer to tag the commit with a version such as v1 but apparently a tag in git is not scoped in the branch - that is, I could not have a 1 v1 tag in lf5.2 and another one in lf6.0 - so I have to name the branch. Is it correct BTW?

答:
What stumps me it the fact that each portlet has it's own repository (but your story might not be complete). Personally I would create a repository per project. Projects often have multiple portlets and are all build in the same run against the same version of Liferay.
Each project can be a duplicate of an existing project that build against a different version of Liferay but I would only split a product if the differences are too big. If a build works against Liferay 5.1 and 5.2 I would not split the project. I would use scripting or Maven (or both) to let everything work.
I would use a Wiki (or Trello) for management of each product and with what version of Liferay it can be build against.

By the way: I am a Java programmer, Maven specialist, Build specialist and have experience with Liferay and other portal servers (IBM WebSphere and Glassfish).

But this is just my €0.02.


答:
Don't let schooling interfere with your education.

-- Mark Twain

I'm a mexican and telling you this because in Mexico is not exactly a good place for education (in any level), at least in public education.

Well, at the middle of my career (CS) I feel exact the same way you're feeling, so I start learning by my own and I spend one year learning algorithms, linux, scripting, how my computer works, a bit of relational databases, html, css, etc (a little about all). And of course, I had to skip classes*, let my grades down* and graduate one year after*, all in order to learn.

After that year, I return to my "normal" routine, back to regular classes, homework, exams and projects. The classes were still boring, nothing new to learn, all was the same. So I decided to enter to programming contest sites like UVA judge online, code chef and project euler, then I watched some lectures at the MIT Open Course Ware and I was still learning by own, but in a different way.

The lesson: Don't let the things happen, make the things happen. If you're not happy with the way you're learning, change It!

*Not the wisest decisions that I have made.

Title: Why is CS taught to be memorized?


问:
Regulation of the software industry
Every few years someone proposes tighter regulation for the software industry.

This IEEE article has been getting some attention lately on the subject.

If software engineers who write programs for systems that expose the public to physical or financial risk knew they would be tested on their competence, the thinking goes, it would reduce the flaws and failures in code—and maybe save a few lives in the bargain.

I'm skeptical about the value and merit of this. To my mind it looks like a land grab by those that proposed it.

The quote that clinches that for me is:

The exam will test for basic knowledge, not mastery of subject matter

because the big failures (e.g. THERAC-25) seem to be complex, subtle issues that "basic knowledge" would never be sufficient to prevent.

Ignoring any local issues (such as existing protections of the title Engineer in some jurisdictions):

The aims are noble - avoid the quacks/charlatans1 and make that distinction more obvious to those that buy their software. Can tighter regulation of the software industry ever achieve it's original goal?

1 Exactly as regulation of the medical profession was intended to do.

答:
Regulation of the software industry is best done through regulation of the Quality Assurance processes.

This is already done - large software companies have multitudes of testers, QA managers, automated testing suites, code review processes, testing processes, on and on. There are companies whose entire purpose is performing software quality audits on other companies. The standards organisations have guidelines for QA and for QA Audits.

Internal to a company, a software engineer is responsible for the quality of their work. Their checks and balances, however, are in the company's quality processes.

Title: Regulation of the software industry


问:
Components under what licenses can I use in my paid app?
I'm working on an application and I need to use some existing components such as libraries and JavaScript frameworks that are covered by licenses. My application will be paid (not free) and closed-source.

Can I use components in my app that are under one of following licenses:

MIT

Apache

BSD

答:
From MIT :

It is a permissive license, meaning that it permits reuse within proprietary software provided all copies of the licensed software include a copy of the MIT License terms.

From Apache :

Like any free software license, the Apache License allows the user of the software the freedom to use the software for any purpose, to distribute it, to modify it, and to distribute modified versions of the software, under the terms of the license.

From BSD :

The BSD License allows proprietary use, and for the software released under the license to be incorporated into proprietary products. Works based on the material may be released under a proprietary license or as closed source software.

So, the answer is : yes, you can use libraries with all 3 licences, but if you modify them, then take a look into licence details.


答:
You could use a tool like doxygen within you code. Now create script that would generate the doxygen documentation and run it regularly, perhaps as part of your nightly build (you do a nightly build, right?).

I think you can assigned a custom attribute in doxygen to your addition to highlight it as being new.

If your teammates are any good, they would go through the new documentation.

Title: How to let teammates know what changes I made to an object?

Body:
Suppose I have a PHP object, let's say: companyObj.

```<code>class companyObj
{
  private company_name;
  private company_address;

  public function print_contact()
  {
    //logic
  }
}
</code>```

This is the object I wrote, and shared with the teammates. Now I would like to make it more powerful, like this:

```<code>class companyObj
{
  private company_name;
  private company_address;
  private company_contact_person;

  public function print_contact()
  {
    //logic updated
  }
}
</code>```

Now, how can I notify my teammates that my object had more attributes that they can set?

Instead of sending e-mail to everyone in the development team, how do I make the team know what's going on, when I don't want my teammates to waste their time to look at what is changed at the source code level?

ContentLicense: CC BY-SA 4.0


答:
It depends a lot on the concrete situation. Let's assume the new property you added is mandatory, i.e. it has to be set always. Then you must search through the code yourself and update it everywhere a companyObj is created, to ensure that it is constructed properly (including setting the new property). I assume PHP has constructors, in which case you only need to add a new constructor parameter and the compiler will automatically mark every constructor call without the extra parameter as a compilation error. This will also ensure that teammates learn about the new property as soon as they use a companyObj.

If the new property is optional, however, things are less clear. You may or may not have a suitable default value for it. In the latter case, I would still suggest you update all instance creations to set the new property whenever appropriate. This is to ensure that the code is kept in a consistent state at all times.

Communicating the change to your teammates is another, distant step here. Agile teams prefer face to face communication, and, IMHO for a good reason. Relying on documents is a very slow and ineffective means of spreading information around a team. A Wiki is somewhat better, but still, documenting every single class attribute is IMHO overkill. It is only going to become a huge burden on the team, and is quickly bound to become unreliable and useless anyway, as we are humans so we are bound to forget the update sometimes, moreover I bet that not many team members are going to regularly check the documentation (be it in whatever form) to get informed of the latest code changes.

The latter is also true to automatically generated documentation via e.g. Javadoc or Doxygen. Although they can be configured into an automatic build to keep the generated documentation up to date at all times, I have never seen a development team with members regularly browsing through the documentation to get informed about the latest code changes. And if you are using any source control system, the first place to notice the changes is when you update your local copy of the code anyway - then you can check for changes in familiar classes and see precisely what and how has changed (along with a brief explanation and/or reference to a task ID, if your team is accustomed to add meaningful checkin comments - which is going to be missing from automatically generated docs).

Communication is one prime reason why Extreme Programing teams do pair programming. If you make the changes together with a teammate, there are two of you right away who know about each change, and next time each of you are going to pair up with someone else, so useful information spreads quite quickly. It is not always applicable though, for various reasons. Barring that, you may simply talk to your neighbours about the change in an appropriate moment (e.g. during lunch, if you happen to lunch together), or send a mail around if it is a bigger, more important or more complicated change.

In the latter case, there may be a good reason to document it properly. IMHO design documents are best when they offer a coarse grained, high level overview of the system, while the implementation details are in the code (adhering to the DRY principle).


答:
I don't have access to hard data or facts, so I can only offer you anecdotal observations gleaned from my last 20 years in IT.

I believe there is a vast difference between the that way most developers create software today as compared to 20 years ago. With the Agile movement having gained so much momentum, particularly in the last 5-6 years, I've seen a real shift in attitudes in the workplace.  So much so that the quality of what we do just seems to grow in leaps and bounds every year, and with every project as we apply the lessons we've learned from project to project. Leaner processes combined with a focus on test-first development has grown from being very controversial to commonplace. So much so that to walk into many companies today, if you are not comfortable with Agile you'll be lucky if they don't show you the door.

So what impact has this had. First of all, I have noticed that problems do often get identified much earlier.  Often it is the case that if the problem doesn't look to be too great, it can sometimes be put on hold indefinitely. In a rare handful of cases, I have seen bugs that were thought to be trivial become serious problems when addressed later, as some fundamental issue becomes apparent that wasn't considered at the time. Sometimes this can lead to a drawn out fix cycle, and that can be costly to a degree, but that cost is often measured less in terms of resourcing, and more often in terms of the impact on the relationship between customer and developer.  Customers are growing used to this Agile way of thinking, which returns results to them much faster than it did in the old days, with highly iterative development sprints and fast turnaround between requests and implementation, so they have come to expect a great deal of us. And as far as the actual bugs are concerned, the time to get a bug fixed is more often greatly diminished as a result of having a solid suite of tests to support changes, and the ability to create new tests from which to provide insight and solutions to the problems reported.

So on the whole, it appears that the overall effort to fix bugs has been in most cases reduced if there is a robust suite of tests in place, and procedures to ensure that testing remains the focus of what the developer does, but the actual cost has in some ways shifted in part at least from the implementation, to other areas of the business, because in some ways, the focus has also shifted from pure supply and demand to relationship management.

Another thing that has become apparent, is that our gut instincts of a few years ago which suggested that being Agile would reduce our maintenance cycles has been proven to a degree both right and wrong. Right in the sense that solid testing has made it easier to debug and fix our code to a large degree, and to reduce overall the number of bugs released into production code, and wrong in the sense that we are now working harder to avoid needing to maintain legacy code, by constantly refactoring code and improving architecture such that it is becoming rarer that we need to develop new products completely from scratch.

So in the end, what does this mean with regards to the OP's question? Well, it means that the answer really isn't as cut-and-dry as we once might have thought it to be. 15 years ago, I would have probably answered the question as a Yes, but now I feel it's more realistic to say that it really is too difficult to measure empirically, because the nature of what we do to develop software has changed greatly from when we first started asking ourselves the OP's question back then. In some ways, the more we advance our techniques and skills as an industry, the further the question grows from a definitive yes, to a point where I suspect that in a short number of years we'll be saying that it doesn't matter when we fix bugs, because our tests and processes will be so much more robust, that the timing of the bug fixes will be less driven by efforts to save our budgets, and more by priorities to satisfy our customers needs, and the relative cost will become virtually meaningless contextually.

But as I say, this isn't hard data-supported evidence, just my observations of the past few years, and my gut telling me that there will be more ground-shaking wisdom to come that will improve the way that we do things.


答:
Now, how can I notify my teammates that my object had more attributes that they can set?

Well, you shouldn't inform your teammates about every little thing you make. Otherwise, you'd have to send lots of emails. If it is a big thing, then you can make a small meeting, and let them know what you did (If you do scrum, then no need to set a separate meeting).

If you use an IDE that supports auto completion, then your teammates should notice your change. I just hope you do comment your code.


问:
Anyone know of any parallelizing compilers following the approach of the Dragon Book?
In Compilers: Principles, Techniques, & Tools, Aho et al describe an approach for optimizing for parallelism (chapter 11 in the second edition). Is anyone aware of any existing compilers which follow that approach?

答: I don't have any first-hand experience with it, nor do I know whether the techniques used are in the Dragon Book to the letter, but the Sun Studio C and C++ compilers can do automatic parallellization of for loops.


问:
Does it make sense to avoid a framework when building a large webapp with PHP?
Being a PHP web application developer for several years now, I've had my share of MVCs and frameworks. At first I thought they were the best thing since sliced bread; everything seemed to be very easy to implement.

Now however, it seems that the more complex the application gets, the more hassle the framework introduces, so I have to develop workarounds to overcome them. Such workarounds are usually pretty daunting and complex since I have to delve down into the framework core code and make changes so that it behaves the way I want.

For example, in one of my projects where I use Slim(C)+Idiorm(M)+Twig(V) (which I believe is very flexible), I have to create a custom function just to display dynamic data in parent templates; without a framework I could have simply executed mysql_query() in the included file.

Okay, frameworks are cool if I'm creating a simple company profile website; I can just whip some code in one night and they're usually ready by the morning, and the amount of good coding practice and design patterns I've learned from them is very valuable.

But really, for a complex web application like an all-in-one web based school management system, frameworks usually get in the way of my business process like in the example above.

So my question is: is it okay to just go back to basics, and use standard PHP code and libaries for doing my next project where there might be a gazillion frameworks and libraries, provided I can sufficiently use good coding practices and follow sensible design patterns like MVC? My development team is pretty small: only 2 programmers and 1 designer. The other programmer agrees with my thoughts above.

答:
There are multiple sides to writing your own code vs. using a Framework:

The size, basic knowledge and experience of the team you are working with: If they never used a framework or have an idea of how to architect an application you are better with a well documented framework with a lot of examples and see that you speed them up.

The size of the application: You never know beforehand how it will be used. So you better be prepared for growing and changing. Can your framework, that you want to code in one night, grow with the needs of the management? Change field-types in the DB and it takes a minute or a day to implement, that is my point here.

The Preparation: If you use a framework you can start designing the application instead of coding the core of your application, use one where security and deployment are important parts, that is what takes so much time. Everytime.

I always argument with "the management" to use Symfony2 as it is a framework for webdevelopment. Management thinks it's to big, it will cost money and shy away programmers as the learning curve is steep.


问:
Querying key/value store
I don't know whether this question is reasonably answerable (and therefore will be closed), but I will take my chances: What are the possible problems (and solutions), one might encounter, when developing query mechanism for key/value store/database (like redis for example)? All the values will consist only of JSON documents and all data will be located only in RAM. Query mechanism should be able to search/query for data based on document field values, so I assume one of the problems might be performance based on number of docs in database (this could however be lowered by partitioning documents based on their type like posts, comments, ...).</p>

答:
I am not familiar with Redis, however, some other key/value store databases have the following problems:

Updates are not instantly visible immediately.

SQL joins are to be performed by application.

Some SQL features such as Distinct, Group By are to be performed by application.

No stored procedures, triggers, etc.

No FKs

(2) and (3) above are particulary important because to achieve this you have to move large amounts of data to the client as well as write the logic.

Title: Querying key/value store


答:
I once read an article that had two interesting points (unfortunately the references I had is long gone, so I'll have to just postulate here). The first point they made was that around 50% of all errors were introduced in the requirements specification and that around 90% of all errors where found during UAT or System tests.

The second point they had was that for each phase in the V-model the cost was increased 10-fold. Whether or not the factor is correct I find kind of irrelevant but the most costly errors are when your design is based on an incorrect assumption. This leads to a massive amount of rewritting.
All the code that works because of that assumption but fails when the correct assumption is applied will have to be rewritten.

I've experienced the entire domain model having to be rewritten because of one incorrect assumption in the requirements specifications. If such a bug is caught early, Ie when reviewing the requirements specifications the cost is very low. In this particular case it would have taken ten lines of text. In the case where it's found during UAT (as this was) the cost is sumstantial (in the given example the project cost was increased by 50%)


答:
It's the same as most modern attempts as solving "software related problems". Those that try to legislate have little knowledge of the root course of the problem. If following the prescribed process (and the intent of course) when developing safety critical software, be that for aircrafts, nuclear plants of medical equipment a single bug will never be enough to cause a failure. An entire algorithm can be implemented incorrectly with out any one being harmed.

FDA and FTA both requires a risk analysis and based on that a mitigation strategy. The later is usually a swiss cheese strategy where one accept that any mitigation is flawed, so multiple mitigations for the same risk is applied (one mitigation might also be applied to several risks) each mitigation is like a slice of swiss cheese you can look through one, maybe two slices put together but put enough slices together and that's no longer possible. Even when the mitigations are implemented perfectly that does not result in a 100% safe piece of equipment. If the risk analysis is incorrect there will be risks no one thought of (Y2K).

You can test the engineers all you want you could even test on subject matter and require an extremely high level but it would matter much. Most safety critical errors are integration errors. They are not errors in one mans code but arise due to misalignments between software and hardware of two software systems or because an alpha particle knocked the program counter out of it's proper location.

I've been on several safety critical systems with highly experienced and capable developers, whom would pass any sensible test in their field. I've never been on a project where we did not have a safety critical error. (I've fortunately never been on one where the system ever harmed anyone)

Title: Regulation of the software industry

Body:
Every few years someone proposes tighter regulation for the software industry.

This IEEE article has been getting some attention lately on the subject.

If software engineers who write programs for systems that expose the public to physical or financial risk knew they would be tested on their competence, the thinking goes, it would reduce the flaws and failures in code—and maybe save a few lives in the bargain.

I'm skeptical about the value and merit of this. To my mind it looks like a land grab by those that proposed it.

The quote that clinches that for me is:

The exam will test for basic knowledge, not mastery of subject matter

because the big failures (e.g. THERAC-25) seem to be complex, subtle issues that "basic knowledge" would never be sufficient to prevent.

Ignoring any local issues (such as existing protections of the title Engineer in some jurisdictions):

The aims are noble - avoid the quacks/charlatans1 and make that distinction more obvious to those that buy their software. Can tighter regulation of the software industry ever achieve it's original goal?

1 Exactly as regulation of the medical profession was intended to do.


问:
Best-practice to manage concurrency into a basket in a e-commerce website
What is the best practice to manage the case where two customers add in the same time a product whose the stock was only 1 ?

Must there be a check in the code of the basket to avoid one of these 2 customers to add the same product ?

Or does this check must be carried out in the payment phase in doing for instance a second query to confirm the concerned product is still present in stock (means not bought yet by the concurrent customer) ?

答: As always, it depends on what your requirements are. If you are Amazon and sell 100,000,000 items per day, the overhead for preemptive checking and locking is probably prohibitive, and the problem of one customer per day not getting their item after all is negligible. It you deal in rare antique religious icons that are unique and expensive, the opposite probably applies. You yourself must know where your business case is located on that spectrum.</p>


答:
There is no perfect answer for this question and all depends on details.

As a first 'defense line' I would try to avoid such situations at all, by simply not selling out articles that low if any possible. If this is possible may depend on the situation and the kind of articles you want to sell. In the company I work, articles are mostly removed from the website before we run out of stock. But we are selling whole sale and the few remaining articles are sold by our sales people as special offers. This may not be an option for small shops, especially when selling high priced articles.

The solution to do the double check when adding something to the basket isn't very good. People put a lot in baskets without ever actually placing an order. So this may block this article for a certain period of time.

So in my humble opinion for small jobs the best way is to do a final check right before the payment, when the order is actually placed. In worst case you have to tell you customer that you where running out of stock right now (what for small shops will not happen that often).

Title: Best-practice to manage concurrency into a basket in a e-commerce website

Body:
What is the best practice to manage the case where two customers add in the same time a product whose the stock was only 1 ?

Must there be a check in the code of the basket to avoid one of these 2 customers to add the same product ?

Or does this check must be carried out in the payment phase in doing for instance a second query to confirm the concerned product is still present in stock (means not bought yet by the concurrent customer) ?


答: Have you considered simply talking to them? Schedule a short meeting: "hey, I made some changes to object X, I want to show you what changed and why". Or, just talk to each person individually if a meeting seems too formal or disruptive.


问:
How to prioritize tasks when you have multiple programming projects running in parallel?
Say you have 5 customers, you develop 2 or 3 different projects for each. Each project has Xi tasks.

Each project takes from 2 to 10 man weeks.

Given that there are few resources, it is desired to minimize the management overhead.

Two questions in this scenario:

What tools would you use to prioritize the tasks and track their completion, while tending to minimize the overhead?

What criteria would you take into consideration to determine which task to assign to the next available resource given that the primary objective is to increase throughput (more projects finished per time unit, this objective conflicts with starting one project and finishing it and then moving on to the next)?

Ideas, management techniques, algorithms are welcome

答:
Sounds like the company has taken on more work than it can handle and it's trying to dig itself out of a hole.

Give your salespeople a vacation, pick the projects that have the higest profit ratios, finish them and postpone the rest until they can be worked on.

Or get more people to work on the projects that you can't handle (it's not a mythical man-month scenario if there is no-one to work on them).


答:
The best practice, for the user, is obviously to make sure the second add fails. But this is going to slow your whole site down for the sake of the 0.1% case.

The most technically efficient solution, and the one to maximise sales, is to allow it to succeed and then try to fulfil both orders later -- just cause you don't have stock right now, doesn't mean you can't find it in an emergency. If you can't then someone has to contact the user who lucked out and apologise. But that is exactly what led to uproar before Christmas this year (this is not the only article that appeared, so apologies to Best Buy but it was the first I found).

Your job is to present all the options to the business, with pros and cons, and let them decide based on your advice. If they can afford an occasional small hit to reputation to maximise sales then fair enough; if they can't and traffic is so low that you can check for double-updates quickly then that's also their call.


答:
In my experience, memorization comes with simple practice and there's absolutely no need to teach it at all. More importantly, this approach means only memorizing what you actually need to remember in whatever you're doing, not a bunch of random junk that your teacher hopes you might need and invariably you won't. The time spent memorizing the implementation of some algorithm could be much better devoted to some other cause.

After all, why would you ever need to practice writing an algorithm? Once you write it once, you can re-use it for all time- even on the exceedingly remote chance that someone else hasn't already written a freely available implementation for the language of your choice and that your environment doesn't already provide such an algorithm for your use, which is trivially not true for the vast majority of simple algorithms like sorting and such. Practicing something where it's highly unlikely that you'll ever have to do it in the first place and even if you do you'll only ever have to do it once? Not a valuable use of time.

The important thing to know about Heapsort is not how to implement it at all. It's the operating complexity in best and worst cases, and similar things. But, surprise, there's a handy-dandy table on Wikipedia that will instantly give you this information. So again, there's no value in having that knowledge. It's instantly available for you whenever you want it from now until the end of time at effectively no cost. So why would you want to memorize it? It's pointless.

In my experience, there is absolutely no reason to require a student to memorize anything. If you're asking a question which can be answered from a reference source, then you're asking a question where being able to answer it has no value.

Title: Why is CS taught to be memorized?


答:
I think best practice is to choose which of below options is more appropriate for particular business case:

Optimistic Offline Lock

...solves this problem (problem of session conflict) by validating that the changes about to be committed by one session don't conflict with the changes of another session. A successful pre-commit validation is, in a sense, obtaining a lock indicating it's okay to go ahead with the changes to the record data. So long as the validation and the updates occur within a single system transaction the business transaction will display consistency...

Pessimistic Offline Lock

  ...prevents conflicts by avoiding them altogether. It forces a business transaction to acquire a lock on a piece of data before it starts to use it, so that, most of the time, once you begin a business transaction you can be pretty sure you'll complete it without being bounced by concurrency control...

  "Whereas Pessimistic Offline Lock assumes that the chance of session conflict is high and therefore limits the system's concurrency, Optimistic Offline Lock assumes that the chance of conflict is low. The expectation that session conflict isn't likely allows multiple users to work with the same data at the same time."


问:
Factory design pattern - getting the types from a table
I've implemented a generic factory as described here

I need to register elements to the factory hard-code like this:

```<code>Factory.Register(1, typeof(MyClass));
</code>```

this factory will have to be correlated with a simple domain data type table [id,Display], in this case id 1 is related to MyClass.

I was thinking to add a column to that table with the qualified type, so I can simply retrieve the id to types. table will be [id,Display, typeName]

and I will use the factory like this:

```<code>Factory.Register(id, Type.GetType(typeName));
</code>```

I tried it and it's working ok.

is this a good design?

are there any security flaws?

is there a better way to do things?

答:
For a Factory design pattern it is fundamental that the knowledge of the mapping between an id and the corresponding class is only handled by the Factory. Instead in the example given it seems that the caller is aware of the mapping. I would encapsulate this knowledge within the Factory pattern, hard-coded.

If you don't want this knowledge to be hard-coded, i.e. you want to give the mapping after having implemented the Factory class, you can provide the mapping as a configuration file and let the Factory class use computational reflection to handle instantiation of the class whose name is given as a string into the file.


问:
Where can I find good example of techniques to compact data in-memory?
I'm writing a Java framework to manipulate a large amount of data in-memory, where many "cells" that are near each other will have the same value.

I'm looking for algorithms and/or techniques specially designed to eliminate those duplication while maintaining fast in-memory read access speed. That is, techniques that keeps an O(1) read-access speed.

My data is store in immutable objects, to allow fast multi-threading. The data itself can be anything, from 4 bits-per-cell to doubles to arrays of beans, etc.

答:
If there is a lot of repetition of values then some form of run length encoding might work for the compression side, the tricky part would be maintaining O(1) lookup (or if we relax that constraint slightly, fast lookup)

you could get log m lookup relatively easily (where m is the number of runs , not the number of values) by instead of storing the length with each value store the index

e.g. using the wikipedia example of

```<code>WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW
</code>```

instead of storing the lengths with each value for a run (added parens for clarity)

```<code>(12 W)(1 B)(12 W)(3 B)(24 W)(1 B)(14 W)
</code>```

we could store the indexes at which we change value (pluss an ending value if necessary)

```<code>(0 W)(12 B)(13 W)(25 B)(28 W)(52 B)(53 W)(67 null)
</code>```

we can then use a binary search on the index to find the value for any index in log(m) which may be quick enough?

Body:
If there is a lot of repetition of values then some form of run length encoding might work for the compression side, the tricky part would be maintaining O(1) lookup (or if we relax that constraint slightly, fast lookup)

you could get log m lookup relatively easily (where m is the number of runs , not the number of values) by instead of storing the length with each value store the index

e.g. using the wikipedia example of

WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW

instead of storing the lengths with each value for a run (added parens for clarity)

(12 W)(1 B)(12 W)(3 B)(24 W)(1 B)(14 W)

we could store the indexes at which we change value (pluss an ending value if necessary)

(0 W)(12 B)(13 W)(25 B)(28 W)(52 B)(53 W)(67 null)

we can then use a binary search on the index to find the value for any index in log(m) which may be quick enough?


问:
Do ALL your variables need to be declared private?

Possible Duplicate:

  Why do we need private variables?

I know that it's best practice to stay safe, and that we should always prevent others from directly accessing a class' properties. I hear this all the time from university professors, and I also see this all the time in a lot of source code released on the App Hub. In fact, professors say that they will actually take marks off for every variable that gets declared public.

Now, this leaves me always declaring variables as private. No matter what. Even if each of these variables were to have both a getter and a setter.

But here's the problem: it's tedious work. I tend to quickly lose interest in a project every time I need to have a variable in a class that could have simply been declared public instead of private with a getter and a setter.

So my question is, do I really need to declare all my variables private? Or could I declare some variables public whenever they require both a getter and a setter?

答: The reason why you always have to implement getters and setters is because everybody tells you to (sane people call that a Dogma). In the 10 years I program Java, probably 99 percent of the properties I used are publicly available through getters and setters, so in practice they ARE public. We facilitate the exception, instead of the rule.</p>


问:
Methods to rewrite a program

Possible Duplicates:

  How to approach refactoring an existing web application?

  Starting a coherent architecture in a legacy application

We have a fidelity system running on the company I work for.

It is written in C# and Flex and my boss want to change it to HTML5 and PHP to serve more customers and he is worried about the fact that Adobe left Flash, the enormous amount of bugs and requests for changes and also complaints about slowness.

The system is really big and the database is a total mess.

I'm the one responsible for that project and I have no idea on how to begin rewriting the entire code and database. Where do I begin?

Is there any methodology to do that kind of work?

答:
First off, give serious consideration to the PHP bit - if you've got C# code and presumably therefor skills why throw it away? There are any number of ways to deliver good, modern, flexible, standards compliant websites using C#

Secondly, what you really need to do is establish control over what you've got - to whatever degree its desirable to rewrite the application (I can see replacing front end flash with HTML5 and Javascript) if you'd don't have the right tools and practices you're just going to end up with the same mess again.

So a read of this book might help: Brownfield Application Development in .NET - its not heavyweight and is full of good guidance.

You should be able to deal with many of the issues by systematically refactoring the code, but the database is a bit more of a challenge. You can do various clever things - e.g. if you change table structures you can include views that contain the old structure - but in the end its going to involve pain.

If your really are going to rewrite the app from the ground up then do just that. Ignore what's gone before in terms of code, establish your user stories (you can use the current application to "inform" your stories and the order in which you plough through the backlog), work out your idealised schema and march forward from there...

Can't comment on which approach will get you the desired end result first - but a refactoring approach as per the book will get you visible results (particularly in terms of delivery to your users) a lot sooner.

Title: Methods to rewrite a program


答:
Look into memoization. You may be able to store pointers to the data, or a partial prefix of it, instead of the data itself.

Of course if your data are small enough this may not be a win.

Title: Where can I find good example of techniques to compact data in-memory?

Body:
I'm writing a Java framework to manipulate a large amount of data in-memory, where many "cells" that are near each other will have the same value.

I'm looking for algorithms and/or techniques specially designed to eliminate those duplication while maintaining fast in-memory read access speed. That is, techniques that keeps an O(1) read-access speed.

My data is store in immutable objects, to allow fast multi-threading. The data itself can be anything, from 4 bits-per-cell to doubles to arrays of beans, etc.


答:
You've got C# & Flex. I assume you're using C# for the backend and Flex for your UI.

Have you considered just transitioning to ASP.Net?  Then you'd be able to save a ton of your code...can go to more of a MVC type thing with ASP.Net and avoid the headache of all that re-design and porting.

Title: Methods to rewrite a program

Body:
Possible Duplicates:

  How to approach refactoring an existing web application?

  Starting a coherent architecture in a legacy application

We have a fidelity system running on the company I work for.

It is written in C# and Flex and my boss want to change it to HTML5 and PHP to serve more customers and he is worried about the fact that Adobe left Flash, the enormous amount of bugs and requests for changes and also complaints about slowness.

The system is really big and the database is a total mess.

I'm the one responsible for that project and I have no idea on how to begin rewriting the entire code and database. Where do I begin?

Is there any methodology to do that kind of work?


答:
The point with getters/setters vs. public variables is separation of concerns. Internal variables are an implementation detail of a class and thus should not be seen from outside.

What should be visible from outside is the properties that are handled by the class, and these properties may not have a one-to-one matching with internal variables.

For instance a class may handle a 'temperature' property. An internal variable may be linked to this temperature but users should make no assumption of what represent the value stored in that variable: °C, °F, °K, or even, depending on the sensor, raw measure expressed in: mm, V...

Getters and setters should apply to properties, not internal variables, thus allowing calibration or conversion functions to be included.

That way, class internals may change without updating its interface and all other components depending on that class.

Title: Do ALL your variables need to be declared private?

Body:
Possible Duplicate:

  Why do we need private variables?

I know that it's best practice to stay safe, and that we should always prevent others from directly accessing a class' properties. I hear this all the time from university professors, and I also see this all the time in a lot of source code released on the App Hub. In fact, professors say that they will actually take marks off for every variable that gets declared public.

Now, this leaves me always declaring variables as private. No matter what. Even if each of these variables were to have both a getter and a setter.

But here's the problem: it's tedious work. I tend to quickly lose interest in a project every time I need to have a variable in a class that could have simply been declared public instead of private with a getter and a setter.

So my question is, do I really need to declare all my variables private? Or could I declare some variables public whenever they require both a getter and a setter?


答:
Exposing members whether as public fields or through simple getter and setters goes against the original ideas of OO.

If you are modelling values and not objects there might be reason to model them as values.

Puristically speaking objects are about behaviour any member variable is an implementation detail and no value is part of the behaviour. So if you wish to do puristic OO every time you want to create a setter or getter, you should ask your self questions about your design seeing that the need for getters and setters (when not talking about values as oppossed to objects) is a smell that you are not modelling what the system does (behaviour) but what it is (data). A paradigm that focuses on the separation of these concepts is DCI


问:
OCCI for non-web application
I am writing a non-web application (written in java) which will allocate cloud resources. I want to make it compatible with as many providers as possible. Is it wise to use OCCI interface? Will it be too complicated?</p>

答:
The reality is that there is no one standard to connect to cloud providers, whether that be at the PaaS, SaaS or IaaS levels. I'm assuming you're utilising IaaS aspects here (your 'allocating resources' wording)?

OCCI is certainly one standard you can implement to cut down the number of different providers you want to support.  However, the reality is that you'll also need to write custom code (hopefully RESTFul if you're lucky) or grab custom open source components to connect to some of the cloud providers.

Title: OCCI for non-web application


答:
This is a people problem, as well as a database problem, the database locking is the easy bit!

Given that a customer may never check out…

You have two basic options:

You reserve an item for the customer for a fix time say (20 minutes)
after they have added it to the basket – after they time they have to
recheck the stock level or start again.   This is often used to
ticket to events or airline seats.

Or you say something like “xxx normal despatched in 24 hours”, but
reserve the stock when they checkout, in this case you must allow
them to cancel the order after checkout if some items are in stock
but not others.  (Green, Yellow, Red stock levels can also work well,
or some website say “low stock” when they are down to 1 or 2)


问:
Is reusability roughly synonymous with good design?
Reusability is a feature of good software design.

Is reusability an acceptable gloss ("brief notation of the meaning") for good software design? Why?

答:
I think a better indicator of good design is adherance to fundamental ideas such as the single responsibility principle and maintaining cohesion of each component.  By using abstractions with a clean and concise interface and maintaining compliance with the Liskov Substitution Principal we encourage reuse while not trying to predict what will and will not be reused.

Sticking to these fundamental design principles makes code easier to test and easier to reuse.

Good design == good design, reusability is a by-product.


答:
As you put it yourself:

But here's the problem: it's tedious work.[emphasis mine] I tend to quickly loose
  interest in a project every time I need to have a variable in a class
  that could have simply been declared public instead of private with a
  getter and a setter.

You are getting around the tedious work by trying to argue it's necessity out of existence, rather than making it less tedious, which basically means working around the problem instead of solving it. To solve it:

Use the right tools and use them right

If creating plain accessors is too much work, then your current toolset needs improvement.

In fact, any time there is some tedious work, your toolset needs improvement.

For many languages, there's some sort of syntactic sugar available to create accessors or you can use preprocessors for that and most IDEs provide code snippets/code generators. In fact in any decent IDE it is a matter of one keystroke to convert a public field into a private one with accessors.

I could provide a rather lengthy explanation on why using public fields completely violates OOP. At the same time, OOP is not the ultimate truth and it is sometimes better to consciously choose an alternative, if you know what you're doing and the circumstances are right. So yes, there are cases where using plain public fields is ok.

This however is no such case, because you are not making this decision based on any sort of technical constraints, but only because your workflow needs optimization.


答:
After reading some answers my first point would be that in this context I do not believe should is the same as saying must which is not the same as saying have to, I think you are perhaps over emphasizing always.

should implies there this is a generalized consensus that this is a better or more appropriate approach

you should always declare your members private

must implies that this is the way it is done

you must always declare your members private

have to implies no other option

you have to always declare your members private

Indeed in all three examples (particularly given the circumstance from which this question derived) one would and IMO should (though neither must or have to) query any statement put to them, this is how you program the best computer of all. For example if someone was to say you should always do something despite the fact you know that this time doing so would be detrimental would you do it without questioning their rational?

I imagine in this case your tutor (quite probably for ease) has surmised to you, a better practice which indeed I (and perhaps many others) would agree with. The question I feel should never be why make a member private but in fact the inverse as to why make it public, taking as an example facebook, people clearly like to publicize information about themselves but, even then, maybe just my friends can see this, my family can see that, and you who I don't know can't see anything.

Bringing this back to OOP and in particular Java, one of the main reasons for getters and setters is IMO (and I may be wrong) a case of good semantic practice, you obj.getState() and obj.setState() as opposed to obj.state and obj.state = 'foo', in both cases I would argue the process of doing so is imperative. I'd like to think object orientation is not solely about breaking away from this paradigm but among others encapsulating data and function into a reusable component. If we didn't hide anything do we just end up with some namespace for storing data and methods?

Another key point I believe boils down to overriding, classes inheriting from a super class containing public variables is now stuck with a public variable which to me sounds as though this could lead to a decrease in re-usability. By using getters and setters you have provided a way for sub-classes to override access to your variables, maybe add that bit of validation you never bothered with.

As for it being tedious regarding writing getters and setters this is really null and void as I think most IDE's will do much of this for you (and as I have just found lombok which looks pretty cool and reminds me of @property etc in objective-c)

In short yes you should always use private members unless you have a good reason not to (DTO's would be, to some extent, a reasonable exception)


问:
How can I write HTML, CSS, and JavaScript to make back-end developers work easier?
When I get a design from a designer, I get it as a PSD (Photoshop) file. I always expect proper layer and folder names, basically a clean and managed PSD. From this desigbn I develop HTML, CSS and JavaScript and deliver it to the back-end developers. To make it easy for them to understand, I

write semantic code,

keep JavaScript and CSS in external files,

add useful comments in HTML, CSS and JS files,

use CSS sprites (though developers don't like it),

use HTML5 boiler plate,

use jQuery for JavaScript,

try to use new HTML5 tags and CSS3 whenever possible and

sent a Zip file containing the HTML, CSS, JS and images.

I expect that if small changes will need to be made to the layout, the developers can handle that.

I would like to hear from back-end developers and other CSS ninjas what more one could do in terms of organization of files and mark-up to make the integration with back-end systems easier (i.e. back-end technologies, PHP, .NET, Ruby etc.) Different client uses different systems.

答: It still won't let me just comment (so stupid) but as a personal note, I would mention, I work back to back with a PHP coder everyday (as well as assisting in his work) and the easiest tool we have found is to make use of Komodo's toolbox and listing "transfered" variables of each view/controller/model in the toolboxx, so that at anytime, if i'm looking at designing a page around a set of data sent to that page, I can look in the toolbox and see exactly what data is being sent and what "type"" it is being sent in as, as well as vice versa on his end.  Just a tip.</p>


问:
Is it a must for every programmer to learn regular expressions?
I am new to programming, and at an interview I got a question on regular expressions; needless to say I couldn't answer. So I was wondering whether I should learn regular expression? Is it a must for every programmer of all fields? Or it is a must for programming for some particular fields?

Related questions:

Why are regular expressions so morbidly attractive?

When you should NOT use Regular Expressions?

答: Regular expressions are a tool. It happens to be a very useful tool, so many people choose to learn how to use it. However, there's no "requirement" for you to learn how to use this particular tool, any more than there is a "requirement" for you to learn anything else.</p>


答:
Regular expressions are a very terse way to express how to match patterns in text.

The requirement to parse and extract data from text or to validate that some text conforms to a specific pattern comes up very often in programming, so I would say that yes, it is important to learn about them and understand them.

They are a good tool to have in your toolbox and I would expect any experienced programmer to know how to use them.

One of the best resources to learn about regular expressions is Jeffery Friedl's book, Mastering Regular Expressions. It is rather advanced so you may want to actually read it when you have had some more experience.

You can start with the tutorial at regular-expressions.info.

Title: Is it a must for every programmer to learn regular expressions?

Body:
I am new to programming, and at an interview I got a question on regular expressions; needless to say I couldn't answer. So I was wondering whether I should learn regular expression? Is it a must for every programmer of all fields? Or it is a must for programming for some particular fields?

Related questions:

Why are regular expressions so morbidly attractive?

When you should NOT use Regular Expressions?


答:
regular expressions? Hmmm... sometimes is it usefull to know them but most time you allways use the same. I have used regex quite often but I woulnd't say that I am good with it. I don't like it at all and I think there are more important things to know than regex.

But in validation of formulars or data its very usefull. I think allmost every professional form is validated with regex. ASP.NET using it.

But at all: Try to do an expression when you need it and save it. You will use them hopefully all more than once. But dont waste your time with RegEx!


答:
I wouldn't call it tighter regulation, but instead barriers for entry.  In that regard I think there is merit.   For increased quality, that's very debatable.

Currently any John/Jane Doe can write a program.  There is no barrier for entry.  Pick up a few books on scripting and web technology and start hacking away, or worse just start Googling for how to "do" it.

When we as a collective whole decide maybe its time to increase the barriers for entry, to hold the industry to a higher standard, to evolve from hacker/craftsman to engineer, that sort of regulation I am all in on.

There are too many unqualified individuals programming today.  Whether or not they work on critical systems, they are still producing code, still producing Big Balls of Mud.

In that regard, self regulation or more aptly creating barriers for entry is a good thing.  Because we are saying, hey you can't just come in off the street and call yourself a Software Engineer.  You actually have to demostrate a level of skill.

Demostrating skill is more than just taking a test or getting a "badge of honor".  A test is just a validation.  Real validation is School, internship, apprenticeship, mentoring under seniors, practicing, is all a part of it.

I can see what the IEEE is trying to achieve, but at this point it is a fruitless exercise.  The industry changes rapidly, too much demand for pushing product out the door, the "hacker" mindset, etc.  The regulation has to come from within if at all.

Title: Regulation of the software industry


答:
Regular expressions are such an incredibly convenient tool, available across so many languages that most developers will learn them sooner or later.

For an interviewer, they are a nice way to probe experience during an interview. If you are interviewing someone claiming years of experience who doesn't understand them, you need to dig further.


答:
I would not be surprised if, for example, a games programmer or a programmer at the LHC never learned regular expressions. I might even give a games programmer a pass on not knowing SQL.

But, if you are working in information systems of any sort, and if you do not know regular expressions, you are doing yourself a disservice.

On the flip side, I wouldn't expect your standard IS programmer to know the matrix mathematics that a games programmer would. There are distinct disciplines of programmer, however must of us fall under the "information systems" umbrella.


答:
to quote another answer :

Regular expressions are a very terse way to express how to match
  patterns in text.

So if this is an important part of your job there is probably a better way to design the system you are developing. Unless lots of text is domain specific to your area (eg bioinformatics).

I have worked on three different enterprise systems (at three different companies over ten years) and I've written them less than five times, and that includes copy and pasting a basic e-mail validator twice.


问:
What tools do you use to manage requests from users?
I'm drowning in user emails and I'd like to implement a better way to manage all these requests I get and put them in a queue where those people on a team, as well as users, have access to them and can make common notes. I'm thinking about some sort of task management tool that would allow multiple tasks to be created under a project where emails, comments, ideas, etc. could be dropped/entered and easily accessible.

I need something that all parties can be involved in - users, managers, team leaders, developers. I'm looking for a tool that can allow:

Users to just drag/drop an email to submit a request for maintenance or enhancement.

Developers to just see their queue and the weighted priority of each task/project.

A team of developers to see what everyone is working on in real-time.

Management to keep a a log of time spent on each task.

I I am starting to look in more of a Agile/Scrum direction for solving this problem. I found list of scrum agile sofware project management open source tools. Since I am limited on time, has anyone used these? Which one should I test to see if it will meet my needs? TeamPulse is a good direction, but think it is a little too bloated. I need something simple for all parties.

答:
FogBugz

an integrated web-based project management system featuring bug/issue tracking, discussion forums, wikis, customer relationship management, and evidence based scheduling developed by Fog Creek Software.

The feature tracker allows users to manage, filter, sort and navigate a tree-structure of tasks, that contain information, tags and attached files related to a particular issue. Discussion forums and wikis may be created around any topic and posts/pages may be added into the same. Users may integrate their email accounts into the system to send/receive email and create issues regarding the same.

Prediction of future tasks and completion estimation of future milestones are based upon past records of user performance. Users must manually input an estimated duration for every task, and state the task they are currently working on which builds a daily work log (timesheet) that may be reviewed later...

Honestly one of the best systems I've used. Plus you can have email addresses per-client which will automatically create a new task.


答:
Reusability is often an implicit design goal. If you can create a component, or an entire design, in such a way that it can be reused later, it seems obvious that you should do that.  What's not always obvious is that it can take a lot of time and effort (and money) to make something reusable, and the benefit of reusability must therefore be weighed against its cost.

A reusable design that costs twice as much and/or takes twice as long to build than what the customer needs is not a good design from the customer's perspective, particularly if the customer doesn't need reusability.

There are a number of similar attributes that are often considered to be implicit design goals because they seem obviously good:

minimizing cost

minimizing development time

minimizing complexity

maximizing reliability

These things are all objectively good, but may not always be important to a particular client at a particular time, so it's important to fully understand what your customer needs (even if that customer is just your boss). There are a number of aphorisms that are meant to remind us of this fact (e.g. "Done is better than perfect" and "Good, cheap, fast: pick any two"), but it's still easy to fall into the trap of trying to make software that's great in every respect when in fact great in every respect isn't always needed.

To get to the title question, then: No, reusability is not synonymous with good design. Reusability may be a useful component of a particular good design, but only when it's required.

Title: Is reusability roughly synonymous with good design?

Body:
Reusability is a feature of good software design.

Is reusability an acceptable gloss ("brief notation of the meaning") for good software design? Why?


问:
Why is SQL known as a relation-based / functional language?
We're learning that most languages are classified as either of the two, "relation based" or "high level". I've never used SQL before, but from reading its syntax it seems more like the imperative/high-level syntax than functional/relation-based (Lisp, Haskell)??

Or it could just be that my interpretation of my professor's lecture notes is wrong... but it definitely lists SQL as one of the relation-based languages (as opposed to high level), and it equates relation-based with functional... or perhaps it's that I don't understand why the fact that SQL deals with relational databases makes a functional language the way it should be implemented? (and why 'relation-based' equates with 'functional' when categorizing programming languages?)

Thanks :)

答:
SQL is a relational, set-based language that has had procedural functionality tacked on.

I don't know if I would consider SQL functional, however it does have some aspects of functional languages. Modern variants of SQL (with the procedural bits) are definitely not functional.


问:
How should I plan and start a project?
Every time I start a project, I decide at crucial moments to completely change the core classes and get caught up in obscure errors. I try planning in advanced and usually start off on a good foot but then I go to it another day and decide I would like to do it 'another way'.

Is there a standard, of sorts, when starting a project such as mapping out classes and starting with unit tests? What is a good convention when planning and starting a medium project.

The last project and started was a projectile motion simulator - I know, predictable.

答: In my experience, this problem goes away when you have some more experience- you get a feel for what works and what doesn't. In addition, good encapsulation can lower the costs of changing design. The more tightly encapsulated your modules are, the cheaper it is to change later. Consider it an excellent motivation for keeping your classes separate.</p>

Title: How should I plan and start a project?


答:
In my experience, the system design often takes as long or longer than the actual coding.   When you say "planning in advance" what do you actually plan?  Maybe go old school and use one of the tried and tested design methodologies. Or go old school and write the pseudo code before writing actual code.

I think you have to ask yourself why are you changing things at crucial moments rather than sticking with the original plan.  Was the original plan flawed?    Or did you have an insightful moment that showed a better way to do things.  Was it actually better or just different?

Title: How should I plan and start a project?

Body:
Every time I start a project, I decide at crucial moments to completely change the core classes and get caught up in obscure errors. I try planning in advanced and usually start off on a good foot but then I go to it another day and decide I would like to do it 'another way'.

Is there a standard, of sorts, when starting a project such as mapping out classes and starting with unit tests? What is a good convention when planning and starting a medium project.

The last project and started was a projectile motion simulator - I know, predictable.


答: SQL is not really as much functional language as it is declarative. Functional languages, in general, emphasize declarative style over imperative to minimize side effects. This could lead some people to refer to SQL as functional, but it's not accurate. It's declarative with procedural elements.</p>

Title: Why is SQL known as a relation-based / functional language?

Body:
We're learning that most languages are classified as either of the two, "relation based" or "high level". I've never used SQL before, but from reading its syntax it seems more like the imperative/high-level syntax than functional/relation-based (Lisp, Haskell)??

Or it could just be that my interpretation of my professor's lecture notes is wrong... but it definitely lists SQL as one of the relation-based languages (as opposed to high level), and it equates relation-based with functional... or perhaps it's that I don't understand why the fact that SQL deals with relational databases makes a functional language the way it should be implemented? (and why 'relation-based' equates with 'functional' when categorizing programming languages?)

Thanks :)


问:
Do you think that exposure to BASIC can mutilate your mind?

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration

-- Edsger W. Dijkstra

I have deep respect to Dijkstra but I don't agree with everything he said/wrote. I disagree specially with this quote on linked paper wrote 35 years ago about the Dartmouth BASIC implementation.

Many of my coworkers or friends programmers started with BASIC, questions below have answers that indicate many programmers had their first experience on programming at BASIC. AFAIK many good programmers started at BASIC programming.

I'm not talking about Visual Basic or other "modern" dialects of BASIC running on machines full of resources. I'm talking about old times BASIC running on "toy" computer, that the programmer had to worry about saving small numbers that need not be calculated as a string to save a measly byte because the computer had only a few hundreds of them, or have to use computed goto for lack of a more powerful feature, and many other things which require the programmer to think much before doing something and forcing the programmer to be creative.

If you had experience with old time BASIC on a machine with limited resources (have in mind that a simple micro-controller today has much more resources than a computer in 1975, do you think that BASIC help your mind to find better solutions, to think like an engineer or BASIC drag you to dark side of programming and mutilated you mentally?

Is good to learn a programming language running on a computer full of resources where the novice programmer can do all wrong and the program runs without big problems? Or is it better to learn where the programmer can't go wrong?

What can you say about the BASIC have helped you to be a better/worse programmer?

Would you teach old BASIC running on a 2KB (virtual) machine to a coming programmer?

Sure, only exposure to BASIC is bad. Maybe you share my opinion that modern BASIC doesn't help too much because modern BASIC, as long other programming languages, gives facilities which allow the programmer doesn't think deeper.

Additional information: Why BASIC?

答: I am currently using BASIC to teach my son to write his own simple games. I never used it, I started my carrier with PowerBuilder and PowerScript and jumped over to C/C++ and then Delphi. Today, I use almost all languages available and I adapt very fast because the ground of all languages are the same, mathematical formulas with different signs, operators and symbols. That's also what I am teaching my son and because of that he can already read and explain C++ code. My son is 12 btw.</p>


问:
How safe is it to cache a user ticket in SESSION
I'm working on a client library to interface with my company's api, and we generate a user ticket when the user logs in using the api.

Obviously I don't want to send the user ticket to the client for resubmission on subsequent requests - is it (relatively) safe for me to cache this value in $_SESSION for later calls?

答: I don't see why it wouldn't be. The biggest consideration that I can see is you don't want your data being clobbered by the other code that is using the session. My common practice in this instance is to create a session key of __{$company_name} and store all of my bits there. This drastically reduces the chance that some other code will nuke my session variables.


答:
SQL is not imperative because the process of HOW queries and relationships are resolved are not defined by the programmer, but rather by the compiler/optimizer/interpreter.  SQL is a declarative language - In SQL, you declare relationships.  This builds up a data structure (that again is not physically defined with the language but by its implementation) using inserts, updates, and deletes.

Use of the relations is then done using queries (SELECT statements), which are functional in that they do not have side effects.

The whole thing is wrapped around the relational model.


答:
Is it possible that your notes are scrambled?

I've never heard of programming languages as being divided between "relation based" and "high level". Low level/High level is usually used to distinguish assembler and C from languages that provide direct support for more abstract structures. Relations are a pretty abstract structure, so I'd say anything that supports relations is high-level by definition.

Pure SQL is usually describe as being a declaritive language, with some procedural bits tacked on by the various vendors. The fact that SQL doesn't support functions as variables seems to me to immediately disqualify it from being a functional language.


答:
It depends on the area/platform you are working in

For desktop application, you can live a kool life without knowing anything about regular expressions. But mind you, Visual Studio has regular expression search but I wonder if anyone use it on regular basis. I am thinking not (you have to fix your regular expression first because you can make a search :) ).

As a web developer you will most likely have to learn Regular Expression. You can get away with it because you can easily find code snippet online that will suffice you need but learning will help.

There are areas like documentation, litigation, legal stuff where regular expression is an indispensable tool. You have to know it. If you don't you simply wont get the job.

So in short, if it is not part of a job description, don't even bother about it. If you like to learn it, learn it for fun.


答: It seems that your planning isn't helping.  That's no surprise because you don't have enough experience to make a feasible plan.  The solution is simple.  Stop planning so much.  Just accept that you are going to write and rewrite the code as you go.  That's ok, because code is free, except for your time. If you are writing a UI application, just start with a blank window and add a bit at a time until you are done.  When you have more experience, your projects will go faster.  Worrying because you are changing code is like a music student worrying about all the notes wasted in practice.</p>

Title: How should I plan and start a project?


答:
OCCI as an open standard is indeed a good option with regards to interoperability between different resource providers.

There are quite a few OCCI implementations under development. A list can be found here:

OCCI GitHub Account

Pollux may be a good starting point for OCCI clients written in Java.

As OCCI was published last year and is still in an early adoption face, support by resource providers is just beginning. OCCI 1.1 support in OpenNebula will be followed by support for OpenStack within the next months.

It's reasonably easy to adopt an OCCI server like the OpenNebula OCCI Implementation (written in Ruby) for other resource providers as well and work is already under way to support a wider range of resource providers.

Title: OCCI for non-web application

Body: I am writing a non-web application (written in java) which will allocate cloud resources. I want to make it compatible with as many providers as possible. Is it wise to use OCCI interface? Will it be too complicated?</p>


问:
Is programming or computer science in general, all about algorithms?
As a grad student, I find it more and more common for prestigious companies (like Google, Facebook, Microsoft,...) to put algorithm questions in their test and interviews. A few startups I applied to also asked about algorithms. I wonder if algorithms fluency is the most important thing for software developer in those companies?

If the answer being yes, what are the best method or resources for one to learn & practice about algorithms effectively? I can't seem to get interested in solving seemingly too complicated problems found in most textbook or websites. Though easily understand basic algorithms (like quicksort, bubblesort,...), I find it immensely difficult to remember and reuse them later.

Thanks.

P/S: If you ask me what I like, it's building good softwares to solve users' problems innovatively. I suppose that does not necessarily mean the software has to be very complicated.

答:
I personally see "standard" algorithms and datastructures as part of a programmer's vocabulary. And many of the practical problems you face as a programmer often have a solution which is (at least partially) expressible in this vocabulary.

Having this vocabulary as your disposal prevents you from having to come up with your "own" solutions (reinventing the wheel so to say), allowing you to work smarter and often faster.

"I can't seem to get interested in solving seemingly too complicated
  problems found in most textbook or websites"

"I find it immensely difficult to remember and reuse them later"

Force yourself to complete them. You will thank yourself later on. Even if you don't remember them in full detail (although with enough practice you certainly will), to be able to say "I remember solving something similar using algorithm X or datastructure Y" will help you tremendously. Even if it does require you to look up the details and refresh your memory.


答:
Although you cannot be a good programmer without knowing your algorithms, it is unfair to keep other aspects of the programming profession out of the picture. For example, strict discipline and good command of your native tongue are at least as significant to being a good programmer as your knowledge of algorithms is. One should also not underestimate the importance of understanding your basic tools, such as programming languages, source control systems, testing environments, et cetera.

However, when it comes to interviews, measuring your understanding of algorithms is a lot simpler than measuring your other abilities related to working as a programmer. That is why interviewers often concentrate on asking about algorithms, and pay close attention to the way you explain them during the interview. It is not because other things are less important, but because it is hard to assess these other things in the 30 minutes allocated for the interview.

Title: Is programming or computer science in general, all about algorithms?

Body:
As a grad student, I find it more and more common for prestigious companies (like Google, Facebook, Microsoft,...) to put algorithm questions in their test and interviews. A few startups I applied to also asked about algorithms. I wonder if algorithms fluency is the most important thing for software developer in those companies?

If the answer being yes, what are the best method or resources for one to learn & practice about algorithms effectively? I can't seem to get interested in solving seemingly too complicated problems found in most textbook or websites. Though easily understand basic algorithms (like quicksort, bubblesort,...), I find it immensely difficult to remember and reuse them later.

Thanks.

P/S: If you ask me what I like, it's building good softwares to solve users' problems innovatively. I suppose that does not necessarily mean the software has to be very complicated.


问:
Worst coding standard you've ever had to follow?
Have you ever had to work to coding standards that:

Greatly decreased your productivity?

Were originally included for good reasons but were kept long after the original concern became irrelevant?

Were in a list so long that it was impossible to remember them all?

Made you think the author was just trying to leave their mark rather than encouraging good coding practice?

You had no idea why they were included?

If so, what is your least favorite rule and why?

Some examples here

答:
Had a professor once who demanded we have at least one comment for each line of code.

```<code>//Set x to 3
var x = 3;

//if x is greater than 2
if(x>2){

    //Print x
    Print(x);
}
</code>```

It was pretty ridiculous.

Body:
Had a professor once who demanded we have at least one comment for each line of code.

//Set x to 3
var x = 3;

//if x is greater than 2
if(x>2){

    //Print x
    Print(x);
}

It was pretty ridiculous.