问:
What is the point to namespaces in branches in git?
So I mainly use Mercurial for my projects and I decided to sit down and learn all Git's shenanigans to discover if I'm in the right side (at least for me).

I'm learning that git uses namespaces for branches and I would like to know (in your experience) what is the point of namespaces?. In Mercurial I could just set the convention of naming branches like so:

```<code><branch name> //for "origin" branches
<username>/<branch name> //for user branches
</code>```

I imagine that there is more to it than just the name (aside from avoiding naming conflicts), but what do I get out of this seemingly more complicated (not necessarily bad) model?

答:
Git doesn't "use" namespaces in the sense like they are required.  It offers the completely optional ability for a user to use namespaces if they want them.  You can use the exact same naming convention as you did in mercurial if you want, and I imagine that's what the vast majority of people do.

What namespaces buy you is the ability to combine multiple repositories into one, but be able to only show branches from the one virtual repository.  Within the namespace, you can still name the branches using whatever method you prefer. Personally, I don't really see the benefit over just using multiple repositories, but obviously someone thought it might be useful sometimes.

Git has a ton of features, of which maybe 3-5% see daily usage by the typical developer.  The trick to getting along with git, is for those features you don't want/like/understand, don't worry about them.


问:
How do you pronounce the '...' operator
Now, in c++ '...' became a first class operator.
In speech, how do you pronounce it?

So far I've heard:

dot dot dot

triple dot

ellipsis

related: Is it OK to replace ... with ellipsis in writing?
e.g. "The ellipsis operator expands the pack"

EDIT (clarification): We are all aware that '...' as a punctuation mark is indeed called ellipsis. But in the context of C++ we don't pronounce the names of the punctuation mark. For example, the '&' operator, depends on the context is pronounced as 'and', 'bitwise and', 'address of', 'logical and' (when && is used), or 'reference'. It is rarely pronounced as 'ampersand'.

In speeches, I've a feeling that 'dot dot dot' is used more often. For example: http://channel9.msdn.com/Events/GoingNative/GoingNative-2012/Variadic-Templates-are-Funadic (an excellent presentation about variadic templates).

On the other hand, 'dot dot dot' is awkward hard to pronouce ('d' and 't' are both pronounce with the tongue).

Can we pronounce it 'unpack'?

答:
I pronounce it with a long e.

E-lip-seez

Merriam-Webster doesn't pronounce the e as a long E.  It's more like an i.

\i-ˈlip-səs, e-\

Also, I don't think you could go wrong either way when writing your statement "The ellipsis operator expands the pack".  Since the '...' is technically called an ellipsis, "The ellipsis operator expands the pack" is fine, but since '...' is also the representation of the operator, "The '...' operator expands the pack" would also be completely fine, in my opinion.

ContentLicense: CC BY-SA 3.0

Title: How do you pronounce the '...' operator


问:
Modular enterprise architecture using MVC and Orchard CMS
I'm making a large scale MVC application using Orchard. And I'm going to be separating my logic into modules. I'm also trying to heavily decouple the application for maximum extensibility and testability.

I have a rudimentary understanding of IoC, Repository Pattern, Unit of Work pattern and Service Layer pattern.

I've made myself a diagram. I'm wondering if it is correct and if there is anything I have missed regarding an extensible application.

Note that each module is a separate project.

Update

So I have many UI modules that use the db module, that's why they've been split up. There are other services the UI modules will use. The UI modules have been split up because they will be made over time, independent of each other.

答:
Correct in terms of what? Your question is vague so it is hard to answer. I think you may have some misconceptions about what Orchard is. Your diagram shows Orchard as as what seems to be a web server, and it looks like you plan to do all this architecting of your modules, separating ui from db, and using all the patterns you mentioned, etc on top of Orchard. But Orchard already provides all that, Orchard provides a method of data access, dependency injection, content management, versioning, Theming, uses asp.net MVC which is your flavor of MVC, etc. The point of it is that you can use Orchard's existing extensibility to build your application. People using Orchard have even discussed whether or not "framework" might be a better description for Orchard than "CMS", because of all the things it does, and the variety of apps that can be built with it.

There is already a pattern for how to build applications with Orchard, which is different from your diagram.  You are free to do your own type of db access, and customize everything, but if you find yourself building a new app from scratch with Orchard, and from the get-go circumventing all the patterns that Orchard provides, you may want to rethink things.

You should read or re-read the documentation at http://orchardproject.net. You will find that to build a site with Orchard you just need to make one or more modules, and a theme. The modules can be as granular as you want, and if you build things the way the Orchard docs suggest, and using existing modules (both core Orchard ones, and 3rd party ones from the gallery) as examples, your app will have a good separation of concerns. You will be able to takes pieces in and out, replacing them with different implementations without too much effect on the rest of the system, etc. If you just follow the docs to build a super simple module, you will have used pretty much all the patterns and architectural concepts you mentioned whether you are aware of it or not.

OwnerDisplayName: MrJD

OwnerDisplayName: Giscard Biamby


问:
Is there an opposite for the term "Backporting"?
As I understand, the term "Backporting" is used to describe a fix which is applied in a future version which is also ported to a previous version. Wikipedia definition is as follows:

Backporting is the action of taking a certain software modification (patch) and applying it to an older version of the software than it was initially created for. It forms part of the maintenance step in a software development process...

For example:

A problem is discovered and fixed in V2.0. The same fix is ported and applied to V1.5.

What is the term when this is done in the opposite direction?

The problem is discovered and fixed in V1.5. The same fix is ported and applied to V2.0.

Would the term "Backporting" still apply? Or is there a term such as "Forwardporting" (which amusingly sounds a lot like "Port Forwarding")?

答: It's the same as the opposite of a backslash.  Everyone wants to call it a forward slash, but really it's just a "slash."  The opposite of backporting is simply "porting."  </p>


问:
Do non-manager coders in their forties or older out there sometimes regret about not being managers?
And why do most programmers quit coding and become managers so early compared to other areas? You can work as a construction worker, a lawyer, researcher, writer, architect, movie director for decades if not your whole life, without quitting the favorite thing you are doing. And yet most programmers think being a manager, or better, a non-coding manager is a cool thing and the ultimate goal of the software career. It's so rare to see an ordinary coder in his 40s or 50s (or 60s!) in a typical software company. Why?

(And I am for being a coder for as long as you love doing it.)

答: I'm 40 now, I've been manager for two loooooooooong years, and I'm very glad to be back to coding again.</p>

ContentLicense: CC BY-SA 2.5


问:
Should I organize my folders by business domain or by technical domain?
For example, if I'm using some MVC-like architecture, which folder structure should I use:

```<code>domain1/
    controller
    model
    view
domain2/
    controller
    model
    view
</code>```

Or:

```<code>controllers/
    domain1
    domain2
models/
    domain1
    domain2
views/
    domain1
    domain2
</code>```

I deliberately left out file extensions to keep this question language-agnostic.

Personally, I'd prefer to separate by business domain (gut feeling), but I see that most/many frameworks separate by technical domain. Why whould I choose one over the other?

答:
From my personal experience with a web shop consisting of 300 000 lines of code, I would always go for organizing by business domain. This way, you can not only get a quick overview of all relevant classes when you work on one functional area, in Java you can also make use of the package visibility.

Some details for those who are interested:
When the project was started 5 years ago, the developers created the following package structure:

```<code>com
  example
    web
      struts
        action
        form
      shared
      functionality1
      functionality2
</code>```

Each shop function such as shopping cart, product search etc. consists of several actions, each with its own form class (structure mandated by the MVC framework). What we ended up with are over 200 classes in the action package, each one completely separated from their associated form class. What's worse is that actions don't implement too much logic, but call function-specific services which reside in yet another package.

I suggested and convinced the team that we should switch to organizing packages by business domain. The reasoning is simple: if you really want to see a list of all actions, you can simply open the type hierarchy view of any decent IDE. However, what the IDE cannot do is infer the business domain a class belongs to. Furthermore, that approach allows you to make only those classes public which are needed by several functionalities, keeping the rest on package visibility.

Body:
From my personal experience with a web shop consisting of 300 000 lines of code, I would always go for organizing by business domain. This way, you can not only get a quick overview of all relevant classes when you work on one functional area, in Java you can also make use of the package visibility.

Some details for those who are interested:
When the project was started 5 years ago, the developers created the following package structure:

com
  example
    web
      struts
        action
        form
      shared
      functionality1
      functionality2

Each shop function such as shopping cart, product search etc. consists of several actions, each with its own form class (structure mandated by the MVC framework). What we ended up with are over 200 classes in the action package, each one completely separated from their associated form class. What's worse is that actions don't implement too much logic, but call function-specific services which reside in yet another package.

I suggested and convinced the team that we should switch to organizing packages by business domain. The reasoning is simple: if you really want to see a list of all actions, you can simply open the type hierarchy view of any decent IDE. However, what the IDE cannot do is infer the business domain a class belongs to. Furthermore, that approach allows you to make only those classes public which are needed by several functionalities, keeping the rest on package visibility.


问:
How should I implement the repository pattern for complex object models?
Our data model has almost 200 classes that can be separated out into about a dozen functional areas. It would have been nice to use domains, but the separation isn't that clean and we can't change it.

We're redesigning our DAL to use Entity Framework and most of the recommendations that I've seen suggest using a Repository pattern. However, none of the samples really deal with complex object models. Some implementations that I've found suggest the use of a repository-per-entity. This seems ridiculous and un-maintainable for large, complex models.

