答:
Thanks for the pointers to the existing questions.  The answers to those are rather different to what I understand you want though.   I'll give you some suggestions from my own experience.  My own degree is in physics, do I came to the field with gaps around formality, correctness/verification, algorithm analysis, dynamic programming, database systems, and to a large extent in the beginning, selection of data structures and algorithms.   The most obvious gaps (e.g. data structures and algorithms) I closed early but I still read books in that area, to deepen my understanding, see alternative presentations, and refresh my memory.   (I'm around 40, so books work for me :)

Here's a reading list (in no particular order other than it's the order they came to mind).

Programming Pearls (Jon Bentley)

More Programming Pearls (Jon Bentley)

The Art of Computer Programming (Donald Knuth)

Algorithms In C++ (Robert Sedgewick)

The Algorithm Design Manual (Steven Skiena)

The Practice of Programming (Kernighan and Pike)

Elements of Programming (Stepanov)

How to Solve It (Polya)

Structure and Interpretation of Computer Programs (Abelson and Sussman)

I also got a lot out of Writing Solid Code when I read it in the mid-90s.   But it's not in the list since it doesn't really relate strongly to thinking skills as such (it deals more with designing APIs to minimise the chance of accidental incorrect use - or at least that was my main take-away from it).

I also got a lot out of Gödel, Escher, Bach  (Hofstadter) as a teenager, but it's already mentioned in the answers to the questions you already pointed to.  It's a book to read for pleasure, rather than directly to develop one's computer science skills.

I work with a pretty large number of talented programmers, and almost universally they are fans of Programming Pearls.  Certainly I wish more of the candidates I interview had read chapter 4 of that book.

Title: Thinking skills to be a good programmer


问:
Are there any real-world cases for C++ without exceptions?
In When to use C over C++, and C++ over C? there is a statement wrt. to code size / C++ exceptions:

Jerry answers (among other points):

(...) it tends to be more difficult to produce truly tiny executables with C++. For really small systems, you're rarely writing a lot of code anyway, and the extra (...)

to which I asked why that would be, to which Jerry responded:

the main thing is that C++ includes exception handling, which (at least usually) adds some minimum to the executable size. Most compilers will let you disable exception handling, but when you do the result isn't quite C++ anymore. (...)

which I do not really doubt on a technical real world level.

Therefore I'm interested (purely out of curiosity) to hear from real world examples where a project chose C++ as a language and then chose to disable exceptions. (Not just merely "not use" exceptions in user code, but disable them in the compiler, so that you can't throw or catch exceptions.) Why does a project chose to do so (still using C++ and not C, but no exceptions) - what are/were the (technical) reasons?

Addendum: For those wishing to elaborate on their answers, it would be nice to detail how the implications of no-exceptions are handled:

STL collections (vector, ...) do not work properly (allocation failure cannot be reported)

new can't throw

Constructors cannot fail

答:
Qt almost never uses exceptions. Errors in Qt are signified with error codes and signals. The officially stated reason is:

When Qt was started exceptions were not available for all the compilers that needed to be
  supported by Qt. Today we are trying to keep the APIs consistent, so modules that have a
  history of not using exceptions will generally not get new code using exceptions added.

Why does QT use so few exceptions?

Today, one common criticism of Qt is that its exception safety is not complete.

ContentLicense: CC BY-SA 3.0


问:
Thinking skills to be a good programmer
I have been programming for last 15 years with non-CS degree. Main reason I got into programming was that I liked to learn new things and apply them to my work. And I was able to find and fix programming errors and their causes faster than others. But I never find myself a a guru or an expert, maybe due to my non-CS major. And when I saw great programmers, I observed they are very good, much better than me of course, at solving problems.

One skill I found good in my mid-career is thinking of requirements and tasks in a reverse order and in abstract. In that way, I can see what is really required for me to do without detail and can quickly find parts of solution that already exist.

So I wonder if there are other thinking skills to be a good programmer. I've followed Q&As below and actually read some of books recommended there. But I couldn't really pickup good methods directly applicable for my programming work.

What non-programming books should a programmer read to help develop programming/thinking skills?

https://softwareengineering.stackexchange.com/questions/44654/skills-and-habits-to-develop-to-be-good-at-programming-im-a-newbie

答:
There are two non-programming books that I think are crucial.

The first is "Lady or the Tiger", by Raymond Smullyan. This is a great set of logic puzzles that sneakily includes a sort of tour of automata theory. Nifty stuff.

The second is "Godel, Escher, Bach: An Eternal Golden Braid" by Douglas Hofstadter, which gets you thinking about recursion and language theory.

If you want good habits for a newbie, read "Apprenticeship Patterns" by Hoover and "The New Programmers Survival Manual" by Carter. Both of these books talk about how to expand your skills and how to expand your career. They take different approaches, but they work well together.

Title: Thinking skills to be a good programmer


问:
Strategy/algorithm to divide fair teams based on history
We are a group of people playing floorball together on a regular basis. Every session starts with the daunting task of dividing teams...

So what would be better than an application to pick teams automatically?

So, given a history of team-combinations and results, and a list of people showing up for this particular session, what would be a good strategy to find the optimal teams? By optimal, I mean teams as equal as possible.

Any ideas?

Edit: To make it clear, the data that I have to base the picking on, would be something like this:

```<code>[{ team1: ["playerA", "playerB", "playerC"],
   team2: ["playerD", "playerE", "playerF"],
   goals_team1: 10,
   goals_team2:  8
 },
 { team1: ["playerD", "playerB", "playerC"],
   team2: ["playerA", "playerE", "playerG"],
   goals_team1:  2,
   goals_team2:  5
 },
 { team1: ["playerD", "playerB", "playerF"],
   team2: ["playerA", "playerE", "playerC"],
   goals_team1:  4,
   goals_team2:  2
 }]
</code>```

答:
If you want your algorithm to be reasonably, simple algorithms just won't cut it. They will often give you strange results

You will have to go with something like ELO or Trueskill system (ELO does not work for teams without modifications, though).


问:
Review quality of code
I have been asked to quality review two code bases. I've never done anything like that, and need advice on how to perform it and report it.

Background

There are two providers of code, one in VB and one in C (ISO 9899:1999 (C99)). These two programs do not work so well together, and of course, the two suppliers blames  each other. I will therefore as a independent person review both codes, on a comprehensive level review the quality of the codes to find out where it is most likely that the problem lies. I will not try to find problems, but simply review the quality and how simple it is to manage and understand the code.

Edit:
I have yet not received much information about what the problem consists of. I've just been told that I will examine the code in terms of quality. Not so much more. I do not know the background to why they took this decision.

答:
Roll a 6 sided die. 1-3 is the VB code, 4-6 is the C code. Take a 2 month vacation and tell everyone which code is bad after you return. You are in a political fight it would appear.

Or better yet, tell them you are going to review the code, but don't. Come back with working fixes to both sets of code that allow them to work together.

OwnerDisplayName: magol

Title: Review quality of code


问:
When too much encapsulation was reached
Recently, I read a lot of good articles about how to do good encapsulation. And when I say "good encapsulation", I am not talking about hiding private fields with public properties; I am talking about preventing users of your API from doing wrong things.

Here are two good articles about this subject:

http://blog.ploeh.dk/2011/05/24/PokayokeDesignFromSmellToFragrance.aspx

http://lostechies.com/derickbailey/2011/03/28/encapsulation-youre-doing-it-wrong/

At my job, the majority of our applications are not destined for other programmers but rather for the customers.

About 80% of the application code is at the top of the structure (Not used by other code). For this reason, there is probably no chance ever that this code will be used by other application.

An example of encapsulation that prevents users from doing wrong things with your API is returning an IEnumerable instead of IList when you don't want to give the ability to the user to add or remove items in the list.

My question is: When can encapsulation be considered simply OOP purism, keeping in mind that each hour of programming is charged to the customer?

I want to create code that is maintainable and easy to read and use, but when I am not building a public API (to be used by other programmers), where can we draw the line between perfect code and not so perfect code?

答:
The fact that your code is not being written as a public API is not really the point--the maintainability you mention is.

Yes, application development is a cost center, and the customer does not want to pay for unnecessary work.  However, a badly designed or implemented application is going to cost the customer a lot more money when they decide that it needs another feature, or (as will certainly happen) the business rules change.  Good OO principles are there because they help make it safer to modify and append the code base.

