问:
How Client Side Programming Works
I'm not coming from web-development at all, but am looking to build a web application.

So far, I've looked into all the server-side stuff (for example, I think my stack will be Linux + node.js + ExpressJS + MongoDB), and have learnt a lot! At this point, I'm comfortable setting up an HTTP server, routing requests, using RESTfull interaction with a database, and serving dynamic HTML using an HTML template engine like ejs or Jade. I even looked into Websockets as a means for establishing a TCP connection to add fast user interaction without page refreshing.

Now I'm looking to do pretty stuff; add graphs, tabs, ect to my web-applications! I've looked into things like Dojo, JQuery, CanvasJS, AngularJS ect, and all them seem cool. Problem is, now that I think of it, I have no idea how client-side programming works. For example, in AngularJS I may find something like:

```<code>   <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
    <script src="components.js"></script>
  </head>
</code>```

What is this saying? Does my server actually replace "components.js" with the actual "componennts.js" code before transmitting the response? What's going on with the https://ajax... source? Does the browser, (or the server?) actually have to go to this url, and retrieve code?

As I said, as far as I'm concerned, the server responds with an HTML document composed of ASCII characters. What then, is actually running on the client side, and how does it get this code? (i.e. on V8 or whatever).

答: what Carlos said regarding .js files also applies to image (.jpg) and style source files (*.css)  Once all files are downloaded, the client uses them to view and/or manipulate the page.  If the browser does not recognize a command (because the browser is old, it has javascript turned off, or the code uses vendor-specific code), the app 'crashes'

Title: How Client Side Programming Works


问:
Understanding bitmap logic
I was going though this blog and it says

You can represent a list of distinct integers no larger than N using exactly N bits: if the integer i appears in your list, you set the i th bit to true. Bits for which there is no corresponding integers are set to false. For example, the integers 3, 4, 7 can be represented as 00011001. As another example, the integers 1, 2, 7 can be represented as 01100001.

Can someone please explain me how [3, 4, 7] = 00011001 and [1, 2, 7] = 01100001 and also why 8 bits are taken?

答: Think of it as ['0d: OFF', '1st: OFF', '2nd: OFF', '3rd: ON', '4th: ON', '5th: OFF', '6th: OFF', '7th: ON'].</p>

ContentLicense: CC BY-SA 3.0

Title: Understanding bitmap logic


问:
Is it common to print out code on paper?
I like to keep my lines of code under 80 characters because:

I don't have to do any horizontal scrolling;

I know the line is probably too complicated if it exceeds this limit; and

it prints out nicely on paper.

Concerning the latter, I've met only a few who actually print out code to look at (I'm one of them). So how common is it to print out code?

答:
In the last 10 years or so, I only recall printing out code, so I can use highlighter pens on it, to mark up sections that have something in common before planning how to refractor the code.

I do however sometimes miss being able to print out onto wide continuous paper, as laying the code out on the floor, could give a good overview, mostly along with coloured highlighter pens and postit notes.  A4 printed pagers are no better then what a reasonable monitor gives.

Monitors have got a lot better and bigger while printers are worse for code then they used to be.

ContentLicense: CC BY-SA 2.5


问:
How to do a clean refactoring of an If Else Code without leaving any free blocks?
```<code>if(condition1)
{
   Statement1A;
   Statement1B;
}
else if(condition2)
{
  Statement2;
}
else if(condition3)
{
  Statement3;
}
else
{
   Statement1A;
   Statement1B;
}

   return;
</code>```

I would like to refactor that code so that I do not duplicate Statements. I always need to check condition1 before any other condition. (So I cannot just change the order of the conditions). I also do not want to write &&!condition1 after every other condition.

I solved it like this

```<code>if(condition1)
{
}
else if(condition2)
{
  Statement2;
  return;
}
else if(condition3)
{
  Statement3;
  return;
}

Statement1A;
Statement1B;
return;
</code>```

However I do not think an empty if condition will be easily understandable by others (even by me after a while).

What is a better approach?

答:
I'm not a fan of your empty if and return statements.  It becomes tricky to follow, and it's generally frowned upon to have multiple return statements within the body of your code.  Given your goals, I would do something like this:

```<code>if ( ! condition1 )
{
   if ( condition2 )
      Statement2;
   else if ( condition3 )
      Statement3;
}
else
{
   Statement1A;
   Statement1B;
}
</code>```

Note: This solution is wrong!  Consider !condition1  && !condition2  && !condition3

Body:
I'm not a fan of your empty if and return statements.  It becomes tricky to follow, and it's generally frowned upon to have multiple return statements within the body of your code.  Given your goals, I would do something like this:

if ( ! condition1 )
{
   if ( condition2 )
      Statement2;
   else if ( condition3 )
      Statement3;
}
else
{
   Statement1A;
   Statement1B;
}

Note: This solution is wrong!  Consider !condition1  && !condition2  && !condition3


问:
Is functional programming actually used to create applications?

Possible Duplicate:

  What are some well known applications written in F#?

I see a lot of people talking about how cool functional programming is, how awesome Lisp and Haskell and F# are, etc, but what I don't see is them actually being used.  Just about every program on my computer is written in either something in the C family, Delphi, or Python.  I see tutorials talking about how easy it is to use functional languages to do complicated math problems, but no one talking about using them to do things most people actually care about using computers for, like business applications and games.