Is it really necessary to create a UnitOfWork for each operation, and a Repository for each entity? I could end up with thousands of classes. I know this is unreasonable, but I've found very little guidance implementing Repository, Unit Of Work, and Entity Framework over complex models and realistic business applications.

答:
Maybe you should have a look at Domain-Driven Design. It recommends grouping your objects in Aggregates and creating repositories only for the Root entity of each Aggregate. It's a nice way to bring order to a big complex object model.

Your different functional areas could be Bounded Contexts. There are various techniques to deal with overlapping Bounded Contexts if the separation between them isn't clear.

OwnerDisplayName: Eric Falsken


答:
in the context of C++ we don't pronounce the names of the punctuation mark

I disagree with your premise. In my experience people refer to the meaning of the symbol when that's what they're talking about, but use the name when they need to refer to the symbol itself:

I see your problem: you're using bitwise AND instead of logical AND -- you need to use two ampersands for logical AND.

The trouble with ... in C and C++ is that it's not an ellipsis character. I'm sure it's meant to represent an ellipsis, and its meaning is similar to what an ellipsis represents in English, but I'd guess that most compilers would choke on a real ellipsis (…). That surely wasn't an issue in the old days, when ASCII and EBCDIC were all there was and ellipses could only be simulated with .... These days, though, you might cause some confusion if you said:

I see your problem: that function should take variadic arguments -- add an ellipsis to the declaration.

To be really precise in such a situation, you should say "dot dot dot." If you're just talking about existing code, though, it'd be fine to say elipsis:

You can see from the ellipsis that foo(int bar, ...) takes a variable number of arguments.

Can we pronounce it 'unpack'?

Only if you don't care about being understood, or if you plan to preface your comments with "I'm going to pronounce 'dot-dot-dot' as 'unpack.'"

Title: How do you pronounce the '...' operator

Body:
Now, in c++ '...' became a first class operator.
In speech, how do you pronounce it?

So far I've heard:

dot dot dot

triple dot

ellipsis

related: Is it OK to replace ... with ellipsis in writing?
e.g. "The ellipsis operator expands the pack"

EDIT (clarification): We are all aware that '...' as a punctuation mark is indeed called ellipsis. But in the context of C++ we don't pronounce the names of the punctuation mark. For example, the '&' operator, depends on the context is pronounced as 'and', 'bitwise and', 'address of', 'logical and' (when && is used), or 'reference'. It is rarely pronounced as 'ampersand'.

In speeches, I've a feeling that 'dot dot dot' is used more often. For example: http://channel9.msdn.com/Events/GoingNative/GoingNative-2012/Variadic-Templates-are-Funadic (an excellent presentation about variadic templates).

On the other hand, 'dot dot dot' is awkward hard to pronouce ('d' and 't' are both pronounce with the tongue).

Can we pronounce it 'unpack'?


答:
I think it's enlightening to ask, "what am I more likely to add on a regular basis, more domains or more technical divisions?"  Then whatever the answer is, put that at the top level.

In most cases your technical architecture will solidify faster than your domain.  That means you should organize by domain first, then by architectural component.  The reason is that when something in a domain changes, you may have to add or change multiple technical components in that domain, but hopefully that's localized and doesn't spill over much into other domains.

If you changed your GUI framework, then that means your changes will spill across the whole application, but then again, you rarely change your GUI framework, but you're always changing your domain logic.

Keep things together if they're likely to change at the same time.

Title: Should I organize my folders by business domain or by technical domain?

Body:
For example, if I'm using some MVC-like architecture, which folder structure should I use:

```<code>domain1/
    controller
    model
    view
domain2/
    controller
    model
    view
</code>```

Or:

```<code>controllers/
    domain1
    domain2
models/
    domain1
    domain2
views/
    domain1
    domain2
</code>```

I deliberately left out file extensions to keep this question language-agnostic.

Personally, I'd prefer to separate by business domain (gut feeling), but I see that most/many frameworks separate by technical domain. Why whould I choose one over the other?


答: I call it the variadic operator. If that's been misinterpreted or not understood, people have been far too polite about it.</p>

Title: How do you pronounce the '...' operator


问:
How should an API use http basic authentication
When an API requires that a client authenticates to it, i've seen two different scenarios used and I am wondering which case I should use for my situation.

Example 1. An API is offered by a company to allow third parties to authenticate with a token and secret using HTTP Basic.

Example 2. An API accepts a username and password via HTTP Basic to authenticate an end user.  Generally they get a token back for future requests.

My Setup: I will have an JSON API that I use as my backend for a mobile and web app.  It seems like good practice for both the mobile and web app to send along a token and secret so only these two apps can access the API blocking any other third party.

But the mobile and web app allow users to login and submit posts, view their data, etc.  So I would want them to login via HTTP Basic as well on each request.

Do I somehow use a combination of both these methods or only send the end user credentials (username and token) on each request?  If I only send the end user credentials, do I store them in a cookie on the client?

答:
HTTP basic authentication requires the username and password to be sent with every resource request. The username:password is passed in the "Authorization" request header base64 encoded string prefixed with "Basic ". If all of your http communication is encrypted (via ssl) the Authorization header's information shouldn't be able to be easily used by attackers since it's unlikely that they'll be able to get a hold of it.

SSL encrypted http with basic authentication should be enough.


答: Backporting in the opposite direction is just porting, but there's no reason to do that in the context you describe.

Title: Is there an opposite for the term "Backporting"?

Body:
As I understand, the term "Backporting" is used to describe a fix which is applied in a future version which is also ported to a previous version. Wikipedia definition is as follows:

Backporting is the action of taking a certain software modification (patch) and applying it to an older version of the software than it was initially created for. It forms part of the maintenance step in a software development process...

For example:

A problem is discovered and fixed in V2.0. The same fix is ported and applied to V1.5.

What is the term when this is done in the opposite direction?

The problem is discovered and fixed in V1.5. The same fix is ported and applied to V2.0.

Would the term "Backporting" still apply? Or is there a term such as "Forwardporting" (which amusingly sounds a lot like "Port Forwarding")?


答:
I think the term "backport" refers only to the action of bringing a feature of a new release of a program to an older  of the same program, for the benefits of  still using it.

As you don't develop new feature on old, closed, versions no "reverse" backporting exists (if you are, by definition, the version is not old).

What you're calling a "forwardport", fixing a problem both in an old and a new verion, is a mere bugfix or patch.


答:
I did one year of managing nearly two decades ago, and didn't like it.  I've been a programmer, or architect, or anything but a manager and still doing coding since then, with no cause for regret.  And the AARP just sent me an invitation to join based on my next birthday - I must be getting old!

I'm lucky - I work for a big company that has career tracks for senior technical staff who want to remain technical staff.

Title: Do non-manager coders in their forties or older out there sometimes regret about not being managers?

Body:
And why do most programmers quit coding and become managers so early compared to other areas? You can work as a construction worker, a lawyer, researcher, writer, architect, movie director for decades if not your whole life, without quitting the favorite thing you are doing. And yet most programmers think being a manager, or better, a non-coding manager is a cool thing and the ultimate goal of the software career. It's so rare to see an ordinary coder in his 40s or 50s (or 60s!) in a typical software company. Why?

(And I am for being a coder for as long as you love doing it.)


答:
I guess I would use the terms: future-proofing or, alternatively, forward compatibility:

From Wikipedia future-proof:

Future proof: The phrase future proofing describes the exclusive process of trying
  to anticipate future developments, so that action can be taken to
  minimize possible negative consequences, and to seize opportunities.

And forward-compatibility:

Forward compatibility or upward compatibility (sometimes confused with
  extensibility) is a compatibility concept for systems design, as e.g.
  backward compatibility. Forward compatibility aims at the ability of a
  design to gracefully accept input intended for later versions of
  itself.

Or both "future-proofing through forward-compatibility".

Oh the buzzwordry :)


问:
Why use other number bases when programming
My coworkers and I have been bending our minds to figuring out why anyone would go out of their way to program numbers in a base other than base 10.

I suggested that perhaps you could optimize longer equations by putting the variables in the correct base you are working with (for instance, if you have only sets of 5 of something with no remainders you could use base 5), but I'm not sure if that's true.

Any thoughts?

答:
As you probably know, computers are based on binary - this is base 2.

It is easy to convert between base 2 and 4, 8 and 16 (and similar multiples of 2), and keeping this translation in the source code can make working with numbers a lot easier for to reason about.

For low level languages such as Assembly and C, this can translate directly to processor operations (bit shifting for division and multiplication, for example), meaning that using these number bases ends up with much faster code.

Additionally, not all operations are numeric operations - there are bit maps where you do need to fiddle with the bits directly - using a base 2 or one of the multiples of it to do so makes the operations much easier.

If you wish to learn more, I recommend reading Code by Charles Petzold.


答:
Outside of highly specialized programs, it's pretty rare to use bases other than 10, 16 or 2.

Base 16 (hexadecimal) is useful simply because the full range of a byte (0-255) can be represented in two digits (0x00-0xFF), which can make working with raw hex-dumps or binary data a lot easier.  Hexadecimal is also useful when using bit masks with bitwise operators, because the two-digits to a byte correspondence helps with readability.

More rarely, base 2 (binary) can also be used with bitwise operations, but many programming languages don't support base-2 literals, and anyway hexadecimal is much more concise and readable.

Base-8 (octal) is also sometimes used because of UNIX file permissions.  Other than that, it's pretty rare to use bases other than 10 outside of highly specialized mathematical contexts.

