答:
What David Hammen said.  Your question doesn't make a lot of sense.  E.g. would you program Shortest Path Programming or Dynamic Programming as opposed to Object Oriented programming?  No these are just techniques for constructing algorithms.  Similarly Linear Programming is just another technique for constructing algorithms.  You probably heard of network flow problems (if not consult any algorithm text book) and these can all be modeled as more general linear programs that can be solved by linear programming.  It is more efficient to use specialized network flow algorithms to solve them.

Supposedly linear programming is much more efficient now that some patents expired on newer techniques for solving those problems.  You can generally find solver libraries to solve these problems for you.

People in operations research commonly use linear programming.  For example, how do you assign people to teams where you have some information on how well each person fits in a team and you want to maximize the fit or minimize some cost (like pay for each team) over all the assignments?  You can use linear programming to find the answer.

I used to work with a bunch of chemical engineers who in their previous job worked creating simulations of oil refineries.  They would program optimization problems all the time.

So basically it is used primarily in optimization.  But this is not a programming paradigm like object oriented, procedural, or functional.  It is just another technique for solving algorithms like greedy, dynamic programming, divide and conquer, etc...

Title: Common to use linear programming?

Body:
I have read about linear programming and its content and I wonder if this way of programming is common to use in the market? I often hear about object oriented programming but not linear programming.

I would like to hear a discussion about it.


问:
Do I need to understand pointers to use C++?
Well, I love C++, I have been using it for a while: I like all the libraries (Allegro, SDL, QT, Ogre, etc.), but I have a problem: I don't understand pointers.

Do I really need them ? I just program for fun: but I want to study it some day.
Thanks.

答: Yes, you need them, if you want to use libraries like the one you mention, that are designed to rely on them.</p>

ContentLicense: CC BY-SA 3.0


问:
Storing passwords for usage in scripts
There are few situations that require users to provide their password while automating things during development process. Site deployment is only one of the common situations. Creating dmg files under OS X requires password as well. Most of the command line utilities used in scripts has an ability to receive a password via stdin.

Providing password each time the script is run kinda defeats the purpose of "automatic". Storing it plain text in the script defeats the purpose of "password". What is the most optimal approach to providing passwords to scripts that requires them?

答: If the purpose of the password is to ensure the operation is authorized by the person trusted with the password, then it makes no sense to attempt to bypass it or automate it.</p>

Title: Storing passwords for usage in scripts


问:
Who is responsible for defects found during development?
When the QA find an error like 'broken design in web programming', do you call it a bug and the corrections 'patches'? (Assume all this is before delivery.)

I was of the feeling that the corrections for bugs found after delivery were called patches.

Developers don't add bugs intentionally and it's QA's duty to find bugs. Sure I agree a programmer should be able to solve the bug, but should the programmer be blamed for these bugs?

答:
'Bug' is a very broad and often misused term, so please define what you mean by 'bug'.

Having said that, generally, the one who wrote the code is responsible for the defect. But sometimes 'bugs' are due to deficiencies in requirements gathering, or bad behavior on the part of other components of a system that the writer of the code could not forsee and/or control.


问:
Why prefer a wildcard to a type discriminator in a Java API (Re: Effective Java)
In the generics section of Bloch's Effective Java (which handily is the "free" chapter available to all: http://java.sun.com/docs/books/effective/generics.pdf), he says:

If a type parameter appears only once in a method declaration, replace it with a wildcard.

(See page 31-33 of that pdf)

The signature in question is:

```<code>public static void swap(List<?> list, int i, int j)
</code>```

vs

```<code>public static void swap(List<E> list, int i, int j)
</code>```

And then proceeds to use a static private "helper" function with an actual type parameter to perform the work.  The helper function signature is EXACTLY that of the second option.

Why is the wildcard preferable, since you need to NOT use a wildcard to get the work done anyway?  I understand that in this case since he's modifying the List and you can't add to a collection with an unbounded wildcard, so why use it at all?

答:
Why is the wildcard preferable

I believe Josh states it clearly:

In a public API, the [wildcard] is better because it’s simpler.

That is, for the users of the API. The small extra complexity in the implementation is not visible from outside. And as the implementation is written only once, but the API may be used many times by many different people, simplifying the API at the cost of making the implementation slightly more complex is still an overall win.

> why use it at all?

You mean, why is it better than

```<code>public static void swap(List list, int i, int j)
</code>```

? Because the latter would forfeit generics altogether, letting the compiler omit all generic type checking, and allowing us to write sloppy code. I think it is better to use generic type signatures even if they are this general, just to keep up the habit.

Update reflecting on the comment below

You forgot the generic parameter declaration from the second signature, correctly it should be

```<code>public static <E> void swap(List<E> list, int i, int j)
</code>```

That is, <E> appears twice, for no added benefit, vs <?> appearing only once in the first signature. This is why it is simpler.

Body:
Why is the wildcard preferable

I believe Josh states it clearly:

In a public API, the [wildcard] is better because it’s simpler.

That is, for the users of the API. The small extra complexity in the implementation is not visible from outside. And as the implementation is written only once, but the API may be used many times by many different people, simplifying the API at the cost of making the implementation slightly more complex is still an overall win.

> why use it at all?

You mean, why is it better than

public static void swap(List list, int i, int j)

? Because the latter would forfeit generics altogether, letting the compiler omit all generic type checking, and allowing us to write sloppy code. I think it is better to use generic type signatures even if they are this general, just to keep up the habit.

Update reflecting on the comment below

You forgot the generic parameter declaration from the second signature, correctly it should be

public static <E> void swap(List<E> list, int i, int j)

That is, <E> appears twice, for no added benefit, vs <?> appearing only once in the first signature. This is why it is simpler.


问:
What is better for prototyping: a statically-typed language, or a dynamically-typed one?
When working out the design for a new system, is it better to start with a statically-typed language (like Haskell), or a dynamically-typed language (like Ruby)?

Arguments I can think of:

With a static language, you can quickly create a specification and scope for what the program will do.  With a dynamic language, you can quickly create a working demo to present to the customer for review.

With a dynamic language, you often avoid having to rearrange data structures and refactor code when you change your design.  With a static language, you can define types before implementation, keeping the code to maintain very small.

With a static language, you have to figure out in advance what your program will do.  With a dynamic language, you can start writing code, and let the design grow organically.  As Paul Graham says in Hackers and Painters:

A programming language is for thinking of programs, not for expressing
  programs you've already thought of.

With a static language, the compiler can help identify many types of bugs.  With a dynamic language, you can begin testing and finding bugs sooner.

Static and dynamic typing both have advantages and disadvantages as far as prototyping is concerned.  However, they both seem to me like equally valid approaches.  Based on your experiences, which one is ultimately better?

Notes

Prototyping in natural language

A third type of language to consider: natural language.  Instead of prototyping in code, one can prototype in writing.  The customer can then read your documentation and critique your design early on, but cannot toy around with a working demo.  If well-written, the documentation can make implementation in any language straightforward.  Caveats:

The documentation may be tedious to read through, and difficult to digest without being able to see it.  I speculate that a customer would rather experiment with something that works rather than read a wall of text (and images).

Prototyping an application in English rather than in type definitions is more verbose and less concrete.

Haskell types are descriptive

Note that types are particularly descriptive in Haskell, more so than in many static languages like C++ and Java.  For example, suppose I have a function with this type signature in Haskell:

```<code>foo :: forall a. [a] -> a
</code>```

A function that, for any type a, takes a list of items of type a and returns a value of type a.

Even without knowing the function's name, I know for a fact that:

It does not perform input/output or modify any values (well, unless it uses unsafePerformIO incorrectly), because Haskell is purely functional.

It cannot treat the items as, say, integers, because it has to support any type.

It has to use the input list (that, or throw an exception or go into an infinite loop).  Otherwise, where would it get a value of type a from?

Therefore, the only thing this function could possibly do (other than fail) is extract an item out of the input list and return it.  Although I still do not know which item it will use, [a] -> a tells me just about everything else.

答:
I'm going to side with Paul Graham on this one: dynamic typing is most useful for creating programs organically, which is exactly what prototyping ought to be. The point is to get something done quickly that demonstrates the functionality of the final product, not the final product itself. Static typing is about formal correctness—well, ostensibly; at least it should be (as in Haskell or Agda)—but dynamic typing is about practical correctness, which is what matters more when you're prototyping.

In the right language, static type hints can be provided after the fact as an optimisation (and to provide added safety for future changes), or the prototype can be rewritten in a statically typed language once the requirements have been elucidated and solidified by the prototype.


问:
Best Practices for Corporate Sponsorship of Open Source Project
We are preparing to OpenSource our ASP.NET MVC multi-tenancy CMS.  We currently use BitBucket.org to host our source repository and we are considering best approaches to repository naming.

In terms of the user/host of the repository, We are debating using our company name which is the sponsor of the project versus the project name itself.

The company name is JoyaTech Solutions, the project name is JoyaCMS.

Do people think that having a company name as the user/owner of an open source project is a turn off or is there value in displaying that relationship?

答: To the programming community, software is either open source or not. Your software could be called something ridiculous and if it's open source, most people would not care. Then again, you haven't specified what your goal is or what you're trying to prevent. I'm going to guess you're considering usage of your software.</p>