Does anyone have any examples of actual programs that people have heard of and are using, written in a functional language?  The only one I can think of off the top of my head is Abuse, from almost 15 years ago.  (Things like Emacs, where the core program is written in C with a functional language scripting layer on top, don't count.)

答:
Lisp dialects are used all over the place - but it's not really mainstream... yet

Jak and Daxter (YouTube demo) was written using GOAL (Game Oriented Assembly Lisp). From the Gamasutra review, I quote (emphasis added for clarity):

5. GOAL rules! Practically all of the run-time code (approximately half a
  million lines of source code) was
  written in GOAL (Game Object Assembly
  Lisp [acronym correct?]), Naughty Dog's own internally
  developed language, which was based on
  the Lisp programming language. Before
  you dismiss us as crazy, consider the
  many advantages of having a custom
  compiler.

Lisp has a very consistent, small set
  of syntactic rules involving the
  construction and evaluation of lists.
  Lists that represent code are executed
  by evaluating the items that are in
  the list; if the head of the list is a
  function (or some other action), you
  could think of the other items in the
  list as being the parameters to that
  function. This simplicity of the Lisp
  syntax makes it trivial to create
  powerful macros that would be
  difficult or impossible to implement
  using C++.

Other software written using Common Lisp includes:

Simple Grid Protocol for distributed computing

OpenMusic for composing musical scores

DART logistics tool used by the US military

the list goes on. It's fair to say that although Lisp is not exactly a fully mainstream language, it certainly solves a lot of difficult problems in a neat and elegant way.


问:
When did current source control management emerge?
The use of source control management tools is nowadays a standard
practice in the software industry.  Furthermore, it seems that there
is quite a strong consensus (for deliverables) to have an instable
branch where new features arrive and one or several stable branches
where only bugfixes are added.  I am interested into the history of
the emergence and consolidation of these practices.  Can anybody
provide information about the following milestones?

When SCM was used for the first time in an organisation developing software?

When was released the first free-software SCM?

When was released the first SCM shipped by a software company?

When was given the first talk about SCM in a developer's meeting
of international importance?

Which alternative schemes to the one unstable and one or more
stable branches scheme are used today, by a significantly large
community (e.g. a large company).

(Note that if a project uses topic branches, development happens in
numerous branches, but none of them correspond to deliverables.)

答: SCCS is one of the oldest ones, dating back to 1972. It has been introduced to early versions of Unix and is now part of the Single Unix Specification. </p>


问:
MVC to create desktop and mobile webapps?
I'm planning the creation of a webapp with a dedicated mobile web interface and a dedicated desktop/tablet interface.

I am considering ASP.NET MVC, but it is clear to me that MVC is for separation of concerns as explained here, anyway in my case i'd like to minimize the code and to support elegantly phones and desktop (may be landscape tablet can be "desktop" too).

So is MVC a wise choice in this case or which is the 1st stop for this kind of xdevice web app?

答:
MVC is a design pattern with aim to reduce coupling and increase cohesion of the UI, there are many different flavors from it such as MVP and MVVM.

Currently the trend is not to build a dedicated interface for each device platform, but to use something called responsive design (ex: bootstrap); this was possible after the release of CSS3 media queries, allowing your interface to adapt to the device it is being used on, also you can use bootstrap which is a very good UI framework that provide you with out-of-the-box responsive behavior CSS.

So bottom line (options using MVC):

responsive design: you'll be returning the same view allows and the CSS3 HTML5 will be responsible to adapt to device type.

controller device detection and multi views serving: your controller will detect the browser type and device;accordingly you'll be served a view that address you need - example if you open from desktop index will serve you IndexDesktop, if mobile the same model will be created the same item but will return IndexMobile. (to detect the mobile device and stuff go and download c# code)

dedicated sites: which is not what i recommend because you'll be repeating your self in every move and would duplicate the amount of work.

Is MVC a wise choice in this case or which is the 1st stop for this kind of xdevice web app?

Personally I would recommend you go with a solid MV* framework; which one this is totally your call, you can go to MVC and it'll help you select one, I personally recommend using angularJS backbonejs or emberjs, they are all really nice and solid to work with, ASP.net MVC is a real nice framework but the problem is when it come to client side work, the framework will start to become problematic.

EDIT: Why ASP.Net MVC is a bit problematic when it come to client side?!

I personally use MVC4 for web development, and the number of things that you can do using it, is amazing; stuff like web API, testing, dependency injection, the out-of-the-box stuff like asp.net identity, but when it come to internal page routing, caching, handling internal page ajax, you'll need to use something other than razor.

sometimes you need to relay on the client browser for the app to work as desired, stuff like single page apps, and fat client apps (example gmail). you need to relay then on technologies that leverage client side behaviors like HTML5\CSS3\JavaScript.

most of the time i use MVC .net with some client side framework for optimum behavior, the result become something like a hybrid solution which the best from both sides.

Check this website out Hot towel - angular


问:
Why are
,  and  tags not used much when I see sites that are in HTML 5?
I've noticed that even when a websites front end is coded in HTML 5 as evidenced by the <!DOCTYPE html>, people rarely seem to use the new HTML 5
,  and  tags.

Is it because people don't understand that you're supposed to use reusable classes for styling things within a
 instead of the full path of tag selectors to the element?

答:
Because those elements do not add enough value to overcome the increase in cognitive load that developers must incur to implement them. Why should I alter my process (however slightly), when that change brings zero benefit? </p>

<p>If Google prefers you have your logo within a header tag instead of a div with class "header", the ranking increase has got to be so miniscule as to be mostly irrelevant. Having good content and in-bound links to your site is wwwaaayyyyyyy more important for Google ranking than the specific tags you use. </p>

Title: Why are <section>, <header> and <footer> tags not used much when I see sites that are in HTML 5?

Body:
Because those elements do not add enough value to overcome the increase in cognitive load that developers must incur to implement them. Why should I alter my process (however slightly), when that change brings zero benefit?

If Google prefers you have your logo within a header tag instead of a div with class "header", the ranking increase has got to be so miniscule as to be mostly irrelevant. Having good content and in-bound links to your site is wwwaaayyyyyyy more important for Google ranking than the specific tags you use.


答:
Repeating statements is only a problem in so much as you're replicating an aspect of your code -- in this case, "do Statement1A, then do Statement1B".

A cleaner re-factoring is to move each of those blocks into separate methods,  even if the other method is only two lines.

```<code>void _statement1() {
  Statement1A;
  Statement1B;
}
</code>```

Having a such a method allows you to simply reference it in places where you would have repeated yourself.

```<code>if(condition1)
{
  _statement1()
}
else if(condition2)
{
  Statement2;
}
else if(condition3)
{
  Statement3;
}
else
{
  _statement1()
}
</code>```

Of course, this raises the follow-up question of "when should I use a method instead of just repeating myself?", which has considerations all of its own.  (I prefer "whenever possible", but also flagrantly violate that rule depending on the language.)

Title: How to do a clean refactoring of an If Else Code without leaving any free blocks?

Body:
```<code>if(condition1)
{
   Statement1A;
   Statement1B;
}
else if(condition2)
{
  Statement2;
}
else if(condition3)
{
  Statement3;
}
else
{
   Statement1A;
   Statement1B;
}

   return;
</code>```

I would like to refactor that code so that I do not duplicate Statements. I always need to check condition1 before any other condition. (So I cannot just change the order of the conditions). I also do not want to write &&!condition1 after every other condition.

I solved it like this

```<code>if(condition1)
{
}
else if(condition2)
{
  Statement2;
  return;
}
else if(condition3)
{
  Statement3;
  return;
}

Statement1A;
Statement1B;
return;
</code>```

However I do not think an empty if condition will be easily understandable by others (even by me after a while).

What is a better approach?

Body:
Repeating statements is only a problem in so much as you're replicating an aspect of your code -- in this case, "do Statement1A, then do Statement1B".

A cleaner re-factoring is to move each of those blocks into separate methods,  even if the other method is only two lines.

void _statement1() {
  Statement1A;
  Statement1B;
}

Having a such a method allows you to simply reference it in places where you would have repeated yourself.

if(condition1)
{
  _statement1()
}
else if(condition2)
{
  Statement2;
}
else if(condition3)
{
  Statement3;
}
else
{
  _statement1()
}

Of course, this raises the follow-up question of "when should I use a method instead of just repeating myself?", which has considerations all of its own.  (I prefer "whenever possible", but also flagrantly violate that rule depending on the language.)


答:
The first free source management system was RCS developed by Walter F Tichy in 1982.

If you follow the references in his original 1982 paper, cited in the Wikipedia article, you will get answers to some of your other questions.

Title: When did current source control management emerge?

Body:
The use of source control management tools is nowadays a standard
practice in the software industry.  Furthermore, it seems that there
is quite a strong consensus (for deliverables) to have an instable
branch where new features arrive and one or several stable branches
where only bugfixes are added.  I am interested into the history of
the emergence and consolidation of these practices.  Can anybody
provide information about the following milestones?

When SCM was used for the first time in an organisation developing software?

When was released the first free-software SCM?

When was released the first SCM shipped by a software company?

When was given the first talk about SCM in a developer's meeting
of international importance?

Which alternative schemes to the one unstable and one or more
stable branches scheme are used today, by a significantly large
community (e.g. a large company).

(Note that if a project uses topic branches, development happens in
numerous branches, but none of them correspond to deliverables.)


问:
What to do with bugs that do not repro?
I have a tester that while testing will have an error occur (ok so far), but then he frequently reports it right away.  We (the developers) then later find that the tester has not tried to reproduce the issue and (when asked) cannot find a way to make it happen again.

Now these are still bugs, I don't want to ignore them.  But without repro steps I am kind of stuck.  Sometimes there is a stack trace (though frequently it is not useful because this is compact framework and there are no line numbers).  But when there is one I can take the stack trace and crack open the code and start guessing, but that does not lead to testable "fixes".

What do you do in scenarios like this?

答: stick a keylogger on this tester's workstation!</p>

Title: What to do with bugs that do not repro?


问:
Image strategy on Android
I am creating an application with lots of photos. They will take > 100 mb on memory. So far I have 3 ideas:

Place it in @drawable  - app will be heavy

Download by JSON and place in java array - caching - How long it can be there?

Download by JSON, place it on phone memory/SD card and read in the application from memory. User can Remove pictures.

The best option will be to give possibility to user if he want to have a pictures or not.

What strategy is most efficient and recommended?

答:
Option 1 or 3 seems to be the best solutions for this situation.

Option 2 Download by JSON and place in java array is not recommended since it's not reliable.
The OS might kill your application process when it's in the background therefore destroying the memory cached images.

This would require users to redownload the 100mb of images all over again next time they open your app (not a good idea on mobile).

Option 1 Place it in @drawable might lead to a larger intial app download, but at least guarantees the images are present and will never require a re-download. Also, since you're not downloading anything in the background, your users will know how much space the application will take on their device from the get-go.

Option 3 Download by JSON, place it on phone memory/SD card and read in application from memory.  allows for a smaller app download. And caching images on the SD-card instead of memory would bypass the issues option 2 has. Libraries like android-query have this kind of functionality available with only 1 or 2 lines of code. (See Image Loading docs)

If your app can't function properly without the images (crashes, bugs, glitches etc.), the images won't be updated in the future and you don't mind large app packages, go with option 1.
Else, go with option 3.

Title: Image strategy on Android


答:
```<code>notCondition2And3 = !condition2 & !condition3;
// in place of notCondition2And3 should be some meaningful name
// representing what it actually MEANS that neither condition2 nor condition3 were true
</code>```

And now:

```<code>if (condition1 || notCondition2And3)
{
   Statement1A;
   Statement1B;
   return;
}
if (condition2)
{
   Statement2;
   return;
}
if (condition3)
{
   Statement3;
   return;
}
</code>```

As I wrote in my comment to Kieveli's answer, I see nothing wrong about multiple returns in a method, if there is no memory management considerations (as it might be the case in C or C++ where you have to release all resources manually before you leave).

Or another approach still. Here's the decision matrix so that we don't mess it up:

```<code>F F F - 1
---------
F F T - 3
---------
F T F - 2
F T T - 2
---------
T F F - 1
T F T - 1
T T F - 1
T T T - 1
</code>```

Ts and Fs represent the values of condition1, condition2 and condition3 (respectively). The numbers represent the outcomes.

It makes it clear that it's also possible to write the code as:

```<code>if (!condition1 && condition2) // outcome 2 only possible for FTF or FTT, condition3 irrelevant
{
   Statement2;
   return;
}
if (!condition1 && !condition2 && condition3)  // outcome 3 only when FFT
{
   Statement3;
   return;
}
// and for the remaining 5 combinations...
Statement1A;
Statement1B;
</code>```

Now if we extracted !condition1 (which is present in both ifs), we would get:

```<code>if (!condition1)
{
    if (condition2) // outcome 2 only possible for FTF or FTT, condition3 irrelevant
    {
       Statement2;
       return;
    }
    if (condition3)  // outcome 3 only when FFT
    {
       Statement3;
       return;
    }
}
// and for the remaining 5 combinations...
Statement1A;
Statement1B;
</code>```

Which is almost exactly what Kieveli suggested, only his disdain for early returns caused his implementation to be buggy (as he noted himself), because it wouldn't do a thing if all 3 conditions were false.

Or, we could revert it like so (this probably wouldn't work in every language - it works in C#, for one, since C# allows for equality comparison between multiple variables), now we're virtually back to the first one:

```<code>// note that "condition1" on the right side of || is actually redundant and can be removed,
// because if the expression on the right side of || gets evaluated at all,
// it means that condition1 must have been false anyway:

if (condition1 || (condition1 == condition2 == condition3 == false)) // takes care of all 4 x T** plus FFF (the one special case).
{
    Statement1A;
    Statement1B;
    return;
}
// and now it's nice and clean
if (condition2)
{
    Statement2;
    return; // or "else" if you prefer
}
if (condition3)
{
    Statement3;
    return; // if necessary
}
</code>```

Body:
notCondition2And3 = !condition2 & !condition3;
// in place of notCondition2And3 should be some meaningful name
// representing what it actually MEANS that neither condition2 nor condition3 were true

And now:

if (condition1 || notCondition2And3)
{
   Statement1A;
   Statement1B;
   return;
}
if (condition2)
{
   Statement2;
   return;
}
if (condition3)
{
   Statement3;
   return;
}

As I wrote in my comment to Kieveli's answer, I see nothing wrong about multiple returns in a method, if there is no memory management considerations (as it might be the case in C or C++ where you have to release all resources manually before you leave).

Or another approach still. Here's the decision matrix so that we don't mess it up:

F F F - 1
---------
F F T - 3
---------
F T F - 2
F T T - 2
---------
T F F - 1
T F T - 1
T T F - 1
T T T - 1

Ts and Fs represent the values of condition1, condition2 and condition3 (respectively). The numbers represent the outcomes.

It makes it clear that it's also possible to write the code as:

if (!condition1 && condition2) // outcome 2 only possible for FTF or FTT, condition3 irrelevant
{
   Statement2;
   return;
}
if (!condition1 && !condition2 && condition3)  // outcome 3 only when FFT
{
   Statement3;
   return;
}
// and for the remaining 5 combinations...
Statement1A;
Statement1B;

Now if we extracted !condition1 (which is present in both ifs), we would get:

if (!condition1)
{
    if (condition2) // outcome 2 only possible for FTF or FTT, condition3 irrelevant
    {
       Statement2;
       return;
    }
    if (condition3)  // outcome 3 only when FFT
    {
       Statement3;
       return;
    }
}
// and for the remaining 5 combinations...
Statement1A;
Statement1B;

Which is almost exactly what Kieveli suggested, only his disdain for early returns caused his implementation to be buggy (as he noted himself), because it wouldn't do a thing if all 3 conditions were false.

Or, we could revert it like so (this probably wouldn't work in every language - it works in C#, for one, since C# allows for equality comparison between multiple variables), now we're virtually back to the first one:

// note that "condition1" on the right side of || is actually redundant and can be removed,
// because if the expression on the right side of || gets evaluated at all,
// it means that condition1 must have been false anyway:

if (condition1 || (condition1 == condition2 == condition3 == false)) // takes care of all 4 x T** plus FFF (the one special case).
{
    Statement1A;
    Statement1B;
    return;
}
// and now it's nice and clean
if (condition2)
{
    Statement2;
    return; // or "else" if you prefer
}
if (condition3)
{
    Statement3;
    return; // if necessary
}


问:
Backbone.js app pulling large data sets with fetch()
I'm currently making some improvements for a client on a backbone.js app. The app is a web store and inventory management system. One thing that bothers me about this app (and other backbone.js apps I've encountered) is that it loads the entire collection of inventory items into memory from the server on every initial page load. After about a year and a half in production, this data set (not including image assets) is around 2.7 MB. So for every visitor to the web site, the javascript front-end pulls 2.7 MB data over the wire on initial page load. Of course this results in serious lag (around 8-12 seconds to load over most consumer-class broadband connections in my area). To me this load time is unacceptable. Of course once the data is loaded, the rest of the website is super snappy and responsive. </p>

<p>Is loading an entire collection really the best-practice way of developing backbone.js apps? I'm trying to figure it out because the books and tutorials I've come across seem to teach this. Is there another pattern to follow? Trying to keep it backbone.js specific --- but how does one manage large datasets in this framework? </p>

答:
There isn't any real reason you need to load more stuff than you're going to display on the page. What's the extra data for? And 8-12 seconds is going to lose you customers. Our website monitoring throws errors if numbers climb into the hundreds of milliseconds.

There has to be a way to restrict the dataset you're loading...Are there no subsections to the inventory? And I'd try to frontload the most commonly requested items. That'll save your customers time and you bandwidth.


问:
COBOL & Mainframe & Business
I have made a search on a Hong Kong job seeking website. There numerous of jobs titled "Computer Analyst". These are the requirements of the job:

```<code>Over 3 year experience relevant working experience in IBM Mainframe environment.
University degree in Computer Subject.
Proficient in system analysis, design and coding for the banking systems.
Application knowledge of Core banking and Card applications is definitely an advantage.
Sound in using IBM CICS/COBOL, and VSAM for both online and batch application systems.
Good communication skills with internal users.
</code>```

Quite a number of jobs are similar: They requires candidates to have the following qualities:

Computer Subjects especially Computer Science

3 years above experience

IBM Mainframe COBOL

Proficiency

Then it comes to my question:

It makes it hard for new programmers to enter the industry. How should someone enter the industry, i.e. making him/herself suitable for this kind of position?

Do they still want new programmers in this field?

How should one learn to operate IBM Mainframe(Or any kind of Mainframe)?

Is knowledge in finance required or crucial?

答:
Every now and then I see one of these, and I think of how long I spent trying to purge COBOL from my resume. It boggles the mind. I'll try and answer the questions in order.

1) It's very hard to get one of these jobs, because the paradigm is so outdated. There are no new systems (effectively), so you're competing against people who've been doing it forever. Fortunately a lot of them are dying, so occasional positions do open up.

If you get one of those positions, prepare to be hated. HATED. Because this stuff is so old, you're going to be dealing with incredibly hard to maintain code. Tons of customization. Very old development models. The learning curve is steep, and you will not be as responsive as the person who just retired/died. You will spend years trying to overcome this.

2) A lot of this stuff is financial code, and financial code has to change to reflect changes in the law. Changes in tax law will keep you in new code forever.