Title: Why use other number bases when programming

Body:
My coworkers and I have been bending our minds to figuring out why anyone would go out of their way to program numbers in a base other than base 10.

I suggested that perhaps you could optimize longer equations by putting the variables in the correct base you are working with (for instance, if you have only sets of 5 of something with no remainders you could use base 5), but I'm not sure if that's true.

Any thoughts?


问:
Is this a violation of the Liskov Substitution Principle?
Say we have a list of Task entities, and a ProjectTask sub type. Tasks can be closed at any time, except ProjectTasks which cannot be closed once they have a status of Started. The UI should ensure the option to close a started ProjectTask is never available, but some safeguards are present in the domain:

public class Task
{
     public Status Status { get; set; }

     public virtual void Close()
     {
         Status = Status.Closed;
     }
}

public class ProjectTask : Task
{
     public override void Close()
     {
          if (Status == Status.Started)
              throw new Exception("Cannot close a started Project Task");

          base.Close();
     }
}
```

Now when calling Close() on a Task, there is a chance the call will fail if it is a ProjectTask with the started status, when it wouldn't if it was a base Task. But this is the business requirements. It should fail. Can this be regarded as a violation of the Liskov substitution principle?

答:
It is not a violation of the Liskov Substitution Principle.

The Liskov Substitution Principle says:

Let q(x) be a property provable about objects x of type T. Let S be a subtype of T. Type S violates the Liskov Substitution Principle if an object y of type S exists, such that q(y) is not provable.

The reason, why your implementation of the subtype is not a violation of the Liskov Substitution Principle, is quite simple: nothing can be proven about what Task::Close() actually does. Sure, ProjectTask::Close() throws an exception when Status == Status.Started, but so might Status = Status.Closed in Task::Close().


答:
For some algorithms, base 2 makes more sense than anything else.  For example, would you rather write a function to traverse a binary tree, or a 10-ary tree?

But, more frequently, base 2 is used because that's how computers almost universally represent their numbers.  This means that:

many operations are more efficient in base 2:

multiplication, division, and modulo powers of 2 are much faster than general division

flags and small values can be stored, retrieved, and manipulated more efficiently as binary digits of a larger number.

operations that read, write, and manipulate data files and network data streams must deal directly with the fact that they are represented as binary numbers.

Also, there is always the rare application that inherently requires an odd base which may be neither 2 or 10.


答:
The usual reason for writing numbers, in code, in other than base 10, is because you're bit-twiddling.

To pick an example in C (because if C is good for anything, it's good for bit-twiddling), say some low-level format encodes a 2-bit and a 6-bit number in a byte: xx yyyyyy:

```<code>main() {
    unsigned char codevalue = 0x94; // 10 010100
    printf("x=%d, y=%d\n", (codevalue & 0xc0) >> 6, (codevalue & 0x3f));
}
</code>```

produces

```<code>x=2, y=20
</code>```

In such a circumstance, writing the constants in hex is less confusing than writing them in decimal, because one hex digit corresponds neatly to four bits (half a byte; one 'nibble'), and two to one byte: the number 0x3f has all bits set in the low nibble, and two bits set in the high nibble.

You could also write that second line in octal:

```<code>printf("x=%d, y=%d\n", (codevalue & 0300) >> 6, (codevalue & 077));
</code>```

Here, each digit corresponds to a block of three bits.  Some people find that easier to think with, though I think it's fairly rare these days.

Body:
The usual reason for writing numbers, in code, in other than base 10, is because you're bit-twiddling.

To pick an example in C (because if C is good for anything, it's good for bit-twiddling), say some low-level format encodes a 2-bit and a 6-bit number in a byte: xx yyyyyy:

main() {
    unsigned char codevalue = 0x94; // 10 010100
    printf("x=%d, y=%d\n", (codevalue & 0xc0) >> 6, (codevalue & 0x3f));
}

produces

x=2, y=20

In such a circumstance, writing the constants in hex is less confusing than writing them in decimal, because one hex digit corresponds neatly to four bits (half a byte; one 'nibble'), and two to one byte: the number 0x3f has all bits set in the low nibble, and two bits set in the high nibble.

You could also write that second line in octal:

printf("x=%d, y=%d\n", (codevalue & 0300) >> 6, (codevalue & 077));

Here, each digit corresponds to a block of three bits.  Some people find that easier to think with, though I think it's fairly rare these days.

OwnerDisplayName: Norman Gray


答:
The main reason I use different bases is when I care about bits.

It's much easier to read

```<code>int mask=0xFF;
byte bottom_byte = value & mask;
</code>```

than

```<code>int mask=255;
byte bottom_byte = value & mask;
</code>```

Or image something more complex

```<code>int mask=0xFF00FF00;
int top_bytes_by_word = value & mask;
</code>```

compared to

```<code>int mask=4278255360; //can you say magic number!?
int top_bytes_by_word = value & mask;
</code>```

It's very clear here what the intent is with the hex examples because hex is basically just a more compact form of binary... In contrast, base-10 (what we use) doesn't map nearly as well to binary.

```<code>0xFF = b11111111 = 255
0xFFFF = b1111111111111111 = 65536
0xF0F0 = b1111000011110000 = 61680
</code>```

There are also other bases you can use in some languages. You will find very little use of bases other than binary, hex and decimal.. Some odd people still use octal, but that's about the most esoteric you'll see in a sane program.

Body:
The main reason I use different bases is when I care about bits.

It's much easier to read

int mask=0xFF;
byte bottom_byte = value & mask;

than

int mask=255;
byte bottom_byte = value & mask;

Or image something more complex

int mask=0xFF00FF00;
int top_bytes_by_word = value & mask;

compared to

int mask=4278255360; //can you say magic number!?
int top_bytes_by_word = value & mask;

It's very clear here what the intent is with the hex examples because hex is basically just a more compact form of binary... In contrast, base-10 (what we use) doesn't map nearly as well to binary.

0xFF = b11111111 = 255
0xFFFF = b1111111111111111 = 65536
0xF0F0 = b1111000011110000 = 61680

There are also other bases you can use in some languages. You will find very little use of bases other than binary, hex and decimal.. Some odd people still use octal, but that's about the most esoteric you'll see in a sane program.

OwnerDisplayName: Earlz


答:
The most common valid reason to use other bases has to do with ease of conversion to base 2: it is trivial to convert a base-8 or a base-16 number to binary without using a calculator by memorizing a short table of eight or sixteen numbers:

```<code> 0000 0     0001 1     0010 2     0011 3
 0100 4     0101 5     0110 6     0111 7
</code>```

```<code> 1000 8     1001 9     1010 A     1011 B
 1100 C     1101 D     1110 E     1111 F
