问:
What naming conventions do you use for php classes?
I really like using ClassNames and memberNames as convention but I am not sure how I would name the file containing a class.

I like making my classes defined in a file with the exact same name as the class. But I also like making php files all lowercase. So I am conflicted.

If I have a class called ProductGroup should that be defined in ProductGroup.php, productgroup.php, or product_group.php?

I know there is no right answer, so I am looking for what is most common or your opinion of which to use.. which do you use?

答: I use a modified version of PEAR Coding Standards. As mentioned before it helps with autoloading, and I find it looks a little cleaner and easier to read IMO. Basically what it comes down to is just decide what works for you and stick to it. As long as all the code looks the same, in the end the rest will fall into place.</p>


问:
Establish/meet deadlines when I am constantly working with unfamiliar platforms and frameworks
I work for a product development organization that is in online advertising. The assignments I receive are almost always on platforms or tools that I have never worked on before. At first it was android. Then node.js, then windows phone, then debian packaging, then python, hadoop, ganglia, reverse engineering, geo PostgreSQL, and the list goes on.

I am happy to be able to learn so much while on the job. The problem I keep running into is meeting deadlines. Often times it is not clear what is needed to be done to accomplish a certain task. I would need to set up the relevant SDK, run intobeginning issues, read online, pore through documentation, research online for every single item of work in that platform. Sometimes I am given deadlines, sometimes I create those deadlines.

I find it very hard to meet deadlines a lot of times. One becomes faster at doing something the second time around but I never work on some language or framework for longer than a week or two. And this is very stressful and painful to deal with. I get all the flak and public shaming that comes with missing deadlines. I suspect this cannot be normal. It cannot be possible to deliver 7 windows aphone apps not knowing a single thing about c# in a week. But I managed to do it one-day after the deadline.  All I have a lot of times is google search to guide me. Often there is little to no documentation on the tool I am customizing.

I sometimes get stuck on something sometimes for hours or even days.  This takes a toll on my health and I am no longer able to burn the midnight oil for every task. This causes a lot of mental anguish and depression.

In this situation, Am I correct in thinking any deadline I provide is a shot in the dark?

Is this normal? Does every single work item for you involve learning something completely new every time? I am not sure if it is fair to say I am a poor performer for not being able to meet deadlines on tasks involving a tool I don't know anything about. How do I handle this?

答:
This kind of work is typical in interactive agencies. An endless stream of unrelated, throwaway projects under impossible deadlines.

Look at this as a potentially useful career stage but be ready to move on before you burn out. You cannot change this business and its needs.

ContentLicense: CC BY-SA 3.0


问:
Modern programming language with intuitive concurrent programming abstractions
I am interested in learning concurrent programming, focusing on the application/user level (not system programming). I am looking for a modern high level programming language that provides intuitive abstractions for writing concurrent applications. I want to focus on languages that increase productivity and hide the complexity of concurrent programming.

To give some examples, I don't consider a good option writing multithreaded code in C, C++, or Java because IMHO my productivity is reduced and their programming model is not intuitive. On the other hand, languages that increase productivity and offer more intuitive abstractions such as Python and the multiprocessing module, Erlang, Clojure, Scala, etc. would be good options.

What would you recommend based on your experience and why?

EDIT: Thanks everybody for your interesting answers. It's hard to make a conclusion without actually trying since there are many good candidates: Erlang, Clojure, Scala, Groovy, and perhaps Haskell. I voted the answer with the most convincing arguments, but I'll try all the good candidates before deciding which one to pick :)

答:
I may get hit over the head for this, but have you read chapter 7 of TAOUP? The section I'm thinking of specifically is threads vs processes. I've found that the concept of concurrent processing makes most people think of threads, yet I've never seen an instance where a thread is easier and faster to use than spawning a child process.

You are farming out all the details of handling concurrency to the smart guys who built your OS. There's already lots of communication methods in place, and you don't have to worry about locking of shared resources. Basically, threads are an efficiency hack, which falls under the rule of optimization. Don't optimize if you haven't tested for necessity.

Find a good subprocess library, such as envoy for python. Or you could just write several separate programs in C, and write another "master" program to use fork and pipe to spawn and communicate with the subprocesses.


问:
Why should we preferably use first class collections?
As per rule number 4 of Object Calisthenics by Jeff Bay (RTF) in The ThoughtWorks Anthology, it is recommended that one should "Use first-class collections".

Rule 4: First class collections

Application of this rule is simple:
any class that contains a collection should contain no other member
variables.   Each collection gets wrapped in its own class, so now
behaviors related to the collection have a home.  You may find that
filters become a part of this new class.   Also, your new class can
handle activities like joining two groups together or applying a rule
to each element of the group.

What I could understand from this was that we should use a separate class wrapping up the collection and with methods to add,delete modify data of that collection.

and We need this so that we are sure of what datatype goes into the collection and what comes out.

In case we use generic collection (in languages where it is applicable), do we need to follow this rule?

If I am missing an important significance, please clarify.

答:
The simple answer is "No" if you are using a language that supports Generics. Because there is no need to check for type as the language feature itself does a pretty good job at this ( From my Java generics experience).

But if You have any situation where you want to customize the data structure given from the language, You can create a wrapper class around the original data structure and expose your own APIs and still use the underlying implementation of the original data structure.


问:
people fork my project but don't fetch from upstream - what can I do?
Several people have forked my github repo but they have not fetched-merged from upstream. So my original repo has evolved significantly since the fork took place, and meanwhile these people are showing an old outdated version of my work, which kind of makes me look bad (e.g. what they're displaying is incomplete, contains bugs that I've fixed since then, etc.).

These people apparently don't understand what a fork is for; they just push the fork button (perhaps as a way of saying "this is cool") and then walk away. Ideally what I'd like is for them either to keep their fork updated from upstream or make a significant contribution or delete the fork. Is there anything I can do about this? (There isn't, is there? This is just the price of being open source, isn't it?)

答:
There is no way to get these forks updated, unless you email each one of the owners and ask them to update.

I don't think you need to be worried about outdated forks, though. Let me explain why.

For some background (though you probably know this), here is how forks accumulate: Whenever I send a pull request to a GitHub project, I first fork it, send the request, and then forget about my fork. I might never use the project sources again, so I don't ever repush to it, unless I send another pull request. As a result I now have something like 50 forks and counting lying around, none of which are up-to-date. I've never bothered to delete any of those, simply because there is no reason to.

Depending on their workflow, some people might fork-then-clone just in case they ever want to send a pull request, which is why it looks like "they just push the fork button".

As a result, all active projects have outdated forks accumulating: If you check the Rails forks, you'll find that pretty much all of them are out of date.

Because of that, when I browse GitHub I assume that other people's forks are generally just throwaway copies, rather than properly maintained projects. So if I see "forked from" at the top, I'll instantly go to the upstream. I don't think I've ever cloned from a fork, unless the upstream explicitly told me that development continues in the fork.

So to summarize: Don't be embarrassed at all those old versions of your software lying around. Nobody uses them anyway. Think of them as a badge of popularity for your project instead. ;-)


答:
... use a separate class wrapping up the collection and with methods to add,delete modify data of that collection

This does much more than guarantee the type of the objects stored in the collections though, it also guarantees any collection invariants.

Trees (red-black, AVL etc.) are sensitive to ordering and their behaviour depends on rebalancing when appropriate.  Hash table performance will also depend on appropriate re-hashing.  Do you want to remember to check the load factor every time you insert into a hash map?

FWIW, the text is quite clear about this (and I'll edit the whole thing into your question, so no-one else needs to download that RTF):

Each collection gets wrapped in its own class, so now behaviors related to the collection have a home

Nothing to do with types (or therefore generics), everything to do with associating the collection's behaviour with it's data.

Title: Why should we preferably use first class collections?

Body:
As per rule number 4 of Object Calisthenics by Jeff Bay (RTF) in The ThoughtWorks Anthology, it is recommended that one should "Use first-class collections".

Rule 4: First class collections

Application of this rule is simple:
any class that contains a collection should contain no other member
variables.   Each collection gets wrapped in its own class, so now
behaviors related to the collection have a home.  You may find that
filters become a part of this new class.   Also, your new class can
handle activities like joining two groups together or applying a rule
to each element of the group.

What I could understand from this was that we should use a separate class wrapping up the collection and with methods to add,delete modify data of that collection.

and We need this so that we are sure of what datatype goes into the collection and what comes out.

In case we use generic collection (in languages where it is applicable), do we need to follow this rule?

If I am missing an important significance, please clarify.


答:
Type safety is a very minor reason to use first-class collections.  From your link:

Rule 4: First class collections
  Application of this rule is simple: any class that contains a collection should contain no other member variables.   Each collection gets wrapped in its own class, so now behaviors related to the collection have a home.  You may find that filters become a part of this new class.   Also, your new class can handle activities like joining two groups together or applying a rule to each element of the group.

The idea here is if you find yourself searching, filtering, validating, or anything beyond add/remove/iterate semantics on a collection, the code is asking you to put it in its own class.  If you need to update just one value (after a search), that probably goes in the collection class.

The reasoning for this is pretty simple, collections tend to get passed around.  Soon enough, 4 different classes have their own SearchByID() method.  Or you get return values like Map<Integer, String> with the context of what's stored in that map stripped away.  A first-class collection is a simple solution that costs a single source file.  In practice, once those are in place (they're very easy to write unit tests for as well), any change dealing with the collection is easy to handle, like when SearchByID needs to take a GUID instead of an int.