问:
What happens at [platform] user groups?
I'm a .NET developer, but I've never been to a .NET user group meeting or anything like that.

I might have the opportunity soon to start attending one, but I'm wondering. What happens at user groups? I'm not looking necessarily for info specifically about .NET ones, but they are preferred.

What do you get out of it excluding the opportunity for networking?

答: In addition to the items listed by @Ryan, sometimes employers make a quick "I am hiring; please see me after the meeting if you're looking for work" announcement. Or someone talks about the conference they are having in a month or two, maybe asks for volunteers with some project related to the community. It's a great way to stay connected.</p>

ContentLicense: CC BY-SA 2.5

Title: What happens at [platform] user groups?


问:
Manager keeps changing requirement specification after every demo

Background of my working environment

My manager has no background or understanding of computers or software whatsoever. It is highly likely he hasn't seen code in any form (not even from a physical distance of 10 feet or less) in his life.

There is no one who understands the complexity of what I am asked to implement. To the point that if I semi-hardcode no one would know.

On Joel's test we score an unbelievable score 0.

The problems

The manager and at times other "senior" keep changing the requirement specification. Changes which, if good engineering be done and not patchy "fixes", require change in the underlying design.

There is absolutely no one who looks at code (probably because no one knows how to, or even if it should be done) which means no one will ever be able to:

Appreciate the complexity of the problem or the elegance of the solution.

Suggest improvement to the approach.

Appreciate the quality of the code.

Point out where the code can be improved.

A lot of jargon is used which makes sense grammatically but fails to make any sense any other way.

Doesn't feel, behave or work like a software company.

The question

What should be done? Especially regarding there being no one who would point out improvements in my code.

Update

To answer HLGEM's (and possibly others) question about what I've done to try and fix it. I offered to set up Redmine and introduce source control to everyone. I said I would recommend distributed (git or mercurial) but will also talk about centralized ones and let the team decide. Response was that things are being done and will be done within weeks. Haven't seen that nor am I aware if other parts of the company use it.

答:
Option 1 - tell them 'with all the changes you are making to this project, by the time we deploy it, the system will run very slowly' or 'the customer won't be able to figure it out'. Your managers don't care about spaghetti code but they do care about customer. Pitch the problem to them in terms of what they comprehend, not in terms of code writing.

Option 2 - give them what they want. When they complain about something you say 'but that's what you asked for'


问:
Is it better to team up with a graphical designer, or to piece out design work to a contractor?
I am clueless when it comes to graphical design but I am proficient in programming. If you are a programmer who lacks visual design skills, what has worked best for you -- to pair up with a graphic designer or to do all the programming and then piece out specific work?

I have done some piecing out of work but I am not completely satisfied because I see too much of my influence come out in the design.  I guess this happens since I have to be explicit in what I want with contractors, and they are limited in creativity by the architecture I have created.

It feels like having a partner would allow for greater collaboration, but I have read plenty of entrepreneur books that warn against partnerships.

答:
In my experience I've found that finding a designer that is consistently available to do any front end work that your projects need is worth their weight in gold over contractors. You learn what each other likes, how you communicate, and just mesh as a unit much easier.

Now this can happen with contractors of course, and not every designer available consistently is going to be guaranteed to be awesome on first choice, but from my experience, the odds stack in the designers favour. Not only was that the arrangement when I was running my own company, but for most shops I've worked for, almost all of them have at least one designer hired to do just that. The one or two that didn't, would have one hired within a year or two after trying to have the developers do design as well.


问:
Favoring Immutability in Database Design
One of the items in Joshua Bloch's Effective Java is the notion that classes should allow mutation of instances as little as possible, and preferably not at all.

Oftentimes, the data of an object is persisted to a database of some form. This has led me to thinking about the idea of immutability within a database, especially for those tables that represent a single entity within a larger system.

Something I have been experimenting with recently is the idea of trying to minimize the updates I do to table rows representing these objects, and trying to perform inserts instead as much as I can.

A concrete example of something I was experimenting with recently. If I know I might append a record with additional data later on, I'll create another table to represent that, sort of like the following two table definitions:

```<code>create table myObj (id integer, ...other_data... not null);
create table myObjSuppliment (id integer, myObjId integer, ...more_data... not null);
</code>```

It is hopefully obvious that these names are not verbatim, but just to demonstrate the idea.

Is this a reasonable approach to data persistence modeling? Is it worth trying to limit updates performed on a table, especially for filling in nulls for data that might not exist when the record is originally created? Are there times when an approach like this might cause severe pain later on?

答:
The primary purpose of immutability is to ensure that there's no instant in time when the data in memory is in an invalid state. (The other is because mathematical notations are mostly static, and so immutable things are easier to conceptualize and model mathematically.) In memory, if another thread tries to read or write data while it's being worked with, it might end up going corrupt, or it might itself be in a corrupt state. If you have multiple assignment operations to an object's fields, in a multithreaded application, another thread might try to work with it sometime in between -- which could be bad.

Immutability remedies this by first writing all the changes to a new place in memory, and then doing the final assignment as one fell-swoop step of rewriting the pointer to the object to point to the new object -- which on all CPUs is an atomic operation.

Databases do the same thing using atomic transactions: when you start a transaction, it writes all the new updates to a new place on disk. When you finish the transaction, it changes the pointer on disk to where the new updates are -- which it does in a short instant during which other processes can't touch it.

This is also the exact same thing as your idea of creating new tables, except more automatic and more flexible.

So to answer your question, yes, immutability is good in databases, but no, you don't need to make separate tables just for that purpose; you can just use whatever atomic transaction commands are available for your database system.


答:
I think the static vs. dynamic type issue isn't as important as many people make it out to be.

I use both. Sometimes one is simply more useful than another in a given situation. This is most often caused by needing to use some specific tool/library/technology. So I chose what works well with the other components I have.

I think that one of the things that people like about dynamic languages is that many are interpreted; You can modify them while they are running in an interactive manner using a REPL console. Any language with an eval function or something equivalent can do this. So, at least for this one aspect the type system is actually irrelevant.

You can build prototypes using things that have no formal type system at all like shell scripts. (They do have REPL though...)

Title: What is better for prototyping: a statically-typed language, or a dynamically-typed one?

Body:
When working out the design for a new system, is it better to start with a statically-typed language (like Haskell), or a dynamically-typed language (like Ruby)?

Arguments I can think of:

With a static language, you can quickly create a specification and scope for what the program will do.  With a dynamic language, you can quickly create a working demo to present to the customer for review.

With a dynamic language, you often avoid having to rearrange data structures and refactor code when you change your design.  With a static language, you can define types before implementation, keeping the code to maintain very small.

With a static language, you have to figure out in advance what your program will do.  With a dynamic language, you can start writing code, and let the design grow organically.  As Paul Graham says in Hackers and Painters:

A programming language is for thinking of programs, not for expressing
  programs you've already thought of.

With a static language, the compiler can help identify many types of bugs.  With a dynamic language, you can begin testing and finding bugs sooner.

Static and dynamic typing both have advantages and disadvantages as far as prototyping is concerned.  However, they both seem to me like equally valid approaches.  Based on your experiences, which one is ultimately better?

Notes

Prototyping in natural language

A third type of language to consider: natural language.  Instead of prototyping in code, one can prototype in writing.  The customer can then read your documentation and critique your design early on, but cannot toy around with a working demo.  If well-written, the documentation can make implementation in any language straightforward.  Caveats:

The documentation may be tedious to read through, and difficult to digest without being able to see it.  I speculate that a customer would rather experiment with something that works rather than read a wall of text (and images).

Prototyping an application in English rather than in type definitions is more verbose and less concrete.

Haskell types are descriptive

Note that types are particularly descriptive in Haskell, more so than in many static languages like C++ and Java.  For example, suppose I have a function with this type signature in Haskell:

```<code>foo :: forall a. [a] -> a
</code>```

A function that, for any type a, takes a list of items of type a and returns a value of type a.

Even without knowing the function's name, I know for a fact that:

It does not perform input/output or modify any values (well, unless it uses unsafePerformIO incorrectly), because Haskell is purely functional.

It cannot treat the items as, say, integers, because it has to support any type.

It has to use the input list (that, or throw an exception or go into an infinite loop).  Otherwise, where would it get a value of type a from?

Therefore, the only thing this function could possibly do (other than fail) is extract an item out of the input list and return it.  Although I still do not know which item it will use, [a] -> a tells me just about everything else.


问:
Should I use one database per application or share a single database amongst multiple applications
I have multiple applications some that use data from the same sources.
Is it best practice (or what are the pros/cons) to:

leave the data in databases shared by multiple applications

saves space as only one database is needed

complicates indexing as different applications have different querying needs

import data daily into per-app databases

uses more space as duplicated data exists in per-app databases

easier indexing as each app can focus on its individual needs

I may have left out other advantages/disadvantages, please list if any, also how is this done at your workplace?

答:
If these applications are meant to work from the same data - for example, the same list of products and customers - then keep the database together.  You dont gain anything by seperating the databases.  Thats purely a 'human' issue - to the server its just bytes on a disk.  It doesnt care if its 1 or 100 databases.  But if you do split it, you then have to deal with data synchronization.  The indexing issues you bring up arent a real issue - you'd spend the same amount of processor time maintaining the indexes if the db's were split.