So, the customer may not directly care what your code looks like, but the next guy who has to modify it certainly will.  If the encapsulation (as you're defining it) is not there, it's going to take him a lot longer and be much riskier for him to do what he needs to do to serve the customer's needs.

Title: When too much encapsulation was reached


答:
Encapsulation exists to protect your class invariants. This is the primary measure for 'how much is enough'. Any way to break invariants breaks class semantics and is bad (tm).

A secondary concern is limiting visibility and as such the number of places that can/will access data and thus increase coupling and/or number of dependencies. This needs to be done with care though. As requirements change, often times that decision to limit what the class exposes leads to awkward hacks to deal with the new requirement.

This though is one of those design concerns that comes with experience. In doubt, favor encapsulation. The concerns are regardless of 'public' API or not. Even for internal code, new or forgetful or sleepy programmers will write bad code. If your class needs to be resistant to bad code, then do so.

Title: When too much encapsulation was reached

Body:
Recently, I read a lot of good articles about how to do good encapsulation. And when I say "good encapsulation", I am not talking about hiding private fields with public properties; I am talking about preventing users of your API from doing wrong things.

Here are two good articles about this subject:

http://blog.ploeh.dk/2011/05/24/PokayokeDesignFromSmellToFragrance.aspx

http://lostechies.com/derickbailey/2011/03/28/encapsulation-youre-doing-it-wrong/

At my job, the majority of our applications are not destined for other programmers but rather for the customers.

About 80% of the application code is at the top of the structure (Not used by other code). For this reason, there is probably no chance ever that this code will be used by other application.

An example of encapsulation that prevents users from doing wrong things with your API is returning an IEnumerable instead of IList when you don't want to give the ability to the user to add or remove items in the list.

My question is: When can encapsulation be considered simply OOP purism, keeping in mind that each hour of programming is charged to the customer?

I want to create code that is maintainable and easy to read and use, but when I am not building a public API (to be used by other programmers), where can we draw the line between perfect code and not so perfect code?


问:
Win32 and Win64 programming in C sources?
I'm learning OpenGL with C and that makes me include the windows.h file in my project. I'd like to look at some more specific windows functions and I wonder if you can cite some good sources for learning the basics of Win32 and Win64 programming in C (or C++).

I use MS Visual C++ and I prefer to stick with C even though much of the Windows API seems to be C++. I'd like my program to be portable and using some platform-indepedent graphics library like OpenGL I could make my program portable with some slight changes for window management. Could you direct me with some pointers to books or www links where I can find more info? I've already studied the OpenGL red book and the C programming language, what I'm looking for is the platform-dependent stuff and how to handle that since I run both Linux and Windows where I find the development environment Visual Studio is pretty good but the debugger gdb is not available on windows so it's a trade off which environment i'll choose in the end - Linux with gcc or Windows with MSVC.

Here is the program that draws a graphics primitive with some use of windows.h This program is also runnable on Linux without changing the code that actually draws the graphics primitive:

```<code>#include <windows.h>
#include <gl/gl.h>

LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM);
void EnableOpenGL(HWND hwnd, HDC*, HGLRC*);
void DisableOpenGL(HWND, HDC, HGLRC);

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    WNDCLASSEX wcex;
    HWND hwnd;
    HDC hDC;
    HGLRC hRC;
    MSG msg;
    BOOL bQuit = FALSE;
    float theta = 0.0f;

    /* register window class */
    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style = CS_OWNDC;
    wcex.lpfnWndProc = WindowProc;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = hInstance;
    wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    wcex.lpszMenuName = NULL;
    wcex.lpszClassName = "GLSample";
    wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);;

    if (!RegisterClassEx(&wcex))
        return 0;

    /* create main window */
    hwnd = CreateWindowEx(0,
                          "GLSample",
                          "OpenGL Sample",
                          WS_OVERLAPPEDWINDOW,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          256,
                          256,
                          NULL,
                          NULL,
                          hInstance,
                          NULL);

    ShowWindow(hwnd, nCmdShow);

    /* enable OpenGL for the window */
    EnableOpenGL(hwnd, &hDC, &hRC);

    /* program main loop */
    while (!bQuit)
    {
        /* check for messages */
        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            /* handle or dispatch messages */
            if (msg.message == WM_QUIT)
            {
                bQuit = TRUE;
            }
            else
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }
        else
        {
            /* OpenGL animation code goes here */

            glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            glClear(GL_COLOR_BUFFER_BIT);

            glPushMatrix();
            glRotatef(theta, 0.0f, 0.0f, 1.0f);

            glBegin(GL_TRIANGLES);

                glColor3f(1.0f, 0.0f, 0.0f);   glVertex2f(0.0f,   1.0f);
                glColor3f(0.0f, 1.0f, 0.0f);   glVertex2f(0.87f,  -0.5f);
                glColor3f(0.0f, 0.0f, 1.0f);   glVertex2f(-0.87f, -0.5f);

            glEnd();

            glPopMatrix();

            SwapBuffers(hDC);

            theta += 1.0f;
            Sleep (1);
        }
    }

    /* shutdown OpenGL */
    DisableOpenGL(hwnd, hDC, hRC);

    /* destroy the window explicitly */
    DestroyWindow(hwnd);

    return msg.wParam;
}

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
        case WM_CLOSE:
            PostQuitMessage(0);
        break;

        case WM_DESTROY:
            return 0;

        case WM_KEYDOWN:
        {
            switch (wParam)
            {
                case VK_ESCAPE:
                    PostQuitMessage(0);
                break;
            }
        }
        break;

        default:
            return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }

    return 0;
}

void EnableOpenGL(HWND hwnd, HDC* hDC, HGLRC* hRC)
{
    PIXELFORMATDESCRIPTOR pfd;

    int iFormat;

    /* get the device context (DC) */
    *hDC = GetDC(hwnd);

    /* set the pixel format for the DC */
    ZeroMemory(&pfd, sizeof(pfd));

    pfd.nSize = sizeof(pfd);
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DRAW_TO_WINDOW |
                  PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 24;
    pfd.cDepthBits = 16;
    pfd.iLayerType = PFD_MAIN_PLANE;

    iFormat = ChoosePixelFormat(*hDC, &pfd);

    SetPixelFormat(*hDC, iFormat, &pfd);

    /* create and enable the render context (RC) */
    *hRC = wglCreateContext(*hDC);

    wglMakeCurrent(*hDC, *hRC);
}

void DisableOpenGL (HWND hwnd, HDC hDC, HGLRC hRC)
{
    wglMakeCurrent(NULL, NULL);
    wglDeleteContext(hRC);
    ReleaseDC(hwnd, hDC);
}
</code>```

答:
The book to buy for learning the basics of the WinApi would be Charles Petzold's Programming Windows http://www.amazon.com/Programming-Windows%C2%AE-Edition-Microsoft-Series/dp/157231995X

He is supposed to have the 6th edition sometime this year. I believe the new edition will cover C# as well as C/C++.


问:
Does Mono have a place in the enterprise world?
For enterprise windows-based solutions, .NET is the best choice sometimes. How is Mono looked at by the enterprises who have to use Linux (or rather prefer to use Linux) ? Assuming that the developers aren't a problem and they are familiar with .NET/Mono and other possible competitors such as Java.   </p>

<p>Would a medium/large company run Mono on their servers as opposite to technologies such as Java? Do you know of any such company ? </p>

答:
Before using mono, we have to ensure no hardcoded '\' for path string (use Path.Combine()) or
"COM" prefix (simply accept string instead of integer) for serial port is in the program.

What works well:

Console App

Web App

Problems encountered:

WinForms not stable: crash randomly.

Language support: The community may not know every language well, especially the dialects for some countries/cities. Corresponding locales / collations may be missed.

Rarely used methods may have incompatible behaviour with .NET.

xsp only supports HTTP 1.0. Currently it lacks support HTTP 1.1.

Browser control does not work well.

It is better to use mono internally (such as ERP system) as a controlled environment.

ContentLicense: CC BY-SA 2.5


答:
Mono is a great alternative if you already have .NET code that needs to run on a cross-platform environment. Mono is used pretty extensively in the business world specifically to solve this very problem.

I would argue against using the existence of Mono as an excuse for starting a project with .NET that you know will need to be cross-platform. The reason for this is the lag between the state-of-the-art with .NET versus the development speed of Mono.

On the other hand, if you do intend to use Mono in a future project, I would caution you to target the Mono framework and run on .NET as a secondary alternative since Mono is largely a subset of the full .NET functionality.

Title: Does Mono have a place in the enterprise world?

Body:
For enterprise windows-based solutions, .NET is the best choice sometimes. How is Mono looked at by the enterprises who have to use Linux (or rather prefer to use Linux) ? Assuming that the developers aren't a problem and they are familiar with .NET/Mono and other possible competitors such as Java.   </p>

<p>Would a medium/large company run Mono on their servers as opposite to technologies such as Java? Do you know of any such company ? </p>


问:
Is it a good programming practice to have a class with several .h files?
I suppose the class have several different interfaces. Some it shows to some class, some it shows to other classes.

Are there any good reason for that?

One thing I can think of is with one .h per class, interface would either be public or private.

What about if I want some interface to be available to some friends' class and some interface to be truly public?

Sample:

```<code>@interface listNewController:BadgerStandardViewViewController <UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,NSFetchedResultsControllerDelegate,UIScrollViewDelegate,UIGestureRecognizerDelegate> {
}

@property (nonatomic) IBOutlet NSFetchedResultsController *FetchController;
@property (nonatomic) IBOutlet UITextField *searchBar1;
@property (nonatomic) IBOutlet UITableView *tableViewA;
+ (listNewController *) singleton; //For Easier Access
-(void)collapseAll;
-(void)TitleViewClicked:(TitleView *) theTitleView;
-(NSUInteger) countOfEachSection:(NSInteger)section;
@end
</code>```

Many of those public properties and function are only ever called by just one other classes. I wonder why I need to make them available to many classes.

It's in Objective-c by the way

What do you mean? Interface is interface. In C++ you can declare some classes as "friends". In Objective-c you cannot I think. Basically I want to emulate that. My friends can access some members that's not available too publicly,.

答:
Typically you want one .h file per class.  This helps to encapsulate all of the related info for a class in one place.  Personally I have never run into multiple .h files for a single class, though I have often run into multiple classes in a single .h file.

Ultimately it comes down to whether or not others will need to work with your code.  If so I recommend staying with a single .h file per class.  If no one else will ever see your code then do what makes sense to you.  Just keep in mind that bad habits can be hard to break.


答:
I'm interested in how you evaluate the skill of other programmers.

I think that specific, applicable knowledge creates much more impressive results than general skills do. If you already have a lot of context, and maybe have seen similar problems before, you may be able to find the cause of an issue very quickly. If you already know how to use a set of applicable tools, you may be able to build solutions very quickly. If you don't already have that knowledge, but you do have the necessary skills, it will take you more time to acquire the knowledge you need. If that's the case, you're taking longer to cover more distance, which doesn't necessarily mean you're slower.

Of course, if you can build up knowledge and learn to use tools that will help you later, this will give you an advantage. I find that learning a little bit about a wide variety of topics helps here, as they end up overlapping more than I would expect, and just knowing where to look for the information you need can save a lot of time. But maybe that's just me.

Title: Thinking skills to be a good programmer

Body:
I have been programming for last 15 years with non-CS degree. Main reason I got into programming was that I liked to learn new things and apply them to my work. And I was able to find and fix programming errors and their causes faster than others. But I never find myself a a guru or an expert, maybe due to my non-CS major. And when I saw great programmers, I observed they are very good, much better than me of course, at solving problems.

One skill I found good in my mid-career is thinking of requirements and tasks in a reverse order and in abstract. In that way, I can see what is really required for me to do without detail and can quickly find parts of solution that already exist.

So I wonder if there are other thinking skills to be a good programmer. I've followed Q&As below and actually read some of books recommended there. But I couldn't really pickup good methods directly applicable for my programming work.

What non-programming books should a programmer read to help develop programming/thinking skills?

https://softwareengineering.stackexchange.com/questions/44654/skills-and-habits-to-develop-to-be-good-at-programming-im-a-newbie


答:
You like to learn new things and can fix errors rapidly. It means you have the two key elements to become a guru: enthusiasm and ability. But you think you never find yourself an expert, maybe you need two things more: focus and time. For example, when Linus Torvalds first released Linux in 1991, no one regarded him as a guru. He is still working on Linux everyday and you can see his merging log from Linux kernel Git repository nowadays. His focus makes him the most famous guru in Linux field. Time is an abstract concept, it means keeping yourself up to date, gaining experience through constant practice, sharing your knowledge to other people and improving with retrospect.

I have the same situation with you. I have been programming for 15 years with non-CS degree (EE degree), and I am always confused by my huge gap with the guru in my field. But I have the dream to become a guru and started to attend an open source project. Thinking skills come from practice and experience. Some books may be helpful, but their significance are mainly instructional. The thinking skills belonging to yourself are from your own experience. Let's start from now on!

Title: Thinking skills to be a good programmer


问:
How do I know if I am using Scrum methodologies?
When I first started at my current job, my purpose was to rewrite a massive excel-VBA workbook-application to C# Winforms because it was thought that the new C# app will fix all existing problems and have all the new features for a perfect world.

If it were a direct port, in theory it would be easy as i just need to go through all the formulas, conditional formatting, validations, VBA etc. to understand it. However, that was not the case. Many of the new features are tightly dependant on business logic which I am unfamiliar with.

As a solo programmer, the first year was spent solely on deciphering the excel workbook and writing the C# app. In theory, I had the business people to "help" me specify requirements, how GUI looks and work, and testing of the app etc; but in practice it is like a contant tsunami of feature creep.

At the beginning of the second year I managed to convince the management that this is not going anywhere. I made them start from scratch with the excel-VBA.

I have this "issue log" saved on the network, each time they found something they didn't like about the excel-VBA app, they will write it in there. I check the log daily and consolidate issues (in my mind) mainly into 2 groups: (1) requires massive change. (2) can be fixed in current version.

For massive change issues, I make a copy of the latest excel-VBA and give it a new version number, then work on it whenever I can. For current version fixes, I make the changes in a few days to a week, and then immediately release it. I also ensure I update the same change in any in-progress massive change future versions.

This has gone on for about 4 months and I feel it works great. I made many releases and solved many real issues, also understood the business logic more and more. However, my boss (non-IT trained) thinks what I am doing are just adhoc changes and that i am not looking at the "bigger picture".

I am struggling to convince my boss that this works. So I hope to formalise my approach and maybe borrow a buzzword to confuse him. Incidentally, I read about Agile and SCRUM, about backlog and sprints. But it's all very vague to me still.

QUESTION (finally): I want to tell him that this is SCRUM! But I want to hold my breath first and ask whether my current approach is considered SCRUM or SCRUM-like? How can I make it more SCRUM-like? Note that I have only myself, there's no project leader or teams.

答:
When I got you right, this is mainly about you and your boss. What you are doing is not scrum, I guess (do you have daily scrum meetings? I don't think so.) For me it seems you are doing  just classical incremental development in small steps, supported by an issue/requirement list and some lightweight configuration management. Some people call this "agile" nowadays, but for me that seems just to be a fancy word for an old wisdom.

However, my boss (non-IT trained) thinks what I am doing are just adhoc changes and that i am not looking at the "bigger picture".

[...]  maybe borrow a buzzword to confuse him

I don't think this is a good strategy. If your boss does not see the value in your work, you should not confuse him with buzzwords. Instead you should make the value more transparent.

For example: do you keep a changelog? I mean, a changelog for the end-user, not referring to any internal code changes, but one where every user (and your boss) can see which new features / feature changes you have implemented in each version. This may a thing to start with.

What I don't understand is what your boss thinks what the bigger picture should look like, and why your approach does not go in that direction. From what you are telling, you are not just making ad-hoc changes, you are also planning and implementing bigger changes, and all changes are motivated by user requirements. So you obviously following a "bigger picture".

Or is your boss thinking the Excel-VBA solution should be replaced by a .NET application on the long-term? If that's the case, I would recommend to choose a path which can be followed incrementally. A C# rewrite may not be the best thing to reach that goal. A better approach may be to port parts of your Excel-VBA to VB.NET, step-by-step. I have done something similar in the past utilizing Excel-DNA. Using VB.NET when you have a lot of existing VBA code makes the porting a hell lot easier.

Concerning rewrites, I recommend this great article from Joel Spolsky.


问:
Why was Tanenbaum wrong in the Tanenbaum-Torvalds debates?
I was recently assigned reading from the Tanenbaum-Torvalds debates in my OS class. In the debates, Tanenbaum makes some predictions:

Microkernels are the future

x86 will die out and RISC architectures will dominate the market

(5 years from then) everyone will be running a free GNU OS

I was a one year old when the debates happened, so I lack historical intuition. Why have these predictions not panned out? It seems to me, that from Tanenbaum's perspective, they're pretty reasonable predictions of the future. What happened so that they didn't come to pass?

答:
1. Microkernels failed

For the reasons that Linus Torvalds stated, that on paper it looks theoretically attractive but in implementation on modern systems - which are very complex systems - the complexity becomes exponentially unmanageable.  Case study is GNU Hurd, a fully microkernel system which failed to even achieve basic functions.  Mac OS X is similar to Hurd in structure and it's the least stable and most constrained OS out there.

2. CPU architecture

This has become diversified for various use cases.  One CPU architecture did not dominate because embedded, mobile, desktop, server and so forth use cases are different and required different approaches.  Tannenbaum failed to see this diversification.

3. GNU vs World?

GNU did not dominate, but Linux did on server, embedded and mobile.  Apple tablets and phones run iOS which is just plain old Unix.  Accurate statistics are difficult to acquire for Linux deployments on desktop because there is no real core mechanism - sale of units - that can surely give an accurate value.  Most Linux deployments on the desktop are sometimes recorded as Windows deployments because users buy a Windows system and then write over it with Linux.  However, if you segment OS's then Linux has around 5-6% on the desktop according to http://www.w3schools.com/browsers/browsers_os.asp and this is equal to the number of Windows Vista users worldwide which is highly significant.

Based on my own estimations from various sources it seems that Linux on the desktop could actually be equal to the number of users on Windows XP - roughly 25% - if you count non-Western nations like China and India where Linux is more popular than in the USA or EU but who might not be counted in Western statistics because they only count traffic to English speaking websites aimed at Westerners.

In India most college students use Ubuntu or Fedora because this is the default OS of the Indian education systems and at the famous IIT's. Most Indian government offices use Linux also.  In China Red Flag Linux is the offical OS of the Chinese government and school systems - Academies of Arts and Sciences - and is the recommended OS in China by the state run media as an effort to stop young impoverished Chinese from using pirated copies of Windows.  If you counted the useage of Linux in India and China it would shock most Western tech experts and radically change the perceptions of the true dominance of Linux desktop in non-Western developing nations where it is dominant.


问:
Reading input all together or in steps?
For many programming quizzes we are given a bunch of input lines and we have to process each input , do some computation and output the result.

My question is what is the best way to optimize the runtime of the solution ?

Read all input, store it (in array or something) ,compute result for all of them, finally output it all together.

or
 2. Read one input, compute the result, output the result and so on for each input given.

UPDATE

Since no answer was specific I would ask which approach is the best for problems like this:

Quadrant Queries (30 points)

There are N points in the plane. The ith point has coordinates (xi, yi). Perform the following queries:

1) Reflect all points between point i and j both including along the X axis. This query is represented as "X i j"

  2) Reflect all points between point i and j both including along the Y axis. This query is represented as "Y i j"

  3) Count how many points between point i and j both including lie in each of the 4 quadrants. This query is represented as "C i j"