</code>```

This opens up multiple possibilities:

When a number represents a composition of meaningful binary numbers, you can determine the individual components without a computer. For example, if a 24-bit number represents a color in RGB, it is trivial to tell that 0xFF00FF is magenta (Red+Blue); the task is much harder when you are presented with 16711935

When a number represents a bit mask, it is more practical to write it down as a compact hex number, rather than a much longer binary number

Certain architectures went out of their way to make their binary code easy to read when printed as octal numbers. PDP-11 was one such system: the most significant bit would let you tell 8-bit operations from 16-bit ones; the last two octal groups would let you tell the two registers involved in the operation, and so on. I knew several people who could read PDP-11 binary code off the screen without a disassembler, but they needed the machine code to be printed in octal system.

Body:
The most common valid reason to use other bases has to do with ease of conversion to base 2: it is trivial to convert a base-8 or a base-16 number to binary without using a calculator by memorizing a short table of eight or sixteen numbers:

 0000 0     0001 1     0010 2     0011 3
 0100 4     0101 5     0110 6     0111 7

 1000 8     1001 9     1010 A     1011 B
 1100 C     1101 D     1110 E     1111 F

This opens up multiple possibilities:

When a number represents a composition of meaningful binary numbers, you can determine the individual components without a computer. For example, if a 24-bit number represents a color in RGB, it is trivial to tell that 0xFF00FF is magenta (Red+Blue); the task is much harder when you are presented with 16711935

When a number represents a bit mask, it is more practical to write it down as a compact hex number, rather than a much longer binary number

Certain architectures went out of their way to make their binary code easy to read when printed as octal numbers. PDP-11 was one such system: the most significant bit would let you tell 8-bit operations from 16-bit ones; the last two octal groups would let you tell the two registers involved in the operation, and so on. I knew several people who could read PDP-11 binary code off the screen without a disassembler, but they needed the machine code to be printed in octal system.


问:
Is C# development effectively inseparable from the IDE you use?
I'm a Python programmer learning C# who is trying to stop worrying and just love C# for what it is, rather than constantly comparing it back to Python.

I'm caught up on one point: the lack of explicitness about where things are defined, as detailed in this Stack Overflow question. In short: in C#, using foo doesn't tell you what names from foo are being made available, which is analogous to from foo import * in Python -- a form that is discouraged within Python coding culture for being implicit rather than the more explicit approach of from foo import bar.

I was rather struck by the Stack Overflow answers to this point from C# programmers, which was that in practice this lack of explicitness doesn't really matter because in your IDE (presumably Visual Studio) you can just hover over a name and be told by the system where the name is coming from. E.g.:

Now, in theory I realise this means when you're looking with a text editor, you can't tell where the types come from in C#... but in practice, I don't find that to be a problem. How often are you actually looking at code and can't use Visual Studio?

This is revelatory to me. Many Python programmers prefer a text editor approach to coding, using something like Sublime Text 2 or vim, where it's all about the code, plus command line tools and direct access and manipulation of folders and files. The idea of being dependent on an IDE to understand code at such a basic level seems anathema. It seems C# culture is radically different on this point. And I wonder if I just need to accept and embrace that as part of my learning of C#.

Which leads me to my question here: is C# development effectively inseparable from the IDE you use?

答:
This is an interesting view on C# development. What you are asking goes beyond C# though, if you're asking about the IDE.

Like you say, in Python, you can use various editors to write your code. You can do that with the .NET framework too. There are also other IDE tools you can use such as SharpDevelop. Visual Studio is very tightly co-developed with the .NET framework and is relatively expensive. Tools such as SharpDevelop and the "Express" versions of VS exist to entice more developers to use .NET. Essentially all an IDE does for you is provide an organised environment, usually with intellisense, add-ons for productivity and a "helper" to assemble what can end up being a very scary looking command-line to pass to your compiler. The same is true for Java, tools such as Eclipse just provide the organisation and productivity enhancements for us. Under the hood, nothing magical happens until you build or compile your project and that respect, all IDE's are just pretty faces to the unfriendly compiler.

When you talk about the "using" statement in C# and compare it to Python, it's not really the same thing going on under the hood. The using statements are used by the compiler to aid it's effort in transforming the C# code into MSIL. In MSIL, there is no "import all these classes from this namespace" directive. By the time code is at MSIL level, all the classes have been tagged with their fully qualified names. These "using" and "import" statements are to aid human readability. They are not compiler optimisation commands. After all this initial "tagging of fully qualified names" has gone on, there might be a kind of low-level "minify" to the FQNs but this is to aid the compiler/interpreter to execute faster. This is the optimisation - but there is no control of this offered to the developer, unless you are writing your own custom version of the compiler!

One final fundamental difference between all these languages mentioned on here are that some of them are interpreted by VMs, some are interpreted JIT style and some are fully compiled. How these using directives are implemented across those compilers and interpreters differs greatly.

HTH.


问:
Should I be using a JavaScript SPA designed when security is important
I asked something kind of similar on stackoverflow with a particular piece of code however I want to try to ask this in a broader sense.

So I have this web application that I have started to write in backbone using a Single Page Architecture (SPA) however I am starting to second guess myself because of security.  Now we are not storing and sending credit card information or anything like that through this web application but we are storing sensitive information that people are uploading to us and will have the ability to re-download too.

The obviously security concern that I have with JavaScript is that you can't trust anything that comes from JavaScript however in a Backbone SPA application, everything is being sent through JavaScript. There are two security features that I will have to build in JavaScript; permissions and authentication.

The authentication piece is just me override the Backbone.Router.prototype.navigate method to check the fragment it is trying to load and if the JavaScript application.session.loggedIn is not set to true (and they are not viewing a none authenticated page), they are redirected to the login page automatically.  The user could easily modify application.session.loggedIn to equal true (or modify Backbone.Router.prototype.navigate method) but then they would also have to not so easily dynamically embedded a link into the page (or modify a current one) that has the proper classes, data-* attributes, and href values to then load a page that should only be loaded when they user has logged in (and has the permissions).

So I have an acl object that deals with the permissions stuff.  All someone would have to do to view pages or parts of pages they should not be able to is to call acl.addPermission(resource, permission) with the proper permissions or modify the acl.hasPermission() to always return true and then navigate away and then back to the page.

Now certain things is EMCAScript 5 like Object.seal() or Object.freeze() would help with some of this however we have to support IE 8 which does not support those pieces of functionality.

Now the REST API also performs security checks on every request so technically even if they are able to see parts of the interface that they should not be able to, they still should not be able to actually affect any data.

The main benefits for me in developing a JavaScript SPA application is that the application is a lot more responsive since it is only transferring the minimum amount of JSON data for the requested action and performing the minimum amount of work too.  There are also other things that I think are beneficial like you are going to have to develop an API for the data (which is good if you want expand your application to different platforms/technologies) or their is more of a separation between front-end and back-end however if security is a concern, it is really wise to go down the road of a JavaScript SPA application for the front-end?

答: SPA's can be just as secure as any web application. They are not less secure. You have a lot of options dependent upon your security requirements. Some are discussed in this Security StackExchange Question. There is a lot of guidance on the web for securing SPA's. I am working on a SPA project where we are using a combination of basic authentication and cookies to maintain session identity on the server. Each call to a REST API for the AJAX methods are authorized at the server.  If authorizations fails we return an HTTP Forbidden error to the client and it handles it accordingly. We are able to still maintain a true single page application by using a jQuery UI modal dialog for log-on.  I would not maintain session information specific to identity on the client or set permissions on the client. And of course you still want to use HTTPS/SSL to secure data on the wire.</p>


问:
Numerous Unexpected Obstacles Ruining any Project Plans
I am working as software developer and struggling with this problem time and time again for almost thirteen years. There seems not to be any way out of the following problem.

And it happens with small projects as well.

For example, I plan to write an extension for Microsoft Visual Studio. I dowload learning materials, get some book on the topic and allocate time for learning and development.

However, during the development, many seemingly trivial problems arise, for example:

Why the script refuses to delete the file?

Why Visual Studio does not register the extension?

(after two days) OK, it registers it, but now it got broken. How to fix it?

each of these "small" obstacles usually take 1-5 days to resolve and the project finally consumes several times more man-hours than planned.

Maybe it happens only because I am working on Microsoft platform and many of their Frameworks and architectures are bit confusing and badly documented.

I would like to have most problems resolved by finding answer in a book or official documentation (MSDN), but the only answer I usually find is on some weird forum or personal blog googled after desperately searching for any relevant information on the topic.

Do you have the same struggles? Do you have techniques on how to prevent these problems?

I was thinking of simply multiplying projected time for a given project by some factor, but this does not help. Some projects get done briskly and some take months and the guiding factor here are these small "glitches" which take programmers whole weeks to resolve.

I have to admit that lots of these obstacles demoralizes me and drains me of focus and joy of work (who likes to get back to work when he have to resolve some stupid registry problem or weird framework bug instead of doing creative work?)

After the project is finally done, I am feeling like dying from thousand cuts.

答:
Imagine you're doing creative work: creating a new Boeing, larger, more powerful, etc.

One day, you're waiting for truck which should deliver bolts for a part of the aircraft, but it appears that there was a human mistake, so instead of arriving in your city, the truck is stuck in the middle of nowhere and will be late.

Another day, some very important and very experienced worker is hit by a bus. To continue the work, you need to quickly find another such experienced person.

You also discover that the wiring shipped from different countries is incompatible. You should rewire a large part of the aircraft and expect important delays.

When the aircraft is finished, it appears that the tail is rubbing the runway during the takeoff while it shouldn't. You need to handle this situation and explain to your customers why you're three months late because of this.

The randomness you have with IT projects exist everywhere. This is risk, and you can't avoid it. You can still reduce it:

By reusing code written by skilled developers only. If you take a piece of code which is written by some unknown, underpaid programmer, you can't be sure that it will be painless to use it. It may work, it may fail.

By choosing the technologies you already know. If you start a web application and never used Ruby but have ten years experience in Python, don't pick Ruby if you need to avoid bad surprises. There is nothing wrong in trying something new for the first time, but don't do it on a business critical project with tight deadlines.

By asking help. Stack Overflow is for people who are stuck in front of a problem some other developers may have experienced before.


问:
Pros and cons of working remotely / from home
I have never had the opportunity to work from home on certain days, but I would definitely like to try it if I can.  What are the pros and cons?

I'll list a few that I can think of.

Pros:

You don't need to do any work.  (That's a JOKE)

You can be a lot more productive.  No commute, relaxed, no meetings, no interruptions

Cons:

Less of a team effort.

Other team members can get held up due to having to wait for information for an off-site member

Apologies if this has been asked before - I did a search but couldn't find a pros and cons discussion.

Edit: It appears The Oatmeal has already covered this! :-)

答:
In France, telecommuting is far from common. Here is why:

The boss cannot show the progress of your work and thus cannot give you more work when you're done with one activity.

The unions cannot be in contact with you and thus are afraid that you could be manipulated by the boss.

This all ends up with gazoline being wasted in climate change and productivity misses.

Seth Godin has a blog post about this subject: Goodbye to the office.


答:
... consumes several times more man-hours than planned.

Sounds like you're planning things where you or your team don't have sufficient experience or knowledge to understand the potential pain points. This is common, and the best way I've seen for solving or managing this is a Proof of Concept (POC).

That is, in a POC you are given a well defined amount of time - say 2-3 weeks - and you are tasked with seeing what can be done to solve a particular problem or use a particular technology. The result isn't necessarily the work that you did, but a report on what it's like using the technology, the pain points, the efficiencies gained, and now your estimate of how long it would take to develop the solution.

This estimate still has a strong likelihood of being wrong... but much less wrong than it would have been otherwise.

Title: Numerous Unexpected Obstacles Ruining any Project Plans

Body:
I am working as software developer and struggling with this problem time and time again for almost thirteen years. There seems not to be any way out of the following problem.

And it happens with small projects as well.

For example, I plan to write an extension for Microsoft Visual Studio. I dowload learning materials, get some book on the topic and allocate time for learning and development.

However, during the development, many seemingly trivial problems arise, for example:

Why the script refuses to delete the file?

Why Visual Studio does not register the extension?

(after two days) OK, it registers it, but now it got broken. How to fix it?

each of these "small" obstacles usually take 1-5 days to resolve and the project finally consumes several times more man-hours than planned.

Maybe it happens only because I am working on Microsoft platform and many of their Frameworks and architectures are bit confusing and badly documented.

I would like to have most problems resolved by finding answer in a book or official documentation (MSDN), but the only answer I usually find is on some weird forum or personal blog googled after desperately searching for any relevant information on the topic.

Do you have the same struggles? Do you have techniques on how to prevent these problems?

I was thinking of simply multiplying projected time for a given project by some factor, but this does not help. Some projects get done briskly and some take months and the guiding factor here are these small "glitches" which take programmers whole weeks to resolve.

I have to admit that lots of these obstacles demoralizes me and drains me of focus and joy of work (who likes to get back to work when he have to resolve some stupid registry problem or weird framework bug instead of doing creative work?)

After the project is finally done, I am feeling like dying from thousand cuts.


问:
Developing web sites that imitate desktop apps. How to fight that paradigm?
Supposse there's a company where web sites/apps are designed to resemble desktop apps.

They struggle to add:

Splash screens

Drop-down menus

Tab-pages

Pages that don't grow downward with content, context is inside scrollable area so page is of a fixed size, as if resembling the one-screen limitation of desktop  apps.

Modal windows, pop-ups, etc.

Tree views

Absolutely no access to content unless you login-first, even with non-sensitive content. After splash screen desapears, you are presented with a login screen.

No links - just simulated buttons.

Fixed page-size.

Cannot open a links in another tab

Print button that prints directly ( not showing printable page so the user can't print via the browser's print command )

Progress bars for loading content even when the browser indicates it with its own animation

Fonts and color amulate a desktop app made with Visual Basic, PowerBuilder etc.

Every app seems almost as if were made in Visual Basic.

They reject this elements:

Breadcrumbs

Good old underlined links

Generated/dynamic navigation, usage-based suggestions

Ability to open links in multiple tabs

Pagination

Printable pages

Ability to produce a URL you can save or share that links to an item, like when you send someone the link to an especific StackExchange question. The only URL is the main one.

Back button

To achieve this, tons of javascript code is needed. Lots and lots of Javascript and Ajax code for things not related with the business but with the necessity to hide/show that button, refresh this listbox, grey-out that label, etc.

The coplexity generated by forcing one paradigm into another means most lines of code are dedicated to maintain the illusion of a desktop app.

What is the best way to change this mindset, and make them embrace the web, and start producing modern, web apps instead of desktop imitations ?

EDIT:

These sites are intranet sites. Users hate these apps. They constantly whine about them, but they have to use them to do their daily work. These sites are in-house solutions, the end-users have no choice but to use them. They are a "captive audience". Also, substitution will not happen because of high costs. But at least if that mindset is changed, new developments would be more web-like.

答: I would point them towards successful web apps by Big Companies that have harnessed the web format instead of sticking to the desktop one. Wordpress comes to mind. Google's business apps as well.</p>


问:
Why to use web services instead of direct access to a relational database for an android app?
I searched on the web how to access in an efficient manner to a central database at a remote location and I met suggestions to use web services instead direct access (i.e. JDBC etc ) to a  database.I wonder the reason of that and any other suggestions.</p>

答:
It puts a layer of abstraction between the app and the DB. This gives you a lot of advantages such as:

Limiting access to the DB to only the parts that the app needs. This both simplifies the app's code, and keeps your DB secure.

Asbstracts the inner working of the DB, so if you decided later on to change your schema, queries, or even your whole database the link to your app is not broken as long as you maintain the middle layer correctly.

It allows you to add functionality outside the scope of a DB. Caching data that is fairly constant for instance. Business rules are another part that should be apart from the DB.


答:
This is a problem with predicting development times. I think I've read somewhere a fancy term for this situation, but I can't remember it now.

The bottom line is, when predicting how much time will it take for a certain project, if you haven't done a similar project before, be sure that you can't have a reliable prediction. If you are going to work on a new platform/work with a new framework for the first time, there will always some relatively minor problems that will set you back for hours/days/weeks.

That's why, at least around where I live, people working in software industry never gives certain estimates, and tend to exaggerate a lot.


答:
This sounds like the underlying problem is a failure to adapt. It will be difficult to convince them they should as well. I think your best bet would be a combination of things:

Point to big companies' (Google, Microsoft, etc) web applications

Make a good list of points on the difference between desktop apps and web apps and why they shouldn't try to act the same

If all else fails make a small-ish example program. Say, a notepad replacement. Make it "desktop on the web" style, and make it in typical web-app style. Show your bosses why people are more likely to use the web-app style.

Finally show them that web-apps are the way they are for a reason. It's cheaper in multiple ways. Takes less time to develop(pretending HTTP is a stateful protocol is such a time waster), less resources to run, and your customers are more likely to pay for whatever you're selling.

A few starting points for #2:

It is physically impossible to know for sure that a customer has left your web app. HTTP is stateless. You can do polling, but this isn't great.

Web apps do not require installation. This is one of their greatest selling points. Don't muck this up by requiring a login for things that don't require it.

It is physically impossible to know for sure what size of browser-window the user has. This is why flowing layouts are so good, they dynamically adjust to whatever the window size is automatically. In comparison, the desktop-style approach is usually a fixed layout where you're stuck with basically a lot of wasted screen space for no good reason.

With web apps, it's very possible that someone is using a different OS than Windows to access your website. You should strive to use common fonts and not rely on proprietary fonts unless you have a failback font that looks decent.

HTTP is stateless. The more you pretend it's not, the more resources you need to make that "true". At the highest end, it basically means for each request to your website, you will require sending all of the data from every request to your website since the last visit. Internet is getting faster and servers more powerful, but why buy a 5 mile-per-gallon gas guzzler for $80,000 when a better looking 40 mile-per-gallon car does the same thing for less.

Users hate being inconvenienced. If your website is stateful and they are about to buy something and accidentally press the browser back button instead of your proprietary back button, that may cause them to start over. Chances are they will take their business elsewhere rather than deal with finding the product again, putting in their info, and actually buying the product

They should absolutely facilitate the ability of users to share URLs to their content! This is probably the most important point. What's easier "hey go to this URL and look at this" or "hey go to this URL and then click search, and then type in "super bacon cooker" and then click on the 3rd result, the super bacon cooker XL and take a look at that".... Can you guess which of these processes a user will never do? Do you want free advertising or not?

Title: Developing web sites that imitate desktop apps. How to fight that paradigm?

Body:
Supposse there's a company where web sites/apps are designed to resemble desktop apps.

They struggle to add:

Splash screens

Drop-down menus

Tab-pages

Pages that don't grow downward with content, context is inside scrollable area so page is of a fixed size, as if resembling the one-screen limitation of desktop  apps.

Modal windows, pop-ups, etc.

Tree views

Absolutely no access to content unless you login-first, even with non-sensitive content. After splash screen desapears, you are presented with a login screen.

No links - just simulated buttons.

Fixed page-size.

Cannot open a links in another tab

Print button that prints directly ( not showing printable page so the user can't print via the browser's print command )

Progress bars for loading content even when the browser indicates it with its own animation

Fonts and color amulate a desktop app made with Visual Basic, PowerBuilder etc.

Every app seems almost as if were made in Visual Basic.

They reject this elements:

Breadcrumbs

Good old underlined links

Generated/dynamic navigation, usage-based suggestions

Ability to open links in multiple tabs

Pagination

Printable pages

Ability to produce a URL you can save or share that links to an item, like when you send someone the link to an especific StackExchange question. The only URL is the main one.

Back button

To achieve this, tons of javascript code is needed. Lots and lots of Javascript and Ajax code for things not related with the business but with the necessity to hide/show that button, refresh this listbox, grey-out that label, etc.

The coplexity generated by forcing one paradigm into another means most lines of code are dedicated to maintain the illusion of a desktop app.

What is the best way to change this mindset, and make them embrace the web, and start producing modern, web apps instead of desktop imitations ?

EDIT:

These sites are intranet sites. Users hate these apps. They constantly whine about them, but they have to use them to do their daily work. These sites are in-house solutions, the end-users have no choice but to use them. They are a "captive audience". Also, substitution will not happen because of high costs. But at least if that mindset is changed, new developments would be more web-like.


答:
Nowhere in your question do you mention the end user. All questions like "should we use design A or design B?" should start with the needs of the users. Are they happy and productive with the current designs, or are they the ones asking for these changes?

A lot of what you mentioned can be used both in successful and unsuccessful apps. Before you go trying to change things, make sure the change makes your user experience better. If the current scheme works for them, why change? If you're thinking "I think this would improve the experience of my users", that's the wrong answer. You need to do just a tiny usability study of just a few real users so you can confidently say "I know this would improve the experience of my users".

If you want to change the mindset of your team, get them to understand that a) it's all about the users, and b) the users are not being served by the current designs. If they don't agree with either one of those points, you'll have a hard time convincing anyone.


答:
I'm a little premature for this, at 35 I am a CTO that still manages to write some code when I'm not distracted by Q&A sites, interviews, budget sheets, pending litigation, that black hole called the US Patent office and other things.

I first learned the 'business' end of programming when I got sick of working for other people. I was familiar with some aspects of administration, such as software licenses and contracts in general so it was a natural move for me. Quite frankly, I hate it.

Currently, I'm well versed enough to continue to not only keep pushing neat products out the door, but also ensuring that we keep and maintain people who can push neat products out the door. I also try my best to steer us away from legal pitfalls. I refuse to stop writing code, so it is indeed like working two full time jobs.

My goal? Make enough money so I can just go back to pushing neat stuff out the door, without having to worry about anything else. That probably won't happen for another 15 years, which, remarkably, puts me at the same age that you raised in your question.

You also have to consider that most (good) companies take a different look at management. I would not, for instance, interfere with a project that I knew nothing about even though my title 'entitles' me to do so unless there was some compelling reason to do so. If you are going to go through all of the hassle of establishing a 'senior' level and then short circuit it, what's the point?

Where I work, if you are able to come up with an idea, draft a spec, a plan and a budget, you own it, it's your baby and you are free to spend money and run with it with minimal oversight.

I think most sensible companies are realizing that they make more money when they (within reason) put people at what they want to do. Manager today, grunt tomorrow, consultant the following week. As long as the compensation reflects your responsibilities, I don't see how a title makes any difference :)

Footnote: I hate software patents and am a member of the LPF (league for programming freedom)


答:
Adding a web service layer gives you an opportunity to make your client more lightweight, both in terms of the required CPU power and the bandwidth used during the processing. Both factors are extremely important to end-users:

Using less CPU increases the battery life,

Using less bandwidth reduces monthly payments for users with metered plans

By introducing a web application layer you move the bulk of the processing from a hand-held mobile low-power, low bandwidth, low-memory client to a plugged-in, high-power high-bandwidth, server that has more memory than it needs - an environment where processing and communications cost a fraction of what they cost on a client.

But wait, there is something in it for you as well: by splitting the system you get more control over your business rules, the structure of your database, and the versions of what's out there. Once you let a mobile client connect directly to the database, your design is "married" to that database structure: almost any change would break backward compatibility to a client that may be reluctant to upgrade his app.

In contrast, adding a web service in between lets you evolve the interface to mobile clients in more manageable ways: for example, you could keep the old interface in place, add a new one that works "in parallel" with it, and then entirely restructure your database without breaking a single client.

If you follow some pretty basic design principles while designing your web service, you could also get significant benefits by reusing mature server-side infrastructure that has been put in place: for example, you can get cache and proxy services for free.

Finally, this will open the door to other developers exposing your application to platforms that you could not service yourself, ultimately playing to your company's advantage.

Title: Why to use web services instead of direct access to a relational database for an android app?

Body: I searched on the web how to access in an efficient manner to a central database at a remote location and I met suggestions to use web services instead direct access (i.e. JDBC etc ) to a  database.I wonder the reason of that and any other suggestions.</p>


答: Perhaps if you were writing a game which simulates the economy of some ancient civilization that uses a base 12 system.</p>


答:
There is a paradigm shift in the web industry. The term SPA(single page application) is getting more and more traction each day, as big projects/startups continues to produce amazing web apps each passing day.

As web is changing constantly, and fast, embracing web is a vague term IMO. The old sync. request-response with full page loads using HTML is being replaced by json over async. requests.

Now, there are two types of 'things' on web: web sites and web apps. Each of them has it's own pros/cons.

programmers.SE is a web site. There is no need for 'app' functionality, as the 'web site' concept is already useful for a QA network.

On the other hand, Basecamp(online project management software) is a web app. The traditional way of web sites, which includes separate pages for everything, full page loads etc. won't really fits a project management software. Instead, using the SPA model, you have a software that can be used with a web browser, with the power of a desktop app. Best of both worlds.

The problem is, as always, you should choose which type, web site or web app, fits your product. Take the end user experience to front side when making decisions.


问:
C++11 support for higher-order list functions
Most functional programming languages (e.g. Common Lisp, Scheme / Racket, Clojure, Haskell, Scala, Ocaml, SML) support some common higher-order functions on lists, such as map, filter, takeWhile, dropWhile, foldl, foldr (see e.g. Common Lisp, Scheme / Racket, Clojure side-by-side reference sheet, the Haskell, Scala, OCaml, and the SML documentation.)

Does C++11 have equivalent standard methods or functions on lists? For example, consider the following Haskell snippet:

let xs = [1, 2, 3, 4, 5]
let ys = map (\x -> x * x) xs
```