问:
How do I review my own code?
I'm working on a project solo and have to maintain my own code. Usually code review is done not by the code author, so the reviewer can look at the code with the fresh eyes — however, I don't have such luxury. What practices can I employ to more effectively review my own code?</p>

答:
I can't tell you the number of times I have been explaining something to a code reviewer and the lightbulb in my head turns on and says, "Hey wait a minute." So I often find my own mistakes in the code review that the other person didn't see.  So you could try that, just start explaining the code as if there was a person sitting next to you who was trying to understand what you did and why.

Another thing that I find frequently in code reviews is that the developer did not actually follow the requirement. So comparing your code and what it does the the actual requirement is a good check.

We frequently do things like SSIS packages that have similar structural needs - for code reviews I developed a checklist of things to check (is the configuration correct, is logging set up, does it use the metadata database, are the files in the standard location, etc.). You might have some things that would be handy to check every time in a code review as well. Sit down and think about what you would put on a checklist of things you want to make sure to check in your code review (First item, make sure the requirement is met, next item might have something to do with trapping and logging errors). As you make mistakes and correct them, you may add other items to the list (say something like, do I move to the next record in a loop or am I going to endlessly repeat the same first item - it only take one endless loop to teach you to look for that!). This is mostly to keep you from forgetting to do some things that should be done.

Title: How do I review my own code?


问:
How do I keep an eye on a remote freelancer?
I've been hiring several developers from different places around the world. It all goes well, but I see that some of them are abusing my polite overlooking too much lately.

They are all hired for a full-day. However, I see that after 5 hours in a day, not much has been done.

I am considering to develop a software that will take a screenshot of the computer screen every 1-5 minutes and upload it to my system. However, this is going to the extremes.

How do people usually manage remote developers?

答:
They either produce enough code for what you are paying or you find someone who can. If they pounded on their keyboards and mice for 10 hours a day and produced garbage, are you still going to keep them just because you're paying them for 8 hours?

Set demands and get agreed upon deadlines. If you can't agree, hire people who will. You're a programmer and should be able to spot if they have hit legitimate obstacles or not.


答:
Start reserving time for estimation. The less familiar you are with a technology, the more time you need in order to produce a good estimate.

Try to get a fixed amount of time to produce something exploratory toward the needs given. You should have a much better idea of what you need to do after that. For instance, one or two weeks to get up to speed on Hadoop is on the low end, but it should be enough to give you more confidence in your estimates.

After that, you just need more estimation skills. Try tracking what you spend your time on. Make sure that always gets into your estimates up front. Track your estimates versus the actual time spent and factor that into future estimates.

And always give yourself a buffer.

Title: Establish/meet deadlines when I am constantly working with unfamiliar platforms and frameworks

Body:
I work for a product development organization that is in online advertising. The assignments I receive are almost always on platforms or tools that I have never worked on before. At first it was android. Then node.js, then windows phone, then debian packaging, then python, hadoop, ganglia, reverse engineering, geo PostgreSQL, and the list goes on.

I am happy to be able to learn so much while on the job. The problem I keep running into is meeting deadlines. Often times it is not clear what is needed to be done to accomplish a certain task. I would need to set up the relevant SDK, run intobeginning issues, read online, pore through documentation, research online for every single item of work in that platform. Sometimes I am given deadlines, sometimes I create those deadlines.

I find it very hard to meet deadlines a lot of times. One becomes faster at doing something the second time around but I never work on some language or framework for longer than a week or two. And this is very stressful and painful to deal with. I get all the flak and public shaming that comes with missing deadlines. I suspect this cannot be normal. It cannot be possible to deliver 7 windows aphone apps not knowing a single thing about c# in a week. But I managed to do it one-day after the deadline.  All I have a lot of times is google search to guide me. Often there is little to no documentation on the tool I am customizing.

I sometimes get stuck on something sometimes for hours or even days.  This takes a toll on my health and I am no longer able to burn the midnight oil for every task. This causes a lot of mental anguish and depression.

In this situation, Am I correct in thinking any deadline I provide is a shot in the dark?

Is this normal? Does every single work item for you involve learning something completely new every time? I am not sure if it is fair to say I am a poor performer for not being able to meet deadlines on tasks involving a tool I don't know anything about. How do I handle this?


问:
Is it reasonable to run processes with CI tools?
At my company, we have a quagmire of disparate cron jobs (on multiple systems) and manually kicked off processes which keep our business functioning that is a result of years of expedient development and subsequent neglect.

Someday, we will need to come up with a more centralized solution for obvious reasons.

One thought that we have been kicking around is to use our Continuous Integration software (Jenkins) to run these processes, which seems logical.

My question is: Are other companies doing this? Is this a generally accepted practice? Doesn't this conflict with the definition of a CI tool implicit in its name? Are there any other options?

Note:
https://wiki.jenkins-ci.org/display/JENKINS/Meet+Jenkins

Jenkins claims that it focuses on "Monitoring executions of externally-run jobs, such as cron jobs and procmail jobs". I'm not sure if this is exactly what I am talking about.

答:
We've been using Jenkins as a cron drop in for a couple years now, and here are some pros and cons:

Pros

If you are managing a large number of processes across dozens of servers and multiple environments, it makes many things easier.  You get email alerts out of the box, a common dashboard for everything, a web interface for logs, and an easy way to setup additional nodes to run jobs on.  Support teams especially appreciate having this central location for checking problems and re-running jobs.

Jenkins plug-in ecosystem is very active and provides a host of additional functionality... I think this is really Jenkins 'killer' feature, since if Jenkins itself doesn't provide what you're looking for (often the case), more often than not there is a plugin that does.  Some of my favorites:  Cron Column, Rebuild, NodeLabel Parameter, Log Parser, and Email-ext.

Advanced scheduling/trigger support:  The schedule syntax basically is cron, so you have the same flexbility there, but this is supplemented by Triggers, the REST API, and the Groovy/Java API

Cons

Central point of failure:  Because all your jobs are kicked off by one server, if that box goes down and nobody notices, Big Trouble.  So you better have good monitoring to catch outages immediately, as well as all your configurations saved in source control.  Even if you can't get the original server back up, as long as you have your job configs it's trivial to get them setup somewhere else.  If time to resolution is a concern, having a standby pre-configured somewhere is probably a good idea as well.

If you have multiple environments (Dev, UAT, Prod), typically you have slightly different versions of a job running on each environment.  Having all these jobs on one Jenkins can become unwieldly, and manually configuring them gets to be a huge pain.  In our case, we run a separate Jenkins 'Cron' instance for each environment.  The instances are installed and configured automatically using an in-house deployment tool.  You may not have something like that, but there are open source tools which do similar things (generate configs using templates).  If you can solve the config generation problem, this makes setting up and deploying Jenkins much easier, and also makes it easier to keep all your stuff in source control.

Upgrading Jenkins sometimes breaks functionality, especially with plugins.  Don't upgrade your mission critical Jenkins instance until you've tried the new version somewhere else first.  This is where having a mirror Dev environment with its own Jenkins instance comes in really handy.

One thing to perhaps emphasize:  We do indeed also use Jenkins for CI, but this is a separate instance... the 'cron' instances are dedicated to job management, and the 'CI' instance is dedicated to CI.  Separating the concerns seems to make things cleaner.

As a side note, I use Jenkins instead of cron on my Linux box at home :)

By the way, this is actually a pretty common Jenkins use case.  For example, Sandia National Lab uses Jenkins this way:
https://software.sandia.gov/trac/fast/wiki/Hudson

And there are numerous blog posts and tutorials describing this.  Here are a couple examples:
http://blog.vuksan.com/2011/08/22/using-jenkins-as-a-cron-server/

http://morgajel.net/2011/12/12/1108

I should also add that this really just pertains to Jenkins, and not all CI tools in general.  Just because Jenkins is well-suited to do this does not mean others (TeamCity, buildbot, etc) are...


问:
Referencing external javascript vs. hosting my own copy
Say I have a web app that uses jQuery.  Is it better practice to host the necessary javascript files on my own servers along with my website files, or to reference them on jQuery's CDN (example: http://code.jquery.com/jquery-1.7.1.min.js)?

I can see pros for both sides:

If it's on my servers, that's one less external dependency; if jQuery went down or changed their hosting structure or something like that, then my app breaks.  But I feel like that won't happen often; there must be lots of small-time sites doing this, and the jQuery team will want to avoid breaking them.

If it's on my servers, that's one less external reference that someone could call a security issue