3) Step 1, get a mainframe. No, seriously, there is practically no way to learn. Fortunately, most companies don't really expect you to have experience. They just want it if they can get it (which they probably can't). If you're dealing with a "standard" OS, you may be able to get some classes (HP-UX, AIX, etc). Most of the mainframes still in production will probably be using much older versions of those, however, and you won't be able to get classes. God forbid you find a job where the mainframe is running something really bizarre (MPE/iX leaps to mind). There are barely even books for that.

4) Absolutely not. Your job is to talk to the accountants and make their math into code. You shouldn't ever be doing your own math. The auditing requirements on the code are unbelievable...Prepare to have to justify every change you make to every program you touch. Spend an hour trying to understand a piece of code, and then feel the desire to add a helpful comment? KILL IT. Every change has to be extensively documented.

I don't know. I sort of fell into this (Y2K got me COBOL experience), and I've been fighting it ever since. It's no fun. You're always working on systems that everyone hates, systems that have been slated for replacement for decades. Nothing is ever new or fast or easy.

Title: COBOL & Mainframe & Business


答:
I don't think there are any solution specific to Backbone, since it is quite a flexible framework that does not impose any special behaviour.

What I would do in your case, pretty much like @Satanicpuppy pointed out, is load the data in small chunks so you have immediately something to show from the beginning and keep loading the data in the background (you could implement some kind of infinite scrolling too). You can achieve this transparently by implementing your own sync or fetch method in your Collection. Look at the Annotated code to know where to look.

Another option you have is still to load the full collection but only limited properties (id & name?) and then fetch the full details of the single model when they are required to be shown (maybe on click?).

Also look at this SO question which highlights a similar problem: https://stackoverflow.com/questions/8953624/backbone-js-fetch-large-collection-causes-script-to-freeze

Title: Backbone.js app pulling large data sets with fetch()

Body:
I'm currently making some improvements for a client on a backbone.js app. The app is a web store and inventory management system. One thing that bothers me about this app (and other backbone.js apps I've encountered) is that it loads the entire collection of inventory items into memory from the server on every initial page load. After about a year and a half in production, this data set (not including image assets) is around 2.7 MB. So for every visitor to the web site, the javascript front-end pulls 2.7 MB data over the wire on initial page load. Of course this results in serious lag (around 8-12 seconds to load over most consumer-class broadband connections in my area). To me this load time is unacceptable. Of course once the data is loaded, the rest of the website is super snappy and responsive. </p>

<p>Is loading an entire collection really the best-practice way of developing backbone.js apps? I'm trying to figure it out because the books and tutorials I've come across seem to teach this. Is there another pattern to follow? Trying to keep it backbone.js specific --- but how does one manage large datasets in this framework? </p>


问:
So Singletons are bad, then what?
There has been a lot of discussion lately about the problems with using (and overusing) Singletons. I've been one of those people earlier in my career too. I can see what the problem is now, and yet, there are still many cases where I can't see a nice alternative - and not many of the anti-Singleton discussions really provide one.

Here is a real example from a major recent project I was involved in:

The application was a thick client with many separate screens and components which uses huge amounts of data from a server state which isn't updated too often. This data was basically cached in a Singleton "manager" object - the dreaded "global state". The idea was to have this one place in the app which keeps the data stored and synced, and then any new screens that are opened can just query most of what they need from there, without making repetitive requests for various supporting data from the server. Constantly requesting to the server would take too much bandwidth - and I'm talking thousands of dollars extra Internet bills per week, so that was unacceptable.

Is there any other approach that could be appropriate here than basically having this kind of global data manager cache object? This object doesn't officially have to be a "Singleton" of course, but it does conceptually make sense to be one. What is a nice clean alternative here?

答:
A bit late to the party, but anyways.

Singleton is a tool in a toolbox, just as anything else. Hopefully you have more in your toolbox than a just a single hammer.

Consider this:

```<code>public void DoSomething()
{
    MySingleton.Instance.Work();
}
</code>```

vs

```<code>public void DoSomething(MySingleton singleton)
{
    singleton.Work();
}
DoSomething(MySingleton.instance);
</code>```

1st case leads to high coupling etc; 2nd way has no problems @Aaronaught is describing, as far as I can tell. Its all about how you use it.

Title: So Singletons are bad, then what?

Body:
A bit late to the party, but anyways.

Singleton is a tool in a toolbox, just as anything else. Hopefully you have more in your toolbox than a just a single hammer.

Consider this:

public void DoSomething()
{
    MySingleton.Instance.Work();
}

vs

public void DoSomething(MySingleton singleton)
{
    singleton.Work();
}
DoSomething(MySingleton.instance);