Input:

The first line contains N, the number of points. N lines follow.

  The ith line contains xi and yi separated by a space.

  The next line contains Q the number of queries. The next Q lines contain one query each, of one of the above forms.

  All indices are 1 indexed.

Output:

Output one line for each query of the type "C i j". The corresponding line contains 4 integers; the number of points having indices in the range [i..j] in the 1st,2nd,3rd and 4th quadrants respectively.

Constraints:

```<code>1 <= N <= 100000
1 <= Q <= 1000000
</code>```

You may assume that no point lies on the X or the Y axis.

  All (xi,yi) will fit in a 32-bit signed integer

  ...

答:
This question isn't really answerable - or rather, the answer is: it depends.

For a short-running task, it doesn't really matter. If the whole thing is done after 1 second, you might as well just go with something that fits the problem well. If the tasks are orthogonal, i.e doesn't depend on each other in any way, you could just read input and compute output directly. However, it's often architecturally sound to do it as described further down in this answer.

For a longer task, typically 10+ seconds, it's very important usability-wise to show feedback, and also validate all input before computation starts. Note that the importance grows exponentially with the execution time.

I've used some tools that has two or more stages. Instead of validating even the syntax for the second stage, it would quit after 10+ minutes with the message 'command line syntax invalid' or something like that. Incredible stuff.