If performance starts becoming an issue, replicated the db to multiple servers to balance things out.


问:
What should you leave behind for your successors?
Assume that you're a sole developer leaving a job. What kind of information/material, outside of the code itself, should you create and leave behind for your replacement?

An obvious answer is "whatever you would want at a new job" for sure, but it's been a while since I started a new job, and I forget what the most important things that I needed were back then.

I'm thinking:

accounts/passwords

location of equipment, backups, software CDs

What else?

答: We'd all like a complete data flow diagram of the system with a list of functional requirements. More than likely you never got that when you wrote the system in the first place ! Like most places the best documentation is probably the code itself so what I would love most is well documented code. Lines and lines of comments in the code explaining what you are trying to do both technically and functionally.</p>


答:
Do what works best for you and for what you are trying to do.  I find that I currently prototype best in a static language.  Prototyping with an expressive type system lets you do some cool things:

Write function signatures without corresponding implementations.  My early stage Haskell code often has statements like:

foo :: Foo -> Bar

 foo _ = error "not defined"

This is because I want an idea of what foo does when I write code that uses it, without having to actually have a working copy of foo.  In other languages this is accomplished with something like throw new Exception(), which is something you would never do in real code, but helps a ton at early stages.

Write code without writing the types first, and use type inference to learn things about your code.  I frequently call :t in the GHCi (Haskell REPL) to discover what it was that I just wrote.  For example, this can tell you how generic a piece of code is, thus revealing the requirements of different pieces of your code and corresponding structure.

Conal Elliot described his view of Haskell to help with iPhone development this way:

"Once I was writing Haskell, the imperative machinery faded from view and I couldn’t help but start seeing essential patterns. Tinkering with those patterns led me to new insights ... I am grateful to have this higher-order lazy language with rich static typing as a thought tool, to help me gain insights and weed out my mistakes. It’s a bonus to me that the language is executable as well."  Source

That's right.  One of the gods of functional programming thinks that Haskell's primary worth is a modeling language, rather than a implementation language.  Other guru's think similar things: Erik Meijer uses Haskell to help clarify underlying algebra and patterns that eventually go into object oriented frameworks.

The most important reason though for prototyping in a strict language, is that much of the time the things one wants to "prototype" are not the nifty early stage web apps that Paul Graham wants to fund.  Often you need to prototype:

Extensions to current infrastructure

APIs for a specific language

Architecture, not just new features

In each of these cases you really want to use a language that is close to the eventual implementation language in meaningful ways.

One nitpick though

```<code> foo :: forall a. [a] -> a
</code>```

has no "correct" (always terminates without producing an error or undefined) instances.  That is because

```<code>[] :: forall a. [a]
</code>```

But no function from [] to a could exist for a that have no instances.

Body:
Do what works best for you and for what you are trying to do.  I find that I currently prototype best in a static language.  Prototyping with an expressive type system lets you do some cool things:

Write function signatures without corresponding implementations.  My early stage Haskell code often has statements like:

foo :: Foo -> Bar

 foo _ = error "not defined"

This is because I want an idea of what foo does when I write code that uses it, without having to actually have a working copy of foo.  In other languages this is accomplished with something like throw new Exception(), which is something you would never do in real code, but helps a ton at early stages.

Write code without writing the types first, and use type inference to learn things about your code.  I frequently call :t in the GHCi (Haskell REPL) to discover what it was that I just wrote.  For example, this can tell you how generic a piece of code is, thus revealing the requirements of different pieces of your code and corresponding structure.

Conal Elliot described his view of Haskell to help with iPhone development this way:

"Once I was writing Haskell, the imperative machinery faded from view and I couldn’t help but start seeing essential patterns. Tinkering with those patterns led me to new insights ... I am grateful to have this higher-order lazy language with rich static typing as a thought tool, to help me gain insights and weed out my mistakes. It’s a bonus to me that the language is executable as well."  Source

That's right.  One of the gods of functional programming thinks that Haskell's primary worth is a modeling language, rather than a implementation language.  Other guru's think similar things: Erik Meijer uses Haskell to help clarify underlying algebra and patterns that eventually go into object oriented frameworks.

The most important reason though for prototyping in a strict language, is that much of the time the things one wants to "prototype" are not the nifty early stage web apps that Paul Graham wants to fund.  Often you need to prototype:

Extensions to current infrastructure

APIs for a specific language

Architecture, not just new features

In each of these cases you really want to use a language that is close to the eventual implementation language in meaningful ways.

One nitpick though

 foo :: forall a. [a] -> a

has no "correct" (always terminates without producing an error or undefined) instances.  That is because

[] :: forall a. [a]

But no function from [] to a could exist for a that have no instances.


问:
What is a good code practice of when to make a function/method for small repetitive code segments?
Many times throughout writing larger programs I have questioned after how many copy and pastes does it make sense to put the code into a function or method and what is a good rule of thumb?
I have been using a rule of thumb of four lines or greater and appearing more then twice, then I make a simple function / method containing that code.
Can you think of a better practice or offer any pointers?
This is more of a general design pattern question rather then a language specific question.</p>

答:
That depends on the nature of the cohesion of the repeated code. If the repeated section of code is performing a specific function, then it is an excellent candidate for being made into a method, partly because of the DRY principle, partly because if the function needs to be optimized or corrected, then there is only one section of code to deal with.

If the association is coincidental, it is better to repeat the code rather than make it into a method. If you need to add something to the middle of one of the code sequences to satisfy one of the uses of that snippet, if it is in a method, the change you make may affect other uses of that method.

See the Wikipedia article on the concept of code cohesion.

OwnerDisplayName: Nirma


问:
What is the best way to maintain software tool chains?
Short Question

What is the best way to create, maintain, and distribute software development tool chains?

Background

I am trying to develop a workflow / process to create an isolated environment in install and deploy software tool chains for embedded targets.  Each tool chain typically would contain an IDE, compiler, and a small set of common tools.  I have looked into two solutions but the both have their limitations and I hope to find a solution that has the best of both implementations.

The rational behind a stand alone tool chain is so that all developers would be able to build the exact same code (matching CRC etc..).  As well as be able to rebuild the same code after X number of years to support legacy code.  A third option would be to use a central build server, which we plan on doing for nightly builds, but we still need to be able to build 'on the fly' when working on a test bench or remotely.  So only using a build server will not suffice.

Ideal Goals for Deployed tool chain

Work on Windows XP, Vista, and 7 (excluding drivers)

Contain all required information to run use the tool chain (excluding drivers)

------------------ Possible Options ------------------

Option 1: Full Stand alone Virtual Machine

Pros

Open Source packaging via Virtual Box

100% isolation

Guarantees the tools can interact with one another

Cons

Licensing multiple copies of windows

At best only one developer could legally use a Windows VM at a time.

Running the same VM on physically different lap tops (Macbook Pro, Dell 830, Dell E6500, etc...).  Typically when Windows see's a new CPU or motherboard it will force a re-activation.

Very large files to maintain

Option 2: Virtualized Application

Pros

Through packagers like Cameyo, applications can run on nearly all versions of Windows.  (Note that Cameyo is also free)

Little to no licensing issues for most tools / IDEs.  Purchased compilers might have additional restrictions, all of our current compilers do support this type of usage.

Smaller files to maintain via a SCM, such as  SVN or GIT.

Cons

Difficult, if even possible, to get a single file that contains the entire tool chain

Difficult, if even possible, to get the tools to see / work with one another.  I have seen this very issue with Cameyo.

Closing Thoughts

There may not be a solution that meets all of my design goals, but I would like to find out if anyone else been successful in this type of deployment.

答:
I was doing exactly this a few years ago, and found the answers were either a full VM solution, or a meticulous version control system for all of you build setup.
Given you appear locked into Windows, you could get an MS developer license that allows multiple copies per dev of Windows, and activation and legal issues disappear for a annual fee.

We ended up with a build server and a rule the only way to get anything onto the build server was through the revision control. A few squeals from some about binaries and size issues aside, it worked. The relaxation to that was a file containing list of clearly labeled DVD's, a file store of ISO images of those, along with full build machine setup instructions. These we randomly tested for accuracy, and although they rarely worked first time, were always able to bring up a build server from a clean VM.

Keep in mind, disk-space is very cheap, use it. Licenses can be a pain, but work with the tool provider (including MS) to find a solution.

Broken build machines, inability to build old software etc is expensive, but so is carrying around excess baggage. If the software really is past it's use by date, destroy it. Don't keep stuff lying around because you might need it one day. Only keep it around because you will need it or are legally obligated to.

In the end with an embedded system build, you should be able to bring up a clean build machine from source and a couple of install DVD's. If you need more than that, look at your tool chainan consider it may be too complex to be reliable.

My goal was always "Clean machine, Checkout, make, deploy." never got there, but got very close most times...


问:
C++ to friend or not to friend
I have an object oriented programming with c++ course this semester at college and we were learning about friend functions.

I instinctively dislike them for their ability to bypass the security that Encapsulation and Data hiding provide, I read a few articles on the internet and some people thought that it was a good idea with some legitimate uses.

