问:
Give a more formal definition for the term "pythonic" than PEP8?
For me as python programmer having a formal definition for the term "pythonic" would be much more important and less subjective compared to asking more rhetoric (non-formal) questions. This may lead to better communication by argumentation being less subjective (as discussed in here).

PEP8 by Guido is assumed as a starting point despite of some religious dogmatism (e.g. PEP20 is more axiomatic, shorter and simpler, but has no code). Having identified minimalism, readability (human comprehension) and unambiguity (explicit code) is actually the same as paraphrasing PEP20. But is it possible to rewrite zen of python in python? Obviously print('Beautiful is better than ugly') does not capture python in python ;-) Any thoughts on this?

Ultimately I would like to get closer to more logical or mathematical interpretation of the matter. Argument in form of the code answering why family of snippets A is pythonic compared to family of snippets B is also acceptable.

EDIT If possible try to reduce your answer to the following outline.
Let us consider all possible syntactically correct program texts generated by some procedure (e.g.). Please note that we a considering only programs written in python (which is a formal language with respective grammar). Also being syntactically correct does not mean semantical correctness (programs may be buggy or without any obvious purpose). Further we observe (assume) that ultimate family POmega of all syntactically correct programs in python must contain a subset of programs which are called Pythonic. Now in order to argue about what does it mean to be pythonic we will use a formal method - another language called Reason which would be less ambiguous (consistent, complete) than natural language. We will define a mapping from programs in Omega into Reason. Such mapping we will call interpretation. We will also produce more mappings in similar manner (e.g. as in) for all individual symbols in Python and their combinations (statements). Now if we would argue about images of such mappings, we would do so in form of proofs in Reason language. The question would be if subset Pythonic indeed exists can we follow that up from aximos in Reason built/reformulated from "Zen of python" or other motivating set of concepts? In fact, the whole deductive core of the language Reason would be built from "Zen" or PEP8. We will have to proof that each program from Pythonic will consist only from statements for images of which in  Reason can be shown to satisfy initial axioms of the model language. Different outcomes are plausible:

Subset of Pythonic programs could be empty. We have not found any programs that would satisfy our axioms in Reason.

It could happen that this set of axioms would turn out to be ambiguous (inconsistent or incomplete). Then our original assumption about existence of Pythonic programs would be wrong.

Alternatively axiomatic "Zen" could be simple enough and so well-chosen that Pythonic set is non-empty. Now the question is will such (consistent, complete) set be of practical value, i.e. can we say that such set of axioms is indeed a formal definition of "pythonic"?

This is a draft of how one can try to approach answering the question in formal manner. I would appreciate recommendations on a more elegant approach for solution to the problem (everything except ignoring it). But at the end it matters to me to see how such set of axioms looks like. Hence it will allow in precise (quantitative) way to ask and try to explain questions like why programs have "pythonic" qualities once written according to following python "dogmas"?

BTW One can built a more sophisticated model of Reason by introducing an equivalent of "human factor" - a software developer of the programs. Then the question would be - can human formally claim the program he rights belongs to "Pythonic" subset?

答:
```<code>funcs = dir(__builtins__)
help funcs[1]
</code>```

<p>Is my favorite </p>

Body:
funcs = dir(__builtins__)
help funcs[1]

Is my favorite


答:
Good code is good code whether one person deems it "Pythonic" or not. If it scales well, is tested, documented, easily read (doesn't use strange language hacks, etc) and follows sound architectural principles (DRY, SOLID, etc) then at the end of the day, who cares?

As "zen" is completely subjective to the reader, there is no measurable way of defining "Pythonic" code without some religious debate sparking. Best practices and standardization (such as PEP8) are a good start to achieving quality through automated consistency, but by no means gives a full definition to "Pythonic" code.

ContentLicense: CC BY-SA 3.0

Title: Give a more formal definition for the term "pythonic" than PEP8?

Body:
For me as python programmer having a formal definition for the term "pythonic" would be much more important and less subjective compared to asking more rhetoric (non-formal) questions. This may lead to better communication by argumentation being less subjective (as discussed in here).

PEP8 by Guido is assumed as a starting point despite of some religious dogmatism (e.g. PEP20 is more axiomatic, shorter and simpler, but has no code). Having identified minimalism, readability (human comprehension) and unambiguity (explicit code) is actually the same as paraphrasing PEP20. But is it possible to rewrite zen of python in python? Obviously print('Beautiful is better than ugly') does not capture python in python ;-) Any thoughts on this?

Ultimately I would like to get closer to more logical or mathematical interpretation of the matter. Argument in form of the code answering why family of snippets A is pythonic compared to family of snippets B is also acceptable.

EDIT If possible try to reduce your answer to the following outline.
Let us consider all possible syntactically correct program texts generated by some procedure (e.g.). Please note that we a considering only programs written in python (which is a formal language with respective grammar). Also being syntactically correct does not mean semantical correctness (programs may be buggy or without any obvious purpose). Further we observe (assume) that ultimate family POmega of all syntactically correct programs in python must contain a subset of programs which are called Pythonic. Now in order to argue about what does it mean to be pythonic we will use a formal method - another language called Reason which would be less ambiguous (consistent, complete) than natural language. We will define a mapping from programs in Omega into Reason. Such mapping we will call interpretation. We will also produce more mappings in similar manner (e.g. as in) for all individual symbols in Python and their combinations (statements). Now if we would argue about images of such mappings, we would do so in form of proofs in Reason language. The question would be if subset Pythonic indeed exists can we follow that up from aximos in Reason built/reformulated from "Zen of python" or other motivating set of concepts? In fact, the whole deductive core of the language Reason would be built from "Zen" or PEP8. We will have to proof that each program from Pythonic will consist only from statements for images of which in  Reason can be shown to satisfy initial axioms of the model language. Different outcomes are plausible:

Subset of Pythonic programs could be empty. We have not found any programs that would satisfy our axioms in Reason.

It could happen that this set of axioms would turn out to be ambiguous (inconsistent or incomplete). Then our original assumption about existence of Pythonic programs would be wrong.

Alternatively axiomatic "Zen" could be simple enough and so well-chosen that Pythonic set is non-empty. Now the question is will such (consistent, complete) set be of practical value, i.e. can we say that such set of axioms is indeed a formal definition of "pythonic"?

This is a draft of how one can try to approach answering the question in formal manner. I would appreciate recommendations on a more elegant approach for solution to the problem (everything except ignoring it). But at the end it matters to me to see how such set of axioms looks like. Hence it will allow in precise (quantitative) way to ask and try to explain questions like why programs have "pythonic" qualities once written according to following python "dogmas"?

BTW One can built a more sophisticated model of Reason by introducing an equivalent of "human factor" - a software developer of the programs. Then the question would be - can human formally claim the program he rights belongs to "Pythonic" subset?


问:
Separating a "wad of stuff" utility project into individual components with "optional" dependencies
Over the years of using C#/.NET for a bunch of in-house projects, we've had one library grow organically into one huge wad of stuff. It's called "Util", and I'm sure many of you have seen one of these beasts in your careers.

Many parts of this library are very much standalone, and could be split up into separate projects (which we'd like to open-source). But there is one major problem that needs to be solved before these can be released as separate libraries. Basically, there are lots and lots of cases of what I might call "optional dependencies" between these libraries.

To explain this better, consider some of the modules that are good candidates to become stand-alone libraries. CommandLineParser is for parsing command lines. XmlClassify is for serializing classes to XML. PostBuildCheck performs checks on the compiled assembly and reports a compilation error if they fail. ConsoleColoredString is a library for colored string literals. Lingo is for translating user interfaces.

Each of those libraries can be used completely stand-alone, but if they are used together then there are useful extra features to be had. For example, both CommandLineParser and XmlClassify expose post-build checking functionality, which requires PostBuildCheck. Similarly, the CommandLineParser allows option documentation to be provided using the colored string literals, requiring ConsoleColoredString, and it supports translatable documentation via Lingo.

So the key distinction is that these are optional features. One can use a command line parser with plain, uncolored strings, without translating the documentation or performing any post-build checks. Or one could make the documentation translatable but still uncolored. Or both colored and translatable. Etc.

Looking through this "Util" library, I see that almost all potentially separable libraries have such optional features that tie them to other libraries. If I were to actually require those libraries as dependencies then this wad of stuff isn't really untangled at all: you'd still basically require all the libraries if you want to use just one.

Are there any established approaches to managing such optional dependencies in .NET?

答: I'm going to recommend the book Brownfield Application Development in .Net. Two directly relevant chapters are 8 & 9. Chapter 8 talks about relayering your application, while chapter 9 talks about taming dependencies, inversion of control, and the impact this has on testing. </p>


问:
Web Development: is always Typing necessary or can type on demand work?
I realize this idea might seem really foreign but I started thinking about this a bit back.

Far as web sites go, at least in my experience, there is far more time spent retyping things to a String than the other way around.  For instance:

Say you have a user model:

```<code>user
  int UserId
</code>```

And I wanted to log the user in:

```<code>View  -> string to int -> controller -> int to dbInt -> database -> dbint to int -> controller -> int to string -> View
</code>```

At no point in that whole exchange did I need an int.  The one typing I did need was with the database, but that's just kind of expected.

Now if I wanted to show a list of users based on a group id, the same thing happens except that UserId conversion happens for how many there are on the list and in the end it will just be represented as a string in the UI.

Now I understand that a string might be larger memory wise than some types (bool for example) but is this more costly than all the typing that happens?

Could it be more productive to only type when needed (Validating a number, date, ect) and just leave them as strings for the most part?

答: In addition to what Justin Cave wrote, let me add that you do not have to go as far as dates to see the problem: if plain numbers were represented in string format in databases, 1111 would be sorted between 100 and 122. That would not work, would it? So, in order for the database to properly sort the number-strings, it would have to convert them to actual numbers first. Well, it turns out it saves everyone time, effort and headache if they are simply stored as numbers.</p>


答:
A formal definition for the term "pythonic" would be largely impossible.

It's as impossible as a definition for "aesthetic" or "convenient" or "delightful".

It can't be less subjective than it is now.

Why not?

Because Python is merely as aesthetic judgement based on the opinions of a fairly large number of people.  The GvR points are respected, but do not have the force of law. Many people write code for the Python world, and their various inputs influence other developers.  It's a vast social network of people all liking (and disliking) the code they read.

Ultimately I would like to get closer to more logical or mathematical interpretation of the matter

You would do well to start with studying art, aesthetics and philosophy first.  Then, after mastering aesthetics and morals, switch to ontology so that you can encode what you learned about truth and beauty.  Once you've finished that, you'll have a formal definition of Pythonic along with formal definitions of all the various subjective values that we hold.

axioms ... built/reformulated from "Zen of python"

It's a poem.  It's value is entirely aesthetic.  What more evidence does one need that Pythonic is a value judgement based on depth of experience?


问:
What is "Scalable Integrated Systems"?
I've come across a job posting that asks for experience with "Scalable Integrated Systems", but honestly that sounds like "generic buzzword," and I'm trying to figure out what the actual work behind "Scalable Integrated Systems" is. What does a "Scalable Integrated System" look like?

Is it making distributed computing software? Is it writing APIs between services in a way they "scale", and if so, scale in what way?

I don't understand what a Scalable Integrated System is.

The company seems competent and I have competent programmer friends working there who say they are a great place to work in. If it was SpammyCoOnCraigslist@yahoo.com, I wouldn't bother asking.

答:
I will give it a shot.. keeping it abstract and hopefully simple ;-)

