问:
Should we choose Java over C# for a new project?
We have a team of .NET developers (C#) with a range of experience from 2 to 6 years. Over the last few years we have been developing Silverlight, ASP.NET MVC, and WPF applications. However, there is a new two year project which means we will develop a HTML5 application on Linux.

The company I work for would like all developers across their offices to use the same programming language which is Java. Although there is talk of using Mono but using the same language and sharing modules, services, etc. already created in Java is the main reason for moving to Java.

Some of the developers here are upset. How do I find something positive in moving over that will convince the other developers?

There will be a training budget, but the thought of learning to work with Java libraries and a new platform (Linux) will be scaring a lot of the guys.

What should I do?

答: If my employer gave me an OPPORTUNITY to work on a new project and learn a new language/framework and there was a training budget and understanding that there would be a ramp up time to become proficient in the new language, I would probably hug them.


问:
Understanding the Macro Aspects of Data Structures
I am studying data structures right now, but I still need to find a teacher/site/book with a clear explanation of the macro aspects of this topic.

What I mean is: most lessons/text books mix everything together, with no logical structure. They start with linked lists, then talk about stacks, queues, heap priorities and so on. But as far as I can tell, a linked list and a stack are not really in the same category. After all you can use the linked list to implement different types of data strcutures (e.g., a stack, a queue, etc).

So would it be right to say that the types of data structures are: the stack, the queue, the hash-table, the heap, and the tree; while arrays (static) and linked lists (dynamic) are tools you are going to use to implement those data structures?

If the above statement is not completely correct, maybe a linked list is indeed a data structure in itself, and therefore we would be using one data structure (e.g., the linked list) to build other data structures on top of it (e.g., a stack)?

答: Stacks, Queues, Heaps, Hash table are what are considered abstract data structures. The implementation is up to you to implement. You can use a linked list to do it, or you may need to used another abstract data type to create it. For example, a priority queue can be created using a min-heap which can be created using a binary tree. The implementation is up to you as long as you follow the "rules" (e.g min-heap having a running time for findMin being constant or the lookup of a value in a hash-table being constant, there are a few ways to do that)</p>

ContentLicense: CC BY-SA 3.0


问:
Why did Microsoft make parameters, local variables and private fields have the same name naming convention?
I asked this question quite some time ago: How do you name your private variables in C#?

In one of the answers, I was pointed to Microsoft's MSDN page that shows that private variables/fields should be named like this:

```<code>private int myInteger;
</code>```

But a parameter would be:

```<code>void SomeMethod(int myInteger)
</code>```

and a local variable would be like this:

```<code>int myInteger;
</code>```

So when you reference them like this

```<code>myInteger = 10;
</code>```

you have no way of knowing which one you are talking about.

I am now starting a new project and one of my co-workers is asking me why we don't do something to differentiate at least some of these.

I am wondering the same thing.  Why didn't Microsoft's standard keep these different?

答:
Because they are pretty distinguishable as they are depending on the context they are written in.

For example, have you ever used a parameter as a member variable? Or a local variable as a parameter? How about a member variable as a local one?

All member variables are in the "body" of a class. I really don't buy the argument that you need to prefix the member when you can use this to distinguish it from a local variable with a similar name, otherwise it's not needed.

A local variable is also only defined inside a method's scope or a in code block scope.

A parameter is always defined in the method signature.

If you get all of these types of variables confused or mixed together then you really should be thinking more about your code design to make it more readable or discoverable. Give them better and more self descriptive names than myInteger.


问:
Databases and Unit/Integration Testing
I have had a discussion with someone about unit/integration testing with web applications and I have a disagreement about 1 core idea.  The issues is that the person I am talking to think that the database the unit test work off of should have pre-populated data in it and I think it should be completely empty before and after the tests are executed.

My concern with pre-populated data in the database is that there is no way to make sure that data is maintained in a good state.  The tests themselves are going to be creating, deleting, and modifying data in the database so I really don't see how having data in the database before you start the tests is a good thing.

Is seems the the best way of testing database functionality would be having the following setups:

In a "setup" phase before the test actually run, you first truncate all the tables in the database

Then you insert all the data needed for the test cases you are about to run

Then you run and validate the test cases

Then in a "teardown" phase you once again truncates all the tables in the database

I don't see any other better way to ensuring that the data you are testing against in is a good testable test.

Am I missing something here?  Is this not the best way to test database related functionality?  Is there some benefit to have pre-populated database that always exists in the database (even before you start the tests or after the tests are done)?  Any help in ideas to explain my process differently to better get my point across would also be great (that is if my point has merits).

答:
Frankly I think if you do unit testing without a database roughly the same size as the existing production database, you are going to have many things that pass the tests and fail in production for performance. Of course I'm against perople developing aon a tiny local database for this reason as well.

And if the code is data specific, how can you effectively test it without data? You will miss seeing if the queries returned the correct results. Why would you even want to consider testing against an empty database, all that tells you is if the syntax is correct not if the query is correct. That seems short-sighted to me. I've seen too much stuff that runs and passes tests that is categorically wrong. Don't you want to find that in unit testing? I do.

Title: Databases and Unit/Integration Testing


问:
Will it ever be possible to build quality websites with editors alone, without needing to know HTML?
Lots of big companies, from Apple to Microsoft to Google, are putting more and more money into creating tools that will allow anybody to create a website with a WYSIWYG editor.

For example, this email I just got from Adobe:

Build websites as quickly and easily as an Adobe® InDesign® layout.

Currently in beta form, the application code-named "Muse" is a new technology that enables graphic designers to use familiar, free-form tools to design and publish HTML and CSS websites—all without writing code or being restricted to templates. Be part of this incredible free preview and experience how Muse will revolutionize the way you create for the web.

As a web developer, I can't foresee any way that Adobe or any other company will be to create some solution which allows a user with no HTML/CSS/JS knowledge to build a useful website design for these reasons:

The code generated will almost certainly be a mess, which makes it difficult for a programmer who wants to write the backend for the site to work with it. They may even be required to change the code themselves to structure it as they need it.

HTML is not pixel-based, so it is very difficult to develop a tool that can easily design templates which can flow with changes in text size, etc. In addition, elements should follow each other in reasonable order, not in some random order (e.g. as dictated by when an element is added).

Code generated in one tool would likely not be portable to other tools easily, which would lock you in to the original tool.

(I am assuming that the tool would allow complete control of a website; as Adobe said, "as quickly and easily as an Adobe InDesign layout". Programs which let you use professionally-designed templates are a different story.)

Do you think it will ever be possible for a person unskilled in HTML to create quality (both behind-the-scenes and appearance) web designs/sites?

答: Probably, as long as the tool can produce what the client wants. As soon as the client wants something that cannot be done by this tool, then the answer will be "no".


答:
Not anytime soon.  The era of WYSIWYG editors is long over (like the dinosaurs) but companies continue to pump it out.  I remember the days of using Dreamweaver and having dozens of spacer.gif images to put the layout in the same way.

Software like this is fool's gold - it's meant to appeal to people who want something quick and dirty (tomorrow as opposed to in three months) and who don't know or care about quality.  It's not a real solution, it just provides that illusion; in the immortal words of Admiral Ackbar: It's a trap!

To be perfectly honest, and I'm going to adopt a ranty tone for this so be warned, the fact that snake oil like this is perpetuated disgusts me because it fosters and encourages the idea that you don't have to do things correctly.  Whether it's some WYSIWYG editor to let the receptionist create a web page or some nifty wizard that looks like it will create a full CRUD application for you in a couple of clicks, it's the attitude that I hate - it makes businesses think that quality doesn't matter and you can just toss out garbage as quickly as possible, so when the time comes that the shoddy design falls apart there's too much invested in it to do it properly and you're left trying to monkey patch a leaky pipe because nobody wants to replace the thing.  It's completely the wrong attitude to have, but it gets pushed more.  To go back to the Star Wars references, it's the path to the Dark Side, and once you start down that path forever will it dominate your destiny.

To flat out answer your question, yes someday there will be a way to create a good website without using raw HTML, but that day is far off.

Title: Will it ever be possible to build quality websites with editors alone, without needing to know HTML?

Body:
Lots of big companies, from Apple to Microsoft to Google, are putting more and more money into creating tools that will allow anybody to create a website with a WYSIWYG editor.

For example, this email I just got from Adobe:

Build websites as quickly and easily as an Adobe® InDesign® layout.

Currently in beta form, the application code-named "Muse" is a new technology that enables graphic designers to use familiar, free-form tools to design and publish HTML and CSS websites—all without writing code or being restricted to templates. Be part of this incredible free preview and experience how Muse will revolutionize the way you create for the web.

As a web developer, I can't foresee any way that Adobe or any other company will be to create some solution which allows a user with no HTML/CSS/JS knowledge to build a useful website design for these reasons:

The code generated will almost certainly be a mess, which makes it difficult for a programmer who wants to write the backend for the site to work with it. They may even be required to change the code themselves to structure it as they need it.

HTML is not pixel-based, so it is very difficult to develop a tool that can easily design templates which can flow with changes in text size, etc. In addition, elements should follow each other in reasonable order, not in some random order (e.g. as dictated by when an element is added).

Code generated in one tool would likely not be portable to other tools easily, which would lock you in to the original tool.

(I am assuming that the tool would allow complete control of a website; as Adobe said, "as quickly and easily as an Adobe InDesign layout". Programs which let you use professionally-designed templates are a different story.)

Do you think it will ever be possible for a person unskilled in HTML to create quality (both behind-the-scenes and appearance) web designs/sites?


答:
In a sense, this is already possible. This is the entire point of blogging tools like WordPress and its many templates: to enable content creators to make great websites with little technical know-how about HTML.

That said, the functionality of the website is completely constrained to what the website-creation tool included. Just like with everything in life, if you want novel functionality and a custom creation then that involves lots of work under the hood.


答:
Your points sound logical. However, building web pages for data processing applications are offering alternatives to pure HTML/CSS interface, for example: MS-Silverlight, ZOHO Creator, Code OnTime, and possibly others. Also for information processing applications, the use of controls takes care of many visual aspects without having to know much about the HTML/CSS world.

Also, for web sites there is at least one tool that is truly genius that does not require HTML to build great sites (may be it is using templates internally) but if you don't know HTML/CSS, it would not be too bad if you could select from 50 templates or so - The tool is Artisteer: http://www.artisteer.com/


问:
Java SE and Java EE?
I was now talking with some people and they told me that if i was intrested in a job in the future for Java programming i should not spend too much time only learning Java SE i should spend time learning Java EE instead.. Now that brought me to some questions..

Java Enterprise Edition why use this ? What can i make with this that i can't make in Java SE?, And what kind of applications is this good for?

Is there any good books out there that i can read to learn the Java EE?

If i know Java SE well is it easier to learn Java EE ?

Thanks! I will keep browsing the web for some anwears for theese questions.. And if i find anything i wil update this question.

答:
Here you can see a list of features or technologies that the Java Enterprise Edition 6 includes. I think, you cannot "learn" all these framework parts, if there is no appropriate-sized project, where you could apply them. So in my view, it is good to know about them, but not necessary to know all the details.

The Java Standard Edition covers on the one hand much more basic features (like Collections, Threading and I/O), which every Java developer should really know and on the other hand specialized APIs (for example to create GUIs), which again you only need to know about their existence, but not detailed.

OwnerDisplayName: TheCompBoy

Title: Java SE and Java EE?


问:
Best git practices for android project with multiple sets of resources
I have a commercial Android project that I have created a client-specific version for (mainly UI tweaks). Since the bulk of the tweaks are in the res/ folder in XML files, we have the changes currently in a branch but I really don't want to have to port changes back and forth between branches in perpetuity. I'm curious if anyone has any source control strategies that will make managing multiple client-specific versions of an Android application as painless as possible.

Also, not sure if this belongs here or StackOverflow. Feel free to transition over there if I guessed wrong.

答: The path we are going down is we are avoiding custom code as much as possible, and the app resources (everything in the res/ subdirectory) are stored in a separate git project with its own branches. That way we can decouple feature branches from UI branches and test features with different UI's without having to do the gymnastics from before where the UI was tied with the code on a per-branch basis, if that makes sense.</p>


问:
Did jQuery kill the JavaScript discussions?
There are over 100,000 questions on Stack Overflow tagged as questions relating to JQuery troubleshooting/usage.  Compare this to the 124,000 questions on stack overflow that are tagged for JavaScript issues.  We are very close to almost half of all JavaScript related questions on Stack Overflow being attributed to JQuery (plus or minus any margin for the few other JS frameworks that get questions on SO).

What I'm getting at is, jQuery is not a language and it is not the be all and end all of frameworks that must be applied to every scenario in which JavaScript is present, yet it is quickly catching (and I predict will soon eclipse) JavaScript as a source of discussion/inquiry on sites like Stack Overflow.

Is jQuery killing the JavaScript star?  Is there no longer a firm grasp by the next generation of web developers regarding the power, simplicity and use of JavaScript as a means for DOM manipulation?  Is this just the natural evolution of things and the viewpoint I'm presenting typical of the coder's ego (i.e., is this how assembly programmers view the .NET/Java/Web crowd?) or is this really the beginning of the end of the true JavaScript developer?

答:
Jquery abstracts away the most annoying and boring tasks of developing a javascript for a web site. Traversing the DOM is repeatable task that requires a lot manual labor with very little benefits from doing it the hard way. The only cases where I don't use jQuery nowadays are the mobile versions of the sites - you just cannot afford one more request and 100k there. Same is with ajax loading.

Also jQuery makes quasi functional programming seem like fun. It introduces the concept of  function as a first class object really intuitively to developers. Throw some eye candy effects and some very good plugins - its quite impressive little tool that is perfectly suitable for the task.

Standard javascript - > Jquery for me felt like in migrating from C++ and mfc to winforms and C#.


问:
Rewriting IBM assembler + COBOL in C++
I work as a rental agent / manager for a car rental company that is running on a rental system that was written in 1972. I decided that maybe it was time for an update. For a bit of background, here is a short example of the madness that we have to deal with from this program daily:

A rental agent must remember that printing on one screen uses "MXC" in the ACT field (everything is based on short codes), which perplexingly stands for "MaXimum display on a Contract", while on another it requires PR (for PRint) in the ACTION field, but several screens use a Y in the PT (for PrinT) field, yet another screen uses Y in the PRT (for PRinT) field, yet another screen requires the user to hit enter (but not the enter next to the letters, as that's a new line character, it must be the enter on the number pad) and then F8, a different but related screen requires simply F8, some screens have a field labeled PRT, which should be for PRinT, but the field actually does nothing and printing is done automatically after going through several prompts, and still more screens have a field labeled PRINT Y/N, which insanely defaults to Y for operations in which another location is already delivering paperwork, and to N for operations in which another dealer will need paperwork.

I decided that I could do a better job than this, so I set out to contact the person in the company that would make the decision to update this. I eventually get through to the VP of IT, who is in charge of this program. I get a bit of information out of him, and learn that my car rental company has its rental program written in IBM mainframe assembler with a little bit of COBOL mixed in. He says that there are no positions open right now, but that I should e-mail him my resume anyway (in case something opens up).

This leads me to my questions.

The first is technical. With the idea of improving maintainability in the future, my thought is to re-write it in a higher-level language than assembly language. My area of experience is in C++, so that is the obvious choice for me. The company is in dire need of an easier way to update the program, as I recently read an article where the man I spoke with is quoted as saying the team worked hard, and they are proud to announce that the program now has support for 5-digit location codes (instead of 4) and 8 digit car numbers (instead of 7). My philosophy on updates, even in situations this dire, is in line with Joel's: http://www.joelonsoftware.com/articles/fog0000000069.html in short, re-writes should be incremental, rather than throwing out everything there was before and starting fresh.

Is there an easy way to integrate IBM assembly with C++, and if so, how should I do it? I am vaguely aware of the asm keyword, but I don't know if it's best to use that or do something else. Is such a plan ill-advised? I do most of my work on Linux using g++ and GNU make, so answers specific to that are welcomed, but definitely not required (since I have no idea what sort of build system they have no, but I suspect almost none).

The second question is more political. How should I go about persuading this company that they need to make the switch? The theoretical cost savings are huge (based on my estimates, the company is wasting an extra million or so dollars per year, just on increased training costs to learn how to interact with the program), but my proposed changes would probably put all of the current programmers out of work, should they be enacted, so there is great structural resistance to change.

edit: I should explain why me modifying what the company already has seems like the best solution to me. I am still open to other suggestions, because this is a monster of a program, however. I've never had a programming job before, so please correct me on any incorrect analysis I might give.

First off, there is the off-the-shelf solution.

From my talks with a few mid-level managers about this sort of thing, one of the main concerns with switching to a new system is the large number of loyal employees who have been with the company for decades and are comfortable with the system by now. If I have the ability to modify what we have, I could maintain the current interface in a sort of 'compatibility mode'. Users already have to log in to use the current system, so I could add the ability to activate a setting when users log in for the 'first' time (after I make this change), where they are given the option to use either the 'classic' interface or the 'new' interface. There is no way I'll find an off-the-shelf solution that allows that, and I think that fears of senior employees getting confused by changing technology would be a major reason for upper management to say no.

My company also owns the software we use; we do not license it. This means that the management I am currently talking to are the same people who could actually authorize me to make a change. With a third-party solution, I would have to get approval from my company in addition to securing whatever rights would be necessary from the company that developed the product we use, which adds an additional hurdle. This would also require convincing the company to give up on "their" product and take some other product, which seems like a greater hurdle than attempting to update what we have, but I could very well be wrong on this issue.

Finally, looking into the future, I don't just want to improve the user interface and fix a few bugs. After I update those 'urgent' issues, I was hoping to update fundamental way the company runs as related to technology. After spending 1-2 years on these sorts of issues, my plan was to go back to management and propose more dramatic changes. There are many ways the company runs that could be fundamentally improved by technology that they simply are not using right now. For instance, each region pretty much operates the same way. The local major airport is the central hub to distribute cars. They are primarily sent on an as-needed basis. However, the airport is used as the home base for all operations. They'll send two people in one car to my location to pick up one car from us that we don't need, then return to the airport with the car they came in, plus what they are taking back (we are 32 miles from the airport). Then they will come to the location 5 miles away from us in two cars to drop one of them off, then return in their other car to the airport. They do this even if the car we sent back is the same kind of car they need near us. I've been with the company for about two years now, and I've only seem them deviate from this in the most extreme emergencies of car shortages (so about three times ever). I would replace the 4 people working in every region with an automated scheduling system that determines what cars go where and try and find the path that requires the least amount of time + miles + drivers to deliver all cars where they need to be, as an example of the higher level fixes I hope to some day add.

However, before I would feel comfortable proposing all of this, I feel it would be helpful to get a toehold in the company and the code base by doing the smaller tasks, like updating the interface. Solutions like outsourcing or otherwise would remove this possibility.

答:
I had a similar problem some years ago at BellSouth. I simply wrote COBOL code to scan assembler language programs byte by byte, separate out the opcodes and operands, convert branch instructions to go tos, and convert compare instructions to IFs. This program converted DC instructions to the equivalent COBOL Data Division code, and converted moves, zaps, etc., as appropriate.

Once that was done, I wrote a second program to convert IFs and GOTOs to IF-THENs, with moves and such in the lines between these clusters (this wasn't really all that hard to do - the secret is to insert the IFs and ELSEs as you re-read the 1st-phase "pidgin" cobol from back-to-front).

IF-THEN-ELSER looked for situations where it found a GOTO reference in close proximity to a label, which could safely be deleted (decrementing its number of references by 1). You run this IF-THEN-ELSER program iteratively (that is, you run it again and again, stopping only when your last pass can't find a way to make any more changes). Most of the critical work is done by this if-then-elser, whose COBOL product must be carefully reviewed and vetted by an experienced, competent assembler-language programmer (namely, me). In my experience, my "if-then-elser" was able to eliminate more than 90 percent of the GO TOs resulting from the original branch instructions.

I suppose it's possible to go forward from this point with a straightforward conversion to C (or C++) - languages I am also conversant with. However, at BellSouth, our target language of choice was COBOL/II. There is always a bit of complexity which arises from situations where a remaining label has multiple GO TO references (many times, these situations are handled by COBOL PERFORMs, but can sometimes be simply represented by OR and AND constructs).

I think it's nice to produce code in elegantly block-structured COBOL/II, with EVALUATEs (Case constructs) and 88 level condition-names. Adding these finishing-touches led to another pair of programs, which proved handy on COBOL programs not originating in programs converted from assembler.

I don't know if this helps.

As others above have commented, you have to conduct this process with care. It helps to have 10-12 years of assembler coding experience informing your decision making processes. We who have that experience are hard to find any more.

As a final note: We only wrote in assembler back then because the compilers for the high-level languages produced cumbersome, inefficient object code. Today's "optimizing" COBOL compilers don't have those same bad habits. ----------

OwnerDisplayName: David Stone

Title: Rewriting IBM assembler + COBOL in C++


问:
Are there problems with using Reflection?
I don't know why, but I always feel like I am "cheating" when I use reflection - maybe it is because of the performance hit I know I am taking.

Part of me says, if it is part of the language you are using and it can accomplish what you are trying to do, then why not use it.  The other part of me says, there has to be a way I can do this without using reflection.  I guess maybe it depends on the situation.

What are the potential issues I need to look out for when using reflection and how concerned should I be about them?  How much effort is it worth spending to try to find a more conventional solution?

答:
It isn't cheating, but like any tool, it should be used for what it is intended to solve. Reflection, by definition, allows you to inspect and modify code through code; if that is what you need to do, then reflection is the tool for the job. Reflection is all about meta-code: Code that targets code (as opposed to regular code, which targets data).

An example of good reflection use is generic web service interface classes: A typical design is to separate protocol implementation from payload functionality. So then you have one class (let's call it T) that implements your payload, and another that implements the protocol (P). T is fairly straightforward: for every call you want to make, simply write one method that does whatever it is supposed to do. P, however, needs to map web service calls to method calls. Making this mapping generic is desirable, because it avoids redundancy, and makes P highly reusable. Reflection provides the means to inspect class T at runtime and call its methods based on strings passed into P through the web service protocol, without any compile-time knowledge of class T. Using the 'code about code' rule, one can argue that class P has the code in class T as part of its data.

However.

Reflection also gives you tools to get around restrictions of the language's type system - theoretically, you could pass all parameters as type object, and call their methods through reflections. Voilà, the language that is supposed to enforce strong static typing discipline now behaves like a dynamically typed language with late binding, only that the syntax is far more elaborate. Every single instance of such a pattern I've seen so far has been a dirty hack, and invariably, a solution within the language's type system would have been possible, and it would have been safer, more elegant, and more efficient in all regards.

A few exceptions exist, such as GUI controls that can be data-bound to various non-related types of data sources; mandating that your data implement a certain interface just so you can data-bind it isn't realistic, and neither is having the programmer implement an adaptor for each type of data source. In this case, using reflection to detect the type of data source and adjusting the data binding is a more useful choice.


问:
Will my communication skills be wasted in a software engineering career?
I've been in the financial engineering arena (after BA Math and BA Computer Science) for about 5 years (20% analysis/programming, 80% communicating) and take pride in my ability to communicate with people and discuss technical problems (i.e. interacting with a team).  I love this part of my job.  Going to the white board to draw abstract ideas and brainstorm.

However, for many reasons, I want to transition my career into a technology company (software engineering) but I'm deeply afraid that I will fall into a stereotypical programming job where programmers code with big headphones on.  I certainly know this is only a stereotype but I've witnessed similar environments before (at startups) and it scares me to think that I would be migrating to a career of isolation.

I love coding and thinking algorithmically, but I don't want to give up interacting with people. I understand that having communication skills is only a positive, but am I setting myself up for career-happiness failure by transitioning into software engineering.  I'd love to hear any clarifications and/or advice.

答:
I firmly maintain that my biggest competitive advantage over other programmers and IT-types that I know is my ability to communicate with people who are not fluent in IT concepts. It is the single-most underestimated and underdeveloped skill by the average member of the IT community, and yet it is one of the most important.

In almost every role imaginable, at some point, you are going to need to need to talk to someone who has almost no grasp of what you do, and you will need to be able sell them on what it is that you're doing.

You may also need to deal with users to gather requirements for a specification - that specialised kind of listening (coupled with the right prompts and questions) is communication too!

It does have one further benefit, of course - good communications skills make getting a job in the first place a whole lot easier.


问:
Unit testing vs Integration Testing
What is the difference between unit testing and integration testing when it come to web development (where 90-95% of the code relies on a database)?  One thing I here all the time is that unit testing should not deal with databases and integration testing should.  The issue I have with this is that to me that means the only difference between unit testing and integration testing is the data source and if that is the case, you are testing the same functionality.  If the functionality that is tested is the same, why even bother with unit testing and always test against a database?</p>

答:
Integration testing is about testing the integration points between 2 or more systems, this could be a database, it could be a web service.. whatever it is, it is interaction based, i.e. What happened to my component when it calls a stored proc that does xy and z? Has a web service changed its interface?

Unit testing deals with a single unit of work. Each unit test should test just one thing that method should do, this is where you stub out the database and any external interfaces or interactions.

Title: Unit testing vs Integration Testing


答:
Congratulations.  You have a bright future as an application engineer and then an application engineering manager (FAE Manager).

As part of this sterling profession you will create powerpoint presentations for tier-I customers with the text "Software Stack" written all over them and abstract very complex software engineering designs into rectangular blocks of different colors, often arranged haphazardly; these presentations will be initiated from the principal software engineers at the top levels of R&D, become watered down into the lowest-common-denominator customer mentality, and subsequently pasted back into requirements documents which are presented back to the principal software engineers at the top levels of R&D as make-or-break-the-business specifications.  One of your bonuses will depend on liberal use of the word "cloud".

Title: Will my communication skills be wasted in a software engineering career?

Body:
I've been in the financial engineering arena (after BA Math and BA Computer Science) for about 5 years (20% analysis/programming, 80% communicating) and take pride in my ability to communicate with people and discuss technical problems (i.e. interacting with a team).  I love this part of my job.  Going to the white board to draw abstract ideas and brainstorm.

However, for many reasons, I want to transition my career into a technology company (software engineering) but I'm deeply afraid that I will fall into a stereotypical programming job where programmers code with big headphones on.  I certainly know this is only a stereotype but I've witnessed similar environments before (at startups) and it scares me to think that I would be migrating to a career of isolation.

I love coding and thinking algorithmically, but I don't want to give up interacting with people. I understand that having communication skills is only a positive, but am I setting myself up for career-happiness failure by transitioning into software engineering.  I'd love to hear any clarifications and/or advice.


答:
A unit test is:

Repeatable: You can rerun the same test as many times as you want.

Consistent: Every time you run it, you get the same result. (for
example: Using threads can produce an inconsistent result)

In Memory:
It has no "hard" dependencies on anything not in memory (such as file
system, databases, network)

Fast: It should take less than half a
second to run a unit test.

Checking one single concern or "use case" in the system: (More than one can make it harder to understand what or
where the problem is when the problem arises.)

By breaking any of
these guidelines, you increase the chance of developers either not
trusting or not believing the test results (due to repeated false
failures by the tests), or people not wanting to run the tests at all
because they run too slowly.

http://www.typemock.com/unit-tests-integration-tests

Another thing that isn't mentioned above is that it shouldn't rely on any special configuration.  Can any developer check out a copy of the source code and run the unit tests?

With a database you require each developer to have the same database configuration set up. What if some of the developers don't work with the database normally?

Title: Unit testing vs Integration Testing

Body: What is the difference between unit testing and integration testing when it come to web development (where 90-95% of the code relies on a database)?  One thing I here all the time is that unit testing should not deal with databases and integration testing should.  The issue I have with this is that to me that means the only difference between unit testing and integration testing is the data source and if that is the case, you are testing the same functionality.  If the functionality that is tested is the same, why even bother with unit testing and always test against a database?</p>


问:
Is it practical to use Twitter for service logs?
Recently my boss suggested that we post logs of our service that is hosted on Windows Azure into twitter. His idea is that it's conveniently readable and if Azure cloud fails logs persist. He also said, lots of people do this, I Googled and couldn't find any data about this.

Currenly my concerns are the following. First, perhaps twitter is not very convenient for logging something that can happen very frequently (for example, when our service role starts each instance writes tens of records over several minutes). Second, even if twitter EULA allows such use at this moment it might be changed in future to cut off tweets that occur too often to be human-originated.

Is it practical to post service logs on twitter? What to consider if we implement this?

答:
No.  Use syslogd hosted via any cheap ISP or on your own BSD server exposed to the internet via your corporate firewall.

man logd:

```<code>NAME
 syslogd -- log systems messages

SYNOPSIS
 syslogd [-468ACcdknosuv] [-a allowed_peer] [-b bind_address]
     [-f config_file] [-l [mode:]path] [-m mark_interval]
     [-P pid_file] [-p log_socket]

DESCRIPTION
 The syslogd utility reads and logs messages to the system console, log
 files, other machines and/or users as specified by its configuration
 file.
</code>```

Body:
No.  Use syslogd hosted via any cheap ISP or on your own BSD server exposed to the internet via your corporate firewall.

man logd:

NAME
 syslogd -- log systems messages

SYNOPSIS
 syslogd [-468ACcdknosuv] [-a allowed_peer] [-b bind_address]
     [-f config_file] [-l [mode:]path] [-m mark_interval]
     [-P pid_file] [-p log_socket]

DESCRIPTION
 The syslogd utility reads and logs messages to the system console, log
 files, other machines and/or users as specified by its configuration
 file.


问:
What good reasons are there to capitalise SQL keywords?
There seem to be a lot of developers who write their SQL by capitalising the keywords:

```<code>SELECT column
FROM table
     INNER JOIN table
     ON condition
WHERE condition
GROUP BY clause
HAVING condition
</code>```

I'm wondering why people stick to this approach? Clearly, it's a long established convention - but I've never run into a RDBMS that requires capitalisation.

Personally, I find KEYWORDS THAT SHOUT to be calling attention to exactly the wrong part of the query, which is why I write the keywords in lowercase.

Still, enough people use this convention that I figure I might be missing something, hence this question.

答:
I find this sort of capitalization provides a quick and easy way to visually break up the different parts of the query. This combined with good indentation can help the readability and understanding of the logic.

Whether or not that has anything to with how the standard came about, I don't know. But that's my personal experience.


答:
Capitalization makes them stand out, as opposed to the other characters that are in the query window.

The reason I don't do this as it's a huge time waster.  You can do one of two things:

1) Hold your shift key down while typing out the word: way too error-prone and just haphazard.

2) Put on caps lock for the duration of the word: a bit too much of time consumption.

I use SQL Server, and the environment (SSMS) has great syntax highlighting so I don't personally believe keyword capitalization is as prevalent these days as it used to be (if at all).

It is good practice in books and online tutorials, though, so it is evident what the reserved keywords are.  It's just one of those unwritten things.

Title: What good reasons are there to capitalise SQL keywords?

Body:
There seem to be a lot of developers who write their SQL by capitalising the keywords:

```<code>SELECT column
FROM table
     INNER JOIN table
     ON condition
WHERE condition
GROUP BY clause
HAVING condition
</code>```

I'm wondering why people stick to this approach? Clearly, it's a long established convention - but I've never run into a RDBMS that requires capitalisation.

Personally, I find KEYWORDS THAT SHOUT to be calling attention to exactly the wrong part of the query, which is why I write the keywords in lowercase.

Still, enough people use this convention that I figure I might be missing something, hence this question.


问:
Which Linux distro to pick for volunteering?
The number of Linux distributions is large.  Someone wanting to volunteer with one of them might have a hard time picking between them, because it's hard to sense the culture, environment, and level of community and esprit de corp.  Also, some might be very strict with long processes before you are trusted, or else much looser with a smaller community with more trust.  It's hard to tell where to look for information.  Maybe one is in great need, and others are well-established with less need.  How would I find out who is in greatest need?

Joining a Linux distribution's team of writers, developers, testers, coordinators, and administrators is a big decision.  This is an extremely sensitive question, and I hope nobody is slighted by either the question or responses.

答:
Check DistroWatch for a comprehensive list of Linux distros. You will find many not known distros that might need help.

After you established a good reputation, you can try to switch to another famous distro like Fedora or Arch Linux.

On a side note, the book "The Linux Programming Interface" is amazingly useful resource.


答:
Auto-generation leads to fluff (especially with web development).  Fluff leads to bulky and unncessary bytes going over the wire.

In my opinion, I'd rather have complete control over what gets put into markup.  The closest thing to a compromise is saving markup snippets that take a little longer to type out.

There's no free lunches! =)


答:
Unit Testing is all about testing a single component (and thus simpler than integration testing).

Unit test is really good to make sure your public interface does not break during bug fixes. Each class (component) is tested in isolation without using any dependencies (dependencies are usually injected and mocked). Thus you are usually able to test 100% of execution paths (by getting your injected dependencies to give you every different kind of result (including errors)). This would be really hard achieve with a real data source as generating the error responses are hard (e.g. DB how do your force DB exception at the correct point in the test).

Integration tests is about how the components work together.

And as a result can be easier to write but harder to set up to test all possibilities.

Here you write test on how systems of components work together. It test to make sure that you have not deprecated any interfaces that are needed. Stuff like that.

Title: Unit testing vs Integration Testing


答:
Well back in the olden days, keywords weren't highlighted in any way when you wrote code so it was an attempt to help people differentiate between the SQL parts and the database objects parts of the queries, it could have gone the other way but objects tend to have longer names making them more of a pain to capitalize and some object naming conventions were case specific.

Personally I find it just as easy to read if they aren't capitalized but many people are so used to reading them that way, it throws them off if you don't capitalize.


答:
You wrote the question without HTML, and it appears on a website.

However, rich web applications interact with users in complex ways.  That complexity is irreducible.  The complexity remains whether HTML is used, or Javascript, or any other language.  It has proven very hard to express that complexity through a drag-and-drop process.  We've been trying to do that for decades now with limited success.  Even if we could do that, the complexity is still there, and some talent and skill will be needed to deal with it.  HTML could become the assembly language of web design, but there will still be plenty of work for web developers.


问:
How far can I push refactoring without changing external behavior?
According to Martin Fowler, code refactoring is (emphasis mine):

Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior. Its heart is a series of small behavior preserving transformations. Each transformation (called a 'refactoring') does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.

What is "external behaviour" in this context? For example, if I apply move method refactoring and move some method to other class, it looks like I change external behaviour, doesn't it?

So, I'm interested in figuring out at what point does a change stop being a refactor and becomes something more. The term "refactoring" may be misused for larger changes: is there a different word for it?

Update. A lot of interesting answers about interface, but wouldn't move method refactoring change the interface?

答:
To me, refactoring has been most productive / comfortable when the boundaries were set by tests and/or by formal specification.

These boundaries are sufficiently rigid to make me feel safe knowing that if I occasionally cross, it will be detected soon enough so that I won't have to roll-back a lot of changes to recover. On the other hand, these give sufficient leeway to improve code without worrying about changing irrelevant behavior.

Thing I especially like is that these kinds of boundaries are adaptive so to speak. I mean, 1) I do the change and verify that it complies with spec/tests. Then, 2) it is passed to QA or user testing - note here, it may still fail because something is missing in spec / tests. OK, if 3a) testing passes, I'm done, fine. Otherwise, if 3b) testing fails then I 4) roll-back the change and 5) add tests or clarify spec so that next time this mistake won't repeat. Note that no matter if testing passes or fails, I gain something - either of code / tests / spec gets improved - my efforts don't turn into total waste.

