问:
Learn programming backwards, or "so I failed the FizzBuzz test. Now what?"

A Little Background

I'm 28 today, and I've never had any formal training in software development, but I do have two higher education degrees equivalent to a B.A in Public Relations and an Executive MBA focused on Project Management. I've worked on those fields for about 6 years total an then, 2,5 years ago I quit/lost my job and decided to shift directions.

After a month thinking things through I decided to start freelancing developing small websites in WordPress. I self-learned my way into it and today I can say I run a humble but successful career developing themes and plugins from scratch for my clients - mostly agencies outsourcing some of their dev work for medium/large websites.

But sometimes I just feel that not having studied enough math, or not having a formal understanding of things really holds me behind when I have to compete or work with more experienced developers. I'm constantly looking for ways to learn more but I seem to lack the basics.

Unfortunately, spending 4 more years in Computer Science is not an option right now, so I'm trying to learn all I can from books and online resources. This method is never going to have NASA employ me but I really don't care right now. My goal is to first pass the bar and to be able to call myself a real programmer.

I'm currently spending my spare time studying Java For Programmers (to get a hold on a language everyone says is difficult/demanding), reading excerpts of Code Complete (to get hold of best practices) and also Code: The Hidden Language of Computer Hardware and Software (to grasp the inner workings of computers).

TL;DR

So, my current situation is this: I'm basically capable of writing any complete system in PHP (with the help of Google and a few books), integrating Ajax, SQL and whatnot, and maybe a little slower than an experienced dev would expect due to all the research involved.

But I was stranded yesterday trying to figure out (not Google) a solution for the FizzBuzz test because I didn't have the if($n1 % $n2 == 0) method modulus operator memorized.

What would you suggest as a good way to solve this dilemma? What subjects/books should I study that would get me solving problems faster and maybe more "in a programmers way"?

EDIT - Seems that there was some confusion about what did I not know to solve FizzBuzz.

Maybe I didn't express myself right: I knew the steps needed to solve the problem. What I didn't memorize was the modulus operator. The problem was in transposing basic math to the program, not in knowing basic math.

I took the test for fun, after reading about it on Coding Horror. I just decided it was a good base-comparison line between me and formally-trained devs.

I just used this as an example of how not having dealt with math in a computer environment before makes me lose time looking up basic things like modulus operators to be able to solve simple problems.

答:
In your case, as you're self-taught and already have what seems to be a good, healthy and no-BS approach to learning. Still some suggestions...

Practice Makes Perfect

I think you should dive into progamming exercises, like the:

Project Euler,

the classic 99 Prolog Puzzles (just as good for any language),

TopCoder,

Google Code Jam,

and so forth.

Even grab the past exam questions of known universities around you, or of local (or remote) programming competitions. For example, we have a nice one in France for aspiring high-school programmers is called Prologin, and it does provide every year a good series of head-scratching puzzles (probably French only though, sorry, but that's the sort of things I mean).

For more: Where Can I Find Programming Puzzles and Challenges?

Classic Books and References

We could also recommend a very long list of amazing books, but I'd say the Zen answer is that there's no single right way to Enlightenment.

It would be hard to tell you which ones are top of the list. So keep reading a ton of stuff to learn general pitfalls to avoid and best practices to follow, as you are correctly doing now.

For more:

List of Freely Available Programming Books

What is the Most Influential Book Every Programmer Should Read?

What Books Should Everyone Read?

What Papers Should Everyone Read?

What Videos Should Everybody Watch?

or even Where do You Start When You Have an Interest in Computer Science and Programming?

Become a Programmer, Motherf*cker (Pardon his French ;) His tutorials and lists of resources are worth it)

Pushing the Limits

Also, look for head-scratching material, like:

Hacker's Delight by Henry S. Warren,

Matters Computational by Jörg Arndt.

Not necessarily to be taken as an example of things to do nowadays, but worth trying to figure out what the hell is happening in there.

Peer Systems are Motivational

You may also want to lurk around (and get involved in) the following communities to improve your skills incrementally by being confronted to others.

P.SE, naturally,

StackOverflow,

CodeGolf.SE,

CodeReview.SE,

or even the crazy folks at CS.SE (or specialized ones like Crypto.SE),

or many, many others SE or non-SE community sites.

Part-Time Education

If you don't have the time or motivation to engage in another 4 year course or something similar (which may not even be necessary or rewarding anyways, and expensive), you could consider looking for teaching material online. Of course, these are not limited to computer science.

Thanks to the original MIT OpenCourseWare effort, there are now tons of universities that followed suit, and you can find a lot of university-level course material for  free. It's not always easy to navigate and read through it on your own, but some are pretty well done. To start from the ground up and go pretty high up, consider also looking at the Khan Academy.

Some go a bit further, and offer real online-courses for free, where you similarly have access to the course's material, but where they also provide paced lectures and regular self-assessments. For instance, visit Coursera or Udacity.

Most of the above often publish their lectures on Youtube or iTunesU, so you'll find plenty of material if your thirst for knowledge wasn't already quenched by all the previous links.

If you want something that provides a closer experience to the "real" university, you can consider remote universities, which also allow you to work part-time, but require you to follow the pace, and to have both self-assessments and end of year exams (sometimes on-site), like with the OpenUniversity and its international variants.

Passion Keeps You Going

Find a pet project: create your own or join one or more existing software projects and contribute.

Code, code, code. And then code some more.

(and get enough eyeballs looking at your code to criticize you and hqve different perspectives)

The French say:

C'est en forgeant que l'on devient forgeron.

Keep doing what you're doing, and eventually you'll be an expert. Takes time and work.

See also I'm Having Trouble Learning for more suggestions.

PS: Though it's a very controversial tool for interviews, and doesn't help to identify good candidates, I do often use FizzBuzz to at least weed out the incredibly "bad ones". So get crankin' on this practicing thing! :)


答:
Keep coding, keep learning. Eventually, with enough dedication, you'll look at FizzBuzz and wonder why you even had to think about it. Lots of companies do a FizzBuzz-style question as a very early part of their interviews, so failing this one time means you've at least learned something about the hiring process.

Just keep writing code, coming up with project ideas, and researching.

ContentLicense: CC BY-SA 3.0

Title: Learn programming backwards, or "so I failed the FizzBuzz test. Now what?"

Body:
A Little Background

I'm 28 today, and I've never had any formal training in software development, but I do have two higher education degrees equivalent to a B.A in Public Relations and an Executive MBA focused on Project Management. I've worked on those fields for about 6 years total an then, 2,5 years ago I quit/lost my job and decided to shift directions.

After a month thinking things through I decided to start freelancing developing small websites in WordPress. I self-learned my way into it and today I can say I run a humble but successful career developing themes and plugins from scratch for my clients - mostly agencies outsourcing some of their dev work for medium/large websites.

But sometimes I just feel that not having studied enough math, or not having a formal understanding of things really holds me behind when I have to compete or work with more experienced developers. I'm constantly looking for ways to learn more but I seem to lack the basics.

Unfortunately, spending 4 more years in Computer Science is not an option right now, so I'm trying to learn all I can from books and online resources. This method is never going to have NASA employ me but I really don't care right now. My goal is to first pass the bar and to be able to call myself a real programmer.

I'm currently spending my spare time studying Java For Programmers (to get a hold on a language everyone says is difficult/demanding), reading excerpts of Code Complete (to get hold of best practices) and also Code: The Hidden Language of Computer Hardware and Software (to grasp the inner workings of computers).

TL;DR

So, my current situation is this: I'm basically capable of writing any complete system in PHP (with the help of Google and a few books), integrating Ajax, SQL and whatnot, and maybe a little slower than an experienced dev would expect due to all the research involved.

But I was stranded yesterday trying to figure out (not Google) a solution for the FizzBuzz test because I didn't have the if($n1 % $n2 == 0) method modulus operator memorized.

What would you suggest as a good way to solve this dilemma? What subjects/books should I study that would get me solving problems faster and maybe more "in a programmers way"?

EDIT - Seems that there was some confusion about what did I not know to solve FizzBuzz.

Maybe I didn't express myself right: I knew the steps needed to solve the problem. What I didn't memorize was the modulus operator. The problem was in transposing basic math to the program, not in knowing basic math.

I took the test for fun, after reading about it on Coding Horror. I just decided it was a good base-comparison line between me and formally-trained devs.

I just used this as an example of how not having dealt with math in a computer environment before makes me lose time looking up basic things like modulus operators to be able to solve simple problems.


问:
what is the term for the class in the bottom of a class hierarchy?
You have a class hierarchy:

D extends C which extends B which extends A, for example.

A would be the top class, but how about D?
I am looking for a short and concise way of describing the position of D within the hierarchy

Is it the most specific class? the deepest class in the hierarchy? the last subclass? final class?

