问:
Is C++0x Compatible with C?
I have heard that there will be a lot of changes done in C++ because of the new standard (C++0x). My question is: What are the major changes, and will C++0x be compatible with C++ 98 and C ?

答:
C++0x now is named C++11.

Since C++ never was compatible with C, i doubt that C++11 will be.

As for compatibility with C++ 98, have a look at the ISO standard for C++11.

Title: Is C++0x Compatible with C?


问:
Is it practical to use Twitter for service logs?
Recently my boss suggested that we post logs of our service that is hosted on Windows Azure into twitter. His idea is that it's conveniently readable and if Azure cloud fails logs persist. He also said, lots of people do this, I Googled and couldn't find any data about this.

Currenly my concerns are the following. First, perhaps twitter is not very convenient for logging something that can happen very frequently (for example, when our service role starts each instance writes tens of records over several minutes). Second, even if twitter EULA allows such use at this moment it might be changed in future to cut off tweets that occur too often to be human-originated.

Is it practical to post service logs on twitter? What to consider if we implement this?

答:
Use an external log server.

Twitter is neither secure, nor reliable.

You shouldn't post the logs on a publicly readable medium, since you never know if it contains sensible data or not.

ContentLicense: CC BY-SA 3.0


问:
Which framework should a ruby beginner start with: rails or sinatra?
What is the best framework for start: rails or sinatra? I heard that sinatra is more flexible but rails has a lot of documentation and tutorials. What's your choice?</p>

答:
I think it's better to start with Rails (BTW I know and like both Rails and Sinatra). Rails is certainly bigger and more complex than Sinatra, but it's easier to use and there's a smaller chance that you get stuck on something (at least from my experience).

Rails handles elegantly most of the common problems you are likely to encounter during application development, in Sinatra the solution will usually require extra effort, searching though documentation and internet. For example: exporting to xml or json.

I'd recommend this tutorial as a a starting point: Ruby on Rails Guides: Getting Started with Rails.

If you decide to start with Sinatra, the best information sources are official README and Sinatra Book.


问:
How do you annotate instantiation in UML class diagrams?
Given this pseudo code:

```<code>class B { }

class A : B
{
    int val;
};

alpha = new A();
</code>```

What arrow do I draw between alpha and A in a UML class diagram? Is this even something UML is meant to do?

```<code>+-------+        +-------+        +-------+
| alpha | --??-- |   A   |------|>|   B   |
|       |        |       |        |       |
+-------+        +-------+        +-------+
</code>```

In my case, I truly do want to express explicitly that alpha instantiates A. So if there is no way in UML, I'll just make up a way -- which is fine, but I want to know if UML can express it already. My situation is that I'm trying to explain OOP to a friend who is very visual. Therefore, I want to try to visually distinguish the two relationships (inheritance and instantiation) so that he can distinguish it mentally.

答:
In a class diagram, you don't show the act of instantiation. That is something that a sequence or communication diagram would show. Class diagrams show the static structure of a system.

If a class A "depends on" a class B, then you could look at the association and dependency relationships. Dependency is the weaker of the two and is usually used if the other class is a parameter to a method and is not stored as an instance variable. Association is stronger and means that class A contains an instance (or instances) of class B, and is further strengthened by the composition and aggregation relations.

In your example, alpha isn't part of a class. If alpha was an instance variable in some class C, you would connect C to A with an association. If it was a parameter to a method or created inside a method of C and not stored as an instance variable, you would use a dependency line to connect C to A. In all cases, you have the ability to specify directionality and multiplicity.

I think a larger problem is that you appear to be associating UML with "class diagram". The UML 2.2 specification has 14 diagram types. There are 7 structural diagrams, and 7 behavioral diagrams (broken down into 3 behavior diagrams and 4 interaction diagrams). Each diagram shows a particular view of the system. Some aspects of the system are best shown using a particular diagram, or in some cases, a series of diagrams. If you are interested, I would recommend checking out Wikipedia's entry on UML and Martin Fowler's UML Distilled. Both give great overviews of the purpose, strengths, and weaknesses of various diagram types.


问:
Tips for achieving "continual" delivery
A team is experiencing difficulty releasing software on a frequent basis (once every week). What follows is a typical release timeline:

During the iteration:

Developers work on stories on the backlog on short-lived (this is enthusiastically enforced) feature branches based on the master branch.

Developers frequently pull their feature branches into the integration branch, which is continually built and tested (as far as the test coverage goes) automatically.

The testers have the ability to auto-deploy integration to a staging environment and this occurs multiple times per week, enabling continual running of their test suites.

Every Monday:

there is a release planning meeting to determine which stories are "known good" (based on the testers' work), and hence will  be in the release. If there is a known issue with a story, the source branch is pulled out of integration.

no new code (only bug fixes requested by the testers) may be pulled into integration on this Monday to ensure the testers have a stable codebase to cut a release from.

Every Tuesday:

The testers have tested the integration branch as much as they possibly can have given the time available and there are no known bugs so a release is cut and pushed out to the production nodes slowly.

This sounds OK in practise, but we have found that it is incredibly difficult to achieve. The team sees the following symptoms

"subtle" bugs are found on production that were not identified on the staging environment.

last minute hot-fixes continue into the Tuesday.

problems on the production environment require roll-backs which blocks continued development until a successful live deployment is achieved and the master branch can be updated (and hence branched from).

I think test coverage, code quality, ability to regression test quickly, last minute changes and environmental differences are at play here. Can anyone offer any advice regarding how best to achieve "continual" delivery?

答:
Without knowing the nature of the user stories and the number of them, I have to say that a 1-week release cycle seems extreme.  The above scenario you described is intricately planned and involves a series of different branches, merge points, hand offs, environments, and test suites, more or less creating a human system where a single mistake amidst the complexity of the plan can cause late release or bad quality.  This can have a domino effect on the subsequent releases.

IMHO the schedule is just too damn tight.

You can increase code coverage by writing more effective unit tests and also environment specific integration tests.

You can increase code quality by introducing pair programming and/or code review, although that eats up at even more precious time.

Better estimation of user story points can also help by implicitly limiting the user stories that go into a single release thereby lowering the denominator on your risk ratio.

On the whole, it sounds like you have good practices in place and you have a good system to handle your extreme release cycle.  You seem to be on the right path.

OwnerDisplayName: Ben Aston

Title: Tips for achieving "continual" delivery


问:
Company wants thoughts about their site during interview
I have an initial phone interview coming up with a company for a Senior Web Developer position and in the email they asked to prepare by signing up on their site because they'd like to hear my thoughts about it and suggestions for improvement.

I've heard stories before of companies that do this.  They interview 10 people and then if everyone gives advice, then they've got a lot of free consultation.

I believe this is the first time I've ever been asked to do something like this so I wanted to hear other people's thoughts of whether it is free consulting or if I'm just being paranoid.

答:
There's a difference between asking "real world" questions and trying to get work for free; you have to judge based on the actual questions themselves.  If you don't care about the job, then if they ask blatant things that they would have to pay for if you were consulting for them, simply state that during the interview that you aren't going to do work for free, and leave (since you didn't want the job anyways, and only a true scumbag would try to hoodwink potential employees to get free work, it doesn't matter if you burn that bridge).

I've often seen companies ask real world type questions but it's always vague enough that they aren't trying to just get free work done.


答:
Sounds almost like a PHB's idea from Dilbert comics. The more I think about it, the funnier it gets. In short: No, unless you want to become laughing stock.

It won't work anyway, Twitter has strict anti-spam limits, it's meant for status updates from human and no one is likely to post 1000+ status updates per day :).

Title: Is it practical to use Twitter for service logs?

Body:
Recently my boss suggested that we post logs of our service that is hosted on Windows Azure into twitter. His idea is that it's conveniently readable and if Azure cloud fails logs persist. He also said, lots of people do this, I Googled and couldn't find any data about this.

Currenly my concerns are the following. First, perhaps twitter is not very convenient for logging something that can happen very frequently (for example, when our service role starts each instance writes tens of records over several minutes). Second, even if twitter EULA allows such use at this moment it might be changed in future to cut off tweets that occur too often to be human-originated.

Is it practical to post service logs on twitter? What to consider if we implement this?


问:
What causes floating point rounding errors?
I am aware that floating point arithmetic has precision problems. I usually overcome them by switching to a fixed decimal representation of the number, or simply by neglecting the error.

However, I do not know what are the causes of this inaccuracy. Why are there so many rounding issues with float numbers?

答:
because base 10 decimal numbers cannot be expressed in base 2

or in other words 1/10 cannot be transformed into a fraction with a power of 2 in the denominator (which is what floating point numbers essentially are)


答:
This is because some fractions need a very large (or even infinite) amount of places to be expressed without rounding. This holds true for decimal notation as much as for binary or any other. If you would limit the amount of decimal places to use for your calculations (and avoid making calculations in fraction notation), you would have to round even a simple expression as 1/3 + 1/3. Instead of writing 2/3 as a result you would have to write 0.33333 + 0.33333 = 0.66666 which is not identical to 2/3.

In case of a computer the number of digits is limited by the technical nature of its memory and CPU registers. The binary notation used internally adds some more difficulties. Computers normally can't express numbers in fraction notation, though some programming languages add this ability, which allows those problems to be avoided to a certain degree.

What Every Computer Scientist Should Know About Floating-Point Arithmetic

Title: What causes floating point rounding errors?

