答:
Here's steps to make it work properly:

use forwarding from one interface to another to build a tree
          of objects which together represent the bitmap

every "extension" of the bitmap will allocate it's own
memory and provide another interface for it

example implementation would be:

```<code>template<class T, class P>
class ExtendBottom {
public:
   ExtendBottom(T &t, int count) : t(t), count(count),k(t.XSize(), count) { }
   P &At(int x, int y) const { if (y<t.YSize()) return t.At(x,y); else return k.At(x, y-t.YSize()); }
   int XSize() const { return t.XSize(); }
   int YSize() const { return t.YSize()+count; }
private:
   T &t;
   int count;
   MemoryBitmap k;
};
</code>```

Obviously for real implementation, the XSize() and YSize() would not work, but you'll need MinX(), MaxX(), MinY(), MaxY() or something like that to keep index numbers consistent.

Title: Infinite Bitmap

Body:
Here's steps to make it work properly:

use forwarding from one interface to another to build a tree
          of objects which together represent the bitmap

every "extension" of the bitmap will allocate it's own
memory and provide another interface for it

example implementation would be:

template<class T, class P>
class ExtendBottom {
public:
   ExtendBottom(T &t, int count) : t(t), count(count),k(t.XSize(), count) { }
   P &At(int x, int y) const { if (y<t.YSize()) return t.At(x,y); else return k.At(x, y-t.YSize()); }
   int XSize() const { return t.XSize(); }
   int YSize() const { return t.YSize()+count; }
private:
   T &t;
   int count;
   MemoryBitmap k;
};

Obviously for real implementation, the XSize() and YSize() would not work, but you'll need MinX(), MaxX(), MinY(), MaxY() or something like that to keep index numbers consistent.


问:
Using TSQL for the first time some basic instructions
I am writing an application that will use many tables and I've been told that I must not use stored procedures in this project because it will be too slow.

It has been suggested that I use TSQL. I have only used stored procedures until now.

Is using TSQL different? Is this the way to go for faster data access or are there other methods?

答:
You can access data in the following ways (assuming you are using .NET) - amongst others:

(1) using ADO.NET (and LINQ)

(2) using ODBC (not recommended if you can use other options)

(3) using T-SQL via ADO.NET

(3A) using T-SQL via LINQ

(4) using SQL Server CLR (C# code on the server side)

The debate between using (1) and (3) is an ongoing debate, however, if you don't have intentions to change your database to another one, it is fairly common to program the database layer in T-SQL. T-SQL is mostly used to do basic Create, Read, Update and Delete operations as well as triggers processing. Unlike plain ADO.NET, T-SQL may be more secure since it keeps your code SQL free.

Most ORM tools generate code for either (1) or (4). So your tool may affect your decision.

If you have complex logic and intensive calculation or if your require several calls to the database before your unit of work is completed, you could then use (4).

You may be interested to know more about this in the following link:
https://stackoverflow.com/questions/14530/linq-to-sql-vs-stored-procedures

ContentLicense: CC BY-SA 3.0


问:
Best open source ASP.NET MVC e-commerce projects
I need to get a e-commerce site up and running, but I really don't want to program it from the bottom up if I don't need to. I want to program it using ASP.NET MVC.

I'm looking for a good open source alternative (or one for purchase if it's modular enough) that I can use as a base and enhance with the needed functions?

It has to have all "normal" e-commerce functions, and also the possibility to integrate with a credit card API of my choice.

If anyone have any recommendations for me here, I would appreciate it :)

答:
Right off the bat you can download and try out The BeerHouse CMS and e-comm project from CodePlex. This is an asp.net MVC based application with e-commerce areas setup and should be able to be wired up to most payment gateways. In addition, it's been around for a while, and has two books which walk through most of the code, design considerations, and it's solutions.

Good luck on your project, and hope this helps some.


问:
Is an assocative array ordered?
An associative array has many common similar names, hash, keymap, map, table, index.

It's a map of keys and values but I cannot find a reputable definition of the phrase which tells me whether a map has to have order to be an associative array.

What is a reputable definition of the term "Associative array"?

Is an associative array ordereded?

Personally I've always believed they have to be ordered because in JavaScript we claim Objects are not associative arrays because Objects are un-ordered maps of keys and values. However I may have been quoting that without a reference or a source.

答:
There seem to be two (2) questions, or perhaps two interpretations for your question that one could take:

Do associative arrays, as they are defined in a theoretical sense imply any kind of ordering

Is there an underlying ordering of the elements in an associative array implementation in language XYZ?

Since your question sports the language-agnostic tag, then one would naturally want to favor the first interpretation. And the answer to that is:
no, associative arrays, by definition do not imply any sort of ordering of elements.

It is however true that in a specific implementation, the data structure used to implement the associative array functionality could have some underlying ordering of the elements, and it might also be the case that a clever programmer might take advantage of that ordering (assuming it is exposed or reachable by the programmer) in the process of writing a program.

The problem with this, however, is that such an implementation or clever trick would only be useful in the specific language, and quite possibly using a specific compiler on a specific architecture, and as such would not represent any thing that could be used for any usage of an associative array.

Title: Is an assocative array ordered?


问:
What constitutes authorship for software documentation?
In science, intellectual contribution to a project is sufficient for someone to be the author of a document. When writing software documentation, this would imply that almost everyone involved in the software development would be included as co-authors.

Unlike in science, it seems odd to include the names of people who do not actually work on the document. One reason is that documentation is constantly evolving and I am concerned about making sure that co-authors regularly review the current state of the document.

question: When writing documentation, are there guidelines for whom, other than those who directly contribute to the document, should be considered an author?

clarification: I am writing documentation about how to use an open source software and database built by and for scientists. As this project represents most of our the team's cumulative experience with software development, we have no existing policies for authorship of documentation (unlike we do with journal articles).

答:
I'm not sure what type of documentation you are creating or attempting to keep current, but in my 20-odd years of technical writing I have never had my name on a single document that was exposed to the public. One reason is that I am a contractor, and most companies are loathe to admit they use us as much as they do.

If it is the policy of to include authors, I suggest you list them by role: authors, contributors (someone who wrote less than a chapter/section), reviewers, editors, illustrators, and perhaps even those who inspire(d) you if you feel the need.


问:
What are some good criteria for using Tracer Bullets?
I was recently reading The Pragmatic Programmer for the first time and I came across the concept of Tracer Bullets.  I realized that I had coded according to this model in the past and just kind of filed the way I was working away in my brain as "agile".

They only give one example of where they had used it in the past.  The way the situation was identified to be a good candidate for Tracer Bullets was

There were many unknowns, and many different environments, and no one was too sure how the GUI should behave.

That kind of seems like the way a huge number of projects start, especially when you're working with non-technical people on a typical line of business app for a hedge fund (as an example).

I used it because it simply felt right, without really knowing what it was called or having it explained to me.  I knew that if I tried to get everyone in a room and got them to spec everything (or at least some things) up front it would be a complete disaster, but again that's a feel kind of thing...

Can anyone come up with some more concrete criteria for when this model might be the way to go?

答:
I came across the concept of Tracer Bullet development in the book Ship It!, edited by the pragmatic programmers.

I guess that in your question, you are referring to the book The Pragmatic Programmer: From Journeyman to Master. I haven't read that one, and I don't know how TBD is presented there. In Ship It!, there is one chapter (20 pages), dedicated to TBD. In particular, they talk about their experience with a concrete example : a datamining application for a biotech company. Basically, they explain that having nice abstraction layers (designed using TBD) helped them remove the performance bottlenecks one by one, by parellelizing each layer.

In my view, TBD is two things :

Create a software architecture by isolating the system objects, and let the developpers collaborate to define the interfaces between these system objects

Use mock objects to ensure the architecture is sustainable (test the architecture early)

I think the first point is a very good way to architect a software, no matter what. The second point is interresting : it can potentially prevent a complete rewrite of a project due to an initial architecture that doesn't work in practice.

OwnerDisplayName: Jason Punyon

ContentLicense: CC BY-SA 2.5


问:
What are the steps in beginning a large project, when all I have is a big idea?
I am computer engineering student. I've been thinking about
how I can handle a big project. What should be my first step to reach my goal in a more efficient and effective way?

When I come up with a project, I don't know how I should start working on it. Many times, I just ignore it. However, I don't want to ignore my project ideas anymore.

Now, I am asking to all of you, can anyone share his/her experiences? How should I start a project when all I have is an idea?

答:
List of things to do when starting a new project:

create new directory

create makefile by copying some existing makefile template

create some header and implementation files

make sure it compiles

start using version control

decide naming convention for classes, functions, data members, variables

write your first class

make sure your class is independent and every member function is independent of other member functions

create several objects by creating functions like main()

repeat steps 7-10 until your program is ready

compile it

ship it to end users


答: Some are, some aren't. Some systems of mapping key to value do depend on order- such as binary search trees. Some like hash maps aren't ordered. There's nothing inherent about association that implies ordering.</p>

Title: Is an assocative array ordered?

Body:
An associative array has many common similar names, hash, keymap, map, table, index.

It's a map of keys and values but I cannot find a reputable definition of the phrase which tells me whether a map has to have order to be an associative array.

What is a reputable definition of the term "Associative array"?

Is an associative array ordereded?