As for other kinds boundaries - so far, I didn't have much luck.

"Observable to users" is a safe bet if one has a discipline to follow it - which to me somehow always involved much effort in analyzing existing / creating new tests - maybe too much effort. Another thing I dislike about this approach is that blindly following it may turn out to be too restrictive. - This change is prohibited because with it loading data will take 3 sec instead of 2. - Uhm well how about checking with users / UX expert whether this is relevant or not? - No way, any change in observable behavior is prohibited, period. Safe? you bet! productive? not really.

Another one I tried is to keep code logic (the way I understand it when reading). Except for the most elementary (and typically not very fruitful) changes, this one was always a can of worms... or should I say a can of bugs? I mean regression bugs. It is just too easy to break something important when working with spaghetti code.


问:
How to balance code quality vs strong developer personalities
On code reviews at work I have been seeing code & patterns that I consider "clever" though not necessarily adding to the overall quality or maintainability of the code base. I point this out on my feedback and am unconvinced by the counterarguments. I am a bit concerned when this code makes into into the repo and later to production.

I want to maintain a cohesive team, so I dont want to create tension by being too vocal about my reservations. I also want to create a great product for our customers without being too leninent.

Traditionally, who has 'veto' power on what gets checked in and how?

How can code that works, but its too involved/clever be removed without stepping on toes?