Body:
I am aware that floating point arithmetic has precision problems. I usually overcome them by switching to a fixed decimal representation of the number, or simply by neglecting the error.

However, I do not know what are the causes of this inaccuracy. Why are there so many rounding issues with float numbers?


问:
Is static universally "evil" for unit testing and if so why does Resharper recommend it?
I have found that there are only 3 ways to unit test (mock/stub) dependencies that are static in C#.NET:

Moles

TypeMock

JustMock

Given that two of these are not free and one has not hit release 1.0, mocking static stuff is not too easy.

Does that make static methods and such "evil" (in the unit testing sense)?  And if so, why does resharper want me to make anything that can be static, static? (Assuming resharper is not also "evil".)

Clarification:
I am talking about the scenario when you want to unit test a method and that method calls a static method in a different unit/class.  By most definitions of unit testing, if you just let the method under test call the static method in the other unit/class then you are not unit testing, you are integration testing.  (Useful, but not a unit test.)

答:
If the real question here is "How do I test this code?":

```<code>public class MyClass
{
   public void MethodToTest()
   {
       //... do something
       MyStaticClass.StaticMethod();
       //...more
   }
}
</code>```

Then, just refactor the code and inject as usual the call to the static class like this:

```<code>public class MyClass
{
   private readonly IExecutor _externalExecutor;
   public MyClass(_IExecutor executor)
   {
       _exeternalExecutor = executor;
   }

   public void MethodToTest()
   {
       //... do something
       _exetrnalExecutor.DoWork();
       //...more
   }
}

public class MyStaticClassExecutor : IExecutor
{
    public void DoWork()
    {
        MyStaticClass.StaticMethod();
    }
}
</code>```

Body:
If the real question here is "How do I test this code?":

public class MyClass
{
   public void MethodToTest()
   {
       //... do something
       MyStaticClass.StaticMethod();
       //...more
   }
}

Then, just refactor the code and inject as usual the call to the static class like this:

public class MyClass
{
   private readonly IExecutor _externalExecutor;
   public MyClass(_IExecutor executor)
   {
       _exeternalExecutor = executor;
   }

   public void MethodToTest()
   {
       //... do something
       _exetrnalExecutor.DoWork();
       //...more
   }
}

public class MyStaticClassExecutor : IExecutor
{
    public void DoWork()
    {
        MyStaticClass.StaticMethod();
    }
}


答:
In mathematics, there are infinitely many rational numbers. A 32 bit variable can only have 232 different values, and a 64 bit variable only 264 values. Therefore, there are infinitely many rational numbers that have no precise representation.

We could come up with schemes that would allow us to represent 1/3 perfectly, or 1/100. It turns out that for many practical purposes this isn't very useful. There's one big exception: in finance, decimal fractions often do pop up. That's mostly because finance is essentially a human activity, not a physical one.

Therefore, we usually choose to use binary floating point, and round any value that can't be represented in binary. But in finance, we sometimes choose decimal floating point, and round values to the closest decimal value.


答: One of the areas of work in C++0x is to improve the compatibility with C99. C++98 referenced C89. So, arguably C++0x will restore the compatibility that existed in 1998-1999, the last time current C++ was based on current C.</p>

Title: Is C++0x Compatible with C?

Body: I have heard that there will be a lot of changes done in C++ because of the new standard (C++0x). My question is: What are the major changes, and will C++0x be compatible with C++ 98 and C ?


答: Neither C++ (98) nor the new standard are fully compatible with C. Annex C of the C++ standard identifies areas in which C++ is incompatible with C. The annex is 14 pages long in both the old (98) and new (0x) versions of the standard.</p>

Title: Is C++0x Compatible with C?


答:
Well, thorsten has the definitive link.  I would add:

Any form of representation will have some rounding error for some number.  Try to express 1/3 in IEEE floating point, or in decimal.  Neither can do it accurately.  This is going beyond answering your question, but I have used this rule of thumb successfully:

Store user-entered values in decimal (because they almost certainly entered it in a decimal representation - very few users will use binary or hex).  That way you always have the exact user-entered representation.

If you have to store user-entered fractions, store the numerator and denominator (also in decimal)

If you have a system with multiple units of measure for the same quantity (like Celsius/Fahrenheit), and the user can enter both, store the value they entered and the units they entered them in.  Don't try to convert and save as a single representation, unless you can do it without loss of precision/accuracy.  Use the stored value and units in all calculations.

Store machine generated values in IEEE floating point (this can be numbers generated by an electronic measurement device, like an analog sensor with an A/D converter, or the unrounded result of a calculation).  Note that this doesn't apply if you're reading a sensor over a serial connection and it's already giving you the value in a decimal format (e.g. 18.2 C).

Store user-viewable totals, etc., in decimal (like a bank account balance).  Round appropriately, but use that value as the definitive value for all future calculations.


问:
Are there problems with using Reflection?
I don't know why, but I always feel like I am "cheating" when I use reflection - maybe it is because of the performance hit I know I am taking.

Part of me says, if it is part of the language you are using and it can accomplish what you are trying to do, then why not use it.  The other part of me says, there has to be a way I can do this without using reflection.  I guess maybe it depends on the situation.

What are the potential issues I need to look out for when using reflection and how concerned should I be about them?  How much effort is it worth spending to try to find a more conventional solution?

答:
Surely it all depends on what are you trying to achieve.

For example, I wrote a media checker application that uses dependency injection to determine what sort of media (MP3 files or JPEG files) to check. The shell needed to display a grid containing the pertinent information for each type, but it had no knowledge of what it was going to display. This is defined in the assembly that reads that type of media.

Therefore I had to use reflection to get the number of columns to display and their types and names so I could set the grid up correctly. It also meant that I could update the injected library (or create a new one) without changing any other code or configuration file.

The only other way would have been to have a configuration file that would need to be updated when I switched the type of media being checked. This would have introduced another point of failure for the application.


答:
No, it's not cheating - it is a way to solve problems in some programming languages.

Now, it is often not the best (cleanest, simplest, easiest to maintain) solution. If there is a better way, use that one indeed. However, sometimes there isn't. Or if there is, it is just so much more complex, involving a lot of code duplication etc. which makes it infeasible (difficult to maintain in the long run).

Two examples from our current project (Java):

some of our testing tools use reflection to load configuration from XML files. The class to be initialized has specific fields, and the config loader uses reflection to match the XML element named fieldX to the appropriate field in the class, and to initialize the latter. In some cases, it can build a simple GUI dialog box out of the identified properties on the fly. Without reflection, this would take hundreds of lines of code across several applications. So reflection helped us put together a simple tool quickly, without much fuss, and enabled us to focus on the important part (regression testing our web app, analysing server logs, etc.) rather than the irrelevant.

one module of our legacy web app was meant to export/import data from DB tables to Excel sheets and back. It contained a lot of duplicated code, where of course the duplications were not exactly the same, some of them contained bugs etc. Using reflection, introspection and annotations, I managed to eliminate most of the duplication, cutting down the amount of code from over 5K to below 2.4K, while making the code more robust and way easier to maintain or extend. Now that module ceased to be a problem to us - thanks to the judicious use of reflection.

The bottom line is, like any powerful tool, reflection too can be used to shoot yourself in the foot. If you learn when and how (not) to use it, it can bring you elegant and clean solutions to otherwise difficult problems. If you abuse it, you can turn an otherwise simple problem into a complex and ugly mess.

Title: Are there problems with using Reflection?

Body:
I don't know why, but I always feel like I am "cheating" when I use reflection - maybe it is because of the performance hit I know I am taking.

Part of me says, if it is part of the language you are using and it can accomplish what you are trying to do, then why not use it.  The other part of me says, there has to be a way I can do this without using reflection.  I guess maybe it depends on the situation.

What are the potential issues I need to look out for when using reflection and how concerned should I be about them?  How much effort is it worth spending to try to find a more conventional solution?


问:
What would motivate you to do free programming work for work after work?
I'm not talking about working overtime for a project, but R&D, or test bed applications that benefit the company. These would become teaching tools, and eventually sales tools. I know it sounds crazy to even ask, but I'm seeing a trend in this industry with regard to rapidly changing technology, and a problem with getting programmers to bring the after hours knowledge gained in house. You would think it would spill over naturally, but I find most leads holding back because the work would then be "managed" by the company, and now the property of the company. Are there solid programs or initiatives that stimulate a back-and-forth, where you can actually bring something to the table and be rewarded for it?

EDIT

Can anyone provide additional feedback on this:

Are there solid programs or initiatives that stimulate a back-and-forth, where you can actually bring something to the table and be rewarded for it?

There appears to be a miscommunication here, where some users are under the impression I'm trying to figure out how to get free work out of colleagues. Just the opposite is true. I want to know if there are programs that exist, or ideas that you have that would motivate you, which doesn't necessarily have to be money.

答:
I've found it possible to attract the attention of younger gang of developers to spend time on coding after work hours and weekends when the purpose was towards a common external charitable cause as part of CSR initiatives of the company. Passionate developers keep finding their own stuff to code in free time, but if you can combine learning, mentoring opportunities with a meaningful context outside project, you have a real chance at pulling them in.

This can't be of course in any way mixed up with company considerations like appraisals or rewards.


答: Reflection is just another form of meta-programming, and just as valid, as the type-based parameters that you see in most languages these days. Reflection is powerful and generic, and reflective programs are a high order of maintainability (when used correctly, of course) and more so than purely object-orientated or procedural programs. Yes, you pay a performance price- but I'd gladly go for a slower program that's more maintainable in many, or even most, cases.</p>


