答:
The reason that it works is because in Java, only the GC can free memory which might contain GC references. That means that as long as you can read objects in a separate thread safely, you would only need to pause the program to observe the references on the stack.

I would suggest for mutation that they implement some form of copy-on-write to inform the GC about the change.

Title: What are the algorithms behind low pause GC?

Body:
Some languages, for exemple java, introduced a low pause GC.

Those GC can do most of the work without pausing the whole world. This is obviously a quite hard problem because it require to analyze the memory when thread are modifying it, resulting in data that can be used in the begining of the process and not anymore when it finishes, or data that appears to be garbages but because the reference was moved in memory and never appeared where the GC was looking.

So basically, what is the algorithm(s) behind that ?

Research papers or really technical article's link would be considered as valid answer, as this topic is really technical.


问:
Reuse Other Company's Content For Same Client
Here's the scenario: a client of mine (lets call them Company A) had a website built by someone else (let's call them Company B).  They then asked me (Company C) to configure a third party framework to look and feel exactly the same as what Company B built for them.

Would it be legitimate for me to use content (including images, CSS, and even HTML) from the site Company B built for Company A?

It's worth mentioning Company A's name is in the copyright notice in the footer of the site Company B made for Company A.

答:
IANAL, but it should be okay. Even if Company B really does hold the copyright (and say Company A modified/added the copyright notice without authorization) unless Company A actually stole it, they should at least have the right to use and modify it. If you hire someone to create a work, even if it's not technically a work for hire under copyright law, you certainly should have the ordinary use you hired them to get the benefit of. That would include the right to use and maintain the work. Web sites are always in flux, so modification should be considered part of ordinary use.

Most likely, the copyright notice is correct and your client holds the copyright. But you may want to find a subtle way to confirm with your client that there are no copyright issues that they're aware of. It's possible they hired you specifically because they know there's a problem and then 'forgot' to tell you about the problem.

ContentLicense: CC BY-SA 3.0


问:
What's the correct approach for passing data from several models into a service?
I have an AccountModel  and a page where the user can upload a file.  What I would like to have happen is when the user uploads the file. The PageController does something like the following.  this is a quick attempt just written in the question to illustrate my question.

```<code>public class PageController : Controller {
  private Service service;
      public ActionResult Upload(HttpPostedFileBase f){
         service.savefile(f,_AccountModel_whatever.currentlyloggedinuser.taxid)          }
}

public class Service
{
// abunch of validation and error checking to make sure the file is good to store
}
</code>```

Wouldn't this approach be in bad practice? Since I'm making my controller dependent on the existence of th AccountModel?  This will become a HUGE program over the next few years, and I really want to maximize the quality of the framework now.

答:
Couple of angles here. First, you could probably pass the account model into your service as a constructor dependency if it is in fact used everywhere there. Using any IoC framework you can pretty easily fob off these dependencies on the framework presuming it knows how to hydrate them.

Second, I would typically avoid rolling my own account model -- or at least writing code to it. In most cases, IPrincipal and IIdentity do the job for you and make your account model very flexible.


问:
How do I appropriately license my open-source project?
I have just recently completed my first open source project and while it is mostly a tool I still want to release it as open source considering it is C# so if someone wanted to they could decompile it. Also, I'm not looking to sell it.

I was researching licensing but the wording is a bit over my head. Mostly I'm just looking for a license that recognizes me as the creator and does not allow anyone else to put their name on it and "steal it." I'm most likely going to use either google code or sourcefourge to host the project and ideally I could have a donation button. I'm not sure if or which software licenses would prevent that sort of thing?

Also, I'm not really sure how licenses and copyrights "work." Do I just choose a license and paste it at the top of every source file? Should I include my name as well? Do I also put the licenses in the project's root directory? How does one obtain a copyright? It seems like most people just stick it on their stuff. Is there an actual process to obtaining one?

As for software licenses I've looked at so far, it seems like Apache 2.0 or MIT/BSD is what I'm looking for but I'm not exactly sure. Basically I just don't want anyone to steal my program and put their name on it. Other than that I'm fine with people looking at the source code, modifying it, or taking pieces from it, as long as they credit me.

答: If you don't know what license to use, go for a very restrictive one (GNU AGPL v. 3 is the most restrictive I know of). You can always rerelease under a less restrictive license later, but you can't go the other way.</p>

OwnerDisplayName: James


问:
Why does DirectX use a left-handed coordinate system?
I considered posting on Stack Overflow, but the question strikes me as being far too subjective since I can't think of a reasonable technical explanation for Microsoft's choice in this matter. But this question has bugged me for so long and the issue keeps coming up in one of my projects, and I have never actually seen an attempt at explaining this:

OpenGL uses a right-handed coordinate system, where the +Z part of the world coordinate system extends toward the viewer.

DirectX uses a left-handed system where the +Z part of the world coordinate extends into the screen, away from the viewer.

I never used the Glide API, so I don't know how it worked, but from what I can gather, it uses a left-handed system as well.

Is there a technical reason for this? And if not, is there some conceptual advantage to a particular handedness of a coordinate system? Why would one choose one over the other?

答:
Neither is ultimately better than the other - you're mapping 3D coordinates to a 2D surface, so the third dimension (which actually makes things 3D) can be chosen arbitrarily, pointing at the viewer or into the screen. You're going to put things through a 4x4 matrix anyway, so there is no technical reason to choose one over the other. Functionally, one could argue:

There is a fairly broad consensus in computing and other fields to have the X axis run from left to right (aviations apparently being a notable exception).

In mathematics, the Y axis points up. (Also, Up Is Where The Bubbles Go).

On computer displays, the Y axis points down (because that's how CRT screens work, and also because that's the order in which most human scripts arrange rows).

When you look at the "visible" side of a surface in the X/Y plane, the normal should point toward the viewer (such as when you look at satellite footage; the "height above sea level" points at the satellite, not at the center of the Earth). Since the normal for the X/Y plane is the Z axis vector, it follows that the Z axis should also point toward the viewer.

When you look at 3D images on a computer screen, points that are further away from the viewer should have a larger Z component. Hence, the Z axis should point into the screen.

Conclusion: There is some consensus for the X axis, but for the other two, both directions can be argued for, yielding two right-handed and two left-handed configurations, and they all make sense.


问:
Why is it unrealistic to expect all browsers to support the same standards?
Ideally, we would have different browsers supporting the same standards and same code producing the same result on all browsers.

That hasn't happened yet. What are the reasons why?

答:
No, it's not realistic, because the specs are confusing at times and everyone understands something differently than others. We're just humans after all. There can only be the one true standard when there's only one vendor with one version of a product.

Joel has written an excellent article on this subject, called Martian Headsets.

I think I'll quote him here, as this is the best explanation on why we won't ever see this as long as different vendors are involved:

Those documents are super confusing. The specs are full of statements
  like “If a sibling block box (that does not float and is not
  absolutely positioned) follows the run-in box, the run-in box becomes
  the first inline box of the block box. A run-in cannot run in to a
  block that already starts with a run-in or that itself is a run-in.”
  Whenever I read things like that, I wonder how anyone correctly
  conforms to the spec.

Also, there's competition and evolution on the market. Take autocomplete-boxes for example. Every major browser has them already, but there's no standard defined. The W3C is just too slow and by the time the standard arrives, there're already 5 different implementations with different behaviours out there in the wild, that you need to support, too, if you want to be competitive. Another prime example for this problem is the embedding of videos.

That said: As long as you need to support various different browsers and environments, be prepared to make adjustments.


问:
What is a "powerful" language?
I have often seen people fighting over that their favorite language is more "powerful" than others. When it comes to describing a programming language, I can understand what an object oriented language is or what a dynamic language is, but I still can't figure out what exactly a "powerful" language is. What are your thoughts?</p>

答:
This has been debated repeatedly at great length (e.g., on comp.lang.lisp, several times). I don't think anybody's ever come up with a "right" answer but a lot of people have come up with answers that strike me as obviously wrong.

In the answers I see here, let me pick on Mason Wheeler's answer. On one hand, the issues he covers are important -- but on the other, I can't quite imagine calling them at all related to "power." It's a bit like he's saying his Honda mini-van is more powerful than a top-fuel dragster because it's safer, quieter, has better handling, more passenger room and a much more comfortable ride. All of this is absolutely true, and it's all important. Those factors (among many others) make the minivan much more practical and reasonable for most people -- but they don't change the fact that the minivan's engine produces only about 250 HP whereas the dragster's produces somewhere around 8000 HP.

The problem, of course, is that with vehicles there's a clear-cut definition of what constitutes "power" and what doesn't. With programming languages, it seems to me that the discussion ends up being about equivalent to treating handling, comfort, speed, cargo capacity, and cruising range as all being parts of "power". The result tends to be threads that run on endlessly, generating a great deal more heat than light. Most of the questions that arise basically come down to the degree of importance you attach to completely unrelated and orthogonal features -- e.g., is the ability to program the MMU in assembly language more or less "powerful" than the ability to create higher level functions in Haskell? At least IMO, there's no meaningful way to compare the two, and no meaningful answer to which is "more powerful", or implies more power, or anything of that nature.

As such, as much as I hate to I have to say that in this case, the only meaningful answer is basically a relativistic one -- a powerful language is one that you find helps you to accomplish what you want to. Differences in peoples' goals render most "absolute" measurements of power meaningless at best.

ContentLicense: CC BY-SA 2.5

Title: What is a "powerful" language?


答:
Not going to happen in the form you describe.