Reading options and input into a proper data structure, validating them and then working on that data gives you a lot for free. It will give you a starting point to start thinking about the problem. It will let you work on the data without worrying about parsing and so on. It will be easy to output timely error messages (since you parse and validate everything at the start).

Even if it is a one-shot thing it's in my opinion definately always worth it to structure the program in a good way.

Title: Reading input all together or in steps?


问:
Does a team of developers need a manager?
Background:

I'm currently part of a team of four: 1 manager, 1 senior developer and 2 developers. We do a range of bespoke in-house systems / projects (e.g. 6-8 weeks) for an organisation of around 3500 staff, as well as all the maintenance and support required from the systems that have been created before. There is not enough of us to do all the work that is potentially coming our way - we're understaffed. Management acknowledge this, but budget restraints limit our ability to recruit additional members to the team (even if we make the salary back in savings).

The Change

This leaves us where we are now. Our manager is due to leave his role for pastures new, leaving a vacancy in the team. Management are using this opportunity to restructure our team which would see the team manager role replaced by another developer and another senior developer. Their logic being that we need more developers, so here's a way of funding it (one of the roles is partially funded from another vacant post).

The team would have no direct line manager and the roles and responsibilities would be divided up between the seniors and the (relatively new to post) service manager (a non-technical role with little-to-no development knowledge/experience whose focus is shared amongst a number of other teams and individuals) - who would be our next actual manager up the food chain.

I guess the final question is:

Is it possible to run a development team without an manager? Have you had experience of this? And what things could go wrong / could be of benefit to us?

I'd ideally like to "see the light" and the benefits of doing things this way, or come up with some points for argument against it.

答:
I would suggest it depends on the battles that need to be fought for the team in the organisation. If there are problems preventing you doing your jobs then the manager should be sorting those out.

That may be things such as ensuring priorities are being controlled and set in a sensible way, ensuring you have the equipment, software etc you need to do your jobs. They should be the team's advocate in the organisation.

How do you engage with the business, how do you determine what you should work on, who determines when you are 'done'. If the organisation deals with these things without your manager having to do much, then great. But then there may be changes outside your team and perhaps if one or two key people in the business change roles you may find yourselves in a difficult situation.

Perhaps you could pick a strong leader in the organisation who can be your advocate, but doesn't need to participate in your day to day management, approach them and see if they would be willing to put your team under them. (Perhaps you already did that with your 'service manager' that you mention.)


答:
short answer: yes it can.

Long answer: but it depends on the team personalities. Obviously, someone has to decide what you're doing and so you need someone to report to - this may not need to be the manager of your team, but someone has to give you work to do. Within the team, you may need someone to decide priorities and/or technical issues, but that can easily be done by a team lead.

Maybe you need to merge your dev team with another one, do you have a test team> would it be better to use the same manager for both, while keeping the dev team semi-autonomous?

It seems to me the service manager can quite happily provide you with the work you need to perform and also check it fits the necessary quality, and he doesn't need any development experience to do this task - software is a business tool, it either fits requirements or it doesn't, and usually the best people to determine that is the users. The service manager will act as a liaison between you and them, and hopefully keep you working right. I'd just worry that he didn't have enough control over your team's responsibilities, as if things started to go awry, you'll end up in an unhappy state until management did make him (or, worse, someone else) responsible for you.

Title: Does a team of developers need a manager?

Body:
Background:

I'm currently part of a team of four: 1 manager, 1 senior developer and 2 developers. We do a range of bespoke in-house systems / projects (e.g. 6-8 weeks) for an organisation of around 3500 staff, as well as all the maintenance and support required from the systems that have been created before. There is not enough of us to do all the work that is potentially coming our way - we're understaffed. Management acknowledge this, but budget restraints limit our ability to recruit additional members to the team (even if we make the salary back in savings).

The Change

This leaves us where we are now. Our manager is due to leave his role for pastures new, leaving a vacancy in the team. Management are using this opportunity to restructure our team which would see the team manager role replaced by another developer and another senior developer. Their logic being that we need more developers, so here's a way of funding it (one of the roles is partially funded from another vacant post).

The team would have no direct line manager and the roles and responsibilities would be divided up between the seniors and the (relatively new to post) service manager (a non-technical role with little-to-no development knowledge/experience whose focus is shared amongst a number of other teams and individuals) - who would be our next actual manager up the food chain.

I guess the final question is:

Is it possible to run a development team without an manager? Have you had experience of this? And what things could go wrong / could be of benefit to us?

I'd ideally like to "see the light" and the benefits of doing things this way, or come up with some points for argument against it.


答:
Processing the data piecemeal will be a hair faster, but for a programming quiz in an academic setting, optimization shouldn't even be on the radar.  Most of the reasons why you should do it this way have nothing to do with run time and everything to do with good practice:

You don't have to re-invent the input-buffering-and-splitting wheel.  Most languages include facilities to read line-at-a-time input that have been debugged and made reasonably efficient.

You don't have to write code to figure out how much input there is and handle storing it before use.

The amount of input isn't limited by available memory.

Repeat the first three items for output.

Your program becomes simpler to write and easier to understand:  read, process, write instead of read and store repeatedly, process and store repeatedly, write repeatedly.

Your program will get along better with other programs when it's part of a pipeline (e.g., generate-input | your-program | process-output).  If you hold all of your output until all of the input has been processed, anything downstream has to sit idle until you start producing output, and you've effectively serialized the process (i.e., you've become a bottleneck).

Don't do anything obviously wasteful, but don't let optimization dictate your design, either.  There's a place for that, but making it run fast doesn't come until after you've made it run and made it run correctly.

Title: Reading input all together or in steps?

Body:
For many programming quizzes we are given a bunch of input lines and we have to process each input , do some computation and output the result.

My question is what is the best way to optimize the runtime of the solution ?

Read all input, store it (in array or something) ,compute result for all of them, finally output it all together.

or
 2. Read one input, compute the result, output the result and so on for each input given.

UPDATE

Since no answer was specific I would ask which approach is the best for problems like this:

Quadrant Queries (30 points)

There are N points in the plane. The ith point has coordinates (xi, yi). Perform the following queries:

1) Reflect all points between point i and j both including along the X axis. This query is represented as "X i j"

  2) Reflect all points between point i and j both including along the Y axis. This query is represented as "Y i j"

  3) Count how many points between point i and j both including lie in each of the 4 quadrants. This query is represented as "C i j"

Input:

The first line contains N, the number of points. N lines follow.

  The ith line contains xi and yi separated by a space.

  The next line contains Q the number of queries. The next Q lines contain one query each, of one of the above forms.

  All indices are 1 indexed.

Output:

Output one line for each query of the type "C i j". The corresponding line contains 4 integers; the number of points having indices in the range [i..j] in the 1st,2nd,3rd and 4th quadrants respectively.

Constraints:

```<code>1 <= N <= 100000
1 <= Q <= 1000000
</code>```

You may assume that no point lies on the X or the Y axis.

  All (xi,yi) will fit in a 32-bit signed integer

  ...


答:
It depends on the problem.

As long as all your data fits in the available physical RAM, there is no reason to pick either possibility for the sake of performance. Reading it all in one go has the advantage that you can jump back and forth in your data without losing performance to I/O, and you can validate all your data before you start processing. Especially with complex data structures (e.g. XML), this approach is much easier than the alternative.

OTOH, processing as you go ('streaming') will make your application more pipe-friendly, that is, if you chain it together with other commands through UNIX pipes (e.g., piping the output of ls into your program, and from there through grep), they will spend less time waiting for each other, and the user will see output right away.

If your input data set is too large to fit in memory at once, you don't have much of a choice - if you try to read it all in one go, you will run out of memory. At best, the system will start swapping, which means slow; at worst, the OS will simply refuse to give your application more memory, or even kill it for misbehaving.

Title: Reading input all together or in steps?


问:
Designing A 2-Way SSL RESTful API
I am starting to develop a WCF API, which should serve some specific clients.

We don't know which devices will be using the API so I thought that using a RESTful API will be the most flexible choice.

All devices using the API would be authenticated using an SSL certificate (client side certificate), and our API will have a certificate as well ( so its a 2 Way SSL)

I was reading this question over SO, and I saw the answers about authentication using Basic-HTTP or OAuth, but I was thinking that in my case these are not needed, I can already trust the client because it possesses the client-side certificate.

Is this design ok?
Am I missing anything?

Maybe there's a better way of doing this?

答: Using mutual authentication is always better than username/passwords as long as you have the appropriate cert management system in place and it's properly managed.  Your management system should provide for an easy way to issue or revoke a cert.</p>

