问:
iOS Resources/Luminaries?
In the .NET world, I was able to find several industry figures or luminaries' blogs to read or to follow on twitter to learn about features and trends.  Moving into the iOS realm, I'm kind of surprised how difficult it has been to find analogous resources.

What resources should I be reading/following/osmosing to get better integrated into the iOS community?

答:
Start at http://planetcocoa.org/, which aggregates quite a few Objective-C, Cocoa, and Cocoa Touch-related blogs.

Other good resources are:

Mike Ash's blog

Dave DeLong's blog

Ridiculous Fish

Marcus Zarra's depressingly-titled Cocoa Is My Girlfriend

Occasionally, Wil Shipley's blog

Uli Kusterer's blog

Wolf Rentzsch's blog

There are about a million iPhone-related blogs, tutorials, etc. Don't believe everything you read, though -- there's a lot of lousy advice out there, and a lot more that's just a rehash of Apple's documentation, which is a better source in most cases. Everyone I linked above has significant credentials and something interesting to say beyond what's in the manual.

Of course, you could always just start reading the ios, iphone, cocoa, cocoa-touch, and objective-c tags here and (better) on StackOverflow. And, of course, Apple has its own developer forums.

Title: iOS Resources/Luminaries?


问:
XML or HTML for User Manual/Help and Why?
I want to make User Manual/Help to my program. I found two good ways - XML or HTML - which should I use and why?

I know how to do it in html (I know how to use js, css and such) but in XML it's harder (or I imagine?)

anyway which way should I choose and why?...

Edit:

There's one important thing I forgot to mention: I need it for the army, I can make it only on army's computer and I cannot install anything you said. I can use notepad and that's it.

答: I'm going to suggest using Markdown because you can write simple text and have it converted to HTML for you. You can use WriteMonkey to write text using Markdown syntax and export it to HTML. For simple documentation, this may be all you need.</p>

ContentLicense: CC BY-SA 3.0


答:
If you like XML then use Docbook then you can generate, HTML, PDF, CHM or whatever from it.

Other alternatives to XML that are easy to generate various outputs are Markdown, Textile and other Wiki-like syntax driven markup languages.

You should really focus on something that can target mutliple formats for final output such as ePub as well.

Title: XML or HTML for User Manual/Help and Why?

Body:
I want to make User Manual/Help to my program. I found two good ways - XML or HTML - which should I use and why?

I know how to do it in html (I know how to use js, css and such) but in XML it's harder (or I imagine?)

anyway which way should I choose and why?...

Edit:

There's one important thing I forgot to mention: I need it for the army, I can make it only on army's computer and I cannot install anything you said. I can use notepad and that's it.


问:
How can I improve my error checking and handling?
Lately I have been struggling to understand what the right amount of checking is and what the proper methods are.

I have a few questions regarding this:

What is the proper way to check for errors (bad input, bad states, etc)? Is it better to explicitly check for errors, or use functions like asserts which can be optimized out of your final code? I feel like explicitly checking clutters a program with a lot of extra code which shouldn't be executed in most situations anyway-- and not to mention most errors end up with an abort/exit failure. Why clutter a function with explicit checks just to abort? I have looked for asserts versus explicit checking of errors and found little to truly explain when to do either.

Most say 'use asserts to check for logic errors and use explicit checks to check for other failures.' This doesn't seem to get us very far though. Would we say this is feasible:

```<code>Malloc returning null, check explictly
API user inserting odd input for functions, use asserts
</code>```

Would this make me any better at error checking? What else can I do? I really want to improve and write better, 'professional' code.

答:
Do check anything at any time (it could have changed after your last check) that is not 100% under your command. And also: During developement even do not trust yourself! ;-)

Okokok ... "anything" is meant to be read as checking for such things which would cause an abnormal abort or anything which could make your application/system do things it should not do.

To be serious, the last part of the last sentence is essential because it points to the main issue:

If you want to build a stable system the main concern it not about what the system should do, but to let it be able to do such mandatory things, one needs to take care of what it should not do, even if it "clutters your code".

OwnerDisplayName: Google


问:
Delegation and MetaClass in C++
We have an OOP course at our university, while discussing the concepts I came across MetaClass and Delegation. As far as I know, these don't exist in C++.

Could someone give an example by which I can better understand how to simulate them instead.

答:
Delegation can be achieved in C++ by using functors (made even more simple to declare in C++11 with lambdas). Any type can define a call operator member function, so you could say that C++ does have Delegation, just not in an easy syntax, but fixed with lambdas.

To be more precise (see comments), lambda don't act as delegate, functors - that are simply objects you can call like function and therefore move around until you need to call them - act as delegates. Lambdas expressions are just syntactic sugar allowing to define "in place" a functor directly in the code that will use it. Look in the wikipedia page for lambda for an introduction, it's the same as in C# or Python but a bit more powerful because you can put more than one-liners in.

MetaClass is harder but not impossible : look for reflection libraries for similar features. However, it's very rare that such features are really useful in C++ as you can read there the reasons. Most of the time, RTTI is enough.

Title: Delegation and MetaClass in C++


答: The easiest way for me to tell the difference is to determine whether the error condition is introduced at compile time or run time.  If the problem is a programmer using the function wrong somehow, make it an assert to draw attention to the problem, but once the fix is compiled into the calling code, you don't need to worry about checking for it any more.  Problems like running out of memory or bad end user input can't be solved at compile time, so you leave the checks in.</p>

Title: How can I improve my error checking and handling?

Body:
Lately I have been struggling to understand what the right amount of checking is and what the proper methods are.

I have a few questions regarding this:

What is the proper way to check for errors (bad input, bad states, etc)? Is it better to explicitly check for errors, or use functions like asserts which can be optimized out of your final code? I feel like explicitly checking clutters a program with a lot of extra code which shouldn't be executed in most situations anyway-- and not to mention most errors end up with an abort/exit failure. Why clutter a function with explicit checks just to abort? I have looked for asserts versus explicit checking of errors and found little to truly explain when to do either.

Most say 'use asserts to check for logic errors and use explicit checks to check for other failures.' This doesn't seem to get us very far though. Would we say this is feasible:

```<code>Malloc returning null, check explictly
API user inserting odd input for functions, use asserts
</code>```

Would this make me any better at error checking? What else can I do? I really want to improve and write better, 'professional' code.


问:
Implementing Asynchronous Insert / Update for a web application
I am in the process of implementing a small web application using memcached for caching objects and sql server for database persistence.

In all the projects I have done before I have done inserts/updates in the web thread itself. In this project I want to implement asynchronous inserts and updates. I will use memcached http://en.wikipedia.org/wiki/Memcached to capture changes and an external service (windows service) to persist the changes in db.

I understand premature performance tuning is evil but this is just a test project to learn memcached.

Has anybody done this before. What are the disadvantages of using this ?

答:
The disadvantage is that you're using distributed systems.

The advantage is that you're using distributed systems.

Knowing the strengths, weaknesses and potential gotchas with distributed systems is something that is key for anyone wanting to move into high traffic applications, whether they're web based or not. It changes the way that you think about your system architecture.

Using distributed systems will make your applications much more complex than they would be otherwise.

Are you building this small application as an excercise in understanding distributed systems? If not, I'd venture to say that you're hitting a nail with a sledgehammer and most likely signing yourself up for a ton of headaches that you would otherwise avoid.


问:
Are there laws to protect us from hackers who disclose vulnerabilities prior to alerting the vendor?
Take the example of the recent ASP.NET (and Java Server Faces) vulnerability disclosure at a Hacker conference in Brazil.  It's my understanding that the poet tool was demonstrated before Microsoft was even aware of the issue.

Are there laws to protect legitimate customers from people who encite the hacker community to start hacking all the ASP.NET servers they can?  Who knows how many legitimate businesses were compromised between when the tool was demoed and the patch was applied to the server.

答:
In the general case, no. It is not illegal to discover a security issue. It is not illegal (and I argue it should not be) to discuss this with other people before notifying the vendor.

It is (in many, probably most jurisdictions) illegal to use a security flaw, without prior permission of the owner of the machine you're using it on.

However, if you ask "is it ethical", I'd have to hedge my answers a bit more. It can be ethical, it can be unethical, it depends on many variables.

You also have the problem of "what to do if the vendor is not responsive". This is, from my understanding, becoming less common these days, but there's certainly been multiple cases in the past when security researchers have notified a vendor of an existing security hole and the vendor has done nothing for years, until they've finally published the research (sometimes, but not always, prompted by seeing the security hole used by cracking toolsets in the wild).

ContentLicense: CC BY-SA 2.5


问:
Deployment in development phase for Agile projects
I'd like to know the Agile stance on the following situation:

A contractual, payable milestone states a working version must be installed and run at customer's location;

Development is still ongoing, not all user stories and issues are addressed;

A later deployment will be required

My understanding was that the product owner would view the software in its development environment until final QA is done, and then (and not before) would it be deployed into the final production environment.

答: My opinion is that the Product Owner just needs a way to verify that the chunk of work is done, whether that is in a Test environment or on a development machine. You don't have to actually release an update every iteration. You could spend 3 iterations putting features into QA and then do a release to Production. </p>


答:
Ask your client to create a test environment that mimes the production one. Do not, under any circumstances, install a new update on the living system, before you test and demonstrate it to the client, because if you screw up your milestone, you also screw up the client's operation;

