问:
Is there any better approach to shortest path finding within a (vehicular) traffic network?
Dear fellow programmers,

We're developing software which simulates vehicular traffic.
Part of the process called "assignment" is concerned with assigning vehicles to their routes and has to use some kind of shortest-path-finding algorithm.

Traditionally, people do this with Dijkstra's, and certain scientific literature seems to indicate that A* and other alternatives don't give any significant improvement, perhaps due to the nature of the graph.

Hence, we're using Dijkstra's as well. A small problem arose in that, if you treat traffic links (spans of roads between intersections) as edges and intersections as nodes, you can't get a classic uni-directional graph:
when approaching an intersection, where you can turn frequently depends on where you're coming from, whereas in a traditional graph you can take any edge from a node.

We resolved this problem quite easily by representing a link-intersection pair (call it "lath") as a node. Since you'd need to traverse a link to get to any subsequent "lath", or point of choice, an edge would then be defined as this traversal, and you get a typical graph.

The results then are stored in a simple table, N x N, where N is the number of "laths."

Here's the (unavoidable?) drawback. If a typical network for our simulation can have, say, 2000 intersections, it will have somewhere around 6000 links, i.e. N = 3V. Obviously, if counted in terms of intersections (V), we're now up to O(log(3V)*(3V + E)).

You might argue that 3 (or 9) is a constant factor, but from the practical standpoint, it does slow things down quite a bit, and increases storage space to 3V x 3V.

Does anyone have any idea how we can restructure this to improve performance?
Not necessarily any alternative algorithm, perhaps reshape the data structures to fit a graph in some other way?

答:
Dijkstra's finds the shortest path between a given node and all other nodes, so I expect it would be more expensive than A*.  However, it looks like you're trying to pre-compute the cost & path from any node to any other?  Then Dijkstra's is the way to go.

As for a simpler representation, a few things come to mind:

At many intersections, you can come & leave any way you want.  It's only a a subset that you have restrictions like "no left turn."  So you could use the "laths" only for intersections where you actually need them.  That should greatly reduce the size right there.

You could do this automatically by looking for "equivalent laths" and combining them.  Two laths are equivalent if all the links coming out are the same.  E.g. if "Intersection X coming from the West" and "Intersection X coming from the South" both lead to the same set of other nodes, with the same cost, then just merge them into a single node.

Are you sure you need/want to precompute the best path, instead of computing it online?  Video games typically compute these things online.

Also, how are you representing the paths?  In your matrix, you only need to represent the first link in the path.  For example, to get from Bob's house to Bob's work, you only need to know the first link, since when they get there, you can now look in your matrix for how to get from the first link to Bob's work, which will give you the second link, etc.


问:
How to explain that sample size does not influence project length
We have big enterprise projects they normally involve copying data from a source database to a destination database and then setting up a number of additional applications that sync this data etc.

The last project contained 250,000 items (rows of data). The next project will only contain 4,000 items. Project managers / business people believe the project should be 1/10 the time to complete because its only a fraction of the size of the last project.

What is a good analogy I can use to explain that writing code to transfer data from one system to another takes the same amount regardless of the number items - writing it for 1 item or for 100,000,000 will take roughly the same amount of time from a programming point of view.

答:
I import hundreds of client files every week.

One thing I have found is that the small files generally take longer to develop the data import for because:

They are less likely to follow the rules (we have standard file
structures, I have never seen a small client give us the data in the
standard format that we ask for but large ones understand why that is
important)

They tend to have more data integrity issues especially if they are
coming from an Excel file rather than a database (where the large
files tend to come from) which already had data integrity rules built
in

They are less likely to be provided in the same format every time.

We have found that we save a lot of time in development by building a parent child SSIS package that has a standard child process and any necessary manipulation to get the data in the form of the standard can be done in the parent. That way, it becomes less an issue of how many records when we do an estimate but an issue of how close to the stanrdard is the file we are getting. We now don't get as many complaints when smaller things take longer to develop because they don't fit the standard.

ContentLicense: CC BY-SA 3.0


问:
Would this be considered dependency injection?
Would this be considered dependency injection, or delegation or object collaboration?

https://gist.github.com/3428071

答:
The ors in your question make it sound like those three things are mutually exclusive.

This is a form of dependency injection, albeit a non-conventional form of it. In the end, you are injecting Logger_model into User_model, so it is injection of a dependency. It is also true to say that Logger_model is a collaborator in this instance. And it is also true that User_model delegates logging to Logging_model.

So, basically, it's all of the above.


问:
Robot arm sample problem in Skiena's "Algorithm Design Manual" seems to be invalid to me
I'm reading Skiena's Algorithm Design Manual and there is a problem on page 5, "Robot Tour Optimisation", where he says this about the sample problem:
"Suppose we are given a robot arm equipped with a tool, say a soldering iron. In manufacturing circuit boards, all the chips and other components must be fastened onto the substrate. More specifically, each chip has a set of contact points that must be soldered to the board. To program the robot arm for this job, we must first construct an ordering of the contact points so the robot visits the first contact point, second, etc..."

"We must first construct an ordering" - that seems strange to me.

Because, well, every chip has certain number of pins and they're numbered and their position is documented, look here:

I mean that chip doesn't have a set of pins, it have an ordered list of pins, ok, it doesn't but it has very specific dimensions and specific order of pins on each side so their precise position (and order) can be easily calculated.

Maybe unrelated, but probably IRL the board is moving on some sort of clamp in X, Y dimension and soldering iron only goes up and down.