System consists of (N) components, integrated with each other, and has efficiency metric m(N). Scalability means as long N grows m(N) must keep it up, at least linear.

Common sense ideas as entropy growing constantly with time or N must give a clue that at some point system will fail to keep it up and stay efficient. That is why it is regarded as engineering challenge.

Now integrated means components are connected and interacting with each other (sending signals, information, sharing resources, etc.).

Often with word integrated one actually means heterogeneous. For instance, if N is a network (graph) some nodes would be more stronger connected than other forming contexts with different levels of integration.

In terms of software it means systems are different because they are written in different languages, using different platforms, tools, architectures and design principles, people and so on. Basically if something has to be integrated it is assumed that it is even more difficult than just working with a system of similar components.

Title: What is "Scalable Integrated Systems"?


问:
What is the difference between waterfall model with iterations and evolutionary software development model?
Does anyone know the difference between those two? </p>

<p>They are both created by iterative approach - giving successive revision after each iteration. They both have the initial idea->analysis->(outline)design phases. </p>

答:
Definitions will vary so I doubt you will get a conclusive answer to this question.

Having said that, the most obvious potential difference I see is how the iterations relate to your high level design / architecture:

In an iterative waterfall model, you might use the iterations more for refinement/elaboration of elements of the overall design in multiple phases of [detailed design / build / test]. In theory, you could plan most of the iterations in advance.

In a true evolutionary model you would not have an overall design - you'd just be adding to whatever you have already built based on some notion of what is most valuable to do next, typically gained through intensive user feedback. You wouldn't have a fixed plan for future iterations (although you might keep a prioritised backlog or something similar).


问:
What do you call a pair of function that are complements of each other?
I am looking for the right word to describe a function and its complement.

Here I am looking for the proper word to describe a couple of functions when applied in sequence the system reverts to its original state.

Marshalling and Unmarshalling would be a subset of this

Add and Remove

Idempotence comes to mind though I am not sure if it can apply to more than one operation.  Reversible could also do, but it seems a tad bit too general. Is there a right word that would describe this "systemic idempotence".

答:
Inverse

Mirror

Reverse

Converse

Opposite

Transpose

Complement

Antithesis

Dual


问:
Is there a viable alternative to the agile development methodology?
The two predominant software-development methodologies are waterfall and agile.  When discussing these two, there is often much focus on the particular practices that distinguish them (pair programming, TDD, etc. vs. functional spec, big up-front design, etc.)

But the real differences are far deeper, in that these practices come from a philosophy.

Waterfall says:  Change is costly, so it should be minimized.

Agile says:  Change is inevitable, so make change cheap.

My question is, regardless of what you think of TDD or functional specs, is the waterfall development methodology really viable?

Does anyone really think that minimizing change in software is a viable option for those that desire to deliver valuable software?  Or is the question really about what sort of practices work best in our situations to manage the inevitable change?

答:
To answer the question, is there a viable alternative, for software perhaps not - or not yet, at least in the general case. I think it comes down to the nature of software. Software, being information, can be duplicated for free. Unlike a bridge or a house. This means, with practice, I could get good at building a house and be operating in a relatively simple domain. At which point why not use a one-shot approach?

But because software has zero duplication costs, why would you ever do the same thing twice? Software tends away from manufacturing. So if all software is the creating of new product then we're always operating in a complex domain where, to some extent, we don't know what we're doing. Or it's expensive to know up front and it's cheaper to find out by doing. In a complex, risky domain, I'd want to try experiments and increment and iterate.

Nuclear power stations and fly-by wire systems are often given as examples of software you'd want to do waterfall. But wasn't the shuttle avionics system developed iteratively? As was the Canadian and US air traffic control systems?

And if OPEN/Metis is iterative and incremental then, for me, it sounds like it has the agile philosophy even if it doesn't associate itself with other common agile practices.


问:
Version Control with SQL Server
I'm starting a new project and using SVN (with Tortoise) as my Version Control System. I was wondering if it was possible to also maintain a SQL Server Database using the same system.

I'd want to version my tables/functions/views/procs/triggers/etc. but not my data as it's all going to be test data anyway. I'm not really sure how to set this up. I've come across a few options but I would like to know if there were any I was missing, and if there's maybe a guide or something out there to help me get running with it.

I've seen and heard of Red Gate, but I'm looking for something free (or at least very low cost). I know I could always write something myself, but I'm not really trying to spend time on that.

One thing I did come across was an open source package put together called ScriptDB4Svn. Has anyone used this before? Is it good? Can it do the things I need it to do and is it pretty simple to get setup?

答:
Yes, I've used a similar tool (developed in-house) on a previous project. It would script all tables, views, sprocs, triggers, etc into individual .sql files. Then, we had a script that ran every night to "validate" that everything in our "development" database was reflected in source control.

So the normal workflow is that you'd change your code, change the corresponding tables and sprocs in the development database as required, then you would run the tool we had which would refresh all of the scripted .sql files. You'd then check everything in at once.

The problem was that if you forgot to run the tool, the code would "work" (and unit tests would pass) because the database was "correct", but the new sprocs/tables wouldn't be source control.

So every night, we have a script which did a checkout of the source code, then rand the tool to refresh all of the scripts. If there was any difference, it means someone forgot to check in their changes and an email notification was generated. It was basically just a way to make sure we didn't forget to keep the source control up to date.

It was a bit annoying because it made it hard to work on changes that spanned multiple days, but it was better than having nothing...

Title: Version Control with SQL Server


答:
You can use Rails.  Rails has a concept of database migrations which you can apply or roll back.  In my experience this is the best way to version a database.  You do check these migration files into SVN.

In my current project, we're not developing the application in Ruby, but we're still using Rails to manage the database.  I wouldn't do it any other way.

Title: Version Control with SQL Server

Body:
I'm starting a new project and using SVN (with Tortoise) as my Version Control System. I was wondering if it was possible to also maintain a SQL Server Database using the same system.

I'd want to version my tables/functions/views/procs/triggers/etc. but not my data as it's all going to be test data anyway. I'm not really sure how to set this up. I've come across a few options but I would like to know if there were any I was missing, and if there's maybe a guide or something out there to help me get running with it.

I've seen and heard of Red Gate, but I'm looking for something free (or at least very low cost). I know I could always write something myself, but I'm not really trying to spend time on that.

One thing I did come across was an open source package put together called ScriptDB4Svn. Has anyone used this before? Is it good? Can it do the things I need it to do and is it pretty simple to get setup?


答:
Technically you don't even need a tool, you can script the objects directly and check them into source control. It is a bit more work without the tool, but it is definitely workable.

BTW: I've used the RedGate tool and it is pretty slick and worth the money.

Title: Version Control with SQL Server


问:
Make a big deal out of == true?
There is a colleague of mine who constantly writes:

```<code>if (someBool == true)
</code>```

It drives me up the wall!  Should I make a big deal of it or just drop it?

答:
I write code like that!

Here is why:

"if bla == true" reads like a sentence, where as "if bla" does not in many cases. It just sounds wrong, when READING actual code.

Also the compiler warns about assignments in if blocks, so there is really no danger in using == true. (confusing it with =)