1st case leads to high coupling etc; 2nd way has no problems @Aaronaught is describing, as far as I can tell. Its all about how you use it.


答: Igor Engraver, a music notation program, is written in Lisp.</p>

Title: Is functional programming actually used to create applications?

Body:
Possible Duplicate:

  What are some well known applications written in F#?

I see a lot of people talking about how cool functional programming is, how awesome Lisp and Haskell and F# are, etc, but what I don't see is them actually being used.  Just about every program on my computer is written in either something in the C family, Delphi, or Python.  I see tutorials talking about how easy it is to use functional languages to do complicated math problems, but no one talking about using them to do things most people actually care about using computers for, like business applications and games.

Does anyone have any examples of actual programs that people have heard of and are using, written in a functional language?  The only one I can think of off the top of my head is Abuse, from almost 15 years ago.  (Things like Emacs, where the core program is written in C with a functional language scripting layer on top, don't count.)


问:
Service layer vs DAO -- Why both?
I have been working with SpringMVC, Hibernate, and some databases in a java web application example.

There are a few different ones that do this, but this Spring 3 and hibernate integration tutorial with example has a model class, view (in jsp), and a service and dao classes for the controller.

My question is, don't both the service and DAO classes do the same thing? Why would you need them both?

This was the tutorial I was actually using: http://fruzenshtein.com/spring-mvc-security-mysql-hibernate/

答:
I have found that the service layer adds unnecessary complexity in most cases. In theory is to avoid to have businesses logic in the dao layer but at the end this just lead to confusion, even some people have disused to remove completely the dao layer as they feel it does not add value. http://ayende.com/blog/4784/architecting-in-the-pit-of-doom-the-evils-of-the-repository-abstraction-layer

But if you have multiple business logics then yes It is a good idea.  How essential is it to make a service layer?

ContentLicense: CC BY-SA 4.0

Title: Service layer vs DAO -- Why both?


问:
Using public API of a BSD-Licensed library in an MIT-Licensed project
I'm writing code that I would like to release under the MIT License. It uses the public API of a library licensed under the BSD 3-clause license. I am not redistributing the library with the source code, and I am not providing binaries, users must install the library themselves and compile from source. Do I need to include the license of the library in my project, effectively overriding the MIT License, even though I am not redistributing source code?</p>

答:
The BSD License stipulates (in all versions):

Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.

As such, since you are not providing either the source code directly nor are you compiling it in binary form, you should not need to provide the BSD clause.

The one clause...

All advertising materials mentioning features or use of this software
  must display the following acknowledgement:
  This product includes software developed by the organization.

...is a bit of a gray area, but because it discusses specifically advertising material, provided you do not place advertisements publicly without the BSD license, again you should be good to go.


答:
Generally the DAO is as light as possible and exists solely to provide a connection to the DB, sometimes abstracted so different DB backends can be used.

The service layer is there to provide logic to operate on the data sent to and from the DAO and the client. Very often these 2 pieces will be bundled together into the same module, and occasionally into the same code, but you'll still see them as distinct logical entities.

Another reason is security - If you provide a service layer that has no relation to the DB, then is it more difficult to gain access to the DB from the client except through the service. If the DB cannot be accessed directly from the client (and there is no trivial DAO module acting as the service) then all an attacker who has taken over the client can do is attempt to hack the service layer as well before he gets all but the most sanitised access to your data.

Title: Service layer vs DAO -- Why both?

Body:
I have been working with SpringMVC, Hibernate, and some databases in a java web application example.

There are a few different ones that do this, but this Spring 3 and hibernate integration tutorial with example has a model class, view (in jsp), and a service and dao classes for the controller.

My question is, don't both the service and DAO classes do the same thing? Why would you need them both?

This was the tutorial I was actually using: http://fruzenshtein.com/spring-mvc-security-mysql-hibernate/


问:
Which useful alternative control structures do you know?
Similar question was closed on SO.

Sometimes when we're programming, we find that some particular control structure would be very useful to us, but is not directly available in our programming language.

What alternative control structures do you think are a useful way of organizing computation?

The goal here is to get new ways of thinking about structuring code, in order to improve chunking and reasoning.

You can create a wishful syntax/semantic not available now or cite a less known control structure on an existent programming language.

Answers should give ideas for a new programming language or enhancing an actual language.

Think of this as brainstorming, so post something you think is a crazy idea but it can be viable in some scenario.

It's about imperative programming.

答:
I sometimes find myself writing a loop that needs to do something different during the first iteration. For example, displaying  tags instead of  tags.

I handle this situation with a boolean flag. Something like this:

```<code>first = true

while (some_condition)
    if (first)
        do_something
        first = false
    else
        do_something_else
</code>```

It seems silly to check the value of first on every iteration when it's going to be false most of the time.

I'd like to have a looping option to specify a different loop body on the first iteration. There would be no need for a separate variable. The compiled code wouldn't need one, either, because the generated code would have two bodies, one for the first iteration and one for the rest.

Body:
I sometimes find myself writing a loop that needs to do something different during the first iteration. For example, displaying <th> tags instead of <td> tags.

I handle this situation with a boolean flag. Something like this:

first = true

while (some_condition)
    if (first)
        do_something
        first = false
    else
        do_something_else

It seems silly to check the value of first on every iteration when it's going to be false most of the time.

I'd like to have a looping option to specify a different loop body on the first iteration. There would be no need for a separate variable. The compiled code wouldn't need one, either, because the generated code would have two bodies, one for the first iteration and one for the rest.


答:
Is loading an entire collection really the best-practice way of
  developing backbone.js apps?

Not necessarily, having worked in a backbone app with similarly large collections we wrote a base collection class that helped us paginate smaller sets of the data.

I'm trying to figure it out because the books and tutorials I've come
  across seem to teach this.

I'd say most tutorials I've read on backbone don't explore what to do with apps that have large sets of data, or a large number of UI elements, so our team always explored options for improvement.

Is there another pattern to follow? Trying to keep it backbone.js
  specific --- but how does one manage large datasets in this framework?

This is a pretty broad question, but like I mentioned before, create a base class that allows you to paginate a collection easily (use internal models to manage state where needed), and write the api support to allow it. In addition to pagination, add search query support, so users can search through data, having your collection fetch keywords on the fly. Always share collections across views and make the most of smaller sets of data.


问:
Unit testing to prove balanced tree
I've just built a self-balancing tree (red-black) in Java (language should be irrelevant for this question though), and I'm trying to come up with a good means of testing that it's properly balanced.

I've tested all the basic tree operations, but I can't think of a way to test that it is indeed well and truly balanced.  I've tried inserting a large dictionary of words, both pre-sorted and un-sorted.  With a balanced tree, those should take roughly the same amount of time, but an unbalanced tree would take significantly longer on the already-sorted list.  But I don't know how to go about testing for that in any reasonable, reproducible way.  (I've tried doing millisecond tests on these, but there's no noticeable difference - probably because my source data is too small.)

Is there a better way to be sure that the tree is really balanced?  Say, by looking at the tree after it's created and seeing how deep it goes?  (That is, without modifying the tree itself by adding a depth field to each node, which is just wasteful if you don't need it for anything other than testing.)

答: If you want to measure time complexity for reads one idea is that you could have the tree issuing callbacks for traversals. This way you could measure the number of operations for a read, which would be a more reliable measurement of time complexity.</p>

Title: Unit testing to prove balanced tree


答:
I like this way:

```<code>        if (!condition1)
        {
            if (condition2)
            {
                Statement2();
                return;
            }
            else if (condition3)
            {
                Statement3();
                return;
            }
        }

        Statement1A();
        Statement1B();
        return;
</code>```

EDIT:

I like even more this way because I have only 1 return and 2 IF statements :

```<code>        if (!condition1 && condition2)
            Statement2();
        else if (!condition1 && condition3)
            Statement3();
        else
        {
            Statement1A();
            Statement1B();
        }
        return;
</code>```

Body:
I like this way:

        if (!condition1)
        {
            if (condition2)
            {
                Statement2();
                return;
            }
            else if (condition3)
            {
                Statement3();
                return;
            }
        }

        Statement1A();
        Statement1B();
        return;

EDIT:

I like even more this way because I have only 1 return and 2 IF statements :

        if (!condition1 && condition2)
            Statement2();
        else if (!condition1 && condition3)
            Statement3();
        else
        {
            Statement1A();
            Statement1B();
        }
        return;


问:
Making a decentralized system utilizing JavaScript/HTML5?
I am interested in decentralized systems, and am currently considering building one myself. I am considering using JavaScript and HTML5, simply because it makes it very easy to use the system (they just have to go to a website).

Some thoughts:

I may or may not use another decentralized network for storage, and even if I do, I probably want to cache stuff on the client. If I do not, I need to store stuff on the client, since the information will then be distributed on my network. Is any of the HTML5 storage models good for this? I've read somewhere that they have a size limit.

When using JavaScript in the browser, my understanding is that I have to use WebSockets instead of regular sockets. Doesn't this force me to use WebSocket in my "protocol spec"?

答:
If I do not, I need to store stuff on the client, since the
  information will then be distributed on my network. Is any of the
  HTML5 storage models good for this? I've read somewhere that they have
  a size limit.

The only way I know how to distribute data in your scenario is with a web server  component. If you want to store your data client side only ( via HTML5 local storage, webSQL, or indexedDB)  you could implement a http://en.wikipedia.org/wiki/Gossip_protocol on the web server, to reflect all data communicated from clients to each other.

When using JavaScript in the browser, my understanding is that I have
  to use WebSockets instead of regular sockets. Doesn't this force me to
  use WebSocket in my "protocol spec"?

You don't have to use Websockets. You could accomplish this with ajax and polling. Websockets however does enable you to easily push data from the server
to the client, so it would make the implementation of your gossip protocol easier. One client posts a message that they have saved locally, and your Websockets enabled web server relays the message to all other clients, who then store the data locally.