答:
My rule of thumb is to bend code quality guidelines in favor of strong developer personalities. I use it always when I don't have time to dig deep enough - such digging by the way is typically quite effort consuming (more on that below).

This rule is based on personal experience. I began (probably as any neophyte) with fanatically following guidelines and thoroughly fighting each and every deviation. Upon time I've gained sufficient skills and learned enough tricks to win such fights with relative ease - which in turn allowed to focus more on learning the overall impact of my "victories". And the impact as far as I can tell was rather negative - guys who "lost the fight" were suffering and became less productive - and, you know, the fact that their code was 200% compliant with quality guidelines did not compensate for that.

This discovery caused me to drop most of the fighting which in turn lead to having more time to analyze problematic cases. And I found that when I dig deep enough there is typically an interesting design problem somewhere behind, a subtle (or not too subtle) problem that was just hiding behind the personalities fighting.

It's like, you know, like say I find 31K source file exceeding the recommended size limit which is say, 30K. My options are either to spend few minutes/hours fighting to force file owner to somehow squeeze that extra kilobyte out or to spend a day or two thinking and digging to find out that, say, there's some library API that can be used instead of all the code in that file (so that it can be just removed).

Such a discovery might sometimes be not much useful from end-user perspective (though sometimes it can have deep impact indeed) but have to admit the fun I get when cracking such a nut makes it well worth the effort anyway... and as an icing on the cake guidelines deviation also goes away without a fight. :)