The class might or might not be final (java) or sealed (c#). what matters is that it is the last one of the hierarchy at a particular moment. If a newer class (E) appears that extends D then the proposed term would apply to it. Also, there might be more than one class that fit this description (both D and E extends C), the term should apply to both classes.

答:
I would use "most derived class", but that's probably because I spend entirely too much time reading the C++ standard, and that's the term it uses.

I doubt there's one term that applies equally well across languages and uses though. In C++, the accepted terms are "derived class" and "base class", so "most derived class" makes sense.

In Smalltalk, by contrast, the accepted terms are "superclass" and "subclass", so trying to use "most derived class" would seem odd, foreign, and quite possibly at least mildly confusing (but no, I don't recall Smalltalk documentation having a specific term that corresponds to "most derived class").


答:
You get good at development the way you get good at anything else: practice.  There is a nice concept in the programming world called the code kata.  This is essentially an exercise where you code a solution to a relatively small problem, analyze what's good and what's bad, scrap it all, and do it again.  FizBuzz is a kata in its own right.  So, do it, and do more. When you find things that don't seem to be very good or just don't work, do research and be thorough about it.  Ask questions on Q&A sites, read articles and blogs, see how others handle this, and then practice what you've learned.

In the course of doing this practice, you'll learn how much additional mathematical/theoretical background you might need.  If you bump into concepts that you just can't wrap your head around, then read about them and their prerequisite knowledge and decide on a case by case basis if you want to take a course or what-have-you in order to expand your theoretical background.


问:
Why are side-effects considered evil in functional programming?
I feel that side effects are a natural phenomenon. But it is something like taboo in functional languages. What are the reasons?

My question is specific to functional programming style. Not all programming languages/paradigms.

答:
Side effects are like "leaks" in your code that will need to be handled later, either by you or some unsuspecting coworker.

Functional languages avoid state variables and mutable data as a way of making code less context dependent and more modular. Modularity insures that the work of one developer won't affect/undermine the work of another.

Scaling rate-of-development with team size, is a "holy grail" of software development today. When working with other programmers, few things are as important as modularity. Even the most simple of logical side effects make collaboration extremely difficult.

ContentLicense: CC BY-SA 2.5


答:
But I was stranded yesterday trying to figure out (not google) a
  solution for the FizzBuzz test because I didn't have the if($n1 % $n2
  == 0) method memorized.

Nobody memorizes that thing. You're supposed to come up with it on your own. If you know the modulus operator and you know what it does, then it's trivially a great fit to the FizzBuzz problem.

I'm going to go out on a limb here and generally suggest that the problem is PHP. I like to say that Java is the worst language ever designed, and PHP is the worst language ever, because even its creators admit that it was never designed. It's hard to learn good software engineering practices when your environment is practically the definition of how not to do it. And depending on a framework to get everything done is not saying much.

I'm currently spend my spare time studying Java For Programmers (to
  get a hold on a language everyone says is difficult/demanding)

Java is one of the easiest and worst languages in existence. It only has one thing: garbage-collected manual inheritance. If your friends or advisors say that Java is hard, then find new friends. C++ is a difficult language that includes a lot of concepts, and that nobody will dispute. You could also do C#, which at least has some generics and lambdas.

How are you going to learn to code, when your languages were designed and implemented by people who can't code, and you depend on frameworks for everything that you do?


答:
... because I didn't have the if($n1 % $n2 == 0) method memorized.

I'm interpreting that to mean, you didn't know about and/or didn't remember the modulus operator.  If this is the case, the place to start is to review the language constructs in the language you are using. Review anything which you don't 'know cold', and learn anything you just don't know.


答:
```<code>I didn't have the if($n1 % $n2 == 0) method memorized.
</code>```

I haven't been coding for very long (started teaching myself SQL about 27 months ago and started coding in Perl about 20 months ago), but the quote above sounds like some things that I've heard from former students:

How am I supposed to memorize which integration technique to use for
  every problem?

I didn't memorize whether I should add or multiply probabilities, or
  use "n choose k" or use factorials.

Wait a minute!  You said that x equaled 2 yesterday!  Now it equals
  zero?!

Okay, that last one was probably a bit harsh...but the point I'm trying to make is that problem solving is not memorization.  If it was, then some genius could program a computer to solve every problem, and none of us would ever have to think again (what a hellish world that would be...).

Now, it is true that any intellectual endeavor consists of at least a little bit of memorization.  In particular, if you're going to code in PHP, then you should understand the basic data types (numbers, strings, arrays), basic things that you can do with them (for numbers: addition, subtraction, multiplication, division, and modulus; for strings: concatenation, substrings, replacement, and at least some knowledge of regular expressions; for arrays: concatenation, tacking on elements, splicing out elements, looping, counting elements, etc), and the basic logical structures that one can use (if/then/else statements, foreach loops, while loops, etc).

Then, when you encounter a problem, use the problem to provide the context for what tools you need.  For FizzBuzz, you need to tell when a number is divisible by 3, 5, or 15.  Okay, so we're dealing with numbers....what basic tools allow us to tell when one integer is divisible by another?  Well, the modulus operator.  So, use that.  (Of course, if your number is $n, you could be fancy and see if the last digit of $n is 0 or 5, and/or if the digits of $n add up to something divisible by 3, but I digress...)  You need to do this for each number between 1 and 100, so to avoid getting carpel tunnel, use a foreach loop.

The morale of the story is that if on one hand you say "I'm basically capable of writing any complete system in PHP" and on the other hand you can't code FizzBuzz, then the first assertion is incorrect.  Some of my former calculus students swore up and down that they understood the concepts, but they just couldn't do the problems on the exam...or the homework problems...or the quiz problems.  They were wrong about their understanding as well.

Stop making excuses and learn the basics.

Body:
I didn't have the if($n1 % $n2 == 0) method memorized.

I haven't been coding for very long (started teaching myself SQL about 27 months ago and started coding in Perl about 20 months ago), but the quote above sounds like some things that I've heard from former students:

How am I supposed to memorize which integration technique to use for
  every problem?

I didn't memorize whether I should add or multiply probabilities, or
  use "n choose k" or use factorials.

Wait a minute!  You said that x equaled 2 yesterday!  Now it equals
  zero?!

Okay, that last one was probably a bit harsh...but the point I'm trying to make is that problem solving is not memorization.  If it was, then some genius could program a computer to solve every problem, and none of us would ever have to think again (what a hellish world that would be...).

Now, it is true that any intellectual endeavor consists of at least a little bit of memorization.  In particular, if you're going to code in PHP, then you should understand the basic data types (numbers, strings, arrays), basic things that you can do with them (for numbers: addition, subtraction, multiplication, division, and modulus; for strings: concatenation, substrings, replacement, and at least some knowledge of regular expressions; for arrays: concatenation, tacking on elements, splicing out elements, looping, counting elements, etc), and the basic logical structures that one can use (if/then/else statements, foreach loops, while loops, etc).

Then, when you encounter a problem, use the problem to provide the context for what tools you need.  For FizzBuzz, you need to tell when a number is divisible by 3, 5, or 15.  Okay, so we're dealing with numbers....what basic tools allow us to tell when one integer is divisible by another?  Well, the modulus operator.  So, use that.  (Of course, if your number is $n, you could be fancy and see if the last digit of $n is 0 or 5, and/or if the digits of $n add up to something divisible by 3, but I digress...)  You need to do this for each number between 1 and 100, so to avoid getting carpel tunnel, use a foreach loop.

The morale of the story is that if on one hand you say "I'm basically capable of writing any complete system in PHP" and on the other hand you can't code FizzBuzz, then the first assertion is incorrect.  Some of my former calculus students swore up and down that they understood the concepts, but they just couldn't do the problems on the exam...or the homework problems...or the quiz problems.  They were wrong about their understanding as well.

Stop making excuses and learn the basics.


问:
Naming classes becomes debilitating
I'm not sure if this is an OCD trait or not, but I find that sometimes I get completely blocked unable to continue what I am doing when naming a class (or function, or namespace etc) that I believe is to be used outside of a given project. An API for example. Or a utility class library.

If the naming isn't exactly right (in my mind) I just can't continue...I get stuck trying to come up with the right name. I've tried writing little apps that would use it to see what the names look like but that doesn't seem to help...

I know it shouldn't matter, and it's against any programming mindset to assume you'd get it perfect first go...I just feel powerless to it...

Any tips/ideas would be greatly appreciated...

答: I got this from a friend awhile back.  Write out what your process is supposed to do.  Just a short narrative.  Then take the nouns and turn them into classes, the verbs into methods, and the adverbs into properties.</p>

Title: Naming classes becomes debilitating


问:
When/why is it easier to beg forgiveness than ask permission?
The saying "It's easier to beg forgiveness than ask permission" seems pretty popular among programmers and IIRC was attributed to Grace Hopper.  In what situations is this typically true, and why do you believe that such a counterintuitive proposition would hold?</p>

答:
why do you believe that such a counterintuitive proposition would hold

It is a point of view that advocates taking risks.  By that point of view, if you don't take risks, you aren't testing the water, and you will not reach your maximum potential.

If you agree that you learn from your mistakes, then you may agree with this adage.  You may find that the bruises you take aren't nearly as bad as you imagined, and when you are successful, you find yourself rewarded in excess, because you "showed leadership".

This thought pattern makes the concept intuitive, if not the practice.

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

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

In what situations is this typically true

This attitude is most valuable someone who is in a new job situation, but has an established track record (assuming competent management).  This is when mistakes will most often be forgiven (assuming good sense, intentions, and rationale), and progress will be most highly rewarded.


问:
Should I add an "Abstract" prefix to my abstract classes?
Suppose I have an abstract class named Task.

Is there a standard or convention that would suggest I should name it AbstractTask instead?

答:
This is somewhat a matter of preference (but borderline bad practice), but most people don't like seeing part of the qualifiers in the name of the class.

Most IDE's will make that information easily available to you anyway, so putting it in the name isn't necessary, and it will be cleaner to just omit it. It's reminiscent of hungarian notation for variable naming, and that's certainly considered bad form now-a-days. I recommend simply calling it Task.


答: I'm not a Java developer (INAJD?) and don't know the standard nomenclature for such things, but I think Task sounds abstract enough that it can stand alone as-is.

Title: Should I add an "Abstract" prefix to my abstract classes?

Body:
Suppose I have an abstract class named Task.