However; if you code conservatively, it doesn't take much to write code that works reliably and predictably on all new browsers. We've already come a long way over the past decade - even IE currently implements a large subset of the W3C recommendations correctly, enough to actually make browser-agnostic websites.

Of course, if you want to do things that are not in the recommendations, or use features that are specced vaguely, or still implemented incorrectly (or not at all), then you're on your own.

Title: Why is it unrealistic to expect all browsers to support the same standards?

Body:
Ideally, we would have different browsers supporting the same standards and same code producing the same result on all browsers.

That hasn't happened yet. What are the reasons why?


问:
Password insanity! Recommended approaches to password management on multiple client systems?
A software development company I work with has a web based product they are successfully selling to clients. All of these clients have a support agreement with us that generally requires us to access their servers, databases and application data. As the number of clients grows, (and the number of different people supporting those clients grows), we are seeing a need to better manage in particular passwords, but more generally all the information one would need to fully support client systems ie. URLs, application login details, IP addresses, any client-specific weird stuff etc etc. This data is changing on an increasingly rapid basis, as systems get moved around to different machines, IP addresses. The worst problem is superuser passwords for the applications. These are constantly changing and occasionally we find ourselves in a situation where nobody seems to know who made the most recent change.

This is clearly an unsatisfactory situation. There are procedures in place which say that password changes etc need to be documented in a central secure place. But of course, people being humans, sometimes forget to document these things. The danger is that when people get so fed up of password chaos, that you can end up with a situation where everyone's password is "password123" as they can't be bothered any more.

Apart from enforcing the procedures, what other approaches could we take? One suggestion I heard was to have a "hidden" application superuser whose password is easily remembered/derived, which only support personnel would know about it. Personally I think that solution is a scary security hole, especially when you have multiple clients using your software.

So how would you handle this situation if you were supporting multiple clients? More strict procedure enforcement, or a technical approach to make life easier for everyone?

答:
I suggest that you use an application or document management tool that allows you to keep details about each customer in 1 or more documents. Then you create security rules to access each type of information or each customer.
Have a supervisor perform a check on a periodic basis to make sure that the information is documented and that documented information is correct (by testing it).
Have an admin. to manage this application.</p>


问:
Tracking hours on a project
Other than the following, are there any helpful (to programmers) reasons to track hours/time on a project down to the "accurate number of hours per week" level?

Reasons:

Beneficial to see how estimates vs. actuals came out (to improve estimation)

Management said so (for contractual or business reasons)

This is a bit tongue in cheek, but my personal preference has always been to track at an abstracted level.  For example: a person is either "full time" (defined as either 40hrs/week or a less intense 32hrs/week) or part time, or they spend a few hours here and there on the project.

It seems (as a manager) that chasing any kind of accurate number for actual hours is much like measuring the length of a coastline.  The more accurate you try to get, the more confounding it is.  That said, I'd appreciate any insights on benefits to programmers.

thanks!

答:
There are a number of metrics that can be derived if you know {something} and time.

Just knowing the task and time is useful from a business perspective for tracking cost of a project. At a business level, you would typically know how much you are paying your engineers, so knowing time allows you to compute the cost of people for the project. Typically, people are the most expensive component of a software project, so knowing this is a huge plus to benefit. It's not the only cost, but it's useful.

From a developer's standpoint, like you said, knowing time can be useful for estimation. The best estimates come from engineers, and to continue to provide good estimates, the engineers need to continually refine their estimates. Some engineers track their time well, while others need a little encouragement. Detailed time tracking is a good way to make (or at least try to make) engineers track their time and improve estimates. However, it's only useful if the engineer wants to continually improve - it's easy to neglect the data.

You can relate time spent on activities to how effective your process is. For example, let's say you are following an agile methodology. In a given iteration, you spend 6 man-hours in code reviews and had 35% of your defects make it through to system testing. In the next iteration, you spent 12 man-hours, and now 30% of your defects made it through to system testing. You spent twice as long on code reviews, yet only detected 5% more defects - this raises a red flag that the code review process needs to be reviewed. You can apply the same techniques to requirements engineering, design, testing, and so forth.

Project effort is also typically measured in time. It's fairly well known that SLOC/time is a poor measure of effort, but measuring some level of output/time (features, story points, earned value) is often used. Sometimes, just the total number of man-hours on the project is tracked. Either way, it lets you know how much time your people are putting into the project.

Title: Tracking hours on a project


答:
No, because W3C in many specifications give the responsibility of the implementation of somewhere to the UA implementers (browser implementers). Why I say that, because I usually write my articles directly from W3C specifications and see these cases. For example, W3C says that browsers should take user's consent about sharing their position (via Geolocation API), but it doesn't say how they should ask for it. This could result in different types of messages shown differently (popup, slide-down, etc.) in different browsers.

In general, we can say that:

As long as there are some pluralistic requirement implementation, consistency between browsers are hard to achieve.

We only can see consistent browsers when W3C imperatively tell browser implementers what to do.


答:
If you keep track of time to a relatively accurate level, staff may then watch what they are doing and may be encouraged to manage their own time as well. If I know that my boss will see that I am spending 5 hours in meetings that resulted in nothing significant, I will think of a quicker way to get things done.
I don't know your team, however, in my experience given a large number of people, you get to see all kinds.

My idea here is not to use this as a threatening tool, but to try to link deliverable with resource cost (time).

To accomplish near accurate time tracking, you need to specify the tasks on a consistent level. For example, Create Report as a task may involve many other sub-tasks, so the team needs to know what level of break down to use so that the data becomes meaningful. This is not trivial work for you!

Another benefit your organization would get is that if you keep good records, it could help you do estimations in the future.

The downside is that I guess that 99% of programmers hate time sheet and I know some people that were almost insulted when they were asked to prepare them!

Another draw back is that you will loose time in collecting time information and in analyzing this information.

Title: Tracking hours on a project

Body:
Other than the following, are there any helpful (to programmers) reasons to track hours/time on a project down to the "accurate number of hours per week" level?

Reasons:

Beneficial to see how estimates vs. actuals came out (to improve estimation)

Management said so (for contractual or business reasons)

This is a bit tongue in cheek, but my personal preference has always been to track at an abstracted level.  For example: a person is either "full time" (defined as either 40hrs/week or a less intense 32hrs/week) or part time, or they spend a few hours here and there on the project.

It seems (as a manager) that chasing any kind of accurate number for actual hours is much like measuring the length of a coastline.  The more accurate you try to get, the more confounding it is.  That said, I'd appreciate any insights on benefits to programmers.

thanks!


问:
Avoid ELSE when setting a variable?
Which of these styles do people prefer?

```<code>string mystring = "defaultvalue";
if (condition)
   mystring = "othervalue";
</code>```

VS

```<code>string mystring = null;
if (condtion)
   mystring = "othervalue";
else
   mystring = "defaultvalue";
</code>```

VS

```<code>mystring = condition? "othervalue" : "defaultvalue";
</code>```

答: The first style is 3 lines compared to 5 lines, and doesn't seem any less clear or readable; it's an easy preference from my point of view.</p>

Title: Avoid ELSE when setting a variable?


答:
I'd prefer the first style just because it's shorter and still readable. Depending on the language, I think choice 3 is even better:

```<code>string mystring = condition ? "othervalue" : "defaultvalue"
</code>```

or

```<code>string mystring = if (condition) "othervalue"
    else "defaultvalue"
</code>```

because it allows you to make mystring an immutable variable, which has some nice benefits.

Title: Avoid ELSE when setting a variable?

Body:
Which of these styles do people prefer?

```<code>string mystring = "defaultvalue";
if (condition)
   mystring = "othervalue";
</code>```

VS

```<code>string mystring = null;
if (condtion)
   mystring = "othervalue";
else
   mystring = "defaultvalue";
</code>```

VS

```<code>mystring = condition? "othervalue" : "defaultvalue";
</code>```

Body:
I'd prefer the first style just because it's shorter and still readable. Depending on the language, I think choice 3 is even better:

string mystring = condition ? "othervalue" : "defaultvalue"

or

string mystring = if (condition) "othervalue"
    else "defaultvalue"

because it allows you to make mystring an immutable variable, which has some nice benefits.


问:
Effectiveness of "what is your greatest strength/weakness" interview questions
As someone who is now finding himself on the other end of the interview table, I'm wondering how useful these questions are from an employer's perspective. Some of my coworkers think they're good because you can see "how they respond," but I'm not convinced it tells you anything useful, for several reasons:

It's not a very comfortable question and can lead people to twist their answers, even if not on purpose

People may not fully know their greatest strengths or weaknesses (i.e. judge them by their peers)

Explaining what a strength is isn't as good as showing it

I still don't know any more about the candidate afterwards

The rationale of my coworkers is that it can help weed out people that give ridiculous responses, like one guy that said his greatest strength was "his intellect" or people that try to turn the weakness question into a strength like "I work too hard." But I think there's more effective ways to determine such things. If you want to see if someone's smart, ask them technical questions. If you want to see if someone is productive, look at their work history. If you want to see how someone reacts under stress or change, ask them how they've dealt with it and ask for concrete examples.

What are people's thoughts on these questions, from the perspective of an interviewer? What do they really tell you about a candidate, and what are better alternatives? How do I convince my colleagues of this?

答:
I got this question a little while back (not for a programming job though) that I liked:

"What is the ideal/'golden standard' [profession]?", which was followed by "How do you compare to that?" and others.