Title: Designing A 2-Way SSL RESTful API


问:
Are Intel compilers really better than the Microsoft ones?
Years ago, I was surprised when I discovered that Intel sells Visual Studio compatible compilers. I tried it in particular for C/C++ as well as fantastic diagnostic tools. But the code was simply not that computationally intensive to notice the difference. The only impression was: did Intel really do it for me just now, wow, amazing tools with nanoseconds resolution, unbelievable. But the trial ended and the team never seriously considered a purchase.

From your experience, if license cost does not matter, which vendor is the winner?

It is not a broad or vague question or attemt to spark a holy war. This sort of question is about two very visible tools. Nobody likes when tools have any mysteries or surprises. And choices between best and best are always the pain. I also understand the grass is always greener argument. I want to hear all "what ifs" stories.

What if Intel just locally optimizes it for the chip stepping of the month, and not every hardware target will actually work as well as Microsoft compiled? What if AMD hardware is the target and everything will slow down for no reason? Or on the other hand, what if Intel's hardware has so many unnoticable opportunities, that Microsoft compiler writers are too slow to adopt and never implement it in the compiler? What if both are the same exactly, actually a single codebase just wrapped into two different boxes and licensed to both vendors by some third-party shop?

And so on. But someone knows some answers.

答:
WARNING: Answer based on own experience - YMMV

If the code is really computationally expensive, yes, definitely. I have seen an improvement of over 20x times with the former Intel C++ Compiler (now Intel Studio if I recall correctly) vs the standard Microsoft Visual C++ Compiler. It's true the code was very far from perfect and that may have played a role (actually that's why we bothered using the Intel compiler, it was easier than refactoring the giant codebase), also the CPU used to run the code was an Intel Core 2 Quad, which is the perfect CPU for such a thing, but the results were shocking. The compiler itself contains myriads of ways to optimize code, including targeting a specific CPU in terms of, say, SSE capabilities. It really makes -O2/-O3 run away ashamed. And that was before using the profiler.

Note that, however, turning on really aggressive optimizations will make the compilation take quite some time, two hours for a large project is not impossible at all. Also, with high levels of optimizations, there's a higher chance of an error in the code to manifest itself (this can be observed with gcc -O3, too). To a project you know well, this might be a plus, since you'll find and fix any eventual bugs you didn't catch earlier, but when compiling a hairy mess, you just cross your fingers and pray to the x86 gods.

Something about performance on AMD machines: It's not as good as Intel CPUs, but it's still way better than the MS C++ compiler (again, from my experience). The reason is that you can also target a generic CPU with SSE2 support (for example). Then AMD CPUs with SSE2 will not be discriminated much. Intel compiler on Intel CPU really steals the show, though. It's not all double rainbows and shiny unicorns, however. There have been some heavy accusations about binaries not-running at all on non-GenuineIntel CPUs and (this one is admitted) artificially induced inferior performance on CPUs by other vendors. Also note this is information from at least 3 years ago and it's validity as of now is unknown, BUT the new product descriptions gives binaries a carte blanche to run as slow as Intel sees fit on non-Intel CPUs.

I don't know what it is about Intel and why they make so good numeric computation tools, but have a look at this, too: http://julialang.org/. There is a comparison and if you look at the last row, MATLAB shines by defeating both C code and Julia, what strikes me is that the authors think the reason is Intel's Math Kernel Library.

I realize this sounds a lot like an advertisement for the Intel Compiler toolkit, but in my experience it really did the job well, and even simple logic dictates that the guys who make CPUs should know best how to program for them. IMO, the Intel C++ compiler squeezes every last bit of performance gain possible.


问:
Algorithms for pairing a rating system to an assignment queue
Attempting to research how to allow a group of people to effectively rank a set of objects (each group member will have contributed one object to the group), and then assign each member an object that's not their own based on:

Their ratings of the objects,

Their objects rating, and

The object remaining to be assigned.

Idea is to attempt to assign objects to people based on the groups rating of their contribution to the group relative to other member's contribution, the the personal preferences expressed via the ratings.

Any suggestions for:

Further research,

Refining the statement of the problem/solution, or

A solution.

答:
It depends a lot on the type of objects and persons in your sample. There may be several ways to achieve what you are trying to but I am listing an approach I have myself used in the past and hence am familiar with in quite a lot of detail. Other users may mention innovative new techniques.

I will refer to the activity of choosing an item as "buying" but it can refer to anything --voting, hating etc. This approach is only valid for objects that associate similarly with the buyer's (or chooser's, user's etc.) psychology. In such a case a preference/ratings matrix can be a very simple and crude way to solve the problem. Here is how such an approach works:

Step 1: Data Gathering

You would ask people to contribute objects they liked with a scaled rating (say on a scale of 10).

In the "analysis" or "taste discovery" phase you would suggest them items that they haven't rated and ask them to rate them.

Furthermore, you would ask them to group/tag the items into pre-defined categories.

Step 2: Analyze Correlation and R-Squared of buying tendencies

An example object-person ratings matrix may look like:

           Object 1    Object 2    Object 3  .  .  . Object N
Person 1      6           4           4                10
Person 2      4           2           1                 8
Person 3      8           9          10                 1
.
.
.
Person N      3           4           9                 2
```

You will then have to run a regression on this matrix to determine correlations and R-Squared between object-object pairs, person-object pairs, and person-person pairs. Repeat this analysis with the category-object matrix and then finally the category-person matrix.

Step 3: Interpret

If you can show that people who like A, B, and C also like D with a high probability (measured relative to other probabilities) then you can assume that another person who likes A, B, and C will also like D with a high probability. In some cases you can also measure likeliness coefficients --probability that objects will be liked/disliked given that another object is liked/disliked.

In cases where you cannot establish enough correlation between individual objects it may be possible to group/divide objects into hierarchies or genres (science fiction movies, Asian cuisine, denim outfits, swiss watches etc.) and then get correlation stats between those higher groupings. You can continue to hierarchise objects into broader or narrower groupings until you get meaningful correlations out. That is why we also collected category information above.

In many other cases, where no meaningful correlations exist, you will have to rely on network effects. For example, a person A may tend to follow person B's choices --regardless of the objects in question. You do not need to know if A is person B's friend/follower because the data you have collected will predict this pattern (if it exists) anyway.

Pitfalls

Small sample size (of either users or objects). See also, law of large numbers.

Misinterpreting correlation as future prediction indicator --use both R-Squared and correlation to calculate probabilities.

Misclassifying the problem --sort of obvious. Here I have assumed that objects associate similarly with buyer's psychology --if that is not the case, this approach may not work.

Body:
It depends a lot on the type of objects and persons in your sample. There may be several ways to achieve what you are trying to but I am listing an approach I have myself used in the past and hence am familiar with in quite a lot of detail. Other users may mention innovative new techniques.

I will refer to the activity of choosing an item as "buying" but it can refer to anything --voting, hating etc. This approach is only valid for objects that associate similarly with the buyer's (or chooser's, user's etc.) psychology. In such a case a preference/ratings matrix can be a very simple and crude way to solve the problem. Here is how such an approach works:

Step 1: Data Gathering

You would ask people to contribute objects they liked with a scaled rating (say on a scale of 10).

In the "analysis" or "taste discovery" phase you would suggest them items that they haven't rated and ask them to rate them.

Furthermore, you would ask them to group/tag the items into pre-defined categories.

Step 2: Analyze Correlation and R-Squared of buying tendencies

An example object-person ratings matrix may look like:

           Object 1    Object 2    Object 3  .  .  . Object N
Person 1      6           4           4                10
Person 2      4           2           1                 8
Person 3      8           9          10                 1
.
.
.
Person N      3           4           9                 2

You will then have to run a regression on this matrix to determine correlations and R-Squared between object-object pairs, person-object pairs, and person-person pairs. Repeat this analysis with the category-object matrix and then finally the category-person matrix.

Step 3: Interpret

If you can show that people who like A, B, and C also like D with a high probability (measured relative to other probabilities) then you can assume that another person who likes A, B, and C will also like D with a high probability. In some cases you can also measure likeliness coefficients --probability that objects will be liked/disliked given that another object is liked/disliked.

In cases where you cannot establish enough correlation between individual objects it may be possible to group/divide objects into hierarchies or genres (science fiction movies, Asian cuisine, denim outfits, swiss watches etc.) and then get correlation stats between those higher groupings. You can continue to hierarchise objects into broader or narrower groupings until you get meaningful correlations out. That is why we also collected category information above.

In many other cases, where no meaningful correlations exist, you will have to rely on network effects. For example, a person A may tend to follow person B's choices --regardless of the objects in question. You do not need to know if A is person B's friend/follower because the data you have collected will predict this pattern (if it exists) anyway.

Pitfalls

Small sample size (of either users or objects). See also, law of large numbers.

Misinterpreting correlation as future prediction indicator --use both R-Squared and correlation to calculate probabilities.

Misclassifying the problem --sort of obvious. Here I have assumed that objects associate similarly with buyer's psychology --if that is not the case, this approach may not work.


答:
We tried this at work a while back.  Most of our codebase is in Delphi, but we've got some highly computationally-intensive functionality that someone thought would be a good idea to do in a C++ DLL way back when.  And one of my coworkers had heard great things about the Intel compiler, so he decided to try it out.  We rebuilt the DLL in the Intel compiler and ran some speed tests, and the results surprised him so much that he figured he must be doing something wrong.

The DLL has to calculate some very difficult problems with combinatorics and topology components, which are technically in the NP-hard difficulty class if we did them "right", but we use various heuristics to avoid NP performance.  Even so, there's a lot of number crunching going on.  And for the tests we ran, the difference between the VS compiler and the Intel compiler was either within epsilon, or the Intel compiler was noticeably slower, generally by somewhere in the neighborhood of 20%.  And it stayed like that no matter what changes he made to the compile settings to try to get the Intel compiler to produce faster code.  So we ended up not switching to it.

This is only one real-world example, of course. Your mileage may vary.

Title: Are Intel compilers really better than the Microsoft ones?

Body:
Years ago, I was surprised when I discovered that Intel sells Visual Studio compatible compilers. I tried it in particular for C/C++ as well as fantastic diagnostic tools. But the code was simply not that computationally intensive to notice the difference. The only impression was: did Intel really do it for me just now, wow, amazing tools with nanoseconds resolution, unbelievable. But the trial ended and the team never seriously considered a purchase.

From your experience, if license cost does not matter, which vendor is the winner?

It is not a broad or vague question or attemt to spark a holy war. This sort of question is about two very visible tools. Nobody likes when tools have any mysteries or surprises. And choices between best and best are always the pain. I also understand the grass is always greener argument. I want to hear all "what ifs" stories.

What if Intel just locally optimizes it for the chip stepping of the month, and not every hardware target will actually work as well as Microsoft compiled? What if AMD hardware is the target and everything will slow down for no reason? Or on the other hand, what if Intel's hardware has so many unnoticable opportunities, that Microsoft compiler writers are too slow to adopt and never implement it in the compiler? What if both are the same exactly, actually a single codebase just wrapped into two different boxes and licensed to both vendors by some third-party shop?

And so on. But someone knows some answers.


答:
The simple answer to your question is yes as other folks have indicated.

A more complete but more complex answer to your question is to address:

"Management acknowledge this, but budget restraints limit our ability to recruit additional members to the team"

Management saying "yes we acknowledge that, we recognize that" is just "words" to make you feel better.  They don't consider it critical to the organization's success, or they would really support actually getting someone!

Other things to watch out for (since there's a lot of psychology in this) is when management tells you bad news, but mixes in some kinda joke, maybe mentioning the issue directly, maybe not, but which basically makes it impossible to question it (its a subtle and clever technique).  Another one to watch for is a 3 hour meeting where you are presented with the the plan and at 2 hours 55 minutes in are asked your opinions.

Be leery of management that "says" the right thing as opposed to management that "does" the right thing.


问:
An alternative to multiple inheritance when creating an abstraction layer?
In my project I am creating an abstraction layer for some APIs. The purpose of the layer is to make multi-platform easier, and also to simplify the APIs to the feature set that I need while also providing some functionality, the implementation of which will be unique to each platform.

At the moment, I have implemented it by defining and abstract class, which has methods which creates objects that implement interfaces.
The abstract class and these interfaces define the capabilities of my abstraction layer.

The implementation of these in my layer should of course be arbitrary from the POV view of my application, but I have done it, for my first API, by creating chains of subclasses which add more specific functionality as the features of the APIs they expose become less generic.

An example would probably demonstrate this better:

```<code>//The interface as seen by the application