Is there a standard or convention that would suggest I should name it AbstractTask instead?


答: No. Intellisense will trivially tell me if it is abstract, so you're just violating DRY here.</p>


答:
There is no convention. It's all about what will help you, as the developer, code faster and better, and help others understand your code.

Ask the people who will be seeing and maintaining the code. What would they rather see? What will make it easier on them? Then name it based on what they'd like.

On another note, Code Conventions for the Java Programming Language: 9. Naming Conventions suggests no requirement:

Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML).


答:
A good rule of thumb is to not include properties in a name that are obvious from the syntax. Since in Java, you need to mark an abstract class with the aptly named abstract keyword, I would not include it in the name. In C++, for example, the case is not so clear cut, but at least the compiler will tell you when you incorrectly used an abstract class. In something like Python again, explicitly naming an abstract class as such is not a bad idea.

The usual exception to the rule is when the name is ambiguous. If, for whatever reason, there is a concrete subclass Task (in other examples, this may be more sensible, but whatever), then sure, use AbstractTask.


答: In .NET, the use of "Base" as a suffix to denote an abstract base class is often seen. I would defer to the other answers as to whether this is common practice in Java.</p>


问:
HTML5 localStorage and encrypted sensitive data
I'm looking for a way to have a website remember sensitive data, but without actually storing it server side.  And I was looking at HTML5 localStorage to do it.  Here's the plan as I see it.

User enters sensitive data into form, and submits.

Server encrypts data via AES-256 with a strong key that is kept in private source control.

Server responds, providing encrypted data to rendered page.

Page runs javascript to save encrypted data to localStorage

Later...

User visits a page that uses javascript to fetch encrypted data from localStorage and sends it to the server.

Server decrypts encrypted data, gaining access to sensitive information for that request.

My thinking is that that allows either the client or server to compromised, and things stay secure.  If the client is compromised, then the hacker can read only an encrypted string they do not have the key to decrypt.  If the server database is compromised, the data is simply not stored there so it obviously can't be accessed by the hacker.