The simplest problem I can give as an example of Robot Optimisation tour is a pizza courier  who rides a car and needs to visit all his clients (let's assume that traffic is near zero)  and returns to the restaraunt with as little  gasoline spent as possible. So he needs a tool (car navigator), that will solve this problem for him. And that navigation application needs to find the optimal route - so, it illustrates the problem.

Am I right that original problem illustration with robot arm is wrong?

答:
Before the robot can solder the pins, it must first know where the pins are, and it's probably more efficient to visit the pins in a specific sequence, than it is to visit them randomly. Hence, the ordering.

Remember, machines don't know anything except what you tell them, so if you want them to visit points in a specific sequence, you have to tell them what that sequence is, so it can perform the calculations to move the arm from one point to the next.

Note that the chip in your illustration is a surface-mount device; it is highly likely that it is soldered using a Vapor Phase or convection system, which solders all pins simultaneously without requiring a robotic arm.  It is therefore probably not a very good example.


答:
Writing a program is kind of like hiring a new employee. You have to teach them where to find the data, what to do with it, and how to give you the results. You have to keep an eye on them for a little while to make sure they're doing it right. It might take a little longer to train them if they have a complicated/important job or if they're going to do a very large amount of work, but it takes a substantial amount of time no matter what.

Many managers are familiar with the overhead involved in training a new employee, so this might make sense to them.

(the analogy breaks down insofar as your new employee is a superpowered robot who can get the job done in a trivial amount of time no matter how many records you throw at them, but hopefully you've made your point by then.)

Title: How to explain that sample size does not influence project length

Body:
We have big enterprise projects they normally involve copying data from a source database to a destination database and then setting up a number of additional applications that sync this data etc.

The last project contained 250,000 items (rows of data). The next project will only contain 4,000 items. Project managers / business people believe the project should be 1/10 the time to complete because its only a fraction of the size of the last project.

What is a good analogy I can use to explain that writing code to transfer data from one system to another takes the same amount regardless of the number items - writing it for 1 item or for 100,000,000 will take roughly the same amount of time from a programming point of view.


答:
It's true that pins on a chip are numbered.  But when figuring out the best order to solder the pins, the existing numbering isn't necessarily optimal.  When pins are laid out in a line around the edge, the given numbering is probably optimal.  But when you have some weird layout, like the layout in an x86 processor, it might not be.

In fact, the pins on such a processor aren't numbered, but referenced by row and column:

Title: Robot arm sample problem in Skiena's "Algorithm Design Manual" seems to be invalid to me

Body:
I'm reading Skiena's Algorithm Design Manual and there is a problem on page 5, "Robot Tour Optimisation", where he says this about the sample problem:
"Suppose we are given a robot arm equipped with a tool, say a soldering iron. In manufacturing circuit boards, all the chips and other components must be fastened onto the substrate. More specifically, each chip has a set of contact points that must be soldered to the board. To program the robot arm for this job, we must first construct an ordering of the contact points so the robot visits the first contact point, second, etc..."

"We must first construct an ordering" - that seems strange to me.

Because, well, every chip has certain number of pins and they're numbered and their position is documented, look here:

I mean that chip doesn't have a set of pins, it have an ordered list of pins, ok, it doesn't but it has very specific dimensions and specific order of pins on each side so their precise position (and order) can be easily calculated.

Maybe unrelated, but probably IRL the board is moving on some sort of clamp in X, Y dimension and soldering iron only goes up and down.

The simplest problem I can give as an example of Robot Optimisation tour is a pizza courier  who rides a car and needs to visit all his clients (let's assume that traffic is near zero)  and returns to the restaraunt with as little  gasoline spent as possible. So he needs a tool (car navigator), that will solve this problem for him. And that navigation application needs to find the optimal route - so, it illustrates the problem.

Am I right that original problem illustration with robot arm is wrong?


答: There are typically multiple chips of varying sizes on the board. In what order do you move among the chips? Are you are assuming that the arm would finish soldering one chip before moving on to the next? It may require less motion of the robot arm to solder the pins on adjacent edges of neighboring chips before finishing the pins the far side.</p>


问:
Is it a good idea to design an architecture thinking that the User Interface classes can be replaced by a command line interface?
In Code Complete page 25, it's said that it's a good idea to be able to easily replace the regular user interface classes by a command line one.

Knowing its advantages for testing, what about the problems it may bring?

Will this extra work really pay off for web and mobile projects? What about small and medium projects; do the same rules apply?
What if it makes your design more complex?

答:
There's a different way of looking at things. Rather than assuming that a command line is the only way to go, why not assume that speech control might be used instead? An entirely different paradigm is required then.

Before Jobs took over Apple, very sophisticated voice control mechanisms were being explored. Apple squelched this in favor of things like Siri.

Sigh.

Popular and obvious aren't always "best."


问:
Is the 'C' in MVC really necessary?
I understand the role of the model and view in the Model-View-Controller pattern, but I have a hard time understanding why a controller is necessary.

Let's assume we're creating a chess program using an MVC approach; the game state should be the model, and the GUI should be the view. What exactly is the controller in this case?

Is it just a separate class that has all the functions that will be called when you, say, click on a tile? Why not just perform all the logic on the model in the view itself?

答: Document-View  (ie model view) is the standard model for the majority of Windows apps written in MFC so it must work for a lot of cases.</p>

Title: Is the 'C' in MVC really necessary?


问:
How to decide how backward-compatible my new Mac OS X application should be?
I'm currently contemplating writing an OS X version of my Windows software. My Windows application still supports Windows XP, and I know that if I drop support for it now, our customers will cry bloody murder.

I'm new to OS X development, and as I learn the technology, APIs, etc., I realized that if I'm going to provide comparable level of backward compatibility (e.g. down to OS X 10.5), I would not be able to use many things that look very useful and relevant in my case (ARC, XPC communications, many others). This is quite different from Windows, in my opinion, where there are very little changed between Windows XP and Windows 7 from desktop application developer's standpoint.

So, on one hand, it seems like a complete waste to stick to 2007 or 2009-level API in 2012. On the other hand, according to NetMarketShare report and Stat Owl report Mac OS X 10.5 and 10.6 market share is still 11% and 35%-40% respectively. However, I'm not sure if these older OS users are my target audience (buyers of software utilities) if they didn't bother to upgrade their OS...

My question: Are there any other reasons I should take into account when deciding if I target 10.5 or 10.6 or 10.7 for a new application?

答:
There is a pretty obvious approach here -- survey your customers and figure out what they are using and perhaps why they are stuck to that version. Upgrading OSX is relatively less painful than upgrading windows, I know lots of folks don't do it until there is something they need that the later version can handle that their version can't.

Aside from that I'd focus on the differences between these API versions. IE, if there is some large underlying system you need to use or reinvent which is only in 10.7+, go for it. If there aren't reasons to push the ball forward then why make it a blocking issue?


问:
Running software as a service using unmodified GPL(v2+) program as a core dependency: must the SaaS source code be released?
I'm designing a software as a service project which will only be accessed online. I may have a hard dependency on an executable which is covered by GNU GPL (v2 or later).

I understand that my code, if I were ever to distribute it, must be distributed under the GPL terms as well. I am pretty sure that running the service over the network is not conveying/distributing the code. Thus, am I correct in thinking that I may use the GPL dependency without having to disclose all my code?

Just so I can provide a concrete example: Let's say I'm designing on online document processing system, kind of like Google Docs. I want to be able to upload basically any file type into the system and have it get converted to whatever internal format. Instead of trying to scratch out a converter, I'd rather use an existing program I know about that allows for the conversion. This program is an executable with GNU GPL v2 (or later) licensing. Can I legally have a software-as-a-service without providing my source code?

答: From the description you have provided, the answer is "no, you don't have to disclose."  You are either relying upon the output of the GPL'd executable or you are treating it as a system, which are two exceptions to the viral nature of the GPL.  Dig into the GPL FAQ and you'll find your answers based upon the specifics of your scenario. </p>


答:
I think MVC is dumb, maybe in specific areas it works well but personally even websites i write are not suited to mvc. Theres a reason why you hear frontend, backend and never database-end or something-else-end

IMO there should be an API (backend) and the app which uses the API (frontend). I guess you could call the GET request the controller (which simply calls the backend api) and the html the view but i don't usually hear people talking about view as pure html nor model being backend API.

IMO everything should be a solid API. Actually they don't need to be solid (as in clean and well built) but its internals should remain private and the app/frontend/outside of the api should never get say the database connection nor be able to make raw queries.

Now if your code/design involves glue its fine. If in your chess game there is some markup you can edit to skin the GUI, the gui collects the coords/input and calls MovePiece(srcPosition, dstPostion) (which may return a bool or enum to say if it is a valid move or not) and your ok with all logic being in the model then sure call it MVC. However i'd still organize things by classes and APIs and make sure theres no kitchen-sink class that touches everything (nor any APIs to have to know about everything).

Title: Is the 'C' in MVC really necessary?

Body:
I understand the role of the model and view in the Model-View-Controller pattern, but I have a hard time understanding why a controller is necessary.

Let's assume we're creating a chess program using an MVC approach; the game state should be the model, and the GUI should be the view. What exactly is the controller in this case?

Is it just a separate class that has all the functions that will be called when you, say, click on a tile? Why not just perform all the logic on the model in the view itself?


问:
Is Object Oriented Programming a solution to complexity?
Do you think Object Oriented Programming is a solution to complexity. Why? This topic may be a bit controversial but my intentions to know the answer of Why from the experts here !</p>

答:
Object oriented programming is a way of representing a problem, nothing more, nothing less. It is, in and of itself, not any less complex than any other programming paradigm. A well designed OOP system manages and reduces complexity, but it is also very easy to design a system that is much more complex than necessary and gets in the way of everything.

As oft said of C++, OOP gives you enough rope to hang yourself.

ContentLicense: CC BY-SA 2.5


答:
IANAL but IMO the GPL do have a little ambiguity here (or interpretation). GPL gives you a lot of freedom when it comes to "usage", but it does it lots of limitation concerning "distribution of derivative works". First it's regarding use vs derivative works. If your code are only "using" the GPL software, you don't need to distribute your code that uses the GPL code (if you modify the GPLed code itself though, you still have to distribute that part of you are planning to distribute the changes), in the other hand if it's considered derivative work, then you do have to distribute your source code. One of the key points is whether your code runs in the same process address space to the GPLed code, the official GNU position is that if a program is linked to a GPLed code into the same process address space then it's considered a derivative work, but a process calling into GPL code that lives in separate process or separate machine, communicating through IPC (pipes, sockets, etc) may not fall under GPL depending in the nature of the communication (simple communication such as giving options and file names for the program to work on is considered usage, but exchanging complex internal format could makes it linking).

There's also the ambiguity whether providing a web service to allow people to use GPLed code is considered redistributing the software or just a way of using the software. I think most people consider that simply providing a web service does not fall under redistribution.

Best to ask the software author what they think of what you're doing. It's best to respect their interpretation instead of going on your own interpretation. At the very worst if it ever becomes a problem, you could argue that you've got explicit permission from the authors themselves or you would have a chance to find another more permissive library or negotiate an exception.

Title: Running software as a service using unmodified GPL(v2+) program as a core dependency: must the SaaS source code be released?

Body:
I'm designing a software as a service project which will only be accessed online. I may have a hard dependency on an executable which is covered by GNU GPL (v2 or later).

I understand that my code, if I were ever to distribute it, must be distributed under the GPL terms as well. I am pretty sure that running the service over the network is not conveying/distributing the code. Thus, am I correct in thinking that I may use the GPL dependency without having to disclose all my code?

Just so I can provide a concrete example: Let's say I'm designing on online document processing system, kind of like Google Docs. I want to be able to upload basically any file type into the system and have it get converted to whatever internal format. Instead of trying to scratch out a converter, I'd rather use an existing program I know about that allows for the conversion. This program is an executable with GNU GPL v2 (or later) licensing. Can I legally have a software-as-a-service without providing my source code?


问:
How should UI layer pass user input to BL layer?
I'm building an n-tier application, I have UI, BL, DAL & Entities (built from POCO) projects. (All projects have a reference to the Entities).

My question is - how should I pass user input from the UI to the BL, as a bunch of strings passed to the BL method and the BL will build the object from the parameters, or should I build the objects inside the UI submit_function and send objects as parameters?

EDIT: I wrote n-tier application, but what I actually meant was just layers.

答:
A service is an interface.  A method/function is an interface.  A service should be for overcoming changes to the physical layers, not logical layers.

You could even have a single logical layer that is split over several physical networks and communicates with itself. So services should not be a hard-line for splitting logical layers. They are for physical splits.

Now if you want your UI and BLL to have the flexibility to work whether on the same box or different, then go with a service. Otherwise it's not a sin to have a direct method call to the bll.


问:
Best Way To Bring C++ Into Objective-C Project
For an upcoming XCode iOS project I'm planning on writing my views and view controllers in Objective-C. My model will be provided to me in C++.

I am aware of 2 ways of using C++ in an objective-c project. They are described below. What are the pros and cons of each method. Is there any other recommended way, and what are its pros and cons?

-In C++ header files, use extern "C" declaration as described in Wikipedia.

-Wrapping C++ with an Objective-C++ as described by Rob Napier.

答:
I don't know much about Objective-C, but the extern "C" approach will only work if your C++ header files don't contain C++ classes, only C style structs and functions. If your model is written in C++, I guess this will not be the case, so I think you will have to try the second road.

extern "C" is intended to use C code in C++, not vice versa.


问:
Should I change the name of the WTFPL?
I'm using the WTFPL in my personal projects that I have published on GitHub.

Currently I'm using the license verbatim, but I have a suspicion that I shouldn't be leaving the third line:

```<code>Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
</code>```

in there, and instead should use my name instead of Sam's.

But the license is very confusing about this.

Half of the WTFPL site is about the WTFPL itself, so I thought that copyright statement might refer to a copyright on the license text itself, and not on the project that is using the license.

However, the site also says:

Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.

So would I have to change the name from "WTFPL" to something like "WTFPL-Domenic"?

答:
You can put your name there.

Sam Hocevar would say "do the fuck you want. isn't it clear enough?"

Title: Should I change the name of the WTFPL?


问:
What made object oriented programming successful?
What is that feature according to you that has made object oriented programming so much successful ?

Message Passing

Inheritance

Polymorphism

Encapsulation

Or some other feature that you may like to introduce.

Also I would like to know that what is the connection between Abstract Data type and Object Oriented programming?

答:
in simple words OOP is the key for re-usability and encapsulation that results in the production of large frameworks that makes the life easy for programmers in this era as the can just call the API's and do what day want most often.

as ur question is about the 4 features of OOP so you can say

Inheritance and 4. Encapsulation are the most important features and other two are very much necessary to achieve the first two

so  1. Message Passing and  3. Polymorphism are actually supporting 2. Inheritance and 4. Encapsulation.

Inheritance and 4. Encapsulation are key to success for OOP


问:
Should I continue to perform freelance work for customers who keep on demanding more without paying?
So a client comes to me and says it needs some work done. Basically 4 tasks, which I agreed to perform for a certain price. The customer creates the job offer (a fixed time and price job) on ODesk, I accept it, but it took some days and constant reminding for the customer to initiate a contract based on that job.

The problem is that the original task has been completed, the contract is still active, I have not been paid yet, the customer says he will pay when the project is completed, and until then, new tasks occur constantly, or changes to older tasks that require full re-doing of elements. For all of this the client promises payment. No updates from this client on ODesk, no new tasks there. I keep reminding the client about sorting out the administrative issues, but with no results. At the same time, the client pushes on continuing work, since the project is soon to be launched.

I don't know what to do.

If I refuse to perform any work without the bureaucracy, the project will be late. But it's not my fault, is it? I am scared that I might receive a negative feedback in this case, or something even worse.

If I drop out of this project I'm afraid I won't be getting even what I've earned.

If I continue like this, I'll be wasting a lot of time doing stuff similar to the stuff described here, but as a programmer (yes, it has already come to similar requests, for lots of hardcoded content).

How do I communicate with such clients in such situations? How do I avoid a conflict?

P.S. The client is a small company. Different people handle different aspects of this project, and everybody introduces their own changes to the original specs.

After 2 years: Wow! Very question! Much popular!

I decided to let everyone in on the ending of this story. I've confronted the customer, explained that I will not work until I get paid for what I did, and until a hourly contract is open. They paid me the next day and opened a contract. A fruitful, but short collaboration started. Everyone was happy. Except I didn't get any feedback.

答: oDesk has as dispute resolution team/policy. You can contact them including the details above especially about the extra tasks.</p>


答:
I'd suggest that the most important characteristic of object oriented programming is that of complexity management.

The human brain can only hold so many concepts at one time - the oft quoted limit of remembering 7+/-2 independent items comes to mind.

When I'm working on a 600kloc system at work, I can't hold the whole thing in my head at once. If I had to do that, I'd be limited to working on much smaller systems.

Fortunately, I don't have to. The various design patterns and other structures that we've used on that project mean that I don't have to deal with the entire system at once - I can pick up individual pieces and work on them, knowing that they fit into the wider application in well defined ways.

All of the important OO concepts provide ways to manage complexity.

Encapsulation - let me deal with an external API that provides me with various services, without worrying how those services are implemented.

Abstraction - let me concentrate on the essential characteristics and ignore what's not relevant.

Composition - let me reuse components that have already been built in new combinations

Polymorphism - let me ask for a service without worrying about how different objects might provide it in different ways.

Inheritance - let me reuse an interface or an implementation, providing only the pieces that are different from what has gone before.

Single Responsibility Principle - lets keep the purpose for each object clear and concise, so it's easy to reason about

Liskov Substitution Prinicple - let's not lay traps for each other by introducing odd dependencies

Open/Closed Principle - let's allow extension and modification in ways that don't require us to risk breaking existing code

Dependency Injection - let's take composition to the next level and assemble the components together much later.

Interface oriented development - let's take abstraction to the next level and only depend on the abstraction, never on a concrete implementation.

Title: What made object oriented programming successful?

Body:
What is that feature according to you that has made object oriented programming so much successful ?

Message Passing

Inheritance

Polymorphism

Encapsulation

Or some other feature that you may like to introduce.

Also I would like to know that what is the connection between Abstract Data type and Object Oriented programming?


答:
Your views and view controllers will need to be Objective-C, because of the frameworks. This much is given. The question then is where to put the bridge between your C++ code and your Objective-C code.

Firstly, I'd advise against wrapping the C++ code in C functions with an extern C {} linker convention. You've then given yourself two problems: how to handle the C++ classes and types from within C, and how to use the structured C interface from within Objective-C objects. Both of these problems are surmountable but you may as well not have to introduce them.

Three approaches seem possible:

write your application's logic and behaviour in C++, where certain of the classes have member fields that are Objective-C types so that you can interface with the frameworks. This approach is likely to run into "impedance mismatch" problems between the frameworks - which have a "don't call us, we'll call you" policy - and your own code which is trying to take control of the application's behaviour from outside the framework's ambit.

in your view controllers, keep references to C++ types as instance variables. Your view controller classes will be Objective-C++ files.

write Adapter or Façade classes in Objective-C++ that provide an Objective-C API and internally manage the C++ types. Your view controllers access the model exclusively via this layer.

Of these approaches, I would prefer the third. You separate the responsibilities of "managing the model" (in the C++ code), "displaying model content" (in the ObjC view controller classes) and "bridging C++ to ObjC" (in the adapter layer). You'll meet many developers who know ObjC but not C++ and vice versa, this approach makes it easiest for those developers to contribute to your codebase, whether they end up working with you or just trying to help you out on the web.

Title: Best Way To Bring C++ Into Objective-C Project

Body:
For an upcoming XCode iOS project I'm planning on writing my views and view controllers in Objective-C. My model will be provided to me in C++.

I am aware of 2 ways of using C++ in an objective-c project. They are described below. What are the pros and cons of each method. Is there any other recommended way, and what are its pros and cons?

-In C++ header files, use extern "C" declaration as described in Wikipedia.

-Wrapping C++ with an Objective-C++ as described by Rob Napier.


问:
The limit of Int32 for Identity Column
This is just a consideration for a site am creating and for other big sites out there.

I am using Identity Column to store the ID of some of my tables and I have classes whose Id are decorated with Int32 to hold the value of the ID retrieved from database.

My worry is that as the site grows bigger, some tables that grows exponentially e.g QuestionComments might exceed the Int32 limit in future. So I change my class to use long.

```<code>public class Question
{
   public long QuestionID { get; set; }
   ...
}
</code>```

//Converting database value to .Net type

```<code> Question q = new Question();
 q.QuestionID = Convert.ToInt32(myDataRow["QuestionID"]);
</code>```

How true is my assumption? Would using a UniqueIdentifier be better? Are there other way to address this?

UPDATE:

But for the sake of learning, how would site like FaceBook, Google, StackOverflow etc. handle Visit table assuming they have VisitID as Identity Column

答:
Int32 is a 32 bit integer. It's also signed. This means it can hold 2^31 - 1  different positive values. This comes to:

2,147,483,647

That's over 2 billion unique IDs. If you can use an unsigned integer this doubles to 4 billion.

long is a 64 bit signed integer. That's 2^63 - 1 different positive values which comes to:

9,223,372,036,854,775,807

That's over 9 quintillion unique IDs (name courtesy of http://www.webmath.com) which is many orders of magnitude more than the 32 bit integer can hold.

So if you think you are going to get over 2 billion entities in any of your tables you should use long. This should be enough for any purpose.

Title: The limit of Int32 for Identity Column


问:
What is a "behavior rich object" and why would it be advantageous?
I am referring to the article Mocks aren't Stubs by Martin Fowler. When naming cases when he think "mockist" TDD will be advantageous, he said

It's particularly worth trying if you are having problems in some of
  the areas that mockist TDD is intended to improve. I see two main
  areas here. [...]  The second area is if your objects don't contain
  enough behavior, mockist testing may encourage the development team to
  create more behavior rich objects.

My question, what does he mean by "behavior rich objects", objects that "contain enough behaviour", etc? And why does it matter if an object contains many behaviour or not, if it works correctly?

答:
I think the quote is referring to objects which are (mostly) devoid of logic, representing only data.  This is referred to as the Anemic Domain Model, and is generally an anti-pattern in OOP.  From the Wikipedia article:

Anemic domain model is a term used to describe the use of a software domain model where the business logic is implemented outside the domain objects.

So basically, your quote seems to be saying that TDD (and specifically, mocking) encourages people to move their logic into the object (where it should have been, in the first place).  I've noticed this myself, but don't have any actual data to back it up.

Edit:

To clarify, I'm simplifying here by pointing out one end of the spectrum, the anemic domain model.  Fowler is probably referring to more of a soft-defined "sweet-spot", where your object contains an "optimal" amount of logic (by some measure).  This object would be complicated enough to warrant its existence, but not so complicated so that it should yet be split into multiple.  Of course, this is very difficult to define, so I've stuck with the simple explanation.


问:
Term for 24-bits
Is there a term for a 24-bit (3-byte) integer?

I know uncommon bit counts (such as a "nibble" or "nybble" for 4 bits) have names, and having 24-bits in both video and audio technology, for instance, is very common.

答:
No, I don't think there is a specific name for a 3-byte word.

Note that those 24 bits usually represent a RGB value, or a X, Y, depth coordinate, so usually those values are referred to with names specific to the API at hand.

Title: Term for 24-bits


答:
I know you asked for an analogy, but I think that's the wrong technique.

I believe, as others have mentioned in passing, that you need to emphasize that data size affects run time, not build time.

So, break it down for them - you actually have two sub-projects, building and running. The building project should (for the most part) be irrelevant of how much data it will run on, it only matters the types of data.

As for the runtime - sure, they can factor that according to data size (excluding any non-trivial fixed overhead).

It's like if you have to drive to Melbourne - but first you have to build the car.

Sure, driving to Sydney might be faster - but building the vehicle takes the same amount of time.

Okay, I gave you an analogy after all.


问:
Is defining a variable to name a method argument a good practice?
For the sake of readability I often find myself defining temporary variables while calling functions, such as the following code

```<code>var preventUndo = true;
doSomething(preventUndo);
</code>```

The shorter version of this to this would be,

```<code>doSomething(true);
</code>```

But when I come back to the code I often wonder what true refers to. Is there a convention for this kind of conundrum?

答:
It is not the role of the caller to define the role of arguments. I always go for the inline version, and check the signature of the called function if I have a doubt.

Variable should be named after their role in the current scope. Not The scope where they are sent.


答:
I think your solution makes your code a bit more readable but I would avoid defining an extra variable just to make your function call clearer.
Also, if you do want to use an extra variable, I would mark it as constant if your programming language supports it.

I can think of two alternatives which do not involve an extra variable:

1. Use an extra comment

```<code>doSomething(/* preventUndo */ true);
</code>```

2. Use a two-valued enum instead of boolean

```<code>enum Options
{
    PreventUndo,
    ...
}

...

doSomething(PreventUndo);
</code>```

You can use alternative 2 if your language supports enums.

EDIT

Of course, using named arguments is also an option, if your language supports them.

Regarding the extra coding needed by enums, it really seems negligible to me. Instead of

```<code>if (preventUndo)
{
    ...
}
</code>```

you have

```<code>if (undoOption == PreventUndo)
{
    ...
}
</code>```

or

```<code>switch (undoOption)
{
  case PreventUndo:
  ...
}
</code>```

And even if it is a little more typing, remember that code is written once and read many times, so it can be worthwhile typing a bit more now in order to find a more readable code six months later.

Title: Is defining a variable to name a method argument a good practice?

Body:
For the sake of readability I often find myself defining temporary variables while calling functions, such as the following code

```<code>var preventUndo = true;
doSomething(preventUndo);
</code>```

The shorter version of this to this would be,

```<code>doSomething(true);
</code>```

But when I come back to the code I often wonder what true refers to. Is there a convention for this kind of conundrum?

Body:
I think your solution makes your code a bit more readable but I would avoid defining an extra variable just to make your function call clearer.
Also, if you do want to use an extra variable, I would mark it as constant if your programming language supports it.

I can think of two alternatives which do not involve an extra variable:

1. Use an extra comment

doSomething(/* preventUndo */ true);

2. Use a two-valued enum instead of boolean

enum Options
{
    PreventUndo,
    ...
}

...

doSomething(PreventUndo);

You can use alternative 2 if your language supports enums.

EDIT

Of course, using named arguments is also an option, if your language supports them.

Regarding the extra coding needed by enums, it really seems negligible to me. Instead of

if (preventUndo)
{
    ...
}

you have

if (undoOption == PreventUndo)
{
    ...
}

or

switch (undoOption)
{
  case PreventUndo:
  ...
}

And even if it is a little more typing, remember that code is written once and read many times, so it can be worthwhile typing a bit more now in order to find a more readable code six months later.


答:
Don't write code you don't need.

If you find doSomething(true) difficult to understand, you should either add a comment:

```<code>// Do something and prevent the undo.
doSomething(true);
</code>```

or, if the language supports it, add the parameter name:

```<code>doSomething(preventUndo: true);
</code>```

Otherwise, rely on your IDE to give you the signature of the called method:

Cases where it's useful

Putting an additional variable can be useful:

For debugging purposes:

```<code>var productId = this.Data.GetLastProductId();
this.Data.AddToCart(productId);
</code>```

The same code can be written in a single line, but if you want to put a breakpoint before adding a product to cart in order to see if the product id is correct, writing two lines instead of one is a good idea.

If you have a method with lots of parameters and each parameter goes from an evaluation. In one line, this may become totally unreadable.

```<code>// Even with indentation, this is unreadable.
var doSomething(
    isSomethingElse ? 0 : this.getAValue(),
    this.getAnotherOne() ?? this.default,
    (a + b + c + d + e) * f,
    this.hello ? this.world : (this.hello2 ? this.world2 : -1));
</code>```

If the evaluation of a parameter is too complicated. An example of a code I've seen:

```<code>// Wouldn't it be easier to have several if/else's (maybe even in a separate method)?
do(something ? (hello ? world : -1) : (programmers ? stackexchange : (com ? -1 : 0)));
</code>```

Why not in other cases?

Why shouldn't you create additional variables in simple cases?

Not because of the performance impact. This would be a very wrong assumption of a beginner developer who is micro-optimizing his app. There is no performance impact in most languages, since the compiler will inline the variable. In those languages where the compiler doesn't do that, you might gain a few microseconds by inlining it by hand, which doesn't worth it. Don't do that.

But because of the risk of dissociating the name you give to the variable to the name of the parameter.

Example:

Let's say the original code is:

```<code>void doSomething(bool preventUndo)
{
    // Does something very interesting.
    undoHistory.removeLast();
}

// Later in code:
var preventUndo = true;
doSomething(preventUndo);
</code>```

Later, a developer working on doSomething notices that recently, the undo history introduced two new methods:

```<code>undoHistory.clearAll() { ... }
undoHistory.disable() { ... }
</code>```

Now, preventUndo seems not very clear. Does it mean that only the last action will be prevented? Or maybe it means that the user will not be able to use undo feature any longer? Or that the undo history will be cleared? The clearer names would be:

```<code>doSomething(bool hideLastUndo) { ... }
doSomething(bool removeAllUndo) { ... }
doSomething(bool disableUndoFeature) { ... }
</code>```

So now you have:

```<code>void doSomething(bool hideLastUndo)
{
    // Does something very interesting.
    undoHistory.removeLast();
}

// Later in code, very error prone, while the signature of the method is clear:
var preventUndo = true;
doSomething(preventUndo);
</code>```

What about enums?

Some other people suggested using enums. While it solves the immediate problem, it creates a bigger one. Let's take a look:

```<code>enum undoPrevention
{
    keepInHistory,
    prevent,
}

void doSomething(undoPrevention preventUndo)
{
    doTheJob();
    if (preventUndo == undoPrevention.prevent)
    {
        this.undoHistory.discardLastEntry();
    }
}

doSomething(undoPrevention.prevent);
</code>```

Problems with that:

It's too much code. if (preventUndo == undoPrevention.prevent)? Seriously?! I don't want to write such ifs every time.

Adding an element to the enum is very tempting later, if I'm using the same enum somewhere else. What if I modify it like this:

```<code>enum undoPrevention
{
    keepInHistory,
    prevent,
    keepButDisable, // Keeps the entry in the history, but makes it disabled.
}
</code>```

What will happen now? Will doSomething method work as expected? In order to prevent this, it would require to write this method this way from the beginning:

```<code>void doSomething(undoPrevention preventUndo)
{
    if (![undoPrevention.keepInHistory, undoPrevention.prevent].contains(preventUndo))
    {
        throw new ArgumentException('preventUndo');
    }

    doTheJob();
    if (preventUndo == undoPrevention.prevent)
    {
        this.undoHistory.discardLastEntry();
    }
}
</code>```

The variant which uses booleans starts to look so nice!

```<code>void doSomething(bool preventUndo)
{
    doTheJob();
    if (preventUndo)
    {
        this.undoHistory.discardLastEntry();
    }
}
</code>```

Body:
Don't write code you don't need.

If you find doSomething(true) difficult to understand, you should either add a comment:

// Do something and prevent the undo.
doSomething(true);

or, if the language supports it, add the parameter name:

doSomething(preventUndo: true);

Otherwise, rely on your IDE to give you the signature of the called method:

Cases where it's useful

Putting an additional variable can be useful:

For debugging purposes:

var productId = this.Data.GetLastProductId();
this.Data.AddToCart(productId);

The same code can be written in a single line, but if you want to put a breakpoint before adding a product to cart in order to see if the product id is correct, writing two lines instead of one is a good idea.

If you have a method with lots of parameters and each parameter goes from an evaluation. In one line, this may become totally unreadable.

// Even with indentation, this is unreadable.
var doSomething(
    isSomethingElse ? 0 : this.getAValue(),
    this.getAnotherOne() ?? this.default,
    (a + b + c + d + e) * f,
    this.hello ? this.world : (this.hello2 ? this.world2 : -1));

If the evaluation of a parameter is too complicated. An example of a code I've seen:

// Wouldn't it be easier to have several if/else's (maybe even in a separate method)?
do(something ? (hello ? world : -1) : (programmers ? stackexchange : (com ? -1 : 0)));

Why not in other cases?

Why shouldn't you create additional variables in simple cases?

Not because of the performance impact. This would be a very wrong assumption of a beginner developer who is micro-optimizing his app. There is no performance impact in most languages, since the compiler will inline the variable. In those languages where the compiler doesn't do that, you might gain a few microseconds by inlining it by hand, which doesn't worth it. Don't do that.

But because of the risk of dissociating the name you give to the variable to the name of the parameter.

Example:

Let's say the original code is:

void doSomething(bool preventUndo)
{
    // Does something very interesting.
    undoHistory.removeLast();
}

// Later in code:
var preventUndo = true;
doSomething(preventUndo);

Later, a developer working on doSomething notices that recently, the undo history introduced two new methods:

undoHistory.clearAll() { ... }
undoHistory.disable() { ... }

Now, preventUndo seems not very clear. Does it mean that only the last action will be prevented? Or maybe it means that the user will not be able to use undo feature any longer? Or that the undo history will be cleared? The clearer names would be:

doSomething(bool hideLastUndo) { ... }
doSomething(bool removeAllUndo) { ... }
doSomething(bool disableUndoFeature) { ... }

So now you have:

void doSomething(bool hideLastUndo)
{
    // Does something very interesting.
    undoHistory.removeLast();
}

// Later in code, very error prone, while the signature of the method is clear:
var preventUndo = true;
doSomething(preventUndo);

What about enums?

Some other people suggested using enums. While it solves the immediate problem, it creates a bigger one. Let's take a look:

enum undoPrevention
{
    keepInHistory,
    prevent,
}

void doSomething(undoPrevention preventUndo)
{
    doTheJob();
    if (preventUndo == undoPrevention.prevent)
    {
        this.undoHistory.discardLastEntry();
    }
}

doSomething(undoPrevention.prevent);

Problems with that:

It's too much code. if (preventUndo == undoPrevention.prevent)? Seriously?! I don't want to write such ifs every time.

Adding an element to the enum is very tempting later, if I'm using the same enum somewhere else. What if I modify it like this:

enum undoPrevention
{
    keepInHistory,
    prevent,
    keepButDisable, // Keeps the entry in the history, but makes it disabled.
}

What will happen now? Will doSomething method work as expected? In order to prevent this, it would require to write this method this way from the beginning:

void doSomething(undoPrevention preventUndo)
{
    if (![undoPrevention.keepInHistory, undoPrevention.prevent].contains(preventUndo))
    {
        throw new ArgumentException('preventUndo');
    }

    doTheJob();
    if (preventUndo == undoPrevention.prevent)
    {
        this.undoHistory.discardLastEntry();
    }
}

The variant which uses booleans starts to look so nice!

void doSomething(bool preventUndo)
{
    doTheJob();
    if (preventUndo)
    {
        this.undoHistory.discardLastEntry();
    }
}


答:
Explaining Variables

Your case is an example of the introduce explaining variable / extract variable refactoring.  In short, an explaining variable is one which is not strictly necessary, but allows you to give a clear name to something, with the aim of increasing readability.

Good quality code communicates intent to the reader; and as a professional developer readability and maintainability are your #1 goals.

As such, the rule of thumb I would recommend is this:  if your parameter's purpose is not immediately obvious, feel free to use a variable to give it a good name.  I think this is a good practice in general (unless abused).  Here's a quick, contrived example - consider:

```<code>editButton.Enabled = (_grid.SelectedRow != null && ((Person)_grid.SelectedRow).Status == PersonStatus.Active);
</code>```

versus the slightly longer, but arguably clearer:

```<code>bool personIsSelected = (_grid.SelectedRow != null);
bool selectedPersonIsEditable = (personIsSelected && ((Person)_grid.SelectedRow).Status == PersonStatus.Active)
editButton.Enabled = (personIsSelected && selectedPersonIsEditable);
</code>```

Boolean Parameters

Your example actually highlights why booleans in APIs are often a bad idea - on the calling side, they do nothing to explain what's happening.  Consider:

```<code>ParseFolder(true, false);
</code>```

You'd have to look up what those parameters mean; if they were enums, it'd be a lot more clear:

```<code>ParseFolder(ParseBehaviour.Recursive, CompatibilityOption.Strict);
</code>```

Edit:

Added headings and swapped the order of the two main paragraphs, because too many people were focusing on the boolean parameters part (to be fair, it was the first paragraph originally).  Also added an example to the first part.

Body:
Explaining Variables

Your case is an example of the introduce explaining variable / extract variable refactoring.  In short, an explaining variable is one which is not strictly necessary, but allows you to give a clear name to something, with the aim of increasing readability.

Good quality code communicates intent to the reader; and as a professional developer readability and maintainability are your #1 goals.

As such, the rule of thumb I would recommend is this:  if your parameter's purpose is not immediately obvious, feel free to use a variable to give it a good name.  I think this is a good practice in general (unless abused).  Here's a quick, contrived example - consider:

editButton.Enabled = (_grid.SelectedRow != null && ((Person)_grid.SelectedRow).Status == PersonStatus.Active);

versus the slightly longer, but arguably clearer:

bool personIsSelected = (_grid.SelectedRow != null);
bool selectedPersonIsEditable = (personIsSelected && ((Person)_grid.SelectedRow).Status == PersonStatus.Active)
editButton.Enabled = (personIsSelected && selectedPersonIsEditable);

Boolean Parameters

Your example actually highlights why booleans in APIs are often a bad idea - on the calling side, they do nothing to explain what's happening.  Consider:

ParseFolder(true, false);

You'd have to look up what those parameters mean; if they were enums, it'd be a lot more clear:

ParseFolder(ParseBehaviour.Recursive, CompatibilityOption.Strict);

Edit:

Added headings and swapped the order of the two main paragraphs, because too many people were focusing on the boolean parameters part (to be fair, it was the first paragraph originally).  Also added an example to the first part.

ContentLicense: CC BY-SA 4.0


答:
Oh man, I was in this position so many times back when I freelanced I'm feeling your pain right now.

It all changed when I changed my way of thinking about clients: all clients are con artists.

Let me say that again:

ALL CLIENTS ARE CON ARTISTS

When you change to this perspective it is when you realize you actually have the leverage most of the time, even when you don't have a contract that backs you up.

Here is what you do:

If you have delivered already, you are already screwed: At this point you must decide if you want to keep getting screwed and have the client continue making you his b****.

If you have not delivered, there is hope: The launch is your leverage and you can still get paid. Negotiate payment for at least 50% or just drop the whole project and leave him to his luck, this is your leverage. I was in this position at least two times and didn't take the chance when I could, things went bad for me and I paid the price. It sounds cold-hearted, but this is often the point of no return.

If you think this is just a communication problem, you can fix it (if and only if the client wants to): You can use the previous still as a leverage, but the solution is to ask the client to designate a single representative for the project, your best options for this are:

The project owner

A stakeholder designated by the project owner

The owners' "right-hand"

This will effectively make them funnel all requests to a single point where things can be sorted out on their side, not on yours. You are experiencing a mixture of feature creep and lack of expectation management.

In any case and if I were you, I would contact oDesk for assistance with this case. I'm sure there are a lot of clients who behave like this to extort more work out of contractors. If you have evidence that the project is complete according with the contract, use the contract as your weapon.

I'm sure oDesk has contracts for something.

Also, it can also look like being cold-hearted, but when it comes down to getting screwed or not screwed, their launch, their deadlines, and their mind-faps are their problem, not yours.

I made the mistake of caring too much about the client in my days, but you don't have to.

Edit: Last piece of advice, don't make the final delivery until you have the final payment. You can always give a demonstration in your own laptop/premises to assure everything works.

Alternatively and if you have absolutely no choice, and the customer needs the application deployed to pay you (because it is in the contract, otherwise don't give in), deploy it in your own infrastructure and give no access to it to anyone other to those that you would trust with your life (I'm serious about this). This is your last possible leverage where you can say: "you have X days to pay up or the service will be taken down". Pretend that he is renting a house you own, and he might just leave one day unannounced and you will never be able to track him back or give him a reason to pay you.

Title: Should I continue to perform freelance work for customers who keep on demanding more without paying?

Body:
So a client comes to me and says it needs some work done. Basically 4 tasks, which I agreed to perform for a certain price. The customer creates the job offer (a fixed time and price job) on ODesk, I accept it, but it took some days and constant reminding for the customer to initiate a contract based on that job.

The problem is that the original task has been completed, the contract is still active, I have not been paid yet, the customer says he will pay when the project is completed, and until then, new tasks occur constantly, or changes to older tasks that require full re-doing of elements. For all of this the client promises payment. No updates from this client on ODesk, no new tasks there. I keep reminding the client about sorting out the administrative issues, but with no results. At the same time, the client pushes on continuing work, since the project is soon to be launched.

I don't know what to do.

If I refuse to perform any work without the bureaucracy, the project will be late. But it's not my fault, is it? I am scared that I might receive a negative feedback in this case, or something even worse.

If I drop out of this project I'm afraid I won't be getting even what I've earned.

If I continue like this, I'll be wasting a lot of time doing stuff similar to the stuff described here, but as a programmer (yes, it has already come to similar requests, for lots of hardcoded content).

How do I communicate with such clients in such situations? How do I avoid a conflict?

P.S. The client is a small company. Different people handle different aspects of this project, and everybody introduces their own changes to the original specs.

After 2 years: Wow! Very question! Much popular!

I decided to let everyone in on the ending of this story. I've confronted the customer, explained that I will not work until I get paid for what I did, and until a hourly contract is open. They paid me the next day and opened a contract. A fruitful, but short collaboration started. Everyone was happy. Except I didn't get any feedback.


答:
I find this is the simplest and easiest to read:

```<code>enum Undo { ALLOW, PREVENT }

doSomething(Undo u) {
    if (Undo.ALLOW == u) {
        // save stuff to undo later.
    }
    // do your thing
}

doSomething(Undo.ALLOW);
</code>```

MainMa doesn't like that.  We may have to agree to disagree, or we can use a solution that Joshua Bloch proposes:

```<code>enum Undo {
    ALLOW {
        @Override
        public void createUndoBuffer() {
            // put undo code here
        }
    },
    PREVENT {
        @Override
        public void createUndoBuffer() {
            // do nothing
        }
    };

    public abstract void createUndoBuffer();
}

doSomething(Undo u) {
    u.createUndoBuffer();
    // do your thing
}
</code>```

Now if you ever add an Undo.LIMITED_UNDO, your code won't compile unless you implement the createUndoBuffer() method.  And in doSomething() there is no if (Undo.ALLOW == u).  I've done it both ways and the second method is pretty heavyweight and a little hard to understand when the Undo enum expands to pages and pages of code, but it does make you think.  I usually stick with the simpler method to replace a simple boolean with a 2-value enum until I have reason to change.  When I add a third value, I use my IDE to "Find-usages" and fix everything up then.

Body:
I find this is the simplest and easiest to read:

enum Undo { ALLOW, PREVENT }

doSomething(Undo u) {
    if (Undo.ALLOW == u) {
        // save stuff to undo later.
    }
    // do your thing
}

doSomething(Undo.ALLOW);

MainMa doesn't like that.  We may have to agree to disagree, or we can use a solution that Joshua Bloch proposes:

enum Undo {
    ALLOW {
        @Override
        public void createUndoBuffer() {
            // put undo code here
        }
    },
    PREVENT {
        @Override
        public void createUndoBuffer() {
            // do nothing
        }
    };

    public abstract void createUndoBuffer();
}

doSomething(Undo u) {
    u.createUndoBuffer();
    // do your thing
}

Now if you ever add an Undo.LIMITED_UNDO, your code won't compile unless you implement the createUndoBuffer() method.  And in doSomething() there is no if (Undo.ALLOW == u).  I've done it both ways and the second method is pretty heavyweight and a little hard to understand when the Undo enum expands to pages and pages of code, but it does make you think.  I usually stick with the simpler method to replace a simple boolean with a 2-value enum until I have reason to change.  When I add a third value, I use my IDE to "Find-usages" and fix everything up then.


答: MySQL made up the non-standard name, MEDIUMINT.  I find their TINYINT (instead of byte), SMALL (instead of short), MEDIUMINT (24-bit), INT (normal - sort of), and BIGINT (instead of long) to be very confusing.  I wish they had named them INT08, INT16, INT24, etc. instead.  I hesitate to propose their standard-bucking terminology as a new standard, but in the absence of anything better...  I'd say call it a 24-bit integer or int24.</p>

Title: Term for 24-bits

Body:
Is there a term for a 24-bit (3-byte) integer?

I know uncommon bit counts (such as a "nibble" or "nybble" for 4 bits) have names, and having 24-bits in both video and audio technology, for instance, is very common.


答: I was under the impression that any modern database used a 64-bit unsigned "long" integer as a surrogate key (unique identifier) by default.  In MySQL, every record has a row number and if you declare this column properly, it does not actually take any (additional) storage in the database.  Why would you ever use anything else?</p>

Title: The limit of Int32 for Identity Column

Body:
This is just a consideration for a site am creating and for other big sites out there.

I am using Identity Column to store the ID of some of my tables and I have classes whose Id are decorated with Int32 to hold the value of the ID retrieved from database.

My worry is that as the site grows bigger, some tables that grows exponentially e.g QuestionComments might exceed the Int32 limit in future. So I change my class to use long.

```<code>public class Question
{
   public long QuestionID { get; set; }
   ...
}
</code>```

//Converting database value to .Net type

```<code> Question q = new Question();
 q.QuestionID = Convert.ToInt32(myDataRow["QuestionID"]);
</code>```

How true is my assumption? Would using a UniqueIdentifier be better? Are there other way to address this?

UPDATE:

But for the sake of learning, how would site like FaceBook, Google, StackOverflow etc. handle Visit table assuming they have VisitID as Identity Column


答:
I agree with what @GlenPeterson said:

```<code>doSomething(Undo.ALLOW); // call using a self evident enum
</code>```

but also insteresting would be the following since it seems to me there are only two posibilities ( true or false )

```<code>//Two methods

doSomething()  // this method does something but doesn't prevent undo

doSomethingPreventUndo() // this method does something and prevents undo
</code>```

Body:
I agree with what @GlenPeterson said:

doSomething(Undo.ALLOW); // call using a self evident enum

but also insteresting would be the following since it seems to me there are only two posibilities ( true or false )

//Two methods

doSomething()  // this method does something but doesn't prevent undo

doSomethingPreventUndo() // this method does something and prevents undo


答:
Typically when you have to hound your client for updates that's a bad sign.

I also work on oDesk; and going forward you might want to consider working exclusively on hourly contracts and estimating up front how many hours give or take a task would take you.

On hourly contracts you can correctly mark what you've worked on and how much you're owed. It's much easier to get oDesk to force the client to pay up.

On fixed price contracts, there is no chance. Your client and only your client decides when and how much to pay. oDesk even says so in their documentation/support site. I'm sorry to say, if your project is fixed price; I'd say hold the work for ransom and demand whatever you can get - then bail.

Clients like this suck the life out of you.


问:
How to edit existing user stories
I'm quite new to working in Agile and with user stories and scenarios in the BDD tool Cucumber and ideally I'll need to go on a course of all of this. I have a set of user stories that need to be edited for an upcoming release.

As an example one of the user stories is:

```<code>'As a user
I want a visual indicator on entry into the application'
</code>```

This needs to be changed to:

```<code>As a producer, I don’t want a textured background in the application
</code>```

The Acceptance Criteria (In Gherkin format for those familiar with Cucumber) for the original user story (the first one above) is

```<code>    Scenario: Show background image when video is not playing

    Given the application restarts
When the home menu is displayed
Then the full-screen textured background should be visible at the correct resolution
</code>```

For the new user story (second one above), the acceptance criteria that I have written, but not certain of is:

```<code>Scenario: Show dark grey background when video is not playing

Given the application restarts
When the home menu is displayed
Then the dark grey background should be visible at the correct resolution
</code>```

Does this look right? Or am I missing information? I'm, quite new to this, so please bear with me.

答:
One item of feedback I would have about your stories. The When component is for describing an action that the user performs - therefore I would expect to see a verb near the start of each When step. Currently your When steps are more like Givens, as they set up the scenario in a known state.

Does the user actually have to do anything to get the home menu to display? It may be that in your scenario the user does not perform any action, in this case it's perfectly acceptable that there be no When steps, only Givens and Thens.

```<code>Given the application starts
Then the home menu should be displayed
And I should see a dark grey background
</code>```

Or you might decide that the user action is (re)starting the application, in which case you don't necessarily need a Given...

```<code>When I restart the application
Then the home menu should be displayed
And I should see a dark grey background
</code>```

Title: How to edit existing user stories

Body:
One item of feedback I would have about your stories. The When component is for describing an action that the user performs - therefore I would expect to see a verb near the start of each When step. Currently your When steps are more like Givens, as they set up the scenario in a known state.

Does the user actually have to do anything to get the home menu to display? It may be that in your scenario the user does not perform any action, in this case it's perfectly acceptable that there be no When steps, only Givens and Thens.

Given the application starts
Then the home menu should be displayed
And I should see a dark grey background

Or you might decide that the user action is (re)starting the application, in which case you don't necessarily need a Given...

When I restart the application
Then the home menu should be displayed
And I should see a dark grey background


答:
When you look at two classes to see how coupled they are, one of the categories is data coupling, which refers to code in one class calling methods of another class and just passing in data, like what month you want a report for, and another category is control coupling, calling methods and passing in something that controls the behaviour of the method. The example I use in class is a verbose flag or a reportType flag, but preventUndo is also a great example. As you have just demonstrated, control coupling makes it hard to read calling code and understand what's happening. It also makes the calling code vulnerable to changes in doSomething() that use the same flag to control both undo and archive, or add another parameter to doSomething() to control archiving, thus breaking your code, and so on.

The problem is that the code is too tightly coupled. Passing a bool to control behaviour is, in my opinion, a sign of a bad API. If you own the API, change it. Two methods, doSomething() and doSomethingWithUndo(), would be better. if you don't own it, write two wrapper methods yourself in code you do own, and have one of them call doSomething(true) and the other call doSomething(false).


答:
I don't think there is a particular name for such an integer; in fact, the only integer sizes with their own names that I can think of are 1 (bit), 4 (nibble) and 8 (byte).

Other sizes either go by "n-bit integer" or names that mean different things on different platforms (word, int, long, short, double word, etc.) or in different contexts (character).

So, in line with '32-bit integer' and '64-bit integer', '24-bit integer' makes the most sense.

Title: Term for 24-bits


答:
i think it's more of a solution to maintainability, because, as a programmer, you are supposed to put methods where you have the data, thus creating an object model of your application.

yes, it's also a solution to complexity by providing a model for you to "see" your code in a natural way, as objects that have properties and possible actions

Title: Is Object Oriented Programming a solution to complexity?

Body: Do you think Object Oriented Programming is a solution to complexity. Why? This topic may be a bit controversial but my intentions to know the answer of Why from the experts here !</p>


答:
Neither, you shouldn't write methods with boolean flags.

To quote Robert C. Martin says in his book Clean Code (ISBN-13 978-0-13-235088-4), "Passing a boolean into a function is a truly terrible practice."

To paraphrase him, the reasoning is that the fact that you have a true/false switch means that your method is most likely doing two different things (ie "Do something with undo" and  "Do something without undo"), and should therefore be split into two different methods (that may internally call the same thing).

```<code>DoSomething()
{...

DoSomethingUndoable()
{....
</code>```

Body:
Neither, you shouldn't write methods with boolean flags.

To quote Robert C. Martin says in his book Clean Code (ISBN-13 978-0-13-235088-4), "Passing a boolean into a function is a truly terrible practice."

To paraphrase him, the reasoning is that the fact that you have a true/false switch means that your method is most likely doing two different things (ie "Do something with undo" and  "Do something without undo"), and should therefore be split into two different methods (that may internally call the same thing).

DoSomething()
{...

DoSomethingUndoable()
{....


答:
Just for a less conventional solution and since the OP mentionned Javascript a possibility is to use an associative array for mapping values. The advantage over a single boolean is that you can have as many arguments as you like and not be worried about their sequence.

```<code>var doSomethingOptions = new Array();

doSomethingOptions["PREVENTUNDO"] = true;
doSomethingOptions["TESTMODE"] = false;

doSomething( doSomethingOptions );

// ...

function doSomething( doSomethingOptions ){
    // Check for null here
    if( doSomethingOptions["PREVENTUNDO"] ) // ...
}
</code>```

I realize this is a reflex of someone from a strongly-typed background and might not be so practical but consider this for originality.

Another possibility is to have an object and is also possible in Javascript. I'm not a 100% sure this is syntacly correct. Have a look at patterns such as Factory for further inspiration.

```<code>function SomethingDoer( preventUndo ) {
    this.preventUndo = preventUndo;
    this.doSomething = function() {
            if( this.preventUndo ){
                    // ...
            }
    };
}

mySomethingDoer = new SomethingDoer(true).doSomething();
</code>```

Body:
Just for a less conventional solution and since the OP mentionned Javascript a possibility is to use an associative array for mapping values. The advantage over a single boolean is that you can have as many arguments as you like and not be worried about their sequence.

var doSomethingOptions = new Array();

doSomethingOptions["PREVENTUNDO"] = true;
doSomethingOptions["TESTMODE"] = false;

doSomething( doSomethingOptions );

// ...

function doSomething( doSomethingOptions ){
    // Check for null here
    if( doSomethingOptions["PREVENTUNDO"] ) // ...
}

I realize this is a reflex of someone from a strongly-typed background and might not be so practical but consider this for originality.

Another possibility is to have an object and is also possible in Javascript. I'm not a 100% sure this is syntacly correct. Have a look at patterns such as Factory for further inspiration.

function SomethingDoer( preventUndo ) {
    this.preventUndo = preventUndo;
    this.doSomething = function() {
            if( this.preventUndo ){
                    // ...
            }
    };
}

mySomethingDoer = new SomethingDoer(true).doSomething();


问:
Why isn't functional programming more popular in the industry? Does it catch on now?
During my four years at university we have been using much functional programming in several functional programming languages. But I have also used much object oriented programming to, and in fact I use object oriented languages more when doing my own small project to prepare for my first job. But I often wish that I was coding in a functional programming language when doing these projects.

However, when looking for a job, it is very rare to see a job where knowledge of a functional programming language is required.

Why isn't functional programming languages used more in the industry? There is quite much news about functional programming languages these days, so I wonder if functional programming is catching on in the industry now?

答:
You already write code in functional style, just you don't know it.

When you are required to make unit tests for your code, you tend to write testable functions, which does not create or depend on side effects, and always returns the same result on the same arguments (so called pure functions). This is the primary advantage of functional programs.

I think functional languages are too limiting. So instead of replacing imperative languages with functional, imperative languages will get functional features. Nowadays almost every programming language has closures and lambdas.


答:
What I would do in JavaScript is have the function take an object as the only parameter something like this:

```<code>function doSomething(settings) {
    var preventUndo = settings.hasOwnProperty('preventUndo') ? settings.preventUndo : false;
    // Deal with preventUndo in the normal way.
}
</code>```

Then call it with:

```<code>doSomething({preventUndo: true});
</code>```

Body:
What I would do in JavaScript is have the function take an object as the only parameter something like this:

function doSomething(settings) {
    var preventUndo = settings.hasOwnProperty('preventUndo') ? settings.preventUndo : false;
    // Deal with preventUndo in the normal way.
}

Then call it with:

doSomething({preventUndo: true});


问:
How can I make refactoring a priority for my team?
The codebase I work with daily has no automated tests, inconsistent naming and tons of comments like "Why is this here?", "Not sure if this is needed" or "This method isn't named right" and the code is littered with "Changelogs" despite the fact we use source control. Suffice it to say, our codebase could use refactoring.

We always have tasks to fix bugs or add new features, so no time is put aside to refactor code to be better and more modular, and it doesn't seem to be a high priority.

How can I demonstrate the value of refactoring such that it gets added to our task lists? Is it worth it to just refactor as I go, asking for forgiveness rather than permission?

答:
Your main problem is that the codes isn't getting enough visibility.

I suggets using a continuous integration tool like Jenkins, and a static code analisys tool integrated to it that measures cyclomatic complexity, naming standards, code length, etc.

When a programmer commitS a change, Jenkins will run the units tests, run the static code analisys tool on it and generate a web report that everybody can see, with traffic-light-like color status.

When the code quality is visible to everyone ( specially the team lider and the boss ) and version control and unit tests are there to have your back... people feel encouraged to refactor.


问:
Comparison of my own Insertion Sort versus the standard algorithm
I come from a background of making MVC websites and HTML5 applications, and have recently decided to dive into the sort of stuff i wasn't taught at university, namely the things most people would learn on a computer science course.

I've been reading a book on algorithms, and the first one it mentions was the Insertion Sort. I didn't really understand it the first time, but I understood the goal, so I had a crack at coming up with my own solution before reading more into the proper solution to see how close I got.

I got pretty close, and here is my function in C#:

```<code>    int[] SortNumbersTomsVersion(int[] numbersIn)
    {
        int[] output = new int[numbersIn.Count()];

        for (var i = 0; i < numbersIn.Count(); i++)
        {
            int cardsLowerThan = 0;

            for (var n = 0; n < numbersIn.Count(); n++)
            {
                if (numbersIn[n] < numbersIn[i])
                {
                    cardsLowerThan++;
                }
            }
            output[cardsLowerThan] = numbersIn[i];
        }
        return output;
    }
</code>```

The concept of it is that, i start off with a group of numbers. Then, for each number, I compare it to all of the other numbers in the array, to see how many others are lower in value. It then takes the resulting count, and places the current number into an output array at that index. The algorithm goes through all the numbers until they are all at the same location.

My question is, what makes the original better than my solution?

for reference, here is the accepted algorithm outside of a function:

```<code>    int temp, k;
    for (int i = 1; i < array_size; i++)
    {
        temp = array[i];
        k = i - 1;
        while (k >= 0 && array[k] > temp)
        {
            array[k + 1] = array[k];
            k--;
        }
        array[k + 1] = temp;
    }
</code>```

答:
Comparing performance of 2 algorithms, assuming both work correctly, involves several factors such as space, speed, etc. Without detailed analysis, your code has nested for loops each bound by (n) iterations:

```<code>for (var i = 0; i < numbersIn.Count(); i++)
     {
            ...

            for (var n = 0; n < numbersIn.Count(); n++) ...}}
</code>```

this calls for O(n*n) even at the best case (when elements are already sorted). The insertion sort algorithm is supposed to be O(n) in the best case see: Wiki-InsertionSort.

Body:
Comparing performance of 2 algorithms, assuming both work correctly, involves several factors such as space, speed, etc. Without detailed analysis, your code has nested for loops each bound by (n) iterations:

for (var i = 0; i < numbersIn.Count(); i++)
     {
            ...

            for (var n = 0; n < numbersIn.Count(); n++) ...}}

this calls for O(n*n) even at the best case (when elements are already sorted). The insertion sort algorithm is supposed to be O(n) in the best case see: Wiki-InsertionSort.


答: Real Machines with 24-bit and 48-bit words describes a surprising number of computers that used 24-bit words. You'd think that if there were a particular term other than word to describe that unit of data, it'd be mentioned on that page, but I don't see one there.

Title: Term for 24-bits


问:
Can my company give IP rights away for an application I wrote off hours to another startup?
I am an intern for a health company (unpaid), let's call it Company A and I noticed that they are using a lot of paper form for things that can be done on the computer. Excel files for things that shouldn't be in Excel. So I wanted to improve on my programming and figured that it was the best opportunity to do.

I developed a couple of apps for their use. All these applications were outside company time. One application I did and they love and one of the director has a brother who has a health start up company. He wants me to give over my source code so his brother's company can further develop it and maybe sell it (I am out of the equation).

I have no intention of handing over my code as I put a lot of time outside doing it but I also don't want to burn bridges with anyone in the company. I can't go to the director and tell him "I don't think so".

I am fine with demoing to the brother how it works but the line is giving up my code. If they want to build something like it then they can go right ahead I have no problem with it.

What is the correct way of approaching this and do they have the right to do this to me?

Edit: there is no contract I never signed anything

答:
Put a license on your code that disallows commercial work, and you will be hired to write it again.

Update:

You said its "your code".
I assume you did not put a company copyright line anywhere in your code?
If you did, you already gave up all rights to the source, and you can't say "No" to your boss.

If  you didnt... and have not choosen a licence at all: It's all your copyright and they can do nothing about it.
If your Company A is using your code "for free" and without any licence or contract (look up your contract, often there is a clause saying that everything you do, including home-work, is theirs) you still own all rights to it.

Therefor I recommend you put a non-comercial-use allowed licence like:
http://creativecommons.org/licenses/by-nc-sa/3.0/

Then you can hand-over the code, but they can't use it. (Unless it's a non-profit company)... they could still use it, but that would be against the law.

Now the cheapest and quickest and easiest sollution for Company A+B would be to ask you to write your code "again", this time probably paying for it ;-), and put the new code under a different licence.

(!) WARNING: You said you don't want to burn bridges or get into trouble with either of the company's. So maybe you try be diplomatic and talk to your boss about the conditions you would be willing to hand over the code for your apps first.


答:
It depends on the your contract with Company A. Do they have any clauses in the contract regarding the works you write outside of work? Some do. If that's the case, I'm not sure what you can do. If not, you are still the owner of the code and you aren't obligated to give it up.

You could try to sell them the application source code. I agree that you shouldn't "burn any bridges", but that doesn't mean you can't have a firm stance on your product. You don't have to give things away for free just to maintain a positive outlook in the company's eyes. There is no reason why you can't sell the software to them and still maintain a good relationship with the company.

After all, if the company wants to take advantage of your work like that, do you really care if you burn that particular bridge?

Title: Can my company give IP rights away for an application I wrote off hours to another startup?

Body:
I am an intern for a health company (unpaid), let's call it Company A and I noticed that they are using a lot of paper form for things that can be done on the computer. Excel files for things that shouldn't be in Excel. So I wanted to improve on my programming and figured that it was the best opportunity to do.

I developed a couple of apps for their use. All these applications were outside company time. One application I did and they love and one of the director has a brother who has a health start up company. He wants me to give over my source code so his brother's company can further develop it and maybe sell it (I am out of the equation).

I have no intention of handing over my code as I put a lot of time outside doing it but I also don't want to burn bridges with anyone in the company. I can't go to the director and tell him "I don't think so".

I am fine with demoing to the brother how it works but the line is giving up my code. If they want to build something like it then they can go right ahead I have no problem with it.

What is the correct way of approaching this and do they have the right to do this to me?

Edit: there is no contract I never signed anything


答:
Wow, these guys are greedy.  They get you to work for free, and then want you to donate IP you developed on your own time.  Are you sure you care about their feelings?  They don't sound like very nice people.

The business-like thing to do is set a price for your work.  About $150/hour for the time you spent developing it would be perfectly reasonable; it will cost them at least that much to reproduce it.


答:
You could explain that it was written in your own time as a pet project, and that you are happy for them to continue to continue to use and develop your application, but that it would be reasonable for them to pay you a contribution towards your time. This could be a reasonable amount based on some percentage of the normal bespoke system coding rates. (It comes down to cost/benefit for the company - ie how useful your stuff is).

If you were keen to maintain some rights on your code, you could include a stipulation in the sale that you are to retain rights to it develop and use it for your own purposes as long as you don't conflicy with the company.

This all depends a little bit on your contract, and how fair your employers are. Even where there are intellectual property clauses, this usually relates to the field that the company is selling into - ie it protects against you competing with them. IP that doesn't conflict directly is often exempt.


答:
I'm fond of leveraging language features to help clarity myself. For instance in C# you can specify parameters by name:

```<code> CallSomething(name: "So and so", age: 12, description: "A random person.");
</code>```

In JavaScript, I usually prefer to use an options object as an argument for this reason:

```<code>function doSomething(args) { /*...*/ }

doSomething({ name: 'So and so', age: 12, description: 'A random person.' });
</code>```

That's just my preference though. I suppose it's going to depend greatly on the method being called, and how the IDE helps the developer understand the signature.

Body:
I'm fond of leveraging language features to help clarity myself. For instance in C# you can specify parameters by name:

 CallSomething(name: "So and so", age: 12, description: "A random person.");

In JavaScript, I usually prefer to use an options object as an argument for this reason:

function doSomething(args) { /*...*/ }

doSomething({ name: 'So and so', age: 12, description: 'A random person.' });

That's just my preference though. I suppose it's going to depend greatly on the method being called, and how the IDE helps the developer understand the signature.


问:
Should a stack trace be in the error message presented to the user?
I've got a bit of an argument at my workplace and I'm trying to figure out who is right, and what is the right thing to do.

Context: An intranet web application that our customers use for accounting and other ERP stuff.

I'm of the opinion that an error message presented to the user (when things crash) should include as much information as possible, including the stack trace. Of course, it has to start with a nice "An Error has occurred, please submit the below information to the developers" in large, friendly letters.

My reasoning is that a screenshot of the crashed application will often be the only easily available source of information. Sure, you can try to get a hold of the client's systems administrator(s), attempt to explain where your log files are etc., but that will probably be slow and painful (talking to the client representatives mostly is).

Also, having an immediate and full information is extremely useful in development where you don't have to go hunting through the log files to find what you need on every exception. But that could be solved with a configuration switch.

Unfortunately there has been some kind of "Security audit" (no idea how they did that without the sources), and they complained about the full exception messages citing them as a security threat. Naturally, the clients (at least one that I know of) has taken this at face value and now demands that the messages be cleaned.

I fail to see how a potential attacker could use a stack trace to figure anything out he couldn't have figured out before. Are there any examples, any documented proof of anyone ever doing that? I think that we should fight this foolish idea, but perhaps I'm the fool here, so...

Who's right?

答:
Take a look at this question of IT Security SE. In short, a stack trace can give the attacker more information to work with. The more information the attacker has, the more likely they are to penetrate your system. I wouldn't base my security on the fact that stack traces are always hidden, but that also doesn't mean that you should give that information to attackers.

You can get most of the benefits from proper backend logging anyway. It's slightly less convient, but it's probably not worth risking the secureness of your system and upsetting your customers.


答:
I tend to build an application log, either in DB or in file, and log all such information to that. You can then give the user an error number, which identifies which log item the error is related to, so you can get it back. This pattern is also useful as you can follow errors even if the users don't bother raising them with you, so you can get a better idea of where the problems are.

If your site is installed in a client's environment and you can't reach it, you can get the on-site IT dept to send you some extract based on the error no.

The other thing you could consider is having the system email details of errors to a mailbox that you have sight of, so you know when things are going wrong.

Fundamentally having a system that spills its guts when something isn't right doesn't inspire confidence in non-technical users - it tends to scare them into thinking something is very wrong (eg how much of a BSOD do you understand, and how do you feel when one comes up)?

On stacktrace:

In .Net the stack trace will show the full trace right into the core MS sourced assemblies, and will reveal details about what technologies you're using, and possible versions as well. This gives intruders valuable info on possible weaknesses that could be exploited.

Title: Should a stack trace be in the error message presented to the user?

Body:
I've got a bit of an argument at my workplace and I'm trying to figure out who is right, and what is the right thing to do.

Context: An intranet web application that our customers use for accounting and other ERP stuff.

I'm of the opinion that an error message presented to the user (when things crash) should include as much information as possible, including the stack trace. Of course, it has to start with a nice "An Error has occurred, please submit the below information to the developers" in large, friendly letters.

My reasoning is that a screenshot of the crashed application will often be the only easily available source of information. Sure, you can try to get a hold of the client's systems administrator(s), attempt to explain where your log files are etc., but that will probably be slow and painful (talking to the client representatives mostly is).

Also, having an immediate and full information is extremely useful in development where you don't have to go hunting through the log files to find what you need on every exception. But that could be solved with a configuration switch.

Unfortunately there has been some kind of "Security audit" (no idea how they did that without the sources), and they complained about the full exception messages citing them as a security threat. Naturally, the clients (at least one that I know of) has taken this at face value and now demands that the messages be cleaned.

I fail to see how a potential attacker could use a stack trace to figure anything out he couldn't have figured out before. Are there any examples, any documented proof of anyone ever doing that? I think that we should fight this foolish idea, but perhaps I'm the fool here, so...

Who's right?


问:
User intentions analysis
I'm going to work on some project that would do a user-action recognition based on what he/she does in the system.

As far as I understand there are two main parts here:

Intercept the user actions (say http traffic in web/ui interaction in thick-client)
analysis of user intentions.

While the first part is rather technical and therefor easy to implement, the second one is AI related and can be academic.

So I was wondering whether someone knows some third-parties/academic projects that would implement the 'action-recognition' stuff?

答:
I think you're after CEP (Complex Event Processing), where you look at distinct events and infer something more specific. Your example is a bit trivial but, the two events of going to a search screen and then entering apples would mean that your user wanted to find some apples.

The Complex Event Processing page on Wikipedia gives a number of links to academic research, if you're looking for applications of CEP in the real work, I've come across it looking into Behavioural Analysis in relation to Fraud detection.

Title: User intentions analysis


答:
Yes, there are many.

A stack trace can reveal

what encryption algorithm you use

what some existing paths on your application server are

whether you are properly sanitizing input or not

how your objects are referenced internally

what version and brand of database is behind your front-end

... the list goes on and on. Basically every design decision in a large application might be security-relevant, and almost all of them may be given away through method or module names. Mind you, that doesn't mean it doesn't still make sense to display a stack trace if the environment it's submitted to is safe (e.g. an intranet rather than an internet-facing website), but the cost in security is defintely not zero.


答:
I'd first figure out what your goals are here.  You don't want to hand over the code and you don't want to burn bridges, but what do you want to do with it now?  Open source it?  Try to sell it?  I'm not sure if you know, but I'd figure that out first.

Once you know what you goal is, I'd sit down with your boss and calmly explain your position before you do anything.  Explain how you put a lot of effort into your code, and that you'd rather not hand it over.  You're working for free, so I don't believe your boss can force you to do anything.  If you want to open source it, tell him before you do it.  Otherwise it might look like you tried to undercut him.  If you want to sell it, tell him you're open to negotiating with his brother.

The biggest thing here if you don't want to burn bridges is to be as straightforward and polite as you can.  Don't let on that you're aggravated or insulted that they want you to hand over work and don't be accusatory.  Just explain why you don't want to hand over your code and what you'd like to do with it instead.  If they're reasonable, they should understand.  If they give you grief then frankly I wouldn't worry about it.  If they're going to try to bully you into handing over your work, then they're frankly not worth it.


答:
The thing is, it's not our primary job to make things easier on ourselves.  It's our job to make things easier on the end user.  To us, a stack trace looks like an extremely useful piece of information to provide a developer.  To a user, it looks like complete gibberish that is of no use whatsoever.  Even if you tell them otherwise, they don't internalize it.  If you think it's hard getting that information from system administrators, getting it from end users is even worse.

As far as security goes, you might have a point if it was a desktop application.  In that case, printing a stack trace doesn't provide anything an attacker doesn't already know.  On a web app, that information isn't already available to an attacker.  You are indeed exposing internal details that will make an attack a lot easier.

Why not bypass both sources of concern and get exception reports automatically sent to you?  That way you don't even need to worry about people not reporting errors.