Make your QA team use this test environment;

Agile process assumes that you deliver as soon as possible, so don't collect changes in the test environment. Instead, deploy little changes as soon as they are verified by the client. It's much better then deploying the result of the one year work;

Backup live data before every upgrade

Title: Deployment in development phase for Agile projects

Body:
I'd like to know the Agile stance on the following situation:

A contractual, payable milestone states a working version must be installed and run at customer's location;

Development is still ongoing, not all user stories and issues are addressed;

A later deployment will be required

My understanding was that the product owner would view the software in its development environment until final QA is done, and then (and not before) would it be deployed into the final production environment.


答:
By Scrum means the Team iterates to produce increments, they are not by default releaseable but they are done. If the customer wishes qa tested stables during the whole process all qamust be done in the iterations before. Scrum teams can do that but its not effient... The product owner you mentioned reflects the customers preferences. Scrum never says anything about what or when to code and test. The Team and the PO decide when todo it in order to serve the customer demands like visible progress. It's good to get immediate feedback. In your case it's sound likes bit of wasting resources...

When you are in test driven project you are may already on the half way to qa due mandatory tests.

I'm afraid to say that there is no The agile way to stop customers having demanding Task to offer...


答:
Checking errors during debug builds only is a BAD IDEA(tm), compiling under release overlays reusable variables on stack, removes guard pages, does iffy tricks with calculations, replaces heavy arthritics with precomputed shifts and so on.

Use error checking in release as well, you can resort to something as simple as:

```<code>if(somethinghitthefan)
     abort();
</code>```

This also has a very good side effect that you definitely won't ignore the bug once the application starts crashing on betta testers PC.

Event viewers and logs are completely useless compared to abort(), who checks them anyway?

Body:
Checking errors during debug builds only is a BAD IDEA(tm), compiling under release overlays reusable variables on stack, removes guard pages, does iffy tricks with calculations, replaces heavy arthritics with precomputed shifts and so on.

Use error checking in release as well, you can resort to something as simple as:

if(somethinghitthefan)
     abort();

This also has a very good side effect that you definitely won't ignore the bug once the application starts crashing on betta testers PC.

Event viewers and logs are completely useless compared to abort(), who checks them anyway?


问:
What is the/Is there a right way to tell management that our code sucks?
Our code is bad. It might not have always been considered bad, but it is bad and is only going downhill. I started fresh out of college less than a year ago, and many of the things in our code puzzle me beyond belief. At first I figured that as the new guy I should keep my mouth shut until I learned a little more about our code base, but I've seen plenty to know that it's bad.

Some of the highlights:

We still use frames (try getting something out of a querystring, almost impossible)

VBScript

Source Safe

We 'use' .NET - by that I mean we have .net wrappers that call COM DLLs making it almost impossible to debug easily

Everything is basically one giant function

Code is not maintainable. Each page has multiple files that are created every time a new page is made. The main page basically does Response.Write() a bunch of times to render the HTML (runat="server"? no way). After that there can be a lot of logic on the client side (VBScript), and finally the page submits to itself (often time storing many things in hidden fields) where it then posts to a processing page which can do things such as save the data to the database.

The specifications we get are laughable. Often times they call for things like "auto-populate field X with either field Y or field Z" with no indication of when to choose field Y or field Z.

I'm sure some of this is a result of not being employed at a software company, but I feel as if people writing software should at least care about the quality of their code. I can't even imagine that if I were to bring something up that anything would be done soon, as there is a large deadline looming, but we are continuing to write bad code and use bad practices.

What can I do? How do I even bring these issues up? 75% of my team agree with me and have brought up these issues in the past, yet nothing gets changed.

答:
Don't do it.

Rewriting a large project from scratch is a big mistake most of the times anyway.

OwnerDisplayName: Azkar


问:
What are the disadvantages of automated testing?
There are a number of questions on this site that give plenty of information about the benefits that can be gained from automated testing.  But I didn't see anything that represented the other side of the coin: what are the disadvantages?  Everything in life is a tradeoff and there are no silver bullets, so surely there must be some valid reasons not to do automated testing.  What are they?

Here's a few that I've come up with:

Requires more initial developer time for a given feature

Requires a higher skill level of team members

Increase tooling needs (test runners, frameworks, etc.)

Complex analysis required when a failed test in encountered - is this test obsolete due to my change or is it telling me I made a mistake?

Edit

I should say that I am a huge proponent of automated testing, and I'm not looking to be convinced to do it.  I'm looking to understand what the disadvantages are so when I go to my company to make a case for it I don't look like I'm throwing around the next imaginary silver bullet.

Also, I'm explicity not looking for someone to dispute my examples above.  I am taking as true that there must be some disadvantages (everything has trade-offs) and I want to understand what those are.

答: Perhaps the most important disadvantage is ... tests are production code.  Every test you write adds code to your codebase that needs to be maintained and supported.  Failing to do so leads to tests you don't believe the results of, so you have no other choice.  Don't get me wrong - I'm a big advocate of automated testing.  But everything has a cost, and this is a big one.


问:
C# or .Net features to cut off assuming no backward compatibility needed?
Any product or framework evolves. Mainly it's done to catch up the needs of it's users, leverage new computing powers and simply make it better. Sometimes the primary design goal also changes with the product. C# or .net framework is no exception. As we see, the present day 4th version is very much different comparing with the first one. But thing comes as a barricade to this evolution- backward compatibility.

In most of frameworks/products there are features would have been cut off if there was no need to support backward compatibility. According to you, what are these features in C#/.net?

Please mention one feature per answer.

答:
Defaulting numeric literals to double

For most business apps, decimal is more appropriate anyway... or maybe it would be better to just remove the idea of a default, and force developer to actually make the choice.

(That "remove the default" would be appropriate for some other things, too. For example, I've given up trying to persuade everyone that classes should be sealed by default, but I suspect it's easier to persuade people that they should think about whether their new class should be sealed or not, and make it explicit.)


问:
Why did memory-managed languages like Java, Javascript, and C# retain the `new` keyword?
The new keyword in languages like Java, Javascript, and C# creates a new instance of a class.

This syntax seems to have been inherited from C++, where new is used specifically to allocate a new instance of a class on the heap, and return a pointer to the new instance.  In C++, this is not the only way to construct an object. You can also construct an object on the stack, without using new - and in fact, this way of constructing objects is much more common in C++.

So, coming from a C++ background, the new keyword in languages like Java, Javascript, and C# seemed natural and obvious to me.  Then I started to learn Python, which doesn't have the new keyword.  In Python, an instance is constructed simply by calling the constructor, like:

```<code>f = Foo()
</code>```

At first, this seemed a bit off to me, until it occurred to me that there's no reason for Python to have new, because everything is an object so there's no need to disambiguate between various constructor syntaxes.

But then I thought - what's really the point of new in Java?  Why should we say Object o = new Object();?  Why not just Object o = Object();?  In C++ there's definitely a need for new, since we need to distinguish between allocating on the heap and allocating on the stack, but in Java all objects are constructed on the heap, so why even have the new keyword?  The same question could be asked for Javascript.  In C#, which I'm much less familiar with, I think new may have some purpose in terms of distinguishing between object types and value types, but I'm not sure.

Regardless, it seems to me that many languages which came after C++ simply "inherited" the new keyword - without really needing it.  It's almost like a vestigial keyword.  We don't seem to need it for any reason, and yet it's there.

Question: Am I correct about this?  Or is there some compelling reason that new needs to be in C++-inspired memory-managed languages like Java, Javascript and C# but not Python?

答: Interestingly, with the advent of perfect forwarding, non-placement new isn't required at all in C++ either. So, arguably, it's no longer needed in any of the mentioned languages.


问:
Would it be ethical to create an open source alternative to the software you've been hired to create?
Say you were hired to create education software that will be sold to students of a particular academic institution. You are the only developer working on this project and have written all of the code. An open source alternative to the project has the potential of benefiting underprivileged students from around the world. In short, a free alternative would contribute to the greater good of humanity. Would it be "OK" to create an open source alternative to the software that you are being paid to develop?

P.S. The software will only be used by the students of the institution. There are no plans to distribute it commercially. The application does not make use of other people's intellectual property.

答: Ethical?  Maybe, ethics are a personal decision.  Legal?  Possibly, depending on your contract with the company.  Smart?  Heck no, when future employers see you as their competitor, your resume will go in the trash can.</p>


问:
Does project architecture have a strong relation to used libraries?
Programmers, when it comes to talk about popular patterns in enterprise applications, preach that you should code against interfaces to remove strong relations between components; doing this will aid in changing concrete types while minimizing changes in other areas of the application. The underlying assumption is that interfaces are all about abstractions. When it comes to real life it is almost impossible. Lets use an example:

Lets say you currently use an ORM framework in your application, which you abstracted by applying the repository pattern. Now, can you really change ORM framework seamlessly?

```<code>public interface IRepository<T>
{
    T GetById(int id);
    void Add(T entity);
    void Remove(T entity);
    void Update(T entity);
    IQueryable<T> Query(Expression<Func<T, bool>> filter);
}
</code>```

Theoretically, this implementation can be applied to the rest of the application, but many questions remain about the actual application of this pattern:

How does this pattern shield me from the internal process of libraries?

How does the abstraction deal with the variation in exceptions thrown by each library?

If I have selected an ORM which provides a caching mechanism internally and I later decide to switch to an alternative ORM with no such support, how does the pattern handle this?

So, from this, I believe that the project architecture is strongly influenced on the libraries that are used. Is there anything wrong with this? Am I assuming too much from this pattern?

答:
"In theory, there is no difference between theory and practice.  In practice, there is."

Isolation via interfaces is a great theory.  It rarely succeeds in practice, because the implementations that hide behind the interfaces often have behavioral differences that go way beyond the ability of the interface to hide.  Even interfaces that strive have strong support and are highly isolatable (e.g., SQL) nonetheless fail to be completely isolated.


答:
The crux of the error handling is not whether and how you catch the trouble. It is more of what you do after you learn about it.

First off - i would say, there is no reason why any single error returned by subordinate method is returning shouldn't be handled. And errors and exceptions are just more than the return values or all try/catch.

Just throwing and catching is not enough.

See this : where
the author explains that just by catching but doing nothing
potentially suppresses the exception and unless enough is done to
undo the damage - it is worse than letting the code go just like
that. Similarly just writing "log" statement when there is a file
open or read error might help find the reason why - but by the time
program terminates, it might have caused the data to go damage! It
is not enough to say i have many try/catch - it is more important
to know what they really do!

Don't abuse the try and catch.

Some times - mostly lazy or naive programmers think that after writing sufficient try/catch, their job is over and easy. Quite often it is best to apply corrective action and resume rather than just dump the whole thing. If this cannot be done, one needs to decide at what level you need to go back. Depending on the context and severity, try catch nesting needs careful design.
For example-
See this and this

Define who is responsible:

One of the first thing you should do is to define whether the input given to the routine itself is just an unacceptable (or not-handled so far) scenario or is the exception due to environment (such as system issue, memory issue), or is this situation a completely internal arising out of algorithm outcome. In all cases - the level at which you may want to go back to or action you want to take differs significantly. In this light i would like to say - that when you run the code in production - making abort() to exit the program is good - but not for every small thing. If you spot memory corruption or out of memory it is definite that even after doing your best - things will die. But if you receive a NULL pointer at the input - i wouldn't go on calling abort() -i would rather send it back to the caller with an error and see if she is smart enough to figure out whether it can correct itself.

Define what is the best possible outcome:

What all things must be done under exception is very critical. For example if in one of our cases - a media player finds that it doesn't have full data that to be played out to user - what is it should do?

either skip some bad part and see if it can get ahead with good
things.

if this happens too much consider if it can skip to next
song.

if it finds that it is not able to read any file - stop and
show something.

in the meanwhile

under which of the state should a player POP-UP to the user and

when should it carry on its own?

Should it "halt" things to ask user feed back

or should it put unobtrusive little error note in some corner?

All these are subjective - and perhaps there are more ways to handle problems than we trivially thing. All of the above requires to build and understand depth of the exception and than also make different scenarios should be possible to evolve to.

Sometimes we need to check for exceptions before they arise.  The
most common example is the divide by zero error. Ideally one must
test that before such exception is thrown upon - and if that is the
case- try to put most appropriate non-zero value and move on rather
than go suicide!

Clean-up.  At least this is what you must do! If a function happens
to open 3 files and fourth one fails to open - needless to say the
first 3 should have been closed. Delegating this job to a layer
above is a bad idea. if you decide to quite don't leave without
cleaning memory. And most important - even if you have survive the
exception, do inform the higher up that things haven't took the
normal course.

The way we see (normal) functionality of the software in terms of various hierarchies or layers or abstractions, same way we must categorize exceptions based on their severity as well as scope under which they arise and they are affecting other parts of system - that defines how to handle such different exceptions in best possible way.

Best reference: Code Craft chapter 6 - available for download


问:
How to make security usable in a web application?
I'm in the planning stages of developing a web application that I want to make as secure as possible. I'm pretty clear about how to do that from a technical point of view, but there is one massive potential security hole: I want the site to have users.

As anyone who has ever been a user knows, users forget usernames, forget passwords, sometimes forget that they even had an account with your site. Users respond to phishing emails and give away their credentials. If you do anything that they find too complicated they won't use your site, it has to be simple and all happen in as few clicks as possible, but we have to balance that out by making it as hard as possible for users to accidentally give away their credentials and to keep access to the service as secure as possible.

What I'm particularly interested in are strategies that go beyond the standard username and password combination and ways of recovering or resetting passwords that make things easy for users but hard for anyone trying to steal their account. I know a lot of sites provide an extra user-set security question, but because I don't trust users not to create a stupid question like "what is 1+1" I don't see how this can guarantee security.

Are there strategies that could be useable to the most clueless user but challenging to a determined and targetted attack aiming to break into their account? If not what are the closest things we could get? As a user what are the best/worst sites for this you have encountered and why?