(Obviously some types of server hacking could read sensitive data as it's coming in initially, but such a hack would work whether client storing it or not, so that doesn't apply to this discussion. Also client hacks that log keys and whatnot would still work, I'm simply talking about data storage getting compromised on either side here)

But I'm no security expert, so I am wondering if my plan has any holes in it? Any glaring security vulnerabilities I am missing here?

答:
There are two big problems with this.

It ties the data to that particular browser installation.  So someone cant log in from a different location and access it.  Or even a different browser on the same machine.  That defeats the purpose of most web apps.  Also, what about public machines?  You'd be storing sensitive data, albeit encrypted, on publicly accessible machines.

You have to be extremely careful validating the data that gets sent back to the server.  Once its out of your control, you cant assume anything about it.

And then after that, your server can still be hacked, even if the data isnt compromised.


问:
Stored Procedures a bad practice at one of worlds largest IT software consulting firms?
I'm working at a project in one of the world's top 3 IT consulting firms, and was told by a DBA that company best practice's state stored procedures are not a "best practice".  This is so contrary to everything I've learned.

Stored procedures give you code reuse, and encapsulation (two pillars of software development), security (you can grant/revoke permissions on an individual stored proc), protect you from SQL injection attacks, and also help with speed (although that DBA said that starting with SQL Server 2008 that even regular SQL queries are compiled if they are run enough times).

We're developing a complex app using Agile software development methodology.  Can anyone think of good reasons why they wouldn't want to use stored procs?  My guess was that the DBAs didn't want to maintain those stored procs, but there seem to be way too many negatives to justify such a design decision.

答:
Considering all the above cases, I would like to add one more.
The choice of SP may be depends on people choice as well.

I personally feel frustrated when people puts very complex logic in SP and I believe such SP is very complex to maintain and debug. Even many cases the developer himself faces problem when debugging in code behind (say language part) is much more easier than in SP.

SP should only be used for simple operations. Well that is my choice.


问:
In plain English, what is recursion?
The idea of recursion is not very common in real world. So, it seems a bit confusing to the novice programmers. Though, I guess, they become used to the concept gradually. So, what can be a nice explanation for them to grasp the idea easily?</p>

答:
Recursion n. - A pattern of algorithm design where an operation is defined in terms of itself.

The classic example is finding the factorial of a number, n!. 0!=1, and for any other natural number N, the factorial of N is the product of all natural numbers less than or equal to N. So, 6! = 6*5*4*3*2*1 = 720. This basic definition would allow you to create a simple iterative solution:

```<code>int Fact(int degree)
{
    int result = 1;
    for(int i=degree; i>1; i--)
       result *= i;

    return result;
}
</code>```

However, examine the operation again. 6! = 6*5*4*3*2*1. By the same definition, 5! = 5*4*3*2*1, meaning that we can say 6! = 6*(5!). In turn, 5! = 5*(4!) and so on. By doing this, we reduce the problem to an operation performed on the result of all previous operations. This eventually reduces to a point, called a base case, where the result is known by definition. In our case, 0!=1 (we could in most cases also say that 1!=1). In computing, we are often allowed to define algorithms in a very similar way, by having the method call itself and pass a smaller input, thus reducing the problem through many recursions to a base case:

```<code>int Fact(int degree)
{
    if(degree==0) return 1; //the base case; 0! = 1 by definition
    else return degree * Fact(degree -1); //the recursive case; N! = N*(N-1)!
}
</code>```

This can, in many languages, be further simplified using the ternary operator (sometimes seen as an Iif function in languages that don't provide the operator as such):

```<code>int Fact(int degree)
{
    //reads equivalently to the above, but is concise and often optimizable
    return degree==0 ? 1: degree * Fact(degree -1);
}
</code>```

Advantages:

Natural expression - for many types of algorithms, this is a very natural way to express the function.

Reduced LOC - It's often much more concise to define a function recursively.

Speed - In certain cases, depending on language and computer architecture, recursion of an algorithm is faster than the equivalent iterative solution, usually because making a function call is a faster operation at the hardware level than the operations and memory access required to loop iteratively.

Divisibility - Many recursive algorithms are of the "divide and conquer" mentality; the result of the operation is a function of the result of the same operation performed on each of two halves of the input. This allows you to split the work in two at each level, and if available you can give the other half to another "execution unit" to process. This is typically harder or impossible with an iterative algorithm.

Disadvantages:

Requires understanding - You simply must "grasp" the concept of recursion in order to understand what's going on, and therefore write and maintain effective recursive algorithms. Otherwise it just looks like black magic.

Context-dependent - Whether recursion is a good idea or not depends on how elegantly the algorithm can be defined in terms of itself. While it is possible to build, for example, a recursive SelectionSort, the iterative algorithm is typically the more understandable.

Trades RAM access for call stack - Typically, function calls are cheaper than cache access, which can make recursion faster than iteration. But, there's usually a limit to the depth of the call stack that can cause recursion to error where an iterative algorithm will work.

Infinite recursion - You have to know when to stop. Infinite iteration is also possible but the looping constructs involved are usually easier to understand and thus to debug.

Title: In plain English, what is recursion?

Body:
Recursion n. - A pattern of algorithm design where an operation is defined in terms of itself.

The classic example is finding the factorial of a number, n!. 0!=1, and for any other natural number N, the factorial of N is the product of all natural numbers less than or equal to N. So, 6! = 6*5*4*3*2*1 = 720. This basic definition would allow you to create a simple iterative solution:

int Fact(int degree)
{
    int result = 1;
    for(int i=degree; i>1; i--)
       result *= i;

    return result;
}

However, examine the operation again. 6! = 6*5*4*3*2*1. By the same definition, 5! = 5*4*3*2*1, meaning that we can say 6! = 6*(5!). In turn, 5! = 5*(4!) and so on. By doing this, we reduce the problem to an operation performed on the result of all previous operations. This eventually reduces to a point, called a base case, where the result is known by definition. In our case, 0!=1 (we could in most cases also say that 1!=1). In computing, we are often allowed to define algorithms in a very similar way, by having the method call itself and pass a smaller input, thus reducing the problem through many recursions to a base case:

int Fact(int degree)
{
    if(degree==0) return 1; //the base case; 0! = 1 by definition
    else return degree * Fact(degree -1); //the recursive case; N! = N*(N-1)!
}

This can, in many languages, be further simplified using the ternary operator (sometimes seen as an Iif function in languages that don't provide the operator as such):

int Fact(int degree)
{
    //reads equivalently to the above, but is concise and often optimizable
    return degree==0 ? 1: degree * Fact(degree -1);
}

Advantages:

Natural expression - for many types of algorithms, this is a very natural way to express the function.

Reduced LOC - It's often much more concise to define a function recursively.

Speed - In certain cases, depending on language and computer architecture, recursion of an algorithm is faster than the equivalent iterative solution, usually because making a function call is a faster operation at the hardware level than the operations and memory access required to loop iteratively.

Divisibility - Many recursive algorithms are of the "divide and conquer" mentality; the result of the operation is a function of the result of the same operation performed on each of two halves of the input. This allows you to split the work in two at each level, and if available you can give the other half to another "execution unit" to process. This is typically harder or impossible with an iterative algorithm.

Disadvantages:

Requires understanding - You simply must "grasp" the concept of recursion in order to understand what's going on, and therefore write and maintain effective recursive algorithms. Otherwise it just looks like black magic.

Context-dependent - Whether recursion is a good idea or not depends on how elegantly the algorithm can be defined in terms of itself. While it is possible to build, for example, a recursive SelectionSort, the iterative algorithm is typically the more understandable.

Trades RAM access for call stack - Typically, function calls are cheaper than cache access, which can make recursion faster than iteration. But, there's usually a limit to the depth of the call stack that can cause recursion to error where an iterative algorithm will work.

Infinite recursion - You have to know when to stop. Infinite iteration is also possible but the looping constructs involved are usually easier to understand and thus to debug.


问:
What is the main difference between HAS_MANY and BELONGS TO relationship in mysql?
After making little progress in web development and php I figured out if I can make my grip strong on database designing, I will be able to reduce much code and time in developing the application. But I happen to be a dumb in database designing so can anyone please help to differentiate between has many and belongs to relationship. They seems quite same to me</p>

答:
has many

Useful for describing 1:n or n:n relationships.  Using the 1:n relationship, we are looking at a single object and looking at the 1 or more other objects related to the first object.

A parking garage has many cars parked within it.

The primary object has many secondary objects.

The primary key has many foreign keys (linking the primary entry to many other entries in other tables.)

belongs to

Useful for describing 1:1 or n:1 relationships (note that n:1 is the reverse of 1:n, so you're looking at the relationship in the opposite direction.)

A car belongs to the parking garage.

The secondary object belongs to the primary object.

In the n:n case:

The foreign key is referenced by / belongs to the primary key.


答:
You could find and help others e.g. giving.code (disclosure: my site) or Code for America or whatever.  This is an excellent way to get more exposure to non-PHP-web-page-making problems and feeling good too.

When you have a problem to solve - or help solve, or just understand - the picking up the code comes naturally along the way.  Having a goal is the best way to learn something.


答:
According to Bloch's Effective Java (Item 18) the Abstract prefix is a convention used in a special case.

You can combine the virtues of interfaces and abstract classes by
  providing an abstract skeletal implementation class to go with each
  nontrivial interface that you export.
  ...
  By convention, skeletal implementations are called AbstractInterface, where Interface is the name of the interface they implement.

But Bloch also points out that the name SkeletalInterface would have made sense, but concludes that

the Abstract convention is now firmly established.

As other answers have pointed out, in general there is no reason to apply this naming convention to all abstract classes.


问:
For what problems is object oriented programming not a good choice?
Somewhat inspired by this question: For what common problems is functional programming not a good fit? - but nevertheless a question which I always wanted, but was too afraid to ask.

I've been in ... well, let's call it engineering software development practically all my life, and in all that time, although OO had always been there (well, most of that time) I've never had the need to use "its ways", nor to learn that paradigm. We've always used rather simple program structures, routines/functions/modules and although it is opposite to today's best practices managing those programs (programs up to roughly 300k LOC, nothing too big) never proved to be difficult, let alone impossible.

So I wanted to ask you, what would be the sorta problems for which object oriented paradigm would not be a good choice? In comparison to procedural programming ?

答:
Most programmers, OO savvy or not, uses concepts like abstraction, information hiding and interfaces in their code. OO languages simply makes that easier since these concepts are already built-in. You don't have to invent them yourself.

A core algorithm like qsort() uses abstractions for comparison of arbitrary objects. fread() uses an interface to abstract away the details of the stream etc.

From that standpoint I find it hard to come up with any particular problem that are better solved with a non-OO approach.


问:
Should my source code be in UTF-8?
I feel that often you don't really choose what format your code is in. I mean most of my tools in the past have decided for me. Or I haven't really even thought about it. I was using TextPad on windows the other day and as I was saving a file, it prompted me about ASCII, UTF-8/16, Unicode etc etc...

I am assuming that almost all code written is ASCII, but why should it be ASCII? Should we actually be using UTF-8 files now for source code, and why? I'd imagine this might be useful on multi-lingual teams. Are there standards associated with how multilingual teams name variables/functions/etc?

答: Most IDEs will default to saving with UTF-8 encoding, and you should almost certainly choose UTF-8 over ASCII when given the option. This is will ensure you don't run into weird problems with internationalization code.</p>

Title: Should my source code be in UTF-8?


答:
The choice is not between ASCII and UTF-8. ASCII is a 7-bit encoding, and UTF-8 supersedes it - any valid ASCII text is also valid UTF-8. The problems arise when you use non-ASCII characters; for these you have to pick between UTF-8, UTF-16, UTF-32, and various 8-bit encodings (ISO-xxxx, etc.).

The best solution is to stick with a strict ASCII charset, that is, just don't use any non-ASCII characters in your code. Most programming languages provide ways to express non-ASCII characters using ASCII characters, e.g. "\u1234" to indicate the Unicode code point at 1234. Especially, avoid using non-ASCII characters for identifiers. Even if they work correctly, people who use a different keyboard layout are going to curse you for making them type these characters.

If you can't avoid non-ASCII characters, UTF-8 is your best bet. Unlike UTF-16 and UTF-32, it is a superset of ASCII, which means anyone who opens it with the wrong encoding gets at least most of it right; and unlike 8-bit codepages, it can encode about every character you'll ever need, unambiguously, and it's available on every system, regardless of locale.

And then you have the encoding that your code processes; this doesn't have to be the same as the encoding of your source file. For example, I can easily write PHP in UTF-8, but set its internal multibyte-encoding to, say, Latin-1; because the PHP parser does not concern itself with encodings at all, but rather just reads byte sequences, my UTF-8 string literals will be misinterpreted as Latin-1. If I output these strings on a UTF-8 terminal, you won't see any differences, but string lengths and other multibyte operations (e.g. substr) will produce wrong results.

My rule of thumb is to use UTF-8 for everything; only if you absolutely have to deal with other encodings, convert to UTF-8 as early as possible and from UTF-8 as late as possible.

Title: Should my source code be in UTF-8?

Body:
I feel that often you don't really choose what format your code is in. I mean most of my tools in the past have decided for me. Or I haven't really even thought about it. I was using TextPad on windows the other day and as I was saving a file, it prompted me about ASCII, UTF-8/16, Unicode etc etc...

I am assuming that almost all code written is ASCII, but why should it be ASCII? Should we actually be using UTF-8 files now for source code, and why? I'd imagine this might be useful on multi-lingual teams. Are there standards associated with how multilingual teams name variables/functions/etc?


问:
Why should I declare a class as an abstract class?
I know the syntax, rules applied to abstract class and I want know usage of an abstract class

Abstract class can not be instantiated directly but can be extended by other class

What is the advantage of doing so?

How it is different from an Interface?

I know that one class can implement multiple interfaces but can only extend one abstract class. Is that only difference between an interface and an abstract class?

I am aware about usage of an Interface. I have learned that from Event delegation model of AWT in Java.

In which situations I should declare class as an abstract class? What is benefits of that?

答:
This answer does a good job of explaining the differences between an abstract class and an interface, but it doesn't answer why you should declare one.

From a purely technical standpoint, there is never a requirement to declare a class as abstract.

Consider the following three classes:

```<code>class Database {
    public String[] getTableNames() { return null; } //or throw an exception? who knows...
}

class SqlDatabase extends Database { } //TODO: override getTableNames

class OracleDatabase extends Database { }  //TODO: override getTableNames
</code>```

You don't have to make the Database class abstract, even though there is an obvious problem with its implementation: When you are writing this program, you could type new Database() and it would be valid, but it would never work.

Regardless, you would still get polymorphism, so as long as your program only makes SqlDatabase and OracleDatabase instances, you could write methods like:

```<code>public void printTableNames(Database database) {
    String[] names = database.getTableNames();
}
</code>```

Abstract classes improve the situation by preventing a developer from instantiating the base class, because a developer has marked it as having missing functionality.  It also provides compile-time safety so that you can ensure that any classes that extend your abstract class provide the bare minimum functionality to work, and you don't need to worry about putting stub methods (like the one above) that inheritors somehow have to magically know that they have to override a method in order to make it work.

Interfaces are a totally separate topic.  An interface lets you describe what operations can be performed on an object.  You would typically use interfaces when writing methods, components, etc. that use the services of other components, objects, but you don't care what the actual type of object you are getting the services from is.

Consider the following method:

```<code>public void saveToDatabase(IProductDatabase database) {
     database.addProduct(this.getName(), this.getPrice());
}
</code>```

You don't care about whether the database object inherits from any particular object, you just care that it has an addProduct method.  So in this case, an interface is better suited than making all of your classes happen to inherit from the same base class.

Sometimes the combination of the two works very nicely.  For example:

```<code>abstract class RemoteDatabase implements IProductDatabase {
    public abstract String[] connect();
    public abstract void writeRow(string col1, string col2);

    public void addProduct(String name, Double price) {
        connect();
        writeRow(name, price.toString());
    }
}

class SqlDatabase extends RemoteDatabase {
    //TODO override connect and writeRow
}

class OracleDatabase extends RemoteDatabase {
    //TODO override connect and writeRow
}

class FileDatabase implements IProductDatabase {
    public void addProduct(String name, Double price) {
         //TODO: just write to file
    }
}
</code>```

Notice how some of the databases inherit from RemoteDatabase to share some functionality (like connecting before writing a row), but FileDatabase is separate class that only implements IProductDatabase.

Body:
This answer does a good job of explaining the differences between an abstract class and an interface, but it doesn't answer why you should declare one.

From a purely technical standpoint, there is never a requirement to declare a class as abstract.

Consider the following three classes:

class Database {
    public String[] getTableNames() { return null; } //or throw an exception? who knows...
}

class SqlDatabase extends Database { } //TODO: override getTableNames

class OracleDatabase extends Database { }  //TODO: override getTableNames

You don't have to make the Database class abstract, even though there is an obvious problem with its implementation: When you are writing this program, you could type new Database() and it would be valid, but it would never work.

Regardless, you would still get polymorphism, so as long as your program only makes SqlDatabase and OracleDatabase instances, you could write methods like:

public void printTableNames(Database database) {
    String[] names = database.getTableNames();
}

Abstract classes improve the situation by preventing a developer from instantiating the base class, because a developer has marked it as having missing functionality.  It also provides compile-time safety so that you can ensure that any classes that extend your abstract class provide the bare minimum functionality to work, and you don't need to worry about putting stub methods (like the one above) that inheritors somehow have to magically know that they have to override a method in order to make it work.

Interfaces are a totally separate topic.  An interface lets you describe what operations can be performed on an object.  You would typically use interfaces when writing methods, components, etc. that use the services of other components, objects, but you don't care what the actual type of object you are getting the services from is.

Consider the following method:

public void saveToDatabase(IProductDatabase database) {
     database.addProduct(this.getName(), this.getPrice());
}

You don't care about whether the database object inherits from any particular object, you just care that it has an addProduct method.  So in this case, an interface is better suited than making all of your classes happen to inherit from the same base class.

Sometimes the combination of the two works very nicely.  For example:

abstract class RemoteDatabase implements IProductDatabase {
    public abstract String[] connect();
    public abstract void writeRow(string col1, string col2);

    public void addProduct(String name, Double price) {
        connect();
        writeRow(name, price.toString());
    }
}

class SqlDatabase extends RemoteDatabase {
    //TODO override connect and writeRow
}

class OracleDatabase extends RemoteDatabase {
    //TODO override connect and writeRow
}

class FileDatabase implements IProductDatabase {
    public void addProduct(String name, Double price) {
         //TODO: just write to file
    }
}

Notice how some of the databases inherit from RemoteDatabase to share some functionality (like connecting before writing a row), but FileDatabase is separate class that only implements IProductDatabase.


答:
can anyone please help to differentiate between has many and belongs to relationship. They seems quite same to me

It is good that you are learning about database design and data modeling. In data modeling, one has to name relationships carefully so that the meaning of the association is reflected on the model and so that the model can be checked for competence and accuracy.

The association/relationship name "has many" is very generic. For example, one could say that a BookStore has many Books (this is reading the association name left to right). If you read the association name from right to left, you should name the association in such a way that preserves the left-to-right name. So, you would say A book belongs to one Bookstore. The phrase has many is composed of 2 words. Has (which describes the relationship) and the many part which describes the cardinality.

As you can see the naming above is inaccurate. A more accurate naming would be:

A Bookstore Stocks zero, One or More BookCopy.

A BookCopy is stocked in a BookStore.

(assuming the bookstore has 1 branch).

In general the many side indicates a physical column called Foreign key to be defined. In the above example, that column would belong to the BookCopy table.

in UML the phrase "has a" indicates aggregation whereas the phrase "is a" indicates composition. You may want to take a look at a good book in ERD or UML or check the web for that.

Title: What is the main difference between HAS_MANY and BELONGS TO relationship in mysql?

Body: After making little progress in web development and php I figured out if I can make my grip strong on database designing, I will be able to reduce much code and time in developing the application. But I happen to be a dumb in database designing so can anyone please help to differentiate between has many and belongs to relationship. They seems quite same to me</p>


问:
How do you put a database online?
I have a very beginner question regarding web development.

I've had some experience with JSP, Hibernate, and MAMP to create a simple system for tracking inventory and sales. But this was all done locally on one computer.

This time, I want to create a system that could be accessible online. It's to help my mother track her business wherever she goes. So there would be similar aspects like tracking inventory and sales. I understand that you have to have a server in which to host all the files in. But I don't understand how you can access your database online. Or what sorts of applications or products should be used.

Currently the host of my database is localhost. How do put it online such that you can still do CRUD operations? Are there any guides to do this?

答:
This is more of a conceptual answer, but here it goes...

If you want to persist data, across multiple computers you obviously need to store the data; which you accurately identified as using a "Database" and second you need to access the data.  When accessing the data from the web people write web applications that access the database, and write frontends in html/css/javascript to display the information.

If you are looking to retrieve the data across the internet from another program (maybe installed on your mothers laptop) you can implement a Web-API such as REST, XMLRPC, JSONRPC, etc.

It is important to note that some type of security is needed if you are exposing the web server to the internet if you don't want others accessing your mothers information.

Title: How do you put a database online?


答:
If you work in a team, then entire team must decide whether you should prefix abstract classes with "Abstract".

If you work on your own, then it's entirely up to you, not me or anybody else on this site.


问:
PHP Parallel Requests and Session Stability
I've experienced a lot of issues that were the result of the nature of PHP living within the bounds of a stateless HTTP request, especially considering the asynchronous environment expected of modern web applications.

Namely, regeneration of session handles can cause session self-destructs if parallel requests are occurring.  Additionally, unless a request locks the session for its duration, session updates on parallel requests are at risk of conflicting and being overwritten by the other.  If they do lock the session, it forces serialization of the requests.

What did you find to be the most effective response to this problem?

Do you just live with it and implement workarounds?  Did you ultimately migrate to a different platform that didn't have this flaw?  Or is there a PHP solution to this problem I'm not aware of?

答:
The simple solution would be to call session_start() just before you actually need $_SESSION (and not at the head of the script) and session_write_close() just after you finished with it. That's a bit awkward, but it works fairly well.

The not so simple solution would be to write a custom database backed session handler (see: SessionHandler for PHP 5.4), fined tuned locking is a bit easier with a database. For example for MySQL/InnoDB you could have locking reads with "SELECT ... FOR UPDATE". If InnoDB sounds too resource hungry for you, you could go for a Memory table, but locking will be a bit more complicated.

That said, what you really need to ask yourself is whether you're relying on $_SESSION a bit too much, especially the default file based flavour. Have you considered Memcached? As a session backend and as an alternative persistence mechanism.

There are a lot other, perhaps more exotic choices, I'm currently exploring Amazon's DynamoDB as a session backend. Here's a brief outline of Dynamo backed sessions, written by our CTO, who couldn't resist calling me out:

Do not use session variables as a replacement for caching. For example, we have seen developers saving whole HTML blocks in the session array.


问:
Incorporating GoF design patterns in Objective-C without Abstract/Virtual classes
As someone who is becoming more comfortable working in Objective-C I would like to be able to incorporate more design patterns and OOP features in my projects but struggle to implement them as required by GoF because you cannot create an abstract class. I want to 1) avoid lots of subclassing, 2) minimize use of respondsToSelector, conformsToProtocol, etc, 3) avoid techniques like swizzling as much as possible, 4) maximize encapsulation, and 5) avoid long conditionals or lots of typedef enum.

