问:
Can I apply for "Software Engineer" jobs without being an engineer?
I am from a country in which the use of the word "Engineer" or "Engineering" is strictly regulated by legislation. This means that you must hold a degree in Engineering AND passed an exam to join the Engineers' professional association to use the title. I am a bit confused about the term "Software Engineer" as used in the industry, globally.

I read the wikipedia page on Software Engineer and the linked section of the page about the term usage, which offer an in-depth discussion. However my question is somehow more concrete.

Knowing that I don't hold a degree in engineering (yet, I like to think I produce funcional, well designed software!), when I see an opening for a software engineer from an international company, would it be appropriate for me to apply? Should I somehow emphasise that I don't hold a degree in engineering?

答:
You are not going to waste anyone's time. Go for it. And you don't even need to emphasize that you don't hold a degree in engineering.  Your CV (Resume) will obviously state what degrees you hold, and by inference what you do not hold. Only avoid companies that specifically state that they are only looking for accredited etc etc.

EDIT: The reason for this is that computer software development has been, still is, and will continue for a while to be an explosively growing, industry-led field, where 99% of "what the job is all about" is learned at the workplace, not at the University. The University is good for learning to specialize on a specific subject by means of a Master's or higher degree, and when a company is looking for a specialist they usually state this requirement. This comes from someone who holds a "Bachelor's Degree in Computer Science" and who nevertheless learned that what he is doing is in fact a science outside of the University. (Initially in highschool, when I learned what binary search is, and later at work, when I learned what OOP was. At the University they had not heard of OOP yet.)


问:
What is important when optimising for the CPU cache (in C)?
Reading these two questions, I see that understanding CPU caching behaviour can be important when dealing with large amounts of data in memory. I would like to understand the way the caching works to add another tool to my optimisation toolbox.

What are the core points about the way the CPU cache works so I can write code that uses it sensibly? Relatedly, is there a way to profile code to see if poor cache use is slowing things down?

答:
The intricacy of this issue has been beyond human comprehension these days. (It has been that way since the last 5 years.) Combine that with short-vector parallelism (SIMD) and you have a sense of hopeless that optimizing code by hand is no longer economically feasible - not that it's not possible, but it would not be cost-effective anymore.

The current approach is to rely on teaching computers how to optimize - by making variations of code that compute the same answers with different structures (loops, data structure, algorithms) and automatically evaluating the performance. The rules for code transformations are specified with a very rigorous mathematical model, so that it is something both computer scientists can understand and computers can execute.

The following is a link posted by Larry OBrien in one of his answers.

http://onward-conference.org/2011/images/Pueschel_2011_AutomaticPerformanceProgramming_Onward11.pdf

ContentLicense: CC BY-SA 3.0


问:
How to organize programming exercise
Due to my bad performance on past job interviews, I decided to perform daily programming exercises out of my work.

Currently, I am concentrating on algorithms, design patterns, and unit testing in C++ language platform. But I'd like to have balance over more important areas. So if I may, I'd like to know how other programmers organize their programming exercises.

答:
I was there. I was also rejected at lots of interviews, and was guessing whats going wrong. For me one important thing going wrong was I was never good in C++, and I was saying that, yes I am good in C++. And falling on my face in interviews.

Then I came across this Modern C++ design, and I instantly know that I actually dont know anything in C++. I was thinking I know, but it opens a whole new universe.
In your case, it may also be  this basic part of programming of data structure and algorithms. But you never know.

Here are few programming sites which can help you. Choose suitable.

tocoder.com

codechef.com - [Comes with answer]

spoj.pl

These sites also help me, specifically to know that what I am missing in programming, and how to increase efficiency. For these you need to write the programs which completes some tasks on large inputs in less time. I have personally learn a lot by solving their assignments.

All the best!

Title: How to organize programming exercise


答: Normally in the job advertisements it is mentioned whether a degree is required or not. Decide whether to apply or not, depending on this. If it is not mentioned, then there are chances that the job requires more of an experience or attitude than degree. In that case, in my opinion you can apply and take your chances. Anyways when the recruiters see that you do not have any degree in your resume, they will decide whether to select you.  </p>

Title: Can I apply for "Software Engineer" jobs without being an engineer?

Body:
I am from a country in which the use of the word "Engineer" or "Engineering" is strictly regulated by legislation. This means that you must hold a degree in Engineering AND passed an exam to join the Engineers' professional association to use the title. I am a bit confused about the term "Software Engineer" as used in the industry, globally.

I read the wikipedia page on Software Engineer and the linked section of the page about the term usage, which offer an in-depth discussion. However my question is somehow more concrete.

Knowing that I don't hold a degree in engineering (yet, I like to think I produce funcional, well designed software!), when I see an opening for a software engineer from an international company, would it be appropriate for me to apply? Should I somehow emphasise that I don't hold a degree in engineering?


答:
Keep your data small if possible

Keep things that will be accessed together (or right after another) next to each other in memory

Learn about your compiler's optimization parameters

Read What every programmer should know about memory for more details than you could ever want

Title: What is important when optimising for the CPU cache (in C)?

Body:
Reading these two questions, I see that understanding CPU caching behaviour can be important when dealing with large amounts of data in memory. I would like to understand the way the caching works to add another tool to my optimisation toolbox.

What are the core points about the way the CPU cache works so I can write code that uses it sensibly? Relatedly, is there a way to profile code to see if poor cache use is slowing things down?


问:
Which languages use "paired" header/implementation files?
C is ubiquitous, and C++ nearly as much, but I'm curious which other languages follow a similar model of header files.  Specifically, in which other languages is it idiomatic to edit pairs or groups of "header" and "implementation" files?  (A group as in multiple headers with one corresponding implementation file or a single header with multiple implementation files, as also seen in C.)  For example, the pair "blah.h" and "blah.c".

C's header files are tied into the C preprocessor, but that's not the detail I'm focusing on here.  For example, PHP has various include mechanisms, but you don't have a pair/group of "blah-header.php" plus "blah-notheader.php".

Some languages generate a file from source in a one-to-one mapping, such as Java, but that's not what I'm talking about either.  I'm interested in cases where the programmer directly edits both/all files in the pair/group.

Perhaps to put it another way: which languages have a declaration file ("header") and definition file ("implementation") such that a person would generally edit both files in tandem?

答: Erlang has header files that are often used (among other things) to declare data structures used in a module. They are not necessary, though, and many, if not most, modules don't use them.</p>

OwnerDisplayName: Roger Pate

LastEditorDisplayName: Roger Pate

ContentLicense: CC BY-SA 2.5


问:
Why isn't rich code formatting more common?
I was reading Code Complete and in the chapter on layout and style, he was predicting that code editors would use some sort of rich text formatting. That means, instead of code looking like this

```<code>Procedure ResolveCollisions
{ Performs a posteriori collision resolution through spatial partitioning algoritm }
(
  CurrentMap : SpriteContext,
  PotentialColliders: SpriteList
)
var Collider  : Sprite,
    Collidee  : Sprite,
    Collision : SpriteCollision
begin
  DoStuff();
end.
</code>```

it could look something like this:

Procedure ResolveCollisions

Performs a posteriori collision resolution through spatial partitioning algorithm

Parameters

CurrentMap : SpriteContext

PotentialColliders : SpriteList

Local Variables

Collider  : Sprite

Collidee  : Sprite

Collision : SpriteCollision

```<code>    DoStuff();
</code>```

I've seen syntax coloring and highlighting and even parentheses coloring, but nothing that looked like this in actual code. I was wondering if this sort of thing actually ever existed, or perhaps if it was decided that it didn't have enough benefit or that it was an entirely bad idea.

Have any of you seen richly-formatted code like this before, or know if the idea was ever considered and eventually rejected?

答:
In addition to the other answers, I'd like to point out that besides the technical difficulties of using rich formatting, it is also object of personal preference.

If you edit plain text, you can choose the fonts and colors you like, and they are set automatically. If you'd edit rich text, what if you just don't like particular colors and fonts which are set manually?


答:
Both nwong's and Michael Borgwardt's answers give good advice.

Also, trust first the compiler's optimizations on these issues.

If using a recent GCC compiler, you might use (with parsimony) its __builtin_prefetch function. See this answer on stackoverflow.


问:
What is a value object in domain-driven design?
I have an entity and I've realised that there is a group of properties that work together. So, I moved them to a value object (together with their behavior) and now I have a reference from my entity to this value object.

I've read "Domain Driven Design Quickly" (PDF) and I came across the following statement when explaining Value objects:

If Customer is an entity object, then one instance of this  object, representing a specific bank client, cannot be reused for  account operations corresponding to other clients. The outcome  is that such an instance has to be created for every client. This  can result in system performance degradation when dealing with thousands of instances.

But I'm still not clear exactly what this means. Is my new object a value object or should it be an entity? I am having trouble reasoning whether it should in fact be an entity. In other words, what questions should I ask in my domain to assure me that it should be a value object?

答:
To expand on the answer by ques, a value object does not have a surrogate identity such as a customer number, but the object itself is its own natural identity.

Take an address for example. All addresses are unique, and the various components of an address (number, street name etc) make up the addresses identity. When you move house, you don't pick up your address, change the number on the door and take it with you, you get a new address. As such value objects don't change - they are immutable. However you could have 2 or more customers living at the same address, in which case the address value is reusable - it is not tied to a single customer entity.


问:
Shipping test code as a form of sanity check
Have you ever shipped test code (JUnit, NUnit etc) with your application that could be runnable by the end-user ?

Basic Idea is this :