<p>How can I express the second expression in modern standard C++?</p>

```std::list<int> xs = ... // Initialize the list in some way.
std::list<int> ys = ??? // How to translate the Haskell expression?
```

What about the other higher-order functions mentioned above?

Can they be directly expressed in C++?

答:
Even more, C++ have such functions, take a look to algorithm (or with C++11 additions) header:

```<code>std::transform
std::for_each
std::remove_copy_if
</code>```

They can be easily used with any container.

For example your code can be expressed like this (with C++11 lambdas for easy coding):

```<code>std::vector<int> x = {1, 2, 3, 4, 5};
std::vector<int> y;
std::transform(x.begin(), x.end(), std::back_inserter(y), [](int elem){ return elem * elem; });
</code>```

Less intuitive, but you can easily wrap the std::transform call into function which would return new container (with move semantics for better perfomance).

Body:
Even more, C++ have such functions, take a look to algorithm (or with C++11 additions) header:

std::transform
std::for_each
std::remove_copy_if

They can be easily used with any container.

For example your code can be expressed like this (with C++11 lambdas for easy coding):

std::vector<int> x = {1, 2, 3, 4, 5};
std::vector<int> y;
std::transform(x.begin(), x.end(), std::back_inserter(y), [](int elem){ return elem * elem; });