What would an OOPs expert say about friend fucntions in C++? Should I just skim over it or should I learn more about it?

答:
Does "friend" violate encapsulation?

No. It does not. "Friend" is an explicit mechanism for granting access, just like membership. You cannot (in a standard conforming program) grant yourself access to a class without modifying its source.

Title: C++ to friend or not to friend


答:
Versioned toolchain, shared out via file servers

It's been awhile, but when I last worked with windows it was for a multi-platform product.  linux-x86, linux-arm, win-ce, and win-nt.  I think we managed the toolchain on all platforms by installing into a segregated directory, and then checking that into version control.  We then checked them out onto a nfs server (linux), and windows share server for mounting by the developers and build machine.

We had to jump through a few hoops to make sure no writes were happening to the remotely mounted directories, but other than that it worked pretty well.  I don't think we actually had to install the entire IDE in separate directories, just the compiler, linker, and standard libs.

We did updates/upgrades in place.  Various versions were checked out into different directories and used by anyone who working on customer problems, bug fixes, etc.

Title: What is the best way to maintain software tool chains?

Body:
Short Question

What is the best way to create, maintain, and distribute software development tool chains?

Background

I am trying to develop a workflow / process to create an isolated environment in install and deploy software tool chains for embedded targets.  Each tool chain typically would contain an IDE, compiler, and a small set of common tools.  I have looked into two solutions but the both have their limitations and I hope to find a solution that has the best of both implementations.

The rational behind a stand alone tool chain is so that all developers would be able to build the exact same code (matching CRC etc..).  As well as be able to rebuild the same code after X number of years to support legacy code.  A third option would be to use a central build server, which we plan on doing for nightly builds, but we still need to be able to build 'on the fly' when working on a test bench or remotely.  So only using a build server will not suffice.

Ideal Goals for Deployed tool chain

Work on Windows XP, Vista, and 7 (excluding drivers)

Contain all required information to run use the tool chain (excluding drivers)

------------------ Possible Options ------------------

Option 1: Full Stand alone Virtual Machine

Pros

Open Source packaging via Virtual Box

100% isolation

Guarantees the tools can interact with one another

Cons

Licensing multiple copies of windows

At best only one developer could legally use a Windows VM at a time.

Running the same VM on physically different lap tops (Macbook Pro, Dell 830, Dell E6500, etc...).  Typically when Windows see's a new CPU or motherboard it will force a re-activation.

Very large files to maintain

Option 2: Virtualized Application

Pros

Through packagers like Cameyo, applications can run on nearly all versions of Windows.  (Note that Cameyo is also free)

Little to no licensing issues for most tools / IDEs.  Purchased compilers might have additional restrictions, all of our current compilers do support this type of usage.

Smaller files to maintain via a SCM, such as  SVN or GIT.

Cons

Difficult, if even possible, to get a single file that contains the entire tool chain

Difficult, if even possible, to get the tools to see / work with one another.  I have seen this very issue with Cameyo.

Closing Thoughts

There may not be a solution that meets all of my design goals, but I would like to find out if anyone else been successful in this type of deployment.


答:
Design first because it drives the work

In my experience it's always much easier to start with design mockups.  This helps to drive how much work there actually is to do and it helps with the prioritization.  It also have a longer period of time to evaluate how the design and how it works.

Update

The implication is to pair up with a designer.  That or at least make the design the first work completed.  Doing it after the fact just means you probably have more programming to do since there are always integration issues.

Title: Is it better to team up with a graphical designer, or to piece out design work to a contractor?

Body:
I am clueless when it comes to graphical design but I am proficient in programming. If you are a programmer who lacks visual design skills, what has worked best for you -- to pair up with a graphic designer or to do all the programming and then piece out specific work?

I have done some piecing out of work but I am not completely satisfied because I see too much of my influence come out in the design.  I guess this happens since I have to be explicit in what I want with contractors, and they are limited in creativity by the architecture I have created.

It feels like having a partner would allow for greater collaboration, but I have read plenty of entrepreneur books that warn against partnerships.


问:
How have you got chances to learn multiple languages?
I read A programmer should concentrate on at least how many languages?, and I found out that I don't know languages in number 2, 3 of first answer. I want to learn more languages to increase my knowledge and programming skill. However, usually in companies they use fixed framework and languages and changes seldom. So I'm not sure if I can get a chance to learn those languages and I think it would be same to other programmers.

However, I've seen many developers who knows multiple languages in here. How do you get chances to learn many languages?

Update

I think, there are many people who feel uncomfortable because it seems I don't want study in my spare time at all. Actually, that's not true.:) I'm an enthusiast programmer and that's why I posted this kind of question here. I study in my spare time but I just thought it would be not enough to be skillful in languages. Anyway, thanks for all answers!

答:
Sometimes opportunities come from you employment. There are usually one of three drivers for this type of opportunity.

It is a brand new technology. For instance, many companies paid for C# training for their developers in the first two or three years after .NET was released.

It is easy to learn. For instance, in a linux shop, you will find you need to write .bash scripts. If you have been using terminal sessions, etc., and there are other developers who have experience writing them, you should be able to acquire this skill, if only to automate some of your own tasks.

It is uncommonly used technical skill, and your company does not want to go through the time and expense of finding a consultant to do the work. For instance, I learned how to write XSLT because we needed an easy way to transform some XML (log) files for display.

Other opportunities you need to make for yourself outside of work. Choose carefully -- what technologies do you see being useful in the future? In these cases, you have to put time and effort into learning and applying the technology. This should be part of an overall career plan, and you may have to pay for classes. (I was lucky -- when I learned Java, they were teaching it evenings at a local community college).


问:
Should my multi-server RDBMS or my Application handle database Referential Integrity?
Should items like Foreign Keys, Constraints, Default Values, and so on be handled by the database management system (in this case, MS SQL 2005) or the application? I have heard opinions from both sides and I'm honestly not sure which way to go.

There is a chance we will be spanning multiple servers/databases and I don't think Foreign Keys can be used across linked servers. In addition to that, there are some circular references in the database design which prevents me from using ON UPDATE CASCADE on everything.

The database is MS SQL 2005 (possibly 2008) and all interactions with it should go through the application.

答:
If there's any chance that the DB will be modified outside your application, you want the constraints in the database.  If the DB is and always will be nothing more than the back end of the application, you can leave them out, although I'd document them just in case and probably just keep them in if the performance hit wasn't too bad.  (Peoplesoft software works this way - the constraints are in the software, and (I'm not making this up) it runs everything as SYS on Oracle.)

You want things like that to be monitored by the application, so it can react intelligently and not at best parrot back a database error message to the user.

And, yes, this is double coverage, but without it you're probably going to get preventable data corruption or a bad user interface.


答:
I consider that some fraction of my job is "research". In 1998 research meant fixing Y2K bugs. Last month reserch meant learning Subversion. I have beeen doing research for 40 years. When I list the languages I must list them in alphabetical order.

When I learn a language, I read the reference manual cover to cover. Then I actually use it for a few months. Then I read the reference manual again.  The second reading reveals lots of tricks and implications that I missed the first time through.

Practial research covers normal languages, like C# and Pascal. Advanced research covers weird languages, like LISP and FORTH. You will probably never use LISP professionally, but learning it broadens your mind considerably.

Of course, in my environment, I am not paid for time, I am paid for delivery. If I can deliver in two weeks, using six hours a day, I can use the other three for research. If it takes twelve hours a day, well, no research then.

All research, of course, should have some potential utility to the one paying me. Small utilities are good; next time you want to process your C source code, try it in Python. (No, I don't know Python, but I've heard it's good for string manipulation.)

Title: How have you got chances to learn multiple languages?

Body:
I read A programmer should concentrate on at least how many languages?, and I found out that I don't know languages in number 2, 3 of first answer. I want to learn more languages to increase my knowledge and programming skill. However, usually in companies they use fixed framework and languages and changes seldom. So I'm not sure if I can get a chance to learn those languages and I think it would be same to other programmers.

However, I've seen many developers who knows multiple languages in here. How do you get chances to learn many languages?

Update

I think, there are many people who feel uncomfortable because it seems I don't want study in my spare time at all. Actually, that's not true.:) I'm an enthusiast programmer and that's why I posted this kind of question here. I study in my spare time but I just thought it would be not enough to be skillful in languages. Anyway, thanks for all answers!


问:
PHP as a scripting language
I have reasonable knowledge of PHP, Perl, and Bash. I use Perl for most text processing on my system (find, replace, filter output, etc). I use PHP for web development, allowing a user to view and interact with database data via the browser. I use Bash for quick and dirty scripts often to supplement the more complex Perl scripts.

I'm a big believer of focusing on as few languages as possible (to get the job done) and becoming an expert in them.

So the question is, why not use PHP for the common tasks that Perl (and Bash) are used? Are there good reasons (limitations or features) why PHP is mostly used for web development, while Perl and Bash are mostly used for "offline" "scripting"?

答: I think its mostly tradition and preference and when people are looking for examples of how to do X,Y,Z if it tends to be in bash/perl, then why rewrite just to use php.</p>

Title: PHP as a scripting language


答:
Do you mean feature or design prototypes?