答:
My only suggestion on the "usable but secure" front would be to have set questions, but user-entered answers (e.g. notable place, first pet's name, notable date). Although these aren't watertight individually, making them answer a combination of two or three person-specfic questions should be good enough.

And don't forget Captcha words or similar to slow down or identify brute-forcing.


答:
This is more a guideline than a feature, but I think it's important because it's already too much ingrained in people's minds as the canonical and best solution:

The official pattern to implement IDisposable.

It's cumbersome and there're better ways.

Title: C# or .Net features to cut off assuming no backward compatibility needed?

Body:
Any product or framework evolves. Mainly it's done to catch up the needs of it's users, leverage new computing powers and simply make it better. Sometimes the primary design goal also changes with the product. C# or .net framework is no exception. As we see, the present day 4th version is very much different comparing with the first one. But thing comes as a barricade to this evolution- backward compatibility.

In most of frameworks/products there are features would have been cut off if there was no need to support backward compatibility. According to you, what are these features in C#/.net?

Please mention one feature per answer.


答:
If you take up actual code and some critical design which is already developed in your paid project - copying that and giving in Open Source - that is Un-ethical and Illegal.

Even if your code is fresh - if yo are taking away any Intellectual property it is Un-ethical and illegal.

If you use time or other resources of the company for what you are paid to use that towards open source project instead of contributing to your real project - that is Un-ethical (and might become illegal if you are caught).

The balance seems to be governed by natural laws of competition in the society.

Dipan.

Title: Would it be ethical to create an open source alternative to the software you've been hired to create?

Body:
Say you were hired to create education software that will be sold to students of a particular academic institution. You are the only developer working on this project and have written all of the code. An open source alternative to the project has the potential of benefiting underprivileged students from around the world. In short, a free alternative would contribute to the greater good of humanity. Would it be "OK" to create an open source alternative to the software that you are being paid to develop?

P.S. The software will only be used by the students of the institution. There are no plans to distribute it commercially. The application does not make use of other people's intellectual property.


答:
This approach greatly changes the ACID guarantees of your application. If your memcached server goes down, you lose all changes since your last database synch with no way of recovering them. Out of the box, memcached will throw out old values when it runs out of RAM. If your app is write-heavy, this could mean losing data between synchronization.

You can improve the chances of data making it into the database by adding redundancy to your memcached layer, but it still doesn't create a solution with the same guarantees as a relational database. This isn't always a disadvantage. Some NoSQL approaches are consciously trading ACID guarantees for performance and scalability. There's even some math behind it in Brewer's CAP Theorem.

Regardless, most non-ACID NoSQL solutions guarantee eventual consistency. That's something your current approach doesn't provide and most users won't live without. If you lose my order, enlightening blog post, or witty comment, I'll likely find a different software provider.

Title: Implementing Asynchronous Insert / Update for a web application

Body:
I am in the process of implementing a small web application using memcached for caching objects and sql server for database persistence.

In all the projects I have done before I have done inserts/updates in the web thread itself. In this project I want to implement asynchronous inserts and updates. I will use memcached http://en.wikipedia.org/wiki/Memcached to capture changes and an external service (windows service) to persist the changes in db.

I understand premature performance tuning is evil but this is just a test project to learn memcached.

Has anybody done this before. What are the disadvantages of using this ?


问:
Does objective-c's method overhead make a 'many small methods' design approach inadvisable?
I generally favour using small methods, as recommended by, amongst others, Bob Martin in Clean Code. I've also read enough about Objective-C's internals to have at least some idea about how its message dispatch works (bbums series is particularly informative on this).

Premature optimisation concerns notwithstanding, I'd like to know if all that work that Objective-c does with objc_msgSend is, in practical terms, significant enough for the 'many small methods' approach to be inadvisable for Objective-C projects.

Empirical findings are particularly welcome (maybe I'll set up a test myself sometime). Experience from anyone who has written large objective-c projects would also be great.

Clarification

The general tone of the question is intentional. I'm not asking about performance tuning of specific apps (which is why I ask here rather than on SO), but more about whether Objective-C's language characteristics discourage a certain design approach. I have observed that much of the code I've seen from Apple, and other parties (on github etc) tends towards large methods (and classes), and I'm wondering if this is a bias that has crept in because of the language itself. Of course I may have been reading the wrong code, or it may be cultural rather than technical factors that have led to the tendency if it exists.

(For what it's worth, I am currently writing Objective-C, and I'm using small methods)

Further request

I agree with both the answers that have been given. One further thing I'd like is for someone to point me to a (hopefully substantial) open-source (or otherwise visible) Objective-C codebase that uses nice short methods (and small classes). I haven't seen anything in Objective-C yet to compare with (for example) the fitnesse source.

答:
The vast majority of code is not going to be performance-critical in any application, so even if the method overhead were significant compared to other languages, the optimal approach would still be to have many small methods in most places and inline only those that profiling has shown to be performance-critical.

Of course, there are many people who don't know how to optimize properly, and of those some may know about method overhead and engage in acts of global premature optimization, but I do not believe that group is large enough to have a significant impact on the Objective-C ecosystem.

Large methods and classes are far more likely to be the work of the large group of people who know or care nothing about profilers, method overhead or proper design, and who will tend to produce Big Balls of Mud in any language. And yes, some of those people do work on high-profile codebases in major software companies.


答:
Quick tip: if you do propose management with a list of reasons why you should code differently, include as an argument "Improved morale / working conditions for the programmers".

Make it clear that the tech team will be more content writing and maintaining clean code than this current mess, and this can certainly improve your attitude towards work. Could be a useful argument.

Title: What is the/Is there a right way to tell management that our code sucks?

Body:
Our code is bad. It might not have always been considered bad, but it is bad and is only going downhill. I started fresh out of college less than a year ago, and many of the things in our code puzzle me beyond belief. At first I figured that as the new guy I should keep my mouth shut until I learned a little more about our code base, but I've seen plenty to know that it's bad.

Some of the highlights:

We still use frames (try getting something out of a querystring, almost impossible)

VBScript

Source Safe

We 'use' .NET - by that I mean we have .net wrappers that call COM DLLs making it almost impossible to debug easily

Everything is basically one giant function

Code is not maintainable. Each page has multiple files that are created every time a new page is made. The main page basically does Response.Write() a bunch of times to render the HTML (runat="server"? no way). After that there can be a lot of logic on the client side (VBScript), and finally the page submits to itself (often time storing many things in hidden fields) where it then posts to a processing page which can do things such as save the data to the database.

The specifications we get are laughable. Often times they call for things like "auto-populate field X with either field Y or field Z" with no indication of when to choose field Y or field Z.

I'm sure some of this is a result of not being employed at a software company, but I feel as if people writing software should at least care about the quality of their code. I can't even imagine that if I were to bring something up that anything would be done soon, as there is a large deadline looming, but we are continuing to write bad code and use bad practices.

What can I do? How do I even bring these issues up? 75% of my team agree with me and have brought up these issues in the past, yet nothing gets changed.


问:
Should I get a Math bachelors and then go into Computer Science?
This is my first question. I love Mathematics; I love the logic and the problem solving. At the same time, I enjoy Computer Science and hope to go into Artificial Intelligence research after I get my Bachelors degree, i.e pursue a PhD in Computer Science. Are there any advantages of having a firm grasp of Mathematics to studying Computer Science? Also, would I be at a disadvantage in getting a Bachelors in Mathematics instead of Computer Science when applying for graduate school to study Computer Science, particularly at institutions with high quality research infrastructure, like MIT and Stanford? Also, in reference to the first question, could you please tell me the advantages of a solid grasp of Mathematics, if there are any?

Thank you.

答: You could get both at the same time.  Many schools have a CS bachelors degree with a math/science emphasis that, once you've taken the required math courses for the CS degree, will leave you only a few courses away from the double major in math.</p>


问:
Where does the term "Red/Black Tree" come from?
A Red/Black Tree is one way to implement a balanced binary search tree.  The principles behind how it works make sense to me, but the chosen colors don't.  Why red and black, as opposed to any other pair of colors or of attributes in general?  When I hear "red and black," the first things that come to mind are checkerboards and Les Misérables, neither of which seems particularly applicable in this context.</p>

答:
EDIT: Answer from Professor Guibas:

from  Leonidas Guibas guibas@cs.stanford.edu to
  of the "Red-Black" term mailed-by cs.stanford.edu hide details 16:16
  (0 minutes ago)

we had red and black pens for drawing the trees.

I believe the term first appeared in "A dichromatic framework for balanced trees" from Leonidas J. Guibas and Robert Sedgewick in 1978.


答:
You say you like both Math and Computer Science. Are you good at both? How do you know that you are good in both?

To answer your question:

Are there any advantages of having a firm grasp of Mathematics to studying Computer Science?

The answer is yes, but most of the mathematics you need you will learn as part of the CS major. You probably won't need to be proficient in proving math theorems (which math majors should do) you need to understand some of them only. Pure math. subjects are not required, for example, Projective Geometry is not a must know.

You need to be careful when you persue a degree in Math. The study is very hard and from a career perspective, jobs may not be that easy to find. You need to have really good IQ to survive in Math related careers.

CS offers more applied careers than math would. This gives you chocie which is a nice thing.

Remember that what you like today is not necessarily the same things you will like 4, 10 or 20 years from now for CS. Mature universities have figured what is needed. If there is a deficiency, you should be able to take a course or two to cover for it.

The above is my opinion and is not based on any science.

Title: Should I get a Math bachelors and then go into Computer Science?

Body:
This is my first question. I love Mathematics; I love the logic and the problem solving. At the same time, I enjoy Computer Science and hope to go into Artificial Intelligence research after I get my Bachelors degree, i.e pursue a PhD in Computer Science. Are there any advantages of having a firm grasp of Mathematics to studying Computer Science? Also, would I be at a disadvantage in getting a Bachelors in Mathematics instead of Computer Science when applying for graduate school to study Computer Science, particularly at institutions with high quality research infrastructure, like MIT and Stanford? Also, in reference to the first question, could you please tell me the advantages of a solid grasp of Mathematics, if there are any?

Thank you.


答:
If you are set on going into AI, you should really try and get an AI bachelor. I don't know if this is an option or not, and it might be more restrictive than a Math or a CS degree but if this is your dream you should follow it.

An AI bachelor, to put it extremely roughly, is a 50% Math and 50% CS degree. The University of Edinburgh School of Informatics (home of AIAI) pamphlet describes their AI degree as:

In first year you will study a general course in
  Informatics that includes programming, logic,
  the theory of computation, and the nature of
  information processing. You will study two
  other subjects in parallel. For most degrees this
  includes a Mathematics course tailored to the
  subject.

In the second year you will have specific
  Informatics courses that lay the foundations
  of Artificial Intelligence (such as reasoning,
  search, planning, inference learning, and
  language processing), further courses in
  Mathematics or your joint degree subject, and
  the possibility to continue with an additional
  subject.

In the third and fourth year (and fifth year
  for MInf) your studies will be focused on the
  discipline(s) of your chosen degree

To further add to the confusion, they offer five AI degrees:

BSc Honours in:

Artificial Intelligence

Artificial Intelligence and Computer Science

Artificial Intelligence and Mathematics Cognitive Science

BEng Honours in:

Artificial Intelligence with Management

Artificial Intelligence and Software Engineering

You can get a better idea of what they do but going through their open courseware.

If you have the option of an AI degree you should probably contact the university directly (all schools have undergraduate / prospective students advisors) and ask about the degree structure and what career paths it can offer you.

PS. I'm in no way affiliated with the University of Edinburgh :)


答:
The programs you are after should list prerequisites for entrance.  Make sure whatever you take up will fulfill at least the minimum requirements at your top 5 schools.  I would suspect that any graduate program involving computing would require a strong background in data structures and theory of computation.

If you know you abilities in math, and are confident that you will survive and thrive in that area, then major in math with a strong backing in CS (either a double major, as wshato suggests, or a major/minor).  Graduate school has so much more to do with your passion for the subject and how well you grasp the fundamentals more than whether you took Math 305 or CS 440.


问:
How do I do TDD when expected behaviour is to be changed?
I've been doing TDD with a project I'm working on, and I have quite a large number of tests.  I have quite a few automated tests around restrictions enforced in code, making sure things that shouldn't be allowed aren't allowed.  Now I've been told that due to changes in our licensing model, some of those restrictions need to be removed.

Since I've done the entire project using TDD, I'm not sure how to make a change like this also using the TDD mindset.

So, my question is: Do I make the back end changes and see what tests break, or do I try to find the tests that enforce the behaviour, and change those first?

My concern is that if there are operations A, B, C and D where a check is done to disallow the behaviour, and I have equivalent tests TestA, TestB, TestC, and TestD (possibly in different places) no matter which half I change first, I may miss one or two spots and end up with incorrect behaviour, but still have all the tests pass (e.g. what if I miss TestD?)

答: Having done the entire project with TDD, I'd advise you to stick with it.  Many requirements are changing, but take them one at a time.  For a new requirement, either write a test for it, or find the existing test that should now have different results.  Change it to correspond to the new requirement, and watch it turn red.  Now make it pass.  When you make it pass, you might find another test (or tests) breaks, because that test depended on the old behavior.  That's fine.  Review the breaking test and ensure that you haven't really broken behavior (if you have, undo your change).  Update the breaking test to correspond to the new desired behavior, and watch it turn green.  Repeat until done.</p>


答:
Ideally, find the tests that enforce the behaviour, and change those first. This way you can see the test fail before you make it pass again, which is perfect TDD.

If you miss one then so be it. Pragmatism would usually kick in and you just fix the test.

If you were being really pedantic, you should be able to change the code back, change that test, see them all fail and then fix it again. I am quite strict with myself about TDD and even I'm not that pedantic. I just don't think that step would offer much.

Title: How do I do TDD when expected behaviour is to be changed?

Body:
I've been doing TDD with a project I'm working on, and I have quite a large number of tests.  I have quite a few automated tests around restrictions enforced in code, making sure things that shouldn't be allowed aren't allowed.  Now I've been told that due to changes in our licensing model, some of those restrictions need to be removed.

Since I've done the entire project using TDD, I'm not sure how to make a change like this also using the TDD mindset.

So, my question is: Do I make the back end changes and see what tests break, or do I try to find the tests that enforce the behaviour, and change those first?

My concern is that if there are operations A, B, C and D where a check is done to disallow the behaviour, and I have equivalent tests TestA, TestB, TestC, and TestD (possibly in different places) no matter which half I change first, I may miss one or two spots and end up with incorrect behaviour, but still have all the tests pass (e.g. what if I miss TestD?)


问:
What is Module Object and Function Object?
I am currently teaching myself Python, using the GNU licensed book "Introduction to Computer Science using Python."

In chapter 3, functions are covered. While I understand the concept of functions and how they simplify code by executing a defined sequence of statements whenever they care called, and that Modules are collections of related functions and variables, stored in a file, I do not understand the concept of module objects and function objects. For example, when "import math" is executed, it says, a module object is created. Also, when a function is defined and is executed, a function object is created.

Could someone please explain what these "objects" are to me?

答:
Python at run-time keeps a lot of information around about the state of the code it's executing, and exposes quite a lot of it to programmers.  So, at run time, there is an actual object (an instance of a class) called a module object that is created when a module is imported.  It is a genuine Python object and you can do anything with it that you can do with a Python object.  It has methods and everything.

When a function definition that gets executed (which isn't the same as the function being executed - normally the definition would be executed once for the function when the module is imported) it creates a function object, which is just a special kind of object that is a wrapper around the executable code.  This too is a real object, you can set variables to it, pass it as a parameter, call it's methods, etc.


答:
A function object refers to the fact that Python treats functions first class objects. This allows Python to use certain techniques from functional programming, particularly the passing of functions in ways similar to how you would pass any other object like a String or an Array.

A module object is an object created that represents a library of functions. It would be similar to an Abstract Class in a more Object Oriented Language. You'd import in to get sets of predefined functions that you might need to use.

Title: What is Module Object and Function Object?

Body:
I am currently teaching myself Python, using the GNU licensed book "Introduction to Computer Science using Python."

In chapter 3, functions are covered. While I understand the concept of functions and how they simplify code by executing a defined sequence of statements whenever they care called, and that Modules are collections of related functions and variables, stored in a file, I do not understand the concept of module objects and function objects. For example, when "import math" is executed, it says, a module object is created. Also, when a function is defined and is executed, a function object is created.

Could someone please explain what these "objects" are to me?


问:
Why has the rate of programming language popularization slowed down in recent decades?
If I understand correctly, there was a huge birth of programming languages during the early decades of computing, but then things have stabilized.

Basically, why are many universities and industries still using languages such as C and C++ (which were created decades ago), when there have been plenty of decades since then to improve upon and create more effective (and human-friendly) languages?

答:
Languages such as C/C++ are far closer to what the metal actually executes. This means they can teach you what the machine is really doing in tandem with teaching you the fundamentals of algorithms and data structures.

Don't forget, even though C & C++ were "created decades ago", they are still fundamental to a lot of new development (see: Linux Kernel).

Also, don't forget that it actually takes time to create, review, polish and get approved new course content. The academic world is on general, more conservative in vetting changes than the non-academic world.

Having said this, while I studied Computer Science, I still had classes on .NET, Java, PHP and more.

I direct your eyes to this study of Australian University introductory programming courses and the languages they used. You will note that the highest was Java at almost 44% and the second highest was VB at almost 19%.


答:
"I started fresh out of college" -- should answer your question.

The management probably know there code is sub-optimal. Most code is unless you hired Ray Gosling, Guido Van Rossum or someone else really good and expensive to write it.

The management also know it works using whatever definition of "works" applies to your company (Doesn't crash, sells , delivers the reports or whatever).

They want you to keep the code "working" at minimal cost. They don't want a proposal for an expensive project to re-write everything.


答:
One can extend this question to many things: why has the progress of chess slowed down? Why has the progress of aviation slowed down? Why was I learning math so fast in grade school but in grad school and thereafter I am publishing papers VERY SLOWLY. Why was Facebook progressing so fast as start-up, and now with 1200+ employees it does not really change all that much?

The progress has not stopped; it goes on, but, as George Carlin put it, "Now you've got shit all over the world. The supply lines are getting harder to maintain".

The success of languages depends partly on having very large API base and user base, and the success of airplanes depends on being able to provide a million of conveniences to the customer. And the work of an academic is more complicated than  that of a student.

So, having to deal with backwards compatibility, having to test a new language feature in conjunction with all of the existing ones, having to worry about breaking libraries that worked with Python 2.7 (for instance), just concentrating on improving the API, dealing with new computer architectures that need to be supported, dealing with inter-operability with some other popular technologies, being invited to conferences as the father of a language, having to deal with lots of fan/hate mail, general time waste due to the inreased size of code base / organization, finding time to write a book about the language you have just made ... the responsibilities can suddenly pile up exponentially, but the time ticks away at the same speed. So, as complexity of things grows, the progress appears to slow down. The only way to deal with that is to throw more people at the problem, but not every organization can afford to do that. They would have to be benefiting financially from the product at least proportionally to its complexity. The for-profit model could work better in this case, although Sun & Oracle had cash but have/are not making revolutionary changes to Java now days.

These are just some things that I thought of ...

Title: Why has the rate of programming language popularization slowed down in recent decades?

Body:
If I understand correctly, there was a huge birth of programming languages during the early decades of computing, but then things have stabilized.

Basically, why are many universities and industries still using languages such as C and C++ (which were created decades ago), when there have been plenty of decades since then to improve upon and create more effective (and human-friendly) languages?


问:
As a C# developer, would you learn Java to develop for Android or use MonoDroid instead?
I'd consider myself pretty well versed in C#. It's my language of choice at the moment, and it's where basically all my professional experience lies.

Still, I'm puzzled by the existence of the MonoDroid project. My understanding has always been that C# and Java are very close. Like, if you know one, you can learn the other really quickly. So, as I've considered developing my first Android app, I just assumed I would familiarize myself with Java enough to get started and then just sort of learn as I go.

Wouldn't this make more sense than using MonoDroid, which is likely to be less feature-rich than the Java Android SDK, and requires learning its own API (albeit a .NET API) anyway? I just feel like it would be better to learn a new language (and an extremely popular one at that) and get some experience in it—when it's so close to what you already know anyway—rather than stick with a technology you're experienced with, without gaining any more valuable skills.

Maybe I'm grossly misrepresenting the average potential MonoDroid user. Maybe it's more for people who are experienced in Java and .NET and just prefer .NET. Or maybe (in fact it's likely) there are other factors I just haven't considered. I'm just wondering, why would you use MonoDroid instead of just developing for Android using Java?

答:
This is a kind of supplementary answer, since one thing that seems to have been overlooked in answers so far, concerns what is actually cross-platform. According to Xamarin themselves that is basically your business logic, not your UI or any hardware control such as GPS, audio, address book and so on. Those will have to be written specifically for each platform. See their FAQ entry I have a MonoTouch or WindowsPhone 7 application, can I just rebuild it with Mono for Android and target Android?.

Using Mono, you can write your UI and phone control code using C# but it will not be portable to any platform. You will have to write the UI and phone control for each platform, even though you can write it in C#. Either way, you will still have to learn the specifics of UI controls on Android and how Android handles phone resources.

Using Mono, you'll have to learn the Mono API, that calls into the Android API. You'll also have to wait for Mono to implement new Android features and hope they implement all Android features. Even if C# is more powerful than Java, you'll not be able to do more than if you use the Android SDK directly (in Java).

If you're going straight from C# to Android, since C# is so syntactically similar to Java, then most of a C# developer's learning for Android will be learning the Android API.

Some considerations...

C# to Android

Need to Learn

Android API

Java API : String, Calendar and event handling etc.

Don't need to learn

Java syntax : C# is very similar syntax.

Other considerations

You won't be able to reuse code across platforms.

You won't have any dependencies between you and the Android SDK. You will get new Android features as they are released.

You will likely have greater support and examples for Android code than Mono.

C# to Mono

Need to Learn

Android : You still need to learn Android's UI and hardware control features.

Mono API : You have to learn how to call Mono's API to do stuff with Android's UI and hardware.

Don't need to learn

Java API and syntax : You can develop in C#

Other considerations

Reuse code : You can re-use C# code that is devoid of any UI or hardware control code and so is pure "business logic". Although ideal, having such a clean separation is not always easy. You will have to evaluate how much of your code will not have any UI or hardware control.

Dependencies : You are dependent on Mono implementing the Android API. There may be some lag from Android API releases or some Android features may never be implemented.

You may have less documentation and examples to choose from.


答:
A lot of "modern" programming languages aren't so different to C++.

Java has classes and function calls. So does C++. Java has block structures such as if and for - which are copied from C.

A major thing that Java has, but which C++ doesn't, is garbage collection. That's no so modern - it was invented for Lisp in the 1950s. The resource management system used in C++ (based on RAII and timely reliable destructors) is actually much newer than GC.

Functional languages like Haskell and the ML family are much more interestingly modern - and have mostly been considered academic because you're likely to find them in universities, but not so much in industry - though even that is changing. Even if you don't end up using Haskell in industry, Microsofts F# is a variant of Objective CAML - ie in the ML family - and C# and Python steal quite a few ideas from functional languages.

From what I've seen, the best universities cover quite a few languages, making sure students get a good idea of the various different paradigms that go with them. Take a look at some of the Stanford University courses with freely downloadable materials (inc. lecture videos), for example...

http://see.stanford.edu/see/courses.aspx

To the extent that there's a real problem, though, the answer is simple enough...

The new languages mostly don't include that many new ideas.

The new ideas that do exist tend to be controversial - a lot of people familiar with older ways of working are resistant to them. The greater the paradigm shift, the bigger this problem gets - though circumstances sometimes force change, as the increasing need for concurrency is doing right now.

You don't understand the new ideas (like GC) unless you know how to build them yourself, or at least work without them.

A lot of the benefit in a lot of modern languages come from the "batteries included" standard libraries. But in some ways, it doesn't matter if a library is included as official standards or not - there are plenty of de-facto standard libraries out there, and once you've set up your build environment, it's a bit of a non-issue. This is particularly the case on Linux, where your repository manager can pretty much set up your build environment for you.

If you really believe that old languages never get discarded, give some thought to COBOL, Fortran and Algol. OK, they're still out there, but mostly for maintenance of old code - and the "living death" of old code in mostly forgotten languages is another reason to not jump on the latest programming language bandwagon. It takes a long time to become a true expert in any particular language. A jack of all programming languages is easily replaced, and isn't all that valuable.


答: Yes, but now a days most them are using open source programming languages like PHP, Ruby on rails etc. Past days they are used Visual basic for stand lone application. Now days that was changed into VB.Net. And machine languages like c and C++ are replaced with Java for machine level coding..........!!</p>


答:
Though automation testing has many advantages, it has its own disadvantages too. Some of the disadvantages are:

Proficiency is required to write the automation test scripts.

Debugging the test script is major issue. If any error is present in the test script, sometimes it may lead to deadly consequences.

Test maintenance is costly in case of playback methods. Even though a minor change occurs in the GUI, the test script has to be rerecorded or replaced by a new test script.

Maintenance of test data files is difficult, if the test script tests more screens.

Some of the above disadvantages often subtract from the benefit gained from the automated scripts. Though the automation testing has pros and corns, it is adapted widely all over the world.

Title: What are the disadvantages of automated testing?

Body:
There are a number of questions on this site that give plenty of information about the benefits that can be gained from automated testing.  But I didn't see anything that represented the other side of the coin: what are the disadvantages?  Everything in life is a tradeoff and there are no silver bullets, so surely there must be some valid reasons not to do automated testing.  What are they?

Here's a few that I've come up with:

Requires more initial developer time for a given feature

Requires a higher skill level of team members

Increase tooling needs (test runners, frameworks, etc.)

Complex analysis required when a failed test in encountered - is this test obsolete due to my change or is it telling me I made a mistake?

Edit

I should say that I am a huge proponent of automated testing, and I'm not looking to be convinced to do it.  I'm looking to understand what the disadvantages are so when I go to my company to make a case for it I don't look like I'm throwing around the next imaginary silver bullet.

Also, I'm explicity not looking for someone to dispute my examples above.  I am taking as true that there must be some disadvantages (everything has trade-offs) and I want to understand what those are.


答:
Why do Universities still teach old languages? Because those old languages got it right. Sure they have rough edges, C's strings could be better and C++ could certainly be decrufted a bit. But they work. And there's no denying that. What counts more than anything else isn't efficacy of language, it's environment.

A million years ago when Mainframes were hot stuff and Dr. Knuth still had hair, we had the likes of Cobol, APL and FORTRAN (then spelled in all caps because we hadn't figured out that it wasn't cool to do that). Lisp was there too and so was Algol and so forth (FORTH wasn't quite there yet though, we're still in the 60s). However, most of these languages were fairly limited unless they were supported by the Government (FORTRAN) or Business (COBOL). Remember that the Internet was 4 computers in 1968 so getting information on a language would involve hearing about it from a colleague or some such and then going to a library, looking through a card catalog (a literal file system) and seeing if they had it. If you were lucky you could go to the source directly at whatever university or company was working on it. So knowledge ecosystems were limited.

Now let's talk about hardware. I'm just old enough to have been raised on a 386. A 386 was a God Machine compared to what they had back then. We're talking about transistors the size of cockroaches and wired collections of magnetic cores (Giving us the term "core dump") that held kilobytes of memory. These computers cost hundreds of thousands or millions of dollars. With machines being so expensive and with relatively few users, you had a lot of variation. Word and bit collection sizes that would make most of us go insane with frustration if we had to deal with them today. Bytes have spoiled us all. So what did you program these things in? Assembly on Punched cards. Sometimes you might have a machine specific higher level language to work with like PL/I or similar.

By the end of the decade, integrated circuits had started to come down in price and had begun to displace large scale transistors while memory also got cheaper. You still ran into the issue of all kinds of architectures but things were progressing. Then some bored programmer wanted to play Space War. And it changed the world. While languages like COBOL and Lisp were portable, C was the first language that was portable at a low level. Combined with UNIX (Like a really nerdy Voltron), it battled Pascal for dominion.

By this time, computers at universities were fairly common and Hacker culture was beginning to form. This led to the formation of things like the GNU project and other such initiatives as well as jokes like INTERCAL but I'm getting ahead of myself. There was a parallel stream here, the screaming birth of Software Engineering. Object Oriented Programming was not new in the early 80s but by then computers were common enough that large scale code bases were becoming hard to manage due to greater demand so it spurred development there.

Other developments ensued: the widespread use of home computers, the spread of the internet, the rise of windowing operating systems, the rise of the video game as a popular art form, and the rise of the parallel core machine amongst others.

The most important of these developments for the proliferation of languages are the introduction of the x86 and its various competitors that were folded into the IBM PC and its competitors and then the rise of the internet to facilitate language spread. So you've solved the problem of architecture portability and 90% of the market uses the same operating system. What does this do to the need for languages? It flattens them.

Why? Fundamentally language development and propagation are driven by need to solve problems. If you've got a language that works, you don't need to change it. Perhaps you add a framework here or there to streamline development or a library for task automation or the methodology of the month but ultimately you're crufting onto the language. This cruft though, it's important because there's where you get the environment from. You get culture that way and propagation follows the waves of culture.

Languages adapt and C family languages are incredibly adaptable due to being both widely deployed and extremely powerful. They also have something else, tremendous momentum. Say what you like about COBOL, there is a lot of wrapped COBOL running around out there; some of that is mutating into Java and other things but it will still being going along none the less. Some languages never really take off because they weren't designed to solve a widely scoped problem. C and C++ are widely scoped problem solvers. APL is not, at all. APL was designed to use as few keystrokes as possible in an era when that really mattered. It took it too far compared to other languages at the time and thus balance was not achieved, momentum was not gained and culture rampancy didn't take hold.

Rampancy is another key. The very best languages have something viral about them. They get inside your head and they stay there. That something viral might be monetary like a company saying "This language is win" and giving out T Shirts but I think it's more than that. Java may be a funky, crufty language but it solves a problem (several actually) and has a very powerful, meme-plague ridden ecosystem. So it keeps on propagating. And Propagation really is the key, your professors teach you old languages because they know there languages and these languages are still used out there. C is so close to the metal and so flexible that it is useful conceptually even if you never really use it. C++ is a thornier sell perhaps but I'd argue that as a much "harder" Object Oriented language than most, it serves as an excellent teaching tool.

Computer Science departments are out to teach concepts, not memetic fads. So they pick the best tool that solves that problem. That's why MIT used Scheme for so long. The modern language pantheon offers a lot of choice and therein perhaps lies the final answer. The internet has made it very easy to design, build and market a language. It can provide an ecosystem for you but it also provide a host of competitors. Which do you choose if you are teaching CS? The new hotness that may burn out soon? Which one? Why or why not? Most "fixer" languages are aimed at programmer productivity, not academic learning. And even with industrial usage, would you rather spend 6 months retraining your guys to Newfangled? I'd suspect you'd rather spend 6 months using the C++ you already have a team for and make money. Because that's the problem set in business. How do I make money faster than my rivals? I use proven technology run by smart people. So I can hired more smart people versed in proven technologies to write more code that makes me more money so I can hire even more smart people and pretty soon I have an R&D budget so I can indulge in things like exotic paradigms in Newfangled. But I'm still running in an "old" ecosystem. Because it works.

It just works.


答:
Wikipedia has a chronological list of important programming languages. It's not a complete list of every language ever invented, but I'm not sure that would help. Counting by hand, I see the following:

1950's: 47 languages

1960's: 46 languages

1970's: 45 languages

1980's: 50 languages

1990's: 57 languages

2000's: 36 languages

So there may have been a bit of a drop-off in "important" languages (although some of the languages invented in the last few years may yet prove important enough to be added later). Other than that, the rate of language creation has been remarkably flat.

Do you have any alternative data that supports your assertion?

As for universities: Do you know that they also still teach Latin? Nobody speaks Latin anymore, but you'll find plenty of people who will tell you that it's important. Learning Latin helps you understand a lot about modern languages, and Latin is also the source of a great deal of great literature. C is similar (although people still "speak" it): it's the root of many more modern programming languages, and a great deal of useful code is written in C.


答: The usual way to deal with this is to introduce a flag and change the behaviour of both test and production code according to the flag. For instance, if you introduce self-served purchases of vanilla frappes, then the test code would check the HAVE_AUTO_FRAPPE flag and either assertTrue() or assertFalse() depending on it. This has the advantage that you have to make the change to your test suite and to the production code only once. When the change takes effect, you just flip the bit and nothing else. (You can of course remove the entire mechanism later if it's definitely not going to change back, e.g. when refactoring for clarity, but you don't have to.)</p>


问:
Are there any surveys on to what degree developers like or hate scrum?
Background:
During a conference an analyst pointed out in a tweet that developers hate scrum.

Myself and another person responded that this was not the case, and started discussing different scenarios on why developers would dislike scrum.

One of the scenarios where that lazy developers are not able to hide in a scrum project. They are constantly challenged by the team to contribute.

This discussion resulted in a blog post and video
http://elsewhat.com/2010/05/20/lazy-developers-hate-agile-and%C2%A0scrum/

I've gotten three comments which I've tried to answer in a neutral way, but they comments do point out that there are some people who loathe scrum (and I am always 100% certain they are not lazy developers).

Question

Have there ever been a survey among developers on to what degree developers like or hate scrum ?

答:
I hate it. And most of the developers I know hate it as well.

It's pretty difficult to do cerebral, creative work like software development under a microscope.


问:
How can I best study a problem to determine whether recursion can/should be used?
In some cases, I fail to see that a problem could be solved by the divide and conquer method. To give a specific example, when studying the find max sub-array problem, my first approach is to brute force it by using a double loop to find the max subarray. When I saw the solution using the divide and conquer approach which is recursion-based, I understood it but ok. From my side, though, when I first read the problem statement, I did not think that recursion is applicable.

When studying a problem, is there any technique or trick to see that a recursion based (i.e. divide and conquer) approach can be used or not?

答:
For me, I believe that a problem is a good candidate for recursion if a smaller subset of this problem could be solved easier or obviously.

An easy example: word count all files that end with ".txt" in a folder including it's subfolders.

what if I had one file? (easy: word count that),

what if I had one folder? (easy with (1) available: generate a list of files, apply (1) then sum the results),

what if folders have subfolders? (Recurse using (2) (which uses (1))

Another approach could be "pattern matching": Some times similar problems, with well known problems that have been solved with recursion, pop up. Example again: Is there a structure as a tree involved ?(as above). If so, you can probably traverse it.


答: The best way of knowing when recursion is apropriate is from experiance. Use it and you will get more of a feel for when its apropriate. Also try learning a functional langage, I didnt understand how usefull recursion can be till I started learning F#</p>

Title: How can I best study a problem to determine whether recursion can/should be used?

Body:
In some cases, I fail to see that a problem could be solved by the divide and conquer method. To give a specific example, when studying the find max sub-array problem, my first approach is to brute force it by using a double loop to find the max subarray. When I saw the solution using the divide and conquer approach which is recursion-based, I understood it but ok. From my side, though, when I first read the problem statement, I did not think that recursion is applicable.

When studying a problem, is there any technique or trick to see that a recursion based (i.e. divide and conquer) approach can be used or not?


问:
How good does a well-rounded programmer need to be with bit-wise operations?
I have been browsing some OpenJDK code recently and have found some intriguing pieces of code there that has to do with bit-wise operations. I even asked a question about it on StackOverflow.

Another example that illustrates the point:

```<code> 1141       public static int bitCount(int i) {
 1142           // HD, Figure 5-2
 1143           i = i - ((i >>> 1) & 0x55555555);
 1144           i = (i & 0x33333333) + ((i >>> 2) & 0x33333333);
 1145           i = (i + (i >>> 4)) & 0x0f0f0f0f;
 1146           i = i + (i >>> 8);
 1147           i = i + (i >>> 16);
 1148           return i & 0x3f;
 1149       }
</code>```

This code can be found in the Integer class.

I cannot help but feel stupid when I look at this. Did I miss a class or two in college or is this not something I am supposed to just get? I can do simple bit-wise operations (like ANDing, ORing, XORing, shifting), but come on, how does someone come up with a code like that above?

How good does a well-rounded programmer need to be with bit-wise operations?

On a side note... What worries me is that the person who answered my question on StackOverflow answered it in a matter of minutes. If he could do that, why did I just stare like deer in the headlights?

答:
I would say that as a well-rounded developer, you need to understand the operators and bitwise operations.

So, at a minimum, you should be able to figure out the code above after a bit of thinking.

Bitwise operations tend to be rather low level, so if you work on websites and LOB software, you are unlikely to use them much.

Like other things, if you don't use them much, you wouldn't be conversant in them.

So, you shouldn't worry about someone being able to figure it out very quickly, as they (probably) work with this kind of code a lot. Possibly writing OS code, driver code or other tricky bit manipulation.


答:
the main things you should be aware of is how integers are represented (in general a fixed-length bitvector where the length is platform-dependent) and what operations are available on them

the main arithmetic operations + - * / % can be understood without needing to understand it though it can be handy for micro-optimizations (though most of the time the compiler will be able to take care of that for you)

the bit manipulation set | & ~ ^ << >> >>> require at least a passing understanding to be able use them

however most of the time you will only use them to pass bit flags to a method as ORing together and passing a int and then then ANDing out the settings is more readable than passing several (up to 32) booleans in a long parameter list and allows the possible flags to change without changing the interface

not to mention booleans are generally kept separately in bytes or ints instead of packing them together like the flags does

as for the code snippet it does a parallel count of the bits this allows the algorithm to run in O(log(n)) where n is the number of bits instead of the naive loop which is O(n)

the first step is the hardest to understand but if you start from the setup that it has to replace the bit sequences 0b00 to 0b00, 0b01 to 0b01, 0b10 to 0b01 and 0b11 to 0b10 it becomes easier to follow

so for the first step i - ((i >>> 1) & 0x55555555) if we take i to be equal to 0b00_01_10_11 then the output of this should be 0b00_01_01_10

(note that 0x5 is equal to 0b0101)

iuf we take i = 0b00_01_10_11 this means that 0b00_01_01_10 - (0b00_00_11_01 & 0b01_01_01_01) is 0b00_01_10_11 - 0b00_00_01_01 which in turn becomes 0b00_01_01_10

they could have done (i & 0x55555555) + ((i >>> 1) & 0x55555555) for the same result but this is 1 additional operation

the following steps are in a similar vein

Body:
I have been browsing some OpenJDK code recently and have found some intriguing pieces of code there that has to do with bit-wise operations. I even asked a question about it on StackOverflow.

Another example that illustrates the point:

```<code> 1141       public static int bitCount(int i) {
 1142           // HD, Figure 5-2
 1143           i = i - ((i >>> 1) & 0x55555555);
 1144           i = (i & 0x33333333) + ((i >>> 2) & 0x33333333);
 1145           i = (i + (i >>> 4)) & 0x0f0f0f0f;
 1146           i = i + (i >>> 8);
 1147           i = i + (i >>> 16);
 1148           return i & 0x3f;
 1149       }
</code>```

This code can be found in the Integer class.

I cannot help but feel stupid when I look at this. Did I miss a class or two in college or is this not something I am supposed to just get? I can do simple bit-wise operations (like ANDing, ORing, XORing, shifting), but come on, how does someone come up with a code like that above?

How good does a well-rounded programmer need to be with bit-wise operations?

On a side note... What worries me is that the person who answered my question on StackOverflow answered it in a matter of minutes. If he could do that, why did I just stare like deer in the headlights?


答:
If you went to a decent university you should have been required to take a class in Discrete Mathematics.  You would have learned binary, octal, and hexadecimal arithmetic and logic gates.

On that note it is normal to feel confused by that, if it is any consolation to you since I write web applications primarily I rarely need to look at or write code like this, but since I understand binary arithmetic and the behavior of the bitwise operators I can eventually figure out what is going on here given enough time.

Title: How good does a well-rounded programmer need to be with bit-wise operations?


答:
If you understand how to solve problems like "determine if bits 3 and 8 are set," "clear bit 5" or "find the integer value represented by bits 7-12" you have enough of an understanding of bitwise operators to check the Can Twiddle Bits box on the "well-rounded" checklist.

What's in your example comes from Hacker's Delight, a compilation of high-performance algorithms for manipulating small bits of data like integers.  Whoever wrote that code originally didn't just spit it out in five minutes; the story behind it is more likely that there was a need for a fast, branch-free way to count bits and the author had some time to spend staring at strings of bits and cooking up a way to solve the problem.  Nobody's going to understand how it works at a glance unless they've seen it before.  With a solid understanding of bitwise basics and some time spent experimenting with the code, you could probably figure out how it does what it does.

Even if you don't understand these algorithms, just knowing they exist adds to your "roundedness" because when the time comes to deal with, say, high-performance bit counting, you know what to study.  In the pre-Google world, it was a lot harder to find out about these things; now it's keystrokes away.

The user that answered your SO question may have seen the problem before or has studied hashing.  Write him and ask.


问:
Alternativates to HTML Help
We currently use a system called AsciiDoc which allows us to create documentation in a simple text markup. From that we can generate multiple output formats. We only make use of the pdf output and chm output formats.

I was wondering if there was an alternative to chm? What I am looking for is something that can be used off-line (this is important because quite a few of our users are in very remote places) with our software. It should have an index (it can be as simple as an html page with hyperlinked terms), it should be searchable and it should have a mechanism that allows specific entries to be called up from the code (similar to context sensitive help).

The two things that are against PDF in this case is:

Context sensitive help isn't an option

Generally the document is rather large

PDF is more suitable to printed documentation than context sensitive help

What I would like is to use html. The only problem with html is that I can't seem to figure out how to automatically provide a keyword search (other than the browsers ctrl+f functionality - I would like something more apparent). I also can't seem to find a method to automatically generate a hyperlinked index of key words. Context sensitive help would be simple because of the section tags - I could simply pass the url of the page and section that I am interested into the default browser and that page should load up to the correct section.

My requirements sound an awful lot like chm - they do. I modeled my requirements off chm. The only reason I don't like chm is because of the way the code interacts with it using mapids and such. I would much rather use store a plain text list (that is automatically generated for me) that my code can use to access the context sensitive portion of the documentation.

I am envisioning a script that would go through the html output files and generate an index page that simply contains a list of keywords that it found. obviously there should be word exclusion mechanism to ignore words like: the, it, is, etc.. This part would be relatively easy to write. The second part would need a script of some sort to put together a database of keywords and their location within the html text. I think this would be the tricky part along with providing the search mechanism within the browser.

Any ideas on alternatives would be appreciated. I would love to use a wiki or set of static html pages hosted on a webserver somewhere, but we have a critical offline usage requirement. Simply placing the html on the local drive doesn't provide us with the search requirements that we need.

EDIT:

I design software that is used by the mining industry. A lot of mines are very remote and do not have access to the internet in any meaningful way. There is nothing wrong with pdf or html or chm (except that it is getting old). If I could display a pdf file at the correct location (i.e. context sensitive help) I would use it. I am almost tempted to write my own - basically it would be a portable wiki. Speaking of that, if you suggest portable wiki - you have to think of the end user which may have no experience in using such tools. It has to be dead simple. That was the beauty of chm, it is a pain to work with but the end users like it.

答:
If you're prepared to author your help in DocBook XML markup rather than HTML, DocBook has support for producing WebHelp.

The WebHelp documentation is also a demo of the output: http://docbook.sourceforge.net/release/xsl/current/webhelp/docs/

It gives you a Web-based HTML help format that includes:

Full text search with:

Stemming support for English, French, and German. Stemming support can be added for other languages by implementing a stemmer.

Support for Chinese, Japanese, and Korean using code from the Lucene search engine.

Search highlighting that shows where the searched for term appears in the results.

Search results can include brief descriptions of the target.

Table of contents pane with collapsible TOC tree.

Auto-synchronization of content pane and TOC.

TOC and search pane implemented without the use of a frameset.

An Ant build.xml file to generate output.

ContentLicense: CC BY-SA 4.0

Title: Alternativates to HTML Help


答:
I happened to recognize the code because I've seen it before in software for manipulating video frames.  If you regularly worked with things like audio and video CODECs, networking protocols, or chip registers you would see a lot of bitwise operations and it would become second nature to you.

You shouldn't feel bad if your work happens to not coincide with those domains very often.  I know bitwise operations well, but I slow way down on the rare occasions I need to write a GUI, because of all the quirks with layouts and weighting and expanding and such that I'm sure are second nature to others.  Your strengths are wherever you have the most experience.


答:
Everyone should understand basic bit-wise operations. It is the composition of the basic operations to perform tasks in an optimized, robust way that takes lots of practice.

Those who work with bit manipulation everyday (like embedded folks) are, of course, going to develop strong intuition and a nice bag of tricks.

How much skill should a programmer who does not do low-level stuff have with bit-wise manipulation? Enough to be able to sit down with a stanza such as you pasted and work through it slowly like it was a brain teaser or puzzle.

By the same token, I'd say that an embedded programmer should understand as much about http as a web dev understands about bit-wise manipulation. In other words it is "OK" to not be wiz at bit manipulation if you're not using it all the time.


问:
How can I progress from a software developer to a software manager or team leader?
I've been a software developer (whether part time or full time) for almost 3 years. I've always been the type of person to have that knack for taking a lead on things, and providing the organization around getting things done. Ever since I was the lead on my senior design project back in college, I felt that this was my true calling, not sitting behind a desk coding. Now, I know I need to understand how to code for other developers to truly respect me. Also, I really do love coding. I work on plenty of side projects at home outside of work, keep up with best coding practices, and try and continuously further my knowledge of the domain.

My main question is, what type of things or opportunities should I be looking out for that will help me progress my career to a more managerial role, rather than a coding role. Like I said, I love to code, however I'd love even more to be able to design things at a high level, and organize the team in such a way to get things done, and monitor their progress, while helping out with technical decisions here and there. These types of things truly make me happy, as opposed to just sitting behind a desk coding all day long.

Obviously one of my main dreams is producing some sort of software on my own that would eventually blow up and make it big, and then beginning to hire a team and do it all myself, but I feel like the chances of that happening are far worse than just altering my career path a little to get where I want to go. I feel like I can garner that same satisfaction doing it for an employer rather than myself. Even though I haven't felt that way before, I feel like it has been mainly because I'm not doing what I TRULY want to do.

Any tips, pointers, or things to keep in mind? Anyone that has done just this, and if so, how did you do it?

答:
That sounds to me like you might want to work toward Project Management.  A large number of PM positions within software development require coding experience as well.

I would look for positions where you can grow in to responsibilities that will get you the management/leader ship you desire.  Moving up the ladder, can look different based on how things work where you are working.  But even with smaller amounts of coding experience, PM positions are available if you have any leadership, management experience.

OwnerDisplayName: anon


答:
If you want to move into a project management role then it absolutely doesn't hurt to take night classes and work towards your MBA.

Another option would be to look into the PMBOK Project Management Body of Knowledge certification.  Many places won't consider you unless you have a few years of actual leadership experience or one of the two items listed above.

The PMBOK is an extremely hard test and requires a LOT of studying to pass it.  I also think that they have requirements on actual project management and leadership experience just to be eligible to take the test.

Title: How can I progress from a software developer to a software manager or team leader?

Body:
I've been a software developer (whether part time or full time) for almost 3 years. I've always been the type of person to have that knack for taking a lead on things, and providing the organization around getting things done. Ever since I was the lead on my senior design project back in college, I felt that this was my true calling, not sitting behind a desk coding. Now, I know I need to understand how to code for other developers to truly respect me. Also, I really do love coding. I work on plenty of side projects at home outside of work, keep up with best coding practices, and try and continuously further my knowledge of the domain.

My main question is, what type of things or opportunities should I be looking out for that will help me progress my career to a more managerial role, rather than a coding role. Like I said, I love to code, however I'd love even more to be able to design things at a high level, and organize the team in such a way to get things done, and monitor their progress, while helping out with technical decisions here and there. These types of things truly make me happy, as opposed to just sitting behind a desk coding all day long.

Obviously one of my main dreams is producing some sort of software on my own that would eventually blow up and make it big, and then beginning to hire a team and do it all myself, but I feel like the chances of that happening are far worse than just altering my career path a little to get where I want to go. I feel like I can garner that same satisfaction doing it for an employer rather than myself. Even though I haven't felt that way before, I feel like it has been mainly because I'm not doing what I TRULY want to do.

Any tips, pointers, or things to keep in mind? Anyone that has done just this, and if so, how did you do it?


问:
What are the disadvantages of automated testing?
There are a number of questions on this site that give plenty of information about the benefits that can be gained from automated testing.  But I didn't see anything that represented the other side of the coin: what are the disadvantages?  Everything in life is a tradeoff and there are no silver bullets, so surely there must be some valid reasons not to do automated testing.  What are they?

Here's a few that I've come up with:

Requires more initial developer time for a given feature

Requires a higher skill level of team members

Increase tooling needs (test runners, frameworks, etc.)

Complex analysis required when a failed test in encountered - is this test obsolete due to my change or is it telling me I made a mistake?

Edit

I should say that I am a huge proponent of automated testing, and I'm not looking to be convinced to do it.  I'm looking to understand what the disadvantages are so when I go to my company to make a case for it I don't look like I'm throwing around the next imaginary silver bullet.

Also, I'm explicity not looking for someone to dispute my examples above.  I am taking as true that there must be some disadvantages (everything has trade-offs) and I want to understand what those are.

答:
I'd say the main problem with them is that they can provide a false sense of security.  Just because you have unit tests it doesn't mean they're actually doing anything and that includes properly testing the requirements.

In addition automated tests can also include bugs themselves, so that brings the question over whether unit tests need testing themselves so not necessarily achieving anything.