Less intuitive, but you can easily wrap the std::transform call into function which would return new container (with move semantics for better perfomance).


答:
Well of course they want their web apps to behave just like the desktop apps. You want to convince them to drop all of this, even though, they are willing to pay someone to make it work.

Now if they expected you to develop this with the same amount of time and the same amount of performance at the same price, you have an arguement. As long as they are aware of what they get for what they pay for, you should deliver. If I were paying for software and my employees wanted all these extra bells and whistles at my expense, I'd be the one complaining and not the programmers.

You have job security my friend. No one said it would be easy.


问:
Can graphics in the public domain be used in commercial software?
For example: http://commons.wikimedia.org/wiki/File:Epithalamus.png

Could I take an image file like that, splice it apart, and use it in an application that would be sold?

答:
The only problem with "Public Domain" (as it relates to any kind of resource) is that you don't get an explicit license for using it.  Rather than giving you explicit permission by the author or copyright holder, public domain simply states "You don't need permission."  Anyone can claim that a resource is in the public domain, even if they are not the original author.

For some organizations, that's not quite good enough.  That's why many software developers prefer providing an explicit license, even if it's the "Do whatever the f_ck you want to with it" license.


问:
Can an internally developed fast evolving, agile, short sprint web application lend itself to offshoring?
I have recently been set a target to achieve readiness to successfully manage and deliver results through the usage of offshore teams on our mainline development project within 12 months.

Our mainline is a multi-thousand user highly available web application, and various related SAAS components delivered through the above mentioned web application.

We work agile on the mainline with a rapid 1 week sprint using continuous integration.
Our delivery platform is a bespoke php framework, although we have some .net services and components in the mix.

My view is: an offshore team could work if we either ship out an entire isolated project for offshore development, or we specify a component for our system in huge detail up front.  But we don't currently work like that, and it will conflict with the in-house method, and unless the off-shore is working within our team, with our development/deployment chain it could be an integration nightmare.

So my question is,  given we have a closed source bespoke framework (Private IP) which we train our developers to use, and we work agile minimising documentation, maximising communication and responding to rapidly changing requirements, and much of the quality control is via team skills building and peer review, how can I make off-shoring work on our main line development?

答:
It really depends on off-shore team leadership and efficient management of the team.

In our company we have two off-shore (China) offices and we also have Chinese speaking team-lead in our company as well as one in offshore team, located in China. There clear communication plays vital role in our delivery and success.

Thus, although working together on the same project with offshore team has number of challenges (timing, language, communication, etc.), however once managed properly, with key people on both sides - it may turn into a success and competitive edge of your company in the western markets (in our company case it is the U.S.).


问:
What are best practices for testing programs with stochastic behavior?
Doing R&D work, I often find myself writing programs that have some large degree of randomness in their behavior. For example, when I work in Genetic Programming, I often write programs that generate and execute arbitrary random source code.

A problem with testing such code is that bugs are often intermittent and can be very hard to reproduce. This goes beyond just setting a random seed to the same value and starting execution over.

For instance, code might read a message from the kernal ring buffer, and then make conditional jumps on the message contents. Naturally, the ring buffer's state will have changed when one later attempts to reproduce the issue.

Even though this behavior is a feature it can trigger other code in unexpected ways, and thus often reveals bugs that unit tests (or human testers) don't find.

Are there established best practices for testing systems of this sort? If so, some references would be very helpful. If not, any other suggestions are welcome!

答:
It is useful to add hooks, as suggested, to recreate exact states. Also instrument the system so that it can dump its "seeds" (in your case, including the PRNG seed as well as the kernel ring buffer, and any other sources of nondeterministic input.)

Then run your tests both with true random input, and regression-style with any previously-discovered interesting cases.

In the particular case of your access to the kernel, I'd recommend making a mock in any case. Use the mock to force equivalence classes that are less likely to show up in practice, in the spirit of "empty" and "full" for containers, or "0, 1, 2^n, 2^n+1, many" for countable things. Then you can test with the mock and with the real thing, knowing that you have handled and tested the cases you've thought of so far.

Basically, what I'm suggesting amounts to a mix of deterministic and nondeterministic inputs, with the deterministic ones being a mix of those you can think of and those you were surprised by.