For example, in a recent project I wanted to separate RestKit (a library for accessing RESTful services) from my UIViewController subclasses. I did so by incorporating an Adapter between the two with a base class of ModelController, which could access models. I also created the ModelControllerDelegate protocol for my VC's to wire up. But I experienced great difficulty in creating a ModelControllerDecorator without the use of an abstract base class. I wanted to be able to decorate my ModelController with different aspects, like PaginationDecorator, CompressionDecorator, QueryableDecorator, and so forth.

I've heard that using Objective-C++ is one way to incorporate more OOP features, but how about using standard Objective-C language features? How have you been able to incorporate GoF design patterns that use C++ style features (like virtual classes) in your projects?

答:
I'm not sure why you would think that Objective-C's implementation of OO is in any way inferior to C++'s? Many, including the inventor of the term "OO", would argue that the opposite is true: Objective-C's OO is as good as Smalltalk's OO because, well, Objective-C's OO is Smalltalk's OO. It even uses Smalltalk's syntax!

The GoF book contains Smalltalk code for all the design patterns, the design pattern movement started in Smalltalk, many design patterns were first discovered and described in Smalltalk.

Note, however, that some of the Smalltalk implementations in the GoF book are of questionable quality. Meaning, they try to stay too close to the C++ implementation and don't leverage some of Smalltalk's dynamic features. Some of the patterns aren't even necessary at all in a language like Smalltalk or Objective-C, yet the book still contains Smalltalk implementations for them. (Three of the GoF came from the C++ community, only one from the Smalltalk community, so this kind of bias isn't really unexpected.)

I also don't quite understand why you think you can't have abstract classes in Objective-C. Of course, you can have classes where some of the methods are to be implemented by subclasses. That's the whole point of subclasses in the first place!

About Objective-C++: Objective-C is a language that was created by orthogonally bolting Smalltalk sideways onto C. One major design goal was that the Smalltalk and the C parts should not interact with each other. Objective-C++ is the same. The Smalltalk and C++ parts don't interact. Which means that you have a language with two independent, completely orthogonal type systems, and two independent, completely orthogonal object systems that do not interact or integrate at all with each other. The only thing it makes sense to use from C++ in Objective-C++ are the things that are not about OO: templates, mostly.


答:
```<code>protected abstract SomeClass { }
</code>```

This tells me this is an Abstract class. Adding a prefix is a tautology and anti-pattern and not appropriate in most cases, see the link where it talks about package local being an exception for example.

In most cases Abstract classes shouldn't be part of a public facing API, if it is there should really be a good reason and a good reason should provide an obviously good name other than AbstractSomeClass.

In most cases if you can't come up with a more descriptive name you probably need to do some redesign.

Body:
protected abstract SomeClass { }

This tells me this is an Abstract class. Adding a prefix is a tautology and anti-pattern and not appropriate in most cases, see the link where it talks about package local being an exception for example.

In most cases Abstract classes shouldn't be part of a public facing API, if it is there should really be a good reason and a good reason should provide an obviously good name other than AbstractSomeClass.