Feature prototypes are about showing a feature to the client before starting development of that feature from scratch in the final implementation language, so the point is to write that feature as fast as possible without concern for bugs or maintainability. Dynamic languages allow a correctness-productivity trade-off by allowing ugly hacks that no statically typed language would accept, which makes them, in theory, better suited for writing quick throw-away prototypes. Of course, in practice, the skill of the developer is more important than the language, but a coder equally skilled in both Haskell and Ruby would probably create a prototype faster in Ruby, and the resulting code would be a mess.

Design prototypes are about finding an appropriate program design through trial and error. Ugly hacks are useless — only the ability to refactor designs quickly matters. A fundamental requirement for massive refactoring is a suite of automated tests. In dynamic languages, this is usually a suite of developer-written unit tests, which takes a fair amount of time to write. In statically typed languages, the type signatures serve as automated tests and let the compiler detect any inconsistencies caused by code changes. Statically typed languages shine at refactoring in ways that no dynamically typed language can achieve.


答:
Because Perl has a much more powerful feature set than PHP.

Perl is a more general programming language, and has much more text operations capabilities than PHP, and probably than any other language out there, and better OS interaction.

Perl has a powerful Regex native support, which means string manipulations at its best.

Also, Perl has been around for many years now, and offers a huge library of modules. Create complex scripts with Perl is easy; with the right modules you only need to write little lines of code.

You may want to take a look at this great answer which explains clearly the differences between the two languages.

Title: PHP as a scripting language

Body:
I have reasonable knowledge of PHP, Perl, and Bash. I use Perl for most text processing on my system (find, replace, filter output, etc). I use PHP for web development, allowing a user to view and interact with database data via the browser. I use Bash for quick and dirty scripts often to supplement the more complex Perl scripts.

I'm a big believer of focusing on as few languages as possible (to get the job done) and becoming an expert in them.

So the question is, why not use PHP for the common tasks that Perl (and Bash) are used? Are there good reasons (limitations or features) why PHP is mostly used for web development, while Perl and Bash are mostly used for "offline" "scripting"?


答:
For system scripting, shell scripts have better interaction with the OS.  Its simpler to issue a command in a script rather than wrap that command in a function call in PHP.

That being said, there's no reason not to use PHP for various non-web applications, such as scheduled services/cron jobs that process data somehow (import/export/retrieve/etc).  Its perfectly suitable for such tasks.  I've been doing that for years.  Like you said, there's no point in maintaining code in multiple languages if its not necessary.

Title: PHP as a scripting language


问:
How do you change how intellij auto formats code?
IntelliJ does some odd formatting with Javascript code and I am trying to figure out how to get it to stop formatting this way.  Whenever I chain jQuery functions together, it over indents the auto created code such as this:

```<code>$('#something').focus(function() {
    /* Do some stuff */
}).blur(function() {
        /* this is where the cursor and closing braces end up */
        })
</code>```

I want it to look like this:

```<code>$('#something').focus(function() {
    /* Do some stuff */
}).blur(function() {
    /* cursor and closing braces indented normally */
});
</code>```

How do I change this?

答:
As @intarg mentions, in the comments. You can change File|Settings|Code Style|General and on the Javascript tab set Continuation Indent to 0 for Javascript.

That will get you most of what you want. the problem is that your code is actually all 1 long statement.

```<code>$('#something').focus(
function() {
    /* Do some stuff */
}).blur(function() {
    /* this is where the cursor and closing braces end up */
})
</code>```

Not sure that there is a relevant option to prevent a line break after focus(

Oh, and be sure that you have the Javascript code sample tab active when you are changing options - otherwise you will not change them for Javascript.

EDIT: Now that I have looked further. The Javascript formatter is coded to add a linebreak in that specific case, there isn't an option for it.

Body:
As @intarg mentions, in the comments. You can change File|Settings|Code Style|General and on the Javascript tab set Continuation Indent to 0 for Javascript.

That will get you most of what you want. the problem is that your code is actually all 1 long statement.

$('#something').focus(
function() {
    /* Do some stuff */
}).blur(function() {
    /* this is where the cursor and closing braces end up */
})

Not sure that there is a relevant option to prevent a line break after focus(

Oh, and be sure that you have the Javascript code sample tab active when you are changing options - otherwise you will not change them for Javascript.

EDIT: Now that I have looked further. The Javascript formatter is coded to add a linebreak in that specific case, there isn't an option for it.


答:
It depends on what benefits you expect to gain from immutability. Rei Miyasaka's answer addressed one (avoidance of invalid intermediate states), but here's another.

Mutation is sometimes called destructive update: when you mutate an object, the old state is lost (unless you take additional steps to explicitly preserve it somehow). In contrast, with immutable data, it's trivial to simultaneously represent the state both before and after some operation, or to represent multiple successor states. Imagine trying to implement a breadth-first search by mutating a single state object.

This probably shows up in the database world most often as temporal data. Say last month you were on the Basic plan, but on the 16th you switched to the Premium plan. If we just overwrote some field that indicated what plan you're on, we might have difficulties getting billing right. We might also miss out on the ability to analyze trends. (Hey, look what this local ad campaign did!)

That's what comes to my mind when you say "immutability in database design", anyway.

Title: Favoring Immutability in Database Design

Body:
One of the items in Joshua Bloch's Effective Java is the notion that classes should allow mutation of instances as little as possible, and preferably not at all.

Oftentimes, the data of an object is persisted to a database of some form. This has led me to thinking about the idea of immutability within a database, especially for those tables that represent a single entity within a larger system.

Something I have been experimenting with recently is the idea of trying to minimize the updates I do to table rows representing these objects, and trying to perform inserts instead as much as I can.

A concrete example of something I was experimenting with recently. If I know I might append a record with additional data later on, I'll create another table to represent that, sort of like the following two table definitions:

```<code>create table myObj (id integer, ...other_data... not null);
create table myObjSuppliment (id integer, myObjId integer, ...more_data... not null);
</code>```

It is hopefully obvious that these names are not verbatim, but just to demonstrate the idea.

Is this a reasonable approach to data persistence modeling? Is it worth trying to limit updates performed on a table, especially for filling in nulls for data that might not exist when the record is originally created? Are there times when an approach like this might cause severe pain later on?


答:
You have to distinguish between functions in the structured programming sense and methods of a class.

In your example, what you have shown is a method an as such should not be coded in-line.

you may have to validate a string to see if it is a number or not, in this case, you use a function and most of the preceding answers apply.

This distinction is important specially in large projects.

As much as you can, strive to separate business rules (that are methods) from computing algorithms (that are pure programming functions).

Title: What is a good code practice of when to make a function/method for small repetitive code segments?

Body:
Many times throughout writing larger programs I have questioned after how many copy and pastes does it make sense to put the code into a function or method and what is a good rule of thumb?
I have been using a rule of thumb of four lines or greater and appearing more then twice, then I make a simple function / method containing that code.
Can you think of a better practice or offer any pointers?
This is more of a general design pattern question rather then a language specific question.</p>


答:
Design, like programming is iterative. I think teaming up with a designer helps in this case.
Another point for teaming up is that it is not always easy to keep building comfortable relationship style and communication mechanisms between a designer and a developer where there are different views and several opportunities for friction.
Once you know someone and you are both comfortable in working together, the work becomes much easier.
Partnership does not necessarily have to be a long term contract. It may be for 1 or 2 projects.</p>


答:
I don't think there is any script you couldn't write in PHP.

Of course, Perl is specializied on administrative scripts.

But if your MO is using as little languages as possible, and you are already conversant with PHP, then use it. I don't think you'll miss any tools.

Title: PHP as a scripting language


答:
These days with PCNTL and POSIX functions you can use PHP for scripting and do anything a Perl/Python/Bash script can. My company uses PHP heavily for scripting including some non-trival cases (e.g. custom queue management run as a system service) and it appears PHP is as reliable as Perl/Python/Bash scripts.

However OS support in PHP has improved quite recently. Some time ago it was horrible. IIRC you only had only basic "Program execution" functions with some bizzare limitations (no proc_open() so only one-way pipes with popen() and so on). At the same time you could enjoy Perl/Python many OS modules and achieve anything you wanted with ease.

Title: PHP as a scripting language


答:
I once was a network admin in a student dorm and came across a firewall configuration script a predecessor had written in PHP. I think this was very prospective of him. Some student doing a little admin work (like me) is much more likely to know some PHP than one of the GP scripting languages normally used here. So I was able to do necessary changes without having to handle a language I never used before.
To be honest: When I later mentioned this script he admitted that it in some way was meant as a joke to utilize PHP in this way.</p>

Title: PHP as a scripting language


答: If it's important, let the database handle it.  That way, you don't have to worry about somebody accessing the database outside your application and changing or entering some inconsistent or duplicate data.  Unless it's some high-level application-specific stuff (like "only users in department X having an access class of ZZZ should be allowed to belong to group 999"), but that's not usually referred to as "referential" integrity.</p>

Title: Should my multi-server RDBMS or my Application handle database Referential Integrity?

Body:
Should items like Foreign Keys, Constraints, Default Values, and so on be handled by the database management system (in this case, MS SQL 2005) or the application? I have heard opinions from both sides and I'm honestly not sure which way to go.

There is a chance we will be spanning multiple servers/databases and I don't think Foreign Keys can be used across linked servers. In addition to that, there are some circular references in the database design which prevents me from using ON UPDATE CASCADE on everything.

The database is MS SQL 2005 (possibly 2008) and all interactions with it should go through the application.


问:
Do the young minds need to learn the pointer concepts?
Why did the C master Dennis Ritchie introduce pointers in C? And why did the other programming languages like VB.NET or Java or C# eliminate them? I have found some points in Google, and I want to listen your comments too. Why are they eliminating pointer concepts in modern languages?

People say C is the basic language and pointers is the concept that makes C powerful and outstanding and makes C still to compete with more modern languages. Then why did they eliminate pointers in more modern languages?

Do you think knowledge of pointers is still important for new programmers? People are using VB.NET or Java these days, which supports more highly advanced features than C (and does not use any pointer concepts) and many people as I see now (my friends) choose these languages ignoring C as they support advanced features. I tell them to start with C. They say it's a waste to learn the concepts of pointers when you're doing the advanced things in VB.NET or Java which are not possible in C.

What do you think?

Updated:

The comments I read on Google are:

The earlier computers were too slow and not optimized.

Using pointers makes it possible to access an address directly and this saves time instead of making a copy of it in function calls.

Security is significantly worse using pointers, and that's why Java and C# did not include them.

These and some more what I found. I still need some valuable answers. That would be greatly appreciated.

答:
Back in those days, developers were working much closer to the metal. C was essentially a higher level replacement for assembly, which is almost as close to the hardware as you can get, so it was natural you needed pointers to be efficient in solving coding problems. However, pointers are sharp tools, which can cause great damage if used carelessly. Also, direct use of pointers open up the possibility to many security problems, which weren't an issue back then (in 1970, the internet consisted of about a few dozen machines across a couple of universities, and it was not even called like that...), but became more and more important since. So nowadays higher level languages are consciously designed to avoid raw memory pointers.

Saying that "advanced things done in VB.Net or Java are not possible in C" shows a very limited point of view, to say the least :-)

First of all, all of these languages (even assembly) are Turing complete so in theory whatever is possible in one language, is possible in all. Just think about what happens when a piece of VB.Net or Java code is compiled and executed: eventually, it is translated into (or mapped to) machine code, because that is the only thing which the machine understands. In compiled languages like C and C++, you can actually get the full body of machine code equivalent to the original higher level source code, as one or more executable files/libraries. In VM based languages, it is more tricky (and may not even be possible) to get the entire equivalent machine code representation of your program, but still eventually it is there somewhere, within the deep recesses of the runtime system and the JIT.

Now, of course, it is an entirely different question whether some solution is feasible in a specific language. No sensible developer would start writing a web app in assembly :-) But it is useful to bear in mind that most or all of those higher level languages are built on top of a huge amount of runtime and class library code, a large chunk of which is implemented in a lower level language, typically in C.