Recommendations:
- if you want to use JavaScript across the board, try Node.js and the SocketIO library
- if you want to not have to write the server component, you could try something like https://www.firebase.com/

As for local storage, from html5 rocks: "“5 megabytes” is how much storage space each origin gets by default. This is surprisingly consistent across browsers, although it is phrased as no more than a suggestion in the HTML5 Storage specification."


问:
Binary data storage scheme (saving user-uploaded files)
In our app we are currently saving binary data to the database (terrible, I know; but this is legacy stuff and it wasn't my decision). We're trying to migrate this data out to an external device and I'm trying to come up with a scheme to save these files.

We have multiple tenants, I'd like to have a directory per tenant. My scheme for that is to build path using the first-three letters of the tenant. So if you had a tenant called apple, its files would be at /a/p/p/apple. Within these directories, I will save the files. For the files, I want to generate a random 6-character alphanumeric name (only lowercase characters for the time being because internal reasons). So if we generate a file name called 6a8jxo, it will stored as <tenant>/6/a/6/6a8jxo. With this strategy, each tenant can have a maximum of approximately 916 billion unique files (not that we're attempting to save that many), with a maximum of 46,656 files per directory. If I go for a 5-character name, we will have a maximum of 60.5 billion unique files with 1,296 files per directory.

Are there any drawbacks to this approach? I realize that certain directories may only contain one or two files, but in my mind that is not a huge problem.

My colleague doesn't want to do it this way; he wants to use an autoincremented field in the database and then base the directory structure on the hex-value (I assume 32-bit) of that instead of using the tenant. With his strategy the hex value would be used as follows: the file will be stored in the directory located at <tenant>/aa/bbb where aa is the first two characters (most significant nibbles) of the hex value, and bbb is the next three. His reasoning is that he only wants to create new directories when one fills up instead of having numerous, partially-filled directories.

This approach introduces numerous difficulties on the code side of things and I don't see having completely-filled directories as an argument that justifies the extra effort required to do this.

Are there any other strategies or approaches I haven't considered?

答:
The idea of hashing the directories (not to be confused with generating a hash of the file name) and thus breaking it down into multiple directories is a good one.  If its multi-tenant, you probably have a database id for the clients.  And its a good idea to track the existence of the files in your db with a unique id (auto-increment or other).  So you might simplify your approach and do something like:

```<code>/(client id)/(thousands)/(file-id).txt
</code>```

create a single directory for the tenant, then generate the file path based on the file's unique database id, grouping them in to thousands or tens of thousands.  So the file that has an autoincrementing row id of 53445 for tenant number 8 might look like

```<code>/8/53/53445.txt
</code>```

If you need to support a more distributed setup, you can use a uuid rather than an autoincrement field when tracking files.  I would not use the name of the client as part of the path, because names change, and you may end up encountering a client with a character in their name that cant be used as part of a file name - just skip all that complexity and use the database id.