interface IGenericResource
{
    byte[] GetSomeData();
}

interface ISpecificResourceOne : IGenericResource
{
    int SomePropertyOfResourceOne {get;}
}

interface ISpecificResourceTwo : IGenericResource
{
    string SomePropertyOfResourceTwo {get;}
}

public abstract class MyLayer
{
    ISpecificResourceOne    CreateResourceOne();
    ISpecificResourceTwo    CreateResourceTwo();

    void UseResourceOne(ISpecificResourceOne one);
    void UseResourceTwo(ISpecificResourceTwo two);
}

//The layer as created in my library

public class LowLevelResource : IGenericResource
{
    byte[] GetSomeData()
    {}
}

public class ResourceOne : LowLevelResource, ISpecificResourceOne
{
    int SomePropertyOfResourceOne {get{}}
}

public class ResourceTwo : ResourceOne, ISpecificResourceTwo
{
    string SomePropertyOfResourceTwo {get {}}
}

public partial class Implementation : MyLayer
{
    override UseResourceOne(ISpecificResourceOne one)
    {
        DoStuff((ResourceOne)one);
    }
}
</code>```

As can be seen, I am essentially trying to have two inheritance chains on the same object, but of course I can't do this so I simulate the second version with interfaces.

The thing is though, I don't like using interfaces for this; it seems wrong, in my mind an interface defines a contract, any class that implements that interface should be able to be used where that interface is used but here that is clearly not the case because the interfaces are being used to allow an object from the layer to masquerade as something else, without the application needing to have access to its definition.

What technique would allow me to define a comprehensive, intuitive collection of objects for an abstraction layer, while their implementation remains independent?

(Language is C#)

答:
Without knowing more I would focus on... Not doing that. Chains of subclasses is very rarely the answer, and I would submit never the answer for API implementation of the interface.

The problem is that the API isn't implementing the interface, it's already done. You're creating a least common interface from the different libraries. The focus then should be (if I understand the problem correctly) making your own API, with your own implementation agnostic data types and an adapter layer to the platform implementations (not an abstraction layer from the implementations).


问:
What are best practices when switching between projects/coming back to projects frequently?
The nature of my job is that I have to switch back and forth between projects every few weeks. I find that one of the biggest impediments to my productivity is the ramp-up time to getting all the relevant pieces of code "back in my head" again after not seeing it for a period. This happens to a smaller and larger extent for briefer breaks / longer breaks.

Obviously, good design, documentation, commenting, and physical structure all help with this (not to mention switching between projects as infrequently as possible). But I'm wondering if there are practices/tools that I may be missing out on. What are your specific practices for improving on this?

答:
I switch among different projects (both technical and non-technical) frequently as well.  Organization or "ease of retrieval" has been key for me.  Before leaving a project, I make sure that I put things in order so that it's easy for me to get the context back in my head.  For me, this means putting all relevant things (bookmarks, files, docs, emails, etc) or links to them in one folder so that I don't have to hunt for sources of info.

One thing that I've started to do recently is use one virtual machine for each large project.  When I need to switch to another project, I keep all the relevant apps open and then suspend the virtual machine.  So, when I need to switch back to the project, I can start the VM up and it will present me with all of the information already on the screen.


问:
Ongoing confusion about ivars and properties in objective C
After almost 8 months being in ios programming, I am again confused about the right approach. Maybe it is not the language but some OOP principle I am confused about. I don't know..

I was trying C# a few years back. There were fields (private variables, private data in an object), there were getters and setters (methods which exposed something to the world), and properties which was THE exposed thing. I liked the elegance of the solution, for example
there could be a class that would have a property called DailyRevenue...a float...but there was no private variable called dailyRevenue, there was only a field - an array of single transaction revenues... and the getter for DailyRevenue property calculated the revenue transparently.
If somehow the internals of daily revenue calculation would change, it would not affect somebody who consumed my DailyRevenue property in any way, since he would be shielded from getter implementation.

I understood that sometimes there was, and sometimes there wasn't a 1-1 relationship between fields and properties. Depending on the requirements. It seemed ok in my opinion. And that properties are THE way to access the data in object.

I know the difference betweeen private, protected, and public keyword.

Now lets get to Objective-C.

On what factor should I base my decision about making something only an ivar or making it as a property? Is the mental model the same as I describe above? I know that ivars are "protected" by default, not "private" as in C#.. But thats ok I think, no big deal for my present level of understanding the whole iOS development. The point is ivars are not accessible from outside (given I don't make them public.. but I won't).

The thing that clouds my clear understanding is that I can have IBOutlets from ivars. Why am I seeing internal object data in the UI? *Why is it ok?* On the other hand, if I make an IBOutlet from property, and I do not make it readonly, anybody can change it. Is this ok too?

Let's say I have a ParseManager object. This object would use a built in Foundation framework class called NSXMLParser. Obviously my ParseManager will utilize this NSXMLParser's capabilities but will also do some additional work. Now my question is, who should initialize this NSXMLParser object and in which way should I make a reference to it from the ParseManager object, when there is a need to parse something.

A) the ParseManager

-1) in its default init method (possible here ivar  - or - ivar+ppty)

-2) with lazyloading in getter (required a ppty here)

B) Some other object - who will pass a reference to NSXMLParser object to the ParseManager object.

-1) in some custom initializer (initWithParser:(NSXMLPArser *)parser) when creating the ParseManager object..

A1 - the problem is, we create a parser and waste memory while it is not yet needed. However, we can be sure that all methods that are part of ParserManager object, can use the ivar safely, since it exists.
A2 - the problem is, the NSXMLParser is exposed to outside world, although it could be read-only. Would we want a parser to be exposed in some scenario?
B1 - this could maybe be useful when we would want to use more types of parsers.. I don't know...

I understand that architectural requirements and language is not the same. But clearly the two are in relation.

How to get out of that mess of my?

Please bear with me, I wasn't able to come up with a single ultimate question. And secondly, it's better to not scare me with some superadvanced newspeak that talks about some crazy internals (what the compiler does) and edge cases.

答:
First, I think you're asking many questions, not one.

And half of the answers of these questions is the ever correct "It depends".

In general, exposing object ivars directly is discouraged if you're aiming for looser coupling (obviously). Although I think when it comes to IBOutlets it is an acceptable practice, since after all the Interface Builder is tasked with the creation of the object.

On the other hand, a readwrite property for an NSInteger makes little sense, unless you're doing something very funky, and you can easily use an ivar instead.

Once upon a time, in pre-ARC ages, there were some people, who advocated always using properties for objects, since then you don't need to care about retain/release. However now that ARC is widely used, this makes almost no difference and it is mostly a cosmetical thing.

A final piece of advice: aim for consistency project-wide.

EDIT: I'm not the greatest fan imaginable of Design Patterns, but it seems that most of your questions would find the best answer in this book.


答:
Two things have been key for me: consistency and specification.

Consistency is key for code. I don't need to remember where everything is and how everything interacts if I can extrapolate what I would've done. If it is a project with others that becomes more troublesome, but code standards help quite a bit. Knowing what something is by looking at it and making a few safe assumptions decreases the on-boarding time a bit.

Specification is more helpful for design. At least for me, I find that I tend to forget some of the nuances of product design after a break. Or when I return, it is because of this awesome idea that promptly feature creeps into the project. If your project does not have good requirements (either in a waterfall-y spec or a product backlog) you have to basically re-invent these each time you come back to the project. Almost all of the best practices for software development are still best practices when it is a personal project; don't skimp on them.

Title: What are best practices when switching between projects/coming back to projects frequently?

Body:
The nature of my job is that I have to switch back and forth between projects every few weeks. I find that one of the biggest impediments to my productivity is the ramp-up time to getting all the relevant pieces of code "back in my head" again after not seeing it for a period. This happens to a smaller and larger extent for briefer breaks / longer breaks.

Obviously, good design, documentation, commenting, and physical structure all help with this (not to mention switching between projects as infrequently as possible). But I'm wondering if there are practices/tools that I may be missing out on. What are your specific practices for improving on this?


问:
What are the warning signs of impending doom to watch out for on a project?
Having worked on a failed project is one of the few things that most programmers have in common, regardless of language used, industry or experience.

These projects can be great learning experiences, soul-crushing disasters (or both!), and can occur for a multitude of reasons:

upper management change of heart

under-skilled / under-resourced team

emergence of superior competitor during dev cycle

over/under management

Once you've worked on a couple of such projects, is it possible to recognise at an early stage exactly when a project is doomed to fail?

For me, a big sign is having a hard & fast external deadline combined with feature creep. I've seen projects which were well planned out and proceeding right on schedule go horribly off the rails once the late feature requests started to roll in and get added to the final "deliverable". The proposers of these requests earned the nickname of Columbo, due to rarely leaving the room without asking for "just one more thing".

What are the warning signs you look out for that set off the alarm bells of impending doom in your head?

答:
Developers Running Wild on the Range

This has happened when you realise that other developers (or, unfortunately, you) have developed a component that varies significantly from the design, and that this isn't picked up up until well into system/UAT testing.  I'm not talking bugs; I'm talking about significant system components are missing features or have unasked for functionality and  are never going to pass UAT without significant rework.  This issue indicates that:

Your quality system is broken; why didn't the developer concerned pick up on the issue in the design/implementation phase.  Wasn't the code per reviewed/inspected? Why did the unit and integration tests not pick up on this?  If you don't have some sort of consistent unit/integration testing in place, you're screwed.

Your project manager/technical lead aren't in control of their development team. If they can't get the developers to deliver what is required, they will never be able to deliver a complete solution.


问:
Is Entity Framework ready for production?
I'm looking into Entity Framework for a new project that I'm going to be taking on and as part of my research into it I'm asking some industry professionals if it's stable and ready for 'real world' implementation.

In the running is:

EF

NHibernate

DevExpress XPO

I already have a great deal of experience with XPO, but I'm not particularly happy with it.

答: I would think so. I'm using EF4 code-first (CTP) for developing a multi-tenant web application.</p>


问:
Creating Objects
I have a general coding standard question. Is it bad practice to initialize and create an object in multiple methods depending on the outcome of a users choice. So for example if the user quits a poker game, create the poker hand with the cards the user has received, even if < 5, and if the user played till the end create object to show completed hand to show outcome of the game. The key is that the object will only be created once in actuality, there are just different paths and parameters is will receive depending on if the user folded, or played on to the showdown.</p>

答:
You are correct, trying to eliminate unnecessary lifecycle control from your model. You spotted entity in question and scrutinized it's right to have independent lifecycle. So you nearly answered your own question and just need a confirmation about it being a good practice. It is good improvement of your model. Yes.

If poker player has hand, does it mean the hand is an object ?

Lets check it:
Can hand exist without player ? Can player have more than one hand ? Can player have series of hands over time, but no more than one hand at a time ? Can non-existence of hand be treated as an "empty hand" which still allows for hand object to exist ?

If I understand game correctly, the hand is an attribute, not an object. Player is the only entity, which has a lifecycle. Hand is a slot with fixed capacity, an attribute, so no individual creation or destruction is needed for hand, when player is an object.

Treat object lifecycle as meaningful part of model. Object should be able to express existence of particular thing X, as well as null in place of the object expresses non-existence of X

Object must be created no earlier and no later than particular event/transition in your model requires it. Object must be destroyed exactly with the same considerations. If model contains 2 related classes, where objects have nested lifecycles, nest the classes, so one should be a contaner of other. If lifecycles of this 2 classes match exactly, then eliminate duplicates, demote one of classes to be an attribute.

Title: Creating Objects


问:
Application / Code reviews for lone programmers?
Are there any services that 'for a reasonable price' will give and provide good and technical advice on applications. On a lot of projects, I'm usually the only developer, and sometimes, I think some of my work needs to be improved for efficiency, better MVC interactions, etc. It would be great if there was a professional service that actually can and will do such reviews</p>

答: Find someone else who's an indie and needs their code reviewing, and buddy up with them. Sitting next to each other in an office or pub is best, but you can use online paste bin services and videoconferencing if there's no one in your town.</p>


答:
A few things that help:

Maximally optimize your code for readability and clarity.

Leave pointers and hints for yourself in the code, in the form of comments.

Follow KISS and DRY.

Be consistent, within each project and across projects.

Be religious about refactoring.

Document everything; consider your future self a different person with no way of asking your present self any questions.

Avoid "clever" code that breaks your IDE / editor.

Use source control, with commit messages that tell you where exactly you left things; tag versions that you deem shippable, and aim for short periods between shippable versions.

If you get to pick the programming language, choose one that can help you do things right.

This one's a matter of personal taste, but it works well for me, so I'll recommend it anyway: Keep a simple, concise text document containing upcoming tasks, and update it each time you finish a task. Also use this document for design-level notes that don't fit in code comments. Basically, this text document should contain your entire design, only in condensed form (enough information for you to make sense of, but short enough to get you back in the saddle within 10 minutes). A bug tracker works too, but the text document has a number of advantages: it forces you to cut the fluff and focus on the relevant stuff, and it can be committed to source control alongside the real code, which means it is naturally tied to SCM versions.


答:
I would say no. It is a sign that your class is too complex, or is trying to do too much. It may be that you want to split it into multiple classes, or that you want to rethink your abstractions completely.

One way would be to turn each "interface" into a class of its own, using the main class. You could export the "interface classes", but keep the main class more hidden. Not sure if it would buy you anything, though.

Title: Is it a good programming practice to have a class with several .h files?

Body:
I suppose the class have several different interfaces. Some it shows to some class, some it shows to other classes.

Are there any good reason for that?

One thing I can think of is with one .h per class, interface would either be public or private.

What about if I want some interface to be available to some friends' class and some interface to be truly public?

Sample:

```<code>@interface listNewController:BadgerStandardViewViewController <UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,NSFetchedResultsControllerDelegate,UIScrollViewDelegate,UIGestureRecognizerDelegate> {
}