答:
Why didn't Microsoft's standard keep these different?

The folks at Microsoft wrote a book called Framework Design Guidelines which explained a number of conventions, including why some things were camel cased, and others were pascal cased.

Edit (adding details from the book):

In the book, they mention doing usability studies, as well as some of the lessons-learned from acquiring the Turbo Pascal group. Also, while not all languages are case-sensitive (such as VB), others are (such as C#), so one should be consistent in one's naming. One cannot depend upon differences in case alone to distinguish items. If one sticks to the conventions used by the rest of the framework, it will lead to less confusion by devs.

Chapter 3, Naming Guidelines.

Section 3.1 is capitalization conventions.

camelCasing is for parameter names.

PascalCasing is for namespace, type and member names. In the event that there are 2-letter acronyms as part of the name, keep them capitalized together, such as IOStream.

Section 3.5 covers naming classes, structs and interfaces.

Section 3.6 covers naming type members.

Section 3.7 covers naming parameters.

Title: Why did Microsoft make parameters, local variables and private fields have the same name naming convention?

Body:
I asked this question quite some time ago: How do you name your private variables in C#?

In one of the answers, I was pointed to Microsoft's MSDN page that shows that private variables/fields should be named like this:

```<code>private int myInteger;
</code>```

But a parameter would be:

```<code>void SomeMethod(int myInteger)
</code>```

and a local variable would be like this:

```<code>int myInteger;
</code>```

So when you reference them like this

```<code>myInteger = 10;
</code>```

you have no way of knowing which one you are talking about.

I am now starting a new project and one of my co-workers is asking me why we don't do something to differentiate at least some of these.

I am wondering the same thing.  Why didn't Microsoft's standard keep these different?


答:
To an extent...

It will probably not happen anytime soon that you will not have to know HTML to make a fully customized webpage (unless HTML is replaced by another "language"). But tools such as Wordpress, Blogger (by Google), Webs.com (formerly Freewebs), and other sites allow you to create a customized website, as I said before, to an extent.


答:
An alternative, in cases where the domain of the reflected classes is well-defined, is to use reflection along with other metadata to generate code, instead of using reflection at runtime.  I do this using FreeMarker/FMPP; there are lots of other tools to choose from.  The advantage to this is that you end up with "real" code that can easily be debugged, etc.

Depending on the situation, this can help you make a lot faster code - or just a lot of code bloat.  It avoids the disadvantages of reflection:

loss of compile-time type safety

bugs due to refactoring

slower performance

mentioned earlier.

If reflection feels like cheating, it may be because you're basing it on a lot of guesswork that you're not sure of, and your gut is warning you that this is risky.  Be sure to provide a way to enhance the metadata inherent in reflection with your own metadata, where you can describe all the quirks and special cases of the real-world classes you may encounter.

Title: Are there problems with using Reflection?

Body:
I don't know why, but I always feel like I am "cheating" when I use reflection - maybe it is because of the performance hit I know I am taking.

Part of me says, if it is part of the language you are using and it can accomplish what you are trying to do, then why not use it.  The other part of me says, there has to be a way I can do this without using reflection.  I guess maybe it depends on the situation.

What are the potential issues I need to look out for when using reflection and how concerned should I be about them?  How much effort is it worth spending to try to find a more conventional solution?


问:
Company wants thoughts about their site during interview
I have an initial phone interview coming up with a company for a Senior Web Developer position and in the email they asked to prepare by signing up on their site because they'd like to hear my thoughts about it and suggestions for improvement.

I've heard stories before of companies that do this.  They interview 10 people and then if everyone gives advice, then they've got a lot of free consultation.

I believe this is the first time I've ever been asked to do something like this so I wanted to hear other people's thoughts of whether it is free consulting or if I'm just being paranoid.

答:
I'm a manager, usually interviewing candidates toward the end of their on-site time.   I almost always ask candidates (for any position, from accountant to QA to programmer) for feedback on our site, usually with an open-ended "do you have any questions or comments on our site?".   I'm looking for a few things:

Did they do any research on our company before coming for an interview?

How well do they communicate their thoughts about the site?

Are their comments or questions well thought out?

We don't specifically ask candidates to prepare for this questions, and some admit to not having looked at the site (baffles me that they would not even look at the home page -- we are a well-known internet brand), but it often gives good insight into the candidates inquisitiveness, thought processes, etc.

Once in a while, this results in something that I'll send on to our design or product teams, but mostly it help to get to know the candidate better.


问:
What is an effective way to familiarize yourself with a new application in a new language (and still look productive at a new job)?
I started a new job working on an application I'm vaguely familiar with, and it's in Perl! I come from a PHP and Java background, so while I understand the basics, there are lot of nuances in Perl that make it troublesome.

I'm supposed to be a UI developer, but the smallness of the office requires me to learn and do a lot more than just javascript. So that was slightly unexpected in some aspects and I'm just thinking about what approach to take with this

So far I've been sifting through the code to understand what each part does, printed out copies of code and try to lookup APIs I'm not familiar with, and so I dunno how effective this process is -- I feel like it's going to take some time -- and I don't want my new employers to feel like I'm not being productive.

Anyone have some ideas or approaches for this kind of situation?

I read some of the questions about learning new languages, but I'm curious to see if anyone's had experience with this with Perl.

答:
I've been in the same situation. I started this new job of mine this April and I had to learn Perl too. These two books got me started rather quickly:

Perl Cookbook - It's readily available over Amazon.

Impatient Perl - It's a free ebook. Go ahead and google it ;).

I hope this helps. Most, if not all, the Perl work I do here is backend stuff though.


问:
What's the difference between stateful and stateless?
The books and documentation on the MVC just heap on using the Stateful and Stateless terms. To be honest, i am just unable to grab the idea of it, what the books are talking about. They don't give an example to understand any of the either state, rather than just telling that HTTP is stateless and with ASP.NET MVC microsoft is going along with it. Am I missing some fundamental knowledge, as i can't understand what is stateful and why is stateful and same goes for stateless.

A simple and short example that talks about a control like button or textbox can be simplify the understanding i suppose.

答:
Stateless means that HTTP doesn't have built in support for states; e.g. you can't store if a user has logged in or done something else.

The most common solution is to use sessions to overcome that problem. This means that you have to be able to include a session identifier in each response or request. This is either done by creating a session cookie or by including the session identifier in all links.

WebForms tries to make all that transparent (using ViewState) while MVC forces you to handle it manually.

In your example you mentioned Buttons and TextBoxes. The easiest way to let them maintaining their state is simply to stop posting back the entire page. MVC got excellent support for ajax (through jQuery) and I suggest that you use ajax if you just want to do something on the current page.

OwnerDisplayName: Pankaj Upadhyay

OwnerDisplayName: jgauffin


答:
In my simple opinion the difference between ASP.NET (stateful) and ASP.NET-MVC (stateless) can be isolated to the fact that the first provides server-side controls and the other do not.

It is worth noting that the ASP.NET web forms approach is geared towards transitioning old VB and VC++ programmers who are used in the event model driven model to have a good quick way of learning web programming following the same event model paradigm, like you click a button and voila you trigger an event! All you need to do now is write your code in the event handler. Because of that ASP.NET needed to have concepts like view state and postbacks to monitor the state of the server side controls each round trip.

ASP.NET-MVC, however, does not use server-side controls so it doesn't have to maintain state. The MVC model separates the problem domain into the three partitions so that data is delivered to the client in a streamlined manner.

In summary, the server-side controls are what makes them different in as far as being stateful and stateless.

Title: What's the difference between stateful and stateless?

Body:
The books and documentation on the MVC just heap on using the Stateful and Stateless terms. To be honest, i am just unable to grab the idea of it, what the books are talking about. They don't give an example to understand any of the either state, rather than just telling that HTTP is stateless and with ASP.NET MVC microsoft is going along with it. Am I missing some fundamental knowledge, as i can't understand what is stateful and why is stateful and same goes for stateless.

A simple and short example that talks about a control like button or textbox can be simplify the understanding i suppose.

OwnerDisplayName: Ronald


答:
Wayne M's answer is great since it underlines the major problem of the WYSIWYG editors: they produce low quality code. From Microsoft FrontPage era to Macromedia Dreamweaver to Microsoft Expression suite to Adobe InDesign, every time the advertisement said that the new product is designed to produce high quality, clean HTML and CSS, and every time the next advertisement for the next product showed that the previous one was a lie.

But there is more. Not only they are not sophisticated enough to create a clean code, but they can't do it, and will never be able to do it. Never (of course, I'm not talking about the futuristic year 3000 computers smarter than any men). Why?