Breaking the files down by tenant may not be necessary technically (I usually wouldn't), but may help you if you need to provide those files to the client.  Whether its wise to do so really depends on the nature of your application.

Body:
The idea of hashing the directories (not to be confused with generating a hash of the file name) and thus breaking it down into multiple directories is a good one.  If its multi-tenant, you probably have a database id for the clients.  And its a good idea to track the existence of the files in your db with a unique id (auto-increment or other).  So you might simplify your approach and do something like:

/(client id)/(thousands)/(file-id).txt

create a single directory for the tenant, then generate the file path based on the file's unique database id, grouping them in to thousands or tens of thousands.  So the file that has an autoincrementing row id of 53445 for tenant number 8 might look like

/8/53/53445.txt

If you need to support a more distributed setup, you can use a uuid rather than an autoincrement field when tracking files.  I would not use the name of the client as part of the path, because names change, and you may end up encountering a client with a character in their name that cant be used as part of a file name - just skip all that complexity and use the database id.

Breaking the files down by tenant may not be necessary technically (I usually wouldn't), but may help you if you need to provide those files to the client.  Whether its wise to do so really depends on the nature of your application.


问:
When should var be used instead of declaring an explicit type?
```<code>        var Id = from value in Enumerable.Range(0, 100)
                              select value;

        IEnumerable<int> ids = from value in Enumerable.Range(0, 100)
                              select value;

        foreach (var v in Id)
        {
            Console.WriteLine(v.ToString());
        }

        foreach (var x in ids)
        {
            Console.WriteLine(x.ToString());
        }
</code>```

Both will do the same job, but what is the difference?

答:
There is no difference between the two, except for readability. The second example (ids) is more explicit than the first and perhaps more readable.  But, readability is a matter of taste/opinion with many different viewpoints.  Here are some guidelines...</p>

```<code> public void SampleCode()
        {
            //Use of var is encouraged when  declaration needlessly clutters code
            Widget widget1a = new Widget();  //No
            var widget1b = new Widget();  //Yes, I know I am getting a widget.

            //Use of var is encouraged when method name defines return type
            //or return is type is known without further need of code inspection
            Widget widget2a = GetWidget(); //OK (Verbose)
            var widget2b = GetWidget(); //Yes, But...
            //Danger, Will Robinson!  if GetWidget returns a foo...Code review time!

            //Use of var is discouraged when method offers new clue to type
            //without further code inspection
            Widget widget3a = Process(); //Yes, intent is clear without any further inspection.
            var widget3b = Process(); //No, What does Process do?
        }
</code>```

Body:
There is no difference between the two, except for readability. The second example (ids) is more explicit than the first and perhaps more readable.  But, readability is a matter of taste/opinion with many different viewpoints.  Here are some guidelines...

 public void SampleCode()
        {
            //Use of var is encouraged when  declaration needlessly clutters code
            Widget widget1a = new Widget();  //No
            var widget1b = new Widget();  //Yes, I know I am getting a widget.

            //Use of var is encouraged when method name defines return type
            //or return is type is known without further need of code inspection
            Widget widget2a = GetWidget(); //OK (Verbose)
            var widget2b = GetWidget(); //Yes, But...
            //Danger, Will Robinson!  if GetWidget returns a foo...Code review time!

            //Use of var is discouraged when method offers new clue to type
            //without further code inspection
            Widget widget3a = Process(); //Yes, intent is clear without any further inspection.
            var widget3b = Process(); //No, What does Process do?
        }


问:
When was source control invented?
I'm aware of many version control systems:  CVS, SVN, TFS etc...

I've googled for the very first "revision control/version control system" and seen various conflicting answers.

When was source control invented?  Who invented it?  What was it called?

答:
In 1981, I worked a summer job at Charter Information in Austin TX.  They were formerly Commercial Information Corporation of Woburn MA.  They ran a Xerox Sigma 6 that had been field-upgraded to a Sigma 7.  They used a thing called SPUD (Source Program Update) for source code control.  It was tape-based.

I routinely mounted the "bicentennial SPUD tape" and worked on a mod deck for a piece of code on that tape.  It was called the "bicentennial SPUD tape" because it was written in 1976.  They had older tapes, indicating that SPUD went back farther than 1976.

While a student at UT Austin (1973-1981), I ran up against MODIFY and UPDATE, two source code control programs from Control Data Corporation for the CDC 6600 and later mainframes.  I do not know when they first came out, but I suspect they came out not long after the 6600, which (if memory serves me) came out in the late 1960s.

I suspect that IBM had something well before anyone else did, but I have no knowledge whatsoever of IBM mainframe history, and I like it that way.

Title: When was source control invented?


问:
How do I make multiple calls to a web service without taxing that service heavily? Scaling question
is there a good pattern for how to send multiple calls to a web service but without taxing it and ensuring the data is sent back? I don't know enough to correctly describe the problem to even start googling it properly - current google results compare streaming vs. non-streaming wcf answers?

Scenario: I am working on an app (I'm a jr. dev.) that needs to gather information from several sources about a 'customer' and the domains they own

Technical:
for one of the sources, I need to send a string array of domains to a web service and this web service returns an entry for each domain name, but this list of domain names will be thousands long - I would like to attempt to divide this list into bite-size chunks (1k domain names each) and then... queue them up to send to that web service, but ensure the web service doesn't skip one

PseudoRequirements:
Consumer of web page does not care how long it takes, but would like a list of results up front that does not require pagination to navigate.

Current Theory:
Should I take my massive 30k list, break it into 1k chunks, stuff each 1k-sized chunk into a 'request' object, assemble those 'request chunks' into a 'request chunk list' and iterate over that list (sequentially / blocking, so I don't strangle the WS) and for each 'request chunk' get back a 'response chunk' assemble those into a list, and then pass that list back into the front end for viewing? is this a viable method? is there a better way to queue items? Does anyone know off-hand any useful articles for this sort of queuing? are there any 'gotchas' or additional items to consider before I attempt my first pass?

Additional Edits:
-I do not have full control to the receiving service, I can not view it's code and the developers that manage it are... less than responsive to email. I do not currently know the stress testing limits of the web service. I emailed the owners of that component but have yet to receive a response - I was going to work up my design while I waited on them.

答:
I think your strategy is OK. Other things to consider: Before sending any messages, know how many you plan to send. If you have n messages to send, you might not want to display the full results set until you get all of your responses.

There are other things you could do such as adding correlation IDs or sequence numbers to make tracking all the messages easier, but that would assume you have control over the receiving service, and you don't say if you do.

Other questions: have you actually tested this web service to see what it can reasonably handle in a single request? You might find that it can handle more than you think. Or less than you think. Do you know for certain that a single request with 1000 domain names is optimal?


问:
Can IndexedDB be used in offline hybrid android apps?
Can IndexedDB be used in offline hybrid android apps?

I have tried the [example presented in this post,1 while it is working in my laptopn on Google Chrome, it is not working inside the WebView in my android app.

The HTML part of the app is loading fine inside the webview but the javaScript part containing all Indexeddb stuff is not getting executed at all.

What's wrong?

答:
Depending on your version, it may not be supported in the web view.

Refer to this chart which shows which versions are supported for Android: http://caniuse.com/indexeddb


问:
Does Abstract Factory Pattern scale?
I'm still trying to understand design patterns here, after learning the Abstract factory pattern , I realised that this pattern will not scale well. Take a look at the uml diagram of the abstract factory pattern

If I have to create a new 'AbstractProductC', I will have to add an abstract method 'CreateProductC' in 'AbstractFactory' which effects the implementation of both ConcreateFactory1, ConcreateFactory2.

My question here is, does Abstract Factory pattern scale at all (or) I'm I thinking in the wrong direction here ?

thanks in advance

答:
Abstract Factory scales just fine.

There is a basic principle which states that a class should do one thing well.  Your problem here is you are trying to make many classes do many things.

You don't have to stick to one abstract factory.  You can (and should have) several:

AbstractProductAFactory defines the interface for producing ProductA.  Your concrete implementations (ConcreteProductAFactory1, ConcreteProductAFactory2) would extend it.

AbstractProductBFactory defines the interface for producing ProductB.  Your concrete implementations (ConcreteProductBFactory1, ConcreteProductBFactory2) would extend it.

If you then need a ProductC, create a new AbstractProductCFactory.  No need to change any of your other factories this way.

UPDATE
Ideally ProductA should represent a class of product--that is, all the products that share an interface that you're calling ProductA.  In the comments I suggest that this is something like a Pizza:

```<code>interface AbstractPizzaFactory {
    public Pizza buildPizza(List<Topping> toppings);
}

class ThinCrustPizzaFactory implements AbstractPizzaFactory {
    public Pizza buildPizza(List<Topping> toppings){

        ...

    }
}

class DeepDishPizzaFactory implements AbstractPizzaFactory {
    public Pizza buildPizza(List<Topping> toppings){

        ...

    }
}
</code>```

And so on.  Adding a PanPizzaFactory won't affect any of the other classes--it's just a new concrete implementation of the PizzaFactory.  If you have products that aren't pizzas--sandwiches, for example, that's where you create another abstract factory (e.g., AbstractSandwichFactory).

The real point is, you wouldn't want to have a abstract factory that builds two very different types of product with two different "build" methods.  Group them as logically as you can so that they share an interface, and then create an abstract factory that defines how concrete factories should build implementations of that interface.

Title: Does Abstract Factory Pattern scale?

Body:
Abstract Factory scales just fine.

There is a basic principle which states that a class should do one thing well.  Your problem here is you are trying to make many classes do many things.

You don't have to stick to one abstract factory.  You can (and should have) several:

AbstractProductAFactory defines the interface for producing ProductA.  Your concrete implementations (ConcreteProductAFactory1, ConcreteProductAFactory2) would extend it.

AbstractProductBFactory defines the interface for producing ProductB.  Your concrete implementations (ConcreteProductBFactory1, ConcreteProductBFactory2) would extend it.

If you then need a ProductC, create a new AbstractProductCFactory.  No need to change any of your other factories this way.

UPDATE
Ideally ProductA should represent a class of product--that is, all the products that share an interface that you're calling ProductA.  In the comments I suggest that this is something like a Pizza:

interface AbstractPizzaFactory {
    public Pizza buildPizza(List<Topping> toppings);
}

class ThinCrustPizzaFactory implements AbstractPizzaFactory {
    public Pizza buildPizza(List<Topping> toppings){

        ...

    }
}

class DeepDishPizzaFactory implements AbstractPizzaFactory {
    public Pizza buildPizza(List<Topping> toppings){

        ...

    }
}

And so on.  Adding a PanPizzaFactory won't affect any of the other classes--it's just a new concrete implementation of the PizzaFactory.  If you have products that aren't pizzas--sandwiches, for example, that's where you create another abstract factory (e.g., AbstractSandwichFactory).

The real point is, you wouldn't want to have a abstract factory that builds two very different types of product with two different "build" methods.  Group them as logically as you can so that they share an interface, and then create an abstract factory that defines how concrete factories should build implementations of that interface.


问:
How to do a clean refactoring of an If Else Code without leaving any free blocks?
```<code>if(condition1)
{
   Statement1A;
   Statement1B;
}
else if(condition2)
{
  Statement2;
}
else if(condition3)
{
  Statement3;
}
else
{
   Statement1A;
   Statement1B;
}

   return;
</code>```

I would like to refactor that code so that I do not duplicate Statements. I always need to check condition1 before any other condition. (So I cannot just change the order of the conditions). I also do not want to write &&!condition1 after every other condition.

I solved it like this

```<code>if(condition1)
{
}
else if(condition2)
{
  Statement2;
  return;
}
else if(condition3)
{
  Statement3;
  return;
}

Statement1A;
Statement1B;
return;
</code>```

However I do not think an empty if condition will be easily understandable by others (even by me after a while).

What is a better approach?

答:
Maybe it's just me, but I find a condition like if (!a && b) relatively difficult to read, and generally prefer if (b && !a), when possible (i.e., unless I'm depending on short-circuit evaluation so b will only be evaluated if a was false).

Based on that, I'd probably write it as:

```<code>if (condition2 && !condition1)
   statement2;
else if (condition3 && !condition1)
   statement3;
else {
    statement1A;
    statement1B;
}
</code>```

As I said though, while this is fine if you only care about which statements are evaluated, it doesn't work if you also care about which conditions are evaluated.

Body:
Maybe it's just me, but I find a condition like if (!a && b) relatively difficult to read, and generally prefer if (b && !a), when possible (i.e., unless I'm depending on short-circuit evaluation so b will only be evaluated if a was false).

Based on that, I'd probably write it as:

if (condition2 && !condition1)
   statement2;
else if (condition3 && !condition1)
   statement3;
else {
    statement1A;
    statement1B;
}

As I said though, while this is fine if you only care about which statements are evaluated, it doesn't work if you also care about which conditions are evaluated.


答:
Your scaling factor is a simple matter of dependency management.
The more dependencies a class has - the more stable and thoughtful its API should be.

There is no problem in creating a factory that is defined by the responsibility of creating types of similar or cohesive nature. But the more classes that depend on this factory - the more strict this cohesion should be.

(Note: this can be done in a gradual way, not necessarily by a BDUF)

Title: Does Abstract Factory Pattern scale?

Body:
I'm still trying to understand design patterns here, after learning the Abstract factory pattern , I realised that this pattern will not scale well. Take a look at the uml diagram of the abstract factory pattern

If I have to create a new 'AbstractProductC', I will have to add an abstract method 'CreateProductC' in 'AbstractFactory' which effects the implementation of both ConcreateFactory1, ConcreateFactory2.

My question here is, does Abstract Factory pattern scale at all (or) I'm I thinking in the wrong direction here ?

thanks in advance


答:
There's another way. I would prefer to keep the original control flow. Then, the work that is done twice, can be put it in a function, and then we invoke the function from two different places:

```<code>function X()
{
  if(condition1)
  {
     HandleDefault();
     return;
  }

  if(condition2)
  {
     Statement2;
     return;
  }

  if(condition3)
  {
    Statement3;
    return;
  }

  HandleDefault();
  return;

}
///

function HandleDefault(   )
{
    Statement1A;
    Statement1B;
}
</code>```

Often, if there are blocks of statements that go together, it is possible to give the function a meaningful name, increasing even more the readability of the code. But if you don't have a meaningful name, you can still make a private function with a less descriptive name (as I did in my example).

The reason why I think this is the best solution because it retains the order of conditionals, while it does achieve that you have only one copy of Statement1A and Statement1B to maintain, and it does so without introducing any nesting constructs or temporary variables. This reduces the amount of stuff you need to keep mentally track of when reading this code.

Now, there are languages (most notably C) where early returns can't always be used, but in any other mainstream language I can think of you can.

Body:
There's another way. I would prefer to keep the original control flow. Then, the work that is done twice, can be put it in a function, and then we invoke the function from two different places:

function X()
{
  if(condition1)
  {
     HandleDefault();
     return;
  }

  if(condition2)
  {
     Statement2;
     return;
  }

  if(condition3)
  {
    Statement3;
    return;
  }

  HandleDefault();
  return;

}
///

function HandleDefault(   )
{
    Statement1A;
    Statement1B;
}

Often, if there are blocks of statements that go together, it is possible to give the function a meaningful name, increasing even more the readability of the code. But if you don't have a meaningful name, you can still make a private function with a less descriptive name (as I did in my example).

The reason why I think this is the best solution because it retains the order of conditionals, while it does achieve that you have only one copy of Statement1A and Statement1B to maintain, and it does so without introducing any nesting constructs or temporary variables. This reduces the amount of stuff you need to keep mentally track of when reading this code.

Now, there are languages (most notably C) where early returns can't always be used, but in any other mainstream language I can think of you can.


问:
Contract Based Programming vs Unit Test
I am a somewhat defensive programmer and a big fan of Microsofts Code Contracts.

Now I cannot always use C# and in most languages the only tool I have is assertions. So I usually end up with code like this:

```<code>class
{
    function()
    {
         checkInvariants();
         assert(/* requirement */);

         try
         {
             /* implementation */
         }
         catch(...)
         {
              assert(/* exceptional ensures */);
         }
         finally
         {
              assert(/* ensures */);
              checkInvariants();
         }
    }

    void checkInvariants()
    {
         assert(/* invariant */);
    }
}
</code>```

However, this paradigm (or whatever you would call it) leads to a lot of code cluttering.

I have started to wonder if it is really worth the effort and whether proper unit test would already cover this?

答:
Anything you have in your checkVariants() calls could be done from testing, how much effort that might actually be depends many things (external dependencies, coupling levels etc.) but it would clean the code up from one point of view. How testable a code-base developed against assertions would be without some refactoring I'm not sure.

I agree with @duros, these shouldn't be thought of as exclusive or competing approaches. In fact in a TDD environment you could even argue that the 'requirement' assertions would be need to have tests:).

Asserts however DO NOT make code more robust unless you actually do something to fix the failed check, they just stop data getting corrupted or similar, usually by aborting processing at the first sign of trouble.

A test driven/well tested solution will have typically already thought about and/or discovered many of the sources/reasons of bad inputs and outputs whilst developing the interacting components and already dealt with them closer to the source of the problem.

If your source is external and you have no control over it then to avoid cluttering up your code dealing with other codes problems you might consider implementing some sort of data-cleansing/assertion component in between the source and your component and put your checks in there.

Also I'm curious to what languages your using that doesn't have some sort of xUnit or other testing library that someone has developed, I thought there was pretty much something for everything these days?

Title: Contract Based Programming vs Unit Test


答: Continuation Passing Style comes to mind. Then, of course, you'd like to have Tail Call Optimization as well. </p>

Title: Which useful alternative control structures do you know?

Body:
Similar question was closed on SO.

Sometimes when we're programming, we find that some particular control structure would be very useful to us, but is not directly available in our programming language.

What alternative control structures do you think are a useful way of organizing computation?

The goal here is to get new ways of thinking about structuring code, in order to improve chunking and reasoning.

You can create a wishful syntax/semantic not available now or cite a less known control structure on an existent programming language.

Answers should give ideas for a new programming language or enhancing an actual language.

Think of this as brainstorming, so post something you think is a crazy idea but it can be viable in some scenario.

It's about imperative programming.


答:
The problem with scaling is that code can scale in many different ways. The problem you are having is simply caused by need to scale in a direction, that design pattern is not intended for. In case of Abstract Factory pattern, it is meant to scale in a way of adding new concrete factories, but adding new product causes big structural changes.

One of the points of software design and architecture is to identify most likely directions the code will scale and pick patterns based on those likely directions. If you identify, that adding new product is more likely than adding new concrete factory, then using Abstract Factory is not a good idea and it might be better to completely re-think the design.

Title: Does Abstract Factory Pattern scale?


问:
Is Java free/open source or not?
On November 13, 2006, Sun released much of Java as free and open source software, (FOSS), under the terms of the GNU General Public License (GPL). On May 8, 2007, Sun finished the process, making all of Java’s core code available under free software/open-source distribution terms, aside from a small portion of code to which Sun did not hold the copyright.

OpenJDK (Open Java Development Kit) is a free and open source implementation of the Java programming language. It is the result of an effort Sun Microsystems began in 2006. The implementation is licensed under the GNU General Public License (GNU GPL) with a linking exception.

Why there are still people who say that Java is not open source or free as in free speech?

Am I missing something?

Is Java still proprietary?

答:
In 1997, Sun Microsystems approached the ECMA to formalize the Java but it soon withdrew from the process. Java standard is actually controlled through Java Community Process.

Although in 2006, most of the Java was released by Sun Microsystems under the terms of GPL but the current official implementation is owned by the Oracle.

As Java lacks any formal standardization recognized by ECMA, ISO/IEC, ANSI, or other third-party standards organization, the Oracle implementation is the defacto standard. However, there are alternative implementations like GNU Compiler for Java, GNU Classpath, IcedTea-Web, etc.

Title: Is Java free/open source or not?


答:
Two approaches which have not yet been mentioned are to rewrite the statements as expressions (if they are amenable to such) or (dare I say it) using a little word that starts with g.  There are cases where I would consider each of those the best alternative.

In the case of expressions, the code would be something like:

```<code>if (condition1 ||
     condition2 ? (action2(),1) :
     condition3 ? (action3(),1) :
     1)
  action1;
</code>```

Rather nasty, and not generally something I would use, but it may be reasonable in cases where condition2 and action2 are both encapsulated in a method that attempts an operation and indicates whether it succeeds and likewise condition2 and action3.  In that case, it could become:

```<code>if (cantTryAnything || (
     tryFirstThing() != FIRST_TRY_SUCCESS &&
     trySecondThing() != SECOND_TRY_SUCCESS
)
{
  default actions here
}
</code>```

Do the default actions if either I couldn't try anything, or everything that I tried, failed.

Note that simply copying out the actions or factoring them to a different method would generally be preferable to the above style of logic or a g___. but if code in "default actions here" would need to manipulate local variables, and its exact behavior might change, encapsulating the code into an outside method may be difficult and duplicating the code would pose a risk of the duplicate versions might be changed so as to no longer match perfectly.  Further, the notion that a certain control-flow statement is harmful centers around the fact that most real-world control-flow problems can be mapped nicely into common language constructs, and that when a real-world problem maps well to a language construct one should use it.  If the particular program flow required by an application requires identical behavior under multiple combinations of conditions, I would posit that it's better to explicitly force execution to a common point in all such conditions than fudge around the issue.

Body:
```<code>if(condition1)
{
   Statement1A;
   Statement1B;
}
else if(condition2)
{
  Statement2;
}
else if(condition3)
{
  Statement3;
}
else
{
   Statement1A;
   Statement1B;
}

   return;
</code>```

I would like to refactor that code so that I do not duplicate Statements. I always need to check condition1 before any other condition. (So I cannot just change the order of the conditions). I also do not want to write &&!condition1 after every other condition.

I solved it like this

```<code>if(condition1)
{
}
else if(condition2)
{
  Statement2;
  return;
}
else if(condition3)
{
  Statement3;
  return;
}

Statement1A;
Statement1B;
return;
</code>```

However I do not think an empty if condition will be easily understandable by others (even by me after a while).

What is a better approach?

Body:
Two approaches which have not yet been mentioned are to rewrite the statements as expressions (if they are amenable to such) or (dare I say it) using a little word that starts with g.  There are cases where I would consider each of those the best alternative.

In the case of expressions, the code would be something like:

if (condition1 ||
     condition2 ? (action2(),1) :
     condition3 ? (action3(),1) :
     1)
  action1;

Rather nasty, and not generally something I would use, but it may be reasonable in cases where condition2 and action2 are both encapsulated in a method that attempts an operation and indicates whether it succeeds and likewise condition2 and action3.  In that case, it could become:

if (cantTryAnything || (
     tryFirstThing() != FIRST_TRY_SUCCESS &&
     trySecondThing() != SECOND_TRY_SUCCESS
)
{
  default actions here
}

Do the default actions if either I couldn't try anything, or everything that I tried, failed.

Note that simply copying out the actions or factoring them to a different method would generally be preferable to the above style of logic or a g___. but if code in "default actions here" would need to manipulate local variables, and its exact behavior might change, encapsulating the code into an outside method may be difficult and duplicating the code would pose a risk of the duplicate versions might be changed so as to no longer match perfectly.  Further, the notion that a certain control-flow statement is harmful centers around the fact that most real-world control-flow problems can be mapped nicely into common language constructs, and that when a real-world problem maps well to a language construct one should use it.  If the particular program flow required by an application requires identical behavior under multiple combinations of conditions, I would posit that it's better to explicitly force execution to a common point in all such conditions than fudge around the issue.


问:
How can I automate production deployments without experiencing extreme anxiety?
At our shop we use SVN for source control and CruiseControl for CI on handling automatic builds and deployments to our development, test, and integration environments.

This all works smoothly however due to hardware and resource constraints our integration environment is not a 2 server load balanced environment like our production environment.  While everything else is equal that would be the only difference between our integration and production environments (although a big one!)

Theoretically the difference is a slightly different configuration of our app servers and the deploy script merely would have to drop the build artifacts into two servers instead of just the one, but why am I so nervous to automate our production deployments?!

I am generally not a control freak but I always feel the insatiable need to deploy production to production manually.  I have heard from colleagues that this is generally a Really BAD Thing™ but they failed to make a case against it.

I know that when I do it manually I can SEE that I am physically copying the correct files, I am physically shutting down the app servers and ensuring they closed successfully, I am physically starting the servers back up and then physically inspecting the logs to make sure it started up okay and the deployment was successful.  It gives me a peace of mind.

What are arguments against this OR arguments for automatic scripted production deployment?

答:
Here's the biggest argument against manual deploys to production: You're a human and will make mistakes. There will undoubtedly be times when you'll forget to do something that will cause you grief. A well-written automated deployment doesn't have that same tendency. It's true that you can still have messed-up production deploys, but that's because your automated deployment has bugs that need to be solved.

In my experience the benefits of automated deploys to production are tremendous. The biggest one is that you get to have fun on the weekends instead of trying to march through a manual deployment process that won't cooperate.

That said, here are some key pointers for automating your production deployments:

Don't do it all at once! Start slowly writing your automated deployments. Set up a separate non-production environment first, and try automating deployments there. Once you've built up confidence in your automated deployments, you can start thinking about doing production deploys

Start releasing and deploying very frequently! It's much easier to do automated deployments when you don't have 4 months of code waiting to be released. Release small features and bug fixes multiple times per week. The benefits of this release style cannot be understated!

Rely on automated tests to give you confidence that your production environment will work. Again, this takes time to build up, but is very important. Automated tests are always better than manual acceptance tests. Sure, manual acceptance tests are fine, but automated tests can help you know whether you should deploy into production or not. They are the key that enable this whole process of automated, continuous delivery. If your tests don't pass, you know not to deploy into production.


问:
Do I have to include the Copyright notice from the original author?
I'm using some codes that I modified, from Paradigms of Artificial Intelligence Programming to create another project, the project is released under GPL V2.

The License agreement is written here, it says: Copyright © 1998-2002 by Peter Norvig.

My question is: Were's almost in 2014, do I still have to include that license or did it expire and therefore I may use the codes anyway that I like?

答:
Copyright generally does not expire until 50 or 70 years after the death of the person who wrote it.

Therefore, you must still license your own project under the GPL v2.


答:
As with all legal questions - you really should ask a lawyer.

But a short answer: the date in the copyright is when changes were made by that author, not any indication of copyright expiry. The original author worked on the code between 1998 and 2002 - those changes are still under copyright, and will be for a some while longer.

Title: Do I have to include the Copyright notice from the original author?

Body:
I'm using some codes that I modified, from Paradigms of Artificial Intelligence Programming to create another project, the project is released under GPL V2.

The License agreement is written here, it says: Copyright © 1998-2002 by Peter Norvig.

My question is: Were's almost in 2014, do I still have to include that license or did it expire and therefore I may use the codes anyway that I like?


问:
What to do with bugs that do not repro?
I have a tester that while testing will have an error occur (ok so far), but then he frequently reports it right away.  We (the developers) then later find that the tester has not tried to reproduce the issue and (when asked) cannot find a way to make it happen again.

Now these are still bugs, I don't want to ignore them.  But without repro steps I am kind of stuck.  Sometimes there is a stack trace (though frequently it is not useful because this is compact framework and there are no line numbers).  But when there is one I can take the stack trace and crack open the code and start guessing, but that does not lead to testable "fixes".

What do you do in scenarios like this?

答:
A few more suggestions:

Add logging (and not just a keylogger :}) to your product code. "No repro" bugs may be flukes, but they may be memory or state corruption that only occurs on a dirty system used in unanticipated ways (i.e. like a customers computer). Logging or tracing information can help you figure out what may have been wrong when the tester found the fluke.

Scan the rest of the "no repro" bugs in the database (or whatever you use for bug tracking). Often, the flukes clump together in one area of the product. If it looks like one component is at fault, code review the component for possible flakiness, add additional logging to that component - or both.

Take half an hour or so and watch your tester test. Their approach may give you an idea of what went wrong (e.g. "interesting - I didn't know you could get to that dialog that way"). You also may find that they skip a dialog or configuration step unintentionally. It's worth the time investment to get in their head a bit.

Title: What to do with bugs that do not repro?


答:
The copyright line doesn't refer to the code, but to the license itself. The time span does not determine until when the copyright is active, but during which time span the copyrighted subject was created and/or modified. This is not relevant here.

You are not free to use the code in any way you like: You have to adhere to the license which you linked to:

“The origin of this software must not be misrepresented, either by explicit claim or by omission.” – I would interpret this such that you would have to mark the sections in your source code taken from Mr. Norvig. Omitting any credit to him would be a misrepresenting the origin of your software by omission.

“Altered versions must be plainly marked as such, and must not be misrepresented as being the original software. Altered versions may be distributed in packages under other licenses (such as the GNU license).” – If you alter the code (which you intend you do), you may distribute the altered version under any license you choose. However, you are not allowed to present the altered version as if it were written by Mr. Norvig.

In addition to marking the section of code which are based on Mr. Norvigs work, I would think crediting him with a sentence like

Parts of this software are based on code from Paradigms of Artificial Intelligence Programming by Peter Norvig. See <http://norvig.com/paip.html>.

in your copyright statement would be appropriate.

I am not a lawyer, so you should really consider seeing one.


问:
using pre-commit / post-merge hook script to replace configuration values
I'm having some problem developing a web application with various developers, each one has an specific configuration to work.

and i would like to use the less resource cosuming approach to avoid that any personal configuration goes to the repository.

the basic idea is: to have a config file with all the pairs of key/values to store the configuration and substitute specific constants inserted in the code with the correpondent value in the code.

I'm pretending to replace the values in the code with the key text using this syntax {@KEY_TEXT} in pre-commit and executing the opposite operation in the post-merge hook

i'm doing this right?
there's a more efficent way to do this?

EDIT: Why i don't have all debug configuration in a single file, because all this values are inserted accross various files / and involves lot of different programming languages and differente context.

i'm Using PHP/javascript/Shell/Batch file Language (Windows). in a cross plataform enviroment

答:
How about simply not committing the debug config file?

The production config file can still be in source control with a different name.  Just have your build/packaging scripts rename it during build/packaging.


问:
How to best protect from 0 passed to std::string parameters?
I have just realized something disturbing.  Every time I have written a method that accepts a std::string as a paramater, I have opened up myself to undefined behaviour.

For example, this...

```<code>void myMethod(const std::string& s) {
    /* Do something with s. */
}
</code>```

...can be called like this...

```<code>char* s = 0;
myMethod(s);
</code>```

...and there's nothing I can do to prevent it (that I am aware of).

So my question is: How does someone defend themself from this?

The only approach that comes to mind is to always write two versions of any method that accepts an std::string as a parameter, like this:

```<code>void myMethod(const std::string& s) {
    /* Do something. */
}

void myMethod(char* s) {
    if (s == 0) {
        throw std::exception("Null passed.");
    } else {
        myMethod(string(s));
    }
}
</code>```

Is this a common and/or acceptable solution?

EDIT:  Some have pointed out that I should accept const std::string& s instead of std::string s as a parameter.  I agree.  I modified the post.  I don't think that changes the answer though.

答:
I also encountered this problem a few years ago and I found it to be a very scary thing indeed. It can happen by passing a nullptr or by accidentally passing an int with value 0. It's really absurd:

```<code>std::string s(1); // compile error
std::string s(0); // runtime error
</code>```

However, in the end this only bugged me a couple of times. And each time it caused an immediate crash when testing my code. So no night-long sessions will be required to fix it.

I think overloading the function with const char* is a good idea.

```<code>void foo(std::string s)
{
    // work
}

void foo(const char* s) // use const char* rather than char* (binds to string literals)
{
    assert(s); // I would use assert or std::abort in case of nullptr .
    foo(std::string(s));
}
</code>```

I wish a nicer solution was possible. However, there isn't.

Body:
I also encountered this problem a few years ago and I found it to be a very scary thing indeed. It can happen by passing a nullptr or by accidentally passing an int with value 0. It's really absurd:

std::string s(1); // compile error
std::string s(0); // runtime error

However, in the end this only bugged me a couple of times. And each time it caused an immediate crash when testing my code. So no night-long sessions will be required to fix it.

I think overloading the function with const char* is a good idea.

void foo(std::string s)
{
    // work
}

void foo(const char* s) // use const char* rather than char* (binds to string literals)
{
    assert(s); // I would use assert or std::abort in case of nullptr .
    foo(std::string(s));
}

I wish a nicer solution was possible. However, there isn't.


问:
How to manage styles on a group of websites
Up until now the styles were handled by a single CSS file (for each site).

I'm customizing it like this:

opened the site in Firefox

opened inspector/style editor

changed CSS values around until I was happy with how the site looks

copied the generated CSS code and pasted it in the .css file from the server

The design is quite outdated, so I decide to upgrade the application that powers the sites and the designs.

But now, my developer tells me I'm doing it wrong. He wants to use "less", "compile and cache to css", create themes and allow me to change only basic stuff like colors and fonts through an administration interface. He says that if I want to customize deeper things I would have to learn CSS and edit the "less" files inside a code editor, not Firefox.

Is he crazy or what? I don't understand how is this better than what I'm currently doing?

答:
Your developer is right -- you should take a look at pre-CSS languages like LESS, instead of only code-bashing in a browser's developer toolbar.  The latter is good for finding out why a design doesn't look the way you want it to, or for the roughest prototyping, not for actual design work.

Of course, LESS and its kin are only tools to help you design, not the design in and of itself.  You could skip the muck and instead write your CSS rules by hand, but you shouldn't skip the step of thinking in terms of clear rules and semantic design.  Doing so has quite a few benefits:

It forces you to learn how CSS actually works, which will make both your own life easier down the road and make it possible to hand this site off to a successor as you go on to better things.

It helps you keep the file size smaller, which means your pages will load faster, feel snappier, and impress your customers more.

It lets you get ahead of unexpected code changes, especially oddball formatting in the HTML itself.  Sure, you never have a
 inside of a  NOW, but you don't know what tomorrow may bring.

Good design lets your site look clean even as technologies shift and evolve.  A site made to look good on your 1600x1024 desktop monitor may look terrible on a cell phone, or a tablet, or TV, or other device.

Thinking in terms of rules helps you keep the content and design separate, which is as close to an iron-clad rule of the web are there is.

(And really, take a look at LESS while you've still got the same developer.  There's nothing like a knowledgeable enthusiast to help you learn a new technique.)

Body:
Your developer is right -- you should take a look at pre-CSS languages like LESS, instead of only code-bashing in a browser's developer toolbar.  The latter is good for finding out why a design doesn't look the way you want it to, or for the roughest prototyping, not for actual design work.

Of course, LESS and its kin are only tools to help you design, not the design in and of itself.  You could skip the muck and instead write your CSS rules by hand, but you shouldn't skip the step of thinking in terms of clear rules and semantic design.  Doing so has quite a few benefits:

It forces you to learn how CSS actually works, which will make both your own life easier down the road and make it possible to hand this site off to a successor as you go on to better things.

It helps you keep the file size smaller, which means your pages will load faster, feel snappier, and impress your customers more.

It lets you get ahead of unexpected code changes, especially oddball formatting in the HTML itself.  Sure, you never have a <li> inside of a <td> NOW, but you don't know what tomorrow may bring.

Good design lets your site look clean even as technologies shift and evolve.  A site made to look good on your 1600x1024 desktop monitor may look terrible on a cell phone, or a tablet, or TV, or other device.

Thinking in terms of rules helps you keep the content and design separate, which is as close to an iron-clad rule of the web are there is.

(And really, take a look at LESS while you've still got the same developer.  There's nothing like a knowledgeable enthusiast to help you learn a new technique.)