It is very similar, but somewhat disassociates them describing themselves and describing the ideal (greatest weakness would be where there is the largest difference, strength: the greatest alignment).


答:
While people will have preferences, it doesn't really matter when compared to one particular style being followed consistently, all the time.

I would say, both of them need {} braces to prevent code being added incorrectly:

```<code>string mystring = "defaultvalue";
if (condition)
   mystring = "othervalue";
   string anotherVariable = "a value that someone could think is part of the conditional statement";
</code>```

Some people may view this as overkill, but it seems preferable to me take a simple step that prevents easy defects.

Title: Avoid ELSE when setting a variable?

Body:
While people will have preferences, it doesn't really matter when compared to one particular style being followed consistently, all the time.

I would say, both of them need {} braces to prevent code being added incorrectly:

string mystring = "defaultvalue";
if (condition)
   mystring = "othervalue";
   string anotherVariable = "a value that someone could think is part of the conditional statement";

Some people may view this as overkill, but it seems preferable to me take a simple step that prevents easy defects.


答:
As several others, I personally also prefer the 1st version. One reason not mentioned so far: it makes clear what the default value (and execution path) is.

But overall, the difference is not dramatic, I can live with the 2nd version too (and I do, as there are lots of them in our legacy app).

Title: Avoid ELSE when setting a variable?


答: I prefer the first style when there is a known default value that will occur unless something else is true.  If there's no default, then I will use the second style.</p>

Title: Avoid ELSE when setting a variable?


答:
mystring = condition? "othervalue" : "defaultvalue";

more intuitive for me:)

Title: Avoid ELSE when setting a variable?


问:
How can I judge whether a project is particularly complex or if I'm just slow in picking it up?
I'm making little progress on a major project.  The source is massive, many layers of objects, macaroni code, double-diamond graphs of multiple inheritance, half-baked features frozen when the original writer left, and no one knows why many pieces of it were designed the way they were.

I suppose any competent programmer would have some trouble figuring it all out well enough to fix bugs, finish the half-baked stuff and add new features.  However, I suspect I'm going slower than a typical programmer.

How do I judge whether the source is unusually bad and I'm just doing as well as anyone could, versus the source is typical for a project like this and I'm just slow-witted or underskilled?

答:
While learning something new, many students will think, “Damn, this is hard for me. I wonder if I am stupid.”
 Before going any farther, assure yourself that you are not stupid and that some things are hard. …

Mr Aaron Hillegass with the smart words.

 You're not stupid, you're not slow, and you're  not underskilled. I'm in the same boat, I've come into a new role and the existing code base is incredibly large and shows signs of being repeatedly overdeveloped, it's taken me weeks to get to a point where I feel like I'm even getting close to full-speed. Imagine the project to be like learning an entire new language, it doesn't happen overnight, but takes patience.


答: The first form is superior, as it offers a greater form of exception safety. If condition or some other code before the assignment throws, the string won't have the value that you assume it will.

Title: Avoid ELSE when setting a variable?


答:
I don't much like mystring = condition? "othervalue" : "defaultvalue"; but that is just personal preference and perhaps not being used to seeing it (my language is Delphi).

The others are a toss up and I often let it depend on the distance (number of lines) between the variable declaration and the condition. Short: the start with the default value. The more lines there are between the declaration and the condition, the more I will lean towards having a null or empty value in the declaration and a complete if-else statement for assigning the value.

Title: Avoid ELSE when setting a variable?


答:
The most important reason for estimating development hours precise to the level of hours, is

ECONOMY

It's because stakeholders want to know how much it would cost for them to develop a project, or to implement a feature, or to even doing a task. Our product owner always says:

How many hours would it cost? Tell me that, and I'll tell you whether to implement it or not.

Title: Tracking hours on a project


答:
It depends on how accurate you're talking about.

The best practice as far as I'm concerned is to measure down to approx 15-30 minutes what time you've been spending on what project. This time is not just coding or design time, but any bathroom breaks or office chit-chat that occurs. If you do this, it will tell you more than just estimates and billing. It allows you, the programmer, to track your own performance.

You should be asking yourself how long should this project take me? How long should this task take me? Then determine how long it actually took. Did you get done really quickly compared to what you would have estimated? What internal factors changed that seemed to have sped things up? What external factors? Did it take longer? Why? Knowing these things can better prepare you for future projects and maintenance.

However, I will warn about tracking down to fine-grained numbers (1-15 minutes). Its pointless. First of all, any task you work on (where a task is defined as one issue in your bug tracking system) that gets properly documented, recorded and coded will take at minimum 15 minutes, probably closer to 30. I say stick with 30, when you provide for context switches, documentation, bathroom breaks, etc... that should be as fine grained as you need to get.

Title: Tracking hours on a project


答:
I have the same problem with all the websites I visit personally, my bank details are pretty important to me!

so I use Keepass which is a little DB of passwords and associated information. Put all your passwords and IP details, etc in there. Its easy to use and very secure - you can then give out a single password to support staff (and/or a key file) that they use to open the db file.