If it's referenced externally, then I don't have to worry about the bandwidth to serve the files (though I know it's not that much).

If it's referenced externally and I'm deploying this web site to lots of servers that need to have their own copies of all the files, then it's one less file I have to remember to copy/update.

答:
I had the same question, then I read this article and I was sold on the idea of letting Google host my jQuery library.

The article states the main benefits of letting your libraries be hosted by Google's Content Delivery Network (CDN):

Decreased Latency - Users not physically near your server will be able to download jQuery faster from Google than if you force them to download it from your arbitrarily located server.

Increased Parallelism - Browsers limit the number of connections that can be made simultaneously. Depending on which browser, this limit may be as low as two connections per hostname.  Using the Google AJAX Libraries CDN eliminates one request to your site, allowing more of your local content to downloaded in parallel.

Better Caching - Using the Google AJAX Libraries, your users may not need to download jQuery at all.  On the other hand, if you’re hosting jQuery locally then your users must download it at least once. Each of your users probably already has dozens of identical copies of jQuery in their browser’s cache, but those copies of jQuery are ignored when they visit your site.

As for the two bullet points you listed as pros for hosting your own library, remember that it's Google hosting the cloud version, and Google knows what they're doing and can be trusted as far as availability and security go.  However, @zzzzBov makes a very good point in his answer to this question, where he recommends also storing a local copy of the library and defaulting to that in the unlikely event that the CDN version cannot be accessed for any reason.


答:
You should reference it to Google's Library of APIs..

The primary reason for this is to speed up your page loads. If you user has already visited another site referencing the same library it will already be stored in the browsers cache and it will not need to be downloaded at all.

Title: Referencing external javascript vs. hosting my own copy

Body:
Say I have a web app that uses jQuery.  Is it better practice to host the necessary javascript files on my own servers along with my website files, or to reference them on jQuery's CDN (example: http://code.jquery.com/jquery-1.7.1.min.js)?

I can see pros for both sides:

If it's on my servers, that's one less external dependency; if jQuery went down or changed their hosting structure or something like that, then my app breaks.  But I feel like that won't happen often; there must be lots of small-time sites doing this, and the jQuery team will want to avoid breaking them.

If it's on my servers, that's one less external reference that someone could call a security issue

If it's referenced externally, then I don't have to worry about the bandwidth to serve the files (though I know it's not that much).

If it's referenced externally and I'm deploying this web site to lots of servers that need to have their own copies of all the files, then it's one less file I have to remember to copy/update.


问:
Interception vs Injection: a framework architecture decision
There's this framework that I'm helping to design. There are some common tasks that should be done using some common components : Logging, Caching and raising events in particular.

I am not sure if it's better to use dependency injection and introduce all of these components to each service (as properties for example) or should I have some kind of meta data placed over each method of my services and use interception to do these common tasks?

Here's an example of both:

Injection:

```<code>public class MyService
{
    public ILoggingService Logger { get; set; }

    public IEventBroker EventBroker { get; set; }

    public ICacheService Cache { get; set; }

    public void DoSomething()
    {
        Logger.Log(myMessage);
        EventBroker.Publish<EventType>();
        Cache.Add(myObject);
    }
}
</code>```

and here's the other version:

Interception:

```<code>public class MyService
{
    [Log("My message")]
    [PublishEvent(typeof(EventType))]
    public void DoSomething()
    {

    }
}
</code>```

Here are my questions:

Which solution is best for a complicated framework?

If interception wins, what are my options to interact with internal values of a method (to use with cache service for example?)? Can I use other ways rather than attributes to implement this behavior?

Or maybe there can be other solutions to solve the problem?

答:
For a handful of services, I think Mark's answer is good: you won't have to learn or introduce any new 3rd party dependencies and you'll still be following good SOLID principles.

For a large amount of services, I would recommend an AOP tool like PostSharp or Castle DynamicProxy.  PostSharp has a free (as in beer) version, and they just recently released PostSharp Toolkit for Diagnostics, (free as in beer AND speech) which will give you some logging features out of the box.


答:
It is a better practice to use a CDN, and if that CDN happens to be Google, all the better -- as both @CFL_Jeff and @Morons have noted.

I am adding this answer to point out something that often goes overlooked when pointing elsewhere, which is avoiding the mixed content warning.  Consider using protocol-less URLs, e.g.:

```<code><script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js" type="text/javascript">
</script>
</code>```

There are still some support issues in using protocol-less URLs, so also take a gander at the answers on Can I change all my http:// links to just //? on SO, but do at least try to handle potential mixed-content warnings in some way.

Body:
It is a better practice to use a CDN, and if that CDN happens to be Google, all the better -- as both @CFL_Jeff and @Morons have noted.

I am adding this answer to point out something that often goes overlooked when pointing elsewhere, which is avoiding the mixed content warning.  Consider using protocol-less URLs, e.g.:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js" type="text/javascript">
</script>

There are still some support issues in using protocol-less URLs, so also take a gander at the answers on Can I change all my http:// links to just //? on SO, but do at least try to handle potential mixed-content warnings in some way.


答:
Personally, I take a cue from http://html5boilerplate.com/

```<code><script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script>!window.jQuery && document.write(unescape('%3Cscript src="includes/js/libs/jquery-1.6.1.min.js"%3E%3C/script%3E'))</script></code>```

This pulls the main jQuery file from Google, but if it doesn't load for some reason, the next line loads it from your own server.

Body:
Personally, I take a cue from http://html5boilerplate.com/

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script>!window.jQuery && document.write(unescape('%3Cscript src="includes/js/libs/jquery-1.6.1.min.js"%3E%3C/script%3E'))</script>

This pulls the main jQuery file from Google, but if it doesn't load for some reason, the next line loads it from your own server.


问:
What can slow a developer down?
What things tend to slow a developer down?

Please try to refrain from posting answers that:

are slow now but useful in the feature. (TDD, Refactoring, ...)

list a distraction.

答:
Having to wait about 15 minutes for the PC to boot into a usable state

Waiting for the PC to switch applications

Being the only person in the office who has to make his own tea/coffee.

A broken keyboard (fixed!)

Working outside the Managing Director's (US CEO) office (and not in an office, either), with only a partition in between (especially when there is a meeting)

The boss is only reachable by email, but everybody else is in the building

Not being allowed to use a VCS — apparently it should be in my brain

Small screen

Not allowing time for breaks other than lunch

Having to do remote server backups despite having a sysadmin in the building

Being told to do said backups manually.

Being forced to use a stupid time management system that is needlessly complicated

Only just getting a vague idea of the requirements two months into the job

I could go on, but it's Friday and I want to forget about work.

ContentLicense: CC BY-SA 2.5

Title: What can slow a developer down?


答:
You should do both:

Start with hosting from a CDN such as Google's because it will likely have a higher up-time than your own site and will be configured for the fastest response time. Additionally, anyone who has visited a page that links to the CDN will use their cached copy of the file, so they won't even have to re-download a copy, making the initial loading even faster.

Then add a fallback reference to your own server in case the CDN happens to be down (not likely, but safe is safe). Fallbacks are relatively easy to understand, but need to be customized to suit the script being used:

```<code><script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
<script>
    if (!window.jQuery) document.write('<script src="/path/to/jquery-ver.sion.min.js"><\/script>');
</script>
</code>```

Make sure you don't write </script> anywhere within a

Body:
You should do both:

Start with hosting from a CDN such as Google's because it will likely have a higher up-time than your own site and will be configured for the fastest response time. Additionally, anyone who has visited a page that links to the CDN will use their cached copy of the file, so they won't even have to re-download a copy, making the initial loading even faster.

Then add a fallback reference to your own server in case the CDN happens to be down (not likely, but safe is safe). Fallbacks are relatively easy to understand, but need to be customized to suit the script being used:

<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
<script>
    if (!window.jQuery) document.write('<script src="/path/to/jquery-ver.sion.min.js"><\/script>');
</script>

Make sure you don't write </script> anywhere within a <script> element, as it will close the HTML element and cause the script to fail. The simple fix is to use a backslash as an escape: <\/script>.

One more reason to do both:

If you pick a popular CDN it's highly unlikely that it'll ever have any down-time, however in the far far future (~18 months from now given Moore's law) when the hosting format changes, or the address is adjusted, or the network is placed behind a paywall, or anything else, it's possible that your link will no longer work as-is. If you use a fallback, then it'll give you a bit of time to adjust to any new format for hosting before having to go back through every website you've ever created and change the CDN links.

another reason to do both:

Recently I've been hit with a string of internet outages. I was able to keep working locally on projects where I'd linked local copies of script resources, and I quickly found that there were a number of projects that needed to have local copies linked.


答:
Transform this debugging technique to a code review technique: http://en.wikipedia.org/wiki/Rubber_duck_debugging

The concept works wonders for putting you into a proper mindset for working through code as if it were new.

Title: How do I review my own code?

Body: I'm working on a project solo and have to maintain my own code. Usually code review is done not by the code author, so the reviewer can look at the code with the fresh eyes — however, I don't have such luxury. What practices can I employ to more effectively review my own code?</p>


答:
What about source code repositories and you require them constant committing. Small, atomic commits: "commit early, commit often." Utilize DVCS's features (branches, tags) to commit stuff that isn't meant to be included in the final product.

That way you can have pretty good idea what is done, what has to be done and so on.

Title: How do I keep an eye on a remote freelancer?

Body:
I've been hiring several developers from different places around the world. It all goes well, but I see that some of them are abusing my polite overlooking too much lately.

They are all hired for a full-day. However, I see that after 5 hours in a day, not much has been done.

I am considering to develop a software that will take a screenshot of the computer screen every 1-5 minutes and upload it to my system. However, this is going to the extremes.

How do people usually manage remote developers?


答: I have been working with Scrum lately and I can tell you. With this Agile methodology slackers has no room to avoid transparency. And also proves that you are being a good manager/leader dispatching them achievable tasks. </p>


问:
How can I find a good open source project to join?
I just started working a year ago, and I want to join an open source project for the same reasons as anyone else: help create something useful and develop my skills further.

My problem is, I don't know how to find a project where I'll fit in.

How can I find a beginner-friendly project?  What attributes should I be searching for?  What are warning signs that a project might not be the right fit?  Are there any tools out there to help match people with open source projects?

There's a similar question here, but that question has to do with employment and is limited to PHP/Drupal.

答:
There is a new website out there specifically for this called Code 52 that encourages new developers to get involved in open source by starting a new OSS project every week.

The idea is that it will seem a lot less daunting for people who have never been involved in open source before and hopefully will feel more inclined to get involved in other OSS projects as well.


问:
What to look for in an outsourced partner
I'm working in a small startup as the sole developer in my spare time. We might need some more development help and are looking at an Indian company which comes recommended by someone we know (although they are not very technical).

I'll be having an informal chat with them, and thought I'd see if people here had some wisdom regarding what to look for and good questions to ask.

At least I thought I'd try to get some:

Code examples

Info on any policies they might have regarding documentation of code

Some background on the people we will be working with

If you guys can think of anything else I should be particularly on the lookout for, or have any other tips to run the conversation, your input would be much appreciated!

** Update **

To be clear: I have some about what questions to ask a sole developer/freelancer. In this instance I will be talking to a an Indian company offering outsourcing services. I'm curious to know whether there is any particular issues I should be aware of, and if someone with this kind of experience have any hard earned wisdom to share. See MainMa's answer for one such point, although it's not developer-specific.

I see the title of the question has been slightly modified so it no longer correctly conveys what I was trying to ask.. maybe this was the wrong place for this question. :/

答:
I don't think an interview with a developer off-shore must be very different from an interview with, say, a freelance developer from USA. After all, you search for a person with the same profile and the same skills, doing the same tasks.

Still, I noticed personally and often read that Indian developers have a different approach of a relation with a customer. When you ask them to do something which doesn't make any sense or will be overly expensive or has a high risk of breaking something, they will still do it, instead of [politely] explaining to you that you're stupid and don't know what you're really asking.

Since you're a developer, it may not bother you too much. If I were you, I would still talk to them about this point and how they approach it, in other words if they understand that it's better to say "No" to their customer than to implement something substantially broken.

More generally, when you search for a developer, try to determine following things:

Does the person have the right technical skills?

This is done by asking the right questions, and depends a lot of the specific job. It may be something basic, as "What is the difference between stack and queue? Which one do you use to replace a recursion and how?" to something very advanced in a specific language.

Asking to write code is a good idea (see Joel Test), but may be difficult in an interview by phone. You will feel stupid staying at phone waiting for twenty minutes for a person to solve a problem, and it will stress the interviewed person. You also cannot know if the person is actually solving the problem or asking for help on Stack Overflow.

What about communication skills?

Partially you get the idea by talking to the person, but this may be not enough. Often written skill is more important, and you may want to ask if the person has a blog, a high-rep account on Stack Exchange, etc.

Is the candidate THE candidate you want?

This one is the most difficult to answer, and the risk of making a mistake is high (in both ways). Some questions you may ask include:

In C#, do you use StyleCop? Code Analysis? Code Metrics? Can you talk a bit more about it?

What are the five things/features you lack the most in your preferred programming language? How would you implement them?

How much do you spend actually writing code? What do you do the rest of the time?

Do you use Waterfall? Agile? Can you describe how do you use them?

Why QA matters? Have you worked with testers? According to you, what do they do?

If an end user asks you for support with a question you find completely stupid, how do you answer?

Why the question "Which language is better, PHP or Java?" doesn't make sense?

etc.


答: Most off-Shore developers work for massive companies that give you candidates, and these companies vary widely in quality and business practices, some do some very shady things.  Vetting the company is more important than vetting the developer, so check into their track records before even talking about hiring someone.</p>

Title: What to look for in an outsourced partner

Body:
I'm working in a small startup as the sole developer in my spare time. We might need some more development help and are looking at an Indian company which comes recommended by someone we know (although they are not very technical).

I'll be having an informal chat with them, and thought I'd see if people here had some wisdom regarding what to look for and good questions to ask.

At least I thought I'd try to get some:

Code examples

Info on any policies they might have regarding documentation of code

Some background on the people we will be working with

If you guys can think of anything else I should be particularly on the lookout for, or have any other tips to run the conversation, your input would be much appreciated!

** Update **

To be clear: I have some about what questions to ask a sole developer/freelancer. In this instance I will be talking to a an Indian company offering outsourcing services. I'm curious to know whether there is any particular issues I should be aware of, and if someone with this kind of experience have any hard earned wisdom to share. See MainMa's answer for one such point, although it's not developer-specific.

I see the title of the question has been slightly modified so it no longer correctly conveys what I was trying to ask.. maybe this was the wrong place for this question. :/


问:
Please explain the benefit(s) of using an XML-based syntax (e.g. XAML) instead of normal source code (e.g. WinForms)?
First off, please note that this question is not about WPF vs. WinForms.

What are the highest-ranking benefits that led Microsoft to invent XAML in favour of the “old” approach of generating compilable C# code?

My impression is that other developers seem to find a lot of downsides to it, but Microsoft went with it regardless, which must mean that there is a benefit that I am not seeing. I would like you to explain to me what it is that I am missing.

答:
Using XML gives you meta-data in a format that a huge number of parsers and parsing tools support.  At least in theory this allows anyone to meta-program against it using any language.

More practically, XML lets you seem like a more open standard.  You can argue it's just markup like a browser, but easier to parse.

These are real benefits, but in practice there is too much going on outside the XAML for the benefits to be terribly important.


答:
The biggest benefit of XAML is that it allows you to describe your UI in an declarative way. That is, you don't so much say "create a box, now resize it", you say "create a box and btw, it's this size"

The second place where XAML shines is that it really takes advantage of bindings. For instance:

```<code><Button IsEnabled="{Binding IsBusy}">
</code>```

In your view model you can go about your business and set IsBusy to true or false, and as it changes, the Button's enabled state automatically switches back and forth.

So as a more complex example:

```<code><ListBox ItemsSource={Binding Options}>
 <ListBox.ItemsTemplate>
  <CheckBox Checked="{Binding IsChecked}" Contents="{Binding Name}"/>
 </ListBox.ItemsTemplate>
</ListBox>
</code>```

In this example we're binding to a list (Options) and creating an item in a list box for every item. The cool thing here is that as we add items to the list, or remove them the UI is automatically synced to the state of our list. As we click the checkbox on each item, the underlying objects are automatically updated to match the UI. With powerful tools like this I've hacked out UIs in a fraction of the time it would take me to wire up all the events in a WinForms app.

In general this all means that you can write your UI in a declarative format and this is a massive productivity gain. Although, I must mention that this does at a cost. You will probably get more performance out of a WinForms app as the code will be less generalized. But unless you're doing something like showing 40,000 rows in a data grid, you probably won't notice a big slowdown using XAML.

It should also be mentioned that other UI libs accomplish this same goal without XML. For instance, QT uses Json (http://labs.qt.nokia.com/2009/05/13/qt-declarative-ui/)

Title: Please explain the benefit(s) of using an XML-based syntax (e.g. XAML) instead of normal source code (e.g. WinForms)?

Body:
First off, please note that this question is not about WPF vs. WinForms.

What are the highest-ranking benefits that led Microsoft to invent XAML in favour of the “old” approach of generating compilable C# code?

My impression is that other developers seem to find a lot of downsides to it, but Microsoft went with it regardless, which must mean that there is a benefit that I am not seeing. I would like you to explain to me what it is that I am missing.

Body:
The biggest benefit of XAML is that it allows you to describe your UI in an declarative way. That is, you don't so much say "create a box, now resize it", you say "create a box and btw, it's this size"

The second place where XAML shines is that it really takes advantage of bindings. For instance:

<Button IsEnabled="{Binding IsBusy}">

In your view model you can go about your business and set IsBusy to true or false, and as it changes, the Button's enabled state automatically switches back and forth.

So as a more complex example:

<ListBox ItemsSource={Binding Options}>
 <ListBox.ItemsTemplate>
  <CheckBox Checked="{Binding IsChecked}" Contents="{Binding Name}"/>
 </ListBox.ItemsTemplate>
</ListBox>

In this example we're binding to a list (Options) and creating an item in a list box for every item. The cool thing here is that as we add items to the list, or remove them the UI is automatically synced to the state of our list. As we click the checkbox on each item, the underlying objects are automatically updated to match the UI. With powerful tools like this I've hacked out UIs in a fraction of the time it would take me to wire up all the events in a WinForms app.

In general this all means that you can write your UI in a declarative format and this is a massive productivity gain. Although, I must mention that this does at a cost. You will probably get more performance out of a WinForms app as the code will be less generalized. But unless you're doing something like showing 40,000 rows in a data grid, you probably won't notice a big slowdown using XAML.

It should also be mentioned that other UI libs accomplish this same goal without XML. For instance, QT uses Json (http://labs.qt.nokia.com/2009/05/13/qt-declarative-ui/)


答:
A benefit is that the XAML can be used in other applications.  A good example is that the XAML can be developed in Blend by a designer/artist while the internals (code behind) get coded in visual studio.

I beleive it was Microsoft's attempt at separate UI markup versus code behind and to make it possible for the UI to be coded by non-programmers using a tool like Blend.

But, many shops don't have Blend so for many of us it looks like a re-invention of the wheel.

Here's are 8 points bought out by someone closer to the windows client:

8 XAML Benefits


答:
The 8 Benefits of XAML for UI and Beyond

XAML Describes Data in a Concise, but Human and Machine Comprehensible, Way

XAML is Useful for Many Types of Data

XAML uses Typed Object Models for Better Programming and Validation

XAML is Extensible and Version Tolerant

XAML is Toolable

XAML is XML (it benefits from the availability of off-the-shelf tools, it's human-readable, etc.)

XAML Enables Event Driven Programming Models

XAML can be Compiled or Interpreted

I view XAML as an "intermediate language" of UI; you can use it with any programming language, and on different platforms. It enables language, platform and device-independent description of the user interface.


答:
Working extensively with Indian developers, I would give them a sample requirements document and ask them what they think it means. Communications are often the problem. They will want more information in a requirements document than you are likely to give them at first being used to not having to specify everything.  Further, what you think something means is not what they think it means. Better to see if you can communicate with them from the start. </p>

<p>I would also discuss problem resolution with the company and have something in the contract about the code acceptance process. You don't want to spend hundreds of hours and thousands of dollars to get code that is unusable. So you need to consider up front how you will determine if the code is acceptable and what recourse both sides have. I would also want to negotiate for code reviews (including viewing code in progress when the task is large) and daily progress reports. You might also see if they will be willing to work the same hours that you work. Communication is hard when they are half a world away and working while you are sleeping. It builds delay into the project. </p>

Body:
Working extensively with Indian developers, I would give them a sample requirements document and ask them what they think it means. Communications are often the problem. They will want more information in a requirements document than you are likely to give them at first being used to not having to specify everything.  Further, what you think something means is not what they think it means. Better to see if you can communicate with them from the start.

I would also discuss problem resolution with the company and have something in the contract about the code acceptance process. You don't want to spend hundreds of hours and thousands of dollars to get code that is unusable. So you need to consider up front how you will determine if the code is acceptable and what recourse both sides have. I would also want to negotiate for code reviews (including viewing code in progress when the task is large) and daily progress reports. You might also see if they will be willing to work the same hours that you work. Communication is hard when they are half a world away and working while you are sleeping. It builds delay into the project.


问:
What is happening to PHP 6?
I am excited about the changes in PHP 6 previewed in PHP 5.3+. However, I wonder why it takes so long to release PHP 6? Books about it have been published since 2008, and announcements on it since 2007, but I am yet to hear about an alpha or a beta. Why does it take so long to release it? Or is that the way it goes with all languages when they transition to a major release where I guess it takes around 4-5 years to release?</p>

答:
PHP6 Is not something that is really aimed for right now. Originally it was going to be the "namespace/closure/plus some" release. With the release of PHP 5.3 containing most of the cool stuff that was supposed to be in PHP 6, its not really known what the current trunk will be versioned. Its said it "PHP 5.4, PHP 6 or maybe even PHP 7."

Either way the functionality is looking awesome. Things like array dereferencing (example: echo foo()[0]) are already in trunk for everyone to play with. I wouldn't put too much concern on how long the '6' release is taking. 5.3 was released in July of 2009 (which contained most of the functionality that was supposed to be in 6) and they recently released 5.3.3 (July 2010), so it still seems like development is running smoothly.

Title: What is happening to PHP 6?


问:
Which license would I use for my library code?
I have signed a Non-competitive agreement but I would like to be able to reuse some code across all projects that I work on for this company. So, which license can be used for my library code that would basically say the following:

I (the author) can use my library code in any client project.

You cannot use my code in part or in whole in any of your projects.

You may not redistribute or share my code in any way in part or in whole.

答:
I (the author) can use my library code in any client project.

You cannot use my code in part or in whole in any of your projects.

You may not redistribute or share my code in any way in part or in whole.

The tricky part is defining the terms "use," "client," "project," and "redistribute."  It might be worth your while to take this to a lawyer and have him hammer out some legalese.

In practice, you just need a written agreement with the company about what each party can and cannot do, which is basically what you've done in your question. You also can't contravene the non-competitive agreement you already signed, no matter what verbiage you put in the license.


问:
Data structure to use for complex lookups in an event engine?
What would be an optimal way to organize arbitrary data types into a structure that allows for complex (non-index based) lookups into the data without performing full loop-through's?

For a little background, I am not looking for an answer on how to architect an Event engine, rather I am looking for methods to improve a current implementation.

With the 5 second tour, I have a architecture in place with the following components,

Signals - Signals what handles to execute

Handles - Executes when a signal is received

Queue - Manages handles

Engine - Manages the queues and processes signals, new handles etc..

My current implementation has a few pitfalls,

Signals are currently coupled into a Queue, this is done so the engine can identify Queues in storage and the signals they represent.

There are two separate Queue storages, indexed and non-indexed, index exists for lookups on strings/int's, non-index exists for complex signals such as regex, array comparisons etc..

I think that I may have a solution but would like the thoughts of others that have developed similar systems.

With the new architecture I have thought of, it would consist of the following,

Queues would store only a "data" property rather than a signal which, would be would passed to the engine for signal comparisons.

The engine would no longer have non-index and index storage, rather a single storage would be used that would require loop through lookups.

The library is written in PHP (if that matters), if you want to see the source it's at http://www.github.com/nwhitingx/prggmr.

答:
After doing a lot of research regarding this matter a binary search will provide the greatest gain without to much complexity.

The search function itself is oblivious to the actual data to allow for searching of any arbitrary data, given that it has the ability to be sorted and compared.

The code below is my end result, note that this belongs to an SplFixedArray extension.

```<code>public function binsearch($node, $compare)
{
    $low = 0;
    $high = $this->getSize() - 1;

    while ($low <= $high) {
        $mid = ($low + $high) >> 1;
        $nval = $this->offsetGet($mid);
        $cmp = $compare($nval, $node);
        switch (true) {
            case $cmp === true:
                return $mid;
                break;
            case $cmp === 0:
                $low = $mid + 1;
                break;
            case $cmp === 1:
                $high = $mid - 1;
                break;
            default:
                return null;
                break;
        }
    }

    return null;
}
</code>```

Performance Tests using an array with 1,000,000 nodes

```<code>Binary
0.0001220703125
Linear Search
0.0046999454498291
</code>```

Test code

```<code>$array = new FixedArray();
for ($i=0;$i!=1000000;$i++ ){
    $array->push($i);
}
echo "Binary".PHP_EOL;
$t = microtime(true);
$array->binsearch(6570, function($node, $needle){
    if ($node > $needle) {
        return 0;
    }
    if ($node < $needle) {
        return 1;
    }
    if ($node === $needle) {
        return true;
    }
});
echo microtime(true) - $t.PHP_EOL;
echo "Linear Search".PHP_EOL;
while($array->valid()) {
    if ($array->current() == 6570) break;
    $array->next();
}
echo microtime(true) - $t.PHP_EOL;
</code>```

OwnerDisplayName: prggmr

Body:
After doing a lot of research regarding this matter a binary search will provide the greatest gain without to much complexity.

The search function itself is oblivious to the actual data to allow for searching of any arbitrary data, given that it has the ability to be sorted and compared.

The code below is my end result, note that this belongs to an SplFixedArray extension.

public function binsearch($node, $compare)
{
    $low = 0;
    $high = $this->getSize() - 1;

    while ($low <= $high) {
        $mid = ($low + $high) >> 1;
        $nval = $this->offsetGet($mid);
        $cmp = $compare($nval, $node);
        switch (true) {
            case $cmp === true:
                return $mid;
                break;
            case $cmp === 0:
                $low = $mid + 1;
                break;
            case $cmp === 1:
                $high = $mid - 1;
                break;
            default:
                return null;
                break;
        }
    }

    return null;
}

Performance Tests using an array with 1,000,000 nodes

Binary
0.0001220703125
Linear Search
0.0046999454498291

Test code

$array = new FixedArray();
for ($i=0;$i!=1000000;$i++ ){
    $array->push($i);
}
echo "Binary".PHP_EOL;
$t = microtime(true);
$array->binsearch(6570, function($node, $needle){
    if ($node > $needle) {
        return 0;
    }
    if ($node < $needle) {
        return 1;
    }
    if ($node === $needle) {
        return true;
    }
});
echo microtime(true) - $t.PHP_EOL;
echo "Linear Search".PHP_EOL;
while($array->valid()) {
    if ($array->current() == 6570) break;
    $array->next();
}
echo microtime(true) - $t.PHP_EOL;


问:
Changing from VB.NET to C#?
I am working on co-op at a company as a test engineering specialist.  This is not technically a software job, however at the end of the day, I spend most of my time programming.

I am not a programming wiz by any means, but I am very comfortable using VB.NET since that is what projects started at my company previous to my time were written in, and so it is what I have learned and used in the position.

I have gotten the feeling from my time searching for help online when I need it that there is generally more and better support for C# than there is for VB.NET.  This has led me to thinking that it may be beneficial for the company going forward to start programming less in VB.NET and more in C#.

However, almost all projects in my department (since several other people work on small programming projects) are currently written in VB.NET.  Additionally, most of the software design done in our department is relatively simple I would imagine relative to a software focused area of any company. Probably half of it is generating html pages with graphs to visually illustrate certain data.  Taking these two facts into account, there are obvious disadvantages to trying to switch the main programming language used.  Also, the vb.net language is very similar to VBA (for excel) and VBScript, which are also used quite a bit in my area of the company.

I am basically not sure if it would be worth the work to change the main language used since there is not a lot of complicated programming done, and similar languages are necessary anyways it seems.

I was curious what additional insight experienced programmers may be able to offer me regarding changing the main language used in my area from VB.NET to C#?  What benefits or disadvantages are there that I may not have thought of?  How big a role do each advantage and disadvantage play?

What is your overall opinion on the idea of changing from VB.NET to C#?

答:
Speaking broadly, the only reason to switch languages (simplifying the debate a lot), is to improve developer productivity (in the broadest sense).  Whatever you can do in one language, you can usually do in another, and that goes especially for .NET languages.  So you have to weigh the loss of productivity caused by making switch to a language they don't yet know, and also by having mixing different languages into your codebase, against the gain of productivity that the new language offers.

Given all the facts you cited above, there doesn't seem to be a strong case to switch.

On the other hand, as a developer, you can, and should, personally explore new languages (even new flavors of .NET) yourself, so that you are more versatile, and also know what special features one language has to offer over another. So perhaps you do some small projects that don't directly affect anyone else in C#, just to gain the knowledge and experience.

Title: Changing from VB.NET to C#?


答:
C# and VB.NET are very close, and Microsoft intends to make them even closer by trying to implement exactly the same features in both (if it's possible is a different subject).

Do you actually have something which you can't implement because of VB.NET (and which is possible to do in C#)?

Do you actually have something which is a bottleneck because of VB.NET, and will be much faster in C#?

If no, I don't see any reason to rewrite the whole codebase just because you can. Yes, there is a better support for C# from the community, especially on Stack Overflow. But does it matter? Those two languages are close enough to be able to use the answers given for C# in VB.NET in many cases.

Title: Changing from VB.NET to C#?

Body:
I am working on co-op at a company as a test engineering specialist.  This is not technically a software job, however at the end of the day, I spend most of my time programming.

I am not a programming wiz by any means, but I am very comfortable using VB.NET since that is what projects started at my company previous to my time were written in, and so it is what I have learned and used in the position.

I have gotten the feeling from my time searching for help online when I need it that there is generally more and better support for C# than there is for VB.NET.  This has led me to thinking that it may be beneficial for the company going forward to start programming less in VB.NET and more in C#.

However, almost all projects in my department (since several other people work on small programming projects) are currently written in VB.NET.  Additionally, most of the software design done in our department is relatively simple I would imagine relative to a software focused area of any company. Probably half of it is generating html pages with graphs to visually illustrate certain data.  Taking these two facts into account, there are obvious disadvantages to trying to switch the main programming language used.  Also, the vb.net language is very similar to VBA (for excel) and VBScript, which are also used quite a bit in my area of the company.

I am basically not sure if it would be worth the work to change the main language used since there is not a lot of complicated programming done, and similar languages are necessary anyways it seems.

I was curious what additional insight experienced programmers may be able to offer me regarding changing the main language used in my area from VB.NET to C#?  What benefits or disadvantages are there that I may not have thought of?  How big a role do each advantage and disadvantage play?

What is your overall opinion on the idea of changing from VB.NET to C#?


答:
XAML was designed to simply represent a hierarchy of objects and not only for GUI such as XPS and WF. Using XAML to build applications would help you deliver Rich Internet Applications (RIA) as well as rich desktop applications.

The use of XAML as a text based declarative representation of GUI brings the MS development tools a step closer to other technologies considered as standard in the industry such as HTML.

Some of the main features of XAML (over Windows Forms) are:

XAML allows for drawing Scalable Vector Graphics (SVG) Images and transformations. One of the benefits of vector graphics is that they can scale to any size without losing quality so you don't worry much about the resolution of the user's computer.

Windows forms, in general, suffered from limited support for automatic placement of controls as a result of windows re-size and changes in the GUI surface (as when new controls are added or removed). Controls are positioned by explicit specification of row and column values for each control through the GUI or program code. While XAML allows for this behavior, it introduces a more easy way to solve this problem by providing he Stack Control control and the Wrap Panel controls.

In XAML you can construct new controls from existing ones directly in the XAML using nesting. You can nest an image control within the button control together with a Stack Panel to create a new type of button, that is, a button with a picture. Since this control is created in XAML, you don't need to create a separate dll to use it like as the case is in Windows forms. Example:

```<code><Button Width="90" Height="40">
    <StackPanel Orientation="Horizontal">
      <Image Source="Yes.png" Width="14" Height="14" />
      <TextBlock Margin="5,1,0,0" Text="Yes" />
    </StackPanel>
</code>```

Styling and templates allows you to customize the looks of controls on several levels similar to the capabilities of CSS and HTML. No procedural programming required. One change can be reflected on the entire GUI.

XAML allows advanced data binding techniques not available in Windows forms. You can even bind one control to anther's data value(s).

XAML provides a built in Navigation framework that you can use or replace with other frameworks. In fact WPF, Silverlight and XAML are designed to take advantage of MVVM pattern that you can't exactly achieve with Windows Forms.

With the introduction of XAML, the code behind files could be isolated to a greater degeree from the interface design files. Of course the dependency of some names still exist. However, the fact that XAML is text based declarative language similar to XML and HTML that does not require a compiler, allows interface designers to create separate XAML files to be later integrated with the code behind files. This is unlike the case with windows forms where the GUI is tightly coupled as procedural code in the project. Designers using XAML could even leave Visual Studio and use the MS Expression Blend tool to create their GUI. MS Expression Blend is created for designers rather than programmers.

XAML provides advanced native techniques for animation and video display without the need for 3rd party tools.

XAML was intended to make the development of Windows-Based software and Web Pages more close than it was using ASP.NET nad Windows Forms. Silverlight and WPF both use XAML (although there are some differences, but large part of the experience is transferable).

An SDK for XAML includes interesting controls and it allows you, among other features, to support wizards/storyboard style presentation without using a 3rd party tool.

Body:
XAML was designed to simply represent a hierarchy of objects and not only for GUI such as XPS and WF. Using XAML to build applications would help you deliver Rich Internet Applications (RIA) as well as rich desktop applications.

The use of XAML as a text based declarative representation of GUI brings the MS development tools a step closer to other technologies considered as standard in the industry such as HTML.

Some of the main features of XAML (over Windows Forms) are:

XAML allows for drawing Scalable Vector Graphics (SVG) Images and transformations. One of the benefits of vector graphics is that they can scale to any size without losing quality so you don't worry much about the resolution of the user's computer.

Windows forms, in general, suffered from limited support for automatic placement of controls as a result of windows re-size and changes in the GUI surface (as when new controls are added or removed). Controls are positioned by explicit specification of row and column values for each control through the GUI or program code. While XAML allows for this behavior, it introduces a more easy way to solve this problem by providing he Stack Control control and the Wrap Panel controls.

In XAML you can construct new controls from existing ones directly in the XAML using nesting. You can nest an image control within the button control together with a Stack Panel to create a new type of button, that is, a button with a picture. Since this control is created in XAML, you don't need to create a separate dll to use it like as the case is in Windows forms. Example:

<Button Width="90" Height="40">
    <StackPanel Orientation="Horizontal">
      <Image Source="Yes.png" Width="14" Height="14" />
      <TextBlock Margin="5,1,0,0" Text="Yes" />
    </StackPanel>

Styling and templates allows you to customize the looks of controls on several levels similar to the capabilities of CSS and HTML. No procedural programming required. One change can be reflected on the entire GUI.

XAML allows advanced data binding techniques not available in Windows forms. You can even bind one control to anther's data value(s).

XAML provides a built in Navigation framework that you can use or replace with other frameworks. In fact WPF, Silverlight and XAML are designed to take advantage of MVVM pattern that you can't exactly achieve with Windows Forms.

With the introduction of XAML, the code behind files could be isolated to a greater degeree from the interface design files. Of course the dependency of some names still exist. However, the fact that XAML is text based declarative language similar to XML and HTML that does not require a compiler, allows interface designers to create separate XAML files to be later integrated with the code behind files. This is unlike the case with windows forms where the GUI is tightly coupled as procedural code in the project. Designers using XAML could even leave Visual Studio and use the MS Expression Blend tool to create their GUI. MS Expression Blend is created for designers rather than programmers.

XAML provides advanced native techniques for animation and video display without the need for 3rd party tools.

XAML was intended to make the development of Windows-Based software and Web Pages more close than it was using ASP.NET nad Windows Forms. Silverlight and WPF both use XAML (although there are some differences, but large part of the experience is transferable).

An SDK for XAML includes interesting controls and it allows you, among other features, to support wizards/storyboard style presentation without using a 3rd party tool.


答:
Assuming you are a consultant to this company, you want to sell them a non-exclusive license.  To your plain-English description, I would explicitly add that you require the company to contract individually for any further projects using your library.  Of course, I Am Not A Lawyer (IANAL); you should consult a real one if you are going to write your own contract, especially since your actual laws may vary...

If you are an employee for this company, rather than a contractor, be aware that code written as an employee is usually, by default, work made for hire, which means the company owns it from the get go.  If I were working in any environment that even vaguely resembled employment, I would be inclined to a very careful, explicit, and particular written contract, to ensure that the company did not appropriate my library altogether.  But, again, IANAL.

Additionally:  at least as important as getting the contract right is making sure the people at the company you are contracting with have the same understanding about what they're buying as you do.

The contract is insurance against lawsuits, but mutual understanding is what should make a lawsuit less likely.  After all, your question indicates that you expect repeat business...

Title: Which license would I use for my library code?

Body:
I have signed a Non-competitive agreement but I would like to be able to reuse some code across all projects that I work on for this company. So, which license can be used for my library code that would basically say the following:

I (the author) can use my library code in any client project.

You cannot use my code in part or in whole in any of your projects.

You may not redistribute or share my code in any way in part or in whole.


问:
Reference public exposed property or private field in other parts of a class

Possible Duplicate:

  Private variable vs property?

I have a public property with a get and set accessor.  Associated with this property is a private field.

Is it best practice when referencing these values in other parts of a classes code to use the private field or the public exposed property.  Although I release I have made a private bool personFieldSpecified field when I probably didn't need to I did this to better explain my question.

```<code>        private SimplePerson personField;
        private bool personFieldSpecified;

        public SimplePerson Person
        {
            get
            {
                if (personField == null)
                    personField = new SimplePerson();

                return personField;
            }

            set
            {
                personField = value;

                // Q)  Should I access the public property here or the private field
                PersonSpecified = true;
            }
        }

        public bool PersonSpecified
        {
            get
            {
                return personFieldSpecified;
            }

            set
            {
                personFieldSpecified = value;
            }
        }
</code>```

Because I'm aware of the inner implementation of the set I know that it will effect the end result if I set either, however I am wondering which is the better practice to do for long term maintainability.  This could apply to methods of my class as well!

What would be the reasons for choosing one particular method over the other.  Does it depend on what the property itself is doing in which case I have to have knowledge of it's inner workings or does it come down to design?

答:
If a property exists for a field, I would recommend always using it to access the property even within the class. This will help prevent you introducing bugs in future if you do add other logic in the property getter or setter which you would then bypass if you directly accessed the field.

The rule I follow is if a property exists for a field, only access the field from the class construtor or the property. I'd even go so far as to add a private setter to ensure that any 'set' logic is still encapsulated against further change.

The only time to go against this is if you have a field which is not exposed outside the class (e.g. a bool field to determine whether the class has been disposed).


问:
Should you sacrifice code readability with how efficient code is?
Should you sacrifice code readability with how efficient code is?

e.g. 3 lines of code into 1 line.

I read in Code Craft by Pete Goodliffe that readability is key.

Your thoughts?

答:
Readability is an excuse for incompetent & lazy programmers (actually the same applies for "simplicity" when used as an argument to defend a crappy algorithm/design)!

For every given problem you should strive for the optimal solution! The fact that computers today are fast is not excuse to waste CPU cycles. The only constraint should be "time to deliver". Note that "optimal solution" here means the one YOU can come up with (we cannot all come up with the best solution; or have the skill/knowledge to implement them).

As someone else mentioned if there are "difficult to understand" aspects of a solution, that is what comments are for. The order "correct, readable, fast" (or something like that), which someone else mentioned is just waste of time.

I have a really hard time to believe that there are programmers out there, which when presented with a problem they think in the lines "...this must be done like this but I will make that way which is less efficient but more readable/maintainable and other such crap...". The fallacy of this is, that the next developer (seeing the inefficiencies) will most probably modify the code and the next will do the same and so on... The end result is that after a few versions the code will become what the original developer should have written in the 1st place. The only excuse for the original developer is a. he/she did not think of it (fair enough) and (as mentioned before) b. time & resource constraints.


答:
The grass is always greener......

there's no point to do this change, sure you'll be one of the cool kids, but really its not going to be much different... except you'll miss the XML Literals that you can put in VB.NET, and the syntax that'll just help to confuse you as you keep switching from VB to C# when you come to maintain old and new code.

No, its a bit pointless. Now if you were to rewrite in C++ or Python, then that'd be a different matter as these systems are very different and have different strengths.

Title: Changing from VB.NET to C#?


问:
How can I advocate a semi-strict release schedule in a risk-averse environment?
Recently I've been increasingly plagued by what I would have to describe as one of my most frustrating and morale-killing experiences in this profession: Having to sit on a release that has been tested, re-tested, staged, and for all intents and purposes is ready to ship/deploy.

As an all-around solutions guy and not just a hardcore coder, I do understand and have even advocated the need for proper change control. But lately, the tenuous balance between covering our bases and shipping on time has gone all lopsided, and I've had little to no success in restoring it to something sane.

I'm looking for compelling arguments to help convince risk-averse management that:

The dev team should (or must) be able to set its own release schedule - within reason of course (1-3 months should be conservative enough for all but the biggest Fortune 500 companies);

Software releases are important milestones and should not be treated cavalierly; in other words, unnecessary delays/stoppages are highly disruptive and should be considered only as a last resort to some critical business issue; and

External (non-dev/non-IT) entities who want (or demand) to be involved as stakeholders have a responsibility to cooperate with the dev team in order to meet the release schedule, especially in the last week or so before the planned ship date (i.e. user testing/staging).

The above are assertions that ring true for me based on experience, but it looks like I'm now in the position of having to prove it - so I'm asking for something a little meatier here, if such a thing exists.

Can anyone who has had to "sell" the idea of a fixed (or maybe semi-flexible) release cycle to management give some pointers on what arguments/strategies are effective or persuasive and what is not? Aside from the obvious schedule contention and sunk costs, is there any hard data/evidence that would be useful in making the case that shipping is actually important, even in a "corporate" setting?

Alternatively, I'm open to hearing constructive arguments about why schedule flexibility (even over a period of weeks/months) is more important than shipping on schedule; it's hard for me to believe right now but maybe they know something I don't.

Note we have staged releases, and this went through every stage except production. Issues are tracked using a commercial bug tracker and every issue - 100% of them - that was assigned to this release was closed out. I realize it's difficult to believe and that's really precisely the point - it makes no sense that a 100%, feature-complete, fully-tested, approved-by-stakeholders release would be delayed by management for unexplained reasons, but that's what happened, that's what's been happening, that's the problem to be solved.

答:
I'd say the easiest / most effective way to sell a release is to down tools for a while when its ready to go. Do something else, start a new project, work on bugs for the existing project. Do not do any more to this one until its sent out the door - after all, why bother doing it at all if it doesn't go when its ready.

but in the real world, the actual release is someone else's problem, you should be shipping it to them and then treating that as a release. Once its out of your door, its shipped. If they just sit on it, it's not your problem (in fact, its great, no bugs get reported on it! w00t! Bonuses for a bug-free release all round ;) )

So you need a change control system in  place anyway, and a release manager. Then it's all easy (except you do need to manage the change control, so source control plus deployment builds are very necessary. It requires organisation, but if you're organised, its easy).


答: The Company I work for did make this switch, but only for new projects. After going through the transition I agree with the previous posters that between VB.Net and C# the change will initially cause some slowdown as programmers get used to the new language, but in the end the feature differences are minor. (This is because all .Net languages are first translated to CIL, a common language, before being compiled). In the end, the decision was because our programmers were more comfortable in C# rather than VB.Net. Having trained in C# in my college days, and immediately switched to VB.Net when I was hired (this was 3 years ago). I can tell you that the difficulty in the transition is more syntax than features. Very rarely have I ever come across something I was attempting in one language that I couldn't just check the docs to find out how to do in the other. (For Example MSDN Language Equivalents ). One serious benefit is after the change we've now doubled our resources as we can look for examples and explanations online for both c# and vb.net, this has cut down on time being "stuck." </p>

Title: Changing from VB.NET to C#?


问:
Automated out going ACH transfers
Our team is working on a market place web application where the application will collect payments from individual users then deduct a small percentage fee before paying the balance to the users chosen service vendor. We've encountered problems finding a service provider that will allow outgoing ACH. We've asked both several merchant accounts and banks looking for a solution. Although out going ACH is possible through some banks, we are so far unable to find a bank that exposes an API for automating the process.

We're hoping the community has found a viable solution for the redistribution of funds as described. We're certainly not stuck on any particular technology or method such as ACH.

Your thoughts, idea or solutions are greatly appreciated.

答:
So this is what I would do in this situation: Write your own API based on one of the web forms  and use that as your own API.

I am working on an application at work that so we can accept post-dated credit card charges and the gateway we use only has a single web form that is POST'ed to the server. So, to get the automation we need, I just wrote a wrapper so that I can call the POST from my code using the proper parameters and go from there. From the code's point of view, it is a normal API/library. From the business' point of view, I got the job done and it works. In your case, you may be able to save some money on 3rd party charges if you can do it this way.

Title: Automated out going ACH transfers


答:
I can't imagine that putting the Dev team in charge of the business the way you describe is a "good thing"  It might mask the real problem, but unless the Dev team is in the right position to weigh the inputs from sales, marketing, etc. etc. you risk releasing for the wrong (and potentially bad) reasons.

If I understand your problem- you have completed the project and have a deliverable you can't show to anyone outside of your company. (I hope this summarizes it, I read the whole thread and I'm having trouble putting my finger on it)

Have you tried:

Ask management for a customer or set of customers to act as stakeholders during development?  Usually you can find one customer to take intermediate releases and give feedback.  They can be great advocates when it is time to release.  Even a "limited release" to one customer might be enough to help sway management

Building a release plan including point releases.  That is, you can release 3.4 today because the 3.4.1 release is planned for today + 1 month.  This along with the good idea you already mentioned that a release cadence helps this message.

Get support, sales, or marketing on your side.  Build in fixes that would solve the top 3 support requests and you can get an ally from another department.  If you can't get a customer stakeholder as in #1, try it with a few sales people.  Offer to be available for sales meetings and bring along the product.  When you are on the road, show the sales guy you are with the product (in whatever state it is in)  get them pulling for you.

To answer your other question about "why would management sit on a release?"  Companies do this all the time in non SW fields and I don't think it is unprecedented.  For example, you have a new release that is ready to go, all tested and done.  But the old version hasn't been displaced by the competition yet.  Once the competition releases a competing product you the old version, management releases the version waiting on the shelf and disrupts the market, sets back the competition and maintains sales and the reputation as a market leader.  Releasing too soon tips their hand to competitors who might have a better idea of your roadmap and try to beat you to the endgame.

With all that said... Hanlon's Razor is probably the right answer :-)

Title: How can I advocate a semi-strict release schedule in a risk-averse environment?

Body:
Recently I've been increasingly plagued by what I would have to describe as one of my most frustrating and morale-killing experiences in this profession: Having to sit on a release that has been tested, re-tested, staged, and for all intents and purposes is ready to ship/deploy.

As an all-around solutions guy and not just a hardcore coder, I do understand and have even advocated the need for proper change control. But lately, the tenuous balance between covering our bases and shipping on time has gone all lopsided, and I've had little to no success in restoring it to something sane.

I'm looking for compelling arguments to help convince risk-averse management that:

The dev team should (or must) be able to set its own release schedule - within reason of course (1-3 months should be conservative enough for all but the biggest Fortune 500 companies);

Software releases are important milestones and should not be treated cavalierly; in other words, unnecessary delays/stoppages are highly disruptive and should be considered only as a last resort to some critical business issue; and

External (non-dev/non-IT) entities who want (or demand) to be involved as stakeholders have a responsibility to cooperate with the dev team in order to meet the release schedule, especially in the last week or so before the planned ship date (i.e. user testing/staging).

The above are assertions that ring true for me based on experience, but it looks like I'm now in the position of having to prove it - so I'm asking for something a little meatier here, if such a thing exists.

Can anyone who has had to "sell" the idea of a fixed (or maybe semi-flexible) release cycle to management give some pointers on what arguments/strategies are effective or persuasive and what is not? Aside from the obvious schedule contention and sunk costs, is there any hard data/evidence that would be useful in making the case that shipping is actually important, even in a "corporate" setting?

Alternatively, I'm open to hearing constructive arguments about why schedule flexibility (even over a period of weeks/months) is more important than shipping on schedule; it's hard for me to believe right now but maybe they know something I don't.

Note we have staged releases, and this went through every stage except production. Issues are tracked using a commercial bug tracker and every issue - 100% of them - that was assigned to this release was closed out. I realize it's difficult to believe and that's really precisely the point - it makes no sense that a 100%, feature-complete, fully-tested, approved-by-stakeholders release would be delayed by management for unexplained reasons, but that's what happened, that's what's been happening, that's the problem to be solved.


问:
How do programmers quit a job?
I'm thinking about leaving my current employer and wondering how one goes about that process in the programming world. We have a lot of projects on the go at the moment and I'm the only developer. We have 4-5 projects that are fairly big and need to be done in the next few months and even a few longer than that.

I'm leaving because I'm the only employee and that's doing me no good. I'm young and want to learn, so a team would be nice. It's also too much work and the company is managed horribly.

I have no contract to worry about so I could theoretically quit and just not come back without notice. Just wondering how this is normally handled.

Should I write a resignation letter

How much notice should I give

Should I give a reason for leaving

Should I go to my boss who is the main reason I'm leaving or go to his boss?

Overview of replies

From the feedback here, it looks as though it's best to give 2-4 weeks of notice, and present a written resignation. Don't go into detail explaining why you're leaving in most cases. Don't burn bridges. Be professional.

答:
I'm not sure there's any right way or wrong way to leave a position but I'm a strong believer of what you said about not burning bridges.  A very similar situation happened to a friend of a mine, when he left his company he was honest and upfront with the employer; gave his two weeks notice in person.  The company needed him more then they knew so they ended up contracting through him and his newly started company.  The compensation he currently receives is an order of magnitude larger than what his salary was when he worked for the company.

Just be honest, confident and polite. Good things will happen, if not you're young you'll be fine.

Title: How do programmers quit a job?


答:
There is a big question mark hanging over your question, and that is why your company doesn't wish to release the software.  It's not always just a simple case of risk aversion.  Often there are other causes underlying which don't often get passed down from the lofty managerial heights. So my question to you is, "Have you sat down with your boss and asked him why the product release is being held up?".

There is a big difference between managing risk, and avoiding it. There may be legal or marketing reasons for delaying a product release.  It could be trust issues between management and the development team.  The product may not suit the needs of the customer, even if it is exactly what the customer asked for months ago.  It could even be a case of someone in management seriously covering-ass while trying to shift the blame for delay elsewhere, or even a delay by a third party that is required to complete something before your product ships. I could come up with dozens of scenarios. Quite often the developer assumes risk aversion without understanding the other side of the equation that hasn't been made apparent. On the flip side, it may simply be complacency, conflict between individuals within a company, or even a fear that the product will fail in the market for some reason which results in seemingly ridiculous delays.

In all cases, it's important to have more information about the reasons for delays in product release, and to use that information to build a case for releasing your product as soon as you can.  Yes, it can be very frustrating, but there are other ways to deal with these situations without risking either confrontation with your bosses, or a burnout.  In similar situations, I myself have gathered information, documented whatever progress I've made, and then if worse came to worse, simply shelved the project and moved onto something else. Where I have been able to get a project back on track for release has usually been the result of making a sound business case based on the information I have received as feedback to the questions that I have raised. Where I have been unable to convince the management that the product should be shipped, I have documented the reluctance to ship as simply being a case of project finished, and awaiting release approval by management.  I then make sure that my manager signs my document as accepted and understood by management so that my own butt is covered if they should attempt to blame me later for a non-release.

You always need to dot your I's and cross T's to avoid shipping delays being later blamed on you (no matter how unfairly), and also it's important to avoid becoming too emotionally bound to such issues unless you like the idea of a well earned ulcer. By looking at your own situation with a certain professional detachment, you may find a solution presents itself because you have effectively placed yourself at a greater "distance" as it were from the problem.  If you can't make your case, you may need to let it slide for a while, but in order to make your case in the first place, you need to seem professionally detached, and have arguments based on information that is intimately connected to your company and its inner workings.

Something else that I've just thought about which might be of some help to you, is to perhaps read Lean Software Development, and see if there is anything valuable in there that might relate to your company's situation, particularly in the first few chapters. I think it was chapter 4 that discusses the issue of delivering as quickly as you can and has something relating to delay costs.


问:
How do I keep an eye on a remote freelancer?
I've been hiring several developers from different places around the world. It all goes well, but I see that some of them are abusing my polite overlooking too much lately.

They are all hired for a full-day. However, I see that after 5 hours in a day, not much has been done.

I am considering to develop a software that will take a screenshot of the computer screen every 1-5 minutes and upload it to my system. However, this is going to the extremes.

How do people usually manage remote developers?

答:
Do your homework first

You need to be comfortable with the people you are hiring, before you hire them.

At the point you are thinking of essentially spying on the people you hire, it is too late.  I am an honest programmer, but I wouldn't work under those conditions (even assuming that they are legal).  It's like when you cross the border - you might not be hiding anything, but they sure make you feel like you are.

Do background checks, get references, ask questions.  Use reputable services.  Make careful decisions, and then follow the advice in the other answers given here.


答:
Are you paying for results or time?  If you're paying for results, then it's none of your business how long they take to achieve those results.  If you're paying for time and you don't think they are being honest about their time, let them go and find someone else-if you can't trust them, what good are they?

If you provide the environment, recording is an option, but you'll need to inform them first, which will give them the ability to fake it.  How long does it take them to search for the answer to a problem?  Reading offline resources, simply sitting and thinking?  If they aren't honest, all you're going to do is spend a lot of your time getting inconclusive results. If they are honest, you're probably going to offend them and they'll move on.  Either way, they are gone.


问:
How do I review my own code?
I'm working on a project solo and have to maintain my own code. Usually code review is done not by the code author, so the reviewer can look at the code with the fresh eyes — however, I don't have such luxury. What practices can I employ to more effectively review my own code?</p>

答: Apart from all the recommendations for code review, you can use the tools like PMD and findBug to do first level of sanity for your code.</p>

Title: How do I review my own code?