The application can be deployed in a varied environment and it is hard to gather all the possible hardware - software combination or pre-requisites for the application.  It is however possible to write a test suite that assert that the application has all that it needs to perform the task at hand.  Unfortunately this must be done by mocking a few components so that the test does not affect the real production environment.

There are clear benefits to shipping these tests such as :

give the customer a means to verify the system is in order.

provide reports to help support diagnose issues.

provide means for implementation team to assert their setup should work

etc

Natural way to do this would be to have a subset of tests that are actually packaged with the application (either as a separate project or as a part of each components of the whole).  Even more natural would be to use the tools and techniques we already use for our own unit tests namely Unit test library, mocking framework etc.

Have you ever done this ?  How have you done it ? or why do you think this is a very bad idea ?

答:
Why would the end-user do this?

To me this is part of the deployment pipe line (where it might be a very good idea).  If anything, then you would run this either silently on a regular basis, or have the end-user do it on your request.


问:
How can I efficiently handle input data without a framework?
I am working on a very small project and my design would be using technologies such as JSP, servlets, and POJOs.

I'm considering a workflow where a JSP page will receive input data, then submit it to a servlet. The servlet would then have a lot of helper POJOs in it that would do all the real work.

One thing I've noticed with this approach very early on is that it grew into a huge number of if-then-else statements.

Is there a better way to accomplish what I'm trying to do without having to resort to a framework?