@property (nonatomic) IBOutlet NSFetchedResultsController *FetchController;
@property (nonatomic) IBOutlet UITextField *searchBar1;
@property (nonatomic) IBOutlet UITableView *tableViewA;
+ (listNewController *) singleton; //For Easier Access
-(void)collapseAll;
-(void)TitleViewClicked:(TitleView *) theTitleView;
-(NSUInteger) countOfEachSection:(NSInteger)section;
@end
</code>```

Many of those public properties and function are only ever called by just one other classes. I wonder why I need to make them available to many classes.

It's in Objective-c by the way

What do you mean? Interface is interface. In C++ you can declare some classes as "friends". In Objective-c you cannot I think. Basically I want to emulate that. My friends can access some members that's not available too publicly,.


答:
I do something similar to what RonE does.

Having a project easy to read, with a good design helps, but before leaving a project, make sure all the context and information you have in your head it's written or stored somewhere. For instance, notes about the third party library functions you were using if it was a new one you never used before. I always write notes about the things I learn or think, in my own words.

Also, what I find most important to write in a file is if you write TODO comments in your code, copy the last one you were working on, and paste it in a new text file and call it TODO. Write in it context information about where the TODO tag belong and write what you had in mind or what you think you would like to know about that task.


问:
Class design, One class in two sources
Is it possible define methods from the same class in different "CPP" files?

I have header file "myClass.h" with:

```<code>class myClass
{
public:
    // methods for counting
    ...
    // methods for other
    ...
};
</code>```

I would like to define "methods for counting" in one CPP and "methods for other" in other CPP. For clarity.

Both groups of methods sometime use the same attributes.

Is it possible? Thanks :).

答: Yes, methods can be defined in any TU you care to define them in and do not need to be grouped together. However, this smells like you are violating SRP.</p>

Title: Class design, One class in two sources


答:
Yes, but with some caveats:

It's fully supported by Microsoft, and has a growing community--but being newer than its closest competetor, nHibernate, it still doesn't have quite as mature a community.

Along with having a less mature community, there will be times where a feature is available with EF4 but barely documented; or EF4 will throw exceptions which Google can't help you with.

It is full-featured when used as Microsoft intends, but in my experience it can be quite difficult to retrofit into an existing system.  Ideally you'll use it in a greenfield scenario with a 100% Microsoft stack.  It's certainly flexible enough to intermingle with other systems, but doing so increases the difficulty substantially.

However, to reiterate the main point, it is complete and stable enough for production use.

One key thing to point out, which seems obvious but is often overlooked until it causes pain, is that an ORM works to map from the relational paradigm to the OO-paradigm.  If either of these tiers doesn't follow the rules of its respective paradigm then you'll feel extra hurt.

This can go both ways--if you're well versed in the relational/set-based paradigm of SQL and OOP then the ORM will let the two intermingle like butter.  If your database looks like it wants to be OO, and your OO-code looks like it wants to be record-based, then YMMV.

Title: Is Entity Framework ready for production?

Body:
I'm looking into Entity Framework for a new project that I'm going to be taking on and as part of my research into it I'm asking some industry professionals if it's stable and ready for 'real world' implementation.

In the running is:

EF

NHibernate

DevExpress XPO

I already have a great deal of experience with XPO, but I'm not particularly happy with it.


问:
What are best practices to read high level undocumented and uncommented code?
There are some opensource projects, that have classes and classes without any significant explanation about what the class does and or why is that class needed. For example, classes in the CppEditor plugin for QtCreator. What are the best practices to read undocumented code? Don't read it, is not an option :)</p>

答: Go through it a method/function at a time, and add your own documentation. Keep revising the documentation as you learn more about how it all works.</p>


答:
Really stop and think before you do this as your question is one of the red flags for needing to break up a class into multiple classes.

Also I don't really see how much 'clarity' can be gained by placing methods in two separate files.  In most IDEs it is a simple matter to look through the methods list while in a cpp file and find the appropriate method alphabetically.

Title: Class design, One class in two sources

Body:
Is it possible define methods from the same class in different "CPP" files?

I have header file "myClass.h" with:

```<code>class myClass
{
public:
    // methods for counting
    ...
    // methods for other
    ...
};
</code>```

I would like to define "methods for counting" in one CPP and "methods for other" in other CPP. For clarity.

Both groups of methods sometime use the same attributes.

Is it possible? Thanks :).


答:
I suggest you gather data from all possible sources.

Use the code and begin documenting it yourself. Naturally you'll need to read the code to figure out how it works, but also figuring out what the code was intended to be used for and actually using it that way will help you understand. How well you can read code entirely depends on how comfortable you are with the language (or type of language) and the algorithms and patterns being used.

Read the documentation that surrounds the code. Does the code that calls this code have documentation? Does the code that is called by this code have documentation? Collect as many nuggets of information you can find.
This may be obvious, but look for documentation that is not attached to the code, whether it's an official manual, a FAQ list, or blog posts.

If the code still eludes you, or you have some questions, ask the people who wrote it. Go through the commit log and figure out who wrote the code and see if they are still accessible. Then either email them or the project's mailing list asking if someone could explain what the code does (especially if it's not obvious) and how it was intended to be used. Ask your specific questions and explain your desire to write the documentation for it.

Title: What are best practices to read high level undocumented and uncommented code?

Body: There are some opensource projects, that have classes and classes without any significant explanation about what the class does and or why is that class needed. For example, classes in the CppEditor plugin for QtCreator. What are the best practices to read undocumented code? Don't read it, is not an option :)</p>


问:
Any tips on getting hired as a software project manager straight out of college?
I graduated with a BS in compsci last September, and I've been trying (unsuccessfully) to find a job as a project manager ever since.

I fell in love with software engineering (the formal practice behind it all, not just coding) in school, and I've dedicated the last 3-4 years of my life to learning everything I can about project management and gaining experience.  I've managed several projects (with teams around 12 people) while in school, and I worked with my university's software engineering research lab.  My résumé is also decent - I worked as a programmer before I went to school (I'm 27 now), and I did Google Summer of Code for 3 summers.  I also have general "people management" experience via working as the photo editor for my university's newspaper for 2 years.

My first problem with the job hunt is not getting enough interviews.  I use careers.stackoverflow.com, which is awesome because I usually get contacted by non-HR people who know what they're talking about, but there's just not enough companies using it for me to get interviews on a regular basis.  I've also tried sites like monster.com, and in a fit of desperation, I sent out no less than 60 applications to project management positions.  I've gotten 3 automated rejection letters and that's it.  At least careers.stackoverflow gets me a phone interview with 8/10 places I apply to.

But the main (and extremely frustrating) problem is the matter of experience.  I've successfully managed projects from start to finish (in my software engineering classes we had real customers come in with a real software need and we built it for them), but I've never had to deal with budgets and money (I know this is why HR people immediately turn me away).  Most of these positions require 5+ years PM experience, and I've seen absurd things like 12+ years required.

Interviews are also maddening.  I've had so many places who absolutely loved me and I made it to the final round of interviews, and I left thinking things went extremely well and they'd consider me.  However, when I check in with them a week later, they tell me "We really liked you and your qualifications are excellent, but we're hoping to find someone with more experience."  The bad interviews I can understand - like the PM position that would have had me managing developers both locally and overseas - I had 3 interviews with them and the ENTIRE interview process was them asking me CS brainteasers and having me waste time on things like writing quicksort on paper or writing binary search trees.  Even when I tried steering the discussion towards more relevant PM stuff, they gave me some vague generic replies and went back to the "We want to be Google/MS" crap.

But when I have a GOOD interview, they say my "qualifications are excellent" but they want "more experience"...that makes me want to tear my hair out.  What else can I DO?  While I'm aiming for technically-involved PM positions (not just crunching budget numbers), I really don't want a straight development job because I like creating software from the very high-level vs. spending a lot of time debugging memory leaks.  In fact, I can't even GET development positions that I'm qualified for because I make the mistake of telling them that my future career goals are as PM (which usually results in them saying something like "Well we already have PMs and this position isn't really set up to get you there." - which I take to mean "No, that's my job, stay away.")

My apologies on the long rant, but I'm seriously hellbent on getting hired as a PM since it's both my career goal and the passion that keeps me awake at night.  Any suggestions on what the heck else I can do? I'm currently writing a blog where I talk about my philosophies about software engineering, and I'm writing up specs for an iOS app which I will design, code, and show employers, but this takes an awful lot of time that I don't have.

答: Why don't you apply to Microsoft? They hire PM's right out of college. At most other companies though, you're going to have a very hard time getting in. It's tough getting your first IT job period, never mind slingshotting yourself 5 years ahead into a PM role. In interviews, when they ask where you want to be in 5 years, you say a PM - acknowledging that it's a goal it may take 5 years to achieve. Why are you trying to cut to the head of the line? While it's admirable and I commend you for not selling yourself short, once you're out in the working world for a while you'll realize that you've probably bitten off more than you can chew.</p>


答:
Self managed teams are not that out of the ordinary.  They usually require clear performance metrics to create internally generated accountability.  Your organization could have this, but if you can't generate additional headcount based on cost savings, then perhaps this won't work.  The other challenge is your new boss doesn't sound like someone who would know how to reward talent.

For better or worse, it sounds like you need a player coach.  Someone who can both manage the team, and perform in it.  In a group of 4, this is certainly feasible.  In a group of 8 or 10, it wouldn't be.  The challenge is identifying who should be this player coach.  The default is to make it your best programmer, but do you necessarily want to tie them up with admin?  There's no hard and fast answer, other than to say high performing organizations find ways to not force all their best technicians into becoming managers.


问:
Javascript Form Validation
When validating a JavaScript form, would it be better to process each input field individually, or, where possible check collectively?

e.g.

```<code>validate()
{
     noblanks()
     fieldOne()
     fieldTwo()
}
</code>```

or

```<code>validate()
{
     fieldOne()
     fieldTwo()
</code>```

答:
I'll suggest a third alternative: Validate the fields in a logical order specific to the form. Sometimes that means validate a form one field at a time. Other times it might be more logical to group fields together and validate by each type of validation or some other criteria.

Lets say you validate each field one at a time. This means that if you find that one field is blank, then you can simply skip all the other validations on that field since they will most likely fail. If you instead checked for all blank field first, then you will need extra logic to make sure that you do not do any other validations on any of the fields that were left blank.

For example, if you require the user to enter their password twice when creating an account, then there's no reason to check if the passwords are the same if the first password field was empty. In this case, both password fields are treated as one logical unit for validation purposes.

Another thing to consider is if a form has both client-side validation and asynchronous server-side validation. Then it makes sense to do all (or most) of the client-side validation first to reduce round-trips to the server.

Title: Javascript Form Validation


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

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

答:
I don't know about "have to", but I think they answer is yes, we're supposed to handle the tax rates ourselves.

There's more information here:

You are solely responsible for specifying your own tax rates and for
  updating them if tax rates for your location change. Google won’t
  apply taxes to your orders if you don’t provide any tax information in
  the Merchant Center or via the Checkout API, so be sure to keep this
  information up-to-date. For tax assistance, please consult with a
  qualified tax professional.

That said, one of the options is to automatically use data from Tax Data Systems, and automatically apply tax rates based on zip code1 - so there shouldn't be anything for developers to upkeep.

1Not postal code.  So it sounds like Tax Data Systems is only for the US.

( However, entering tax data is not required on the Android market. I still have it all empty. )