答: As an interviewer for a Senior Web Developer I'd certainly expect that the candidate come with not only a resume and some work examples, but also a sign that they've done some research about my company and examples of the way they can improve our product - i.e. the materials to "sell" themselves to us. I wouldn't think of this as scamming them; it's a rather normal part of the interview process, expecting the candidate to show a good reason they should be hired.

Title: Company wants thoughts about their site during interview

Body:
I have an initial phone interview coming up with a company for a Senior Web Developer position and in the email they asked to prepare by signing up on their site because they'd like to hear my thoughts about it and suggestions for improvement.

I've heard stories before of companies that do this.  They interview 10 people and then if everyone gives advice, then they've got a lot of free consultation.

I believe this is the first time I've ever been asked to do something like this so I wanted to hear other people's thoughts of whether it is free consulting or if I'm just being paranoid.


答:
a problem with getting programmers to bring the after hours knowledge
  gained in house. You would think it would spill over naturally, but I
  find most leads holding back because the work would then be "managed"
  by the company, and now the property of the company.

No, I wouldn't think it'd spill over naturally as I'd question what kind of reception would bringing in that knowledge get.  If someone brings up something that may have questionable value, is this dismissed, trivialized or put down in some way?  That is where I'd see the battleground here, not in the rewards.

Have you ever considered just how much stuff programmers may know?  It could take a long time to sift through all that stuff.  For example, if I tried to bring what was on TV last night, which would be after hours knowledge since I was watching away from work, what would that get?  In small doses it may go over fine but I'm pretty sure I couldn't spend hours in the office discussing "Jersey Shore" right?

Title: What would motivate you to do free programming work for work after work?

Body:
I'm not talking about working overtime for a project, but R&D, or test bed applications that benefit the company. These would become teaching tools, and eventually sales tools. I know it sounds crazy to even ask, but I'm seeing a trend in this industry with regard to rapidly changing technology, and a problem with getting programmers to bring the after hours knowledge gained in house. You would think it would spill over naturally, but I find most leads holding back because the work would then be "managed" by the company, and now the property of the company. Are there solid programs or initiatives that stimulate a back-and-forth, where you can actually bring something to the table and be rewarded for it?

EDIT

Can anyone provide additional feedback on this:

Are there solid programs or initiatives that stimulate a back-and-forth, where you can actually bring something to the table and be rewarded for it?

There appears to be a miscommunication here, where some users are under the impression I'm trying to figure out how to get free work out of colleagues. Just the opposite is true. I want to know if there are programs that exist, or ideas that you have that would motivate you, which doesn't necessarily have to be money.


答:
I believe this is the first time I've ever been asked to do something like this so I wanted to hear other people's thoughts of whether it is free consulting or if I'm just being paranoid.

Another possibility is that they know already what is wrong with it (with "the boss won't let us fix it") and they're looking to see how observant you are.


答:
Primarily, rounding errors come from the fact that the infinity of all real numbers cannot possibly be represented by the finite memory of a computer, let alone a tiny slice of memory such as a single floating point variable, so many numbers stored are just approximations of the number they are meant to represent.

Since there are only a limited number of values which are not an approximation, and any operation between an approximation and an another number results in an approximation, rounding errors are almost inevitable.

The important thing is to realise when they are likely to cause a problem and take steps to mitigate the risks.

In addition to David Goldberg's essential What Every Computer Scientist Should Know About Floating-Point Arithmetic (re-published by Sun/Oracle as an appendix to their Numerical Computation Guide), which was mentioned by thorsten, the ACCU journal Overload ran an excellent series of articles by Richard Harris about the Floating Point Blues.

The series started with

You're Going To Have To Think! in Overload #99 (pdf, p5-10):

Numerical computing has many pitfalls. Richard Harris starts looking for a silver bullet.

The dragon of numerical error is not often roused from his slumber, but if incautiously approached he will occasionally inflict catastrophic damage upon the unwary programmer's calculations.

So much so that some programmers, having chanced upon him in the forests of IEEE 754 floating point arithmetic, advise their fellows against travelling in that fair land.

In this series of articles we shall explore the world of numerical computing, contrasting floating point arithmetic with some of the techniques that have been proposed as safer replacements for it. We shall learn that the dragon's territory is far reaching indeed and that in general we must tread carefully if we fear his devastating attention.

Richard starts by explaining the taxonomy of real numbers, rational, irrational, algebraic and transcendental. He then goes on to explain IEEE754 representation, before going on to cancellation error and order of execution problems.

If you read no deeper than this, you will have an excellent grounding in the problems associated with floating point numbers.

If you want to know more however, he continues with

Why Fixed Point Won't Cure Your Floating Point Blues in Overload #100 (pdf, p15-22)

Why Rationals Won’t Cure Your Floating Point Blues in Overload #101 (pdf, p9-13)

Why Computer Algebra Won’t Cure Your Floating Point Blues in Overload #102 (pdf, p9-14).

Why Interval Arithmetic Won’t Cure Your Floating Point Blues in Overload 103 (pdf, p19-24)

He then switches to trying to help you cure your Calculus Blues

Why [Insert Algorithm Here] Won’t Cure Your Calculus Blues in Overload 104 (pdf, p22-24).

Why Finite Differences Won’t Cure Your Calculus Blues in Overload 105 (pdf, p5-12).

Why Polynomial Approximation Won't Cure Your Calculus Blues in Overload 106 (pdf, p16-25).

Why Computer Algebra Won’t Cure Your Calculus Blues in Overload 107 (pdf, p15-20).

and last but not least, there is

Why Automatic Differentiation Won’t Cure Your Calculus Blues in Overload 108 (pdf, p4-11).

The whole series of articles are well worth looking into, and at 66 pages in total, they are still smaller than the 77 pages of the Goldberg paper.

While this series covers much of the same ground, I found it rather more accessible than Goldberg's paper. I also found it easier to understand the more complex parts of the paper after reading the earlier of Richards articles and after those early articles, Richard branches off into many interesting areas not touched on by the Goldberg paper.

As thus spake a.k. mentioned in comments:

As the author of those articles I'd like to mention that I have created interactive versions of them on my blog www.thusspakeak.com starting with thusspakeak.com/ak/2013/06.

ContentLicense: CC BY-SA 4.0


答: It totally depends. An example of something that would be hard to do without reflection would be to replicate ObjectListView. It also generates IL code on the fly.</p>


问:
How do I sell my software on the Internet?
I'd like to sell my software on the 'net but am not sure how to do the whole Merchant setup.  I have access to Commerce Server 2009, and I want to seem professional so a plain old PayPal account is out.

What do I need to know/do to sell a few things using ASP.NET, accept credit cards, and what not?

答: Personally, I'd just use a payment processor such as WorldPay if it's a small business. You would have to pay them a commission for processing payments on your behalf, but you don't have to worry too much about security on your end, and the liability for security (IANAL, make sure you read the T&Cs carefully) gets shifted to them.</p>

ContentLicense: CC BY-SA 2.5


答:
Reflection is fantastic for building tools for developers.

As it allows your build environment to inspect the code and potentially generate the correct tools to manipulate/init inspect the code.

As a general programming technique it can be useful but is more brittle than most people imagine.

One really development use for reflection (IMO) is that it makes writing a generic streaming library very simple (as long as your class description never changes (then it becomes a very brittle solution)).


答:
There's a difference between getting people to do free work for work after hours and people learning something new because they are interested in it. You seem to be implying that be default what people do in their own spare time should be somehow leverageable for the company. This is not actually fair. </p>

<p>You need to look at Google's 20% practice - I think something like this might be beneficial although few enough companies implement it - in this way your company may benefit more by allowing time to your developers and staff rather than leeching off their spare time activities. As far as bringing ideas to the table are concerned, you need to put a reward and recognition scheme in place as well. </p>

Body:
There's a difference between getting people to do free work for work after hours and people learning something new because they are interested in it. You seem to be implying that be default what people do in their own spare time should be somehow leverageable for the company. This is not actually fair.

You need to look at Google's 20% practice - I think something like this might be beneficial although few enough companies implement it - in this way your company may benefit more by allowing time to your developers and staff rather than leeching off their spare time activities. As far as bringing ideas to the table are concerned, you need to put a reward and recognition scheme in place as well.


答: If you want people sharing what they know from side and hobby projects, what you need is to offer meeting space, a projector, pizza, and beer. Given that, most developers will happily talk about what they've been working on.</p>


答: Nothing would motivate me unless it was my own company, or I was a partner in the company.  Otherwise, I'll do personal projects outside of work for my own learning, but I won't do work for my job after-hours without compensation (whether tangible pay, flex time, or similar).</p>


答: Stick with Rails; you'll learn more overall as a beginner to Ruby.  When you've learned enough and/or run into the walls that can happen when working with Rails, then look at a more freeform framework like Sinatra.  If you start with Sinatra first, you'll have to do most everything yourself and as a beginner that can be fairly daunting and frustrating.</p>

Title: Which framework should a ruby beginner start with: rails or sinatra?

Body: What is the best framework for start: rails or sinatra? I heard that sinatra is more flexible but rails has a lot of documentation and tutorials. What's your choice?</p>


答:
It's not cheating. But it is usually a bad idea in production code for at least the following reasons:

You lose compile-time type safety - it's helpful to have the compiler verify that a method is available at compile time. If you are using reflection, you'll get an error at runtime which might affect end users if you don't test well enough. Even if you do catch the error, it will be be more difficult to debug.

It causes bugs when refactoring - if you are accessing a member based on its name (e.g. using a hard-coded string) then this won't get changed by most code refactoring tools and you'll instantly have a bug, which might be quite hard to track down.

Performance is slower - reflection at runtime is going to be slower than statically compiled method calls/variable lookups. If you're only doing reflection occasionally then it won't matter, but this can become a performance bottleneck in cases where you are making calls via reflection thousands or millions of times per second. I once got a 10x speedup in some Clojure code simply by eliminating all reflection, so yes, this is a real issue.

I'd suggest limiting the use of reflection to the following cases:

For quick prototyping or "throwaway" code when it is the simplest solution

For genuine reflection use cases, e.g. IDE tooling that allows a user to examine the fields/methods of an arbitrary object at runtime.

In all other cases I'd suggest figuring out an approach that avoids reflection. Defining an interface with the appropriate method(s) and implementing it on the set of classes you want to call the method(s) on is usually sufficient to solve most simple cases.


问:
Why shouldn't "responsive" web design be a consideration?
This might seem like more of a graphic design question than a programming question, but I think it has much more technical/programming merit than actual graphic design.

The concept of "responsive" web design revolves around using media queries in CSS3 to detect the size of the viewing device and adjust the CSS rules accordingly - essentially, dynamic CSS. This fills the void on a lot of deployment cases - mobile, in particular.

I think use of media queries is surfacing slowly (I've found that many people don't really know about it), but I'm wondering if there is a reason for slow adoption. Is it impractical for web applications? Is there something I'm missing that might be a fundamental pitfall?

答:
I can't speak for everyone, but from my own experience time and money has been the deciding factor. My colleagues and I are always looking at the latest stuff, but designing and implementing different layouts for differently sized devices is a big deal. Especially considering that on my 3 year old nokia 5800 all our websites look fine - bar that I have to scroll to get the sidebar content. We design and implement websites for small companies and self-employed folk.

Another reason that may be valid is that serving a completely separate website for mobile versions, with its own separate sitemap ( http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=34648 ), is an easy and entry-level way to maintain the site.


答:
If they're asking you for a 12 page report on specific lines of code, I can understand the paranoia.  If that's how they're interviewing, then you'd better think twice about working there.

However, we - a smaller tech agency, consider questions like that par for the course.  It's probably the first question you'll be asked if they hire you, so I think there's some paranoia here for sure (yes, I read the maths above, and yes, they do have some merit in some cases).

It's not unusual to ask someone to complete a small task or project, or ask for improvements to a product.  In terms of my experience having been on both sides of the table, I'm always looking for positive and results oriented team members, and I'm often looking for specific examples.  Why?  Well, there are a lot of people who can talk, or point to work experience, but when it comes right down to it, a lot of people expand their roles in projects or "boast" a little bit on their resumes.  It's so important to be able to demonstrate your awesomeness when you're interviewing, and you could look at this as an opportunity to do just that.

If you don't feel like that's what they're giving you, interview somewhere else. :)

Jonathan


答:
No way is it cheating... Rather, it empowers application servers to run the classes made by the user with the name of their choice, hence providing flexibility to the user, not cheating them.

And if you want to see the code of any .class file (in Java) then there are several decompilers available free of charge!


问:
How far can I push refactoring without changing external behavior?
According to Martin Fowler, code refactoring is (emphasis mine):

Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior. Its heart is a series of small behavior preserving transformations. Each transformation (called a 'refactoring') does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.

What is "external behaviour" in this context? For example, if I apply move method refactoring and move some method to other class, it looks like I change external behaviour, doesn't it?

So, I'm interested in figuring out at what point does a change stop being a refactor and becomes something more. The term "refactoring" may be misused for larger changes: is there a different word for it?

Update. A lot of interesting answers about interface, but wouldn't move method refactoring change the interface?

答:
By "external behaviour" primarily he is talking about the public interface, but this also encompasses outputs/artifacts of the system as well. (ie you have a method that generates a file, changing the format of the file would be changing the external behaviour)

e: I'd consider the "move method" a change to external behaviour.  Bear in mind here that Fowler is talking about existing code bases that have been released into the wild.  Depending on your situation you may be able to verify that your change does not break any external clients and proceed on your merry way.

e2: "So what is the right word for reworks which change external behaviour?" -- API Refactoring, Breaking Change, etc...its still refactoring, its just not following the best practices for refactoring a public interface that is already in the wild with clients.


问:
Is SQL important if I know ORM frameworks well?
I don't have any serious experience in SQL and I even hate to write SQL instead of LINQ. I am happy enough with ORMs.

From the employers and sector view point, is it important to know SQL? Do I have to master on it? Are companies that prefer pure SQL over ORM frameworks a "dinosaur" in the programming world?

答: Even with a good, mature ORM you are inevitably going to run into situations where its emitting some inefficient SQL and its going to make your life a lot easier if you can grok what's going on in the generated SQL.  That said, if you're very proficient with the ORM and know how to use a profiler for your DB of choice you could pretty easily "fake it til you make it".</p>


问:
How to learn Agile as a Solo Developer

Possible Duplicate:

  What good book shoud I buy to learn Agile from scratch?

It seem that Agile for the solo developer is a good idea.

But how to learn it?

Is there any good book, web reference or course that a solo developer could start from?

答:
I think Clean Code: A handbook of Agile Software Craftsmanship, is a great resource.

This book will make you a better developer, not only a better programmer. Surely a must read!

http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882

Title: How to learn Agile as a Solo Developer


答:
Reflection can achieve things that simply can't be done practically otherwise.

For example, consider how to optimize this code:

```<code>int PoorHash(char Operator, int seed, IEnumerable<int> values) {
    foreach (var v in values) {
        seed += 1;
        switch (char) {
            case '+': seed += v; break;
            case '^': seed ^= v; break;
            case '-': seed -= v; break;
            ...
        }
        seed *= 3;
    }
    return seed;
}
</code>```

There's an expensive test smack in the middle of the inner loop, but extracting it requires rewriting the loop once for each operator. Reflection allows us to get performance on par with extracting that test, without repeating the loop a dozen times (and thereby sacrificing maintainability). Just generate and compile the loop you need on the fly.

I have actually done this optimization, although it was a bit more complicated of a situation, and the results were amazing. An order of magnitude improvement in performance and fewer lines of code.

(Note: I initially tried the equivalent of passing in a Func instead of a char, and it was slightly better, but not nearly the 10x reflection achieved.)

Body:
Reflection can achieve things that simply can't be done practically otherwise.

For example, consider how to optimize this code:

int PoorHash(char Operator, int seed, IEnumerable<int> values) {
    foreach (var v in values) {
        seed += 1;
        switch (char) {
            case '+': seed += v; break;
            case '^': seed ^= v; break;
            case '-': seed -= v; break;
            ...
        }
        seed *= 3;
    }
    return seed;
}

There's an expensive test smack in the middle of the inner loop, but extracting it requires rewriting the loop once for each operator. Reflection allows us to get performance on par with extracting that test, without repeating the loop a dozen times (and thereby sacrificing maintainability). Just generate and compile the loop you need on the fly.

I have actually done this optimization, although it was a bit more complicated of a situation, and the results were amazing. An order of magnitude improvement in performance and fewer lines of code.

(Note: I initially tried the equivalent of passing in a Func instead of a char, and it was slightly better, but not nearly the 10x reflection achieved.)


问:
Are there any private code review communities?
Similar to this question https://softwareengineering.stackexchange.com/q/77466/20799, are there any communities out there where I can get my code reviewed. Ideally this would be a private thing between you and the reviewer as it would be large chunks of a full, commercial project, the the whole thing would have to be under NDA or similar.

I'm aware of codereview.stackexchange.com but that's not viable as I don't want to put the code in the public domain and the code would be too big for the format of the Q&A site.

答: Your best idea is to contract a developer and get him to sign a NDA (non disclosure agreement). Anything posted on any public website will be in the public domain.</p>


答: I would head out to your local language meetup group and make some friends. Then you can work something out to review each other's code privately. You can add them as collaborators on GitHub.</p>

Title: Are there any private code review communities?

Body:
Similar to this question https://softwareengineering.stackexchange.com/q/77466/20799, are there any communities out there where I can get my code reviewed. Ideally this would be a private thing between you and the reviewer as it would be large chunks of a full, commercial project, the the whole thing would have to be under NDA or similar.

I'm aware of codereview.stackexchange.com but that's not viable as I don't want to put the code in the public domain and the code would be too big for the format of the Q&A site.


答:
I agree with @Thomas Owens that class diagrams in UML are not meant to show instances in general. However, I must add that UML does provide mechanisms to depict instantiation:

the InstanceSpecification element provides a way to model instances, such as alpha in your example.

the dependency notation (a dashed arrow with plain arrowhead), flowing from the instance to its type, and adorned with the stereotype <<instanceOf>>, provides a way to model the instantiation relationship between an instance and its classifier(s).

Title: How do you annotate instantiation in UML class diagrams?

Body:
Given this pseudo code:

```<code>class B { }

class A : B
{
    int val;
};

alpha = new A();
</code>```

What arrow do I draw between alpha and A in a UML class diagram? Is this even something UML is meant to do?