Personally I've always believed they have to be ordered because in JavaScript we claim Objects are not associative arrays because Objects are un-ordered maps of keys and values. However I may have been quoting that without a reference or a source.


问:
Are there languages that make it easier to understand secure coding principles?
I'm interested in expanding my knowledge of security issues: things like buffer overflows, format string vulnerabilities, etc. I'd like to be able to go through a language and understand its security implications and pitfalls to get a better understanding of secure coding practices in general.

Are there certain languages that are more conducive to a learning experiment like this? Are there languages, due to abstractions or complexity, I should avoid? Where should I start?

答: The key thing to understand is that most security issues are inherently low-level.  C++ is roughly a superset of C, but to really be forced to understand how low-level things work, you need to at least dabble in straight C, or write inherently low-level code (things like memory allocators or string classes) in C++.  If you just learn C++ coming from a background of even higher level languages, chances are you'll try to program in a Java-like style that you're already comfortable with, using lots of objects and never touch the lower-level features inherited from C, which are the important ones if you're trying to learn about security.

OwnerDisplayName: Atul Goyal


问:
Can one truly develop a programming style?
I started teaching myself programming half a year ago, and I've noticed I keep using a few basic techniques over and over again, is this the onset of a style or just ignorance of variation?</p>

答:
When all you have ever used is a hammer, ever problem looks like a nail.  Once you have been introduced to a screw driver, you see screws for what they are.

The same thing happens when programming.  If all you are exposed to is a certain style of programming, you will naturally develop a tendency to work in that style.  As you gain more experience, you will start to see more different styles, particularly ones suited to different problem sets and languages.

Over time, you will eventually start to derive your own style from your experience, but it usually takes a few years solving different problems in different languages.

Right now, I am going to guess you are still walking around with a hammer.  In time, you will have a full set of tools and you will really start to have your own style in how you write code, design your software, and even do your work.


问:
VB.Net vs C# debate
I've been in workplaces where, at the start of a project, the "Should we use VB.Net or C#" question has been raised.

Granted, it's probably less common to have to make that decision now than it was in the early days of .Net, particularly given the trend towards language convergence, but it can still be a heated debate.

So, between VB.Net and C#, Which language do you prefer and why?

答:
In addition to the other answers posted here, I would choose C# over VB because C# programmers get paid more. More experience with C# = more $$ :)

I know both languages are almost the same and its really easy to switch between the two, but I think when management looks at a bunch of curly braces and semi-colons they accept the fact we are doing something they cannot do, where with VB.Net they might look at it and go "oh that must not be that hard to do if I can understand it".

Title: VB.Net vs C# debate


答:
Modern C++ style has a number of constructs that help mitigate security problems. std::vector and string in particular.

So, I would recommend C.

Or, for super-fun times, you could write some assembly programs.

Title: Are there languages that make it easier to understand secure coding principles?

Body:
I'm interested in expanding my knowledge of security issues: things like buffer overflows, format string vulnerabilities, etc. I'd like to be able to go through a language and understand its security implications and pitfalls to get a better understanding of secure coding practices in general.

Are there certain languages that are more conducive to a learning experiment like this? Are there languages, due to abstractions or complexity, I should avoid? Where should I start?


答:
There's no reason to pick C over C++. Pretty much anything C can do, C++ can do, but better. Things like automatic resource management and templates are irreplacable tools. Having to learn to free() is really irrelevant. If you write C code, you still don't have to write your own malloc() or anything like that.

There's nothing language-specific about security.


问:
How large non-OO code bases are managed?
I always see abstraction is a very useful feature the OO provides for managing the code-base. But how are large non-OO code bases are managed? Or do those just become a "Big Ball of Mud" eventually?

Update:

It seemed everyone is thinking 'abstraction' is just modularization or data-hiding. But IMHO, it also means the use of 'Abstract Classes' or 'Interfaces' which is a must for dependency-injection and thus testing. How non-OO code bases manage this? And also, other than abstraction, the encapsulation also helps a lot to manage large code bases as it define and restrict the relation between data and functions.

With C, it is very much possible to write pseudo-OO code. I don't know much about other non-OO languages. So, is it THE way to manage large C code bases?

答:
How it's handled is that you find out the borders of the elements you use. For example, the following elements in C++ has a clear border and any dependencies outside the border must be carefully thought out:

free function

member function

class

object

interface

expression

constructor call / creating objects

function call

template parameter type

Combining these elements and regognizing their borders, you can create almost any programming style you want within c++.

Example of this is for a function would be to regognize that it's bad to call other functions from a function, because it causes dependency, instead, you should only call member functions of the parameters of the original function.


答:
I'd say that there is really only one basic factor that determines how useful a Tracer Bullet approach is: the number and scope of uncertainties in the architecture and design of the application.

Because the primary (if not only) goal of the technique is to clear up such uncertainties, you will not benefit much from it if you don't have any or they don't concern the architecture or design. A greenfield project with no architectural constraints is a typical example for when starting with a Tracer Bullet is almost the only sensible thing to do, whereas a for a mature project with some new features to implement it would probably be a waste of time (even though there may be uncertainties regarding the requirements, clearing those up is more the domain of general agile or iterative development).

Title: What are some good criteria for using Tracer Bullets?

Body:
I was recently reading The Pragmatic Programmer for the first time and I came across the concept of Tracer Bullets.  I realized that I had coded according to this model in the past and just kind of filed the way I was working away in my brain as "agile".

They only give one example of where they had used it in the past.  The way the situation was identified to be a good candidate for Tracer Bullets was

There were many unknowns, and many different environments, and no one was too sure how the GUI should behave.

That kind of seems like the way a huge number of projects start, especially when you're working with non-technical people on a typical line of business app for a hedge fund (as an example).

I used it because it simply felt right, without really knowing what it was called or having it explained to me.  I knew that if I tried to get everyone in a room and got them to spec everything (or at least some things) up front it would be a complete disaster, but again that's a feel kind of thing...

Can anyone come up with some more concrete criteria for when this model might be the way to go?


问:
What does the term day-one-bug mean?
I came across this term recently in a mail chain. Google tells me there is a term zero-day bug and that Microsoft and Adobe are the frontrunners :)

Is there such a term as day one bug? What might that mean?

答:
Ask the person who used the expression. It is not widely-enough used for a generally-agreed-upon definition to exist.

A "zero day exploit" is a security exploit that the developer of the software (or the security community in general) has known about for 0 days (i.e. not yet) so that there can't be a fix. Extrapolating from that, a "one day exploit" would be one that has become publically known today, so if the developer and the users act fast, a few systems may already be patched.

But that extrapolation is not necessarily correct, the expression may not have anything to do with zero-day exploits. Brian's answer actually sounds more likely. Which leads us back to my first paragraph.

Title: What does the term day-one-bug mean?


问:
What does it mean for software, libraries, and languages to be asynchronous?
With popular software out today like Node.js, Celery, Twisted, and others boasting about being asynchronous, what does it mean?

I've gone through the basic Node.js tutorials and written a few Node.js scripts, but still don't feel comfortable with the topic. Please note that I haven't had I had any formal introduction to the topic.

How exactly does asynchronous software work?

What are the pros and cons?

What are callbacks?

Lastly, how does a synchronous web server perform vs. an asynchronous web server?

答:
I just spent the last few weeks implementing a handful of asynchronous web services.  Here's the general idea:

Synchronous messaging is the "standard" pattern.  Client sends a request to Server, then waits for Server to send a response.  It's a lot simpler to program, on both ends, but it has the disadvantage that the Client will be blocked until it gets a response back.

Asynchronous messaging is a bit more involved.  Client sends a request to Server, and Server replies with an acknowledgement. (Not a response, but a "Yes, I got your request and I'll deal with it when I can.")  Server stores the request somewhere, such as in a queue.  When the Server is ready, it processes the request, and sends the response to the Client, which has to be able to receive incoming messages, and there has to be some way to associate this response message with the request it sent earlier, in case it's sent more than one request in the meantime.

It's a lot more involved, but it keeps the client from blocking and having to worry about timeouts, etc.


答:
Synchronous access is when a call fetches * some * data, retrieves it, and directly returns it

Asynchronous access is when a querry to fetch the data is submitted, and the data is retrieved in a callback function passed in the initial call

The basic difference is that in the case of asychronous access you don't know for sure when the data will arrive and if it will even arrive.

The main advantage of asynchronous access is that you avoid lags when waiting for the network connection or the database to work or anything else that could slow down or even freeze your client code. The main disadvantage is added complexity and the fact that you can't rely on the data arriving and this has to be reflected in your code. Using asynchronous access however, you can define a timeout period on the client side and issue an error after the timeout occured and still do something while waiting for the data (like for instance showing a hourglass).

If it's still a question to you, all direct function calls are synchronous. I'm sure you know the advantages and disadvantages to sychronous calls.

Title: What does it mean for software, libraries, and languages to be asynchronous?

Body:
With popular software out today like Node.js, Celery, Twisted, and others boasting about being asynchronous, what does it mean?

I've gone through the basic Node.js tutorials and written a few Node.js scripts, but still don't feel comfortable with the topic. Please note that I haven't had I had any formal introduction to the topic.

How exactly does asynchronous software work?

What are the pros and cons?

What are callbacks?

Lastly, how does a synchronous web server perform vs. an asynchronous web server?


答:
Wikipedia might be a good place to start with some general concepts and basic information.