In most cases if you can't come up with a more descriptive name you probably need to do some redesign.


问:
What is the term for a really BIG source code commit?
Sometimes when we check the commit history of a software, we may see that there are a few commits that are really BIG - they may change 10 or 20 files with hundreds of changed source code lines (delta). I remember that there is a commonly used term for such BIG commit but I can't recall exactly what that term is. Can anyone help me? What is the term that programmers usually use to refer to such BIG and giant commit?

BTW, is committing a lot of changes all together a good practice?

UPDATE: thank you guys for the inspiring discussion! But I think "code bomb" is the term that I'm looking for.

答: A "hot steaming lump of code". :-)</p>

Body: A "hot steaming lump of code". :-)


问:
Is it bad practice to use an interface for categorization only?
For example:

Say I have classes A, B, C. I have two interfaces, lets call them IAnimal and IDog. IDog inherits from IAnimal. A and B are IDogs, while C is not, but it is an IAnimal.

The important part is that IDog supplies no additional functionality. It is only used to allow A and B, but not C, to be passed as an argument to certain methods.

Is this bad practice?

答:
Interface that has no any member or has exactly same members with another interface that is inherited from same interface called Marker Interface and you are using it as a marker.

It is not bad practice but interface can be replaced by attributes(annotations) if the language that you are using support it.

I can confidently say that it is not bad practice because i have seen heavy usage "Marker Interface" pattern in Orchard Project

Here is sample from Orchard project.

```<code>public interface ISingletonDependency : IDependency {}

/// <summary>
/// Base interface for services that may *only* be instantiated in a unit of work.
/// This interface is used to guarantee they are not accidentally referenced by a singleton dependency.
/// </summary>
public interface IUnitOfWorkDependency : IDependency {}

/// <summary>
/// Base interface for services that are instantiated per usage.
/// </summary>
public interface ITransientDependency : IDependency {}
</code>```

Please refer to Marker Interface.

Body:
Interface that has no any member or has exactly same members with another interface that is inherited from same interface called Marker Interface and you are using it as a marker.

It is not bad practice but interface can be replaced by attributes(annotations) if the language that you are using support it.

I can confidently say that it is not bad practice because i have seen heavy usage "Marker Interface" pattern in Orchard Project

Here is sample from Orchard project.

public interface ISingletonDependency : IDependency {}

/// <summary>
/// Base interface for services that may *only* be instantiated in a unit of work.
/// This interface is used to guarantee they are not accidentally referenced by a singleton dependency.
/// </summary>
public interface IUnitOfWorkDependency : IDependency {}

/// <summary>
/// Base interface for services that are instantiated per usage.
/// </summary>
public interface ITransientDependency : IDependency {}

Please refer to Marker Interface.


答:
Yes, it's a bad practice in almost every language.

Types are not there to encode data; they're an aid to prove that your data goes where it needs to go and behaves like it needs to behave. The only reason to sub-type is if a polymorphic behavior changes (and not always then).

Since there's no typing, what a IDog can do is implied. One programmer thinks one thing, another thinks another and things break down. Or the things it represents increase as you need more fine grained control.

[edit: clarification]

What I mean is that you're doing some logic based on the interface. Why can some methods only work with dogs and others any animal? That difference is an implied contract since there is no actual member that provides the difference; no actual data in the system. The only difference is the interface (hence the 'no typing' comment), and what that means will differ between programmers.
[/edit]

Certain languages provide trait mechanisms where this isn't too bad but those tend to focus on capabilities, not refinement. I've little experience with them so can't speak to the best practices there. In C++/Java/C# though... not good.

Title: Is it bad practice to use an interface for categorization only?

Body:
For example:

Say I have classes A, B, C. I have two interfaces, lets call them IAnimal and IDog. IDog inherits from IAnimal. A and B are IDogs, while C is not, but it is an IAnimal.

The important part is that IDog supplies no additional functionality. It is only used to allow A and B, but not C, to be passed as an argument to certain methods.

Is this bad practice?


问:
Do Android developers have to pay sales taxes?
According to blog post by RetroDreamer Android developers have to pay sales taxes for their App sales in countries with have sales taxes while Apple developers don't as Apple pays the taxes directly.

Is this an accurate description? Is so, how do the various people who publish Android apps handle it?

答:
I run an e-commerce business delivering goods to customers by UPS. The government which regulates my sales (the State of California) requires that I collect tax on goods which are delivered within the state of California. I consider UPS to be the customer's agent and I collect sales tax as if the customer came into my office.

All other states and countries are free to control their citizens as they wish, however, I am not handling anything with their taxes.

My opinion (not any actual advice) would be to find out what a comparable company in your location does when they sell packaged software and mail it elsewhere. Then talk to the tax collector with authority over you about how to handle this.


问:
What is an “implementation plan”?
I was recently given the task of creating an implementation plan document. When I asked for an example of one that I could look at, I was told to look at the Project Plan that had already been created an use that as a base. I'm still a bit confused on what I should be creating.

Can anyone point me to a good example out there or to something that explains what this is and more importantly the details about what it should contain.

答:
An implementation plan is a technical document that provides a high level view of the overall structure of your project. Its contents may vary, depending on what information you have in other documents, like the Project Plan, and if this is the first time you are writing an implementation plan it couldn't hurt to ask for a template or the plan for a previous project.

Some examples:

W3C - Implementation Plan for Web Accessibility (short and simple)

NASA JPL - Software Management and Implementation Plan For The Microwave Limb Sounder (MLS) Carried on a NASA Earth Observing System (EOS) Satellite (formal, pdf)

University of Melbourne - National Servers Program Implementation Plan (hardware stack oriented, pdf)

California Institute of Technology - Software Implementation Plan for the Advanced Composition Explorer Science Payload (formal, old, pdf)

From these, the University of Melbourne one has a very typical structure:

1 OVERVIEW

2 POLICY DEVELOPMENT WITH THE SECTOR

3 SERVICE AND SUPPORT ENVIRONMENT DEVELOPMENT PLAN

3.1 ITS positioning

3.2 Infrastructure overview

3.2.1 Virtual Machine configuration

3.2.2 Data storage infrastructure

3.2.3 Connectivity and Bandwidth

3.2.4 Failover and redundancy

3.2.5 Authorisation and Authentication

3.2.6 VM Capacity growth

3.2.7 Data centre development

3.3 Deployment plan

3.4 Access model

3.5 Roles and responsibilities

3.6 Support and the National Servers Program helpdesk

Title: What is an “implementation plan”?


答:
What if you want to write an abstract AbstractSyntaxTree class? Or perhaps just an abstract SyntaxTree?

It's not conventional and it can easily confuse people.


问:
Queries on online project outsourcing sites
I have been looking at RentACoder, Freelancer and eLance from last few years but I always hesitated to register at these site. Hesitation includes little worry too. These questions fill me:

(1) Is there a legal contract between the bidder and the coder? Just in case my delivery date extends, what happens?

(2) After delivery, payment reach without trouble or not.

(3) In case the customer didn't find the project useful, then? Probably he might say that it is not useful to me and you return money. He might copy the source code and return another copy to me.

(4) What are further recommendations? How should I start?

答:
(1) Is there a legal contract between the bidder and the coder? Just in case my delivery date extends, what happens?

Yes and no. For RentACoder.com you have to comply to the project's conditions that are in most case standards. Standard stuff such as intellectual property that you must give away to the company your work for. Obvious things like that.

(2) After delivery, payment reach without trouble or not.

RentACoder.com has an escrow service that limit the troubles. The company that post a bid request pay in advance. But you don't receive the money yet. If you don't provide the work as requested, the company can decide not accept your work. Then there is an arbitration service you can initiate where an arbitrator evaluate the situation and decide what to do. In most case, the process and decision is fair.

(3) In case the customer didn't find the project useful, then? Probably he might say that it is not useful to me and you return money. He might copy the source code and return another copy to me.

It's a risk yes, and very few do it. The arbitration service is pretty fair and will limit those behavior.

(4) What are further recommendations? How should I start?

Create an account, and start to bid on projects.

Give what customers want.

I have managed hundred of projects on the platforms you mention. Here is how I work, and I think that most people do the same.

I discard 9 or 10 bids from user with less than 15 ratings and if the average rating is less than 95%. I then filter on bid price. Sometimes, when I read a nice cover letter from a lower bid, I can decide to go with him. Sometimes in parallel with a higher bid (assign the same project to two different bidders).

I discard every bid with no personal cover letter. I've observed that no cover letter means in most time that he didn't read the requirements. It will leads you to failure.

I generally don't care of the location of the bidder. However, I require a good knowledge of English.

When you get a project, do your best to satisfy the customer. Don't start any new project until the previous one is done. Target high quality. If the customer is not satisfied, negotiate a refund.

You WILL face bad behavior and customers that will take advantage of you. But only at the beginning. As you gain high ratings, you will be able to bid higher and that problem will be less frequent.

To summarize:

Bid lower than others bidders to increase your chances to get projects assigned. Explain why you bid lower

Customer that take lower bids are the most difficult, so you will need to work harder than usual

Always write a personalized cover letter that shows you know what the customer wants

Don't hesitate to negotiate full refund if you think the customer is not happy

Work on one project at a time. Or two maximum if communication with the customer is slow

At the end of each project, add your success in your portfolio


问:
Is it safe to trust emulators when developing multi platform/resolution mobile apps?
I'm currently developing some mobile applications using PhoneGap for Android, testing only in 3 different kinds of smartphones, and using emulators to test on the others target phone resolutions. Later on I will probably use a iOS emulator.