Because they take a wrong path from the beginning. Their idea: give a tool to a fool, and he would be able to do marvels with it and with no skills nor knowledge at all. This is not what happens in real life. I, as a developer, often work with inexperienced self-called designers. They don't know anything neither about the web in general, nor about HTML or CSS. When they give me their design, it's hugely difficult to do clean code. Often impossible. The only way is to change their design first.

I'm an human, so I can do it. On the other hand, a WYSIWYG software product would never dare changing the design made by a human. That's why those products would always produce bad code when being in hands of a person who does not understand how web pages are made. If they are used by an experienced developer who also knows how the visual design must be done in order to be easily transformed into an HTML and CSS code, then of course there are chances that the final code will be pretty clean. But I suspect that those real designers would find it easier to give their design to a programmer who will do the same work by hand, maybe optimizing what needs to be optimized.

This being said, the fact that WYSIWYG products will mostly produce bad code doesn't really matter. When creating those products, the companies are targeting the people who don't care about quality. What's the point in writing valid XHTML 1.1 code or in using CSS sprites or applying some optimization techniques to a small static website which will be used by a hundred of people per day? For those websites, quality doesn't matter.

And when quality matters, the websites will be done by hand, no matter how good WYSIWYG software is.


问:
Tips for achieving "continual" delivery
A team is experiencing difficulty releasing software on a frequent basis (once every week). What follows is a typical release timeline:

During the iteration:

Developers work on stories on the backlog on short-lived (this is enthusiastically enforced) feature branches based on the master branch.

Developers frequently pull their feature branches into the integration branch, which is continually built and tested (as far as the test coverage goes) automatically.

The testers have the ability to auto-deploy integration to a staging environment and this occurs multiple times per week, enabling continual running of their test suites.

Every Monday:

there is a release planning meeting to determine which stories are "known good" (based on the testers' work), and hence will  be in the release. If there is a known issue with a story, the source branch is pulled out of integration.

no new code (only bug fixes requested by the testers) may be pulled into integration on this Monday to ensure the testers have a stable codebase to cut a release from.

Every Tuesday:

The testers have tested the integration branch as much as they possibly can have given the time available and there are no known bugs so a release is cut and pushed out to the production nodes slowly.

This sounds OK in practise, but we have found that it is incredibly difficult to achieve. The team sees the following symptoms

"subtle" bugs are found on production that were not identified on the staging environment.

last minute hot-fixes continue into the Tuesday.

problems on the production environment require roll-backs which blocks continued development until a successful live deployment is achieved and the master branch can be updated (and hence branched from).

I think test coverage, code quality, ability to regression test quickly, last minute changes and environmental differences are at play here. Can anyone offer any advice regarding how best to achieve "continual" delivery?

答:
"subtle" bugs are found on production that were not identified on the staging environment -- in one of the projects with such issues I've seen this was quite successfully addressed by tactic I'd call double-issues. I mean for bugs like that, guys created two tickets in issue tracker: one was assigned to developers to fix the code, another one to testers to design and establish regression test or change in staging environment that would prevent repeating it in future. That helped to keep staging close enough to prod.

problems on the production environment require roll-backs -- if these are frequent then your weekly releases are actually fake - consider adjusting the frequency to level that really works. By fake I mean that if say one of two your weekly releases rolls-back it means that users face new (working) release once in two weeks - which is all that counts, not the number of times you deploy.

enthusiastically enforced feature branches -- does that mean that some time before, you also tried working on single branch and found it inferior? If yes then skip the rest. Otherwise, try working on single branch (if needed, google for branching strategy "development branch" or branching strategy "unstable trunk" for details). Or, if you use Perforce, search web for Microsoft guidelines on branching and merging. Try did I say that? sorry appropriate word should be test: I mean, 1) plan for when and how to measure whether single branch is better or not than one you have now and 2) plan for when and how you will switch back to feature branches in case if this testing fails.

PS.

Probably you can find more tricks like that by searching the web for something like software projects risk management

update

<copy from comments>

I perceive frequent hot-fixes to be a symptom of a broken test pipeline - is this not the case? Either way, they require repeated releases to get the hot fixes out making more work for the ops team. In addition, hot fixes are usually coded under extreme time pressure, meaning they will likely be of lower quality than normal work.

</copy from comments>

last minute hot-fixes -- above concerns look reasonable to me, as well as your reference to broken test pipeline. With this update, your prior note that new code integration is blocked on Monday sounds like one more symptom of broken (I think more precise word would be contended) pipeline. By contention I mean the following: you use single branch to concurrently serve two purposes: integration and release. When release approaches, these two purposes begin clashing with each other, pushing for conflicting requirements: integration purpose is best served with continuously open branch (Merge Early And Often) while release stability benefits from branch being sealed (isolated) as long as possible. A-ha it looks like puzzle parts start getting matched...

..Look, that Monday-freeze now looks like a compromise done to serve conflicting purposes: developers suffer from block of new code integration while testers suffer from this block being too brief, everyone is somewhat unhappy but both purposes are served more or less.

You know, given above I think your best bet would be to try releasing from dedicated branch (other than integration). Whether this branch would be long lived like integration or short lived like your feature branches (with "feature" being, well, release) - it's up to you, it just has to be separate.

Just think of it. Currently you find one day is not enough to conveniently stabilize release, right? with new branching strategy, you can just fork 2 days before release instead of one, no problem. If you find that even two days is not enough, try forking 3 days before, etc. Thing is, you can isolate release branch as early as you want because this won't block merging new code to integration branch anymore. Note in this model, there is no need to freeze integration branch at all - your developers can continuously use it, on Monday, Tuesday, Friday, whatever.

The price you pay for this happiness is complication of hotfixes. These would have to be merges in two branches instead of one (release+integration). This is what you should focus on when testing new model. Track all that is related - extra effort you spend on merging to second branch, efforts related to risk that one might forget merging to second branch - everything related.

At the end of testing, just aggregate what you tracked and learn whether amount of this extra effort is acceptable or not. If it is acceptable, you're done. Otherwise, switch back to your current model, analyze what went wrong and start thinking on how else you can improve.

update2

<copy from comments>

My aim is to get stories tested and deliverable (behind or infront of a config wall) within an iteration, this can only be achieved if the testers are testing work performed in-iteration (and not stabilizing code from the previous iteration).

</copy from comments>

I see. Well I don't have direct experience with that way but have seen in-iteration kind testing done successfully in a project related to ours. Since our project was following the opposite way I also had a luxury of face-to-face comparison for these opposite approaches.

From my perspective, out-of-iteration testing approach looked superior in that race. Yeah their project went fine and their testers detected bugs faster than ours but somehow this didn't help. Our project went fine too, and somehow, we could afford shorter iterations than them, and we had less (much less) slipped releases than them, and there was less tension between dev and testers at our side.

BTW despite faster detection at their side, we managed to have about the same average bug life span (life span is time between introduction and fix, not between introduction and detection). Probably we even had a slight edge here since with shorter iterations and less slipped releases we could claim that on average our fixes reach users faster than their.

Summing up, I still believe that isolation of release codeline has better chances to improve your team productivity.

on a further thought...

isolation of release codeline has better chances -- upon re-reading I feel this might make an impression that I discourage you from trying in-iteration testing. I'd like to make it perfectly clear that I don't.

In your case in-iteration testing approach looks safe to try (er... test) because you seem to have clear understanding of how to achieve it (smooth test pipeline) and what are major obstacles. And after all, you always have an option to fall-back to alternative approach if you find it too hard to get that pipeline right.

BTW regarding obstacles, additional ones worth keeping track in that case will be issues like failure to reproduce bug at dev side and late to find / late to verify fix at testers side. These might stuck your pipeline too, like it happens now with hotfixes.

OwnerDisplayName: Ben Aston

Title: Tips for achieving "continual" delivery


答:
Oh, well, from the point of view of people coming from outside... I can't really say (like all the others do) that programming is all about communication.

It's not really normal day to day communication based on reciprocal respect, and interests, and stakes... it's more about mind reading, kind of nursing, and some arguing is certainly involved. There's a lot of negotiating too, but not the kind you're probably used to.

You don't really sell sh-t to programmers, you must game them, or seduce them with heavy evidences and facts. While this may seem fair for mission critical relevant issues, apply that to petty nuisances no one, not even the one that raised it, really should have ever cared about, and... welcome to communication hell.