This quote from that page sums it up but probably needs a bit of knowledge to fully understand it.

In programming, asynchronous events are those occurring independently of the main program flow. Asynchronous actions are actions executed in a non-blocking scheme, allowing the main program flow to continue processing.

So with synchronous programming the user initiates an action on the program but then has to wait for the operation to complete before being able to do anything else. An example might be saving a file to disk, you can't do anything else until the file is saved.

With asynchronous programming the user initiates an action, but then can carry on doing other work while the operation completes. The program then notifies the user in some way that its finished. An example here might be printing a document. Here you initiate the print then (after some set up) can carry on while the document is sent to the printer. You get some sort of notification that the printing is complete.

Asynchronous applications rely on multithreading or spawning child processes that do the work.

Callbacks are one mechanism where the calling code can do something when the asynchronous operation is complete. You'll register the callback with the long running process in some way then when it completes the code defined by the callback will be executed.


答:
SearchNetworking.com has this explanation:

In computer programs, asynchronous operation means that a process
  operates independently of other processes, whereas synchronous
  operation means that the process runs only as a result of some other
  process being completed or handing off operation. A typical activity
  that might use a synchronous protocol would be a transmission of files
  from one point to another. As each transmission is received, a
  response is returned indicating success or the need to resend. Each
  successive transmission of data requires a response to the previous
  transmission before a new one can be initiated.

Wikipedia has a summary of callback though don't forget the context can matter here as in some cases a callback is viewed differently than a postback.

Imagine a program that takes in 3 numbers and outputs the median of those numbers.  There are a few operations to such a program:  Get the 3 numbers from the user, sort the numbers to find the middle value, and output the result.  This has to be done in that order as you couldn't sort before you have the values and can't output the result until it is computed.


问:
What determines when a computer is considered a "client"?
In web development the terms "server" and "client" are often refered to when discussing how pages are requested on the web. It is also used exstensively when talking about PC, phone, tablets, etc. The question that came to my mind was what qualified a computer to be considered a client?

I took a look at this article from wikipedia and noticed that clients are considered service requesters whereas Servers are considered service providers. If this is true couldn't all computers that request a service in a sense be considered a client?

The stereotype I noticed is that a client computer is usually synonymous with a "consumer" computer, but according to wikipedia this is not entirely accurate. Any idea on how to draw the line in this common scenario?

答: The server calls listen(). The client calls connect().


答:
So, how exactly does asynchronous software work?

By having a call or request return more or less immediately, but without a return value or response, which is instead sent at some later time.

What are the pros and cons?

Pro: the call does not block. If the caller is single-threaded, this enables it to do something else meanwhile. If it is multithreaded but with significant overhead per thread, it may require fewer resources.

Con: it's a more complex programming model. Harder to learn, easier to make mistakes.

What are callbacks?

The pieces of code that deal with the response.

Lastly, how does a synchronous web server perform vs. an asynchronous web server?

That depends on the underlying platform and the demands of the application being run. The general expectation is that an asynchronous server is better at handling large numbers of requests, especially when they require little computation but may have to wait for something else (such as a DB request) before they can complete.

As a warning against blanket statements: Java nio is Java's way of doing asynchronous networking. But there is some good evidence that it may actually perform worse than plain old simple blocking IO for most apps on modern JVMs (in part because those have gotten a lot better at dealing with lots of threads).


问:
Having a Git repo and mercurial in the same directory
Ill explain my problem,

I am currently using an in-house install of gitorious using git. I would like to begin testing FogBugz and Kiln from Fog Creek which uses mercurial. I would like to for at a least a short while continue development using both solutions.

Does anyone know of any long term serious effects of having a git and a mercurial repo in the same directory. Or is there a better way of keeping git and mercurial server in sync.

Ive tried it with a test repo and I haven't seen any issues.

Thanks for any help.

答:
I've found the hg-git bridge fairly usable going the other direction (exposing some stuff on Github that was originally built using Mercurial for source control). Basically, you "just" use mercurial, create a bookmark linking "master" to the "default" when you're ready to push to a git repo, and push. Pull from git works similarly to the way it does when you pull from a remote repo. You don't end up with .git + .hg files in this scenario, you just have mercurial ones on your local box, unless you end up migrating over to git entirely, in which case you'd probably do git clone in a new directory.

There's a similar project for git users that want to push/pull from Mercurial repositories, but I don't have direct experience with it. See https://github.com/offbytwo/git-hg

Other than the potential of accidentally checking in a bunch of the hidden folders from your "other" source control system, I don't see any real problem with doing hg init in a git repo; it just seems less clunky to me to use a bridge, and explicitly choose when to push to the other dvcs system.


答:
To gain a better understanding of what languages like Java buy you in terms of security and memory management, work in C. The only thing that will drive the point home any deeper will be working in assembler¹. While it's nothing like what Java provides, C++ gives you too many tools to manage the kind of complexity that causes these problems, and the temptation to use them will be too great.

Memory management in C is very labor intensive compared to Java and C++. You don't have any sort of automatic garbage collection, you don't have explicit destructors to free up resources when an object goes out of scope, so you have to manually track every memory allocation and match it up with a corresponding deallocation. Arrays don't know how big they are and there's no bounds checking, so you have to track all those buffer sizes yourself and enforce those limits manually. C doesn't provide much in the way of exception handling (signals and setjmp/longjmp are the extent of it, and that's not very much at all), so you have to be careful about how you handle error conditions.

If you really want to appreciate what Java (or even C++) buy you, implement a C library that mimics the behavior of the Java String class.

¹ The best of both worlds would be to work in C and have your compiler write the generated assembly to an output file and study that.


答:
After doing anything for a prolonged period of time, one will eventually a style of his/her own. It is common in programming, it is common in poetry writing ... in anything really.

Were I you, I wouldn't worry about style at this point ... it's useless trying to work on something from which you've no use at all, and it will just seem unnatural, until you figure out for yourself the advantages and disadvantages of some of them. Worry about functionality and how to get things done, ... just write ... if your code is useful, nobody will argue about how it looks (well, maybe some will but don't listen to them ...) - if it's not, nobody will care anyway.

Title: Can one truly develop a programming style?

Body: I started teaching myself programming half a year ago, and I've noticed I keep using a few basic techniques over and over again, is this the onset of a style or just ignorance of variation?</p>


问:
How important are PHP notices really?
I recently turned all possible error-messages on with error_reporting(-1);, on my PHP project. Of course, right away I got alot of messages. For example:

Notice: Undefined variable: foo in /.../file.php on line 205

So I started updating my code to get rid of all the notices. Mostly, by adding isset($foo) and making the $foo = NULL;

So, I'm wondering. How important are these notices really? I mean, if the $foo variable is not set, then it should be false/null/not-set by default..so technically the code works?!