答:
One other reason not to expose the DB directly -- transport. Most relational databases, the kinds of things one talks to with JDBC, are not designed for the public internet in general. Wireless internet is a horribly unreliable end of said public internet. Exception handling would be nightmarish and you'd probably end up writing the reverse of the web services layer inside your app to avoid losing transactions.

There are some newer sorts of databases that do speak HTTP and might be suitable for this sort of thing. They also tend to feature ways to put application code of sorts in the database. You might want to look out CouchDb or RavenDb -- both are document dbs with map/reduce capabilities that work over json and http, much like many modern web services.


答:
why anyone would go out of their way to program numbers in a base other than base 10.

Here are some reasons that did not already appear...

x00 - Some OSs and hardware devices' APIs expect the arguments to be in hex/binary. When you code for such APIs, it is easier to use the numbers in the same format as the API is expecting instead of converting it between different bases. For example, to send an end of message byte to a server or to send a message to close a connection to a communication channel.

x01 - You may want your application to represent characters not available at certain keyboards such as the copyright sign (\u00a9).

x02 - To have some constants/literals persist (visually) across different culture settings, specially when the source code/files be moved across developers with different local settings.

x03 - To make their code look confusing and complex - Good thing is that C# does not support octal constants!


答:
The key issue is representing a single word of computer size in a reasonable way.  The 6502 was an 8 bit processor.  The 4004 was a 4 bit processor.

When dealing with a 4 or 8 bit number works nicely.  A 4 bit number is a single hexadecimal character.  A 8 bit number (a byte) is two hex digits.  Systems that have a power of 2 sized word are the commonly seen standard today - 16 bit, 32 bit, 64 bit.  All of these divide by 4 nicely for representation as hexadecimal.

Octal (base 8) was used in systems where the word size was 12, 24, or 36.  The PDP8, IBM Mainframe, and ICL 1900 of days of old used these. These words were more easily represented using octets rather than a limited range of hexadecimal (yes, they also divide into 4 too).

Apparently there was also a cost savings with using base 8 numbering.  Representing 12 bits in BCD, the first digit can only be 0-4 but the second, third, and fourth may be 0-9.  If this was done as hex, one has 3 hex characters, but each one has 16 possible values.  It was cheaper to produce a nixie tube that only had 0-7 than one that had 0-9 (with additional logic for BCD) or 0-F for hexadecimal.

One still sees octal today with unix file permissions (755, 644) where owner, group and world each have 3 bits representing the permissions.

In the mathematics world, one occasionally does some odd things with different bases.  For example, a weak Goodstein sequence from project euler 396... or something simpler with palindromic numbers.  There is the property of a number in base N that a number which is a multiple of N - 1 will have its digits sum up to a multiple of N - 1.  Furtermore, if N - 1 is a perfect square, this property also exists for sqrt(N - 1).  This has some applications in certain mathematical problems.


问:
I have data that sends in "bursts" of 100 records with a significant delay. How do I structure my classes for multithreading?
My datasource sends information in 100 batches of 100 records with a delay of 1 to 3 seconds between batches.

I would like to start processing data as soon as it's received, but I'm not sure how to best approach this.

Some ideas I've been playing with include:

yield

Concurrent Dictionary

ConcurrentDictionary with INotifyProperyChanged

Events

etc.

As you can see I'm all over the place, and would appreciate some tested guidance on how to approach this

答:
get back to the basics with a producer-consumer buffer (look at thread safe queues)

your receiving code pushes each record to a queue

then several processing threads will pull a record and process it in a loop


问:
Dynamic Forms: Pattern or AntiPattern?
I'm sure you've seen it.  The database has a bunch of tables called Forms, Controls,FormsControls, ControlSets, Actions and the program that queries these tables has a dynamically generated user interface.  It will read all the forms, load a home page that has links to them all, or embed them in some tabbed or paged home page, and for each of those forms it will read the various text boxes, check boxes, radio buttons, submit buttons, combo boxes, labels and whatnot from the controls and form-to-control join tables, lay those elements out according to the database and link all the controls to logic according to other rules in the database.

To me, this is an anti-pattern.  It actually make the application more difficult to maintain because the design of it is now spread out into multiple different systems.  Also, the database is not source controlled.  Sure, it may make one or two changes go more quickly, after you've analyzed the program anyway to understand how to change the data and as long as you don't stray from the sort of changes that were anticipated and accounted for, but that's often just not sustainable.

What say you?

答:
It is definitely not an anti-pattern: when this is done correctly, it lets you complete very complex applications in very short time. I worked for a company that built all its products that way, and it was very successful at what it did*.

The only problem with this approach is that it is extremely difficult to get right. For example, it took a team of some fifty highly skilled programmers, mostly from MIT and Caltech, about three years to build the platform. Once built, however, the platform delivered handsomely: we were able to put complex applications in production in a matter of months.

The biggest benefit behind this approach is that it lets business analysts with very little programming knowledge build reasonably complex applications. Programming such systems is often only slightly more complex than programming Excel, so people with knowledge of the domain could be trained at making the forms, their backing storage, and the business rules controlling the data flow.

* The company collapsed because of failures in its business model.

Title: Dynamic Forms: Pattern or AntiPattern?


答:
I think every time I've tried to do something like this I've ended up scrapping the system and starting over. For me it was creating a tree in a db and having a type field. That type field mapped to various models. I mean yes, technically relational db type stuff is like defining a customized tree, but querying one giant table ends up causing performance issues. Commonly there are exceptions to various rules which end up causing your db schema to be non-acid compliant or just ugly as well. It is much easier to plainly define your architecture using tangible model names. Moral of the story: don't over generalize a problem.

That being said there is another paradigm that states your code is data. In that thought process one might say that saving your applications in a DB does make sense... I suppose...

Doing revs aren't easy, but I suppose it is no different than how systems like wordpress or drupal do revs on their documents.

As @dasblinkenlight said this sounds hard. I'd say it is overly complicated. Sometimes you do need to provide a mechanism for admins to create forms. In those cases you might better off just saving the entire HTML of the form itself. Then saving the filled in form data separately and let admins sift through it however they please.

Title: Dynamic Forms: Pattern or AntiPattern?

Body:
I'm sure you've seen it.  The database has a bunch of tables called Forms, Controls,FormsControls, ControlSets, Actions and the program that queries these tables has a dynamically generated user interface.  It will read all the forms, load a home page that has links to them all, or embed them in some tabbed or paged home page, and for each of those forms it will read the various text boxes, check boxes, radio buttons, submit buttons, combo boxes, labels and whatnot from the controls and form-to-control join tables, lay those elements out according to the database and link all the controls to logic according to other rules in the database.

To me, this is an anti-pattern.  It actually make the application more difficult to maintain because the design of it is now spread out into multiple different systems.  Also, the database is not source controlled.  Sure, it may make one or two changes go more quickly, after you've analyzed the program anyway to understand how to change the data and as long as you don't stray from the sort of changes that were anticipated and accounted for, but that's often just not sustainable.

What say you?


问:
Bulk commits vs Quick commits
I know that most of you would advice to go with the strategy and methodology of the project.

However I just have a quick question, from Senior point of view, what would be better to see quick small commits from a developer, or large chunk of code pushed to the branch?

答:
There are limits, but I prefer small, atomic commits.

First, it makes things easier when you're referring to why a change was made. Second, it drastically reduces the cost of making a mistake.

Two notes of caution though:

If you're using a centralised VCS, only commit when the code builds and tests run. (If you're using DVCS, replace "commit" with "push".)

Do not implicitly refer to one commit comment from another.

```<code>351: pdr: Stop foo from grommiting.
352: pdr: Ooops, got that wrong, let's try again.
353: dan: New launch page.
354: pdr: Third time lucky.
</code>```

That sort of thing. Don't do it. It's very tempting when you're committing often, because you remember the commit you did five minutes ago, and commenting starts to feel like a conversation with yourself. But control yourself. It makes no sense to the poor person, two years into your future, who does a search for the last commit on given files.

Title: Bulk commits vs Quick commits

Body:
There are limits, but I prefer small, atomic commits.

First, it makes things easier when you're referring to why a change was made. Second, it drastically reduces the cost of making a mistake.

Two notes of caution though:

If you're using a centralised VCS, only commit when the code builds and tests run. (If you're using DVCS, replace "commit" with "push".)

Do not implicitly refer to one commit comment from another.

351: pdr: Stop foo from grommiting.
352: pdr: Ooops, got that wrong, let's try again.
353: dan: New launch page.
354: pdr: Third time lucky.

That sort of thing. Don't do it. It's very tempting when you're committing often, because you remember the commit you did five minutes ago, and commenting starts to feel like a conversation with yourself. But control yourself. It makes no sense to the poor person, two years into your future, who does a search for the last commit on given files.


问:
Are testers considered low profile?
I happened to know some system admin and according to him, testing guys are not given preferences in an organization in comparison to developers. No doubt software releases are not possible without testers but I've never laid my hands on testing so not much aware of it. No offense intended. </p>

答:
Update after reading other answers:
There are a lot of QA professionals who love the job they do. Just to give another perspective if you haven't come across any respected QA positions, one example here: Embedded apps/ mobile apps testing for leading automakers. They make sure the business requirements are completely met before a vehicle is released to the market and no user experience a slow or unresponsive car dashboard. They work closely with managers and higher level management, and also the developers starting from planning the QA process to live hands-on testing on simulators in the design facility. I can't think of them being low profile, they handle huge responsibilities and ownership and they are among the best engineers.