答:
JSP pages are served by a servlet, so your sentence "a JSP page will receive input data, then submit it to a servlet" sounds to me like a strange approach (perhaps I didn't understand it well).  Normally, you first see your data in the "servlet", then render a document (i.e. JSP) that is sent to client browser.

If you don't want to use a web framework, you'll end up writing lots of common stuff yourself (parsing parameters, converting them from strings to the needed types, validating them, make the results available to your JSP...), and yes, that needs a lot of if/then/else.

In very general terms, what you want to do is to use a single servlet that services your requests:

```<code> public void doGet(HttpServletRequest req, HttpServletResponse res)
                               throws ServletException, IOException {

    // Parse the request and select an aproppriate POJO that services this action
    // Your service POJOS should have a common interface (i.e. validate(),
    // service()...)

    // Call a binding method that reads parameters from GET/POST and maps them
    // to properties of your POJO

    // Call the POJO "validate()" so you know that input is ok

    // Call the POJO "service()" so it runs the appropriate process:
    // This should return all needed data and the name of the "JSP" you will use

    // Generate and send JSP to client

  }
</code>```

But actually, you need much more flexibility: you need to be able to use redirects from your action, you'll need to handle exceptions in a reasonable way, you'd need to consider content encoding... in short, I strongly suggest you to reconsider using a framework (Struts 2, Spring MVC, Tapestry.... there are so many), or alternatively post the code that services one of your requests so people can suggest improvements.

I hope it helps.

Body:
JSP pages are served by a servlet, so your sentence "a JSP page will receive input data, then submit it to a servlet" sounds to me like a strange approach (perhaps I didn't understand it well).  Normally, you first see your data in the "servlet", then render a document (i.e. JSP) that is sent to client browser.

If you don't want to use a web framework, you'll end up writing lots of common stuff yourself (parsing parameters, converting them from strings to the needed types, validating them, make the results available to your JSP...), and yes, that needs a lot of if/then/else.

In very general terms, what you want to do is to use a single servlet that services your requests:

 public void doGet(HttpServletRequest req, HttpServletResponse res)
                               throws ServletException, IOException {

    // Parse the request and select an aproppriate POJO that services this action
    // Your service POJOS should have a common interface (i.e. validate(),
    // service()...)

    // Call a binding method that reads parameters from GET/POST and maps them
    // to properties of your POJO

    // Call the POJO "validate()" so you know that input is ok

    // Call the POJO "service()" so it runs the appropriate process:
    // This should return all needed data and the name of the "JSP" you will use

    // Generate and send JSP to client

  }

But actually, you need much more flexibility: you need to be able to use redirects from your action, you'll need to handle exceptions in a reasonable way, you'd need to consider content encoding... in short, I strongly suggest you to reconsider using a framework (Struts 2, Spring MVC, Tapestry.... there are so many), or alternatively post the code that services one of your requests so people can suggest improvements.

I hope it helps.


答:
We used to call this smoke test. However, unit tests aren't suitable for this purpose, as they execute small pieces of code in isolation (how big is the chance that your tax calculation method suddenly stops working?) Rather, you need integration tests (also called system tests) to execute the system as a whole, and ensure that it is assembled and configured properly.

The smoke test suite may be a simple, small subset of your full integration / functional test suite, only to verify that the system as a whole can start up and can execute some of its most basic functionalities correctly. Preferably it should be

safe to run on the real, live system (i.e. make no changes to persistent data),

trivial to execute (with a single command, or push of a button),

fast, and

its output concise and unambiguous, like that of the unit tests (e.g. either "Success", or "Tests Foo and Bar failed with the following errors: ...").

And I agree with Thorbjörn in that this should rather be executed - or at least initiated - by the deployer / installer, or the support personnel in case of later system problems.

We have used, and are using such tests on several projects, although these all being server side developments, the end users executing smoke tests was usually not even an option. On the client side, of course, the picture is different. There you may consider making the smoke tests the final step of the installation process, and/or documenting its usage for troubleshooting purposes. Alternatively, if they are fast enough, they may even be run automatically at startup time, always.

Title: Shipping test code as a form of sanity check

Body:
Have you ever shipped test code (JUnit, NUnit etc) with your application that could be runnable by the end-user ?

Basic Idea is this :

The application can be deployed in a varied environment and it is hard to gather all the possible hardware - software combination or pre-requisites for the application.  It is however possible to write a test suite that assert that the application has all that it needs to perform the task at hand.  Unfortunately this must be done by mocking a few components so that the test does not affect the real production environment.

There are clear benefits to shipping these tests such as :

give the customer a means to verify the system is in order.

provide reports to help support diagnose issues.

provide means for implementation team to assert their setup should work

etc

Natural way to do this would be to have a subset of tests that are actually packaged with the application (either as a separate project or as a part of each components of the whole).  Even more natural would be to use the tools and techniques we already use for our own unit tests namely Unit test library, mocking framework etc.

Have you ever done this ?  How have you done it ? or why do you think this is a very bad idea ?


答:
I would try to shape the application developing a DSL (domain specific language).

That would leverage the protocol logic, decupling from the actual input, and via reflection should allows execution (instance of POJO) of the required duties. The protocol grammar could be developed and tested stand alone and incrementally, with the help of a parser generator.

Of course, if you're akin to 'syntax love'.

The answer from @jjmontes is of course somewhat more practical.

Title: How can I efficiently handle input data without a framework?

Body:
I am working on a very small project and my design would be using technologies such as JSP, servlets, and POJOs.

I'm considering a workflow where a JSP page will receive input data, then submit it to a servlet. The servlet would then have a lot of helper POJOs in it that would do all the real work.

One thing I've noticed with this approach very early on is that it grew into a huge number of if-then-else statements.

Is there a better way to accomplish what I'm trying to do without having to resort to a framework?


问:
Static methods on a web context
What happens when concurrent requests call the same static Java method running on an application server?

Say that a method run takes 2 seconds and receives 100 calls in a given second. The method itself wouldn't read/write outer state.

Could it be better to let it be an instance method instead?

答: If the method does not access/change any external state, it is in fact a function. There's nothing wrong with that (some programming languages are based entirely on functions), and it will not cause any performance problems (at least not due to being static).</p>

Title: Static methods on a web context


答:
Does your method change any state (e.g.  Is it mutable)?  If not then you're probably quite safe to make it a static method.  However, it's always best to test these things out.

When you get to the testing part, try simulating your concurrent threads using JMeter.

Title: Static methods on a web context

Body:
What happens when concurrent requests call the same static Java method running on an application server?

Say that a method run takes 2 seconds and receives 100 calls in a given second. The method itself wouldn't read/write outer state.

Could it be better to let it be an instance method instead?


答:
You might also, in addition of good reading and exercises, consider contributing to some free software project. This requires both technical and social skills (for good interaction with a development community) and will learn you a big lot.

And once you did contribute to some free software project, it is probably very positive on a CV.

Title: How to organize programming exercise

Body:
Due to my bad performance on past job interviews, I decided to perform daily programming exercises out of my work.

Currently, I am concentrating on algorithms, design patterns, and unit testing in C++ language platform. But I'd like to have balance over more important areas. So if I may, I'd like to know how other programmers organize their programming exercises.


问:
What is "Problem Domain"
I have to document my program for a school project and we have section called "problem domain" but I have no idea what to discuss in this section.

So the question is: What should be discussed in the problem domain?

答:
From the Wikipedia article on problem domain:

A problem domain is the area of expertise or application that needs to be examined to solve a problem. A problem domain is simply looking at only the topics you are interested in, and excluding everything else.

It is the area where the problems your application is intended to solve, belong to.

Title: What is "Problem Domain"


问:
Separating the UI from its event handlers and database queries
Is it a good practice to separate the handlers and database queries in different classes?

There will be a separate class containing all the necessary event handlers, and there would also be another class for database queries?

答:
Absolutely yes, your code should (almost) always have a separation of concerns:

In computer science, separation of concerns (SoC) is the process of separating a computer program into distinct features that overlap in functionality as little as possible. A concern is any piece of interest or focus in a program. Typically, concerns are synonymous with features or behaviors. Progress towards SoC is traditionally achieved through modularity of programming and encapsulation (or "transparency" of operation), with the help of information hiding. Layered designs in information systems are also often based on separation of concerns (e.g., presentation layer, business logic layer, data access layer, database layer).

There are a ton of software design philosophies and patterns behind this, but the Single Responsibility Principle (SRP) is probably a good default to always use:

In object-oriented programming, the single responsibility principle states that every object should have a single responsibility, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility.

Rough translation is: "Your class/method/function should do one thing and do it well"


问:
Why are /// comment blocks important?
Someone once said we should prefix all our methods with the  ///  comment blocks (C#) but did not explain why.

I started to use them and found they annoyed me quite a bit, so stopped using them except for libraries and static methods. They're bulky and I'm always forgetting to update them.

Is there any good reason to use ///  comment blocks in your code?

I normally use // comments all the time, it's just the ///  blocks I was wondering about.

答:
"It has to be Used Very much, like me ;)"

I used to play with comments (///). For a class you can simply do a comment like this

```<code>namespace test
{
    /// <summary>
    /// Summary description for Calendar.
    /// </summary>
    public partial class DatePicker : System.Web.UI.Page
    {
</code>```

But, for a method you can add-on more with giving description for parameters and return types.

```<code>/// <summary>
/// Assign selected cases to the participating users based on the filters and configurations
/// </summary>
/// <param name="noOfParticipants">No. of participants to the Table</param>
/// <param name="value">Value of the participant</param>
/// <returns>No Of Cases Assigned on successfull completion</returns>
public long AssignCasesToParticipatingUsers(int noOfParticipants,string value)
{
</code>```

You can use a short-cut for creating this comment (///+Tab).

Title: Why are /// comment blocks important?

Body:
"It has to be Used Very much, like me ;)"

I used to play with comments (///). For a class you can simply do a comment like this

namespace test
{
    /// <summary>
    /// Summary description for Calendar.
    /// </summary>
    public partial class DatePicker : System.Web.UI.Page
    {

But, for a method you can add-on more with giving description for parameters and return types.

/// <summary>
/// Assign selected cases to the participating users based on the filters and configurations
/// </summary>
/// <param name="noOfParticipants">No. of participants to the Table</param>
/// <param name="value">Value of the participant</param>
/// <returns>No Of Cases Assigned on successfull completion</returns>
public long AssignCasesToParticipatingUsers(int noOfParticipants,string value)
{

You can use a short-cut for creating this comment (///+Tab).


问:
Is there a subset of programs that avoid the halting problem
I was just reading another explanation of the halting problem, and it got me thinking all the problems I've seen that are given as examples involve infinite sequences. But I never use infinite sequences in my programs - they take too long. All the real world applications have lower and upper bounds. Even reals aren't truly reals - they are approximations stored as 32/64 bits etc.

So the question is, is there a subset of programs that can be determined if they halt? Is it good enough for most programs. Can I build a set of language constructs that I can determine the 'haltability' of a program. I'm sure this has been studied somewhere before so any pointers would be appreciated. The language wouldn't be turing complete, but is there such a thing as nearly turing complete which is good enough?

Naturally enough such a construct would have to exclude recursion and unbounded while loops, but I can write a program without those easily enough.

Reading from standard input as an example would have to be bounded, but that's easy enough - I'll limit my input to 10,000,000 characters etc, depending on the problem domain.

tia

[Update]

After reading the comments and answers perhaps I should restate my question.

For a given program in which all inputs are bounded can you determine if the program halts. If so what are the constraints of the language and what are the limits of the input set. The maximal set of these constructs would determine a language which can be deduced to halt or not. Is there some study that's been done on this?

[Update 2]

here's the answer, it's yes, way back in 1967
from http://www.isp.uni-luebeck.de/kps07/files/papers/kirner.pdf

That the halting problem can be at least theoretically solved for ﬁnite-state
systems has been already argued by Minsky in 1967 [4]:
“...any ﬁnite-state machine, if left completely to itself, will fall eventually into a
perfectly periodic repetitive pattern. The duration of this repeating pattern cannot
exceed the number of internal states of the machine...”

(and so if you stick to finite turing machines then you can build an oracle)

答:
To (partially) answer your question "Is there a subset of programs that avoid the halting problem": yes, in fact there is. However, this subset is amazingly useless (note that the subset I'm talking about is a strict subset of the programs that halt).

The study of the complexity of problems for 'most inputs' is called generic-case complexity. You define some subset of the possible inputs, prove that this subset covers 'most inputs' and give an algorithm that solves the problem for this subset.

For instance, the halting problem is solvable in polynomial time for most inputs (in fact, in linear time, if I understand the paper correctly).

However, this result is rather useless because of three side notes: firstly, we talk about Turing machines with a single tape, rather than real-world computer programs on real-world computers. As far as I know, no one knows whether the same holds for real-world computers (even though real world computers may be able to compute the same functions as Turing machines, the number of allowed programs, their lengths and whether they halt may be completely different).

Secondly, you have to watch out what 'most inputs' means. It means that the probability that a random program of 'length' n can be checked by this algorithm tends to 1 as n tends to infinity. In other words, if n is large enough, then a random program of length n can almost surely be checked by this algorithm.

Which programs can be checked by the approach described in the paper? Essentially, all programs that halt before repeating a state (where 'state' roughly corresponds to a line of code in a program).

Even though nearly all programs can be checked in this way, none of the programs that can be checked in this way are very interesting and they usually won't be designed by humans, so this is of no practical value whatsoever.

It also indicates that generic-case complexity will probably not be able to help us with the halting problem, as nearly all interesting programs are (apparently) hard to check. Or, alternatively phrased: nearly all programs are uninteresting, but easy to check.


答:
Some of the best software developers I have worked with didn't have a degree related to software development.  Myself, I have a degree in IT but still pursued a career in software development.

Professional engineering associations tend to form when a particular technical field has near universal and unchallenged standards and accepted practices AND when their is a relatively large amount of qualified labor as compared to demand for such professionals.  This happens in relatively mature engineering fields.

Software engineering isn't quite there (yet) but slowly getting closer.  The problem is that if you take a random sampling of software engineers today and ask them a simple question, like "Design a CRUD web based application for tracking __" and you will get wildly different designs.  Some will be good designs, some will be poor, some will unique, some will be boilerplate.  Hell if you get James Gosling, Martin Fowler and several other great minds into a room they would probably have more arguments and differences than what they agree on.

Further consider that from a business and societal perspective we tend to be okay with poor quality software sometimes (depending on availability of alternatives and price).  Compare that to business and societal perspective on the quality we expect from a bridge.  Nobody accepts a poor quality bridge, and engineers designing that bridge do so under strict guidelines and accepted standards.

In my opinion it will get to the point someday where the cost and value of 90% of software available today will align more properly, and what will remain will be large, expensive and highly standards driven projects with highly accepted and formalized methods to approach design problems.  Only at this point will the need for qualified engineers in a professional association be greater than the need for a bright wiz kid who can do the job as well with less formality.  I don't see this happening for at least another 15-20 years however.


问:
Protecting the uninitiated (developer) from generics
Is it acceptable to have a dummy generic parameter in the parameters list in order to save method consumers from the need to specify type arguments? For example -

public T Generate<T>(int paramForInstance) where T : MyClass {
    return MyClass.SomeFactoryMethod<T>(paramForInstance);
}

//calling code needs to specify type
MyDerivedClass instance = Generate<MyDerivedClass>(5);

public T Generate<T>(int paramForInstance, T dummy) where T : MyClass {
    return MyClass.SomeFactoryMethod<T>(paramForInstance);
}

//calling code needs to provide a "sample" to enable type inference
MyDerivedClass instance = null;
instance = Generate(5,instance);
```

<p>The assumption here is that if <strike>junior</strike> other devs on the team don't need to think about generics, they're less likely to kick.</p>

<h2>A Little Background (feel free to skip this)</h2>

<p>A couple weeks ago, a management-developer type in my team freaked out when he saw code (my code) that looked like this:</p>

<pre class="lang-cs prettyprint-override"><code>//conversion methods, using generics
private static TResult? IfNotDangerous<TResult>
  (SomeType firstThing, string name, Func<object, TResult?> conversion)
  where TResult : struct
{
    return IfNotDangerous(firstThing, name,
          (any, dummy) => conversion(any), (TResult?)null);
}

private static TResult IfNotDangerous<TResult>
  (SomeType firstThing, string name, Func<object, TResult, TResult> conversion,
  TResult defaultValue)
{
    if (firstThing == null) return defaultValue;
    if (!firstThing.Contains(name)) return defaultValue;
    if (firstThing[name] == DangerousValue) return defaultValue;
    return conversion(firstThing[name], defaultValue);
}
</code>```

The complaint he had was, "Why are you using a struct?! That's so resources-heavy! And what does 'where' mean? Nobody on the senior development end knows what that does - I've asked them all!"

After overcoming my self-pity, I found a way around that didn't use generics for this particular method. Appeasement was achieved. But I'd like to avoid trouble in the future, if possible.

EDIT

I appreciate all the encouragement, but the question was not "should I look elsewhere for work?" - it was "is this a usable workaround?"

答:
I think you absolutely should not do this.

You are not really helping anyone, even though I understand that's what you're trying. But in the end, you are hindering understanding of the static type system by concealing something fundamental. I mean it is not like we're talking covariance/contravariance or higher order types here.

These are simple, first order type parameters with constraints. This is something every programmer should understand. If they don't then they should learn it, and they really aren't willing to, they should code in a dynamic language instead (or be fired if you ask me).

The point of static type systems is to encode your domain knowledge into language semantics. The more powerful the type system, the harder it is to learn, but the more safety you will get automatically. This is an investment of maybe half a day of tutoring at most, that will start to pay off within weeks. Your code base will become more robust, thereby more flexible and thereby the cost of responding to requirement changes and debugging in general will be cut considerably.

If you really feel you must do this, then I guess you should do something like (not sure how this should actually look in C#):

```<code>public T Generate<T>(Class<T> theClass, int paramForInstance) where T : MyClass {
    return MyClass.SomeFactoryMethod<T>(paramForInstance);
}
//which should make this possible
var instance = Generate(MyDerivedClass, 5);
</code>```

The point is, that you're virtually using type parameters here. Once your co-workers accept that, transitioning to Generate<MyDerivedClass>(5) is just a small step for them, but a giant leap for your team ;)

Body:
I think you absolutely should not do this.

You are not really helping anyone, even though I understand that's what you're trying. But in the end, you are hindering understanding of the static type system by concealing something fundamental. I mean it is not like we're talking covariance/contravariance or higher order types here.

These are simple, first order type parameters with constraints. This is something every programmer should understand. If they don't then they should learn it, and they really aren't willing to, they should code in a dynamic language instead (or be fired if you ask me).

The point of static type systems is to encode your domain knowledge into language semantics. The more powerful the type system, the harder it is to learn, but the more safety you will get automatically. This is an investment of maybe half a day of tutoring at most, that will start to pay off within weeks. Your code base will become more robust, thereby more flexible and thereby the cost of responding to requirement changes and debugging in general will be cut considerably.

If you really feel you must do this, then I guess you should do something like (not sure how this should actually look in C#):

public T Generate<T>(Class<T> theClass, int paramForInstance) where T : MyClass {
    return MyClass.SomeFactoryMethod<T>(paramForInstance);
}
//which should make this possible
var instance = Generate(MyDerivedClass, 5);

The point is, that you're virtually using type parameters here. Once your co-workers accept that, transitioning to Generate<MyDerivedClass>(5) is just a small step for them, but a giant leap for your team ;)


答:
I recommend you to read Gödel, Escher, Bach. It's a very fun and illuminating book that, among other things, touches on Gödel's incompleteness theorem and the halting problem.

To answer your question in a nutshell: the halting problem is decidable as long as your program does not contain a while loop (or any of its many possible manifestations).

Title: Is there a subset of programs that avoid the halting problem

Body:
I was just reading another explanation of the halting problem, and it got me thinking all the problems I've seen that are given as examples involve infinite sequences. But I never use infinite sequences in my programs - they take too long. All the real world applications have lower and upper bounds. Even reals aren't truly reals - they are approximations stored as 32/64 bits etc.

So the question is, is there a subset of programs that can be determined if they halt? Is it good enough for most programs. Can I build a set of language constructs that I can determine the 'haltability' of a program. I'm sure this has been studied somewhere before so any pointers would be appreciated. The language wouldn't be turing complete, but is there such a thing as nearly turing complete which is good enough?

Naturally enough such a construct would have to exclude recursion and unbounded while loops, but I can write a program without those easily enough.

Reading from standard input as an example would have to be bounded, but that's easy enough - I'll limit my input to 10,000,000 characters etc, depending on the problem domain.

tia

[Update]

After reading the comments and answers perhaps I should restate my question.

For a given program in which all inputs are bounded can you determine if the program halts. If so what are the constraints of the language and what are the limits of the input set. The maximal set of these constructs would determine a language which can be deduced to halt or not. Is there some study that's been done on this?

[Update 2]

here's the answer, it's yes, way back in 1967
from http://www.isp.uni-luebeck.de/kps07/files/papers/kirner.pdf

That the halting problem can be at least theoretically solved for ﬁnite-state
systems has been already argued by Minsky in 1967 [4]:
“...any ﬁnite-state machine, if left completely to itself, will fall eventually into a
perfectly periodic repetitive pattern. The duration of this repeating pattern cannot
exceed the number of internal states of the machine...”

(and so if you stick to finite turing machines then you can build an oracle)


问:
Is it possible to embed multiple programs into 1
To be more specific, let me explain my end result goal or more of what I would LIKE to have someday and then you can tell me if its even feasible and if not possibly an alternative method.

I really would like to have a tool like smush.it it is a website Yahoo runs that optimizes images, it is currently one of the best out there.  There FAQ page say they use all these programs to do it...

ImageMagick: to identify the image type and to convert GIF files to PNG files.

pngcrush: to strip unneeded chunks from PNGs. We are also experimenting with other PNG reduction tools such as pngout, optipng, pngrewrite. Hopefully these tools will provide improved optimization of PNG files.

jpegtran: to strip all metadata from JPEGs (currently disabled) and try progressive JPEGs.
gifsicle: to optimize GIF animations by stripping repeating pixels in different frames.
More information about the smushing process is available at the Optimize Images section of Best Practices for High Performance Web pages.

So basically you upload an image and it determines it's file type and runs it through the appropriate programs or programs and returns an optimized image and tell the original size and thew new size of the image.

If you search across StackOverflow you will see that many people are searching for an all in one program that can do this, mainly from the command line for Build scripts to use.

Now I am curious, is it possible to make a program that could be like 1 package that would include all these other programs into it, so on Windows it would be like 1 exe file or even a jar file would probably work as I know Yahoo has a jar file for Javascript compression that my Build script can use.

In my searches I have found 1 project that is similar but I am not sure if it is really what I am after, it is http://trimage.org/ it uses uses OptiPNG, PNGCrush, AdvPNG, JPEGOptim.  My problem with this 1 is first of all they do not release it for Windows but they say it's may be able to work on Windows, but mainly I saw the source code and it is just a bunch of Python scripts, also the programs it uses, all have to be installed separately.

My goal is to be able to not have to install 4-5 separate programs but to have them as 1

Please tell me if this is just a dream or something that's id possible, I only have a PHP background so hardly the knowledge for a project like this

答:
What you seem to want to do is the following:

write one program part that just takes a generic image

figure out the images file type

hand the image over to a specific module reponsible for that image type

choose one of the following

apply all the optimizations you have

add another chooser that hands over the image to a submodule

If you're new to programming, have a look at the "decorator pattern". It'll help you handing over the same image to multiple optimizers in a row.


答:
Assuming you have access to all source code, it is probably possible, but not very useful.

First, you should be sure that all the programs (supposedly in C) do not have any name clashes, so no global name (except main) appears in more than one program.

Then you could link all the "quasi-programs" together.

Back in the 1987? on SunOS3.5, shared libraries didn't exist, so Sun shipped a single executable which basically tested the first argument of the program (which is the program name), and executed the appropriate thing, using something similar to (assuming three programs foo, bar, and gee with their global names prefixed by foo_, bar_, gee_ respectively)

```<code> /* the three main-s */
 extern int foo_main(int, char**);
 extern int bar_main(int, char**);
 extern int gee_main(int, char**);

 int main (int argc, char**argv)
 {
    if (!strcmp(argv[0], "foo"))
       return foo_main (argc, argv);
    else if (!strcmp(argv[0], "bar"))
       return bar_main (argc, argv);
    else if (!strcmp(argv[0], "gee"))
       return gee_main (argc, argv);
    else
       fprintf (stderr,
               "expecting foo, bar, or gee as program, but got %s\n",
               argv[0]);
    return 3;
 }
</code>```

PS. I would have asked that on StackOverflow.

Title: Is it possible to embed multiple programs into 1

Body:
To be more specific, let me explain my end result goal or more of what I would LIKE to have someday and then you can tell me if its even feasible and if not possibly an alternative method.

I really would like to have a tool like smush.it it is a website Yahoo runs that optimizes images, it is currently one of the best out there.  There FAQ page say they use all these programs to do it...

ImageMagick: to identify the image type and to convert GIF files to PNG files.

pngcrush: to strip unneeded chunks from PNGs. We are also experimenting with other PNG reduction tools such as pngout, optipng, pngrewrite. Hopefully these tools will provide improved optimization of PNG files.

jpegtran: to strip all metadata from JPEGs (currently disabled) and try progressive JPEGs.
gifsicle: to optimize GIF animations by stripping repeating pixels in different frames.
More information about the smushing process is available at the Optimize Images section of Best Practices for High Performance Web pages.

So basically you upload an image and it determines it's file type and runs it through the appropriate programs or programs and returns an optimized image and tell the original size and thew new size of the image.

If you search across StackOverflow you will see that many people are searching for an all in one program that can do this, mainly from the command line for Build scripts to use.

Now I am curious, is it possible to make a program that could be like 1 package that would include all these other programs into it, so on Windows it would be like 1 exe file or even a jar file would probably work as I know Yahoo has a jar file for Javascript compression that my Build script can use.

In my searches I have found 1 project that is similar but I am not sure if it is really what I am after, it is http://trimage.org/ it uses uses OptiPNG, PNGCrush, AdvPNG, JPEGOptim.  My problem with this 1 is first of all they do not release it for Windows but they say it's may be able to work on Windows, but mainly I saw the source code and it is just a bunch of Python scripts, also the programs it uses, all have to be installed separately.

My goal is to be able to not have to install 4-5 separate programs but to have them as 1

Please tell me if this is just a dream or something that's id possible, I only have a PHP background so hardly the knowledge for a project like this

Body:
Assuming you have access to all source code, it is probably possible, but not very useful.

First, you should be sure that all the programs (supposedly in C) do not have any name clashes, so no global name (except main) appears in more than one program.

Then you could link all the "quasi-programs" together.

Back in the 1987? on SunOS3.5, shared libraries didn't exist, so Sun shipped a single executable which basically tested the first argument of the program (which is the program name), and executed the appropriate thing, using something similar to (assuming three programs foo, bar, and gee with their global names prefixed by foo_, bar_, gee_ respectively)

 /* the three main-s */
 extern int foo_main(int, char**);
 extern int bar_main(int, char**);
 extern int gee_main(int, char**);

 int main (int argc, char**argv)
 {
    if (!strcmp(argv[0], "foo"))
       return foo_main (argc, argv);
    else if (!strcmp(argv[0], "bar"))
       return bar_main (argc, argv);
    else if (!strcmp(argv[0], "gee"))
       return gee_main (argc, argv);
    else
       fprintf (stderr,
               "expecting foo, bar, or gee as program, but got %s\n",
               argv[0]);
    return 3;
 }

PS. I would have asked that on StackOverflow.


答:
Of course this is technically possible. In fact, most software out there does something similar, so I will not further comment on the technical aspects here. If you do have problems with that you may want to ask a more specific question here or on stackoverflow.com.

However, there are some other points you may want to consider:

Usually, you do not bundle the programs as .exe files, but rather include library versions of these. For example, ImageMagick itself is already bundling several graphic libraries (optionally even), like libpng or libjpeg. Another example is transcode, which does similar things with movies instead of images. First, this approach allows you direct API access to the other libraries, and second, you do not have to ship several .exe files and possibly confuse your users as to which one they should execute.

The main problem from a non-technical perspective is the redistribution problem involved, when you take someone else's project and simply make it part of your program. Not all existing programs allow you to do this. You have to be very careful about the licences these programs have been published with. A solution I sometimes come across for this is to require users to actually install the 3rd party software themselves and the program checks for its presence dynamically when being run. As this is not what you seem to want though, I can only urge you again to be careful about the licencing.


答:
The issue isn't on the input (obviously, with unbounded input, you can have unbounded running time just to read the input), it is on the number of internal states.

When the number of internal state is bounded, theoretically you can solve the halting problem in all cases (just emulate it until you reach halting or the repetition of a state), when it isn't, there are cases where it isn't solvable. But even if the number of internal states is in practice bounded, it is also so huge that the methods relying of the boundedness of the number of internal states are useless to prove the termination of any but the most trivial programs.

There are more practical ways to check the termination of programs.  For instance, express them in a programming language which hasn't recursion nor goto and whose looping structures have all a bound on the number of iterations which has to be specified on entry of the loop. (Note that the bound hasn't to be really related to the effective number of iterations, a standard way to prove the termination of a loop is to have a function which you prove is strictly decreasing from one iteration to the other and your entry condition ensure is positive, you could put the first evaluation as your bound).


问:
Data replication patterns / algorithms
I have a series of systems that need to be distributed to a variable number of nodes (at least two, but more likely 8 - 10). For performance reasons, any one piece of state needs to be maintained in memory and replicated to at least two nodes although as demand increases this may be replicated to more nodes as dictated by the manager. Unfortunately, we cannot buy commercial data grids which are already very good at this.

The question: Assuming the state is immutable, what are some patterns and/or algorithms I can use to facilitate this process? I've supplied a sample to facilitate the discussion, but I'm not tied to this. Really!... I'm wide open on picking a new direction to meet these requirements. If you could point me to pictures or code samples that would be much appreciated.

As it stands, one of the nodes will self-promote and will orchestrate who should replicate and when (i.e. the manager).

Other assumptions:

List item

Systems will communicate via TCP/IP and Multicast

No databases

No file transfer... just byte arrays

All components are currently C#, and I can change almost anything

Eventual consistency will be fine

Note: I realize this sample does not handle fail cases. At this point I thought it would over-complicate things

答:
I think it is worth considering distributed cache approach.

Microsoft: http://msdn.microsoft.com/en-us/library/ff383731.aspx

Open source memcached: http://memcached.org/

What is the size of data you want to replicate?

Title: Data replication patterns / algorithms


问:
How to architect enterprise desktop applications for Windows 8
I think I have a grasp on the expectations of consumer application development for Windows 8.  Create a new Metro-based UI on top of WinRT, deploy it to your customer via the Marketplace, and everyone wins.  Seems simple enough.  Unfortunately, I'm not in that business.

I work on internal, line-of-business applications for a large enterprise.  We currently use .NET technologies such as WPF and Silverlight in order to create rich UIs that can be easily deployed to our users via the web or ClickOnce.  The applications can support WinXP and Win7 without too much headache, and our developers get to use XAML which is a very solid UI technology.

It seems like WPF and Silverlight have questionable futures at this point, so it is a bit worrisome to continue investing in those.  But a Metro UI doesn't seem appropriate for enterprise applications, and the WinRT API is quite limiting with regards to "typical" things that enterprise applications need to do.

How should I be architecting my XAML-based applications, currently being deployed to WinXP and Win7, so that they will be supportable and evolvable on Win8?

Assume for the purposes of this question that the features provided by HTML5 on top of ASP.NET are not adequate for the applications I'm looking to create.  I understand that I can use HTML5 for some applications, but I'm trying to figure out what I should do when that isn't enough.

Edit #1:
This is in response to @Emmad Kareem's comment.  I do agree that Silverlight/WPF are viable in the short term (2-5 years).  However, the applications we produce have potentially very long lifetimes (10-20+ years).  So survivability in the long term for a given technology is a concern for us.  Also, we have some concern that it will be more and more difficult to find developers that are interested in Silverlight / WPF development if those technologies are considered "dead" by the community.  I just want to understand my options and make a decision with my eyes open.

答:
How I Learned to Stop Worrying and Love the MS-Stack

You can still run VB6 apps on windows 8. Retro-compatibility for good or bad has always been a trend in the MS ecosystem. You shouldn't worry about the survival of technologies like WPF / Silveright, and even winforms for that matter.

On the other hand, you have to accept that for a long term project, you will never have the latest, cutiest technology.

In fact the questions you should ask yourself about the choice of a technology are :

Is my team comfortable enough with that technology to be productive?

Is my team happy to use that technology?

Can I recruit people for that technology?

That's the combination of the answers to this questions that should lead your choice, and not the trends forged mainly for marketing reasons.

For more about this thematic of ever-changing technology, you should read "Fire And Motion" By Joel Spolsky :

The companies who stumble are the ones who spend too much time reading
  tea leaves to figure out the future direction of Microsoft. People get
  worried about .NET and decide to rewrite their whole architecture for
  .NET because they think they have to. Microsoft is shooting at you,
  and it's just cover fire so that they can move forward and you can't,
  because this is how the game is played, Bubby. Are you going to
  support Hailstorm? SOAP? RDF? Are you supporting it because your
  customers need it, or because someone is firing at you and you feel
  like you have to respond? The sales teams of the big companies
  understand cover fire.

And that was written nearly ten years ago.

Architecture and Technologies

Architecture and Technologies are two separate things and choices to do :

You can do MVC with winforms.

You can do MVVM with WPF/Silverlight.

You can do MVC with ASP.NET.

You can do whatever you want, including MVC and MVVM, with WINRT as far as we know.

You can go functional with F#. Why not ? There are domains where it would make sense.

You can mix all of them, to have different entry points to a common system, then be mocked because it gets too complicated, etc.

You can use services, resources, third party controls, ORMs, etc. with all this technologies, and maybe, or maybe not, with the next ones.

You can twist and bend MVC in many ways with all those technologies : Binding or not ? code behind view or not ? Controller or not ? ViewModel everytime or only when needed ? There are so many ways to implement a design pattern, even within the scope of one specific technology.

That would be irrealistic to force you into one of them without advanced knowledge of your project and team. It would only be based on personal preferences, and would end-up in a "my technology is better than yours" showdown.

The only thing that can be honestly and objectively suggested is to use the best practices you can apply to create an architecture that will stand the test of time, and maybe, really maybe will be portable or reused at least in parts with a future unknown technology. And that upgradability/portability shouldn't even be the main purpose of your architecture.

The main purpose of your architecture and choosed technology is to deliver a product to your boss/customer that meets his realistic requirements.

MVC (and it's younger brother MVVM) proved more and more to be a basis for robust architecture since 1979 in the OOP languages arena and beyond. But choosing what specific technology should be used in a 10 years long project should remain your decision.


答:
I believe there are no ACID transactions and you are aware of BASE and CAP theorems. What I understand from your diagrams is that the Manager X scans the source Y and target Z (this may increase) and facilitate replication between the two. In such a case, you can use the excellent ZMQ library and its C# bindings. It would solve you almost all your problems.

Else you may use MongoDB as it easy to replicate (MongoDB is a document-oriented datastore)

Things may get interesting if you want to be transaction safe.

Title: Data replication patterns / algorithms

Body:
I have a series of systems that need to be distributed to a variable number of nodes (at least two, but more likely 8 - 10). For performance reasons, any one piece of state needs to be maintained in memory and replicated to at least two nodes although as demand increases this may be replicated to more nodes as dictated by the manager. Unfortunately, we cannot buy commercial data grids which are already very good at this.

The question: Assuming the state is immutable, what are some patterns and/or algorithms I can use to facilitate this process? I've supplied a sample to facilitate the discussion, but I'm not tied to this. Really!... I'm wide open on picking a new direction to meet these requirements. If you could point me to pictures or code samples that would be much appreciated.

As it stands, one of the nodes will self-promote and will orchestrate who should replicate and when (i.e. the manager).

Other assumptions:

List item

Systems will communicate via TCP/IP and Multicast

No databases

No file transfer... just byte arrays

All components are currently C#, and I can change almost anything

Eventual consistency will be fine

Note: I realize this sample does not handle fail cases. At this point I thought it would over-complicate things


答:
You say XAML is solid but then say WPF has a questionable future. Unless I'm missing something, WPF uses XAML and I don't see the two ever being separated. Is there some news I'm missing about WPF possibly using some other base technology, or about Microsoft even possibly considering of building yet a another new way to build UIs? Outside of that, I doubt WPF is going anywhere, but it wouldn't be the first time MS has obsoleted boatloads of our code...

If you need a rich UI app and HTML5 won't cut it, and you're org is committed to windows OS, I think WPF is the best choice as it's the lastest/greatest right now, certainly over winforms...

Title: How to architect enterprise desktop applications for Windows 8

Body:
I think I have a grasp on the expectations of consumer application development for Windows 8.  Create a new Metro-based UI on top of WinRT, deploy it to your customer via the Marketplace, and everyone wins.  Seems simple enough.  Unfortunately, I'm not in that business.

I work on internal, line-of-business applications for a large enterprise.  We currently use .NET technologies such as WPF and Silverlight in order to create rich UIs that can be easily deployed to our users via the web or ClickOnce.  The applications can support WinXP and Win7 without too much headache, and our developers get to use XAML which is a very solid UI technology.

It seems like WPF and Silverlight have questionable futures at this point, so it is a bit worrisome to continue investing in those.  But a Metro UI doesn't seem appropriate for enterprise applications, and the WinRT API is quite limiting with regards to "typical" things that enterprise applications need to do.

How should I be architecting my XAML-based applications, currently being deployed to WinXP and Win7, so that they will be supportable and evolvable on Win8?

Assume for the purposes of this question that the features provided by HTML5 on top of ASP.NET are not adequate for the applications I'm looking to create.  I understand that I can use HTML5 for some applications, but I'm trying to figure out what I should do when that isn't enough.

Edit #1:
This is in response to @Emmad Kareem's comment.  I do agree that Silverlight/WPF are viable in the short term (2-5 years).  However, the applications we produce have potentially very long lifetimes (10-20+ years).  So survivability in the long term for a given technology is a concern for us.  Also, we have some concern that it will be more and more difficult to find developers that are interested in Silverlight / WPF development if those technologies are considered "dead" by the community.  I just want to understand my options and make a decision with my eyes open.


问:
how to deal with parallel programming
I know that parallel programming is a big resource in computer graphics, with moder machines, and mayebe a computing model that will be grow up in the near future (is this trend true?).

I want to know what is the best way to deal with it. there is some practical general purpose usefulness in studying processor n-dimensional mesh, or bitonic sort in p-ram machines or it's only theory for domain specific hardware used in real particular signal elaborations of scientific simulations?

Is this the best way to acquire the know how for how to become acquainted with cuda or opencl? (i'm interested in computer graphics applications)

and why functional programming is so important to understand parallel computing?

ps: as someone has advice me i have forked this discussion from https://stackoverflow.com/questions/4908677/how-to-deal-with-parallel-programming

答:
Parallel and distributed computing go hand-in-hand. Omega Centauri rightly pointed out the shared memory architecture. But shared nothing architecture based on the Actor Model seems to be the forerunner for general purpose computing. If you want to learn parallel programming in general, since CPU's are also multiplying their cores, I suggest you to learn the following

Distributed Computing in general. Distributed Systems: Concept and Design gives you an excellent insight

MapReduce - just to think in the parallel, distributed way

Erlang - Actual programming

Also, OpenCL is platform-independent while CUDA is not but CUDA is more mature.
And a final note, neither MapReduce is a silver bullet nor Erlang is a speed machine

Title: how to deal with parallel programming


答: One thing that I think you have to be concious of being on a development "team" is that your code needs to be readable and maintainable by others. I agree with the answers to teach and move the team forward, but until that happens you need to stick with constructs that everyone understands and is comfortable with.</p>

Title: Protecting the uninitiated (developer) from generics

Body:
Is it acceptable to have a dummy generic parameter in the parameters list in order to save method consumers from the need to specify type arguments? For example -

public T Generate<T>(int paramForInstance) where T : MyClass {
    return MyClass.SomeFactoryMethod<T>(paramForInstance);
}

//calling code needs to specify type
MyDerivedClass instance = Generate<MyDerivedClass>(5);

public T Generate<T>(int paramForInstance, T dummy) where T : MyClass {
    return MyClass.SomeFactoryMethod<T>(paramForInstance);
}

//calling code needs to provide a "sample" to enable type inference
MyDerivedClass instance = null;
instance = Generate(5,instance);
```

<p>The assumption here is that if <strike>junior</strike> other devs on the team don't need to think about generics, they're less likely to kick.</p>

<h2>A Little Background (feel free to skip this)</h2>

<p>A couple weeks ago, a management-developer type in my team freaked out when he saw code (my code) that looked like this:</p>

<pre class="lang-cs prettyprint-override"><code>//conversion methods, using generics
private static TResult? IfNotDangerous<TResult>
  (SomeType firstThing, string name, Func<object, TResult?> conversion)
  where TResult : struct
{
    return IfNotDangerous(firstThing, name,
          (any, dummy) => conversion(any), (TResult?)null);
}

private static TResult IfNotDangerous<TResult>
  (SomeType firstThing, string name, Func<object, TResult, TResult> conversion,
  TResult defaultValue)
{
    if (firstThing == null) return defaultValue;
    if (!firstThing.Contains(name)) return defaultValue;
    if (firstThing[name] == DangerousValue) return defaultValue;
    return conversion(firstThing[name], defaultValue);
}
</code>```

The complaint he had was, "Why are you using a struct?! That's so resources-heavy! And what does 'where' mean? Nobody on the senior development end knows what that does - I've asked them all!"

After overcoming my self-pity, I found a way around that didn't use generics for this particular method. Appeasement was achieved. But I'd like to avoid trouble in the future, if possible.

EDIT

I appreciate all the encouragement, but the question was not "should I look elsewhere for work?" - it was "is this a usable workaround?"


答:
The answer to your question is Yes. It is a good idea to separate your application into classes, components and layers. A more sophesticated separation can be achieved using a famous design architecture called N-Tier Architecture where an application physically separate its components into separate physical tiers (not only logical layers). It has many advantages that I would recommend you get to know if you haven't already done so. See for example this:

N-Tier

Another famous design pattern that promotes more independence of the GUI (Wikipidia cosniders it an Architecture) is MVC (Model-View-Controler) - See about it here:

MS-Model-View-Controler-Intro

MVC-Better-Code-Organization

A discussion about N-Tier and MVC may also be useful - See this:

MVC-VS-NTier

Before you use any of this stuff, you need to justify the effort and cost of the learning curve. N-Tier and MVC applications may be classified as "advanced" programming techniques and may be harder for those not familiar with the concepts, so is it worth it?

Title: Separating the UI from its event handlers and database queries

Body:
Is it a good practice to separate the handlers and database queries in different classes?

There will be a separate class containing all the necessary event handlers, and there would also be another class for database queries?


问:
Can I apply for "Software Engineer" jobs without being an engineer?
I am from a country in which the use of the word "Engineer" or "Engineering" is strictly regulated by legislation. This means that you must hold a degree in Engineering AND passed an exam to join the Engineers' professional association to use the title. I am a bit confused about the term "Software Engineer" as used in the industry, globally.

I read the wikipedia page on Software Engineer and the linked section of the page about the term usage, which offer an in-depth discussion. However my question is somehow more concrete.

Knowing that I don't hold a degree in engineering (yet, I like to think I produce funcional, well designed software!), when I see an opening for a software engineer from an international company, would it be appropriate for me to apply? Should I somehow emphasise that I don't hold a degree in engineering?

答:
In the US, it's "software engineer" is a common job title that doesn't really mean anything different from "programmer/analyst" or "software developer". It depends what the company in question wants to give out as a title.

For example, at one place I was employed, almost everyone had a job title that ended either with "engineer" or "technician". The HR manager in my location was called a "Lead Human Resources Engineer".


答:
One thing I will address in my book on MVVM is how to leverage the pattern to create a reusable core application. You should be creating a native UI for the various platforms you target (be it web, silverlight, phone, WPF, or WinRT). But for the most part, you can encapsulate the logic driving that UI behind a ViewModel.

Any services you access should be wrapped behind an interface (Facade pattern) that is more or less portable between platforms. The interface should map to your client API on the front and translate to the API of the wrapped service on the back.

This strategy helps you create a solid core framework that only requires a new UI to be layered on top of it. Think of it as your View Model being the muscles, your services make the skeleton (and organs). WPF/Silverlight/WinRT form the skin.

In fact, one thing that I point out very early in my book is that MVVM isn't as new as it seems to be. Dolphin Smalltalk had a similar pattern that they called MMVC (the two M's were Application Model and Domain Model). The ViewModel we use today is just a combination of the Application Model and Controller from MMVC. In fact many developers are finding that sometimes separating the ViewModel into it's two components makes sense (the controller being used for navigation and orchestrating multiple VMs so that the VM can remain blissfully unaware of other components).


答:
The introspection about whether you're making code too complicated or if it is reasonable to expect others to be about to understand and use your code is a good thing. However, on this particular snippet

```<code>MyDerivedClass instance = null;
instance = Generate(5, instance);
</code>```

I do not like it. In my view, this does not make the code simpler. And it is obviously no more succinct. You haven't saved the developer from having to specify the class type for the generic method call, you have simply moved where it is specified. Either way, you've explicitly stated the type. You're also making me wonder what the method might be doing with instance, why I am reassigning it, etc. (Keep in mind, someone may very well "new up" or otherwise have an instance prior to the method call.) For an experienced* developer, this might not be a problem. For the junior you are trying to shelter?

No, I would opt for what should be simple enough to reason about.

```<code>var instance = Generate<MyDerivedClass>(5);
</code>```

You certainly want to make code as easy to read, use, and decipher as possible, but creating overloads with degenerate parameters is not likely the solution.

(*) I have recently been involved in helping to interview candidates for roles on my current team. Let's just say the "experienced developers" aren't nearly as experienced as you and I might desire and they might believe. These developers with 5, 8, even 20 years of experience would not understand even your simpler snippet. These are people that have been in the industry for years, have been developing C# since 1.1 or 2.0. They are also people who still cannot reason about generics, their go-to collection of choice is still ArrayList, they can't adequately describe much less implement polymorphic behaviors, etc., I don't know what to say. Perhaps they simply haven't been pushed at their prior roles. Maybe they're not as passionate about development, or resistant to change. Maybe they're just cargo cult. Suffice it to say, I can sympathize with your plight.

Body:
The introspection about whether you're making code too complicated or if it is reasonable to expect others to be about to understand and use your code is a good thing. However, on this particular snippet

MyDerivedClass instance = null;
instance = Generate(5, instance);

I do not like it. In my view, this does not make the code simpler. And it is obviously no more succinct. You haven't saved the developer from having to specify the class type for the generic method call, you have simply moved where it is specified. Either way, you've explicitly stated the type. You're also making me wonder what the method might be doing with instance, why I am reassigning it, etc. (Keep in mind, someone may very well "new up" or otherwise have an instance prior to the method call.) For an experienced* developer, this might not be a problem. For the junior you are trying to shelter?

No, I would opt for what should be simple enough to reason about.

var instance = Generate<MyDerivedClass>(5);

You certainly want to make code as easy to read, use, and decipher as possible, but creating overloads with degenerate parameters is not likely the solution.

(*) I have recently been involved in helping to interview candidates for roles on my current team. Let's just say the "experienced developers" aren't nearly as experienced as you and I might desire and they might believe. These developers with 5, 8, even 20 years of experience would not understand even your simpler snippet. These are people that have been in the industry for years, have been developing C# since 1.1 or 2.0. They are also people who still cannot reason about generics, their go-to collection of choice is still ArrayList, they can't adequately describe much less implement polymorphic behaviors, etc., I don't know what to say. Perhaps they simply haven't been pushed at their prior roles. Maybe they're not as passionate about development, or resistant to change. Maybe they're just cargo cult. Suffice it to say, I can sympathize with your plight.


答: I write embedded software for telecommunications equipment.  My problem domain is ethernet, voice, and video protocols.  In other words, all the stuff that has nothing to do with the language I'm programming in, but that I still must understand in order to write the software.  If you're making a website for selling photography services, the problem domain is photography and ecommerce.  If you write firmware for military aircraft, the problem domain is weapons, sensors, and control systems.  Get the picture?</p>

Title: What is "Problem Domain"

Body:
I have to document my program for a school project and we have section called "problem domain" but I have no idea what to discuss in this section.

So the question is: What should be discussed in the problem domain?


问:
Using GPL licensed jQuery scripts on website with ads
I'm making a web application that will generate revenue from displaying ads. The system is meant for me to run and not sold/distributed to anyone else.

My questions are:

Can I use GPL licensed jQuery scripts on the website?

Can I use GPL licensed scripts while generating ad revenue from the page?

Do I need to provide my sites source to everyone if I use GPL licensed scripts?

答:
Can I use GPL licensed jQuery scripts on the website?

Yes, but see the third one.

Can I use GPL licensed scripts while generating ad revenue from the page?

Yes. GPL doesn't say anything about generating revenue.

Do I need to provide my sites source to everyone if I use GPL licensed scripts?

Excepted that the GPL gives you obligations only to people to whom you distribute and not everybody which could get an hand on the it and even less people who don't have access to the program, the matter is murky in my view. Ask a IP lawyer.  At least two questions:

What is distribution for a web site?  (See the discussions about the same question for embedded devices placed at user site but still the property of a service provider).  I am not even sure that the fact that part of the site run on the browser and part on a server is pertinent.

What is the extend of the derived work? Just the script is for sure too small.  The whole site can be arguably too large, at least in some cases. A set of sites could be pertinent in some cases (technical measure such as the deployment on one or several servers shouldn't be pertinent to the notion of derived work).


问:
How to manage your functional documentation?
Our functional / business documentation is spread across Word files on our corporate Intranet.  It's difficult to find and update information.  There has to be a better way.  Any ideas?

We had thought a Wiki would work great. Would seem to be an easy way to find information and easy for individual developers and analysts to add bits of documentation quickly and easily.  We'd be curious to know if other development (or business analysis) teams use Wiki's with success.

The target for this documentation is the internal development team: developers, qa, and to a lesser extent business analysts.

答:
At one company I have worked at we had a lot of success in using a Wiki as a repository for technical documentation.  We tried getting the stone age business analysts to start using it for our benefit as well but alas, anything that would make them more accountable for out of date requirements documents or provide more transparency to their little fiefdom was met with brutal politically charged hostility.

Like all things though you get out of it what you put into it.  Garbage in garbage out.  There are also some helpful practices you can get in the habit of doing, like tagging pages with software release and build numbers so appropriate document history can be queried.

There is still the disconnect at that point where the version of the software is manually enforced to the documentation, in other words, the wiki is not being stored in source control.  If you are diligent and maintain versioning of pages in your wiki then you will help mitigate this problem and still get the benefits of an easy to access and edit online repository of documents.


答:
There are various "single source" solutions for documentation out there. A number of teams I've worked with have had great success with Madcap Flare. I especially like how it integrates well with source control and provides support for creating context-sensitive help.

Full disclosure: I have NO relationship with Madcap, not even as a reseller. But I have never been so thoroughly pleased with a documentation product.

Title: How to manage your functional documentation?

Body:
Our functional / business documentation is spread across Word files on our corporate Intranet.  It's difficult to find and update information.  There has to be a better way.  Any ideas?

We had thought a Wiki would work great. Would seem to be an easy way to find information and easy for individual developers and analysts to add bits of documentation quickly and easily.  We'd be curious to know if other development (or business analysis) teams use Wiki's with success.

The target for this documentation is the internal development team: developers, qa, and to a lesser extent business analysts.


答:
Not everyone writes compilers, bug trackers, frameworks, or other straight computery software packages.

Some people write software for the sand and gravel industry. Some people write software for monitoring refinery refraction towers. Some people write software to control the manufacturing of plastic grocery bags. Some people write software to fill ketchup packets.

Those are all problem domains, where in order to write good software, you need to know a bit about the domain, e.g. ready-mix concrete.

Title: What is "Problem Domain"


问:
Algorithm to determine fastest route?
Let's say we're going from 1 to 5. The shortest route will be 1-4-3-5 (total: 60 km).

We can use Dijkstra's algorithm to do that.

Now the problem is, the shortest route is not always the fastest one, because of traffic jams or other factors.

For example:

1-2 is known to have frequent traffic jams, so it should be avoided.

Suddenly a car accident happens along 4-3, so it should be avoided too.

Etc...

So probably we can speed on the route 1-4-5, because of no traffic jams/accidents, so will arrive at 5 faster.

Well that's the general idea, and I haven't think about more details yet.

Is there any algorithm to solve this problem?

答: You should just be able to replace your distance with the time between nodes and solve it the same way.</p>

Title: Algorithm to determine fastest route?


答:
Yes: Dijkstra

Dijkstra works just as well for this situation.

You just use time rather than distance as the weight of each arc.

Title: Algorithm to determine fastest route?

Body:
Let's say we're going from 1 to 5. The shortest route will be 1-4-3-5 (total: 60 km).

We can use Dijkstra's algorithm to do that.

Now the problem is, the shortest route is not always the fastest one, because of traffic jams or other factors.

For example:

1-2 is known to have frequent traffic jams, so it should be avoided.

Suddenly a car accident happens along 4-3, so it should be avoided too.

Etc...

So probably we can speed on the route 1-4-5, because of no traffic jams/accidents, so will arrive at 5 faster.

Well that's the general idea, and I haven't think about more details yet.

Is there any algorithm to solve this problem?


答:
Yes.  Dijkstra's algorithm will solve this problem.

The problem in your case is that you automatically assume the shortest path equates to distance travelled, when in fact it more appropriately equates to the COST of taking a route.

If one path has a roadblock then its COST should be higher, and the algorithm still applies.

Title: Algorithm to determine fastest route?


问:
How do you maximise the knowledge that you gain from a programming book?
Not because I care how long it takes someone to read a book, but more because I'm interested in how people get the knowledge from a book (or I guess other sources) into their brains in the best, most efficient way.

Personally I take a multi-pass approach (from my answer to the original question):

Skim through contents, dip in and read anything with an interesting looking heading and finally gawp at any nice diagrams and illustrations. I won't take much in at this stage, but it gives me a mental view of the book (an hour or so at most)

First pass through the book, generally I'll read the opening chapters thoroughly for a book that is either very heavy going or introduces something completely new. For books that cover a subject I already know about I'll skim or skip bits that seem trivial. The remainder of the book I'll go through reasonably quickly but not so quickly that I'm just page flipping. (about a week)

Not all books that I read make it this far, but if I find a book interesting or useful enough I'll then study it properly. I will go through the book at a slower pace and do some or all of the examples, try out code, etc. I will often skip entire chapters here unless the book is really good (1-3 weeks depending on the book).

Finally when I've finished reading it and am reading other books I will often dip into it again and again to cross-reference, compare, look things up, browse, etc - so many of my favourite books don't just end up gathering dust on the bookshelf.

I rarely take notes when reading (although I may do some planning on paper if I'm working through something like a code sample). I've also considered starting to use a personal kanban for organising my progress, but have never quite got around to using that technique. Mindmaps are another thing I like the idea of but rarely do.

What other methods to people have? How successful do you find them? Are there any commonly recommended techniques that you feel are a waste of time?

答:
Implement

Implement each new algorithm or technique your read about on your own, using only your memory of the description of the algorithm or technique as reference.


答: Do not get caught up in titles. If they did mean something to that company, they just will ignore your CV/Resume.  You should apply to every single job that you feel you will enjoy.  Do not limit yourself at the starting gate.  At the worst case it wastes thirty minutes of your time.</p>

Body:
I am from a country in which the use of the word "Engineer" or "Engineering" is strictly regulated by legislation. This means that you must hold a degree in Engineering AND passed an exam to join the Engineers' professional association to use the title. I am a bit confused about the term "Software Engineer" as used in the industry, globally.

I read the wikipedia page on Software Engineer and the linked section of the page about the term usage, which offer an in-depth discussion. However my question is somehow more concrete.

Knowing that I don't hold a degree in engineering (yet, I like to think I produce funcional, well designed software!), when I see an opening for a software engineer from an international company, would it be appropriate for me to apply? Should I somehow emphasise that I don't hold a degree in engineering?


问:
Has SSRS replaced Crystal Reports as a new standard for Visual Studio reporting tool?
I never used SQL Server Reporting Services (SSRS) before but used little Crystal Reports. My present project has extensive use of Crystal Reports for Visual Studio 2005. This choice brought some nasty issues of Crystal Reports in front. The very first report failed to print or export because of a bug. After wasting a week, I got stuck in another issue of reducing font size on print and export.

Help in forums is also not coming soon. I want to know whether I should learn and switch to SSRS or migrate my project to Visual Studio 2010 with a higher version of Crystal Reports.

Has SSRS replaced Crystal Reports as a de facto standard reporting tool?

答: It's going to depend on your environment, but there does seem to be a general shift away from Crystal and towards SSRS with the vendors we've talked with (and also other developers that I've talked to).</p>


问:
How do you find errors related to undeclared variables in php?
If I copy a piece of code from somewhere that looks like so

```<code>$blah = array(1,2,3,4);
foreach ($blah as $i)
       echo ($i);
</code>```

and rename the variables but forget to do it correctly like so

```<code>$apple = array(1,2,3,4);
foreach ($blah as $i) <--- notice $blah instead of $apple
       echo ($i);
</code>```

Then my NetBeans IDE doesn't complain and I get an error at runtime when I run this.
Is there a way to catch errors like this without running the code? Which IDE does it? Which plugin? Or the whole PHP development world is living without this?

答:
To add to the advice above : PHP Manual -  (PHP 4, PHP 5)

isset — Determine if a variable is set and is not NULL

bool isset ( mixed $var [, mixed $... ] )

Determine if a variable is set and is not NULL.

If a variable has been unset with unset(), it will no longer be set. isset() will return FALSE if testing a variable that has been set to NULL. Also note that a NULL byte ("\0") is not equivalent to the PHP NULL constant.

If multiple parameters are supplied then isset() will return TRUE only if all of the parameters are set. Evaluation goes from left to right and stops as soon as an unset variable is encountered.


答:
At least in the US, the key is that you need to be able to do what's described in the description.  The way you got those skills less important.

HOWEVER- there are companies that do screening where it helps tremendously for an entry level position if you have:

B.S. or B.A. Degree in something

Preferably a B.S. in something vaguely related to computers - like Computer Engineering, Software Engineering, Computer Science, IT, Math, or something similar.  Even EEs, Physics, or any other science is likely to get you more opportunities than, say, Linguistics or Fine Arts.

A good GPA

This largely has to do with the company's screening process and the number of applicants they have.  The less formal the company, by and large, the less restrictive the screening.

In the end, I have little doubt that you can get a job doing "software engineering" provided you can do what they say in the description and you can make that case through your resume and the interview.  The definition of "engineering" as something highly legislated and baselined is unique enough to the given country that it won't particularly translate internationally.  Some professional certifications might - it all depends on the certification and the specialty it demonstrates.

Resumes

As far as a resume goes, I'd recommend highlighting what you CAN do.  Not what you haven't done.  A classic resume format will include:
- your goals
- your education
- your technical skills
- your previous work experience

Leaving off a critical element is a fine way of demonstrating you don't have that element, you don't have to go above and beyond to say what you don't do.  For example, if you have some number of years of college completed, but have not matriculated, mention where you went to school and how many years, and some key coursework.  The lack of graduation date (or expected graduation date) is a direct tip off that you have not yet finished school.

When speaking to skills you gained through independent personal projects, you have two options, IMO, depending on how much space you have available.

for a younger candidate, I'd list the skills acquirer in a skills section - for example programming languages, methodologies, development tools, etc.  And then list the personal project under "experience" with an annotation that this was a personal project. I met a candidate that had implemented dynamic web server code this way, on a game site, and when he provided the link, I went above and beyond to play with his site and get a sense of what he'd done - it was a real win for our discussion.

for a more experienced candidate with an experience list a mile long - just stick the new skills in the "skills/knowledge section" unless the project is unbelievable and available for review.  For example, if you coded a big part of Hibernate - put that on there!!!  but if you made a web server for your bingo group... I'm probably more interested in the big company that employed you for the last 3 years...

My general philosophy is - it's your job to show the company why they SHOULD hire you.  It's their job to vet whether or not you are the best fit for the position and they will do that by taking you into account in comparison to their larger pool of candidates.  If every other applicant has a formal degree and professional certification, then you may be out of luck... but if not, you may have the perfect skill set.


答:
Here's what I'm seeing based on viewing classified and my own job search process earlier this year.

Most companies with a long established .NET and/or VB6 code are sticking with Crystal for now. Unfortunately, they have too much invested in this or that weird report for various accounting managers, sales managers and such to make any big changes. Therefore, Crystal is one of the items on their "shopping list" when looking for new hires.

For new .NET development, SSRS is preferred by most companies. The difficulty they're having is finding developers sufficiently versed in it to do all the magical things those sales/accounting/marketing/whatever managers want. Sadly, many of them are unwilling to allow for even a brief getting up to speed phase to learn it.

Title: Has SSRS replaced Crystal Reports as a new standard for Visual Studio reporting tool?

Body:
I never used SQL Server Reporting Services (SSRS) before but used little Crystal Reports. My present project has extensive use of Crystal Reports for Visual Studio 2005. This choice brought some nasty issues of Crystal Reports in front. The very first report failed to print or export because of a bug. After wasting a week, I got stuck in another issue of reducing font size on print and export.

Help in forums is also not coming soon. I want to know whether I should learn and switch to SSRS or migrate my project to Visual Studio 2010 with a higher version of Crystal Reports.

Has SSRS replaced Crystal Reports as a de facto standard reporting tool?


答: Its hard to say for certain, because currently there is no business intelligence component to Visual Studio 2010, and there seems to be no plans to add one, so all reports for SSRS must be developed in Visual Studio 2008. However crystal reports can be made in Visual Studio 2010.  SSRS does seem to be better than crystal reports though for the little I've used it.</p>


答: We've been using the products from Atlassian.  They have an integrated solution that combines JIRA, SubVersion, and Confluence (Wiki).  </p>


问:
Decoupling Threads
It's not uncommon to hear of decoupling the UI from program logic, or database design/access from program logic...or even program logic from itself.

However, I've never heard of an approach to generalizing or abstracting away the details of threading tasks to the logic (aside from Tymeac, an Android-specific package). Honestly, with all of the details going into managing threads, I don't expect many solutions to work well anytime soon, so...

My question is, how do you write threads that aren't joined at the hip to the processes that use those threads? What do you normally do when requirements change in an already complicated multi-threaded application? Is there a design approach to this that I should read?

I ask this because we are the dawn of the "bagillion"-core era in computing. Eventually, a good methodology will have to exist to manage 1k+ cores and even more threads here in the next couple of decades.

答: Take a look at Apple's Grand Central Dispatch, which lets programmers take advantage of multiple processors without having to manage threads. The heart of GCD is libdispatch, available under an Apache license, so you can look at the source if you really want to see how to manage generic worker threads. libdispatch is apparently available in FreeBSD if you'd like to try it out but aren't working in MacOS X or iOS.</p>

Title: Decoupling Threads


答: Software engineer isn't a real engineer. There has been a movement to formalize software development into an engineering position, however it has hit a lot of bumps. Software development is still too new and developing too rapidly to be properly defined into an engineering profession, like a mechanical or electrical engineer. There is also some debate as to whether software development actually fits in the same definition of engineer or if it would even be beneficial to make software development an engineering process.</p>


问:
Should I decompress zips before I archive?
I am writing a small personal archiving tool. I frequently work with a lot of client databases for short periods, what my tool will do is in overnight batch jobs it will detach the database and zip up the database files and any extra files that where sitting in the folder that the database resided in and move it to a network storage drive.

My question is quite frequently there will be zip files sitting inside the folder (the most common one would be the client's original backup before I did the processing on it). Would it be better to unzip the file to a unique sub-folder name, delete the zip, then compress the whole parent folder, or are compression algroithoms good enough that I could leave the file zipped (it was likely done with a 7zip Fastest setting) and my archiving (which will be a 7zip Ultra setting) will just compress (mostly) the difference between the two compression levels?

If I can get another 1% off of a 20GB database file it may be worth it to do the decompression.

答: You will get better compression by decompressing the zip files first. Compressing already compressed data will almost never decrease the size significantly, even if it was previously compressed by a "worse" compression program.</p>