If you got a byte at the outside world (the selling stuff/closing deals/shaking hands world) it's really hard to adapt back to the kind of (somewhat juvenile, somewhat academic) interaction programmers experience across cubicles.

The business part of your curriculum will be wasted heavily, unless you'll find a way to climb the management ladder faster than a cat on fire.


问:
What is best practice on ordering parameters in a function?
Sometimes (rarely), it seems that creating a function that takes a decent amount of parameters is the best route.  However, when I do, I feel like I'm often choosing the ordering of the parameters at random.  I usually go by "order of importance", with the most important parameter first.

Is there a better way to do this?  Is there a "best practice" way of ordering parameters that enhances clarity?

答:
I've never seen a documented "best practice" regarding this particular topic, but my personal standard is to list them either in the order in which they will appear in the method they're being used for or if the method is more of a pass-through to a data layer I will list them in the order they would appear in the db schema or data layer methods.

Also, when there are multiple overloads of a method, I notice that the typical manner is to list them starting with parameters that are common to all (or most) of the methods with each different method being appended to the end for each method overload like:

```<code>void func1(string param) { }
void func2(string param, int param2) { }
void func3(string param, string param3) { }
void func3(string param, int param2, string param3) { }
</code>```

Body:
I've never seen a documented "best practice" regarding this particular topic, but my personal standard is to list them either in the order in which they will appear in the method they're being used for or if the method is more of a pass-through to a data layer I will list them in the order they would appear in the db schema or data layer methods.

Also, when there are multiple overloads of a method, I notice that the typical manner is to list them starting with parameters that are common to all (or most) of the methods with each different method being appended to the end for each method overload like:

void func1(string param) { }
void func2(string param, int param2) { }
void func3(string param, string param3) { }
void func3(string param, int param2, string param3) { }


答:
In general: use it.

Write a test for your function, a real world test.

Something you would actually like to do with that function.

And see in what order you did put those down.

Unless you already have (or know of) some functions that do something similar.

In that case: conform to what they do already, at least for the first arguments.

e.g. Do they all take a document/object/file-pointer/series-of-values/coordinates as the first argument(s)? For god's sake conform to those arguments.

Avoid confusing your coworkers and your future self.

Title: What is best practice on ordering parameters in a function?

Body:
Sometimes (rarely), it seems that creating a function that takes a decent amount of parameters is the best route.  However, when I do, I feel like I'm often choosing the ordering of the parameters at random.  I usually go by "order of importance", with the most important parameter first.

Is there a better way to do this?  Is there a "best practice" way of ordering parameters that enhances clarity?


答: I try to put the IN parameters first, OUT parameters second. There are also some natural ordering, e.g. createPoint(double x, double y) is strongly preferrable to createPoint(double y, double x).


答:
Communications skills are helpful, but technical competence trumps everything wrt to developers.

You probably would be happier as an applications engineer, that is, an engineer who helps customers adapt and utilize the software product produced by 'heads down' developers.  That way you work with software, but spend most of your day talking.


答:
I often follow the C/C++ convention of placing the const parameters first (that is, the parameters you pass in by value), and then those that you pass in by reference.  This may not necessarily be the correct method of calling functions but, if you are interested in how each compiler handles parameters, have a look at the following links for the rules governing and/or the order that parameters are pushed onto the stack.

http://msdn.microsoft.com/en-us/library/zthk2dkh%28v=vs.80%29.aspx

http://en.wikipedia.org/wiki/Calling_convention


答:
I usually go with these rules, though not always with the same precedence. I guess it's an automatic thought-process now, and I don't over-think it, except for public API design.

Selection Funnel

Semantics

Importance / Relevance

Frequency of Use

I/O Concerns

1. Semantics First

Especially in OOP, pick parameters based on their semantical significance for the action or message. The signature of a well-named method with a well-named parameter should:

feel natural to call,

be self-descriptive in terms of intent and behavior.

(For these reasons, sometimes using custom types or aliases instead of primitives might increase the expressiveness of your signature.)

2. Then Importance

The most "significant" parameter comes first (or next...)

3. Then Frequency

The frequency matters as well, especially in a language where you don't have named parameters but can have default values on positional parameters. That implies that the order of the parameters doesn't vary, and that obviously you cannot set the N + 1 parameters if you want to force the default value of the Nth parameter (except if your language has a concept of a place-holder parameter).

The good news for you is that usually, frequency relates to importance, so that goes hand in hand with the previous point. And then it's probably up to you to craft your API for it to have the appropriate semantics.

4. Let's Not Forget I/O

if your method/function takes some input and produces an output, and the latter is not to be "returned" (via a return statement) or "thrown" (using an exception system), then you're left with the option to pass values back to the caller using your other parameters (or the input parameter). That relates to semantics, and in most cases it will make sense to have the first parameters define the output, and the last parameters receive the output.

Additionally, an other approach to have less parameters and maximise semantics would be to use a functional approach, or to define a Builder pattern, so you can clearly stack up your inputs, define your outputs, and retrieve them when need be.