I would like to know if I will have any problems with that.

答: I have never used PhoneGap but based on my experience with Android's, iOS', and Corona SDK's emulators you should be fine. Scaling and screen resolutions have always been pretty reliable but when it comes things like animation, and audio those can be really device specific for Android and the emulator is not always accurate.</p>


问:
I'm doing 90% maintenance and 10% development, is this normal?
I have just recently started my career as a web developer for a medium sized company. As soon as I started I got the task of expanding an existing application (badly coded, developed by multiple programmers over the years, handles the same tasks in different ways, zero structure).

So after I had successfully extended this application with the requested functionality, they gave me the task to fully maintain the application. This was of course not a problem, or so I thought. But then I got to hear I wasn't allowed to improve the existing code and to only focus on bug fixes when a bug gets reported.

From then on I have had three more projects just like the above, that I now also have to maintain. And I got four projects where I was allowed to create the application from scratch, and I have to maintain those as well.

At this moment I'm slightly beginning to get crazy from the daily mails of users (read managers) for each application I have to maintain. They expect me to handle these mails directly while also working on two other new projects (and there are already five more projects lined up after those). The sad thing is I have yet to receive a bug report on anything that I have coded myself. For that I have only received the occasional let's-do-things-180-degrees-different change requests.

Anyway, is this normal? In my opinion I'm doing the work equivalent of a whole team of developers.

Was I an idiot when I initially expected things to be different?

I guess this post has turned into a big rant, but please tell me that this is not the same for every developer.

P.S. My salary is almost equal if not lower than that of a cashier at a supermarket.

答: In my experience the academic world or the first 6-12 months of a tech-oriented start-up are the only two reliable areas where you'll encounter a true blank slate. They both carry their own costs but if you love to code and are often horrified by the quality of the code you find out in the wild, you should start pointing your career in one of these directions.</p>


答:
It really depends on what you're doing. If you're creating HTML5+CSS+JS for a web/PhoneGap app, it will probably be OK as initial test (unless you encounter bugs caused by PhoneGap itself). The reason is that underneath both the Android "Internet" browser and iOS' Safari, there is a WebKit core, which is somewhat cross-platform and mature enough.