now my earlier answer, the flip side:

I have observed that engineering graduates hate getting allocated to testing units (context:India, large software services firms where everything is driven by 'business requirements') , since they consider it a a non-technical work environment. They are given excel sheets with instructions like 'click all the links in the webpage and verify', are forced to work with graduates from non-technical streams(science, arts) which they consider as a humiliation and feels like their tech skills are not utilized.  These allocations are purely based on organization's requirements, and a fresher, most of the time, does not have the power to negotiate his career path. So if you are a job seeker aiming at such a big IT company, you have been warned. You cannot do much, practically, except getting out of the company at the right time.

Unless there are opportunities to learn automated testing , load/performance testing etc, the career is stagnant to an extent.Personally I know the opportunities for onsite assignments (=loads of money from an offshore programmer point of view) are more for testing unit in my organization than any other unit. They work with all industry verticals as a filler or glue, as testing is inevitable in projects in all domains.

If you are confident you can drive your career the way you want, testing is nothing low-profile. With 4-5 years of experience and a bit of luck you can get a very good exposure, sometimes interacting with the top-level business users. You also can have a good grasp of the industry/domain you are working in (compared to a developer who would mostly focus on some piece of the system). At this point one can choose to switch to a business analyst kindof role too.

Title: Are testers considered low profile?


答: It doesn't really matter the size, but rather commit must be an atomic as possible. By that I mean that commit must not break the build, it should fix one specific bug, or add one specific feature and be independent from any other commits. If a feature requires a lot of code, well so be it. But usually this strategy naturally produces small frequent commits.</p>

Title: Bulk commits vs Quick commits

Body:
I know that most of you would advice to go with the strategy and methodology of the project.

However I just have a quick question, from Senior point of view, what would be better to see quick small commits from a developer, or large chunk of code pushed to the branch?


问:
Event system architecture for networking when performance is concerned
How should I design a system for an action game (think in Golden Axe) where events can happen remotely?

I'm using TCP for this because the client is in flash.
There's so many options, I can make a binary protocol (I don't like this idea, I found it to be too hard to mantain) but I was also thinking that passing jsons through clients and server can be slow (Is that a exaggerated concern?).

What about the internal architecture for the server? And for the client? I'm really lost, If it's a question that is too big, please indicate me some material so I can formulate a better question next time.

答:
The question is a bit widespread - so I am mostly giving you pointers to think about which can be refined to be more specific.

This essentially applies to design of Application layer protocol (sometimes including session layer). Application layer protocol has following elements

A. definitions of messages:

How many messages do you need? HTTP has GET, PUT, POST as used mostly. What are the essential unique communications client-server needs to do? Which message followed by which other makes sense - and which ones don't?

B. design of structure and encoding of messages:

When sockets receive arbitrary length of bytes - the primary tasks is to find where does the new message start and when it ends? How are bytes represented - ASCII, binary, B64, ASN.1?

C. Is this stateful or stateless?

If there is a state to be maintained by the server during the execution of the message/command or across multiple requests - then that state machine must be consistent and robust; all events orders must be addressable by this state machine to ensure that the protocol doesn't go in the deadlock.

D. Is there a session, authentication or some identifier?

Identification of who's talking to whom, whether one is authorized and or authentication is valid (during session) and maintaining such sessions becomes key to ensure right entities get right information.

Any application layer protocol design really has the questions to be answered. These are things I had learned when I was exploring BEEP. I leave upto you if that is of some good use to you or not. However, but there is a great deal of learning from it; and you are right on the context of it.

See:

1. An Overview of BEEP - The Internet Protocol Journal - Volume 5, Number 2

2. BEEP, understanding why it was created, Marshall T. Rose

3. Building port oriented applications and BEEP


问:
When to favor ASP.NET WebForms over MVC
I know that Microsoft has said

ASP.NET MVC is not a replacement for WebForms.

And some developers say WebForms is faster to develop on than MVC.  But I believe speed of coding comes down to comfort level with the technology so I don't want any answers in that vein.

Given that ASP.NET MVC gives a developer more control over their application, why isn't WebForms considered obsolete?  Alternatively, when should I favor WebForms over MVC for new development?

答: Our reason for not going to MVC a few years ago was it was an immature technology from Microsoft. Over the past few years we are now on a more mature version (4) and MS seems to have worked out where they are going with this. However, we are still reluctant on developing major LOB apps using MVC as the features we want to use in version 4 require a windows 2012 server (re web sockets via IIS8). I reckon in 1 more year we will be more accepting of MVC as hopefully more third party controls will be available, the technology will have settled, and we will have the infrastructure to support it.   </p>

Title: When to favor ASP.NET WebForms over MVC


问:
What is the difference of delegator and dispatcher?
What is the difference of delegator and dispatcher?

I am not quite sure of either concept.

答:
Delegation is assigning a responsibility to some other object. For example, if I am invited to a meeting and I assign it to a junior colleague, I am delegating. The point to note here is that it is the junior colleague who will attend the meeting and there is no intermediary between him and me.

Dispatching is not delegating. Dispatcher is more like an intermediary who relays a request to someone else. For example, to attend the meeting my astute junior colleague may ask a cab company for a pick up and the guy receiving the request may dispatch it to a nearby cab driver. The point here is that dispatcher is only passing along the request.


答:
Dispatcher

The dispatcher can be considered as a Queue where the events are sent.

A dispatcher runs on the UI thread and executes events for the UI.

In windows, UI controls may only be modified by the thread that created them, so any changes to the UI must be done from the UI thread - thus that is one of the critical reasons why operations that modify window elements must be sent to the UI's dispatcher.

A background thread that calls BeginInvoke on the dispatcher will return immediately even though the dispatcher may not have gotten around to processing. If Invoke had been used instead, the background thread would block until the UI thread completed processing. Note that in Silverlight, there is no Invoke on the Dispatcher and in most cases you probably don't want your background thread blocking while the UI thread is processing work.

Delegate

Delegate is used for Callback and Event Handling.

The Dictionary meaning of Delagate is "A person acting for another person". but in .net its a really means a method acting for another method.

Delegate uses worker threads in the thread pool.

When you're on the UI thread (or any thread really) you can call BeginInvoke and Invoke on a delegate. BeginInvoke will use a worker thread to call the delegate using the same way I have told above. Invoke, however, would not use a different thread. It would simply invoke the delegate synchronously in the context of the calling thread and return when completed.

Consider this: delegate.Invoke/BeginInvoke and this.dispatcher.Invoke/BeginInvoke.

BeginInvoke means: "Do this and return before it completes. I either don't care about the return value or you can call me back at this address at some point in the future."

Invoke means: "Do this and I'll sit here and wait for it to complete."

In short: The BeginInvoke is an asynchronous call. It executes a delegate asynchronously on the thread the Dispatcher is associated with.

Body:
What is the difference of delegator and dispatcher?

I am not quite sure of either concept.


问:
Can SDK license influence an application license?
Let's say SDK is under specific license that is not compatible with some other licenses (like Flex SDK with GPLv2). Can I create an application by using for example Flex SDK, and license its distribution under GPLv2? Can my application be considered a derivative work? What is a relation between SDK license and application license that was build by using that SDK?</p>

答: It might. Always read the license.

Body: It might. Always read the license.


问:
Project Management Techniques (high level)
Our software dev team is currently using kanban for our development lifecycles, and, from the reasonably short experience of a few months, I think it's going quite well (certainly compared to a few months ago when we didn't really have a methodology).

Our team, however, is directed to do work defined by project managers (not software project managers, just general business), and they're using the PMBOK methodology.

Question is, how does a traditional methodology like PMBOK, Prince2 etc fit with a lean software development methodology like kanban or scrum? Is it just wasting everyone's time as all the requirements are effectively drawn up to start with (although inevitably changed along the way)?

答:
Don't have enough points to vote up karianna but I agree with him. I moved from developer -> software PM -> Project manager which is now expected to do PMP/Prince2 reporting on software projects.
It is fairly simple to map any agile/kanban method to fit within the Prince2/PMP structure. In the end the only reason people want/need this is to see the progress! So if you can visually show the progress/bottle necks and risks then I can't see any PM insisting on anything else.

As far as requrements go, I would also tend to let the business requrements not get too detailed so that the developers themselves decide how best to break it down into smaller detailed tasks. It is possible, you just have to sit down with the PM and discuss his/her (reporting) requirements and then see how you can provide him/her with it.


答:
I think statistical testing is the only way. Just like random numbers are "tested" for randomness by statistical tests, so need to be algorithms that use of random behavior.

Simply run the algorithm multiple times with either same or different input and compare it to each other. The problem with this approach is massive increase in computational time required to finish the testing.

Title: What are best practices for testing programs with stochastic behavior?

Body:
Doing R&D work, I often find myself writing programs that have some large degree of randomness in their behavior. For example, when I work in Genetic Programming, I often write programs that generate and execute arbitrary random source code.

A problem with testing such code is that bugs are often intermittent and can be very hard to reproduce. This goes beyond just setting a random seed to the same value and starting execution over.

For instance, code might read a message from the kernal ring buffer, and then make conditional jumps on the message contents. Naturally, the ring buffer's state will have changed when one later attempts to reproduce the issue.

Even though this behavior is a feature it can trigger other code in unexpected ways, and thus often reveals bugs that unit tests (or human testers) don't find.

Are there established best practices for testing systems of this sort? If so, some references would be very helpful. If not, any other suggestions are welcome!