If I would get rid of all notices, then does it make the process faster or slow it down (because I'm adding more code, isset($foo), $foo = NULL etc)? How do you guys deal with these notices, or do you even pay attention to them?

I guess, the most important question is: Should the code be written so strict, that it would never generate any notices or warnings?

答:
If it does not have any effect on the functionality of your code, now or in the future, then don't waste your time.

If the particular "offending" line of code does not cause any actual problems then what is your incentive to "fix" it? You are not solving any problems, you are just satisfying an overzealous interpreter.

Conversely, if the line generating the warning is resulting in some undesired operations or affects the status of a method, by all means fix it.

Title: How important are PHP notices really?


问:
Where to look for challenging jobs with a relaxed atmosphere?
I'm a dev at one of the big-name tech companies. I like the job for many reasons:

I do interesting work on a cool product

I solve challenging problems and use a lot of high-level skills (quantitative, creative, writing, presenting)

It pays well

The problem is that I feel I need a more relaxed atmosphere (shorter hours, less performance pressure, and more flexibility), in order to free up time for other pursuits and reduce stress. The ideal would be a job that's around 30-35 hours a week, where there is flexibility to work more or less in a given week. Can anyone suggest where to look for a job like this, where I wouldn't have to sacrifice too much on the above points? (Obviously I would have to sacrifice pay.) My employer does not generally offer part-time employment.

The closest thing I can think of is when I did summer internships at my university's CS department. The work was very intellectually challenging, but if I needed to go home a couple hours early or get flexibility on a due date, nobody batted an eyelash. However, I'd like to find out if there are alternatives to academia since from what I've seen the pay there is a gigantic drop from what I'm currently making.

I've done freelance development before, but I do like that as an employee of a large company I have a lot of things taken care of for me (e.g. benefits and guaranteed stable employment).

答:
Have you considered jobs in a Scientific Research organization?

I think this type of job should keep you happy in the "interesting" and "challenging" departments, while also being competitive in salary (your mileage may vary of course).

Being a research organization, instead of a commercial company, I'd say there's more of a chance that the environment is more relaxed and more flexible too.

I have personally experienced this, although of course I can't generalize and speak for all research organizations.

If you are also looking for shorter hours and more flexibility, I would suggest Europe as a possibility.

In particular, France and Germany seem to offer the best hours and among the best paid time off.

So, to answer your question, look into Scientific Research Organizations in Europe.


答: Cleaning up some notices can potentially thwart a bug.  Undefined variables, for example, can result in errors if you try to read the variable that wasn't initialized.  Whenever possible, I try to write warning and notice free code.  But, if I am using somebody else's code, I don't generally take the time to clean up their errors or notices.</p>

Title: How important are PHP notices really?

Body:
I recently turned all possible error-messages on with error_reporting(-1);, on my PHP project. Of course, right away I got alot of messages. For example:

Notice: Undefined variable: foo in /.../file.php on line 205

So I started updating my code to get rid of all the notices. Mostly, by adding isset($foo) and making the $foo = NULL;

So, I'm wondering. How important are these notices really? I mean, if the $foo variable is not set, then it should be false/null/not-set by default..so technically the code works?!

If I would get rid of all notices, then does it make the process faster or slow it down (because I'm adding more code, isset($foo), $foo = NULL etc)? How do you guys deal with these notices, or do you even pay attention to them?

I guess, the most important question is: Should the code be written so strict, that it would never generate any notices or warnings?


答:
The notices are there to draw attention to things that might be problems. For example, a lot of bugs can come from typos: if the variable name is $filename and I type $filenaem, some languages will catch that, but in PHP, it's valid. So the notices can be useful in those cases.

Using the notices to flag potential errors as you write code the first time can be a very useful process; suddenly turning up the warning level in an existing codebase often results in a ton of useless warnings.

Whether the code should be edited to remove all warnings and notices is a cost-benefit analysis: is it worth the time for the problems it may solve? You have to answer that on a case-by-case basis.

Title: How important are PHP notices really?


问:
Is it OK to Use Dropbox in a Web Installer?
So I'm working in a modding project and they gave me the installing part as to do. We plan to publish it between 30 Aug. - 01 Sept.

My question is; is it logical to use Dropbox to download files in the web installer? I saw Dropbox's public folder has 10 GB download bandwith limit daily, after reaching that; they lock the account. I can insert a quota function and can use more than one Dropbox accounts. But it seems (not sure but) it's illegal or opposite to company's politics.

I don't know is the same bandwith limit applies to downloading directly from the root folder.
Also total size of the packages reaches 1 GB. This why I'm afraid of the bandwith limit.

And, if you don't recommend using Dropbox, what would you advise? I think a simple web automator with Mediafire is a good choice but resuming download will not be possible. Also I have a Fileserve Premium Account (a friend of mine gave as a gift) but most probably it will be banned after using different IP's at the same time.

One more thing I'm writing it in C#.

Thanks...

答:
I don't think Dropbox would like that, even if you could technically get away with it. It's probably forbidden in their terms of use.

What kind of mod project is it? If it's moderately good, you can get free hosting at Revora.

Disclaimer: I'm in that site's staff.


问:
Using TSQL for the first time some basic instructions
I am writing an application that will use many tables and I've been told that I must not use stored procedures in this project because it will be too slow.

It has been suggested that I use TSQL. I have only used stored procedures until now.

Is using TSQL different? Is this the way to go for faster data access or are there other methods?

答:
Speed probably shouldn't be your only consideration.  In terms of productivity and maintainability T-SQL can have problems because it isn't a full, general purpose programming language.  It doesn't support object oriented or functional programming, and even passing data from one stored procedure to another can a bit funny in some cases.  There are far fewer code libraries available.  Debugging support is not as good.  Other than some of the raw SQL statements, it will probably be very hard to port.  The only environment the T-SQL can run in is one that you have to pay for (Express Edition withstanding).

You can now use the SQL Server CLR to get around some of these issues, but there are a lot of limitations imposed so that Microsoft could integrate it with SQL Server and ensure badly written code in the CLR doesn't trash the whole database.

On the other hand, if enough of your business logic is in the database you don't need to worry about object-relational mapping, and it will probably run faster than even a hand-coded object oriented data access layer.

Most people decide to put most or all of their business logic outside the database, but it is possible to put most of it in one.


问:
Over normalization in database
Currently I am working on creating a new database schema as part of a major new product.  Our previous customer address records (in a previous product)  look something like this in our current schema (not all columns shown):

```<code>AddressID, AddressLine1, AddressLine2, City, State. Zip, Country, Etc.
</code>```

I want to normalize this so that an address actually breaks down to:

1 address to many address lines

1 address to a zip/postal code

So I sent out a communication saying that zip code will now be in its own table and that each "address" corresponds to one zip/postal code.  In addition, addresses would be broken out so that we could support more than 2 address lines with a 1 to many relationship.

Some people in my group are now saying that I am over-normalizing the database.  Am I?

Note, I am not a DBA but I feel that this is more logical and more efficient than the previous schema.

Update

Thx to everyone for their input.  I'm not going to break out the address or zips to their own tables.  My original plan was to have a zip code lookup and re-use for the addresses so I would only have to have one set of zips, but I'll just drop everything on the record itself, and have a separate table for zip lookups.

答: I'm not sure if this applies or not but I think I have a crash-and-burn case for your schema:  I have owned two properties within a single zip code.</p>

ContentLicense: CC BY-SA 4.0

Title: Over normalization in database


答: There seem to be more C# code samples online than VB.NET samples.  Not like its all that hard to convert one to the other, but why bother if you don't have to.</p>

Title: VB.Net vs C# debate

Body:
I've been in workplaces where, at the start of a project, the "Should we use VB.Net or C#" question has been raised.

Granted, it's probably less common to have to make that decision now than it was in the early days of .Net, particularly given the trend towards language convergence, but it can still be a heated debate.

So, between VB.Net and C#, Which language do you prefer and why?


问:
What do people in IT consulting firms do?
What do people in IT consulting firms do?

Ok I can guess they consult, provide answers to questions, but exactly what kind of questions do they answer that it is even possible people will pay enough for them to sustain their company expenses?

答:
Bill!

Seriously though "consultancy" is a very vague term and can cover many things.

At one extreme are low level body shops which hire fresh graduates at $250 dollars a day and farm them out to large corporations at $1500 dollars a day. The lack of experience is regarded as a good thing as they take longer to get the job done, their work needs more testing and there are more defects to fix, all of which means more billing.

At the other extreme you get small boutique consultancy firms with some "big name" employees who give expert advice on a subject they actually know about.

Most of the big name consultancies are actually a mixture of both, they have a small core of real experts which lend them credibility and a large pool of worker drones who bring in the money.


问:
If you learned formal methods for software, how useful have you found it?
If you have been trained in the use of formal methods (FM) for programming:

How useful have you found it?

What did your FM training involve (e.g. a course, a book)?

What FM tools do you use?

What advantages in speed/quality has it given you compared to not using FM?

What kind of software do you create with FM?

And if you don't directly use FM now, was it at least worth learning??

I'm curious to hear as many experiences/opinions on FM as can be found in this community; I'm starting to read up on it and want to know more.

Background

Programming and software development/engineering are some of the newest human skills/professions on Earth, so not surprisingly, the field is immature — that shows in our field's main output, as code that is typically late and error-prone.  Industry immaturity is also shown by the wide margin (at least 10:1) in productivity between average and top coders.  Such dismal facts are well covered in the literature, and introduced by books like Steve McConnell's Code Complete.

The use of formal methods (FM) has been proposed by major figures in software/CS (e.g. the late E. Dijkstra) to address (one of) the root causes of errors: the lack of mathematical rigour in programming.  Dijkstra, for instance, advocated for students developing a program and its proof together.

FM seems to be much more prevalent in CS curricula in Europe compared to the US.  But in the past few years, new "lightweight" FM approaches and tools like Alloy have attracted some attention.  Still, FM is far from common usage in industry, and I'm hoping for some feedback here on why.

Update

As of now (10/14/2010), of the 6 answers below, no one has clearly argued for the usage of FM in "real world" work.  I'm really curious if someone can and will; or perhaps FM really does illustrate the divide between academia (FM is the future!) and industry (FM is mostly useless).

答:
I've read a few books about formal methods, and applied some.  My immediate reaction was, "Gee, these books tell me how to be a good programmer, as long as I'm a perfect mathematician."  Another weakness is that you can only prove equivalence with another formal description.  Writing up a formal specification for a program is tantamount to writing a program in a higher-level language, and there's no way you can avoid introducing bugs in a reasonably large spec.

I've never made formal methods work on a large scale.  They can be useful in getting something small and tricky correct, and in convincing me that they're correct.  In that way, I can work with slightly larger building blocks and sometimes get a little more done.

One thing I did pick up that is more generally useful is the concept of an invariant, a statement about a program and its state that is always true.  Anything you can reason from is good.

As alluded to above, I'm not a perfect mathematician, and so my proofs sometimes contain errors.  However, in my experience these tend to be big dumb mistakes that are easy to catch and fix.


答:
There are degrees.  A "contractor" does what you tell him to do, an you pay him. You have less control over him than over an employee, and the option to let him go with rather less ceremony. A lot of contractors (staff aug or feature development teams) list themselves as consultants. Contractors are paid for producing a product.

A "consultant" will analyze your situation and give you advice and additional informations and perspectives. The work product is often a white paper, written by someone who knows the business, which can help you to make decisions. The value of the advice is related to the reputation of the consultant. Letting a lean expert examine your production system can be worth a lot of money, likewise someone who can iron out your product management or software process.

In related circles you find a coach, who is someone who helps your team to implement a certain process or set of processes. This person is experienced in various people skills, logistics, and technical skills. The coach's product is a team that can perform the new skills at least adequately and can self-improve from that point.

Typically an IT consultant is a consultant and may be a coach. You pay for research, analysis, recommendation, and sometimes coaching.

Also be aware that there are contractors who are also consultants and coaches. You may bring them in to help build a product, only to received valuable advice, training, and coaching in addition. Treat those people nice... you need a good relationship with them.

Body:
What do people in IT consulting firms do?

Ok I can guess they consult, provide answers to questions, but exactly what kind of questions do they answer that it is even possible people will pay enough for them to sustain their company expenses?


答:
+1 James.

Big consulting firms have lots of people with different skillsets and different levels of experience.  The skillsets range from telephone support through to high end project managers / Architects.  They then hire out the staff (at a huge mark-up as James suggests).  In the better firms they will have career development plans, decent HR & will look after the staff and move them from contract to contract - however in bad times they can and will have massive rounds of redundancies.

They will hire out anything from one Enterprise Architect or DBA to a whole programming team including managers & testers.  Their bread and butter is signing a big outsourcing deal and supplying 3 team of DBAs, several short term project teams of programmers and other support staff based worldwide providing 24/7 support.  The company doing the outsourcing  may even see a reduction in costs because they don't need to pay 100% of a good DBA but end up with a mix of 75% junior DBA and 25% a good DBA with even better ones available when necessary.  The consulting companies are also usually very capable and efficient at ITIL or similar so they are a lot better at managing the IT function than non-IT managers in, say, a big mining company.

Title: What do people in IT consulting firms do?


答:
I have to say I'm a bit puzzled by the initial question. Presumably when you wrote the stored procedures you used T-SQL ? Also I'm not convinced that stored procedures will actually be especially slow, or slower than other data access methods. Working with stored procedures does have its issues, but in my experience speed is not normally one of them.

If your client doesn't want to use stored procedures, probably there is nothing you can do about it. At the end of the day it is all about keeping the punters happy.

Title: Using TSQL for the first time some basic instructions

Body:
I am writing an application that will use many tables and I've been told that I must not use stored procedures in this project because it will be too slow.

It has been suggested that I use TSQL. I have only used stored procedures until now.

Is using TSQL different? Is this the way to go for faster data access or are there other methods?


问:
Managing SQL Stored Procedures' Version
I am working with a team of 5 persons. We are using SQL Server as our database.
Since long time I want to store the Stored Procedures in SVN so that the versions can be maintained. Is there any tool which can be used as a plugin with SQL Server Management Studio and allows checkin from there.</p>

答:
Sounds like Red Gate's SQL Source Control might be what you're looking for.

It says it connects to "TFS, SVN, SourceGear Vault, Vault Pro, Mercurial, Perforce, Git,
and any source control system with a capable command line," and that it "links your databases to your existing source control system straight from SSMS".

I haven't used it personally, but I have used other Red Gate SQL tools, and they have been excellent.

Title: Managing SQL Stored Procedures' Version


答:
If I remember correctly (it's been years since I've used SQL Server), you can execute external scripts using osql.

For each stored procedure, I'd write a sql script that removes the current one (if it exists) and creates the new version. Saving these in external .sql files will allow you to easily commit them to any versioning system. Then, you could write a script using your language of choice to update the database whenever you want.

Obviously you'd want to create a backup of your current database prior to running your script in case all goes to hell.

Title: Managing SQL Stored Procedures' Version

Body:
I am working with a team of 5 persons. We are using SQL Server as our database.
Since long time I want to store the Stored Procedures in SVN so that the versions can be maintained. Is there any tool which can be used as a plugin with SQL Server Management Studio and allows checkin from there.</p>


问:
Creating a Django development and production app
I just got started on some web development, and got my feet wet by creating a basic facebook app using Django. I am thinking of publishing the app, and consequently now need a development app that I could make subsequent changes to and roll them out to the production app. I'm completely new to this, and would be really thankful if someone could guide me on how I could go about this, and what the best practices are. (I also plan on letting my friend contribute to the app, so I would need to integrate git or some other vcs in the process right?)

Thanks!

答:
I'm a newbie myself and I feel your pain. What I can say is that top-down learning is painful and a safer way to go is to start from the basics. For beginning web development, Facebook is relatively complicated and full of APIs, as is Django (and Google app engine if you decide to lump that in too).
All that aside, Subversion, Github, Google Code, Beanstalk are good version-control software. They have excellent guides online.
I recommend using a local development server like MAMP or WAMP to point your canvas urls to, so you can save time and money and security problems by developing locally until you are ready to host it somewhere. Facebook's developer app (a web application that is more of a html form than a web application) allows you to do this.

I recommend starting with the javascript sdk for facebook, as it is the easy to learn for python. See the Run With Friends Canvas App or the sample template code for Python (run by Google App Engine)

OwnerDisplayName: ejang


答:
Example .gitignore file here: https://stackoverflow.com/questions/3719243/recommended-gitignore-file-for-python-projects

I like to do something like this in my settings file:

```<code>import os

# Get the path where ever you're project is at:
PROJECT_PATH = os.path.join(os.path.dirname(__file__))

# I sometimes use the path to determine if my project is in production.
# This would not be nice for open source projects.
if PROJECT_PATH.startswith('/var/django/'):
    PRODUCTION = True
    DEBUG = False
else:
    PRODUCTION = False
    DEBUG = True

MEDIA_ROOT = PROJECT_PATH + '/media/'
MEDIA_URL = '/media/'

STATIC_ROOT = PROJECT_PATH + '/static/'
STATIC_URL = '/static/'

ADMIN_MEDIA_PREFIX = '/static/admin/'

TEMPLATE_DIRS = (
    PROJECT_PATH + '/templates/',
)

# You can add local_settings.py to .gitignore.
try:
    import local_settings
except:
    pass
</code>```

Title: Creating a Django development and production app

Body:
I just got started on some web development, and got my feet wet by creating a basic facebook app using Django. I am thinking of publishing the app, and consequently now need a development app that I could make subsequent changes to and roll them out to the production app. I'm completely new to this, and would be really thankful if someone could guide me on how I could go about this, and what the best practices are. (I also plan on letting my friend contribute to the app, so I would need to integrate git or some other vcs in the process right?)

Thanks!

Body:
Example .gitignore file here: https://stackoverflow.com/questions/3719243/recommended-gitignore-file-for-python-projects

I like to do something like this in my settings file:

import os

# Get the path where ever you're project is at:
PROJECT_PATH = os.path.join(os.path.dirname(__file__))

# I sometimes use the path to determine if my project is in production.
# This would not be nice for open source projects.
if PROJECT_PATH.startswith('/var/django/'):
    PRODUCTION = True
    DEBUG = False
else:
    PRODUCTION = False
    DEBUG = True

MEDIA_ROOT = PROJECT_PATH + '/media/'
MEDIA_URL = '/media/'

STATIC_ROOT = PROJECT_PATH + '/static/'
STATIC_URL = '/static/'

ADMIN_MEDIA_PREFIX = '/static/admin/'

TEMPLATE_DIRS = (
    PROJECT_PATH + '/templates/',
)

# You can add local_settings.py to .gitignore.
try:
    import local_settings
except:
    pass

OwnerDisplayName: Arnar Yngvason


问:
How to prevent deep indentations?
What steps and measures can I take to prevent deep indentations in my code?</p>

答: I didn't believe it myself, but according to Code Complete this is an appropriate place to use break (if your team is on board).  I'd imagine this is more acceptable with C++ programmers though, where break used in switch statements than it is with Delphi programmers where break is only used when you don't feel like writing a while loop.

Title: How to prevent deep indentations?


问:
Good interview programming projects
I'm looking for some small programming projects that I can give potential employees to gauge their programming abilities. These will be programmers straight out of college. I'm looking for projects that would take someone a couple of hours and they would email back their answers post-interview.

One example would be to take this paragraph of text and return a list of alphabetized unique words. After each word tell me how many times the word appeared and in what sentance(s) the word appreared in.

Anyone have any good suggestions?

答:
In order to ask people to complete a project, you should have a specific set of skills that you want to evaluate in mind and design the project to test those skills.

One example would be to take this paragraph of text and return a list
  of alphabetized unique words. After each word tell me how many times
  the word appeared and in what sentance(s) the word appreared in.

What are you looking for with this question? How many ways are there to solve it, and what does each approach tell you about the person that wrote the answer? Are the skills demonstrated by an effective answer to this question the same skills that are most important to your business?

I don't want the answers to these questions; I just want you to have thought about the answers before you subject a group of candidates to your process. If you know what skills you're looking for, creating a question to look for those skills isn't hard. If you use someone else's question without a thorough understanding of what it was designed to evaluate (if anything), you're really just fooling yourself and wasting everybody's time.

Title: Good interview programming projects


问:
How can one manage thousands of IF...THEN...ELSE rules?
I am considering building an application, which, at its core, would consist of thousands of if...then...else statements. The purpose of the application is to be able to predict how cows move around in any landscape. They are affected by things like the sun, wind, food source, sudden events etc.

How can such an application be managed? I imagine that after a few hundred IF-statements, it would be as good as unpredictable how the program would react and debugging what lead to a certain reaction would mean that one would have to traverse the whole IF-statement tree every time.

I have read a bit about rules engines, but I do not see how they would get around this complexity.

答:
Use OOP. How about create a bunch of classes that handle the base conditions and run random methods to simulate what you are doing.

Get a programmer to help.

```<code>class COW_METHODS {

    Function = array('Action1','Action2',....'ActionX');

    function doAction() {
       execute(Function[random(1,5000]);
    }

    function execute(DynamicFunction) {
        exec(DynamicFunction());
    }

    Function Action1() {
        turnRight();
        eatGrass();
    }
    /*  keep adding functions for COW Methods ...  etc  */
    /*  and add classes for conditions inherit them as needed  */
    /*  keep an object to define conditions =  Singleton etc.  */
}
</code>```

Body:
Use OOP. How about create a bunch of classes that handle the base conditions and run random methods to simulate what you are doing.

Get a programmer to help.

class COW_METHODS {

    Function = array('Action1','Action2',....'ActionX');

    function doAction() {
       execute(Function[random(1,5000]);
    }

    function execute(DynamicFunction) {
        exec(DynamicFunction());
    }

    Function Action1() {
        turnRight();
        eatGrass();
    }
    /*  keep adding functions for COW Methods ...  etc  */
    /*  and add classes for conditions inherit them as needed  */
    /*  keep an object to define conditions =  Singleton etc.  */
}


问:
Choosing the type of Index Variables
We use Integer type represent index variables most of the time. But in some situations, we're forced to choose

```<code>std::vector<int> vec;
....

for(int i = 0; i < vec.size(); ++i)
....
</code>```

This will cause the compiler to raise the warning that mixed use of signed/unsigned variables. if I make the index variable as for( size_t i = 0; i < vec.size(); i++ ), (or an unsigned int )it will sort out the issues.

When it come more specific to use windows types, most of the Windows APIs are dealing with DWORD (which typedef-ed as unsigned long).

So when I use similar iteration, will again cause the same warning. Now if I rewrite it as

```<code>DWORD dwCount;
....

for(DWORD i = 0; i < dwCount; ++i)
....
</code>```

I find this a bit weird. It might be the problem withe perceptions.

I agree that we are supposed to use the same type of index variable to avoid the range problems can happen with the index variables. For e.g if we're using

```<code>_int64 i64Count; //
....

for(_int64 i = 0; i < i64Count; ++i)
....
</code>```

But in the case of DWORD, or unsigned integers, are there any problems in rewriting it as

```<code>for(int i = 0; (size_t)i < vec.size(); ++i)
</code>```

How most of the people are working with similar issues?

答: I use a cast to int, as in for (int i = 0; i < (int)v.size(); ++i). Yes, it's ugly. I blame it on the stupid design of the standard library where they decided to use unsigned integers to represent sizes. (In order to.. what? extend the range by one bit?)

Title: Choosing the type of Index Variables


问:
Which language and GUI toolkit would you use for a prototype program?
Suppose, I have an idea and I have to put it into code quickly. And then I am presenting it to someone who is not so computer savvy. Which language should I use for quick and dirty coding? And which GUI toolkit should I use so that the the computer semi-literate find it easy to use (read shiny-eye-candy). It is a desktop application.</p>

答:
You could use an application to draw mockups instead of writing code. Like Balsamiq Mockups or equivalent.

Using Mockups feels like drawing, but because it’s digital, you can tweak and rearrange easily. Teams can come up with a design and iterate over it in real-time in the course of a meeting.


问:
Do programmers possess the means of production?
I was listening to The Servile State by Hilare Belloc this morning and pondering whether or not I possessed the means of production, as did the peasant of the Middle Ages; as did not his descendants after the oligarchs of England forced him into servitude.

The means of production was the arable land that the serf was seated on, which, even though not legally his, was illegal to evict him from.

So, as programmers, with the hitherto unknown supply of free tools and resources, have we reclaimed as a class of workers, unlike any others, the means of production? Given the chance, a midrange PC and a stable internet connection, could we not each of us be wholly self-sufficient and not just wage-earners?

答:
To expand on Jeremy's answer a bit, the important distinction lies between labor and capital.  Labor is simply the blood, sweat, and tears you put into making a good or service that is sold on the market.  Capital, on the other hand, is an productive property (tools, raw resources, land, IP, etc.) and liquid assets (i.e. money) that is converted by means of labor into the aforementioned good or service.  In a modern economic relationship, a corporation (i.e. it's owners/investors) will provide the capital (or "means of production") and the employees provide the labor.  While there is no formula for determining how much of the sold value a given good or service should go to those providing the capital and those providing the labor, Capitalist societies have generally favored those who own capital (no surprise here).

However, Belloc advocates a society in which most people provide both the capital and the labor for the goods and services they sell.  This is what is meant by "self-sufficiency" in this context.  You are self-sufficient if you own everything you need to make and sell sell a viable product on the market.  Furthermore, since ownership is what provides one with economic power, a person who owns all aspects of production has the resources to ensure they are not abused in economic interactions.  An employer will need to pay you more than you could earn with your own resources before you will work for them, and clients will honor their contracts when they know you have the resources and the will to take them to court should they refuse. One is still dependent upon the web of economic interactions that make up the market, but one's ability to participate effectively is more secure.

In the context of software, this would entail something like a start-up or independent contractor.  I know people who do this, and the low barriers to entry of software development make this much easier to do than many other fields.  Even those of us who work for an employer still do fairly well, but as skilled labor in a high demand market we have a fair bit of economic leverage.  Even so, we employees don't have the same independence or power as we could.  The main reason we don't is that we are too afraid.  There are many barriers to entry to independent producers of all kinds in the forms of laws, taxes, and regulations which are often championed by big businesses and signed into law by our government.  Beyond the rational concerns, there is also the cultural image we have from the height of American capitalism.  The notion that getting a good job (perhaps after getting a degree) and working hard will provide you with all the economic stability you will ever need.  Despite the fact that the real wage has not kept pace with worker productivity for the past 40 years (forcing most families to be 2-income out of necessity, never mind women's rights) most people didn't begin to realize the sham until the recession.

The fact of the matter is that our form of capitalism is one of boom and bust cycles, and we will never be secure so long as the failures of a few "too-big-to-fail" companies determine the livelihood of millions and billions of people.  If our economy was a sever farm I don't think it would even have better up-time that the PlayStation Network.  Frankly we need better load balancing and redundancy.


问:
What is the difference between the Controller in MVC and ViewModel in MVVM?
I can't see the difference between MVC and MVVM clearly. I feel the Command in a ViewModel is just like the Action method in a Controller. And both the Controller and ViewModel will notify the View to refresh itself after modifying the state of the Model through Data Binding. What is the main difference between the two patterns?</p>

答:
The controller and the ViewModel differ in various ways.

In MVC the Controller knows the view, it can change the View. It also knows the Model and can call it. In MVVM a ViewModel is an abstract representation of the View and does not know the concrete UI, it wraps the Model in a way so that it can be displayed as desired.

In classical MVC, a controller is just a strategy of the View to interact with the Model. In fact, sometimes a Controller isn't even necessary. In MVVM you don't need it, as you can have different ViewModels for the same View if you need different behaviours. In MVC you could have for example a ReadOnlyController or an AdminController to communicate with the Model. In MVVM you could just have two ViewModels and you choose the one you need for the View.

But they do have some similarities. In both patterns, the View is an observer. In classical MVC, the view is an observer of the model, in MVVM it's an observer of the ViewModel.

Both patterns are meant to provide a separation of concerns. MVVM primarily aims to provide an abstraction of the View, completely independent of the UI technology in use. MVC does not go that far. It's primary focus is on separation of concerns, so that you don't put business logic (the Model) into the view.

You might also find this answer of mine to a similar question helpful.

At last, I should say that both patterns belong to the same family. MVP, of which MVVM is a descendant is a sibling of MVC. If you want to know more follow this link to Martin Fowler's website, he explains everyting in detail.


问:
"It was working yesterday, I swear!" What can you do?
When you arrive in the morning, you find that your software does not work anymore, even though it did when you left yesterday evening.

What do you do? What do you check first? What do you do to stop being angry and start working on your problem? Do you blame your colleagues and go directly to them? What can be done to avoid being in such a situation?

答:
Trying to find someone to pass the blame is unconstructive and does not solve problems. Don't do it.

If something worked yesterday and does not work now, then either you have non-deterministic behavior (like a race condition) and having it work yesterday was just luck, or something has changed between then and now, and you need to find out what it is.

How exactly you find out which is the case and how it can be fixed depends on the specifics of the situation, but it always helps to be methodical in eliminating causes, i.e. don't change 5 things at once and stop looking if that helps - find out which specific thing caused the problem, and perhaps write down how to fix it so you can look it up when it happens again 3 weeks from now.

Using the appropriate diagnostic tools (debugger, profiler, network analysis tools) can also make a big difference.


答:
Use version control. Do a diff, or use your VCS' blame functionality.:

diff: Every VCS. Shows you the differences of, uhm, different versions

blame: for example git. Shows you on a line by line basis who has changed what

If there is no version control, apart from it being your own or your boss's fault, you can look at the change dates of files and possibly look into your OS' logging facilities.

Apart from that: Recompile everything, make sure to also recompile auxiliary libraries.

Of course: If you've found the source of error, stay calm, ask for why a change was made, explain your problem, and propose a solution that makes you both happy. Don't shout at her/him, that would be poison to your productivity.

If there are no changes at all, it's time to see what has changed on the system. E.g., recently Mac OS computers have updated to a new version of Apache which has driven some configurations invalid.

Title: "It was working yesterday, I swear!" What can you do?

Body:
When you arrive in the morning, you find that your software does not work anymore, even though it did when you left yesterday evening.

What do you do? What do you check first? What do you do to stop being angry and start working on your problem? Do you blame your colleagues and go directly to them? What can be done to avoid being in such a situation?


答:
Fix the bug (however you normally do). Then if you find who caused it send them a polite email letting them know what went wrong.

Every coder makes mistakes and if you start blaming then it will seriously backfire the next time you do the same thing. (possibly even this bug was yours)

Its only if you suspect them of being reguarly careless should you make a big deal out of a couple of bugs.


问:
Multiple Joins or Simple Readable Database Calls
Curious how other developers feel about this. I come across some pretty nasty sql joins, as we all do I'm sure. I would prefer making more database calls for the sake of readability and simplicity rather than have a large SQL statement to maintain; about 3 - 4 joins. For the performance argument, I will give up a little performance for readability.

For example: make the first call, filter the data, and then query the second table, and so on

What is your preference?

答:
Pro tip : SQL queries can be commented to help understand how they work. The same tip applies with regular expressions.

If you think multiple queries are better than one big (well written) one, you should try it with a RDMS server which is not running on the same machine than your application server.

OwnerDisplayName: Scott Radcliff


答:
Given the chance, a midrange PC and a stable internet connection,
  could we not each of us be wholly self sufficient and not just wage
  earners?

"self sufficiency" in a world where division of labor reigns is neither possible nor (IMHO) desirable. That being said, and to answer to the question whether a programmer could be an independent entrepeneur, of course, yes.

But note also, that the products of a programmer have a property that other products do not have: They can be easily copied. Therefore, in a hypothetical free market order, a free programmer had to devote most of his time to devise strategies how he can sell software profitably. This, again, is an opportunity for division of labor and for forming firms. Therefore, the lonely, independent programmer is not very likely to survive.

Title: Do programmers possess the means of production?

Body:
I was listening to The Servile State by Hilare Belloc this morning and pondering whether or not I possessed the means of production, as did the peasant of the Middle Ages; as did not his descendants after the oligarchs of England forced him into servitude.

The means of production was the arable land that the serf was seated on, which, even though not legally his, was illegal to evict him from.

So, as programmers, with the hitherto unknown supply of free tools and resources, have we reclaimed as a class of workers, unlike any others, the means of production? Given the chance, a midrange PC and a stable internet connection, could we not each of us be wholly self-sufficient and not just wage-earners?


问:
How do you prevent the piracy of your software?
Is it still worth it to protect our software against piracy? Are there reasonably effective ways to prevent or at least make piracy difficult?</p>

答:
Don't spend much work on this, and don't make it intrusive.

There are two layers of copy protection that can possibly be worthwhile.  One is to prevent the casual user from copying it, and one is to prevent anybody from copying it.  There's nothing in between, since if any one person can crack your copy protection all the dedicated pirates in the world will have a copy.  The second level is impossible, so don't even try.  The first may have some value.

If you make the copy protection annoying, the pirate sites will have a better version available.  Many people buy a legit copy of software, and then download an illegit to actually use.  I really don't think you want to encourage honest people to download your stuff from pirate sites, and you don't want to annoy your paying customers too much.

You should stop worrying about piracy per se.  For stand-alone service, pirates take nothing from you.  Seriously.  You still have everything you had before.  What they might to is deprive you of possible sales.  In other words, they can do nothing to you that an influential reviewer can't.

What you should be concerned about is revenue, and increasing the number of sales.  Piracy can actually help that, by giving people some free trials and experience.  Many people will buy the stuff they actually use.  Some people attribute some of Microsoft's success to large numbers of people illicitly using their software.  They're better off in the long run with hundreds of millions of Chinese using illegally copied Windows than perfectly legal Linux.

Don't pay attention to the number of illegitimate copies.  They aren't, for the most part, lost sales.  Pirates tend to accumulate large quantities of software they barely use, far beyond their ability to buy.  Pay attention to your actual sales.


答:
Presumably if it's no longer working, you have identified the symptoms of it not working, ie, it hangs, or throws back a particular error dialog to the user.

If the sole description of the problem is "it's not working", the first thing you need to do is gather more information on the symptoms of the problem.

Then you start looking for possible causes, either via logs or attempted recreation of the problem or a combination of both - depends on how your system is set up I guess.

Then you start ruling them out.


答:
...you run regression tests and focus on those that fail.

Actually is what you forgot to do yesterday before leaving, it happens.

You don't have any? Ok.. what where you saying? Blaming? Well...  that might work, then


问:
Composition of a dev team
I'm in a team of fifteen people and the team is in transition after a few changes of management. The current line of management is pushing for an agile approach to developing software but without providing any lead. The team suffers from a big communication problem both inside and with other departments in the company who are our customers.

Management has recently created a sub-team composed by the technical specialists. They have great knowledge of the code base but have been in the company for up to ten years and are not so open to change. There goal is to provide technical direction.

I've joined the team in the last six months. I have a good six years experience developing different software but don't have the same knowledge of the code base as others. I have good communication and organisation skills and can relate to the customers easily.

The company's focus is to deliver innovative new products, but based on my observations we break down in project organisation (we seem to lose focus of the customer, get buried in the code base and misinterpret requirements).

I think I can provide direction in delivering projects with a good focus on the customer, however I don't hold the same technical expertise as the technical specialist team. I also think I'm the only one with previous agile experience in the team.

I've got two questions:

Is there room in a dev team for technical specialists and those that are good at delivering and making the customer happy, i.e the two working in tandem with each other?

Do you need to be a technical specialist to lead a dev project team?

答:
A team is a set of people where each one may have his own purpose based on his own strong points and competencies. There is nothing wrong in a team where technical specialists and people who are oriented more to communication than to technical aspects work side by side.

Of course, it requires a good organization and a mutual respect. There is a risk that people with large technical background and a good knowledge of the codebase will use their codebase knowledge and their technical skills to consider themselves superior, smarter or whatsoever, and try to force everyone to agree with their decisions.

Some situations can make this risk higher. Examples:

having one "guru" in a small team and constantly treating him as the best of the best. For example if a developer has an opinion, and the guru has another opinion, the wrong thing for the management (project manager, director, etc.) is to say: "he's a guru, so do what he says and shut up" (or, in a more polite form: "He has enough experience and he knows the codebase well, so trust him").

having a separate team of technical specialists (is it actually the case in your company?), for the same reason: if you isolate a group of people and consider them publicly as the best of the best, they may start to neglect the opinions of people who are not part of the team.

As for your second question, you need to have enough background to lead a team of developers. Otherwise, not only you will fail to understand what are they doing, but they will also have a bad impression of being lead by an inexperienced person, and will avoid asking you for questions.

This being said, no, you don't have to be a technical specialist. It's a benefit, but if I have to choose between a person who has good communication skills but lacks some technical ones, and a guru who have no communication skills at all, I'll always choose the first one.

Title: Composition of a dev team


问:
Limitations of copy/cut paste functions in System.IO
I'm developing a desktop application (a File Manager) in C#.

For copy/cut and paste operations I will use the default methods in .NET like

```<code>System.IO.File.Copy()
System.IO.File.Move()
</code>```

Are there any limitations of these methods that I should know about ? and if there are, what are the alternatives of these methods ? (win32 API maybe)

答:
Among the things that you have to watch for:

0-Invalid target path name (characters not allowed, etc.)

1-Long file names for the target path

2-Concurrency problems

3-Target path availability

4-Security

5-File/Directory may be readonly (in case of Cut)

6-Hidden files


答:
There is a known limitation of 259 characters, since .NET Framework does not support UNC paths. In this case, you have to use native calls.

There are probably other limitations, but, well, you have to be more specific in your question, since Programmers.SE is not a place for "do my work for me"-style questions.

Title: Limitations of copy/cut paste functions in System.IO

Body:
I'm developing a desktop application (a File Manager) in C#.

For copy/cut and paste operations I will use the default methods in .NET like

```<code>System.IO.File.Copy()
System.IO.File.Move()
</code>```

Are there any limitations of these methods that I should know about ? and if there are, what are the alternatives of these methods ? (win32 API maybe)


答: A kinda short answer (to write) but kinda long to get the gist of it: Why Programs Fail: A Guide to Systematic Debugging by Andreas Zeller (which might look a bit too academic but it's not)</p>


答:
The responsibilities of leading a dev team can vary a lot, ranging from assigning tasks, approving code for production, designing the archictecture, deciding about planning figures or training requirements etc., up to more mundane tasks like granting vacation requests. While you can delegate some of the tasks to members of the team, you will have a hard time leading such a team if you lack expertise in more than some categories. Understanding what the team does and how it does it is important.

From your question I gathered your main concern is that the team lacks in communication skills, so coordination with other departments (or customers) and tracking requirements is a problem. It seems your team would benefit from adding a project manager or liaison manager to the team. That does not imply such a manager needs to be the overall team lead or a technical director. His work forcus is on building a bridge between the communication partners in distress and to translate between them, not necessarily to lead them.

Title: Composition of a dev team

Body:
I'm in a team of fifteen people and the team is in transition after a few changes of management. The current line of management is pushing for an agile approach to developing software but without providing any lead. The team suffers from a big communication problem both inside and with other departments in the company who are our customers.

Management has recently created a sub-team composed by the technical specialists. They have great knowledge of the code base but have been in the company for up to ten years and are not so open to change. There goal is to provide technical direction.

I've joined the team in the last six months. I have a good six years experience developing different software but don't have the same knowledge of the code base as others. I have good communication and organisation skills and can relate to the customers easily.

The company's focus is to deliver innovative new products, but based on my observations we break down in project organisation (we seem to lose focus of the customer, get buried in the code base and misinterpret requirements).

I think I can provide direction in delivering projects with a good focus on the customer, however I don't hold the same technical expertise as the technical specialist team. I also think I'm the only one with previous agile experience in the team.

I've got two questions:

Is there room in a dev team for technical specialists and those that are good at delivering and making the customer happy, i.e the two working in tandem with each other?

Do you need to be a technical specialist to lead a dev project team?


答:
The usual suspects are:

You thought it worked yesterday, but after a full day of work you were too blind to realize that it didn't work.

This morning you no longer can refer to what was in IDE cache memory yesterday.

The workstation has rebooted last night or a nightly maintenance operation cleared /tmp directories.

Something has changed in the code base: check whether someone (possibly yourself) has commited changes between your last compile of yesterday and your last compile of today.

Something has changed in the support libraries: check whether those libraries have been recompiled or upgraded. The cause may be inside the project for specific libraries or outside if a new version of an apparently independent package has been deployed.

Something has changed in the testing environment: new version of a virtual machine, a stub that has been modified, changes in a remote database server...

Something has changed in the compilation chain: changes in Makefiles, new version of IDE, of compiler, of standard libraries...


问:
Videos on Unit Testing
I've been searching for good presentations (slides+audio or video preferred) on Unit Testing but all I seem to find are books and blog posts. The presentation should not be longer than 50 minutes since it will be shown at a brown-bag lunch. General concepts or how to do it on the .NET-platform is what I'm looking for.

Can you recommend a presentation that fits that description?

答:
Instead of a Powerpoint presentation, here is a 6 part video of Brett L. Schuchert

http://vimeo.com/album/210446

which gives you a live demonstration of unit testing as part of "test driven development". I think you don't need all 6 of them, so you can tailor it to your 50 minutes spec. IMHO very impressive.

Title: Videos on Unit Testing


答:
Fantastic.

Your team is huge,

the methodology looks quite wrong for it and chosen for its buzzword value,

the most knowledgeable ones have been practically removed from the team (instead of dispersed into balanced sub teams where they can contribute and lead) and sent on a magical quest on deep thinking island

Those three elements all lead to a single conclusion: your manager is acting at random.

...and you worry about the customer? I mean, the customer is the last of your concerns here, (and yes, it shouldn't come last, on that we probably agree) but what I see here is: (pardon my french)

a big fan,

a pile of manure slowly falling onto it,

and you in the middle, trying to toss your weight all the way into the fan.

Stay off the way of the old ones and their opinions, and take notes of how they and those opinions, affect your work, and the project, how, and when: heavy reorganization will come, and you'll want to have referentiable facts to support your position and role in the situation.

Title: Composition of a dev team


答:
1) If it's not working today, it wasn't working yesterday either.

You thought it was working, but it wasn't.

2) There is a problem, and it must be solved.

Don't think about who's responsible for this or about blaming others.

If nothing has changed between yesterday and today (like I presume reading your question), it means you should do a better job at testing your code before actually state it's working.

To avoid this situation you have to do proper Testing and Debugging.

Define "working" and test the boundaries of your code routines.

Try to become one of the users who will use your program or code functionalities.

Push your code to the allowed limits and beyond, and actually check if it breaks.

One way of doing this is having an automated set of extensive tests run during the night, so that the day after you can check if something went wrong and fix the problems.


问:
Why so many layers with domainobject like objects in an application?
Take a typical Line-of-Business Silverlight applicatioin for example.First,We have a  Product table in database,which has fields of ID,Name,Price,etc;

Then, on the server side,we should have a Product Entity class in the Data Access Layer,which has properties of ID,Name,Price,etc;

Then, we should have a Product DTO Class with properties of ID,Name,Price,etc;
Then, on the client(Silverlight) side, we have the Product DTO class with properties of ID,Name,Price,etc as Data Contract to communicate with the server;

Then, We should have a Product ViewModel Class,which alse has the properties of ID,Name,Price,etc to binding with the View.

Don't these many layers of similar objects violate the Don't Repeat Yourself principle?

What if the Business Domain Model itself faces frequent change? For example, the customer wants to remove/add new properties to the product, which will cause all layers to change its code.

We introduce an addtional DAL layer in the assumption that the underlying database will be changed,but in the real world, the business model itself changes far more frequently than data access or presentation logic.

答:
Doesn't the so many layers of Domain-like Object violate the Don't
  Repeat Yourself principle?

Yes, it does. That's why you should have code-generators to create the necessary classes automatically from metadata. You just maintain the metadata in one place and create the classes automatically when necessary. C#'s partial classes can greatly aid such tasks for example, so you have a place for customization. Other patterns can sometimes be useful to avoid unecessary repitition: Dynamic proxies or wrappers for example.

Then, We should have a Product ViewModel Class,which alse has the
  properties of ID,Name,Price,etc to binding with the View.

Well, in a ViewModel you can always just have your entity and then bind directly to it. Strictly speaking, it violates the Law of Demeter but in such cases that is acceptable. Just expose the entity and do not repeat its fields. Be pragmatic.

Then, on the client(Silverlight) side, we have the Product DTO class
  with properties of ID,Name,Price,etc as Data Contract to communicate
  with the server;

You usually have the DTO classes in an assembly that both, the server and the client can reference. So you won't always need to duplicate the classes.

Also: Be careful with the term domain-like object. Domain objects are the pure objects of the business domain and not technical auxiliaries of the others layers.

Why so many layers with domainobject like objects in an application?

Finally, to answer the question the heading: Technical necessities. If there's a business logical field, it simply needs to exist in various forms. If it's going to be persisted there needs to be a structure that can hold it permanently. This structure must be defined in one way or another. Maybe other applications are going to work with that data, too. Then it needs to be independent of already defined structures in your application. Same thing for DTOs. They're build to communicate data between (sub-)systems.


问:
How important are PHP notices really?
I recently turned all possible error-messages on with error_reporting(-1);, on my PHP project. Of course, right away I got alot of messages. For example:

Notice: Undefined variable: foo in /.../file.php on line 205

So I started updating my code to get rid of all the notices. Mostly, by adding isset($foo) and making the $foo = NULL;

So, I'm wondering. How important are these notices really? I mean, if the $foo variable is not set, then it should be false/null/not-set by default..so technically the code works?!

If I would get rid of all notices, then does it make the process faster or slow it down (because I'm adding more code, isset($foo), $foo = NULL etc)? How do you guys deal with these notices, or do you even pay attention to them?

I guess, the most important question is: Should the code be written so strict, that it would never generate any notices or warnings?

答:
My general approach take is to enable notices on development machine and disable them on live servers. Assuming that you do not know, php 5 has a new error level E_STRICT.
As for fixing the notice messages: It is up to you. You cannot know if a notice message will cause an error unless you look at the code. If you are taking time to look up the code, you might as well fix them.</p>

Title: How important are PHP notices really?


答:
I was very, very impressed with the Full Throttle: TDD video by Rob Ronery and Brad Wilson. It's not free, but it'll be one the best $12 you'll ever spend. The video is a little longer than 50 minutes - I believe it's 65 minutes in total - so maybe you can provide an extra tiny brown bag containing dessert :-)

A snippet from Rob Conery's blog about the video:

The premise was that Brad needed to create a subscription billing system that fires off periodic billings and also updates the Customer record - using C# and xUnit.net (Brad’s testing framework he created with Jim Newkirk). To many, this sounds simple. To those that have implemented such a thing - it’s anything but.

The thing that I really, really enjoyed about this episode is that I pushed Brad just enough to remove the “demo veneer” - I gave him a curveball about 30 minutes in where I said “Oh yeah… did I mention that we also do X?” - and he had to adjust.

When you have a mess of tests that assume one thing, then you have to shift to another - it’s a pain in the ass. But Brad handled it amazingly well - taking the opportunity to push more structure into his testing process, then one by one “transition” his old tests into the new approach.

We worked the whole hour inside a single code file - and I’d never seen anyone do that before. Sure, I’ve created a class right there inside the code - but watching Brad spin up class after class, then rename, then delete, then completely restructure his tests… it was very, very interesting.

They always say TDD is a “design process” - yet I’ve never seen it used in a truly “design-y” way - like a painter might toss color after color on a canvas until it looks/feel just right. And that’s exactly how it felt watching him.

About 15 minutes in Brad mentions that “I leave a class in the test file until it’s ready to go public” - meaning that he has enough tests to justify his design decisions. A concept I’d never really thought about before - sort of like using the test file as a bit of a “womb”.

He “felt” his way through the creation of the billing system - talking to himself the whole time and creating something rather interesting and pretty damn close to what we ended up with after close to 3 years being live.

Title: Videos on Unit Testing

Body:
I've been searching for good presentations (slides+audio or video preferred) on Unit Testing but all I seem to find are books and blog posts. The presentation should not be longer than 50 minutes since it will be shown at a brown-bag lunch. General concepts or how to do it on the .NET-platform is what I'm looking for.

Can you recommend a presentation that fits that description?