So to get to the question,

Do you think knowledge on pointers to the young people [...] is important?

The concept behind pointers is indirection. This is a very important concept and IMHO every good programmer should grasp it on a certain level. Even if someone is working solely with higher level languages, indirection and references are still important. Failing to understand this means being unable to use a whole class of very potent tools, seriously limiting one's problem solving ability in the long run.

So my answer is yes, if you want to become a truly good programmer, you must understand pointers too (as well as recursion - this is the other typical stumbling block for budding developers). You may not need to start with it - I don't think C is optimal as a first language nowadays. But at some point one should get familiar with indirection. Without it, we can never understand how the tools, libraries and frameworks we are using actually work. And a craftsman who doesn't understand how his/her tools work is a very limited one. Fair enough, one may get a grasp of it in higher level programming languages too. One good litmus test is correctly implementing a doubly linked list - if you can do it in your favourite language, you can claim you understand indirection well enough.

But if not for anything else, we should do it to learn respect for the programmers of old who managed to build unbelievable things using the ridiculously simple tools they had (compared to what we have now). We are all standing on the shoulders of giants, and it does good to us to acknowledge this, rather than pretending we are the giants ourselves.


问:
Is there a term for the error-handling anti-pattern of discarding all available info and just returning failure?
From time to time (unfortunately way too often) I have to fix code such as this:

```<code>// C++ code
bool anyOldFunction(Param p) {
  try {
  ...
  if(some_condition_here) {
    handleErrorX();
    return false;
  } else if(other_condition) {
    return false; // (*stackexchange question comment*) Apparently no additional error action taken here
  }
  ...
  return true;
  } catch(...) {
    // (*old comment*) Catch all possible error (FroobleFub and BrabbleBub can happen)
    return false;
  }
}
</code>```

So, the original implementer actually had some inkling what exceptions could be thrown (although the list may not be exhaustive) but had no idea how to do some decent handling and just discarded any info he might have gotten out of the exception objects, leaving the calling code / the calling context non-the-wiser.

Is there a name for this anti-pattern? (If anti-pattern it is indeed.)