```<code>+-------+        +-------+        +-------+
| alpha | --??-- |   A   |------|>|   B   |
|       |        |       |        |       |
+-------+        +-------+        +-------+
</code>```

In my case, I truly do want to express explicitly that alpha instantiates A. So if there is no way in UML, I'll just make up a way -- which is fine, but I want to know if UML can express it already. My situation is that I'm trying to explain OOP to a friend who is very visual. Therefore, I want to try to visually distinguish the two relationships (inheritance and instantiation) so that he can distinguish it mentally.


问:
Silverlight 5 In or Out of Browser?
I'm deciding which I need for my new LOB application. I will list PRO's of each and if I'm wrong - correct me please as this is how I see it.

In Browser

Users can navigate using URL's. I see it as a BIG thing. Users can share links like  app.com/orders/12345

With elevated permissions I can do all the same stuff. Use COM, file system, etc.

I can open other browser windows with other functionality if multi-window needed. The only difference - I won't have such control over those windows as with out of browser.

Out of browser

Runs out of browser. Not sure why I care?

More problematic to handle updates

Yes, there is windows I can open but not modal. So, in-browser separate IE window almost identical

Do I miss anything? I tend to keep it in browser but I want to see where I'm limiting myself.

答:
Note that your #2 of having elevated permissions in browser is only available with Silverlight 5.  If you want to deploy to production soon, and need to do COM automation, you have to use out-of-browser.

I don't believe it is more problematic to handle updates with out-of-browser as you state.  Even though the application is "installed" it is really just a pointer to the same Silverlight app deployed on your web server.  If you push new bits, your out-of-browser users will execute the new bits the next time they launch the app.

In general for LOB apps I prefer in-browser for the same reasons you list.  Also, our portfolio has a mix of Silverlight and ASP.NET apps so in-browser allows for them to look more consistent between each other.

I would only go with out-of-browser when it was important to the users to launch directly from the desktop and have control of the entire screen.  For certain applications like game, having the chrome of the browser surrounding the application might be a downside.

Title: Silverlight 5 In or Out of Browser?


问:
Did jQuery kill the JavaScript discussions?
There are over 100,000 questions on Stack Overflow tagged as questions relating to JQuery troubleshooting/usage.  Compare this to the 124,000 questions on stack overflow that are tagged for JavaScript issues.  We are very close to almost half of all JavaScript related questions on Stack Overflow being attributed to JQuery (plus or minus any margin for the few other JS frameworks that get questions on SO).

What I'm getting at is, jQuery is not a language and it is not the be all and end all of frameworks that must be applied to every scenario in which JavaScript is present, yet it is quickly catching (and I predict will soon eclipse) JavaScript as a source of discussion/inquiry on sites like Stack Overflow.

Is jQuery killing the JavaScript star?  Is there no longer a firm grasp by the next generation of web developers regarding the power, simplicity and use of JavaScript as a means for DOM manipulation?  Is this just the natural evolution of things and the viewpoint I'm presenting typical of the coder's ego (i.e., is this how assembly programmers view the .NET/Java/Web crowd?) or is this really the beginning of the end of the true JavaScript developer?

答:
No, jQuery does not kill JavaScript, rather it unfolds the language.

There's Nodejs, that uses Javascript as cli or for server-side scripting.

About jQuery. I was programming with DOM APIs since 2001 and can assure you that a simple and well-tested DOM API like jQuery lets you work more on the real problem rather than on the API.

I also manipulated DOM in raw Javascript in 2005, and most of the time I spent making it work cross-browser.

Before jQuery, lots of us were spending time on fixing the browser differences and bugs, independently and with little code sharing. We repeated the same work and the same mistakes over and over. jQuery relieved us of this duty. Nowadays, with plenty of jQuery plugins, I work mostly on my problem field, but also can do much more complicated manipulations of the document. Only liberated from DOM headaches I could learn the real power of closures and the JS event loop (must see for any js programmer!)

Most Javascript programmers use jQuery to manipulate the DOM, hence most questions regard this area and jQuery.

There are alternatives to jQuery:

Prototype, it has many entry points (which is confusing), and contains time bombs (It adds some methods to the built-in objects, but only those that aren't in the objects yet. When browser developers implement them in the near future, the objects will change behavior and many sites will stop working. The developers will have to urgently fix their websites.)

RightJS (can't say anything, but seems to have a nice API)

Node.js is a rapidly developing environment, and in a couple of years it may become mainstream server language. My impressions of it is that yet there lack a lot of features that could make the language look more elegant. Right now it takes a lot of effort to organize your code. Can't say if it's fixable with a framework like jQuery or only with a new language version, but be sure this will be addressed by someone, there's enough momentum around Node.js and JS in general.


答:
I'd view it as being closer to the standard library in C++ than to the .Net/Assembly analogy. Or even better, .Net and C#. There is nothing in the C# spec that states that you have to use .Net, but it's tied rather closely together. But anyway, as to your question, most web developers don't care about JavaScript.

In fact, I'd argue that the DOM manipulation part of JavaScript is fairly terrible (especially considering various browsers made it a pain to get stuff to work everywhere). I don't think you could have put something else in there and received a better result, but for years it was a point of frustration (once again usually due to browser makers). Most people would just hack something together prior to jQuery and call it a day (and would proclaim themselves "experts" much of the time). jQuery simply takes the parts that no one liked and puts a nicer face on it. Since that's the main use of JS for now (DOM manipulation), you'll see jQuery pop up more and more (or some other framework like Prototype, etc.). Just so you're aware I don't think the average web developer was a great JS developer prior to jQuery. I think with or without it people aren't going to learn the language (not to a point where they actually know the language anyway).

That being said, JavaScript is doing well as a language. Node.js is a good example of it picking up use as an actual language. I've even looked into using it as an embedded scripting language in some of my apps (lost out to LUA, but only because LUA took less time to set up).

Title: Did jQuery kill the JavaScript discussions?

Body:
There are over 100,000 questions on Stack Overflow tagged as questions relating to JQuery troubleshooting/usage.  Compare this to the 124,000 questions on stack overflow that are tagged for JavaScript issues.  We are very close to almost half of all JavaScript related questions on Stack Overflow being attributed to JQuery (plus or minus any margin for the few other JS frameworks that get questions on SO).

What I'm getting at is, jQuery is not a language and it is not the be all and end all of frameworks that must be applied to every scenario in which JavaScript is present, yet it is quickly catching (and I predict will soon eclipse) JavaScript as a source of discussion/inquiry on sites like Stack Overflow.

Is jQuery killing the JavaScript star?  Is there no longer a firm grasp by the next generation of web developers regarding the power, simplicity and use of JavaScript as a means for DOM manipulation?  Is this just the natural evolution of things and the viewpoint I'm presenting typical of the coder's ego (i.e., is this how assembly programmers view the .NET/Java/Web crowd?) or is this really the beginning of the end of the true JavaScript developer?


问:
Will my communication skills be wasted in a software engineering career?
I've been in the financial engineering arena (after BA Math and BA Computer Science) for about 5 years (20% analysis/programming, 80% communicating) and take pride in my ability to communicate with people and discuss technical problems (i.e. interacting with a team).  I love this part of my job.  Going to the white board to draw abstract ideas and brainstorm.

However, for many reasons, I want to transition my career into a technology company (software engineering) but I'm deeply afraid that I will fall into a stereotypical programming job where programmers code with big headphones on.  I certainly know this is only a stereotype but I've witnessed similar environments before (at startups) and it scares me to think that I would be migrating to a career of isolation.

I love coding and thinking algorithmically, but I don't want to give up interacting with people. I understand that having communication skills is only a positive, but am I setting myself up for career-happiness failure by transitioning into software engineering.  I'd love to hear any clarifications and/or advice.

答:
The programmers might like to code with big headphones on (well, not all of them do), but that doesn't mean they can't communicate, it just means that they do not want to be disturbed at that moment - not that they will never communicate.

Verbal communication skills are still extremely important in meetings with the rest of the team, in ad-hoc meetings, with business users, with other teams, etc.

Written communication skills will also be very important when you email your coworkers with big headphones so they can reply to you later.


答: Communication skills are extremely important to a software developer. Somewhere there is a stat (possibly next to the stat that says 68% of all statistics are made up) that says that a majority of software projects fail because of poor communication. Being the person that can communicate with the business (and understand the business) on a software development team HAS to be a good place to be.</p>

Title: Will my communication skills be wasted in a software engineering career?

Body:
I've been in the financial engineering arena (after BA Math and BA Computer Science) for about 5 years (20% analysis/programming, 80% communicating) and take pride in my ability to communicate with people and discuss technical problems (i.e. interacting with a team).  I love this part of my job.  Going to the white board to draw abstract ideas and brainstorm.

However, for many reasons, I want to transition my career into a technology company (software engineering) but I'm deeply afraid that I will fall into a stereotypical programming job where programmers code with big headphones on.  I certainly know this is only a stereotype but I've witnessed similar environments before (at startups) and it scares me to think that I would be migrating to a career of isolation.

I love coding and thinking algorithmically, but I don't want to give up interacting with people. I understand that having communication skills is only a positive, but am I setting myself up for career-happiness failure by transitioning into software engineering.  I'd love to hear any clarifications and/or advice.


答:
You'll be better off with great communication skills. Heads-down programmers are often the ones that are not put on the exciting projects, since their managers might not understand them as well. Essentially, if you never come up for air, you will be pigeonholed as "the weird guy in the corner".

Again, we're working on stereotypes, and not every environment is like that, but at the very least, good communication skills help you understand the business and the people around you better, so you will become better equipped to handle complex problems in your particular domain.

How much you communicate is up to you. It would be rare for you to end up in a team that's full of heads-down programmers with nobody that wants to talk, but if you're not kin to nerd humor, prepare to be introduced quickly. Also, be prepared for the inevitable socially awkward programmers. There's always at least one.


答: Arguably, most software projects fail not because of technical problems, but because of communication problems. Writing great code is certainly important for a software engineer, but good communication skills are a huge asset to a team - and also harder to improve than coding skills.</p>


答:
I am currently programming with big headphones on.  Well, I was just programming.  Clearly I'm now on StackExchange...anywho:

It's true that a lot of programming is done in solidarity.  In order to program well, you NEED that focus and privacy.  However, do you really even think that most of your time is spent programming?  A lot of your time will be split amongst team meetings, strategy talk, walking, thinking, discussing etc.  Actually sitting at your desk typing won't be your whole life. I remember reading a study in my software engineering course that the best/most-productive programmers on a team are the outgoing ones and NOT the introverts.

Good programmers can communicate well with their team.  Getting and understanding requirements from a technical lead or manager is often not an easy task.  It takes good communication skills to clarify your tasks, as well as to communicate with the team.  If you work your way up to technical lead or manager, communication skills will be pivotal for holding the team together.

I too am someone who loves to be outgoing.  I have to admit, at first, I found the amount of solidarity in my programming job a little depressing.  I took some steps to make the job more social though, mainly:
1) Refusing to eat lunch alone
2) Taking gym/basketball breaks with friends