Then put the db in a version control system so you have to check it out to modify it. This adds a level of 'who did what' to the file, but also (if set up right) allows them to check it out remotely and always get the latest version, whilst still being secure in non-secure environments (ie if I go onsite, I'd want to be able to get the latest version over the internet, or a vpn).

It won't stop people from changing the password on the site and not telling anyone, but nothing will solve that problem short of "human processes" (and a stern talking to from the boss if they fail to comply).

In short - there is no easy way to resolve the problem of people not telling others what they've done. The only technical approach that helps here is to provide a central system that is easy to modify and read so people get in the habit of using it.

Title: Password insanity! Recommended approaches to password management on multiple client systems?

Body:
A software development company I work with has a web based product they are successfully selling to clients. All of these clients have a support agreement with us that generally requires us to access their servers, databases and application data. As the number of clients grows, (and the number of different people supporting those clients grows), we are seeing a need to better manage in particular passwords, but more generally all the information one would need to fully support client systems ie. URLs, application login details, IP addresses, any client-specific weird stuff etc etc. This data is changing on an increasingly rapid basis, as systems get moved around to different machines, IP addresses. The worst problem is superuser passwords for the applications. These are constantly changing and occasionally we find ourselves in a situation where nobody seems to know who made the most recent change.

This is clearly an unsatisfactory situation. There are procedures in place which say that password changes etc need to be documented in a central secure place. But of course, people being humans, sometimes forget to document these things. The danger is that when people get so fed up of password chaos, that you can end up with a situation where everyone's password is "password123" as they can't be bothered any more.

Apart from enforcing the procedures, what other approaches could we take? One suggestion I heard was to have a "hidden" application superuser whose password is easily remembered/derived, which only support personnel would know about it. Personally I think that solution is a scary security hole, especially when you have multiple clients using your software.

So how would you handle this situation if you were supporting multiple clients? More strict procedure enforcement, or a technical approach to make life easier for everyone?


问:
Should I remove unreferenced code?
I'm working on a medium sized (100k lines) code base, it's all relatively recent code (less than a year old) and has good unit test coverage.

I keep coming across methods which are either no longer used anywhere or only referenced in unit tests which only test that specific method.

Should I remove this code if I'm certain that it's no longer needed?

Reasons to remove it:

Less code, less bugs

Less code is easier for others to digest

It's still under source control

Reasons to keep it:

Can be used as reference

It may be useful sometime

It may have been written to 'round-out' the functionality for a class

答:
The only good reason I can see to keep code that isn't currently used is if it is part of a self-contained module: While some parts of the code might not be used at the moment, it may well be that they will be used in the future.

This may be especially true for a library that you use across different projects: you do not want to keep throwing pieces of code in and out, according to what you need for a specific project: I find this time consuming and error-prone.

My approach is: (1) if you use it once, only keep what you really need; (2) if you use it twice, copy and adapt it the second time you use it; (3) if you use it more than twice, make a well-defined, stable module out of it, and use this module as you need.

Summarizing: I would throw away all unused code unless it is part of a general-purpose module that you have designed as such and that you know you are going to reuse several times.

Note: Of course, an even cleaner solution would be to make a separate project for a library, and add a dependency between projects.

Title: Should I remove unreferenced code?


问:
How can variables be created at runtime?
Is it possible to define variables dynamically?

Last night I was writing some code (C and VB2010) and I ran into a problem related to defining variables in my program. The variables needed depend on the number of entries added by the user and the number of users. Even using dynamic memory allocation we have a size limit, but I wonder about this type of thing sometimes. We can define as many variables as we need (to a limit of course) when writing the code, but can't we define more at runtime?

For example: say your whole program is done and when user says 'x', this cannot be created as variable; rather we require a variable to store that x. Why cant we make x a variable at runtime? Can't we build a bridge between compile-time and runtime with some rules?

答: What you're trying to do here is called meta-programming. Writing a code that writes code. Very popular thing with ruby (rails) developers. It's also possible in ObjectiveC. Probably other languages too, 'cause I'm no expert in others.</p>


问:
What's happens if I develop a program taking inspiration from another GNU GPL application?
My friend and I are planning to develop a tiny and simple CMS by taking some inspirations from an already existing GNU GPL CMS.

We take the ideas and try to develop it as simply we can, is it possible ? We are planning to set up the same licence, GNU GPL. Is it a good choice ?

Which are the conditions to do it ?

答:
You can take all the ideas you want, unless they're patented. Copyright doesn't cover ideas or functional elements.

A quick test for whether you can take something or not is this: Can you easily replace the thing you are taking with a thousand other things that would all work just as well? If so, it is expressive, and you may not take it (instead, do one of the other things that work just as well). If not, it is functional, not expressive, and you may take it.

(Consult a lawyer if you need actual legal advice!)


答:
building anything at run-time can be done in two ways:

Things which are dynamically entered by user

Things which are equivalent to writing code

The first one is something almost all developers do. The number of items per page of a paged list, or the tax percentage, or the background color of a form, or anything of this essence is really easy to become dynamic.

However, what you ask is like trying to produce code at run-time. For example, if we have 2 variables:

```<code>string firstName;
int age;
</code>```

now you want to introduce the third variable at run-time:

```<code>string[] interestes;
</code>```

The only thing comes to my mind is through run-time code-generation, then recompiling it run-time, the calling it and executing it. For example, in .NET, the namespace of System.CodeDom is dedicated to this issue.

Title: How can variables be created at runtime?

Body:
Is it possible to define variables dynamically?

Last night I was writing some code (C and VB2010) and I ran into a problem related to defining variables in my program. The variables needed depend on the number of entries added by the user and the number of users. Even using dynamic memory allocation we have a size limit, but I wonder about this type of thing sometimes. We can define as many variables as we need (to a limit of course) when writing the code, but can't we define more at runtime?

For example: say your whole program is done and when user says 'x', this cannot be created as variable; rather we require a variable to store that x. Why cant we make x a variable at runtime? Can't we build a bridge between compile-time and runtime with some rules?

Body:
building anything at run-time can be done in two ways:

Things which are dynamically entered by user

Things which are equivalent to writing code

The first one is something almost all developers do. The number of items per page of a paged list, or the tax percentage, or the background color of a form, or anything of this essence is really easy to become dynamic.

However, what you ask is like trying to produce code at run-time. For example, if we have 2 variables:

string firstName;
int age;

now you want to introduce the third variable at run-time:

string[] interestes;

The only thing comes to my mind is through run-time code-generation, then recompiling it run-time, the calling it and executing it. For example, in .NET, the namespace of System.CodeDom is dedicated to this issue.


问:
What is the proper way to create requirements documents?
Right now my supervisor is creating requirements documentation / specs for me using bugtracking software.  This seems like a terrible idea to me, all the requirements are on these little tickets and I have to click around on this dumb webform to get at the requirements.  What is a sane software solution for requirements / software specs?

To be clear, I am building this large software component with quite a few features and these features are being set forth in this bugtracking software.

答:
I am rather surprised that nobody so far has recommended the use of a wiki for tracking requirements.

I've found it to be an almost perfect system, because:

It allows people to collaborate on the requirements and makes this aspect highly-visible;

It enables you to easily keep the requirements up to date as the project progresses;

You can go in and see the history at any time, in case of a "that's not what we agreed" dispute;

Most modern wikis have decent formatting capabilities, so it looks almost as good as a Word doc;

You can hyperlink directly from your requirements into actual documentation;

You never have to worry about people working off of different/obsolete copies;

Requirements can start to be treated as an iterative process, just like design/implementation;

If the requirements start to get really large/complicated, it's easy to split them up across pages/topics.

Most wikis accept HTML, so if you really need advanced formatting, you can probably use a tool like Windows Live Writer.

Given the choice, I almost always choose the wiki method these days, it's really quite painless compared to the old-fashioned Word documents or trying to cram it all into a bug tracker.


答:
If you use a version control system, then don't worry about future references, as you simply can see through the history of that code and find the deleted part. If you don't and you think it would be used someday, then simply let it stay there, but comment it with a description explaining why it's commented.

However, if you're sure that you won't use it in future, simply remove it. I think the reasons you've mentioned are pretty straightforward for the code to be removed.

But please before removing it, make sure that it's not used anywhere. Visual Studio has a feature called Find All References which searches the entire solution and finds any reference to the current variable, method, property, class, interface, etc. I always get sure that no reference is in place before removing part of my code.

Title: Should I remove unreferenced code?

Body:
I'm working on a medium sized (100k lines) code base, it's all relatively recent code (less than a year old) and has good unit test coverage.

I keep coming across methods which are either no longer used anywhere or only referenced in unit tests which only test that specific method.

Should I remove this code if I'm certain that it's no longer needed?

Reasons to remove it:

Less code, less bugs

Less code is easier for others to digest

It's still under source control

Reasons to keep it:

Can be used as reference

It may be useful sometime

It may have been written to 'round-out' the functionality for a class


答:
Dynamically typed languages can define variables dynamically. Javascript has prototype based objects that can be defined and used as follows:

```<code>var myObj =  {}; // Empty object

// Define var1 in myObj
myObj.var1 = "Hello World";

// Use var1
console.log(myObj.var1);
// Prints: Hello World

// Redefine var1 in myObj
myObj.var1 = 1336;

// Use var1 again
console.log(myObj.var1 + 1);
// Prints: 1337
</code>```

In statically typed languages, such as Java, you need to solve it in a different manner. One easy way to emulate dynamic variables is to use the Map data structure (Map in Java, aka. Dictionary in .NET or Associative Arrays) much like how dynamically assigned variables do under the hood in languages such as Javascript:

```<code>Map<String, Object> vars = new HashMap<String,Object>();

// Define a variable:
vars.put("var1") = "Hello World";

// Use a variable:
System.out.println(vars.get("var1"));
// Prints: Hello World

// Redefine variable (1336 int is actually boxed into an Integer object):
vars.put("var1") = 1336;

// Use the variable again, type casting is needed:
System.out.println(1 + ((Integer) vars.get("var1")));
// Prints: 1337
</code>```

So there are ways to emulate dynamic type variable handling in a statically typed language such as Java, but it will be more verbose than in a dynamically typed javascript.

Edit:

Just to answer the OP in a more direct manner:

say your whole program is done and when user says 'x', this cannot be created as variable; rather we require a variable to store that x. Why cant we make x a variable at runtime?

As I alluded in my answer: Yes, you can emulate this behavior. I've created a small Java class to demonstrate the example and is available as a Gist. Feel free to run the example code and continue hacking on it.

Body:
Dynamically typed languages can define variables dynamically. Javascript has prototype based objects that can be defined and used as follows:

var myObj =  {}; // Empty object

// Define var1 in myObj
myObj.var1 = "Hello World";

// Use var1
console.log(myObj.var1);
// Prints: Hello World

// Redefine var1 in myObj
myObj.var1 = 1336;

// Use var1 again
console.log(myObj.var1 + 1);
// Prints: 1337

In statically typed languages, such as Java, you need to solve it in a different manner. One easy way to emulate dynamic variables is to use the Map data structure (Map in Java, aka. Dictionary in .NET or Associative Arrays) much like how dynamically assigned variables do under the hood in languages such as Javascript:

Map<String, Object> vars = new HashMap<String,Object>();

// Define a variable:
vars.put("var1") = "Hello World";

// Use a variable:
System.out.println(vars.get("var1"));
// Prints: Hello World

// Redefine variable (1336 int is actually boxed into an Integer object):
vars.put("var1") = 1336;

// Use the variable again, type casting is needed:
System.out.println(1 + ((Integer) vars.get("var1")));
// Prints: 1337

So there are ways to emulate dynamic type variable handling in a statically typed language such as Java, but it will be more verbose than in a dynamically typed javascript.

Edit:

Just to answer the OP in a more direct manner:

say your whole program is done and when user says 'x', this cannot be created as variable; rather we require a variable to store that x. Why cant we make x a variable at runtime?

As I alluded in my answer: Yes, you can emulate this behavior. I've created a small Java class to demonstrate the example and is available as a Gist. Feel free to run the example code and continue hacking on it.


问:
Why to let / not let developers test their own work
I want to gather some arguments as to why letting a developer testing his/her own work as the last step before the product goes into production is a bad idea, because unfortunately, my place of work sometimes does this (the last time this came up, the argument boiled down to most people being too busy with other things and not having the time to get another person familiar with that part of the program - it's very specialised software).

There are test plans in this case (though not always), but I am very much in favor of making a person who didn't make the changes that are tested actually doing the final testing. So I am asking if you could provide me with a good and solid list of arguments I can bring up the next time this is discussed. Or to provide counter-arguments, in case you think this is perfectly fine especially when there are formal test cases to test.

答: Because developers are not good at trying to break their own code. Their mind simply follows the correct path of data entry and interaction with the application. Many bugs are the outcome of interacting with the system like a normal guy. Developers are not normal users. They are professional users.


答:
Check out Secret Server -- was built by a software company to solve just this sort of issue -- any sort of secret can be securely stored and there is room for some local notes.

If you need more information that that, I'd advise a wiki and perhaps an issue tracker. We find that redmine handles this perfectly as the integrated issue tracker/wiki helps feed itself.


问:
What are the most over-saturated iPhone App category/markets?
I'm considering learning iPhone development and Objective C but don't want to avoid developing something for the most saturated markets and app categories.

What categories should I avoid?  Are there too many dating applications, or should I just stick to coming up with a creative game or two?

答:
The iOS market has way to many apps in general. Try to make an iPad app. There are less iPad apps out than iPhone/iPod touch.

Alternatively, try to make something for a particular (local) business.
That way you are guaranteed to get paid (by the business) and you get an app out there that is unique.

Games are always good, provided that the gameplay attracts people. Like the speakers at the WWDC 2010 said, watch play testers as they do their thing. It helps a lot with your game development.


答: One issue is developers have little incentive to break their own code -- few people are willing to search for defects in their own works or are willing to make mistakes. Having a separate team helps ensure that things will be broken.</p>

Title: Why to let / not let developers test their own work

Body:
I want to gather some arguments as to why letting a developer testing his/her own work as the last step before the product goes into production is a bad idea, because unfortunately, my place of work sometimes does this (the last time this came up, the argument boiled down to most people being too busy with other things and not having the time to get another person familiar with that part of the program - it's very specialised software).

There are test plans in this case (though not always), but I am very much in favor of making a person who didn't make the changes that are tested actually doing the final testing. So I am asking if you could provide me with a good and solid list of arguments I can bring up the next time this is discussed. Or to provide counter-arguments, in case you think this is perfectly fine especially when there are formal test cases to test.


答:
You can do this in c by dynamically modifying the code but you almost certainly don't want to for anything other than educational interest.

You've mentioned dynamic memory allocation (malloc and friends in c) and then talked about still having to have limits.  Bear in mind that however you create variables there are still limits.  If you are creating automatic variables at runtime then they are created on the (limited) stack.  If you are creating globals they sit in (limited) var space.

I think I would solve this in c using malloc.  Yes you have to place limits, but at least you can define what these limits are and handle them gracefully.


答:
It's most certainly possible in a sufficently dynamic language. However, it's very rarely regarded a good idea even in those languages. Here are a few reasons:

It is not needed. There are associative arrays, which by definition associate a name with a value, like variables do (they are in fact used to implement variables and object members - at least partly - in quite a few of the aforementioned languages). Hash tables are actually more powerful than variables in many (especially static) languages - you get a range of operations that don't necessarily make sense for variables, such as iterating over the keys.

It mixes up concerns. User input is separate from the names used in your implementation, user input shouldn't break the system because it happens to clash with one of your variable names. If you want to treat user input as variables, these should at least be in their own scope. And then you're back to manually using objects to collect user input in - call them a associative arrays or call them dynamically-created scopes, it's exactly the same thing. Except that associative arrays are conceptually simpler, more widely supported, possible more powerful, and more immediately recognized.

To make explicit what has been implied above: Using an associative array is like dynamically creating variables! It's merely restricted to its own scope, which is good and what you'd want anyway.

Also note how ridiclously hard it is to integrate this with static language's views on variables. C++ code doesn't have variable names at runtime, are you suggesting throwing out all the associated optimizations and introducing a ridiculously complicated system for dynamically compiling code, just so you can do the same thing as before under a different name?


答: You can't Patent an Idea, Patents cover inventions, in other words implementations of ideas. Ideas are free to re-implement as long as it is a clean room implementation.</p>

Title: What's happens if I develop a program taking inspiration from another GNU GPL application?

Body:
My friend and I are planning to develop a tiny and simple CMS by taking some inspirations from an already existing GNU GPL CMS.

We take the ideas and try to develop it as simply we can, is it possible ? We are planning to set up the same licence, GNU GPL. Is it a good choice ?

Which are the conditions to do it ?


答:
I am not a lawyer and I am not an expert on the GPL, but;

If I've understood your question correctly you are planning on releasing your work (project A) under the GPL, and want to use some ideas from another project (project B) which was released under the GPL, is this the case?

If so then I think that you can use as much or as little of project B as you wish, including source and the only extra thing you would need to do is credit Project B in the docs and source.


问:
If TDD is about design why do I need it?
TDD gurus more and more tell us that TDD is not about tests, it is about design. So I know some developers who create really great design without TDD. Should they practice TDD then?</p>

答:
Simplistic answer coming from someone striving to learn TDD:  You don't need it, but the major benefit it gives you is, quite simply, confidence: Confidence that your application works.  Confidence that the use cases are satisfied.  Confidence that your logic is sound for the "Foobar" module.  Confidence that your code is structured properly to be maintainable and extensible six months down the road when the CEO wants to add in some new crazy feature he read about.  Confidence that, when your application grows, the foundations have been laid for the architecture to not fall apart or require gobs of messy hacks to jury-rig new features.

I realize the above sounded a bit evangelical but that's how I see the benefit of TDD.  Even if you can create good, solid, well-architected designs using TDD forces your hand into doing things right, and then proves that things are done right, and more importantly provides a baseline for keeping things right.  From the very little I've dabbled in TDD, using it forced me to make the code clean and follow proper software engineering concepts, where otherwise I would do the "quickest thing possible" which often resulted in messy "hack" code.


答:
While the subject of dynamically creating code, compiling it and integrating it into the currently running application is interesting, I'm not sure it is what you are looking for.

Your problem which is reading an undefined number of entries in a format not know in advance and doing something with these does not seem very complicated, or maybe I am mistaken... Spoike's example code would be enough. If you want more than "maps", then yes you may need "meta beans", like for example dynamic beans (this is a Java example).
Apache's BeanUtils library could be exactly what you are looking for.

Edit: in .NET you could use Spring.NET's framework, as it supports dynamic languages such as Groovy for example.


答:
There are a few good reasons to have a dedicated testing team. First, as mentioned above, developers are very good at testing that their code works, but not a breaking it.

Also, as you say, a developer knows what they wrote, but a testing teams knows what should have been written. At times, these two concepts don't match up. One of the jobs of the testing team is to make sure that the software meets the requirements. In many cases, a developer only knows a few parts of the system very well but the QA team knows the whole thing.

Which leads to the next reason, testing teams do full integration testing. The piece of code that you just wrote might work fine on it's own, but could break other functionality that you didn't know about.

Having worked with a QA team and without, I can tell you I 100% appreciate the work that they do and will say they are a valued part of the software team. When you have a QA team, it makes releasing your code that much easier, b/c you know it's been thoroughly tested and that means you'll get less 3am calls.


答:
It's not only developers being protective of their code, if they don't realise a particular case, or misinterpret a specification in the way they develop something, then they will miss those cases when testing their code.

The techniques and skills for testing are both very different too.

Most testing by a test team is functional (that a product functions as per a specification) and black-box (the test team will not see the inner workings of an application). Functional testers do not need to be concerned with how things work, they only need focus on whether they do.


答:
One reason is because developers are too close to their own code. They know it's quirks, it's little weird behaviours. They tend to test around the little idiosyncrasies they know so well. They are not objective enough about it. Test teams treat it like a black box. They write matrices of dozens or hundreds test cases and methodically run through them to see what the code will do. Often they come up with scenarios the development team would never dream of.

Another reason is time. For large projects that are built in stages, the development team will build Stage 1. Then the testers will test it while Stage 2 is being built and the defects of Stage 1 are fixed. This goes on for all stages, so stage being tested is the previous one that was built.


问:
Should this code be rewritten or refactored?
There is a module in our telecoms equipment which is written in C. I think the code in this module has a bad smell because it has a number of symptoms:

When new features are added to this module, some original features go wrong. And some weird problems were finally orientated to the buffer overflow of this module.

It is difficult to add new code to the module. Although the unit tests and integration tests covers new code, errors and flaw concealed in the original code come to the surface.

By means of code review, we found the quality of the code is extremely bad. But the module was tested for many rounds, the errors concealed in the surface of the code were found by the QA engineers. Other problems hidden deeper were difficult to find. as well as a virus in the body.(easy to bring misunderstanding, delete it)

We summarize the status quo lay in these reasons:

The original code has corrupted because of the loose process monitoring, in fact, many self testings are ignored or partial executed.

The first programmer of this module was lack of the programming ability and the team leader didn't find the problem and risk in time.

Many improvement approaches stay in the plan phase due to the team leader's suspicion.

The project came to a new version. Some team leaders want to change this situation and we discussed the procedure many times. Everyone has agreed to revise the module but we have to decide between:

rewriting the module. It means throwing all the code of the module to the trash can and rewriting the code without changing its interface.

refactoring the module. This means one step at a time. we need retain all the code at the beginning and build a solid set of tests for the code. Then we dig into the code and revise a small piece of it, and relying on the tests to tell us whether we introduce a bug. This process is repeated until the refactoring complete.

I agree with rewriting because we already have some rewriting experiences in our systems which were proven to be the best choices. The project manager wishes to refactor the module on account of the limited time available required to complete the detailed design, coding, code review, unit tests and integration testing which is three months. He thinks the time scales are too tight to do a full rewrite.

Should this code be rewritten or refactored?

EDIT:

As Joel said in Things You Should Never Do, Part I

The idea that new code is better than old is patently absurd.

I agree with this viewpoint. But I have some puzzles that some rewriting cases in our project proved to be wise choice. Maybe it relies on the new programmer who is more outstanding than the previous programmer or the testing is more sufficient.

答:
This made me think a lot: "When new features are added to this module, some original features go wrong." I have seen this happen quite often and, IMHO, the reason is mostly related to the fact that the "open/close" principle is not followed.

Basically, you should not add new features by modifying existing, working, and well-tested code. Rather, you should add new features by writing new code on which the old code does not depend.

So, if extending your code breaks old features, can it be that the code is not being extended properly?


答:
If the code is trivial and uninteresting, I just throw it away to rid of unnecessary inertia of the software system.

For interesting code cadavers, I use an archive branch in my version control systems.

Title: Should I remove unreferenced code?


问:
How does css3 hardware acceleration work?
Can anyone tell me how some css3 code (transitions/transformations) get hardware accelerated? In other words, what actually happens when the browser sees css3, what is the pipeline/process involved?</p>

答:
I don't know the details of the respective implementations, but I'd assume that browsers go through some 3D API to render pages - not just for CSS3 specific things, but for everything. A simple implementation of a transition would render both versions of the transition onto textures, then for each frame draw the second one on top of the first one with increasing opacity.

For transforms, it's as simple as changing the current display matrix (modelview matrix in OpenGL lingo) to produce the desired effect.

Some things that have been in CSS prior to version 3 can also benefit from hardware acceleration; for example, to render anti-aliased glyphs, one could render text onto a texture at, say, 8 times the desired size, then use trilinear filtering (which, again, you basically get for free on 3D hardware) to scale it back down.


问:
What tools do PHP Developers use?

Possible Duplicate:

  What would you consider best practice workflow tools for web application (PHP) development?

I start my new job next week as a PHP Developer which is my dream job but it's going to be object-orientated which I've only done in Java whilst at university.

My question is regarding PHP tools - what are the best IDE's (I use notepad++), what versioning packages work best and bug trackers etc, so I was just wondering what tools the PHP developers out there use in their working lives.

答:
It would be normal for a new developer to fit in with what the rest of the team is using, unless the dream job is one where you are the team :). Here's some tools that work for me (you will want to compare notes with the other answers).

IDE: I'd recommend the JetBrains tools, either PhpStorm (PHP Specific) or IntelliJ IDEA (Super-new features appear slightly after PhpStorm but works for multiple languages; I do Java, Python, Ruby and PHP). Unlike many other tools they cost Real Money but since you're in your dream job, convincing your boss to pay shouldn't be a problem :). It's worth paying for these tools rather than the other Java IDEs turned polyglot (Netbeans, Eclipse), if only for the vastly better editor.

In general on IDEs vs text editors: I like beautiful syntax highlighting and completion, as well as the graphical integration with debugger and revision control that IDEA gives me. Many grizzled veterans will tell you that they don't need or want those features, so if Notepad++ works for you that's ok.

Revision control: the DVCS concept seems standard these days; Git is very popular on Linux but it sounds like Mercurial may be more user-friendly on windows.

Bug Trackers: Big companies I've worked in have used Jira. For personal projects I use PivotalTracker (leans more towards project management with the scrum methodology, but could be used just to manage bugs). I've also heard good things about Redmine.

Web Development: You didn't explicitly ask about but I imagine your work will involve web dev in general. Firefox plugins:

Firebug - helpful for debugging and profiling the DOM and your HTTP requests

Web Developer Tools - likewise

Rainbow Colour Tools - figure out what that awesome colour in your favourite community site's logo is

There used to be an add-on called FirefoxThrottle that would let you see how your sites performed on slow connections. No longer exists but you can still use Speed Simulator on Windows.

Title: What tools do PHP Developers use?


答:
The ones I have been using frequently in the last few years

PHPDesigner 7 - simply the best lightweight editor there is. Perfect highlighting, perfect support of smarty and javascript. Very fast, good built in FTP/SFTP browser. And it is not expensive.

PhpStorm - its one of the JetBrains IDEs and I am extremely pleased with it. Good highlighting, good refactoring, good formatting and indentation. If you want to use beta versions and help the JB team it can be used free almost forever for now.

Super flexible file synchronizer - because the project is huge I need something to push to the test server on file change

Mercurial - I prefer to not use the built in PhpStorm mercurial client and do my merges etc from PowerShell

Notepad++ is also good option for fast and dirty edits.

Other tools that are useful

Ditto - I use it all the time. Clipboard manager that remembers your last 500 copy commands. with search in them.

Everything - also another general purpose tool for fast file search in windows.

Title: What tools do PHP Developers use?

Body:
Possible Duplicate:

  What would you consider best practice workflow tools for web application (PHP) development?

I start my new job next week as a PHP Developer which is my dream job but it's going to be object-orientated which I've only done in Java whilst at university.

My question is regarding PHP tools - what are the best IDE's (I use notepad++), what versioning packages work best and bug trackers etc, so I was just wondering what tools the PHP developers out there use in their working lives.


答:
Generally, I would bow to YAGNI on this. If "you ain't gonna need it", then it is simply taking up space in your codebase, unit tests, and assemblies. You may end up needing it, but you may also end up needing to completely rewrite it because between now and when you need anything like it, a lot can change.

However, that changes somewhat when you're writing a utility or API meant for general consumption. Just like you can never expect software end-users to interact with the software in the way you intended, you can never expect consumers of your code to want to use your code exactly the way you think they should. In such cases, as long as you can justify a method's existence with "it's a valid way to want to interact with my object" then it should probably go in, because even if you ain't gonna need it, chances are good SOMEONE will.

Title: Should I remove unreferenced code?


答:
Given that the codebase is less than a year old, it's probably still in a lot of flux (yes?) - so the notion that some bits might need to be resurrected in the near future is not unreasonable.

For bits that were hard to get right in the first place and seem more likely to be resurrected, I'd keep them a bit more "live" than just in source control.  Folks won't know/ remember that they exist - saying "you can just find it in source control" presumes that you know/remember that it's there!  In these kinds of cases, consider deprecation (with an "assert(false)" showstopper) or commenting out.

Title: Should I remove unreferenced code?


问:
Should a special version of a website be developed for tablet users?
Does the desktop browser version of a web site always suffice for the tablet version(assuming no flash)? or is it common for websites to have a special tablet version that is different from both desktop and phone?</p>

答:
Most websites will function adequately on tablets as-is, although you do have to be careful with things like dropdown menus, as there is no concept of "hover" on a tablet.

Many websites actually have a somewhat "better" experience on tablets, because the tablets know how to find the edges of the website and eliminate the unused real-estate (like the white borders you see around this page).

That said, there are many websites that either provide a mobile version of their site (typically auto-detected by the website via the User Agent property of the browser you are using), or give you an app.  On phones, due to the very small screen size, this strategy is essential.


问:
What are the algorithms behind low pause GC?
Some languages, for exemple java, introduced a low pause GC.

Those GC can do most of the work without pausing the whole world. This is obviously a quite hard problem because it require to analyze the memory when thread are modifying it, resulting in data that can be used in the begining of the process and not anymore when it finishes, or data that appears to be garbages but because the reference was moved in memory and never appeared where the GC was looking.

So basically, what is the algorithm(s) behind that ?

Research papers or really technical article's link would be considered as valid answer, as this topic is really technical.

答:
as far as I understand, Java G1 garbage collector uses so called heap regions to avoid pausing the whole world. The way I see it is that while one of the regions is locked by GC performing cleanup, memory allocation is done in another region.

Here is an explanation from Jeremy Manson:

The principle is simple: the collector splits the heap up into fixed-size regions and tracks the live data in those regions. It keeps a set of pointers — the "remembered set" — into and out of the region. When a GC is deemed necessary, it collects the regions with less live data first (hence, "garbage first"). Often, this can mean collecting an entire region in one step: if the number of pointers into a region is zero, then it doesn't need to do a mark or sweep of that region...

here is a technical paper from Sun engineers explaining their design: Garbage-First
Garbage Collection


答:
I've done a bit of PHP work, and I found a couple of tools that worked particularly well.

For source control and bug tracking you'll use the same thing as everyone else on the team.  You won't have many options there and it's really for the best anyway.

For IDE, I was using DreamWeaver.  Which wasn't really anything to talk about as far as development assistance, but has an excellent "synchronization" feature that I wouldn't want to work without.  Basically, it manages the differences between the files on my local machine, the files on the testing site, and the files on the production site.  A couple clicks and you know that all the files on the remote server are synchronized to your current build? Priceless.  So I would heavily recommend any IDE with that kind of a feature in it.

The most important tool I found though was the one that I deployed to the remote site myself: phpMyAdmin.  A big part of the job was creating and manipulating the mySQL database, and for that I couldn't find anything better than a freely available PHP package designed specifically to do that.  As far as "PHP tools" goes, I don't think you can find a more literal match!  8 D

Title: What tools do PHP Developers use?


问:
How risky is it to use Coffeescript without knowing Javascript?
I'm a reasonably experienced programmer trying to learn web developement.  I'm trying to develop a client-side web application which uses svg or canvas for graphics.  I've decided I'd like to write the application code in Coffeescript.  I don't know either Javascript or Coffeescript.

How necessary knowing Javascript to Coffeescript web development?  Am I likely to hit some gnarly problem which requires me to understand Javascript?  Can I work happily with Javascript APIs from Coffeescript?

Edit:
I could easily learn the basics of Javascript in a week.  I'm more concerned that Javascript seems to have a lot of hidden sharp edges.  In the strangest language feature question on StackOverflow Javascript is one of the most common languages.  It has an unusual object and class model.  It has non-obvious name scoping rules.  I find it takes more than a week for me to really know a language.

I'm going to work on a small simple project to learn web development.  Would I be better off to use Javascript or Coffeescript?  I think in the long run I'll prefer Coffeescript but I'm willing to start with Javascript if that I'm going to need a thorough understanding of Javascript to use Coffeescript.

答:
Because "The golden rule of CoffeeScript is: 'It's just JavaScript'," I do recommend at least a basic familiarity with JavaScript.  In particular, have a look at Douglas Crockford's little book, JavaScript: The Good Parts.  You can also watch Crockford's own great introductory presentation about it.

CoffeeScript basically wraps the good parts of JavaScript in a different package:  "CoffeeScript is a simple thought experiment to imagine a language that exposes a minimal syntax for the beautiful object model that underlies JavaScript."  You don't need to know all the details, just enough to understand that JavaScript, itself, is not a class-based object-oriented language.  It has no classes at all.  Instead, it uses "prototypes," and that makes for some differences from other OO languages.  Jeremy Ashkenas cleaned up some of the bad parts of JavaScript syntax, added some enhancements, and made it a bit more Python-esque.

JavaScript has some well-known "gotchas" to watch out for.  Otherwise, it's a great language and is in very common use, today.  We wouldn't have AJAX or jQuery without it, among other things.

Good luck with your CoffeeScript!


问:
I'm writing about language syntax. Is there a language out there in which parameters are placed inside method name?
in JavaScript:

function getTopCustomersOfTheYear(howManyCustomers, whichYear) {
   // Some code here.
}
getTopCustomersOfTheYear(50, 2010);
```

<p>in C#:</p>

<pre class="lang-cs prettyprint-override"><code>public List<Customer> GetTopCustomersOfTheYear(int howManyCustomers,
 int whichYear)
{
   // Some code here
}
List<Customer> customers = GetTopCustomersOfTheYear(50, 2010);
</code>```

in PHP:

public function getTopCustomersOfTheYear($howManyCustomers, $whichYear)
{
   // Some code here
}
$customers = getTopCustomersOfTheYear(50, 2010);
```

<p>Is there any language out there which support this syntax:</p>

<pre class="lang-c prettyprint-override"><code>function GetTop(x)CustomersOfTheYear(y)
{
    // Some code here
}
returnValue = GetTop(50)CustomersOfTheYear(2010);
</code>```

Isn't it more semantic, more readable form of writing a function?

Update: The reason I'm asking this question is that, I'm writing an article about a new syntax for a new language. However, I thought that having such syntax for declaring methods could be nicer and more friendly to developers and would decrease learning-curve of the language, because of being more closer to natural language. I just wanted to know if this feature has already been contemplated upon or not.

答:
I believe you are looking for the abstraction called "fluent interface (I am hereby raising a comment, originally made by @Jesper, to an "answer")."  This now common pattern has been successfully implemented in many languages, of which Objective-C is only one.

Here is a pretty clean example:

```<code>Person bo = new Person();
bo.Set.FirstName("Bo").LastName("Peep").Age(16).Size("Little").LostHerSheep();
</code>```

You can see how something like this can be implemented in Randy Patterson's How to design a fluent interface.

Andre Vianna gives a brief history and then discusses possible implementations in  two more article parts, including plenty of useful information.  Vianna points back to the old idea I first encountered in Smalltalk 80 called "cascading," that enabled sending multiple messages to the same object.  It looked like this:

```<code>aThing one: 'one';
  two: 'two';
  other.
</code>```

Cascading subsequently evolved into "method chaining," where we "Make modifier methods return the host object, so that multiple modifiers can be invoked in a single expression."  Method chaining later grew up to become the fluent interface concept we know and use frequently today.  What you plan to do looks very similar.

Ayende Rahien discusses how "fluent interface" may differ significantly enough from "method chaining" to deserve its own name.

Fluent interfaces are commonly seen in some of the new tools used in behavior driven development (BDD) and have even found their way into NUnit, a major .NET unit testing tool, in its new Constraint-Based Assert Model.

These basic approaches have subsequently been implemented in other languages, including Ruby, Python, C#, Objective-C and Java.  To implement something similar, you will want to study up on the idea of "closure," which is pretty much fundamental to chaining and fluency.

Perhaps you can improve on these models; that's how we get great new languages.  Still, I believe that fully understanding method chaining and fluent interfaces will give you a great starting point from which to evolve your ideas!

Body:
I believe you are looking for the abstraction called "fluent interface (I am hereby raising a comment, originally made by @Jesper, to an "answer")."  This now common pattern has been successfully implemented in many languages, of which Objective-C is only one.

Here is a pretty clean example:

Person bo = new Person();
bo.Set.FirstName("Bo").LastName("Peep").Age(16).Size("Little").LostHerSheep();

You can see how something like this can be implemented in Randy Patterson's How to design a fluent interface.

Andre Vianna gives a brief history and then discusses possible implementations in  two more article parts, including plenty of useful information.  Vianna points back to the old idea I first encountered in Smalltalk 80 called "cascading," that enabled sending multiple messages to the same object.  It looked like this:

aThing one: 'one';
  two: 'two';
  other.

Cascading subsequently evolved into "method chaining," where we "Make modifier methods return the host object, so that multiple modifiers can be invoked in a single expression."  Method chaining later grew up to become the fluent interface concept we know and use frequently today.  What you plan to do looks very similar.

Ayende Rahien discusses how "fluent interface" may differ significantly enough from "method chaining" to deserve its own name.

Fluent interfaces are commonly seen in some of the new tools used in behavior driven development (BDD) and have even found their way into NUnit, a major .NET unit testing tool, in its new Constraint-Based Assert Model.

These basic approaches have subsequently been implemented in other languages, including Ruby, Python, C#, Objective-C and Java.  To implement something similar, you will want to study up on the idea of "closure," which is pretty much fundamental to chaining and fluency.

Perhaps you can improve on these models; that's how we get great new languages.  Still, I believe that fully understanding method chaining and fluent interfaces will give you a great starting point from which to evolve your ideas!


答:
It will stay in source control; it should not stay in the active code base.

The one exception is if the code completes the design and while you aren't using the code, you plan on eventually making the code public and others may want that basic functionality.  Then just design tests to make sure these parts of the code work that mimic how you propose others may use these parts of the code.  However, if you are even considering deleting the code and can't come up with a solid reason to keep it, it should go.  Unused code makes more work for everyone (harder to read the code; the code may be broken; more work to maintain; etc.)

Title: Should I remove unreferenced code?


答:
It depends heavily on the website, I've seen some that work great on tablets (and phones) with no special tweaks or extra configuration, and some websites that are completely hideous to use. The only way to ever be sure is to try it yourself or wait until a user mentions it.

A simple rule is if there's any level of complexity to the site you'll probably want to revise your approach to the site's UI to cope with the different level of interaction.

Title: Should a special version of a website be developed for tablet users?

Body: Does the desktop browser version of a web site always suffice for the tablet version(assuming no flash)? or is it common for websites to have a special tablet version that is different from both desktop and phone?</p>


答:
IBM's real-time JVM uses a garbage collector called Metronome that splits the GC activity into discrete quanta and interleaves them with application processing.  So basically instead of periodic (and non-deterministic) stop-the-world GC pauses, the application instead runs slightly slower while the GC is done in parallel.

There's another GC that does dynamic defragmentation and meets hard-realtime requirements, but the only reference I can find is here (ACM membership required).

An interesting concurrent real-time garbage collector is stopless.  It uses the traditional mark-and-sweep approach, but is designed for use on multiprocessor systems and supports lock-free concurrent multithreading.


问:
Have any of you tried "Basic for Android"?
I have developed for Android for half a year or so and it is going quite well. I found the learning curve steep in the beginning, but then I somehow got the idea of it all and now I don't have to fight so much anymore. Rather I spend the time on specific problems like "How to do X in Android" but that is usually simple enough to google - or to ask here :)

Anyhow, I just discovered Basic for Android and I must admit it looks attractive. It has the kind of IDE I am used to (Delphi) and it seems to be very capable. But on the other hand I am still new in the Android universe so I don't find myself competent enough to really judge the pros and cons of the tool.

Have any of you tried it, and if so, what are your thoughts about it?

答:
I will give a generic response since I have not used this particular toolset.  In general most of the "language translators" do not do as good of a job writing native code as a well versed programmer will.  They either translate some code or execute it under a "virtual machine" of sorts for that device. Much like Titanium Mobile (http://www.appcelerator.com/products/titanium-mobile-application-development/).

That does not mean that they don't serve a purpose.  Some of these tools are very good for prototyping or proof of concept type work if your company (or you yourself) does not have the experience  required to do such work.

They are also very good for people who are well versed in one language and do not want or are incapable of spending the time to get over the learning curve of the native language.

In my opinion since you have already gotten over the curve you would be doing yourself a disservice by going backwards and using a tool that will generate native code that you already know how to write.


问:
What ever happened to the Google AJAX Search API
I am looking to query the main Google search however all references including stackoveflow point to the Google AJAX Search API.

The odd thing is that it does not seem to exist any more not even a note to say it is depreciated?

The old links point to main Google code site. If I look at the list of API's on that site the API it replaced is there  Web Search API (Deprecated) which links back to same page but not the Google AJAX Search API.

Further Google searching is not being helpful either, many blog posts pointing to the same Google site (http://code.google.com/apis/ajaxsearch/) that has no content and redirects to the same place?

Just to prove it did exist I have found it on the way back machine however the last snapshot did not show any special unusual message.

答:
The Google AJAX Search API was deprecated on Nov 1, 2010, in favour of the Custom Search API.

The AJAX Search APIs contained Web, News and Local search among others, but when people referred to the AJAX Search, they typically meant Web search.

You can read some idle speculation on why they retired the AJAX search on the official Google AJAX APIs Group, but it seems to be mostly due to abuse:

https://groups.google.com/forum/#!msg/google-ajax-search-api/79wPelmXxKE/qM5TLOLxnss

http://googleajaxsearchapi.blogspot.com/2010/03/helping-you-help-us-help-you.html (d'oh! posted a day early!)

According to Google's deprecation policy, the web search API should continue to work until Nov 2013. The web search API is now confirmed to be no longer available as of September 29, 2014.

Here's the timeline, as best as I can reconstruct it:

June 2006: AJAX Search API v0.1 released

October 2006: AJAX Search API v1 released

December 2006: SOAP Search API deprecated

March 2009: AJAX Search API graduates from Labs

August 2009: SOAP API retired

November 2010: AJAX Search API deprecated

November 2010: Custom Search API introduced

November 2013: AJAX Search API access terminated?


问:
How do I avoid "Developer's Bad Optimization Intuition"?
I saw on a article that put forth this statement:

Developers love to optimize code and with good reason. It is so
  satisfying and fun. But knowing when to optimize is far more
  important. Unfortunately, developers generally have horrible intuition
  about where the performance problems in an application will actually
  be.

How can a developer avoid this bad intuition? Are there good tools to find which parts of your code really need optimization (for Java)? Do you know of some articles, tips, or good reads on this subject?

答:
What I've found is the best antidote to premature optimization is this method.

Once you've used it to speed up some code (as in this example), it becomes an addiction of its own, and you understand the first principle of performance tuning isn't tweaking code, it's finding the problem.

Real optimization is to premature optimization as hunting to feed your family is to shooting tin cans.
It's all about finding the quarry.

ContentLicense: CC BY-SA 4.0


问:
Why is it unrealistic to expect all browsers to support the same standards?
Ideally, we would have different browsers supporting the same standards and same code producing the same result on all browsers.

That hasn't happened yet. What are the reasons why?

答:
It's extremely unlikely to happen soon -- in fact, I'd go so far as to say that when/if it does happen, it's strong sign that the world has moved on, and simply doesn't care much about web browsers any more.

The problem is fairly simple: most of the limit on writing new standards for even cooler things that browsers could do, is lack of (even reasonable) conformance with existing standards. Looking at that from a slightly different direction, the minute browsers conform with existing standards (or even come reasonably close to conforming), it's nearly certain that at least a few people are going to start thinking "But wouldn't it be cool if we could...", and they'll then do one of two things: they'll either implement their idea in one browser, and then work on standardizing their idea (almost inevitably before any other browser implements it), or they'll work at writing a standard for that behavior, even though no browser implements it yet.

The bottom line is that implementation of standards across browsers almost inevitably lags behind invention of new standards with which to conform. The only way the browsers can all catch up is if people quit writing/designing new things for browsers to do.

At the same time, I feel obliged to point out that more or less the reverse is also true: this is a constantly growing set of standards with which browsers conform ever more closely. It wasn't very long ago, that the best score any browser got on the Acid3 test was 93/100. As it happens, that's exactly the same score that IE currently gets...


问:
What is Visual Studio Lightswitch and how does it differ from normal Visual Studio versions?
How is Visual Studio Lightswitch different from regular Visual Studio? In what sort of situations would you use this IDE over regular Visual Studio?

I'm trying to decide if this is something that would be worthwhile for me to take the time learning since I am currently doing WPF/Silverlight development.

答:
Clients may not care what you build their apps with as long as it is sound and you use accepted practices (And some don't even take the time to check any of this.). However, if they are under the impression that apps can be built quicker with this type of product, more developers may be pressured to start using it.

You may find yourself with the task of taking over an existing Lightswitch application created by a power user and they need more functionality. Supposedly you can still work with this in Visual Studio to do more.

If there is limited programming expertise in a company, there may be a need to let some of the power users to take over app development. You're more of a teacher/facilitator than purely a programmer except for the heavy lifting. This is common with report writing and may be expanding as rapid application tools improve.

Other than this, I don't see any reason to put too much energy and effort into this if you are already using Visual Studio.


问:
Avoiding wrapper objects in collections
I'm getting a little annoyed of having to wrap primitive types in wrapper objects to store them in collection data structures (sets, maps, lists, etc.) in languages like Java and Objective C. I'd really like to have, say, a Map data structure that works the same way whether I'm mapping NSNumbers to Strings or integers to doubles or integers to MyBigCustomObject*.

My understanding is that the reason collection data structures in these languages require wrapping in an object is so it can just always assume that the number given is a pointer - I actually can make a NSDictionary with [NSDictionary dictionaryWithObject: MyCustomObject forKey: 1], but it will treat the 1 as a pointer instead of an integer, try to access memory address 1 and segfault. But I don't see any reason why you couldn't make a collection data structure that keeps track of the type of keys and values that wouldn't have this problem. Even a relatively inflexible data structure like a Map of specifically-ints to specifically-pointers-to-objects would be a decently common use case (I certainly could use one, I'm doing a lot of work recently that involves indexing objects by an integer ID). Is there a reason why this isn't a common paradigm in languages that have an Object/primitive type distinction?

答:
It is, of course, possible. However, it would require duplicating all the code (which can be quite much for an optimized implementation) for each non-reference type, or a way to automatically specialize the implementation for each type.

I assume that nobody considered the first option worthwhile.

The second way adds some complexity to the language and its implementation. Also, in the case of Java, there are generics (which could in principle be used to implemented the second option) but early design decisions (some would say errors) prevent the second option, as generics are compiled to non-generic code that simply uses objects everywhere and casts as necessary.

Note that there is one language, C++, which has a mechanism for the second option (templates). It doesn't treat objects as pointers (reference types) though.

Edit: As FredOverflow points out in the comments, this does exist. Scala exposes the second option to the programmer with a @specialized annotation.

Title: Avoiding wrapper objects in collections


问:
Should I remove unreferenced code?
I'm working on a medium sized (100k lines) code base, it's all relatively recent code (less than a year old) and has good unit test coverage.

I keep coming across methods which are either no longer used anywhere or only referenced in unit tests which only test that specific method.

Should I remove this code if I'm certain that it's no longer needed?

Reasons to remove it:

Less code, less bugs

Less code is easier for others to digest

It's still under source control

Reasons to keep it:

Can be used as reference

It may be useful sometime

It may have been written to 'round-out' the functionality for a class

答:
One good reason to keep the unused methods is: they could be used on other branches/tags!

Explore all your active branches and tags before removing them.

Title: Should I remove unreferenced code?


问:
Why are data structures so important in interviews?
I must confess that I was not so strong in data structures when I graduated out of college. Throughout the campus placements during my graduation, I've witnessed that most of the biggie tech companies like Amazon, Microsoft etc focused mainly on data structures. It appears as if data structures is the only thing that they expect from a graduate.

To be honest, I felt bad about that. I write good code. I follow standard design patterns of coding, I do use data structures but at the superficial level as in Java exposed APIs like ArrayList, LinkedList etc. But the companies usually focused on the intricate aspects of Data Structures like pointer based memory manipulation and time complexities.

Probably because of my Java background, back then, I understood code efficiency and logic only when talked in terms of Object Oriented Programming like objects, instances, etc but I never drilled down into the level of bits and bytes. I did not want people to look down upon me for this knowledge deficit of mine in Data Structures.

So really why all this emphasis on Data Structures?

答:
Whether you write good code or not is a subjective statement.  It's important to know that functional code does not always make good code.

That said, data structures are important because they are like the behind-the-scenes workers that you, as the programmer, are directing.  It's true that you can call methods on a structure without really understanding what it's doing and you can utilize a structure without really getting how the data is stored, but knowing these details will better prepare you to understand when it is appropriate to use one structure over another.

Knowing, for example, that you can traverse in both directions through a doubly-linked list and only forwards through a singly linked list can help you determine which structure is important when storing data.  You can make an even more education decision by knowing that a singly linked list can potentially have lower overhead in terms of memory consumption (since it doesn't contain pointers to previous elements) so, if you only need to iterate forward through a list, you can save some memory by using an appropriate structure.

These are just small examples and, ultimately, if you're feel you're doing well in your career without intimate knowledge of data structures then maybe you don't need to learn more.  Understanding what's going on under the hood, though, can really help turn functional code into good code.


问:
When would dynamic scoping be useful?
With dynamic scoping, a callee can access the variables of its caller. Pseudo C code:

```<code>void foo()
{
    print(x);
}

void bar()
{
    int x = 42;
    foo();
}
</code>```

Since I have never programmed in a language that supports dynamic scoping, I wonder what some real world use cases for dynamic scoping would be.

答:
(Disclaimer: I've never programmed in a dynamic scoping language)

The scoping is much easier to implement and potentially faster. With dynamic scoping, only the one symbol table is needed (the variables currently available). It just reads from this symbol table for everything.

Imagine in Python the same function.

```<code>def bar():
    x = 42;
    foo(42)

def foo(x):
    print x
</code>```

When I call bar, I put x into the symbol table. When I call foo, I take the symbol table currently used for bar and push it onto the stack. I then call foo, which has x passed to it (likely having been put into the new symbol table on calling the function). After exiting the function, I have to destroy the new scope and restore the old one.

With dynamic scoping, this isn't needed. I only need to know the instruction I need to return to when the function ends since nothing has to be done to the symbol table.

Title: When would dynamic scoping be useful?

Body:
(Disclaimer: I've never programmed in a dynamic scoping language)

The scoping is much easier to implement and potentially faster. With dynamic scoping, only the one symbol table is needed (the variables currently available). It just reads from this symbol table for everything.

Imagine in Python the same function.

def bar():
    x = 42;
    foo(42)

def foo(x):
    print x

When I call bar, I put x into the symbol table. When I call foo, I take the symbol table currently used for bar and push it onto the stack. I then call foo, which has x passed to it (likely having been put into the new symbol table on calling the function). After exiting the function, I have to destroy the new scope and restore the old one.

With dynamic scoping, this isn't needed. I only need to know the instruction I need to return to when the function ends since nothing has to be done to the symbol table.