答:
"Exception Swallowing" (a discussion of it on Phil Haack's blog: https://web.archive.org/web/20110906115349/http://haacked.com/archive/2005/08/10/9293.aspx)

or

"Error Hiding": http://en.wikipedia.org/wiki/Error_hiding

While you are coding in C++ and I'm not sure about its mechanisms when handling exceptions, the main problem with exception swallowing in .NET managed code, is that if it is rethrown or a new exception is created without the original included, the stack trace to the original cause of the failure is not included, which makes debugging slightly harder, as you have discussed in your question.

ContentLicense: CC BY-SA 4.0


答:
The concept of pointers is important in the general computer programming body of knowledge.
Understanding the concept is good for to-be-programmers or programmers of any language, even if the language does not directly support it.

Pointers have their usage in Data Structures (linked lists) and Database design (Foreign Key).

Languages like VB and C# can pass data by "reference" to methods, which can be thought of as a type of pointer.

Understanding where data is allocated in memory (stack vs. heap) is still important for efficiency of algorithms.

Learning the basics right is important in my opinion.

Title: Do the young minds need to learn the pointer concepts?

Body:
Why did the C master Dennis Ritchie introduce pointers in C? And why did the other programming languages like VB.NET or Java or C# eliminate them? I have found some points in Google, and I want to listen your comments too. Why are they eliminating pointer concepts in modern languages?

People say C is the basic language and pointers is the concept that makes C powerful and outstanding and makes C still to compete with more modern languages. Then why did they eliminate pointers in more modern languages?

Do you think knowledge of pointers is still important for new programmers? People are using VB.NET or Java these days, which supports more highly advanced features than C (and does not use any pointer concepts) and many people as I see now (my friends) choose these languages ignoring C as they support advanced features. I tell them to start with C. They say it's a waste to learn the concepts of pointers when you're doing the advanced things in VB.NET or Java which are not possible in C.

What do you think?

Updated:

The comments I read on Google are:

The earlier computers were too slow and not optimized.

Using pointers makes it possible to access an address directly and this saves time instead of making a copy of it in function calls.

Security is significantly worse using pointers, and that's why Java and C# did not include them.

These and some more what I found. I still need some valuable answers. That would be greatly appreciated.


答:
I think it boils down to the fact that the need to deal with pointers fell away as programmers dealt less with the direct hardware they were running on. For example, allocating a linked list data structure in a way that fit perfectly onto the sequence of 640 byte memory modules that the specialised hardware had.

Dealing with pointers manually can be error-prone (leading to memory leaks and exploitable code) and is time consuming to get right.  So Java and C# etc all now manage your memory and your pointers for you via their Virtual Machines (VMs).  This is arguably less efficient than using raw C/C++, although the VMs are constantly improving.

C (and C++) are still widely used languages, especially in the High Performance Computing, Gaming and embedded hardware spaces.  I'm personally thankful I learned about pointers as the transition to Java's references (a similar concept to pointers) was very easy and I wasn't lost when I saw my first NullPointerException (which should really be called a NullReferenceException, but I digress).

I would advise learning about the concept of pointers as they still underpin a lot of data structures etc.  Then go on to chose a language that you love to work in, knowing that if something like a NPE comes up, you know what's really going on.


答:
Yes, yes, yes, yes and yes!!!

If you don't know the basics you will NEVER be able to solve the really hard, strange, difficult and complicated problems that come your way.

And if you do understand the basics really well, you are MUCH more marketable in the job market.

I worked once with a chap who had been programming for 10 years, and had no idea how pointers worked. I (much more junior) spent hours at a whiteboard educating him. That opened my eyes. He had NO IDEA about so many basic things.

Know as much as you possibly can.


答:
Why? You can write a huge system with forms designer and code generator. Isn't it sufficient? (irony)

And now seriously, pointers are not crucial part of programming in many areas, but they allow people to understand how the internals work. And if we will have no-one who understands how internals work, there will be a situation where SQL2020, Windows 15 and Linux 20.04 will be written in garbage collected virtual machine running over 30 layers of abstraction, with code generated via IDE, in JavaScript.

This is definitely not what I want to see.

So yes, they do have to, definitely!


答: Answering your question, from my own experience ( I am fairly new in industry so not much of it) I get to learn new languages by doing some research to see which language best fits my needs. In college, I had a projet in cryptography which required use of large Integers. It was becoming quite combersome in C++ so I turned to Java as it provided BigInteger class. In my current job, I could see that shell scripting was not able to completely solve my problem without becoming too complex so I learnt Perl. Learn on the fly is my advice as one;s requirement. Ofcourse if you find yourself bored, there is a whole world of languages to be explored.</p>


答:
For most practical purposes in high level OO languages understanding references is enough, you don't really need to understand how how these languages implement references in terms of pointers.

There are a lot more functional and modern multi-paradigm approaches I'd value much higher than being able to do fancy pointer arithmetic to say, write the 1000th optimized string copy function probably performing worse than String.copy of your std lib any way.

I'd advise to learn a lot more different, higher level concepts first, and branch out to learn languages of different designs to broaden your horizon before attempting to specialize in close-to-hardware stuff.

I often see totally failed attempts to micro-optimize web servlet or similiar code for 5% gain, when caching (memoization), SQL-optimizing, or just webserver config tuning can yield 100% or more with little effort. Fiddling with pointers is premature optimization in most cases.


问:
centralized hosted application framework or "private copies" for each program?
We have a centralised business application framework, and it contains all our business logic and provides access to all our back-end systems. It is accessed by a number of different programs and clients through remoting.

When we need to do a change in a certain part of the program, we currently have to retest all our different programs and clients. Even assuming we extend our automated testing, we feel that there is no way we can be certain that upon releasing a new version of our application framework all the different programs will work correctly after that change without also manually retesting all these programs.
Every time we release a new version of project C, we have to test program A and B as well for unintended changes.

Preferably, we would move to a release system where upon releasing project C, we only have to retest program C, and not A and B for possible breaking changes that we overlooked.

The idea lives to duplicate our centralised business application framework, one for each sub-project. It would mean for that when we release a new version of program C, we will provide a private version of the application framework. Upon release of program C, nothing will have changed for application A and B, they still communicate with their private application framework - so they do not need to be retested.

I came up with the following pro's and con's:

Con's:

We'll have our framework hosted n times for each project

We'll get confused in what version / project what bug is solved.

With a major fix / change, we will have to re-release all n versions of the application framework.

Pro's:

Significantly cuts down on testing

"Certainty" that no unintended changes are released for different projects.

I must admit I am not a fan of the private copies-approach, but I fail to provide a better alternative, or better arguments against this.

Has anyone been in a similar situation, and how was it handled? Is the above approach of "private frameworks copies" a solid / accepted approach? Any advice is welcomed.

Thanks in advance.

答:
Your framework, like any library code, should be a separate, versioned, project. And each app should be dependent upon a specific version of the framework.

Whenever you make changes to the framework, its version should change, and the new version should be made available in addition to the old version(s) still being available for the other apps.

You can then switch over each app as desired or needed to a new(er) version of your framework. And you can "decommission" a version when not a single app still has it as a dependency.

Yes, there will be duplication, but with a correct folder structure and some configuration in the apps the duplication can be limited to the deployed/deployable files. All other dupplication should be in your version control system (which I do hope you use...).

Just look at your framework as another framework like .Net. My hosting provider happily makes version 2.0, 3.5, 4.0 ... available and which one is used for my site is defined by a configuration setting which can be different from the configuration settings of any other sites hosted by the same server.

With regard to your con's:

I don't see multiple hosted versions as a problem. If anything it makes dependencies a lot more explicit and allows you to develop the framework with confidence.

Whether or not you get confused in what version/project a bug is fixed depends entirely on your bug tracking system. Plus the framework should be its own project. I didn't mention this above because to me it is so obvious that I didn't anticipate anybody having/changing it as part of another project.

Yep if a fix is important enough to be applied to older versions, you will indeed have to fix all previous (and following) releases. But that is a good thing. It will make you think twice about whether something is worhty of being "hot-fixed" (requiring changing all currently maintained releases) or just something that the other apps can get when they switch to a newer version of your framework.


问:
Agile methodology for a single developer working on a prototype

Possible Duplicate:

  Agile for the Solo Developer

For my thesis I will be working on a user interface prototype during a 6 month period. I am required to pick a strategy and create a precise planning. While reading through different descriptions of agile methodologies I felt like I'm in buzz-word heaven. Instead of just picking one because it's famous, I was hoping someone could give some insight into which one/or which parts of it might be useful.

Are there any agile methodologies specifically suitable (or scalable) for single developers?

答:
There is a similar question on StackOverflow. See https://stackoverflow.com/questions/829497/agile-methods-specifically-taylored-to-working-solo.

One of the answers provides a link to the Pomodoro technique, and there is an interesting presentation here.


答:
I think you need to differ.

Java and other higher level languages did not remove pointers. What they did was to remove plain pointer arithmetic.

In fact, Java still allows a protected and restricted pointer arithmetic: the array access. In plain old C, array access is nothing but dereferencing. It is a different notation, a syntactic sugar, if you will, to clearly communicate, what you're doing.

Still, array[index] is equivalent to *(array+index). Because of that it is also equivalent to index[array] although I suppose some C compilers might give you a warning, if you do that.

As a corollary, pointer[0] is equivalent to *pointer. That's simply because the "pointer to an array" is the address of the first entry of the array and the addresses of the subsequent elements are computed by adding the index.

In Java, plain pointer arithmetics (referencing and dereferencing) don't exist anymore. However pointers exist. They call them references, but it doesn't change what it is. And array access still is exactly the same thing: Look at the address, add the index and use that memory location. However in Java, it will check whether or not that index is within the bounds of the array you originally allocated. If not, it will throw an exception.

Now the advantage of the Java approach is, that you don't have code, that just blindly writes arbitrary bytes into arbitrary memory locations. This improves safety and also security, because if you fail to check buffer overflows and such, the runtime will do it for you.

The disadvantage of this is, that it's simply less powerful. It is possible to do memory safe programming in C. It is impossible to benefit from the speed and the possibilities of unsafe programming in Java.

Actually, there is nothing hard about pointers or pointer arithmetic. They are just normally explained in convoluted ways, whereas all a pointer is, is an index to one giant array (your memory space), all referencing a value does is giving you the index where to find it, all what dereferencing does is to lookup the value at a given index. (This is just a bit simplified, because it doesn't take into account that values are of different size in memory, depending on their type. But that's a circumstantial detail, rather than a part of the actual concept)

IMHO, everybody in our job should be able to understand that, or they are simply in the wrong field.


问:
Can you change code distributed under the MIT license, and re-distribute it under the GPL license?
Is it possible to alter the code of the Chili plugin, which had its latest release on July 2008, and it is licensed under the MIT license, to then license it under GPL?

As far I can see, there is no restriction about the new code being licensed under the same license. Is it really so, or is there a minimum number of changes?

In my case, I would change the jQuery plugin in normal Javascript code that is executed in a CMS.
This essentially means that, among other things:

The code will not use the "ChiliBook" namespace.

The function will not be invoked as $($element).chili(), but as GlobalObject.ChiliHighlighter.process($jquery_element), where "GlobalObject" is a JavaScript object used from the CMS.

The code will allow other modules to alter the GlobalObject.ChiliHighlighter object to add functions that are optionally called from GlobalObject.ChiliHighlighter.process() when they are defined.

As alternative, as the repository I am using allows me to include code not licensed under GPL 2 or higher license when the code is not maintained anymore, could the plugin be considered not maintained anymore, as its last version was released three years ago?

答:
It's technically legal.

The MIT (Expat) license places a few restrictions on you. These are a subset of the GPL license. Therefore, if you relicense the code under the GPL, and keep the MIT notice, then you've satisfied the terms of the MIT license and may legally redistribute the code.

Note that you may not claim copyright ownership; you'll have to acknowledge the original copyright.

[edit]
Some people don't seem to understand how F/OSS works in conjunction with copyright and license law. Everything starts with copyright, if only because that's the default. Under the copyright doctrine, the author gets the right to make copies of source code. Under the MIT license, that right is granted to me, as well as the right to recursively grant it to others. Note that the MIT license explicitly includes the right to sublicense. Quoting: "the rights to use, copy, modify, merge, publish,distribute, sublicense, and/or sell"

When I sublicense code, I cannot grant rights that I didn't originally have. In the case of the GPL, I am explicitly forbidden to sublicense only some rights. But neither in law nor in the MIT license do I have an obligation to sublicense all rights as a whole.

Therefore, the MIT license grants me the explicit right to sublicense rights, and neither the law nor the MIT license prohibits me to sublicense only some rights. Also, neither restricts the form in which I do. Therefore, I have the undeniable right to grant a GPL sublicense on that code.


答:
Yes, understanding is important.

A few months back I was programming in C#, and I wanted to make a copy of a list. Of course what I did was NewList = OldList; and then started to modify NewList. When I tried to print out both lists, they were both the same, since NewList was just a pointer to OldList and not a copy, so I was actually changing OldList all along. It didn't take me too long to figure that one out, but some of my classmates weren't that quick and had to be explained why this is happening.

Example:

```<code>List<int> a = new List<int>();
a.Add(2);
a.Add(9);
a.Add(8);
a.Add(1);
List<int> b = new List<int>();
b = a; //Does not make a copy, b is just a synonym!
b.Sort();
for (int i = 0; i < a.Count; i++)
{
    Console.WriteLine("a: " + a[i] + " b: " + b[i]);
}
</code>```

And of course, the result is like this:

```<code>a: 1 b: 1
a: 2 b: 2
a: 8 b: 8
a: 9 b: 9
</code>```

Knowing how to use them isn't that important, yet understanding them is crucial!

Body:
Yes, understanding is important.

A few months back I was programming in C#, and I wanted to make a copy of a list. Of course what I did was NewList = OldList; and then started to modify NewList. When I tried to print out both lists, they were both the same, since NewList was just a pointer to OldList and not a copy, so I was actually changing OldList all along. It didn't take me too long to figure that one out, but some of my classmates weren't that quick and had to be explained why this is happening.

Example:

List<int> a = new List<int>();
a.Add(2);
a.Add(9);
a.Add(8);
a.Add(1);
List<int> b = new List<int>();
b = a; //Does not make a copy, b is just a synonym!
b.Sort();
for (int i = 0; i < a.Count; i++)
{
    Console.WriteLine("a: " + a[i] + " b: " + b[i]);
}

And of course, the result is like this:

a: 1 b: 1
a: 2 b: 2
a: 8 b: 8
a: 9 b: 9

Knowing how to use them isn't that important, yet understanding them is crucial!


问:
What writing rules are different for humans and code?
It seems that some rules of writing code are in direct contradiction with the rules of human writing.  For example in code it's advisable to define each piece of information in only one place and in writing for humans it's normal to repeat important points (though usually phrased differently).

What rules of writing good code contradict the rules of good writing?

答:
Good poetry in writing lets the reader appreciate music of sounds that resonate together.

Good poetry in code (I wouldn't be surprised if someone came with an example from IOCCC) lets the reader only appreciate the performance (and the compiler wouldn't notice at all).


问:
Who owns this work?
I worked for a small company as a long term contractor making websites and other such things.  A client comes along, pays what he said was "A lot of money" for me to spend a week doing his website.  He paid it to the company.

I didn't see any of his money, I've since left that job because they owe me months of back pay and it looks like I'm not going to end up getting much of it. (Bad situation)

I want to consider the possibility now of exploring who owns any work I did that was unpaid, because if I need to, I can use it as leverage to help get my owed money.  The company is still using some work in-house that's unpaid which I'm a lot clearer about contesting rights to.

What's I'm struggling with is working out what to do about the clients website.  From his POV he paid for it, it's his.  From my POV I did it and didn't get paid for it so it's mine.  Who owns it?  If I do, I wouldn't want to strip it away from him, it seems really unfair, but I would like to use it as leverage if it comes to that.

答:
The usual answer for something like this is to seek out the guidance of a lawyer.

What was the terms of the contract? That is the be all end all.

Title: Who owns this work?


答: The terms of the contract, if there is a written contract, will usually spell out ownership issues. However, in the case where work has been done without payment, you should have good leverage with or without a contract. Just the same, the outstanding amount might not be worth chasing. Attorney's fees can quickly eat up what you would gain. Try negotiating further before seeking expensive advice. </p>

Title: Who owns this work?

Body:
I worked for a small company as a long term contractor making websites and other such things.  A client comes along, pays what he said was "A lot of money" for me to spend a week doing his website.  He paid it to the company.

I didn't see any of his money, I've since left that job because they owe me months of back pay and it looks like I'm not going to end up getting much of it. (Bad situation)

I want to consider the possibility now of exploring who owns any work I did that was unpaid, because if I need to, I can use it as leverage to help get my owed money.  The company is still using some work in-house that's unpaid which I'm a lot clearer about contesting rights to.

What's I'm struggling with is working out what to do about the clients website.  From his POV he paid for it, it's his.  From my POV I did it and didn't get paid for it so it's mine.  Who owns it?  If I do, I wouldn't want to strip it away from him, it seems really unfair, but I would like to use it as leverage if it comes to that.


答:
Pointer the concept != Pointer the arithmetic != Pointer the syntax

The first matters always, if you need (and you do) understanding of deep/shallow copy, pass by reference/pass by value, etc. The other two matter only if your language du jour allows you to use them.


答:
It's likely that since you're the person that actually did the work, you likely have copyright for that work, since you didn't explicitly relinquish copyright.

You could try talking to a lawyer, and pursuing legal action against both the former employer and the client that received the work. If the client is suddenly faced with legal action, you can be very certain that they will also pursue legal action against your former employer. The possibility of 2 lawsuits will probably be enough to motivate them to resolve the issue.

By legal action against the client, I mean an injunction to take down the website for copyright violation while the situation is under dispute between you and the former employer. You can be certain they'll respond to something along those lines, and it won't be you that they'll have words with.

Title: Who owns this work?


答:
The professional programmer should master pointers.

The people who want to know programming should learn about its existance and implications, but not necessarily use them.

The people who want to solve personal problems via programming (like me, who use a lot of Python scripts) could very well ignore them at all.

Well, that is my opinion... ;o)