A programming job shouldn't be anti-social.


答:
There will come a time when you have to optimize something complex that the ORM is creating. At that point you generally have an extremely complex query to break down. If you never learned basics, how can you expect to start learning SQL with the advanced stuff? You won't understand enough to even start. ORMs in the hands of a person who understands SQL  - a good tool. ORMs in the hands of someone who deosn't know SQL at all - disaster waiting to happen.

One of the reasons why SQL is critical to understanding databases is that application programmers don't naturally think in terms of data sets. But the only way databases operate at all efficiently is by sets. You need to learn how to think in sets before you even attempt to use an ORM.

Title: Is SQL important if I know ORM frameworks well?

Body:
I don't have any serious experience in SQL and I even hate to write SQL instead of LINQ. I am happy enough with ORMs.

From the employers and sector view point, is it important to know SQL? Do I have to master on it? Are companies that prefer pure SQL over ORM frameworks a "dinosaur" in the programming world?


答: It sounds to me like you should look for a job as a technical consultant. It often involves programming, but also requires a lot of communication - with customers, with colleagues, consultants of other companies... OTOH it also means fixing a lot of technical issues without actually writing code, if you don't like that you should probably look for different paths. HTH.</p>


答:
You could certainly make that argument that jQuery killed javascript discussion, and this trend graph would support it:
http://www.google.com/trends?q=jquery%2C+javascript

Its pretty easy to observe this on your message board of choice as well.  Anytime a "how do you do xxx in javascript?" question gets asked, you can almost bet that the answers are going to be in the format of "use jQuery and just do yyy".

I'd say its more accurate to say that now its more common to discuss javascript in terms of higher level frameworks (whether this is something like a jQuery/prototype or knockout/backbone or node.js or ...)


答:
Reflection is an awesome tool if you are a library author, and thus have no influence over the incoming data. A combination of reflection and meta-programming can allow your library to work seamlessly with arbitrary callers, without them having to jump through hoops of code-generation etc.

I do try to discourage from reflection in application code, though; at the app layer you should be using different metaphors - interfaces, abstraction, encapsulation etc.


问:
How does office bureaucracy affect code quality
I'm interested in stories where office bureaucracy has had direct effect on the final code quality result.

For example, a friend just told me that at his previous work place the version control system was so bulky that programmers were not allowed to create new "modules" (root directories in the source tree) without asking permissions from the VCS gods. The result was that programmers were unwilling to go through the extra bureaucratic step and instead of properly componentizing their services they ended up piling unrelated functionality on top of existing modules even when functionality was just remotely related to the current definition of the module or the module's name was way in the past. (not to mention renaming a module...)

I'm interested in similar stories of office, operational or any other bureaucracy that eventually, perhaps unintentionally affected software quality

答: On a recent project, quality people had many requirement regarding formal unit tests (traceability, coding rules, formal reviews, ...). The coders no longer write unit tests, they only debug their code. This is the same task just renamed, leads to the same technical results, but without the administrative hassle.</p>


问:
Silverlight - modularity. Best way to physically separate binaries?
We are working on LoB app with lot's of content. XAP download will be rather large I think for one time download. I'm planning to break solution into separate projects.

Not sure why - but I DO NOT like many many projects in solution. IMO it is not very good idea. Even when we were working as a large team - it was pain with many projects.

Even now when I'm using MEF/PRISM - there still going to be some core dependencies like:

PRISM libraries

Interfaces

Navigation

Shell/Bootstrapper

App styles

Converters/Commands/Validators

etc.

And than I'm going to have modules that will use all that CORE stuff. Modules will have following inside them:

RIA Services client side

ViewModel's

Views

Those modules will be loaded on demand using MEF. I think size-wise all those modules will be larger than core module because of ammount of logic in them.

I expect to have about 5-6 modules and CORE. I think that will give me reasonable number of client-side projects and libraries/XAPS and it will be manageable solution to work with.

Do you see any issue with breakdown like this? Some online videos will make 7+ projects out of CORE module. What's a point? I think it adds to complexity. Than they show 3-4 DLL out of module. One for views, one for viewmodels and so on. They still need to be loaded together so why?

I'm looking for do's and dont's from you guys who went through this..

Thank you!

答:
Why do you feel that a solution with multiple projects is a BAD IDEA?

If your only doubt about this approach is that the solution will become cluttered then you can simply create multiple solutions, each with a different development perspective.

Solution == Perspective Approach

A solution is merely a collection of projects and defines building a series of projects.  In my project setups I will typically have a Server side Solution, Business Entity Solution, a number of different Presentation Layer solutions and a Master solution that builds all projects.

Projects in the Server Side Solution may be in the Business Entity Solution as well.  This way developers only need to develop in the solution/perspective which is applicable to them.  This avoids the clutter of large numbers of projects.


问:
Why did Microsoft make parameters, local variables and private fields have the same name naming convention?
I asked this question quite some time ago: How do you name your private variables in C#?

In one of the answers, I was pointed to Microsoft's MSDN page that shows that private variables/fields should be named like this:

```<code>private int myInteger;
</code>```

But a parameter would be:

```<code>void SomeMethod(int myInteger)
</code>```

and a local variable would be like this:

```<code>int myInteger;
</code>```

So when you reference them like this

```<code>myInteger = 10;
</code>```

you have no way of knowing which one you are talking about.

I am now starting a new project and one of my co-workers is asking me why we don't do something to differentiate at least some of these.

I am wondering the same thing.  Why didn't Microsoft's standard keep these different?

答: I can't answer your question about Microsoft's standards. If you want a standard to differentiate these things, the standard I use for PL/SQL parameters is prefixing the parameter name with in_, out_, io_, for in-, out-, and in-out- parameters. Variables that are local to a function are prefixed with a v_.


答:
I agree with everyone here that argues communication is key in computer programming. I honestly think that from what is described, you will make a great lead programmer or more of the 'software engineer' type. I started out as general IT in a company and as soon as I was able to prove my programming skills I transitioned to programmer, being I am very social and team-oriented out-going I am now the lead programmer on two projects. You will find that the higher you get on the programming chain, the more white board and problem solving you will start doing.

If your personality has the 'leadership' trait (which is what you are hinting to), you will rise to the top very fast. Just providing that you are in a company that lets you rise in that way.

Social skills, problem solving, and good programming is often rarer than you may think. Employers kill for that kind of skill. I think your on the right track. Just keep up the good work!


答:
Most companies I know have coding standards that specify either an underscore or the lowercase letter m (for "member" I assume) as a prefix for their member variables.

So

_varName

or

mVarName

Title: Why did Microsoft make parameters, local variables and private fields have the same name naming convention?

Body:
I asked this question quite some time ago: How do you name your private variables in C#?

In one of the answers, I was pointed to Microsoft's MSDN page that shows that private variables/fields should be named like this:

```<code>private int myInteger;
</code>```

But a parameter would be:

```<code>void SomeMethod(int myInteger)
</code>```

and a local variable would be like this:

```<code>int myInteger;
</code>```

So when you reference them like this

```<code>myInteger = 10;
</code>```

you have no way of knowing which one you are talking about.

I am now starting a new project and one of my co-workers is asking me why we don't do something to differentiate at least some of these.

I am wondering the same thing.  Why didn't Microsoft's standard keep these different?


答:
I can't tell you for sure why they didn't keep them different. It's likely that nobody can unless someone who took part in creating the standards happens to see this question.

Many people create their own conventions by prefixing instance variables with _ or m_, but  I really don't think it matters. You can infer a lot from context and IDEs these days are smart enough to help you out. Visual Studio with the ReSharper addon, for example, will show you local variables and instance variables in different colours.

If it really matters that you differentiate between the two scopes, you can use the this. prefix to refer to the instance variable:

```<code>public class Test
{
    private int myInteger;

    void SomeMethod(int myInteger)
    {
        this.myInteger = 10; // sets instance variable to 10
        myInteger = 10; // does not affect the instance variable.
    }
}
</code>```

Without any other plugins, Visual Studio will by default help you with Intellisense:

(The pop-up may still be styled by ReSharper there, but ReSharper doesn't add anything to the features of built-in Intellisense, so while the stock one might look a little different, it'll still have both options in there.)

You can also use code analysis tools like FxCop and StyleCop to help you catch potential problems with variable naming and scope.

Body:
I can't tell you for sure why they didn't keep them different. It's likely that nobody can unless someone who took part in creating the standards happens to see this question.

Many people create their own conventions by prefixing instance variables with _ or m_, but  I really don't think it matters. You can infer a lot from context and IDEs these days are smart enough to help you out. Visual Studio with the ReSharper addon, for example, will show you local variables and instance variables in different colours.

If it really matters that you differentiate between the two scopes, you can use the this. prefix to refer to the instance variable:

public class Test
{
    private int myInteger;

    void SomeMethod(int myInteger)
    {
        this.myInteger = 10; // sets instance variable to 10
        myInteger = 10; // does not affect the instance variable.
    }
}

Without any other plugins, Visual Studio will by default help you with Intellisense:

(The pop-up may still be styled by ReSharper there, but ReSharper doesn't add anything to the features of built-in Intellisense, so while the stock one might look a little different, it'll still have both options in there.)

You can also use code analysis tools like FxCop and StyleCop to help you catch potential problems with variable naming and scope.


答:
Here's the secret about programming: it is almost 100% communication. A significant part of that is communicating with a human; the rest is communicating what you've just learned to a computer.

The latter part is the easier of the two. Computers do exactly what they're told and you are always in a position to test that what you told it is correct.

The former is something else. Differences in terminologies, in understanding, in priorities, from person to person make it very difficult to get the correct message to feed to the computer. Miscommunications at this level are much more common than miscommunications between a programmer and a computer.

Good programmers are good at communicating with the computer; great programmers are good at communicating with people too, by one medium or another.

Those programmers you see that never come out of their headphones? They're still doing this communication, whether it be via email or a bug-tracker, or even messenger. It's all happening, otherwise they can't possibly know what to tell the computer to do.

So yes, your communication skills will serve you well.


答: Communication skills will definitely not be wasted. Even if you spend 80% of your time writing program code, you need to be clear on what the code does. Effective communication with your client (or project leader) is necessary to ensure your efforts are not wasted, and actually result in what is required. Additionally, you will be able to explain your work, potential issues with design, simpler implementations, etc more easily to those less familiar with programming. Lastly, when programming user-interactive software, communication skills would be quite helpful in designing a user interface that gets the correct information across in a user-friendly way that will be understood. It will also help you get the correct information from the user to perform the job.</p>


答:
local and parameter variables are named the same way because their scope is the same

As for private variables, there are different opinions on that. I've always used the standards found here, which specifies to use a leading _ before private variables, although the author does say that the _ is a bit controversial and that Microsoft recommends against it.

Wikipedia states that in C and C++

Names beginning with double underscore or an underscore and a capital
  letter are reserved for implementation (compiler, standard library)
  and should not be used (e.g. __reserved or _Reserved).

so perhaps that was the reason behind Microsoft recommending against that, although it is fairly well known that many Microsoft devs use an _ prefix for their private variables anyways.


答:
I agree with everyone else who says that there's plenty of communication in software development, and I'll add that even writing good code requires good communication skills.

Writing code that's correct is important; writing code that other people can understand is arguably much more important. If your code contains a few bugs, but it's written in such a way that I can easily understand what's going on, it won't be hard for me to find and fix the bugs. If your code is completely correct but written in such a way that I'm not so sure I understand it, then I can't really be certain that it's correct, and the odds that I can correctly modify it in the future are much lower.


答:
The original naming conventions had a m_ prefix for class members, this got reduced down to simple an underscore. You'll see a lot of older C# Microsoft code using an underscore prefix. However, I heard in a Tech Ed once that a leading underscore is not CLS compliant. I assume this is the reason why they moved to the simpler one-name-fits-all scheme. It used to be (not sure now) that VB.Net's case insensitive names were also not CLS compliant.

For what its worth, I still use the leading underscore for class members. Even though you can disambiguate using this (this.name as opposed to name), bugs still get through.

You do not have to do everything that MS tells you to do.


问:
Vim key mappings / plugin XCode?
I'm a developer who mostly does web stuff in ruby and C#.

I'd like to start tinkering with iOS and Mac development.

Over the last few month i've been trying to get fluent in one set of key bindings (vi / vim because it just feels right).

I have the awesome ViEmu installed for visual studio on windows which gives me a ton of the vim awesomeness side by side with visual studio power toys.

Is there anything like this for xcode?

I know I could set up MacVim as the default editor, but I'm not too interested in this as it means losing all of xcode's cocoa awareness.

The other option of course would be to go for the lowest common denominator and switch to emacs (as the mac keybindings are based massively on emacs) but let's not think about that for too long. :P

答:
I've been obsessed with finding a solution since moving to developing for iOS, and the best answer I've found so far (that works for Lion, too) is installing KeyRemap4MacBook and manually enabling some of the Ubiquitous Vim Bindings and Vi mode.

One of the awesome features that comes from doing this is that now other applications have Vim keybindings, too (for instance, I've been performing Normal mode commands while typing in this textarea on Chrome).

Title: Vim key mappings / plugin XCode?


答: Of course good communication is important!  What I would focus on is becoming an excellent teacher.  Really effective programmers can explain the foundation of something that took years to understand in a 15 minute phone call.  In the same conversation you must explain the details in non-technical terms so the person on the other end of the line can make an educated decision that is best for their business over a long period of time.</p>


问:
At What Point Should You Start To Think About Performance?
As I'm building applications I find myself constantly asking if this is best way to perform or implement a certain functionality.  Often, I'll post questions on stackoverflow or another forum desiring feedback only to receive comments about how not to "put the cart before the horse" regarding performance.  Do most programmers really not think about performance until the application is finished, or performance is absolutely unacceptable??  I mean, I understand that development environments differ from production environments and that you shouldn't completely rely on the results from your dev laptop...but, there are practices and techniques that yield better performance than others.

Is it bad practice to consider performance throughout the development process?  Should I push these considerations off until performance actually is tanking??

Update

Just to be clear, I'm talking about the situation where you are considering or just about to work on some piece of functionality. You know there are several ways to implement it, but you're not quite sure how well each implementation will scale. Also there might be several techniques you're not even familiar with. On a small scale any of the approaches would probably be adequate, but on a larger scale some will keep up and some won't. Often when I ask for opinions or guidance the response is: worry about it later...

答:
I always rely on a simple formula:

Make it work

Make it right

Make it fast

... in that order.

According to c2, this formulation is attributed to Kent Beck.


答:
Just as other people have pointed out, you can usually tell which is which by the scope that the item is used. You actually can't have the parameter and local variable in the same scope and if you want the private variable, just use this.myInteger. So I don't think Microsoft worried about it too much as you can easily differentiate between them if you want.

But that being said, I'm a bit surprised that no one has said this yet, but forget about Microsoft and their naming conventions (well someone might have said it by now as I had to run to a meeting and left this open without submitting it). Hungarian notation was also a naming convention started at Microsoft (or was it Xerox? I can never remember when Simonyi came up with it). I can't think of anyone that I know that doesn't curse the name of Hungarian notation to this day. We became so annoyed with it at the place that I worked that we came up with our own standard that we used internally. It made more sense to us and sped up our work a bit (it was actually pretty close to what Microsoft suggests now, but everything was pascal case with the exception of private variables).

That being said, the newer standard that Microsoft uses (the mixture of camel case and pascal case) isn't too bad. But if you and your coworkers don't like it, come up with your own set of standards (collectively is best). This of course depends on whether or not your company has a set of standards already. If they do, stick to them. Otherwise come up with what works for you and your coworkers. Just keep it logical.'

Since Aaronaught asked for citation about Charles Simonyi and Hungarian Notation:
http://en.wikipedia.org/wiki/Charles_Simonyi

http://en.wikipedia.org/wiki/Hungarian_notation

http://msdn.microsoft.com/en-us/library/aa260976(v=VS.60).aspx

http://ootips.org/hungarian-notation.html

http://www.hitmill.com/programming/vb/Hungarian.html

http://web.mst.edu/~cpp/common/hungarian.html

Last two are just examples of Hungarian notation and the ootips link is just some quotes concerning some opinions on the subject. Note that there is also system Hungarian Notation but that also, as far as I'm aware, came to popularity from Microsoft programmers (although unlike Simonyi for the apps variation, I don't know whom).


问:
Databases and Unit/Integration Testing
I have had a discussion with someone about unit/integration testing with web applications and I have a disagreement about 1 core idea.  The issues is that the person I am talking to think that the database the unit test work off of should have pre-populated data in it and I think it should be completely empty before and after the tests are executed.

My concern with pre-populated data in the database is that there is no way to make sure that data is maintained in a good state.  The tests themselves are going to be creating, deleting, and modifying data in the database so I really don't see how having data in the database before you start the tests is a good thing.

Is seems the the best way of testing database functionality would be having the following setups:

In a "setup" phase before the test actually run, you first truncate all the tables in the database

Then you insert all the data needed for the test cases you are about to run