Also do guys that don't write "== true", use that "!()" for "== false"? I find it really ugly. And if you use "== false", it is only very consistent to also use "== true", instead of having two distinct ways of verifying truth.

ContentLicense: CC BY-SA 2.5

Title: Make a big deal out of == true?


问:
The case for code obfuscation?
What are the top reasons to write obfuscated code, in terms of a real benefit to the people developing the code, and the business that runs that code (if the code in question is in fact commericial code)? Are there documented cases (available online in some location) which describe when obfuscation did more good than bad? Are there well-known examples where, for example, obfuscation was proven to meaningfully delay a malicious 3rd party from getting at the code? It seems that, just like rolling up your car windows won't stop people from breaking them and stealing your stereo, obfuscating your code just keeps honest people honest.

=========

Background:

This is an attempt to purposely challenge my assumptions on this topic.

I'm big-time against using code obfuscation in general, but I'm curious if I'm missing something. I get why, in cases like JavaScript, minification helps things load faster and all (there's a real, functional benefit there), but I can't seem to come up with a single reason why code obfuscation, for the purpose of being an obstacle to discovering what an section of code/algorithm does, is actually effective for any purpose whatsoever.

With open source being crazy popular, the question seems to be "share the code, or keep it proprietary?" When it comes to commercial code, I can understand why you can't share everything, and you've got the law in your side to fight theft.

BTW, if the reason someone is writing obfuscated code is "job security"  then I would fire any programmer found to be consistently, and purposely using obfuscation with the sole purpose of helping to keep their jobs, unless they could reasonably show that it had some business benefit. It's so completely anti-team that it's ridiculous, and points to someone that's more concerned with keeping their job through misguided practices, then keeping it because they write awesome software.

I only mention this specific case because, while I realize people are usually joking, I'd like to deter any answers whose basic thrust is that obfuscation for job security alone is a good idea.

答:
The case for code obfuscation is that it raises the bar for a 3rd party to determine what/how the code is working.

However, that does NOT mean that a developer should ever be writing obfuscated code.

See, this is the bit I think is missing from your question: Code obfuscation (just like JavaScript minification) does not need to - and should not - be done manually by the developer. Likewise, this should not be stored as your core source files in version control either.

Code obfuscation should happen as a post processing step during compilation into your production build. There are plenty of 3rd party products to do this as well, so there is almost no reason to do this in house.

For example: Dotfuscator

The IEEE has a paper on the effectiveness of code obfuscation

Results show that identiﬁer renaming signiﬁcantly decreases the
efﬁciency of attacks, at least doubling the time needed to complete a
successful attack (even in the worstcase scenario, i.e., against the
best attacker). In addition, obfuscation reduces the gap between
novice and skilled attackers, making the latter less efﬁcient, and
makes systems that are easier to attack in clear more similar to those
that are intrinsically harder to break.

Emphasis mine.

Title: The case for code obfuscation?


问:
Is there such a thing as feature bloat?
I have come across the expression software/feature bloat, but is this a real thing or should we rather be talking about things like performance problems, memory and disk footprint, user experience and on-demand installation? What am I missing here?</p>

答:
During the late 1990s, Microsoft Excel had at least three, and I think four,  mutually-incompatible ways to add an "international" currency symbol onto a formatted number, each accessed by its own separate UI.

So, yeah, "feature bloat" certainly does exist.

Title: Is there such a thing as feature bloat?


答:
One very interesting use case for obfuscation is tracing the origin of illicit copies. Assuming that obfuscation is a relatively cheap operation the original author can supply each client with differently obfuscated versions of the application, if an illicit copy is found the author can compare with supplied versions and trace back the source of the piracy.

That's a form of steganography, inspired and in variation of the "traitor tracing" cryptographic schemes. I have no idea if it's common1, or even if it's a good idea, but I've seen it applied in practice under the following parameters:

Highly competitive nationwide market with just two vendors,

About 50 deployments covered the market,

Average development time for both applications was a couple of years (more or less),

Average obfuscation time for our application was a couple of hours,

Lifespan for both applications was expected to be about ten years.

The rationale was of course security through obscurity initially, and it evolved at the aforementioned scheme at some point2. Both vendors had access to each other's binary code, legally, and I think it's obvious that decompilation attempts from both were expected. Obfuscation did nothing in terms of security, in the long run. Both vendors had highly motivated and talented teams, working in an extremely profitable and niche market, in the end our products were more similar than not, and any competitive advantage was gained through other, less obscure means.

I can't really expand, because (a) it was very early in my career and I didn't get a clear overview of the design decisions or the results of the tracing scheme (if any) and (b) some of my involvement with the project was under a NDA.

Another valid use case for obfuscation could be when you are somehow legally obliged to submit your code to a third party:

If your firm does IP work for technology companies, or is involved in cases involving software source code, you may be obliged to submit your client’s source code to the USPTO, a court or third party.

Since source code is considered a trade secret, most regulatory agencies use a "50%" rule. Source code submitted is obscured so that it cannot be used as-is.

IANAL, and the link is more relevant to hard copies of code rather than actual working code, so this might be completely irrelevant.

Now, as Javascript is the canonical example for obfuscation, there's one side-effect that's not commonly considered, and that's hiding malicious code in obfuscated Javascript. Although there are definite advantages in minifying3 Javascript, I don't see any point in actual obfuscation and I'm happy Douglas Crockford agrees with me:

Then finally, there is that question of code privacy. This is a lost cause. There is no transformation that will keep a determined hacker from understanding your program. This turns out to be true for all programs in all languages, it is just more obviously true with JavaScript because it is delivered in source form. The privacy benefit provided by obfuscation is an illusion. If you don’t want people to see your programs, unplug your server.

As for obfuscation for "job security", that's a behaviour that should never pass code review, and if identified it shouldn't be tolerated. I wouldn't go as far as firing the culprit at first, but repeat offenders definitely deserve a good spanking, at least.

In conclusion, obfuscation is a typical example of security through obscurity, it's only obvious merit is as a deterrent and nothing more. There might be creative use cases4 I don't know of, but in general the benefits are minimal, at best.

1 After writing this I found out this answer which basically describes the same scheme, so it might be more common that I thought.

2 Although steganography is still security through obscurity.

3 Minification ~ removing whitespace and shortening tokens, not intentionally obscuring.

4 Does the International Obfuscated C Code Contest count?

Title: The case for code obfuscation?

Body:
What are the top reasons to write obfuscated code, in terms of a real benefit to the people developing the code, and the business that runs that code (if the code in question is in fact commericial code)? Are there documented cases (available online in some location) which describe when obfuscation did more good than bad? Are there well-known examples where, for example, obfuscation was proven to meaningfully delay a malicious 3rd party from getting at the code? It seems that, just like rolling up your car windows won't stop people from breaking them and stealing your stereo, obfuscating your code just keeps honest people honest.

=========

Background:

This is an attempt to purposely challenge my assumptions on this topic.

I'm big-time against using code obfuscation in general, but I'm curious if I'm missing something. I get why, in cases like JavaScript, minification helps things load faster and all (there's a real, functional benefit there), but I can't seem to come up with a single reason why code obfuscation, for the purpose of being an obstacle to discovering what an section of code/algorithm does, is actually effective for any purpose whatsoever.

With open source being crazy popular, the question seems to be "share the code, or keep it proprietary?" When it comes to commercial code, I can understand why you can't share everything, and you've got the law in your side to fight theft.

BTW, if the reason someone is writing obfuscated code is "job security"  then I would fire any programmer found to be consistently, and purposely using obfuscation with the sole purpose of helping to keep their jobs, unless they could reasonably show that it had some business benefit. It's so completely anti-team that it's ridiculous, and points to someone that's more concerned with keeping their job through misguided practices, then keeping it because they write awesome software.

I only mention this specific case because, while I realize people are usually joking, I'd like to deter any answers whose basic thrust is that obfuscation for job security alone is a good idea.


答:
Inverse function is the mathematical term.

As much of Computer Science is based upon the discipline of Mathematics, I suggest you use that.

Title: What do you call a pair of function that are complements of each other?

Body:
I am looking for the right word to describe a function and its complement.

Here I am looking for the proper word to describe a couple of functions when applied in sequence the system reverts to its original state.

Marshalling and Unmarshalling would be a subset of this

Add and Remove

Idempotence comes to mind though I am not sure if it can apply to more than one operation.  Reversible could also do, but it seems a tad bit too general. Is there a right word that would describe this "systemic idempotence".


问:
Should I put calculation logic in an Entity or in the Business Layer?
Recently I was faced a question about whether a simple calculation should be put in the Entity layer, or should the Entity be pure for just storing the raw data and leave the calculation logics in the business layer.

So my question is whether it is sensible to encapsulate simple calculations in the properties in an entity class?

答:
Well, Entity and business Objects are almost same, most of the time. For example if you have a product class and you want to expose a property which takes some existing property in product class and does some calculation and then exposes it. Its fine in the term that, the logic of creating that property remains with the class.

Now, the question may come, where to fit your business layer class. I prefer using business layer class which has some logic to deal with business problem. For example in your Product example, a business problem could be charging money using third party vendor like paypal.

One key thing to remember is an Entity would always have an identity but a business object are entity with out an identification. For example product is an entity but money would not have an identity. 1000 different instances of money would be same.