答:
If your contract says that you get x% of the customer payment for each project (which I doubt it), then you may have a point. But if you are paid for your time or if you are a full time employee, I guess you are out of luck.

Remember that the company carries other expenses than your salary. Marketing, admins, utilities, rent, etc. so what the customer pays is logically split to cover all these aspects.

Title: Who owns this work?


答: Variable address pointers are a specific case of the more generalized concept of indirection.  Indirection is used in most (all?) modern languages in many constructs such as delegates and callbacks.  Understanding the concept of indirection enables you to know when and how to best use these tools.</p>


答:
Neither Java nor C# eliminated pointers, they have references which are almost the same. What was eliminated is pointer arithmetics, which can be omitted in an introductory course.

No non-trivial application could be done without the concept of pointers or references, so it is worth teaching (No dynamic memory allocation could be done without them).

Consider the following in C++ and Java, and I guess it's not very different in C#:

aClass *x = new aClass();

aClass x = new aClass();

There's not really too much difference between pointers and references, right?

Pointer arithmetics should be avoided unless necessary and when programming with high level models, so there's not much problem there.


答: Ideally, both.  You shouldn't not have the DB handle it, but then again, if the app comes up with data that the DB will reject, that's a runtime error, so the app should have at least some code dedicated to preserving referential integrity.  Also, setting up the right constraints in SQL in the DB is much simpler than setting up code for it client-side, so doing it on the DB greatly reduces the amount of work you need to do.


问:
Best Practices for Corporate Sponsorship of Open Source Project
We are preparing to OpenSource our ASP.NET MVC multi-tenancy CMS.  We currently use BitBucket.org to host our source repository and we are considering best approaches to repository naming.

In terms of the user/host of the repository, We are debating using our company name which is the sponsor of the project versus the project name itself.

The company name is JoyaTech Solutions, the project name is JoyaCMS.

Do people think that having a company name as the user/owner of an open source project is a turn off or is there value in displaying that relationship?

答:
There are a number of open source projects which are maintained by corporate entities. If it's truly going to be open source and you expect to accept outside contributions, I don't think anyone really cares. Having corporate ownership also could make a link for support easier for people to grasp. </p>

<p>If you are going to do this, I would move to Github over using BitBucket. Github provides powerful tools to allow outsides easily contribute minor changes. </p>

Body:
There are a number of open source projects which are maintained by corporate entities. If it's truly going to be open source and you expect to accept outside contributions, I don't think anyone really cares. Having corporate ownership also could make a link for support easier for people to grasp.

If you are going to do this, I would move to Github over using BitBucket. Github provides powerful tools to allow outsides easily contribute minor changes.


问:
What's the purpose of 'so that' clause in user story definition?
A user story can be defined in a sentence like:

```<code>As a <type of user> I want <some goal> so that <some reason>
</code>```

Just Google for 'user story formula' and first links all propose this formula.

My question is, what is the purpose of so that clause? Is it there for managers? Is it there so that project managers and stakeholders can understand the priority of the item better? Why is it there?

Note: I've worked with as a <type of user> I want <some goal> formula, and it works just well. I haven't noticed any problem in my work by implementing this format which is more brief.

答:
The "so that" provides a reason for the goal.

For example, the goal might be to display last month's sales figures. You could work with that, but one reason you need to know why you want to display them so that you can get at the deeper requirements. What do they want to do with the sales figures or prospects? Knowing this information will give you more insight into the application and more chance of designing a user interface that enables the customer to do what they want.

Another use for the reason is to prioritise stories. If you have two stories:

I want to display last month's sales figures.

  I want to display a list of prospects.

but only have the resources to do one - which one do you do? Without the reason you'd just be guessing and you might not deliver the right one in time. Though this is less important as the customer should be telling you which to do first, but occasionally that isn't the case.


答:
Depending on how much money you are owed, it may not be worth getting a lawyer involved.

In the UK, if the total owed is less than £5,000 you might want to consider a small claims track case. Your first port of call should probably be the Citizens Advice Bureau, as they can give you free impartial advice.

I have used the UK governments Money Claim Online to quickly, cheaply and successfully take to court a taxi driver who knocked me off my bike and refused to acknowledge his culpability to his insurance company. I would have absolutely no hesitation using the service again.

Incidentally, IIUIC under UK law, a verbal contract is just as binding as a written or e-mailed contract. If you agreed to do some work for a given price you are bound by that agreement, as are they.

Title: Who owns this work?