Then you run and validate the test cases

Then in a "teardown" phase you once again truncates all the tables in the database

I don't see any other better way to ensuring that the data you are testing against in is a good testable test.

Am I missing something here?  Is this not the best way to test database related functionality?  Is there some benefit to have pre-populated database that always exists in the database (even before you start the tests or after the tests are done)?  Any help in ideas to explain my process differently to better get my point across would also be great (that is if my point has merits).

答:
For me unit tests should not deal with the database, integration tests deal with the database.

Integration tests that deal with the database should in practice have a empty database with a tear up and tear down approach, using a transaction based approach is quite a good way to go (i.e. create a transaction on setup and rollback on tear down).

What your friend sounds like they want to do is test from a 'regression' point of view, i.e. have real data there and see how the system reacts, after all no system is perfect and there can usually be bad data lying around somewhere that provide some quirks to your domain model.

Your best practices are the way to go, and what I tend to do, is if I find a scenario for bad data, write an integration test with a setup up and tear down with that exact scenario.

Title: Databases and Unit/Integration Testing


答:
I think you need to narrow down an example with your collegue and find out what they mean exactly. You may both be on the same page.

Example:  Checking Account Transaction Table

Wouldn't you want to test viewing this table for a user/account with no transactions?

Test adding the first record and see if you can create a balance.

Create records when there are already existing records and check the running balance and any other business rules.

View table with existing records and all the other CRUD.

Whether you achieve this by executing steps 1 & 2 or starting with a database already in this state (restore a backup?) I'm not sure it matters. Your idea of scripting it to me makes it easier to manage any changes you need (Like if you forgot to create an admin account and need it for a new user.). Script files are easier to put into source control than some backup file. This also gets affected by whether or not you distribute this app.

Title: Databases and Unit/Integration Testing

Body:
I have had a discussion with someone about unit/integration testing with web applications and I have a disagreement about 1 core idea.  The issues is that the person I am talking to think that the database the unit test work off of should have pre-populated data in it and I think it should be completely empty before and after the tests are executed.

My concern with pre-populated data in the database is that there is no way to make sure that data is maintained in a good state.  The tests themselves are going to be creating, deleting, and modifying data in the database so I really don't see how having data in the database before you start the tests is a good thing.

Is seems the the best way of testing database functionality would be having the following setups:

In a "setup" phase before the test actually run, you first truncate all the tables in the database

Then you insert all the data needed for the test cases you are about to run

Then you run and validate the test cases

Then in a "teardown" phase you once again truncates all the tables in the database

I don't see any other better way to ensuring that the data you are testing against in is a good testable test.

Am I missing something here?  Is this not the best way to test database related functionality?  Is there some benefit to have pre-populated database that always exists in the database (even before you start the tests or after the tests are done)?  Any help in ideas to explain my process differently to better get my point across would also be great (that is if my point has merits).


答:
Well, I see one benefit in having a prepopulated database: you don't have to write the code that will insert the data you need, since it is there. Otherwise there are only drawbacks. Maybe someone modified the test data on the database ? Maybe someone attempted to refresh the data ?
But the worse thing is having one test case badly messing up the database... You end up recreating the whole database manually several times.

You are right in how tests should be written, except that I would not truncate anything:

setup phase: get a connection to the database and insert the data

run phase

tear down phase: remove the inserted data (truncate)

Now, that scenario is great for unit tests. When one needs data for both unit and integration testing, I found that one big setup phase common to all test cases (we regrouped all "inserts" into one static method) may also work very well. It's like a middle ground between your idea and your friend's idea. The only drawback is that you have to be very careful when adding some new data in order to not break existing test cases (but if you add like two-three rows per table like we did, it should not be a problem)

Title: Databases and Unit/Integration Testing


答:
If your tests depend on the database, then I think it's more important that the data you care about is in a known state for your testing, rather than the database being empty. One of the measures of good tests is that each test should fail for one reason and no other test should fail for that same reason.

So, if your testing cares about the state of the data then get the data into that known state and return the data to that state after your tests have ran, so that your tests are reproducible.

If you can decouple your tests from the state of the data by mocking then that would also be a good thing. You mention you are doing unit / integration testing, but of course those two things should be considered separately. Your unit tests should be de-coupled from the database if at all possible and your integration tests should be testing with the database in a known state.

Title: Databases and Unit/Integration Testing


问:
Understanding the Macro Aspects of Data Structures
I am studying data structures right now, but I still need to find a teacher/site/book with a clear explanation of the macro aspects of this topic.

What I mean is: most lessons/text books mix everything together, with no logical structure. They start with linked lists, then talk about stacks, queues, heap priorities and so on. But as far as I can tell, a linked list and a stack are not really in the same category. After all you can use the linked list to implement different types of data strcutures (e.g., a stack, a queue, etc).

So would it be right to say that the types of data structures are: the stack, the queue, the hash-table, the heap, and the tree; while arrays (static) and linked lists (dynamic) are tools you are going to use to implement those data structures?

If the above statement is not completely correct, maybe a linked list is indeed a data structure in itself, and therefore we would be using one data structure (e.g., the linked list) to build other data structures on top of it (e.g., a stack)?

答:
I would define them as the interface they provide, including complexity of the operations.

One could after all implement a linked list with an array and vice versa (and recursivly), but it would be impossible to keep the complexity.

Update: To clarify: A stack is defined as a datastructure with constant-time add to top, and constant-time remove at top. It doesn't say how we implement it.
One could implement it using an array, or a linked list, but also a double linked list, but that is irrelevant.

The atomic we have on a computer is (binary) memmory, and the most basic form of memmory is an array, thus one can create every kind of datastructure using an array.

One could imagine we had another atomic (maybe a qubit). Then a stack would still be a stack, but maybe we couldn't implement it with that atomic.


问:
Java SE and Java EE?
I was now talking with some people and they told me that if i was intrested in a job in the future for Java programming i should not spend too much time only learning Java SE i should spend time learning Java EE instead.. Now that brought me to some questions..

Java Enterprise Edition why use this ? What can i make with this that i can't make in Java SE?, And what kind of applications is this good for?

Is there any good books out there that i can read to learn the Java EE?

If i know Java SE well is it easier to learn Java EE ?

Thanks! I will keep browsing the web for some anwears for theese questions.. And if i find anything i wil update this question.

答: I suspect they have been pulling your leg. Java EE is nothing but a Java SE running a container application (like JBoss) that supports the additional Java EE frameworks. Not knowing the SE would be a major problem for your future in Java coding.</p>

OwnerDisplayName: TheCompBoy

Title: Java SE and Java EE?


答:
Keeping it simple, SE(Standard Edition) doesnt deal with any application server detail implementations like web components, EJB, security, webservices, messaging etc while EE(Enterprise Edition) deals with all these.

I am not sure how one could directly get into higher studies (EE) without knowing the basics (SE)

Title: Java SE and Java EE?

Body:
I was now talking with some people and they told me that if i was intrested in a job in the future for Java programming i should not spend too much time only learning Java SE i should spend time learning Java EE instead.. Now that brought me to some questions..

Java Enterprise Edition why use this ? What can i make with this that i can't make in Java SE?, And what kind of applications is this good for?

Is there any good books out there that i can read to learn the Java EE?

If i know Java SE well is it easier to learn Java EE ?

Thanks! I will keep browsing the web for some anwears for theese questions.. And if i find anything i wil update this question.


答:
To clarify some things:

Java - a programming language.

JavaSE - a term that refers to Java, and a collection of standard libraries and utilities.

JavaEE - a term that refers to Java, and a collection of libraries used for building "enterprise applications" (usually web applications).

There is nothing you can do in JavaEE that can't be done in JavaSE, but if you need to build an enterprise application, JavaEE will make your life easier.

By definition, you must learn Java (the language) and and some JavaSE (the libraries - though you could skip things like Swing and SWT which could be included in JavaSE but aren't necessary for JavaEE) to work in JavaEE, because it doesn't make any sense to learn JavaEE and not know Java and JavaSE.

Title: Java SE and Java EE?


答:
Yes, the emergent properties of arrays and linked lists allow them to be treated as a data structure "primitives", however that does not mean the linked list is exactly what other structures use underneath.

The important thing to take away from linked lists is that you point to arbitrary spots in memory, rather than holding onto a sequential grouping of memory slots. If random access improves the performance of a more abstract structure, then it's worth the optimizations an array provides. Whereas, using arbitrary pointers gives you slightly more freedom of how you use your memory.

For example, in Clojure a map is implemented as an array underneath until it becomes more beneficial to use a high level of abstraction, for which it switches out the implementation.

Title: Understanding the Macro Aspects of Data Structures

Body:
I am studying data structures right now, but I still need to find a teacher/site/book with a clear explanation of the macro aspects of this topic.

What I mean is: most lessons/text books mix everything together, with no logical structure. They start with linked lists, then talk about stacks, queues, heap priorities and so on. But as far as I can tell, a linked list and a stack are not really in the same category. After all you can use the linked list to implement different types of data strcutures (e.g., a stack, a queue, etc).

So would it be right to say that the types of data structures are: the stack, the queue, the hash-table, the heap, and the tree; while arrays (static) and linked lists (dynamic) are tools you are going to use to implement those data structures?

If the above statement is not completely correct, maybe a linked list is indeed a data structure in itself, and therefore we would be using one data structure (e.g., the linked list) to build other data structures on top of it (e.g., a stack)?