(Notice I don't mention global variables, because why would you use one, right?)

Some Things to consider

Usability

Most of the above will show naturally if you follow ZJR's advice: Use It!

Consider Refactoring

If you worry about parameter ordering, maybe this worry finds its root in the above and in the fact that your API is badly designed. If you have too many parameters, something can most probably be componentized/modularized and refactored.

Consider Performance

Keep in mind that some languages' implementations will incur very important impacts on your runtime memory management when using parameters. Hence the reason why many languages' style-books recommend to keep the parameter list simple and short. At 4 parameters max, for instance. I leave it as an exercise for you to figure out why.

Bevan's answer and mention of Clean Code's recommendations are definitely relevant as well!


答:
At your place (and I, sometimes, am one of those smartasses) I wouldn't remove it, but ask personally to the witty/clever author to document it very well in comments, and if possible, to include some discussion on alternative and simpler writings he could have used, with examples.

I would underline this is for the best, because even him will probably not remember all the bits and bobs there are, in those lines, in two months time.

He will probably drop the smart code in favor of the simplest one, as soon as he's forced to write it, as an example.

Why would that work.

You acknowledged you care about what he writes,

you showed him respect by asking,

by citing memory/focusing problems you devise and break down to him a scenario in which that code must be changed and cannot while he's still working for the company or the team

(without that last allusion this kind of request may be received as a try, on the company's side, to commoditize the programmer, making it interchangeable with any other code monkey at anytime)

Title: How to balance code quality vs strong developer personalities

Body:
On code reviews at work I have been seeing code & patterns that I consider "clever" though not necessarily adding to the overall quality or maintainability of the code base. I point this out on my feedback and am unconvinced by the counterarguments. I am a bit concerned when this code makes into into the repo and later to production.

I want to maintain a cohesive team, so I dont want to create tension by being too vocal about my reservations. I also want to create a great product for our customers without being too leninent.

Traditionally, who has 'veto' power on what gets checked in and how?

How can code that works, but its too involved/clever be removed without stepping on toes?


问:
Is Functional Programming possible in Java?
I was browsing through the Amazon.com Bookstore and I came across the book "Functional Programming for Java Developers".

I know some very basic Functional Programming and have been programming in Java for 3 years.

I would like to know is Functional Programming even possible in Java?

答:
I'm reading the book you mentioned. It is really good BTW.

Yes it is possible to be functional in Java. I don't know to which degree you can achieve it but you can implement many functional programming idioms.

One of the most important things is trying to code with "Don't mutate states" mentality.

For example you use the final keyword to achieve immutability. If you are going to use a data structure then you should code in immutable data structures. Google Guava library is already doing this.

Also for concurrent programming, you can rely on Akka framework (the actor model).

It is worth mentioning that the JVM bytecode doesn't support (at least yet) Tail-call optimization, a very important feature for functional programming languages.


问:
Do I need to deal with the situation where private methods are called through reflection?
When creating a library, must I ensure that the private methods must work as expected when called not by other methods of the same class, but by another library through reflection?

For example, if a private method private DoSomething(int number) expects that:

number is a positive non-zero integer, and:

a private variable string abc is not null and not an empty string,

and completely, ugly fails if those two conditions are not matched, must I handle those failures even if I know that all methods in the class will always¹ assign a non-empty value to abc before calling DoSomething, and pass a positive non-zero integer to this method?

In other words, is the code which is not protected against unsafe calls through reflection can be considered as low quality code, or it belongs to the caller who uses reflection to ensure that the call does not break anything?

Note: my question covers only a standard set of libraries. This does not cover code which must be highly secure (i.e. when somebody may be interested by using reflection in order to make it behave unexpectedly or crash).

¹ Because the class is correctly documented, because there are enough unit tests to be sure that any other developer will not break this method, etc.

答:
By marking your method private you established your intentions and a contract. By using reflection a client code can choose to break with this contract and consequently will have to bear the consequences. The same thing happens with protocols, for things to work rules must be followed or bad things will happen.

The same problem may occur with other languages such as C++ where I saw things like

```<code>#define private public
</code>```

In summary - you are NOT required to deal with these situations, the caller should know better.

Body:
By marking your method private you established your intentions and a contract. By using reflection a client code can choose to break with this contract and consequently will have to bear the consequences. The same thing happens with protocols, for things to work rules must be followed or bad things will happen.

The same problem may occur with other languages such as C++ where I saw things like

#define private public

In summary - you are NOT required to deal with these situations, the caller should know better.


答:
It depends what you mean by "functional programming" and by "possible".

You can obviously implement things following a functional paradigm. However the Java language doesn't provide the syntactic sugar for it, so some things will be tedious at best, and some other ones will be extremely arcane.

Similarly, you can very well write object-oriented code in a language recognized as being non-OO, like C.

Java Libraries

There are libraries that can help you do this, by already doing the legwork for you and hiding the arcane things:

mature/established libraries:

Functional Java

Google guava

LambdaJ

more obscure/experimental libraries:

Fun4J (also comes with a lisp to bytecode compiler)

JCurry

OCaml-Java

Jambda

Bolts

Functional Java (swensen.functional)

These will allow you to write Java code with a more functional approach and possibly more familiar syntax and semantic, as you'd expect from an FP-competent language. Within reason, that is.

JVM Languages

And obviously, you can implement a functional language on top of Java. So that you can then use that one as your FP language. Which is a bit of a higher-level of abstraction than what you asked for, but relatively within context (though I'm cheating a bit here, granted).

For instance, check out:

quite mature languages:

Clojure

Scala

less mature or active / more obscure languages:

Haskell-based:

Frege

Jaskell

Scheme-based:

Bigloo (targets R5RS)

Kawa (targets R6RS)

SISC (targets R5RS)

JScheme (targets R4RS)

ML-based:

Yeti

More-or-Less Functional JVM Languages

While they may not be exactly what you want, there are a number of other languages that have been ported to the Java Platform and that might free you from Java's relatively not so fun-oriented (yes, pun intended) nature and already give you more flexibility. Notable contenders like JRuby, Jython and Rhino (respectively for Ruby, Python and JavaScript / ECMAScript) also offer interesting potential for functional programming, though they arguably aren't really functional programming languages by nature. JetBrains' Kotlin, while clearly acknowledging it isn't a functional language, does support some functional constructs and is also worth a look.

Further Reading

You may also want to read or watch these articles or videos:

Functional Progamming in the Java Language, IBM DeveloperWorks (2004)

Functional Programming Java, Lambda the Ultimate (2004)

Functional Programming: a Pragmatic Introduction, InfoQ/CodePalousa (2011)

and related StackOverflow questions like this one

Title: Is Functional Programming possible in Java?

Body:
I was browsing through the Amazon.com Bookstore and I came across the book "Functional Programming for Java Developers".

I know some very basic Functional Programming and have been programming in Java for 3 years.

I would like to know is Functional Programming even possible in Java?


答:
I usually just go with the "what looks less cyprtic" parameter ordering.  The fewer times that I need to go to the method/function definition the better.  And it's nice to have named parameters that are descriptive as to what they are used for, that way when the little tooltip pops up (VS) then it makes it even easier.

If you have lines and lines of parameters you may want to consider a different design.  Step back and see how you can break that up into more functions/methods.  Just an idea, but when I have a dozen parameters in my function it's almost always not a parameter issue, but a design issue.


答: Order: input(s), output(s), optional parameters.</p>


问:
Are design patterns generally a force for good or bad?
I've heard it argued that design patterns are the best thing since sliced bread.  I've also heard it argued that design patterns tend to exacerbate "Second System Syndrome," that they are massively overused, and that they make their users think they're better designers than they really are.

I tend to fall closer to the former camp, but recently I've been seeing designs where nearly every single interaction is replaced with an observer relationship, and everything's a singleton.

So, considering the benefits and problems, are design patterns generally good or bad, and why?

答:
I will prefer those in the middle. Like the poster rightly pointed out, an understanding of patterns does not make you a good developer. On the other hand an understanding of pattern will help you become a good developer. </p>

<p>Understanding the relationship of patterns and seeing a pattern in a project (while at the conception stage) is what will make you a good developer. </p>

ContentLicense: CC BY-SA 2.5

Body:
I will prefer those in the middle. Like the poster rightly pointed out, an understanding of patterns does not make you a good developer. On the other hand an understanding of pattern will help you become a good developer.

Understanding the relationship of patterns and seeing a pattern in a project (while at the conception stage) is what will make you a good developer.

OwnerDisplayName: gozie


答:
I can definitely relate to this question. I'm currently the technical lead for 2 teams and it's my job to ensure the code we produce is as readable and maintainable as possible. At the same time I've been known to produce some "clever" code and I know most of my teammates will have very hard time follow it.

Few observations I can offer:

You team needs one lead who will make the ultimate decision when there is a disagreement. In the last release I was on a team without leadership and it was atrocious. Everything became an argument, and if you have few people with strong personalities neither one of them will budge. If you do have a lead, regardless if which decision is chosen, everyone on the team MUST understand that what the lead says goes.  That's why management made him the lead.

Keeping people happy is very important. Therefore, instead of pushing the entire team towards your viewpoint, just nudge them there.  Explain SOLID principles, explain importance of small and cohesive classes/methods/interfaces and repeat these things every time you see them being violated (i.e. in a code review).  At the same time, don't make them rewrite every single thing you don't like.  At the end of the day, you need a balance between personal expression vs. following group standards.  Hopefully, the two will converge as personal preferences shift towards how the group in general is operating.

I believe it is much more important to have clean, easy to understand class interfaces, than not to ever have any "clever" code.  For example, we have a class that maintains a list of entries which are looked up 3 different ways.  Currently it simply uses linear search for all lookups which works on a small scale, but because this class is at a very low level, I see it not scaling very well.  I'm about to replace it with a different class, that uses Boost Intrusive containers.  Each element will support being placed into each of the indexes simultaneously and all lookup will be done in O(sqrt(N)).  Yes it will be much more complicated on the inside and a lot of people don't like Boost, but on the outside it will remain 3 methods: Add, Remove, Get.  Bottom line is that people can write whatever code they want (within reason), but interfaces MUST not be clever.

Maintain the idea of code ownership.  Although it is sometimes difficult to achieve as different people might need to add/modify some code.  When the code is written, the original developer is the ultimate keeper of that code. That doesn't mean no one else can touch it.  If others modify their code, that's fine, but at the end of the day original developer reviews it and remains being responsible for whatever goes in there. Whether that code is simple or clever, it is his baby.  If/when, as you are predicting, bugs start piling up because of the design/coding decisions that were made, instead of simply fixing those bugs as they come in, sit down with that developer (who btw should be fixing all those bugs) and reflect on those decisions to see how they could have been made differently. Then give him a book on refactoring and see how you can "unclever" some of it.


问:
Are rollback and roll-forward transactions equivalent for fault tolerance?
I've been reading about systems that employ transactions to provide fault-tolerance -- SQLite, for instance, implements a journal that allows the database to be rolled back to a known state in case of a failure.

Most of the systems I've been reading about write the current state to the journal and use this to roll back when required. I have found far fewer examples where the next state is journalled and used to complete the transaction after a failure.

Are there some good examples out there of systems that employ roll-forward transactions? Are there reasons to choose a roll-forward design over one that rolls back?

答:
Most database schemes use both!

RollBack is the process of undoing changes and reverting to a previous state. This usually occurs either on request when a program detects some logical error and decides the transaction should not take place, or, when the DBMS loses contact with the program before an explicit "COMMIT" has been requested.

RollForward occurs when the database restarts after an abnormal shutdown. Its a process of going to the log files and applying changes from the log files to the underlying database. In the case where the underlying tables have been restored from an old backup this can involve millions of updates and take several hours.


答:
I'd respectfully submit that worrying about parameter ordering is worrying about the wrong thing.

In Uncle Bob's book "Clean Code" he advocates, persuasively, that methods should never have more than two arguments - and most should have only one, if any. When this is the case, ordering is either obvious or unimportant.

However imperfectly, I'm trying to follow Uncle Bob's advice - and it's improving my code.

In the rare cases where a method seems to require more information, introducing a parameter object is a good idea. Usually, I find this is the first step towards discovery of a new concept (object) that's key to my algorithm.

ContentLicense: CC BY-SA 4.0


答:
Well, all sorts of things are possible. It's possible to do object-oriented programming in C; it's just not a very good idea.

Java wasn't designed for FP, so if you're trying to do everything in a purely-FP style, you'll have problems. You'll be fighting the language, instead of working with it. And not just the language - there's also all the wonderful free Java libraries. So don't go for pure FP; take some of the ideas behind FP and integrate them into your Java code, but understand that you can't do that to all the ideas.


答:
It is possible to be somewhat functional in Java.  Doing so is seriously painful.  Instead of

```<code>myList.each { doSomething(it); }
</code>```

You have something like:

```<code>myList.each(new Function() { public void do(Object arg) { something(); }})
</code>```

And if you want true functional programming, with closures and functions as first class objects, pick another language.  Scala, Clojure, Groovy all run on the JVM and can interact with legacy Java classes.  .

Body:
It is possible to be somewhat functional in Java.  Doing so is seriously painful.  Instead of

myList.each { doSomething(it); }

You have something like:

myList.each(new Function() { public void do(Object arg) { something(); }})

And if you want true functional programming, with closures and functions as first class objects, pick another language.  Scala, Clojure, Groovy all run on the JVM and can interact with legacy Java classes.  .