OwnerDisplayName: Katat

OwnerDisplayName: Anand


答:
It depends on the type of architecture you want.

In Domain Driven Design, you would create a Domain Model that would have both data and functionality.

This would mean that an Order has a property (or method) that would return the total price of the order based on the OrderLines. The Order would also have a method AddOrderItem(Product product, int amount) and the Order would check if there is already an OrderLine for that specific product.

In such a model you would also have objects that are not real entities, like a Repository for accessing data or a Factory for creating entities. These are called Domain Services. An Application Layer is responsible for calling the Domain Services (for example to retrieve an entity from the database) and then it will execute functionality on the entity. The Application Layer should be as thin as possible.

This is a nice article about DDD which explains these concepts in more detail.

You can also use an Anemic Domain Model. That means that your entities consist of get/set properties and contain no behavior. In such a design, your Business Layer will contain the behavior, such as calculating the Order price and checking for duplicate OrderLines.

There are different opinions whether an Anemic Domain Model is a bad thing. Personally I prefer a real Domain Model.

This article describes the differences between an Anemic and non-Anemic Domain Model.

Title: Should I put calculation logic in an Entity or in the Business Layer?

Body:
Recently I was faced a question about whether a simple calculation should be put in the Entity layer, or should the Entity be pure for just storing the raw data and leave the calculation logics in the business layer.

So my question is whether it is sensible to encapsulate simple calculations in the properties in an entity class?

OwnerDisplayName: Wouter de Kort


答: Friend of mine proposed reciprocal (reciprocity)</p>


问:
How do I learn Python from zero to web development?
I am looking into learning Python for web development.

Assuming I already have some basic web development experience with Java (JSP/Servlets), I'm already familiar with web design (HTML, CSS, JS), basic programming concepts and that I am completely new to Python, how do I go about learning Python in a structured manner that will eventually lead me to web development with Python and Django?

I'm not in a hurry to make web applications in Python so I really want to learn it thoroughly so as not to leave any gaps in my knowledge of the technologies involving web development in Python. Are there any books, resource or techniques to help me in my endeavor? In what order should I do/read them?

UPDATE:

When I say learning in a structured manner, I mean starting out from the basics then learning the advanced stuff without leaving some of the important details/features that Python has to offer. I want to know how to apply the things that I already know in programming to Python.

答: If Web development in python is what you are looking for, then after a thorough understanding of python , I suggest that you have a look at Flask. Django and other full stack frameworks would definitely make your life much much easier but overall would leave you with an incomplete feeling as if you have not learnt much. Flask IMHO , is the most awesome framework in python as of now, but yes that is just my opinion.</p>


答: I would use inverse or isomorphism. In that order.</p>


问:
Rate your programming language expertise by language concepts
I am looking for a good way to rate the expertise in a particular programming language. The idea arose when I found the following article: Taking falsely all the credits? You don't know JavaScript. It lists, in a comprehensive way, language features and concepts of JavaScript. I wish there would be a list for every programming language. In particular I would be interested about:

Java

C

Python

C# / .NET

C++

JavaScript

Any other language or technology would be also interesting. In a similiar question What's a good way to rate your own code skills the Programmer Competency Matrix was suggested. I think it's a good approach, but I think it's too generic.

Do you know any other summaries of language concepts which could help to rate the programming language expertise?

答:
For evaluating the .Net Programming expertise, Scott Hanselman's gives guidelines on the know-how required for various positions in a .Net Development Scenario.

Everyone who writes code

Mid-Level .NET Developer Senior

Developers/Architects

C# Component Developers

ASP.NET (UI) Developers

Developers using XML

The knowledge acquired from these questionnaires would definitely help overcome obstacles.

Please find the details explained here.


答:
From what I have experienced, people mostly use "waterfall with iterations' as a derisive term  for poor or half-hearted agile implementations and not as a practical methodology.

Anyway I came across this article which has a decent explanation of the term "Iterative Waterfall".

Title: What is the difference between waterfall model with iterations and evolutionary software development model?

Body:
Does anyone know the difference between those two? </p>

<p>They are both created by iterative approach - giving successive revision after each iteration. They both have the initial idea->analysis->(outline)design phases. </p>


问:
Need licensing recommendations for in-house written software
Currently I do a lot of development on my free time to improve my productivity at work. I've got around 50 man hours of unpaid work into a few pieces of software, but I'd rather not have them end up on work computers until they're licensed to prevent redistribution without my permission. Of course, I'm not charging them or anything. I just want to make sure I'm protected legally in the event they decide to try and package it and sell it as their own. I made sure before starting that I didn't sign any agreement that they own everything I work on for the remainder of the time I spend at this company.

I would like an in-house licensing solution. IANAL, so writing a license wouldn't be the best thing I could do. Are there any free, copy-pastable, licensing solutions (copy-pastable in the way the GPL is copy-pastable) that explicitly prevent redistribution without my permission?

答:
Every large company I've worked for has put an intellectual property rights clause in my contract. In all cases this has said that any IP I create is automatically owned by them if it's made during my time at work, or outside of work but solves problems for their business. This is usually in addition to time-limited non-compete clauses.

Depending on where you live this may also be a part of your local employment law. I live in the UK and have never checked the local law, but it's been in all my contracts all the same.

So check both your contract and your local laws before proceeding.


答:
It sounds like you have a mostly Microsoft setup. You could have a look into Database Projects (previously known as DataDude). They basically turn T-SQL into a first-class language in Visual Studio; you can:

Compile projects - it does not merely create a final script, it makes sure object names etc. exist.

Perform static code analysis - for example, ensuring that you always refer to objects by including their schema (e.g. [dbo] in most cases) for that nice 30% performance boost.

Create diff scripts by having it compare different versions of the project.

Update your project from a database or script (reverse engineer).

Intellisense.

There are no diagramming tools.

They unify your code and your database code nicely under source control as well. If you man-up and script your database objects (instead of using Davinci Tools in SSMS) you also land up using one IDE - which is nice.

Title: Version Control with SQL Server


答:
This has been discussed before on stackoverflow: https://stackoverflow.com/questions/2750278/sql-server-2008-create-database-script-schema-data-with-command-line

Also, this external article provides some additional information http://www.sqlteam.com/article/scripting-database-objects-using-smo-updated together with sample code in the form of a Windows Application.

Since what you want to do is something that I have done by myself for MS Access, I will tell you what I have done in case it gives you some ideas: I have written a module called Ado2Xml which converts the schema and data of any ADO-accessible database to xml, and back. It only knows about tables and views though; no stored procedures, no triggers, no nothing. Anyway, in your case this module gets replaced by the tool that you will presumably find which does what you want with MS-SQL. So, every time my application launches, it compares the timestamp of the database against the timestamp of the saved xml file; if the xml file is more recent, then it destroys the database and invokes Ado2Xml to re-create it from the xml file. When my application terminates, it does the reverse: it invokes Ado2Xml to export the database into the xml file. Actually, the ADO objects that extract the database schema are for some reason awfully slow, causing the exporting process to take some time. So, in order to avoid having to wait each time for my application to terminate and visual studio to switch from the debugging layout to the editing layout, right before it terminates my app launches an external app to do the exporting, so that it can terminate immediately.

Title: Version Control with SQL Server


答:
Personally, I strongly dislike the way to say "not" in C based languages.  That little exclamation mark is too easy to overlook.

Hence I write it out in full:

```<code>if (someCondition == false) {
</code>```

After reading that for a while, I want symmetry too with

```<code>if (someCondition == true) {
</code>```

So consider it an artifact of C using ! instead of not.

Title: Make a big deal out of == true?

Body:
There is a colleague of mine who constantly writes:

```<code>if (someBool == true)
</code>```

It drives me up the wall!  Should I make a big deal of it or just drop it?

Body:
Personally, I strongly dislike the way to say "not" in C based languages.  That little exclamation mark is too easy to overlook.

Hence I write it out in full:

if (someCondition == false) {

After reading that for a while, I want symmetry too with

if (someCondition == true) {

So consider it an artifact of C using ! instead of not.


答:
Iterative Waterfall could also mean to simple break down a large projects in milestones and call each milestone an "iteration".

To do this of course is sin since it removes all possibility of review or feedback from previous iterations into the next.  Yet I have seen it applied after which their protractors proclaimed high and loud they were now Agile for doing so !!

Another definition of iterative waterfall is to have successive waterfalls where the next feeds from the previous.  Again no feedback during the cycle itself from design to delivery but only between delivery and design is feedback allowed.  This definition seems to match the link provided by DPD.

My personal definition of "Waterfall" style and "Agile" style processes lies in how the project is viewed and broken down.  Both pretty much cover the same phases and though processes but tackle them in a much different way.  If you view the production of a software as a stack with Inception at the top and deployment and support at the bottom.

Waterfall will break down the software creation process horizontally and traverse each layer in sequence.  For a waterfallist (if such thing can be said) proceeding to the next layer is impossible without having completely worked out the layer above, its just inconceivable.  Typical argument would be that you never build the roof of a house before the foundation and will say things akin to "measure twice but cut once".

Agile on the other hand will break down the creation process vertically producing slices of functionality that get added to the product over time.  with each slices however they do not proceed through the stack from top to bottom but tackle it all at once.  They are able to do this because they have willingly reduced the scope of the target result.  To them it is inconceivable to proceed without testing first to see if the idea makes sense.  With each iterations they add slivers of functionality and test it against the idea and against the rest of the system.

Waterfall is rooted in engineering where the target is a tangible real life product and error is not admissible.  They see software as rigid pieces of steel and concrete that must be assembled into a structure.  Therefore they will tend to be over cautious planing everything minutely wasting resources on the altar of perfection.  For Waterfall to work you need very strong experienced players and a complete trust in them, you need to be extra meticulous at every step of the way in foreseeing what could be and anticipating.

Agile is rooted in the scientific process where knowledge is gathered one bit at a time and tested continuously.  They understand perfectly that software is a malleable and can be bent and shaped at will.  They treat ideas as would a researcher treat a theory, that is it stands as long as it agrees with the tests.  Therefore they will tend to continuously reshape their system wasting resources by recreating the same things over and over each time with a slight twist to fit the new variables.  For agile to work you need to continuously evaluate your system as a whole and place it against the new reality.  Measurements and automation are essential in order to gain the most accurate picture possible of the present such that the next step can be taken as a corrective measure towards the ideal path.  Even the ideal path needs to be re-evaluated to make sure that it does indeed points towards the ideal target.

Waterfall Build software to last as-is, static, set in concrete.

Agile grow software, care and tend for it to an ever changing world.

True that software is malleable early on but as it gains size and age it also gains stiffness resisting changes more and more.  In my opinion there is no silver bullet and there tends to be to much religious devotion at the detriment of rational reflection.  That said of the two extremes Agile seems to be the one that takes into account the soft of software.


答:
I have participated in the development of an MMORPG. This involved server logic and client logic. Throughout the many-year-long development of the project, whenever we considered the interface between the client and the server, the rule was that the client ought to be treated by the server at all times under the presumption that it has been hacked. In other words, the server had to be written in such a way that there was no response that could come from the client that would cause the server to fail, or allow the client to cheat.  Still, it was known from the beginning that hackers would inevitably find holes in the system and exploit them in order to cheat. And after a while they did.

Of course, before shipping the client to the great big world out there, we made sure to obfuscate it. We believe obfuscation had the following effects:

It deterred the non-expert hackers from even trying.

It delayed expert hackers in achieving any hacks.

It reduced the number of hacks achieved by expert hackers.

It limited the effectiveness of the hacks.

Most importantly: it caused the hackers to perform more test runs with their hacked clients against our servers before achieving a working hack, which increased the chances of us discovering them by looking for irregular activity in the server logs.

Game accounts of discovered hackers were terminated without a refund, so this made the hacking business costlier and less attractive.

So, due to all of the above, I believe obfuscation had an overall positive effect in our game, and by extension, obfuscation can have an overall positive effect in any piece of software which is liable to get hacked. (For example, software containing copy protection measures.)

The effects that obfuscation had on maintenance were close to none. There were a few places where some inexperienced programmers were making assumptions about the names of identifiers, (they were using reflection,) but once those were sorted out everything was fine. The obfuscation step just became part of the overall build step for the production version of the game, so most of us developers never had to worry about it or have anything to do with it. We already had a tool to view the logs of the game, so we modified the tool to use the association table (mapping obfuscated identifiers to proper identifiers) produced by the obfuscator in order to translate the logs for us on the fly, so we never even had to see any obfuscated identifiers while doing post-mortem examinations based on logs collected from the field.

Title: The case for code obfuscation?


答:
"Evolutionary design" is a general term, covering all design methods that use some sort of mutation/selection mechanism (that is, change - test - reject / accept cycles); "Waterfall with iterations" specifically describes a development process that applies the Waterfall model iteratively.

An informal single-developer process where all development happens on one machine, changes are made ad-hoc as needed, and deployed whenever they are considered 'ready', is certainly an evolutionary design model, but it hardly fits the Waterfall definition, not even in its most relaxed interpretation.


问:
How to keep a big and complex software product maintainable over the years?
I have been working as a software developer for many years now. It has been my experience that projects get more complex and unmaintainable as more developers get involved in the development of the product.

It seems that software at a certain stage of development has the tendency to get "hackier" and "hackier" especially when none of the team members that defined the architecture work at the company any more.

I find it frustrating that a developer who has to change something has a hard time getting the big picture of the architecture. Therefore, there is a tendency to fix problems or make changes in a way that works against the original architecture. The result is code that gets more and more complex and even harder to understand.

Is there any helpful advice on how to keep source code really maintainable over the years?

答:
The only real solution to avoid code rot is to code well!

How to code well is another question. It's hard enough even if you're an excellent programmer working alone. In a heterogeneous team, it becomes much harder still. In outsourced (sub)projects... just pray.

The usual good practices may help:

Keep it simple.

Keep it simple. This applies especially to the architecture, the "big picture". If developers are having hard time to get the big picture, they are going to code against it. So make the architecture simple so that all the developers get it. If the architecture has to be less than simple, then the developers must be trained to understand that architecture. If they don't internalize it, then they shouldn't code in it.

Aim for low coupling and high cohesion. Make sure everyone in the team understands this idea. In a project consisting of loosely coupled, cohesive parts, if some of the parts becomes unmaintainable mess, you can simply unplug and rewrite that part. It's harder or near impossible if the coupling is tight.

Be consistent. Which standards to follow matters little, but please do follow some standards. In a team, everyone should follow the same standards of course. On the other hand, it's easy to become too attached with standards and forget the rest: please do understand that while standards are useful, they are only a small part of making good code. Don't make a big number of it.

Code reviews may be useful to get a team to work consistently.

Make sure that all tools - IDEs, compilers, version control, build systems, documentation generators, libraries, computers, chairs, overall environment etc. etc. - are well maintained so that developers don't have to waste their time with secondary issues such as fighting project file version conflicts, Windows updates, noise and whatever banal but irritating stuff. Having to repeatedly waste considerable time with such uninteresting stuff lowers the morale, which at least won't improve code quality. In a large team, there could be one or more guys whose main job is to maintain the developer tools.

When making technological decisions, think what it would take to switch the technology; which decisions are irreversible and which are not. Evaluate the irreversible decisions extra carefully. For example, if you decide to write the project in Java, that's a pretty much irreversible decision. If you decide to use some self-boiled binary format for data files, that's also a fairly irreversible decision (once the code is out in the wild and you have to keep supporting that format). But colors of the GUI can easily be adjusted, features initially left out can be added later on, so stress less about such issues.


答:
There are several things we can do:

Give one person overall responsibility for architecture. When choosing that person, ensure they have the vision and skill to develop and maintain an architecture, and that they have the influence and authority to help other developers follow the architecture. That person should be a seasoned developer who is trusted by management and who is respected by their peers.

Create a culture where all developers take ownership of the architecture. All developers need to be involved in the process of developing and maintaing architectural integrity.

Develop an enviroment where architectural decisions are easily communicated. Encourage people to talk about design and architecture - not just in the context of the current project, but in general, too.

The best coding practices make architecture easier to see from code - take time to refactor, to comment code, to develop unit tests, etc. Things like naming conventions and clean coding practices can help a lot in communicating architecture, so as a team you need to take time out to develop and follow your own standards.

Ensure that all necessary documentation is clear, concise, up-to-date and accessible. Make both high- and low-level architecture diagrams public (pinning them to the wall can help) and publically maintainable.

Finally (as a natural perfectionist) I need to recognise that architectural integrity is a worthy aspiration, but that there can be more important things - like building a team that can work well together and actually ship a working product.

Title: How to keep a big and complex software product maintainable over the years?

Body:
I have been working as a software developer for many years now. It has been my experience that projects get more complex and unmaintainable as more developers get involved in the development of the product.

It seems that software at a certain stage of development has the tendency to get "hackier" and "hackier" especially when none of the team members that defined the architecture work at the company any more.

I find it frustrating that a developer who has to change something has a hard time getting the big picture of the architecture. Therefore, there is a tendency to fix problems or make changes in a way that works against the original architecture. The result is code that gets more and more complex and even harder to understand.

Is there any helpful advice on how to keep source code really maintainable over the years?


答:
Unit tests are your friend. Implementing them forces low coupling. It also means that the "hacky" parts of the program can easily be identified and refactored. It also means that any changes can be tested quickly to ensure they don't break existing functionality. This should encourage your developers to modify existing methods rather than duplicating code for fear of breaking things.

Unit tests also work as an extra bit of documentation for your code, outlining what each part should do. With extensive unit tests your programmers shouldn't need to know the whole architecture of your program to make changes and use exiting classes/methods.

As a nice side effect, unit tests will also hopefully reduce your bug count.


问:
Resume dilemma for professional job
On my resume, I list myself as having "7 years of hands-on experience programming in C".

To clarify, I am a self-taught C programmer with some college courses thrown in the mix. I've worked on some small personal projects, and I consider myself to be more competent than a Computer Science grad with no actual real-world experience, though by no means am I anywhere near being an expert.

The issue is this... I keep getting calls and emails from recruiters that see my resume on job sites, inquiring about my interest in senior developer positions, contracts, etc., of which I feel that I am completely under-qualified for. My resume only has 3 years of work experience listed (which is all IT stuff), so when they ask about my prior experience in C, I have to clarify that it was personal work, not professional work.

I'd really like a job as a developer, but I don't want to get hired for something that I can't handle, nor do I want to misrepresent myself while trying to show off my strengths. I deliberately chose the phrasing "hands-on" to imply that it wasn't professional. How should I phrase my C experience on my resume to clarify it better?

答:
worked on some small personal projects, and I consider myself to be
  more competent than a Computer Science grad with no actual real-world
  experience, though by no means am I anywhere near being an expert.

Just say that. It's best to be completely honest and open with your CV - even if most other people aren't! Just my personal opinion. If you say this then when your CV hits a desk of an employer they'll be able to make an informed decision and you won't be wasting their time or yours.

I'm afraid that recruitment agents however, rarely if ever read what you write, most just do a keywords searches and then email or call based solely on keyword hits. They then waste your time asking you about your CV rather than reading themselves. They are glorified telemarketers and just like telemarketers, waste 99% of peoples time. You are better off approaching companies directly.

Title: Resume dilemma for professional job


问:
Programmers' concerns about export restrictions from the United States
Which aspects do I need to consider when designing and publishing software that must meet the US export restrictions for cryptographic software?

Wikipedia says that there are various categories which you can assign to cryptographic software. And the export destination (e.g. China, Russia) does play a major role as well. But I didn't really understand those restrictions and their effect on my work.

Can anybody explain that to me?

I'm asking because if you try to publish your application (e.g. on Apple's App Store or Android's Market) you have to assure that your application meets the US export restrictions. And there are lots of applications who offer secure information storage, e.g. for passwords.

Have they all notified the government and asked for a review? Of course, you cannot know if they did. But do they need to do this?

答:
If this is just a question for interest's sake, then the other answers are great. If it pertains to something you are actually doing?

GO SEE A Lawyer. NOW.

Are you still waiting? Then I'll expand.

Go see a lawyer. Now. Don't wait, don't think. If you don't have one already, find one. Ask them to put you in touch with someone who handles business law as a job. Check his credentials, and if they look right, sit down with that person and offer them money for advice. Feel free to negotiate on terms.

If you don't trust me, and I'll admit I'm being very definite without much experience in this area, read this article, written in May 2010, by someone who's been successfully running a family business since '93.

If you are trying to run an Indie game business, you are, first and foremost, running a business. All local, state, and federal laws apply. You need a business license. Or licenses. Every business should have a lawyer and an accountant. I personally have done without having a dedicated lawyer on tap (an unwise course), but every business should have a skilled accountant.

What this means is that someone whose business comprises two people selling games where lizards in armour beat up goblins is aware he's taking a risk by not having access to his own personal lawyer at all times.

Are you a business? Don't know. If you're selling something, you could well be. Guess who would know? A Lawyer.

You don't have to pay for a very expensive lawyer for a long time, but at the very least you need to have someone available by appointment who you can run things by before doing stuff that may be legally dangerous, and who can explain to you what may be legally dangerous.

Because here's the thing. If you do it up front, then many things apply.

You're less likely to screw up and attract the attention of the govt.

You're more aware when you have screwed up, and what to do about it, including an existing contact you can call to help you.

If you do screw up and attract the attention of the govt, you can explain that you tried to do everything right, and have the notes from the lawyer to prove it.

If you don't? Well, I recently discovered that if you are aware that you're not competent to handle something, and you don't seek advice, that legally means you deliberately chose to screw up. In money, that's fraud. In export sanctions, I think it's on the same scale as treason.

Regarding internet research: This blog post was written in Jan 17 2011. And the first thing it says in there? That this stuff changed recently. So it could change again. It could already have changed. Which means that if someone blindly follows this 3 years from now, they could end up having to spend some serious time explaining to besuited men that they're not a traitor, they're just daft enough to think that blog posts are legal documents.

Do me a favour for my own peace of mind. Go see a lawyer.

OwnerDisplayName: Marco W.


答:
Everybody here is quick to mention code rot, and I completely understand and agree with this, but it still misses the bigger picture and the bigger issue at hand here. Code rot doesn't just happen. Further, unit tests are mentioned which are good, but they don't really address the problem. One can have good unit test coverage and relatively bug free code, however still have rotted code and design.

You mentioned that the developer working on a project has difficulty implementing a feature and misses the bigger picture of the overall architecture, and thus implements a hack into the system. Where is the technical leadership to enforce and influence the design? Where are the code reviews in this process?

You are not actually suffering from code rot, but you are sufferring from team rot. The fact is that it shouldn't matter if the original creators of the software are no longer on the team. If the technical lead of the existing team fully and truly understands the underlying design and is any good at the role of being a tech lead, then this would be a non-issue.


问:
Automatically update copyright date range from git?
As I write, we're 10 days into 2012.  I bet many programmers are editing the copyright string at the top of their source files to something like:

```<code>// Copyright 2008, 2010-2012 Some Company Unlimited
</code>```

Your version control system knows when files were modified so surely it can help write or rewrite these strings.  So my question: is there a script that can examine git logs for each file and output (or better insert) a string like that about?

I'm using git so that's of primary interest but do let me know if such scripts exist for other systems.

Update:

We need a script that does this:

Walks all source files in our working copy

Locates existing copyright string and identifies years e.g. 2007,2009-2011 would be {2007, 2009, 2010, 2011}

For each year that is not mentioned, diff between 1 Jan and 31 Dec (or today if current year).  Examine diff and decide if it's worthy of a mention in the copyright string

Insert new copyright string.

答:
TL;DR

Don't worry! Your copyright over the project won't expire if you didn't update the year in time! You are safe - it doesn't work that way.

Long version:

I'm pretty sure that all year numbers in the copyright notice indicate the start of copyright not the range. If you add a year it means the continuation of the start, not end. You use it if you add new content (like new modules) to indicate the starting year for that new content only. It is optional but should be used for large changes, like whole new modules or a complete design makeover.

The copyright should expire after fixed number years (which depends on the laws in your country) after the last year in your notice.

So, I don't see a reason to busily update source headers at all.

EDIT:

The thing is that usually changes which are substantial enough involve completely new source files or a re-implementation of old ones. So, as long as you always use the current year in the headers of new source files you're fine. There is no need whatsoever to pass through every single file to make the update. Actually, the only thing that requires a manual change is if you have date range in the licence text itself or in readme file.

Disclaimer: I am a programmer, not a lawyer.


答:
No, git does not know when files were modified.

Git commit object simply define the content of all files at specific point. The same content may easily appear in another commit, even unrelated one. There is nothing to make one of them more important. So the answer might be ambiguous, though it often won't.

Title: Automatically update copyright date range from git?

Body:
As I write, we're 10 days into 2012.  I bet many programmers are editing the copyright string at the top of their source files to something like:

```<code>// Copyright 2008, 2010-2012 Some Company Unlimited
</code>```

Your version control system knows when files were modified so surely it can help write or rewrite these strings.  So my question: is there a script that can examine git logs for each file and output (or better insert) a string like that about?

I'm using git so that's of primary interest but do let me know if such scripts exist for other systems.

Update:

We need a script that does this:

Walks all source files in our working copy

Locates existing copyright string and identifies years e.g. 2007,2009-2011 would be {2007, 2009, 2010, 2011}

For each year that is not mentioned, diff between 1 Jan and 31 Dec (or today if current year).  Examine diff and decide if it's worthy of a mention in the copyright string

Insert new copyright string.


问:
How do I go about choosing a development lifecycle model model?
Based on this question about alternatives to the agile philosophy and its answers and comments I thought it might be useful to discuss what goes into the decision of what "methodology" to use when at the start of the project.

Seems the consensus is that if what you are building requires exact specifications that waterfall is the way to go over agile. That seems to leave a HUGE space for agile development. Beyond "this is how are shop develops software" are there questions or "indicators" at the early planning stage that might give a better indication of what might work best for the client/project?

Like with languages the idea is best tool for the job so as professional developers what do you do to make sure you're using the correct development methodology for a project you're about to start?

Is it really as cut and dry as "if it's a bridge or nuke reactor type project use waterfall else use agile?

I am a self taught programmer working for company that gives a lot of flexibility and they put a lot of trust in me so this kind of question is important to me. I want to make sure I am addressing my work/projects in the most efficient cost/time manner as possible.

答:
It has a lot less to do with development methodologies being dominated by two schools of thought.  It would be like asking if there is a difference between "Stiff, unbending, and rigid" vs. "Loose, flexible and ever changing".  They are black and white, with an infinite variety of differing shades of gray.

Further within Agile there are a number of different templates to choose from Sources: Wikipedia:

Agile Modeling

Agile Unified Process (AUP)

Dynamic Systems Development Method (DSDM)

Essential Unified Process (EssUP)

Exia Process (ExP)

Extreme Programming (XP)

Feature Driven Development (FDD)

Open Unified Process (OpenUP)

Scrum

Crystal Clear

Velocity tracking

Notice that I said Templates, because in reality every organization has unique needs that must be tailored to, and one of these templates can provide a good starting point.  If this isn't enough choice for management to make the move to a sane and realistic method of software development that is grounded in reality then they are just dithering and paying lip service to the thought, and would go so far as to say that they are less concerned with writing quality software that fits the customer needs than they are about maintaining the illusion of firm and total control over their process and people.


答:
First, it's not a choice of waterfall or agile, but plan-driven versus agile. There are many plan-driven methodologies to choose from. The other prominate plan-driven methodology is Boehm's Spiral Model. It's iterative development, but it's not (necessarily) incremental. I asked a question about other plan-driven methods, and the other one that was indicated was Cap Gemini SDM.

When you are deciding between a plan-driven methodology and an agile methodology, there are a number of factors to consider. In Rapid Development: Taming Wild Software Schedules, Steve McConnell has an entire section devoted to chosing a lifecycle model. He looks at a number of lifecycle models - pure waterfall, code-and-fix, spiral, modified waterfalls, evolutionary prototyping, staged delivery, evolutionary delivery, design-to-schedule, design-to-tools, and COTS software. Each is discussed in depth, and assessed on its ability to cope with poorly understood requirements, to produce a reliable system, to manage risk, to fit within a constrained schedule or budget, to provide visibility to customers and/or management, and the sophistication of the team.

So, yes, one consideration is the type of project that is being delivered. But there are numerous factors and many lifecycle models that can be chosen from.

Title: How do I go about choosing a development lifecycle model model?

Body:
Based on this question about alternatives to the agile philosophy and its answers and comments I thought it might be useful to discuss what goes into the decision of what "methodology" to use when at the start of the project.

Seems the consensus is that if what you are building requires exact specifications that waterfall is the way to go over agile. That seems to leave a HUGE space for agile development. Beyond "this is how are shop develops software" are there questions or "indicators" at the early planning stage that might give a better indication of what might work best for the client/project?

Like with languages the idea is best tool for the job so as professional developers what do you do to make sure you're using the correct development methodology for a project you're about to start?

Is it really as cut and dry as "if it's a bridge or nuke reactor type project use waterfall else use agile?

I am a self taught programmer working for company that gives a lot of flexibility and they put a lot of trust in me so this kind of question is important to me. I want to make sure I am addressing my work/projects in the most efficient cost/time manner as possible.


答:
Is it really as cut and dry as "if it's a bridge or nuke reactor type project use waterfall else use agile?

Yes.

Actually it is that simple.

The point of Agile is to fit the process to the problem being solved.

The point of Waterfall is a (partly false) analogy between construction trades and software design and development.  Construction (design everything first, build everything second) doesn't apply very well to software, because software is almost entirely a design exercise.  There's little in software development that parallels conventional building or manufacturing.


问:
Too many seniors in one team?
Can having too many senior programmers in one team turn out to be a bad thing?

Having like say, 4-5 senior programmers in a team of 6-7 people.
What is the optimal number/ratio in these kind of situations?

Can this lead to too much philosophy and arguments about ideas?

Has anyone had such an experience, that can share it with me?

答:
I worked in a team where there were 1 lead developer, 4 senior developers, and 1 middle developer. And because of the reason that one "senior" member of the team was not a really mature person (good developer though), it turned out to be a nightmare. He tried to prove  all the time (implicitly or explicitly) that other team members are not senior enough. Also he failed to understand basic principles of software development and specifics of our product, and, therefore, arrogantly and stubbornly tried to prove that he's right. As a result, it seriously affected effectiveness of the team. The sad part is that it even was not too much argument about ideas/solutions - it was argument about nothing. For example:

who broke the build (which most of the time was green and, technically, wasn't broken. it was UI which failed to work properly very often due to the poor architectural solutions)

why there are regressions (modules were not covered by unit-tests which we didn't have access to contribute to)

arguing over architectural solution in module which is somebody other's responsibility knowing nothing about module requirements and specifics.

...

But I admit it was rather an exception. I want to believe that seniors behave properly most of the time :)

Title: Too many seniors in one team?


问:
How to approach web app development?
I have been going through Flask and it seems that now I have a decent understanding to go ahead and build a web application. However I want to know how would I approach the problem. For eg: I decide to build a blogging application. The first thing I do is write down all the things that come to my mind, from user registrations to posting data on the blog to publishing it on the site

But after that I just get into coding. I know that is not the right approach. I have heard of UML diagrams, workflow diagrams and stuff. It would be great if someone could just outline the steps they would follow for building a large application and then I could go ahead and learn more about them.For eg,it could be something like the below:-

Collect requirements

Draw UML diagrams

Draw workflow diagrams

Start coding

Please suggest an exhaustive list so that I can make my approach much more systematic. Thanks

答:
Drop the diagrams for now, and only use them if/when you feel the need.

Look into value-driven development as the overall approach and TDD for the specifics.

Begin by creating a bunch of stories. For instance, if creating a blog web site, the first step would probably be "user should be able to write a simple blog entry" followed by "user should be able to display his blog entry" etc.

Next, pick the most valuable story using this question as guideline: if you had to release today, what would be the single most valuable functionality?

Then, break the selected story into small technical tasks such as "Create a html form", "Write back-end for submits" etc which can be completed in a few hours.

Now:

Pick the next task

Write a unit test for it

Make the test pass

Refactor code

Not satisfied? goto 2

Release it and/or goto 1

Make sure to use small incremental steps and keep your system working after each iteration so you don't get stuck in analysis paralysis.

This is just scratching the surface of course, but it should get you going I think.

Title: How to approach web app development?


答:
IMHO, Waterfall doesn't suit any development, it comes from the construction industry, where redoing something is impossible (or at least, extremely expensive). But to software, redesigning and rewriting is cheap, and it is extremely preferable to review the specs continuously.

OTOH, Agile requires all team members to have approximately the same experience, and teams should be small, otherwise it adds considerable communication overhead. When the experience levels are disparate, it wastes a lot of time for the most experienced.

The approach I've used most, and which I have experienced as more effective, is to have no defined structure at all.

At first, projects require the most talented and skilled ones you can get, to have good foundations. You generally have nothing else to do, just put this people on the project and wait a few days, soon they will start organizing everything; it's the power of nature.

Just having the right people on the right place does the trick. Look for natural leaders (those everyone hates, yet loves). Once the thing starts to move they will switch into guardian-mode to keep things sane, and it will catch speed.

(Well, I admit there is an implicit structure, but it's highly dynamic)

The point is: development consists almost entirely (from this point of view) in social interactions, something extremely complex and resilient to careless intervention, so any attempt to design social interaction is doomed. The only thing we can do about it is to influence, slightly.


答:
One principle that has not been mentioned but that I find important is the open / closed principle.

You should not modify code that has been developed and tested: any such piece of code is sealed. Instead, extend existing classes by means of sub-classes, or use them writing wrappers, decorator classes or using whatever pattern you find suitable. But do not change working code.

Just my 2 cents.


问:
When practicing collective code ownership, can there be experts of each component?
Consider a complex and extensive software component; for example a multi-language text rendering engine, an IPC framework, a scheduler that can handle multiple time zones, a module full of complexities caused by the need to stay backwards compatible, etc... It requires a lot of knowledge of the details to maintain and extend such a component without introducing bugs with every code change. It is also often helpful to know the bug history when receiving a new bug report. Moreover, it requires thorough knowledge about the component's design to be able to maintain its consistency after future extensions, and it is good to know the rationale behind past design decisions. You might try to document this kind of knowledge, but it would require a lot of time and effort, it would rapidly become outdated and hence untrustworthy. Worse, everybody would still need to keep that written documentation in his/her mind.

It seems to me that for such components, it is best to have someone that has in-depth knowledge, as one cannot thoroughly know and keep up with the code produced by a whole group of people without an excessive communication and learning overhead. I wonder whether the practice of collective code ownership allows for such experts, as it seems to me that it would require some kind of "weak code ownership". And if not: how can it succeed without a massive amount of duplicate work?

答: I think that the notion of collective code ownership is really just trying to combat the diseased notion that "I cannot touch that module, because it is Bob's code":- There does not (to me) seem to be any technical reason why you cannot have collective code ownership (in the sense of everybody being able to modify everything in the repository) AND experts with primary responsibility for a particular library, module or products. The main challenge is one of man-management & organizational psychology; and how one would promote the appropriate attitudes in the development team.</p>


问:
How do I choose a package format for Linux software distribution?
We have a Java-based application that, to date, we've been distributing as a tarball with instructions for deploying. It's mostly self-contained so deployment is fairly straight-forward:

Untar on the disk you'd like it to live on;

Make sure Java is in your path and a suitable distro and version;

Verify ownership and group on all the files

Start up the server processes with our start script

If the user wants to get in to start-on-boot stuff with SysV we have some written instructions and a template init file for it in our tarball.

We'd like to make this installation process a little more seamless; take care of the permissions and the init script deployment. We're also going to start bundling our own JRE with the application so that we're mostly free of external dependencies.

The question we're faced with now is: how do we pick a package format for distribution? Is RPM the standard? Can all package management tools deal with it now? Our clients primarily run RHEL and CentOS, but we do have some using SuSE and even Debian. If we can pick a distro-agnostic format we'd prefer that.

What about a self-extracting shell script? Something akin to how Java is distributed. If we're dependency-free would the self-extracting script be sufficient? What features or conveniences would we lose out on going with the script versus a proper package format meant for use by a package manager?

答:
You should not see packaging as a priority.
Packaging is goal of package maintainers, not original developers.

If you have free HR, you can pick up distributions most vital to you, but not package format!, and provide your software packaged in-house.

Be aware, however, that in that case, you are explicitly required to track all upcoming changes within your chosen distribution and keep them, together with changes to your software, up-to-date. Additionally, downloading precompiled (packaged) software outside of distribution own repository is seen as a security risk. Note, that source-based distributions will still rely upon automatic fetching of source tarball from your site, yet this is done by means of the package manager and is normally check summed.

One of the better choices here is to contact active developer within target distribution of your choice and argument upon assigning him as responsible packager for your software within his distribution. Then, you will only have to mention instructions for installation of your software on specific distribution without any actual binaries, as it will be installed using distribution native package management.

See Play-On-Linux as an example.


问:
How to find Sub-trees in non-binary tree
I have a non-binary tree.

I want to find all "sub-trees" that are connected to root.

Sub-tree is a a link group of tree nodes.

every group is colored in it's own color.

What would be be the best approach?
Run recursion down and up for every node?

The data structure of every treenode is a list of children, list of parents. (the type of children and parents are treenodes)

Clarification:

Group defined if there is a kind of "closure" between nodes where root itself is not part of the closure.

As you can see from the graph you can't travel from pink to other nodes (you CAN NOT use root).

From brown node you can travel to it's child so this form another group.

Finally you can travel from any cyan node to other cyan nodes so the form another group

答:
You could use a BFS algorithm (a graph algorithm explained on Wikipedia), starting from the node you want to make root.

The algorith behaves like this:

```<code>procedure BFS(G,v,btree):
      create a queue Q
      enqueue v onto Q
      mark v
      btree = new Tree(v);//Create a tree structure with v as root
      while Q is not empty:
          t ← Q.dequeue()
          btree.add(t) // Here its where you add elements to your tree
          for all edges e in G.incidentEdges(t) do
             o ← G.opposite(t,e)
             if o is not marked:
                  mark o
                  enqueue o onto Q
</code>```

When Q is empty means you processed all the possible nodes and all of them have been added to your binary tree (btree).

Once you have your btree you can apply any simple algorithm to obtain what you need

Body:
You could use a BFS algorithm (a graph algorithm explained on Wikipedia), starting from the node you want to make root.

The algorith behaves like this:

procedure BFS(G,v,btree):
      create a queue Q
      enqueue v onto Q
      mark v
      btree = new Tree(v);//Create a tree structure with v as root
      while Q is not empty:
          t ← Q.dequeue()
          btree.add(t) // Here its where you add elements to your tree
          for all edges e in G.incidentEdges(t) do
             o ← G.opposite(t,e)
             if o is not marked:
                  mark o
                  enqueue o onto Q

When Q is empty means you processed all the possible nodes and all of them have been added to your binary tree (btree).

Once you have your btree you can apply any simple algorithm to obtain what you need


答:
The way I go about this issue is to snip it at the root:

My explanation will be using terms from the Microsoft/.NET, but will be applicable to any platform/toolbox:

Use standards for naming, coding, checkins, bug flow, process flow - basically anything.

Don't be afraid to say goodbye to team members who doesn't adhere to standards. Some developers simply cannot work within a defined set of standards and will become 5th column enemies on the battlefield to keep the code-base clean

Don't be afraid to allocate lower skilled team members to testing for long periods of time.

Use every tool in your arsenal to avoid checking in rotting code: this involves dedicated tools, as well as pre-written unit tests that test the build files, project files, directory structure, etc.

In a team of about 5-8 members, have your best guy do refactoring almost constantly - cleaning up the mess the others leave behind. Even if you find the best specialists in the field, you will still have a mess - it's unavoidable, but it can be constrained by the constant refactoring.

Do write unit tests and maintain them - do NOT depend on the unit tests to keep the project clean, they do not.

Discuss everything. Don't be afraid to spend hours to discuss things in the team. This will disseminate the information and will remove one of the root causes for bad code: confusion on technologies, goals, standards, etc.

Be very careful with consultants writing code: their code will, almost by definition, be the real shitty stuff.

Do reviews preferably as the process step before checkin. Don't be afraid to rollback commits.

Never use the open/close principle unless in the last stage before release: it simply leads to rotting code being left to smell.

Whenever a problem is encounted, take the time to understand it to the fullest before implementing a solution - most code rot comes from implementing solution to problems not fully understood.

Use the right technologies. These will often come in sets and be fresh: It's better to depend on a beta version of a framework you are ensured support from in the future, than to depend on extremely stable, but obsolete frameworks, that are unsupported.

Hire the best people.

Lay off the rest - you are not running a coffee shop.

If management is not the best architects and they interfere in the decision making process - find another job.


问:
Simulating/developing_a_testing_strategy for factors that might cause the same algorithm to produce different results in Distributed Systems
This is a Purely Academic Question

Context:

I am working with some algorithms which are meant to arrive at a consensus in distributed systems. I intended to tackle Byzantine faults with these algorithms. For this I have implemented several algorithms published in IEEE papers and need a platform to test these algorithms. I wanted to test the merit of existing algorithms. For this I implemented thousands of Linux Containers on my system and now i want to do message passing between them, or say simulate my distributed system. But the question is the data that is flowing must have faults. This is the genesis of this question. Why I need something more sophisticated than RNG's is that I will need to attach some real credibility to my work. I want it to tackle some real world application generating faults rather than just fix the faults I myself generated in an algorithm.

So, I need to simulate the factors that result in Byzantine faults.

OR, to quote FrustatedWithFormsDesigner:
I need to develop a testing strategy that will have a deliberate number of faults to test fault-handling

To Summarize:

Say I am running a program in a distributed environment, then what are the factors that might end up generating Byzantine faults and is it possible for me to inculcate these factors in my simulation and how?

So, what I need is:

A program that will make a small no. of mistakes every now and then, and I should not know what mistakes it has made and when.

I do not need it to make multiple mistakes in one set(run of the algorithm), but rather I plan on making (say) 10,000 runs of the program, and I need it to make mistakes 2000 times ..

Very importantly, I must be sanguine that there are no more than (1/5)n mistakes, where n is the total no. of results generated using the program.

The results that I am talking about here can be anything that is quantifiable and verifiable, like eg. an array of values.

Doing something like this:

```<code>1for(int i=0; i<10000; i++)
2   //one fifth of the times put garbage in the array using random function!!
3   for (int j=0; j<5; j++)
4      array[j]=j;
</code>```

using a RNG in step 2 to hide where the fault is present is too simplistic, trivial and not real enough.

I thought I could use some algorithm built around some mathematical function that is bound to fail 1/5th of the times, But I could not think of any.

P.S.
Please tell me if you need more data to understand the problem.

答:
There are two approaches:

non-random: use a counter, and every 5th run tell the software to make a mistake. It will work perfectly, but it will be predictable.

Random: use the random method/command/function in your language of choice to pick a number between 1 and 5 inclusive. If it is 1 then tell the software to make a mistake. For a low number of runs you might get too many or too few runs with mistakes. For a large number of runs you will get closer to the expected number. You will not be able to anticipate which runs will have errors.


答:
In addition to the other answers, I'd recommend layers. Not too many but enough to separate different types of code.

We use an internal API model for most applications. There is an internal API that connects to the database. Then a UI layer. Different people can work on each level without disrupting or breaking other parts of the applications.

Another approach is to get everyone read comp.risks and The Daily WTF so they learn the consequences of bad design and bad programming, and they will dread seeing their own code posted on The Daily WTF.


问:
What is the most effective work rhythm for a programmer?
I was wondering what is the best work rhythm for the job a programmer does? I am coding all day long and sometimes I get stuck in a problem and it keeps me occupied a few hours before I realize that maybe I need a break.

Some say frequent and short brakes help you but sometimes when I am focused on a problem I feel like a break would not help, but rather loose my focus. So how often should a break be taken, and how long? The more basic question regarding this issue is comes from the fact that, you can get tons of "good ideas" ('promodo' for instance) on the net, that promise you will be more effective in whatever you do.

Are these principles good or, this is something everybody should decide for himself?
I wonder if any of them can accomplish what it promises! I mean what they promise is that (if the conditions are met) it works for everybody. Are there really such principles? And if there are, what are these and how can we find them?

答:
...works for everybody. Are there really such principles?

No. It can be proved with a single counter-example. In the end you have to find out what works for you.

That said, regularity and rhythm are usually good in the long run, and there are ideas that tend to work for many, if not most, people. They're a good starting point to start fine-tuning what works for you. For example, there's Pomodoro Technique that essentially creates a rhythm with 25-minute sprints plus 5 minute pauses. For me it works fine when I need to do something not-so-engaging, but once I'm in the flow, I'm definitely not going to pause at an arbitrary time because some technique suggests I should.


答:
I've come to call this the "Winchester Mystery House Effect". Like the house, it started simple enough, but over the years many different workers added on so many odd features without an overall plan that nobody really understands it anymore. Why does this staircase go to nowhere and why does that door only open one way? Who knows?

The way to limit this effect is to begin with a good design that's made where it's flexible enough to handle expansion. Several suggestions have already been offered on this.

But, often you'll take a job where the damage has already been done, and it's too late for a good design without performing an expensive and potentially risky redesign and rewrite. In those situations, it's best to try to find ways to limit the chaos while embracing it to some degree. It may annoy your design sensibilities that everything has to go through a huge, ugly, singleton 'manager' class or the data access layer is tightly coupled to the UI, but learn to deal with it. Code defensively within that framework and try to expect the unexpected when 'ghosts' of programmers past appear.