If, on the other hand, you're writing native code, then don't trust the simulator/emulator. There is a myriad of things that can go wrong. An iOS Simulator example that has bitten me: iOS is case-sensitive. Mac OS X is case-preserving*. Guess what happens when you request a file from the iOS device that is in the wrong case. Tip: EXC_BAD_ACCESS. App - Rejected! (Of course, you should test on a real device way before sending the app for review, so did I, and there wasn't really a rejection).

I can't even start to enumerate the differences, and I'm certain Android emulators do have inconsistencies with the real devices, too. It's just a too complex system to work smoothly on a non-native CPU and in another host OS.

Simulators and emulators do not exist to replace testing devices, they exist to let you reduce testing time for things you'll test later more thoroughly on the devices itself and (possibly) to allow you to get a basic understanding of the framework without paying for the test.

The moral of the story is: don't trust simulators/emulators, they'll turn on you the moment you start depending on them. And from what I've seen, differences are usually very subtle, so finding them and debugging the app is hell.

Title: Is it safe to trust emulators when developing multi platform/resolution mobile apps?

Body:
I'm currently developing some mobile applications using PhoneGap for Android, testing only in 3 different kinds of smartphones, and using emulators to test on the others target phone resolutions. Later on I will probably use a iOS emulator.

I would like to know if I will have any problems with that.


问:
Why Does a Developer Need a "Native" Internet Access?

Setup

We have a situation where developers connect to their development boxes via Citrix terminals (that are installed on their laptops), which brings them into a Gnome session (e.g. Linux), where they do all the coding.

Problem

Until now developers had Internet Access from those Citrix environments + installed Firefox browser. Starting right now the Internet Access [from that environment] is taken away.

Developers still however have the access via their IE9 browser (strictly IE9) from their laptops.

This of course makes the whole development process a lot less productive. At the same time, it is extremely difficult to come up with a solid explanation, reasons on why the productivity suffers from switching environments (on the same laptop) in order to use the Internet.

Question

I'm turning to SO community to help us find those reasons that can convince decision makers to give Internet Access back to developers [from the system they develop on].

答:
Depending on how your environment is configured I'm not convinced you do.  Albeit it may take some changes on how you work I would be suspicious of the fact that it has a heavy impact given that you do have internet access on your local machine.  A second monitor would be helpful because then you could refer to the 'research' in the browser on one and the remote machine in the other.

Personally I use a remote environment at the office (RDP) and although we have internet access on the remote machines I rarely use it.  Really the only time I do use it is when I need to install some utility and I'm to lazy to transfer it from my local machine to the remote machine.

The one caveat to this thought is that you do need copy/paste to work between the local machine and the remote machine.  A way to transfer files would also be necessary.

Update:
Another thought that occurred to me is that this is a fairly common issue when working in sensitive / secure / classified environments (either corporate or government).  I've even worked in an environment where the extreme was taken and all internet access required going to a physically different computer on a physically separate network.  In that case file transfers from the 'internet' was difficult to get approved.  It was painful to develop under that (extreme) situation but doable.


问:
What are/would be the characterists and applications of a programming paradigm where functions can't have statements?
Suppose there is a language where, instead of statements, functions could only be defined in relation to other functions and operators such as partial application and composition. What would be the characteristics of such language? Could everything that is done with statements be done on this design? What would be the limitations? Are there languages like this?</p>

答:
I have used such a language. Haskell.

It is Turing-complete, and has been used to write large business applications.

Although functions in Haskell are not supposed to have side effects, there are many that do, and act much like statements. (These are obviously necessary to do anything.) As an example, here is a Hello World example from Wikipedia:

```<code>module Main where

main :: IO ()
main = putStrLn "Hello, World!"
</code>```

Body:
I have used such a language. Haskell.

It is Turing-complete, and has been used to write large business applications.

Although functions in Haskell are not supposed to have side effects, there are many that do, and act much like statements. (These are obviously necessary to do anything.) As an example, here is a Hello World example from Wikipedia:

module Main where

main :: IO ()
main = putStrLn "Hello, World!"


答:
I cannot see how this would make a great deal of difference in your productivity. (Other than the obvious having to use IE9 instead of Firefox).

Instead of having multiple windows open inside your terminal window, you have the terminal window and browser open.

If you have multiple monitors, then this may actually make your productivity better (terminal on screen 1, browser on screen 2).

If you are sure it has caused a drop in productivity, then you need to be able to prove this. Track your working habits, note down things which are slowing you down.

Title: Why Does a Developer Need a "Native" Internet Access?

Body:
Setup

We have a situation where developers connect to their development boxes via Citrix terminals (that are installed on their laptops), which brings them into a Gnome session (e.g. Linux), where they do all the coding.

Problem

Until now developers had Internet Access from those Citrix environments + installed Firefox browser. Starting right now the Internet Access [from that environment] is taken away.

Developers still however have the access via their IE9 browser (strictly IE9) from their laptops.

This of course makes the whole development process a lot less productive. At the same time, it is extremely difficult to come up with a solid explanation, reasons on why the productivity suffers from switching environments (on the same laptop) in order to use the Internet.

Question

I'm turning to SO community to help us find those reasons that can convince decision makers to give Internet Access back to developers [from the system they develop on].


答:
It's not entirely clear what you are asking here. The concepts of "function" and "statement" are mutually incompatible: a function is a subroutine which returns a value, has no side-effect and is referentially transparent, whereas a statement doesn't have a value and thus must necessarily have a side-effect and thus cannot be referentially transparent.

So, a function can never be defined in terms of statements, only in terms of expressions.

So, yes, there are languages where functions cannot contain statements, namely all functional programming languages. These don't even have statements.

Haskell is a good example. (Note: Haskell actually does have statements. But not at the level of actual computation. For example, module import is a statement, or defining a type. However, those are compile time constructs, not runtime constructs, so, the idea of "returning a value" doesn't even make sense anyway.)

Note, there are also many languages which aren't functional languages that nonetheless don't have statements, e.g. Ruby, Io, Ioke, Seph, Smalltalk, Self, Newspeak, Scheme.

Or, are you talking about programming by combining functions? Then, again, yes, this does exist, and it is called "functional programming". In functional programming, you build programs by using functions as your main (and only!) building block and structuring tool, combining and manipulating them. There are even languages where functions are the only primitive the language provides. Again, Haskell, is an example. It does have things like numeric literals (e.g. 1), but you can interpret those as nullary functions.

Of course, the original manifestation of this idea is lambda calculus.

There are even languages where you don't even have functions, you only have combinators. Unlambda is such a language, which as its name suggests is one of the very few functional programming languages that is not based on lambda calculus. Instead, it is based on the SKI combinator calculus.

The SKI combinator calculus has only three primitives: the S combinator, the K combinator and the I combinator. (Actually, it turns out that the I combinator can be expressed as SKK, so it is not really primitive, you can get by with just S and K.) It doesn't have any sort of data: no booleans, no numbers, no nothing. (Just like lambda calculus.) However, unlike lambda calculus, it also doesn't have, well, lambdas (i.e. functions) nor variables. And yet, it is a Turing-complete model of computation which actually even precedes both Turing Machines and Lambda Calculus.

Title: What are/would be the characterists and applications of a programming paradigm where functions can't have statements?

Body: Suppose there is a language where, instead of statements, functions could only be defined in relation to other functions and operators such as partial application and composition. What would be the characteristics of such language? Could everything that is done with statements be done on this design? What would be the limitations? Are there languages like this?</p>


问:
Learn programming backwards, or "so I failed the FizzBuzz test. Now what?"

A Little Background

I'm 28 today, and I've never had any formal training in software development, but I do have two higher education degrees equivalent to a B.A in Public Relations and an Executive MBA focused on Project Management. I've worked on those fields for about 6 years total an then, 2,5 years ago I quit/lost my job and decided to shift directions.

After a month thinking things through I decided to start freelancing developing small websites in WordPress. I self-learned my way into it and today I can say I run a humble but successful career developing themes and plugins from scratch for my clients - mostly agencies outsourcing some of their dev work for medium/large websites.

But sometimes I just feel that not having studied enough math, or not having a formal understanding of things really holds me behind when I have to compete or work with more experienced developers. I'm constantly looking for ways to learn more but I seem to lack the basics.

Unfortunately, spending 4 more years in Computer Science is not an option right now, so I'm trying to learn all I can from books and online resources. This method is never going to have NASA employ me but I really don't care right now. My goal is to first pass the bar and to be able to call myself a real programmer.

I'm currently spending my spare time studying Java For Programmers (to get a hold on a language everyone says is difficult/demanding), reading excerpts of Code Complete (to get hold of best practices) and also Code: The Hidden Language of Computer Hardware and Software (to grasp the inner workings of computers).

TL;DR

So, my current situation is this: I'm basically capable of writing any complete system in PHP (with the help of Google and a few books), integrating Ajax, SQL and whatnot, and maybe a little slower than an experienced dev would expect due to all the research involved.

But I was stranded yesterday trying to figure out (not Google) a solution for the FizzBuzz test because I didn't have the if($n1 % $n2 == 0) method modulus operator memorized.

What would you suggest as a good way to solve this dilemma? What subjects/books should I study that would get me solving problems faster and maybe more "in a programmers way"?

EDIT - Seems that there was some confusion about what did I not know to solve FizzBuzz.

Maybe I didn't express myself right: I knew the steps needed to solve the problem. What I didn't memorize was the modulus operator. The problem was in transposing basic math to the program, not in knowing basic math.

I took the test for fun, after reading about it on Coding Horror. I just decided it was a good base-comparison line between me and formally-trained devs.

I just used this as an example of how not having dealt with math in a computer environment before makes me lose time looking up basic things like modulus operators to be able to solve simple problems.

答:
I think you have to take a hard look on why you were stranded trying to figure out FizzBuzz. So, suppose, you remembered there's an operator that given $n tell you if it's divisible by an number. And you have bad luck to forget what it is. Fine, why don't you proceed to trying to do it in any other way? If you know anything about code, you should be able to find a dozen other ways of doing it. Some of them may look weird - like, for example, putting every multiple of 5 in an array and then checking if $n is among them - and it is a bad solution, but it still would be a solution. However, you're saying you didn't have any, you just were stuck. It may be a symptom of a bigger issue.

There's two things in programming that you need to learn.

Bag of tricks. How to read file in PHP, how to parse XML in Java, how to connect to database in Python. Some people memorize it, but in fact these things are worth memorizing only if you use them every day. Otherwise, you just go to the docs and look it up. These things do not have any substance except for their literal form - you just need to know how the particular magic incantation sounds and what the result will be.

Mindset. This is the most important thing. This is how you program, and this has nothing to do with memorization. You need to understand how to explain things you want done to the computer, which ways there are for doing it and which of them to use in any particular case. Now, given modern tools and modern documentation, it is plausible that one could write an entire CMS in PHP using "bag of tricks" approach, but once you encounter a task that has no ready-made solution, you're "stuck".

From you description looks like you started with the first part, but somewhat lacking on the second part. Good CS course usually helps with that a lot, but is not the only way. Trying to solve different problems and read about how these problems need to be solved, reading fundamental books quoted here - all that would help. Once you got the programmer's mindset, you'll discover that getting into using a new bag of tricks won't be much of a problem. You'd have to google here and there, of course, but you will never be stranded.


问:
Legality of collaborative reverse-engineering
I have been disassembling a large software project on my own, as a hobby. It is an educational exercise and I have learned a lot in the process. That said, I feel that my progress would be considerably quicker if I was to collaborate on the project with other like-minded individuals.

Herein lies the problem -- maybe. I am reversing this software for personal interest and potentially (but unlikely; given the magnitude of the codebase in question) implementing an interoperable service to interact with this software, replacing the vendor's own service. My (very limited) understanding is that this particular use-case is protected under copyright law.

However, my wish is to collaborate with others freely on the Internet, in a similar system employed by open source projects: version control repositories of assembly files, wikis to coordinate and share knowledge, public mailing lists, et cetera. I have a feeling this may be iffy at best.

Is what I want to do blatantly illegal, a gray area or even legally defensible? Would the situation be any different if the collaboration was in private rather than public? If it has any bearing on the answer, I am located in Australia and the software vendor in located in the USA.

答:
I like to say that no answerers here will pay for your liabilities.

You must ask a lawyer.

My opinion: the risk is very limited since you are an individual of 21 year old, so probably without many assets. Suing you will be a waste of time and money since you won't be able to pay.


答:
Here's one possibility as to why this makes such a difference.  This experiment hit the media a few months ago:

Study: Walking through a doorway wipes out memory

It talks how a doorway acts as a sort of mental reset button.  Most people have had the experience of walking into a room and forgetting what they came there for.  The controlled study shows that it's a real phenomenon, not merely attributable to age or poor memory.

It may be that by having to switch contexts, from your remote Citrix environment to your local laptop, you are, in effect, walking through a virtual doorway.  It may be having the same effect as a physical doorway, compartmentalizing your memory and causing you to forget what you came to the browser for.

This forgetting, in turn, might lead you to do other things people do with browsers (check Facebook, check e-mail, read random news sites).  In the meantime, the doorway effect works in both directions: You eventually return to the Citrix environment and forget what you were working on there.


答:
I call it "typical SVN commit" or "tomorrow is release day commit"

As much as I love SVN, I'm just turned off by the fact that I can't do local commits.

EDIT: they usually have the words "stuff" and "beer" in the commit message.

EDIT AGAIN: Committing a lot of changes, while not necessarily a bad practice, should be as much as possible avoided. I find it easier to review a revision/commit that's short and concise. (paired with a well-written commit message, see my previous edit for a bad example)

Title: What is the term for a really BIG source code commit?

Body:
Sometimes when we check the commit history of a software, we may see that there are a few commits that are really BIG - they may change 10 or 20 files with hundreds of changed source code lines (delta). I remember that there is a commonly used term for such BIG commit but I can't recall exactly what that term is. Can anyone help me? What is the term that programmers usually use to refer to such BIG and giant commit?

BTW, is committing a lot of changes all together a good practice?

UPDATE: thank you guys for the inspiring discussion! But I think "code bomb" is the term that I'm looking for.


答:
For me, my strategy is that I only attack the problem that is relevant to what I'm working, So my advice is that you don't have to learn it all, just read those things that are relevant to what you are working, because if you tried to learn it all at once then there is a tendency that you get prostrated and end up hating programming.

Peace


问:
Is constantly looking for code examples a sign of a bad developer?
I am a CS student with several years of experience in C and C++, and for the last few years I've been constantly working with Java/Objective C doing app development and now I have switched to web development and am mainly focused on ruby on rails and I came to the realization that (as with app development , really) I reference other code way too much. I constantly Google functionality for lots of things I imagine I should be able to do from scratch and it's really cracked my confidence a bit.

Basic fundamentals are not an issue, I hate to use this as an example but I can run through javabat in both java/python at a sprint - obviously not an accomplishment and but what I mean to say is I have a strong base for the fundamentals I think?

I know what I need to use typically but reference syntax constantly. Would love some advice and input on this, as it has been holding me back pretty solidly in terms of looking for work in this field even though I'm finishing my degree. My main reason for asking is not really about employment, but more that I don't want to be the only guy at a hackathon not hammering out nonstop code and sitting there with 20 Google/github tabs open, and I have refrained from attending any due to a slight lack of confidence...

Is a person a bad developer by constantly looking to code examples for moderate to complex tasks?

答:
I think it is a bit like playing Chess. We check the pieces individually and trace where they can move according to the rules, and we must go through that conscious checking for some amount of time until the subconscious joins in, revealing patterns and inspired sequences.

With programming there can be more pieces and rules, I am often stumbling with syntax and stuck on bugs which take forever to find by going through 'the rules', but eventually the subconscious will kick in. When it stays long enough, i can read back sometimes and marvel at what it can do.


答:
I'd like to add onto Kyralessa's answer.

We store data in our human memory, only we have less registers than the computer. While we are looking at the data it is FRESH in our minds. If we must switch screens, the data is lost from our mind and we have to spend time reloading it into our brain.

Speeding up the context switch to the new screen (in this case the browser) could allow you to remember your data longer. If switching out of the Citrix environment is a chore (takes more than 0.25 seconds) then it's going to be harder to hold onto the data in your mind.

Better yet is finding a way to have 2 monitors. Every programmer who has experienced 2 monitors can tell you the huge productivity boost it gives. A pointy-haired boss would see it as a waste of money and request developers maxize the window they are currently viewing or spend time re-sizing windows. While your doing that, you loose data in your mind.

Two monitors allows VERY FAST context switching where you can reload data into your mind with the glance of an eye. Being forced to maximize windows on a single monitor is a slow gross-motor operation.

Speed of the context switch matters.  If you can speed it up to eye-glaces then great!  If you are forced to use 1 monitor then you must have the fastest switch to a new window.