答:
I just read the article link you posted, I have to say Fowler has made some very good points and a lot of things he said, I've been advocating with our team for years.

IMO, if you do any decent design, you should not get into what would be considered a dead-end situation. I've always viewed software as made up of building blocks. I still believe in some up-front design, but the main goal is not to design the entire product, but to provide overall architecture/direction so your team can visualize a common picture that we are all working towards. If you have a bunch of cube and triangle pieces, it's helpful to sketch out how a castle would be put together before you simply start slapping pieces together.

Since I come from OO land, to me each block is a class and the surface area of that block is the public interface (what is visible by external or deriving classes). If you follow good SOLID principles, you will make sure that each block as extremely simply and has an intuitive public interface.  Going back to my analogy, you want to make sure you code only creates simple shapes.  Whenever you create classes, that are too complex (many functions, many variables), you creating shapes which are hard to reuse when requirements change.

I agree with Fowler in that the biggest risk/challenge for evolutionary design is that you leave design decisions to coding time, and you expect each individual developer to make those decisions. This is where the system can break down if you don't have proper feedback mechanisms in place.  Whenever a new feature is asked for, it is extremely tempting to simply find the function that needs to be extended, put some kind of conditional inside it and just add a whole bunch of code right inside that function.  And sometimes, this might be all that's needed, but this is also (IMO) the single most common practice that leads to dead-end components. This has nothing to do with evolutionary design.  This is what's called "no design".

As long as you take the time to step back and say, wait a minute, this class already has 15 member variables, let me extract 6 of these and put into their own self-contained class, your software will be made up of very light-weight, flexible and reusable building blocks.  Sure if PMs come along and change half the products requirements on you, you may have to take some of your blocks out, put them back on the shelf and draw up some new ones (just like when building a castle, you may not use all your cylinders). But at that point, that's just part of doing business.  Requirements changed and by keeping your code flexible and modular, you should be able to change your product to align with your new business direction.

I believe this evolutionary approach to design works with every level of engineer's skill.  Personally, I've done software for a very long time and before our team moved to agile methodology, I was responsible for shipping several major components from my dev PC almost directly to the customer with barely any QA.  At the same time those components have always remained flexible and maintainable.

I'm only trying to say that I'd consider myself relatively decent at designing software. At the same time, if you asked me to write up a 100-page design document, give it to a coder and expect it to work, I probably couldn't design myself out of a paper bag.  When starting work, I would sometimes sketch out few UML-like (very simplified, not full language) diagrams, but as I start coding, I would refactor on as-needed basis and my final code would never look like what I originally drew. Even if I spend a month or two thinking about every little detail, I can't imaging someone else being able to take my diagrams and come up with solid piece of software without modifying the design as they are coding.

On the other end of the spectrum, currently in my team (now agile and I fully support that) we have a couple of guys who joined us from embedded land where they have only done C for the last 15 years. I obviously helped with some initial planning and laying out classes but I also made sure to follow up with regular code reviews and brainstorming sessions where we discuss applications of SOLID and design principles. They did produce some spaghetti code that made me cringe a little, but with just a slight nudge from me, they started refactoring what was already produced and the funny part is that one of them came back to me few days later and says, I hate to say it but after moving that code out, this looks so much more readable and understandable. Dead-end averted. Point I'm trying to make is that even someone who is completely new to OO can produce somewhat decent code, as long as he has a mentor with more experience, to remind him that "evolutionary design" is not same thing as "no design".  And even some of his "more complex" classes aren't that scary because each class doesn't have that much responsibility (i.e. not that much code), so worst comes to worse, if that one class "dead-ends", we chuck it and write a replacement class that has same public interface (so far I never saw a need for this contingency in anything we wrote and I've been doing code reviews twice a week).

As a final note, I'm also a firm believer in design documents (at least for the business conditions of my current team) but the primary goal for our design docs is Organizational Memory, so actual documents are written after the code is produced and refactored. Before coding, we generally have a quick (sometimes not so quick) design phase where we sketch out classes on napkins/mspaint/visio and I always remind people that this phase produces a path to follow, not a blueprint and as they start coding, anything that doesn't make sense should be changed.  Even with these reminders, newer guys tend to try to back fit code into original design no matter how unnatural it feels even to them. This usually surfaces in code reviews.

Dang, I wrote a lot.  Sorry about that.


问:
Are there any surveys on to what degree developers like or hate scrum?
Background:
During a conference an analyst pointed out in a tweet that developers hate scrum.

Myself and another person responded that this was not the case, and started discussing different scenarios on why developers would dislike scrum.

One of the scenarios where that lazy developers are not able to hide in a scrum project. They are constantly challenged by the team to contribute.

This discussion resulted in a blog post and video
http://elsewhat.com/2010/05/20/lazy-developers-hate-agile-and%C2%A0scrum/

I've gotten three comments which I've tried to answer in a neutral way, but they comments do point out that there are some people who loathe scrum (and I am always 100% certain they are not lazy developers).

Question

Have there ever been a survey among developers on to what degree developers like or hate scrum ?

答:
Meta-comment: It would be cool to have survey questions on Programmers.

Since Scrum varies so much between different teams and different organizations this question is going to be very difficult to answer.  Scrum should be about empowering the team to deliver great software and developers should like that.

Where does it go wrong?
The answer is in my statement above.  The team is not empowered or great software is not delivered.

There are so many failure modes, here are some:

The product owner does not understand the customer or the business.

The team does not understand the customer or the business.

Organizational issues stand in the way of the team's accomplishing their goals.

Scrum turns into a day-by-day micro-management.

Those are sometimes known as scrum-buts.

IMO Scrum is more likely to be liked/successful if:

The team has made the decision to adopt Scrum because it felt it was appropriate for the product/project.

There is strong/continuous feedback from the customer through the product owner.

Ship after every sprint.

The team has autonomy, is self-organizing and full trust/support from the organization.

A large percentage of items in the backlog come from the team.

Another comment is that in Scrum "lazy" programmers are only accountable to the team so they may prefer that to being accountable to their boss.  At any rate, I don't think this is a factor.

A problem I see with Scrum is the chicken and egg problem.  If you are already agile you may not need Scrum.  If you are inherently un-agile Scrum will probably not change it, it may even make things worse because it will bring any agility to the surface and make it so visible that the anti-agile forces can squash it :-)

Can a non-agile organization just turn agile?  I don't know.  I think Scrum wants to do that but I'm not sure it can.

ContentLicense: CC BY-SA 2.5

ContentLicense: CC BY-SA 3.0


问:
What are Silverlight, WCF RIA services or applications?
I asked a question here on programmers yesterday about learning HTML & CSS and the community was pretty generous to provide great answers. One of the answers was given by Emmad Kareem and that was : "if you can't do HTML, don't give up. Consider using Silverlight".

This answer made me visit Silverlight.net and I came across the terms WCF RIA Services, Silverlight applications. After going through the website and some articles on website i am unable to draw a conclusive understanding on what this is all about.

Is this another way of building websites using .NET, and is just like another framework like ASP.NET MVC3. What scenario's and requirements are basically targeted to silverlight applications or we are free to use either of Asp.net MVC or Silverlight in any web-application requirements.

答:
On Silverlight, Wikipedia tells us (emphasis mine):

Microsoft Silverlight is an application framework for writing and running rich internet applications, with features and purposes similar to those of Adobe Flash. The run-time environment for Silverlight is available as a plug-in for web browsers running under MS Windows and Apple OS X.

And on WCF RIA Services, MSDN tells us (emphasis mine):

WCF RIA Services simplifies the development of n-tier solutions for Rich Internet Applications (RIA), such as Silverlight applications.
  ...
  To create the best user experience, you want your RIA Services client to be aware of the application logic that resides on the server, but you do not want to develop and maintain the application logic on both the presentation tier and the middle tier. RIA Services solves this problem by providing framework components, tools, and services that make the application logic on the server available to the RIA Services client without requiring you to manually duplicate that programming logic. You can create a RIA Services client that is aware of business rules and know that the client is automatically updated with latest middle tier logic every time that the solution is re-compiled.

Silverlight is an application development platform that's very similar to Adobe Flash and WCF RIA Services is a set of components and a software development toolkit that provides for Silverlight applications to maintain the application logic on both the presentation tier and the middle tier.

The main difference between Silverlight and ASP.Net is that Silverlight applications are vector applications that require a browser plugin to work, whereas the final product of applications built on ASP.Net (what reaches the browser) is a combination of HTML, CSS and JavaScript. Silverlight does not directly compare to ASP.Net MVC, but WCF RIA services might as like ASP.Net MVC is a framework that extends its target platform.

As for the various terms you mention, Silverlight applications are of course applications built on Silverlight, and WCF RIA Services applications or WCF RIA applications are applications built on Silverlight that utilize the extended functionality of WCF RIA Services.

You can watch this interesting video and read this related StackOverflow question to learn more about WCF RIA and you can download the stand alone installer for the WCF RIA toolkit from silverlight.net. By the way, WCF stands for Windows Communication Foundation.


问:
Should service test classes connect to the database
I want to know if the service test classes should use real DAO objects and connect to the database or it should use mock objects to test only the business logic it do?</p>

答:
Your test classes shouldn't connect to the database if you are testing only the business logic, you should use mocks instead.

This way is faster since the tests don't open and close connections and database independent ( you can run the tests without any database. )

If you want to test the DAO objects and the connections to the database then you should have other tests doing that.


问:
What do you do if you reach a design dead-end in evolutionary methods like Agile or XP?
As I was reading Martin Fowler's famous blog post Is Design Dead?, one of the striking impressions I got is that given the fact that in Agile Methodology and Extreme Programming, the design as well as programming is evolutionary, there are always points where things need to get refactored.

It may be possible that when a programmer's level is good, and they understand design implications and don't make critical mistakes, the code continues to evolve. However, in a normal context, what is the ground reality in this context?

In a normal day given some significant development goes into product, and when critical change occurs in requirement isn't it a constraint that how much ever we wish, fundamental design aspects cannot be modified? (without throwing away major part of the code). Is it not quite likely that one reaches dead-end on any further possible improvement on design and requirements?

I am not advocating any non-Agile practice here, but I want to know from people who practice agile or iterative or evolutionary development methods, as for their real experiences.

Have you ever reached such dead-ends? How have you managed to avoid it or escaped it? Or are there measures to ensure that design remains clean and flexible as it evolves?

答:
I refactor my projects permanently and also use UML class diagrams. I mean that I create one or more class diagrams by packages. Each diagram is saved at the root of the package. Each UML classifier has an own Id which is mapped to the related Java Id. It means that when I open my diagram it is automatically updated to the latest code refactoring changes. I can also directly change my class diagrams at graphical level and all my project is immediately refactored. It works pretty well but it will never replace human. My UML class diagram is also only a graphical view of my code. It is very important not to be mix code and model like EMF eclipse is doing because as soon as refactoring is done then model information is also lost.
I never use Model Driven Development code generator because this is useless. I don't like model drives my code but my code drives my UML class diagrams.

Having said that having over 100 class diagrams representing all details of my project structure and full of notes everywhere is really helpful. I only create class diagrams for projects because usually developers don't have time to learn or use other diagrams. Class diagrams are also so good because automatically updated. Class diagrams can be created after the code by just reversing a package and adding notes. It is fast and always accurate and 100% iterative.

Please don't make confusing between model driven development which is a model generating code and usually using UML as graphical presentation with UML class diagrams updated from the code. Only UML synchronized code has a real value for me if multiple iterations.

Sorry to be so long but I think we should give a second chance to UML class diagrams if only used as a graphical view of our project. It means that UML covers the full project and have a single model composed by large class diagrams representing the full project. It would be ridiculous to have hundred of small views and a model for each view within a project having hundred of views :-)


问:
Best Practices for Handing over Legacy Code
In a couple of months a colleague will be moving on to a new project and I will be inheriting one of his projects. To prepare, I have already ordered Michael Feathers' Working Effectively with Legacy Code.

But this books as well as most questions on legacy code I found so far are concerned with the case of inheriting code as-is. But in this case I actually have access to the original developer and we do have some time for an orderly hand-over.

Some background on the piece of code I will be inheriting:

It's functioning: There are no known bugs, but as performance requirements keep going up, some optimizations will become necessary in the not too distant future.

Undocumented: There is pretty much zero documentation at the method and class level. What the code is supposed to do at a higher level, though, is well-understood, because I have been writing against its API (as a black-box) for years.

Only higher-level integration tests: There are only integration tests testing proper interaction with other components via the API (again, black-box).

Very low-level, optimized for speed: Because this code is central to an entire system of applications, a lot of it has been optimized several times over the years and is extremely low-level (one part has its own memory manager for certain structs/records).

Concurrent and lock-free: While I am very familiar with concurrent and lock-free programming and have actually contributed a few pieces to this code, this adds another layer of complexity.

Large codebase: This particular project is more than ten thousand lines of code, so there is no way I will be able to have everything explained to me.

Written in Delphi: I'm just going to put this out there, although I don't believe the language to be germane to the question, as I believe this type of problem to be language-agnostic.

I was wondering how the time until his departure would best be spent. Here are a couple of ideas:

Get everything to build on my machine: Even though everything should be checked into source code control, who hasn't forgotten to check in a file once in a while, so this should probably be the first order of business.

More tests: While I would like more class-level unit tests so that when I will be making changes, any bugs I introduce can be caught early on, the code as it is now is not testable (huge classes, long methods, too many mutual dependencies).

What to document: I think for starters it would be best to focus documentation on those areas in the code that would otherwise be difficult to understand e.g. because of their low-level/highly optimized nature. I am afraid there are a couple of things in there that might look ugly and in need of refactoring/rewriting, but are actually optimizations that have been out in there for a good reason that I might miss (cf. Joel Spolsky, Things You Should Never Do, Part I)

How to document: I think some class diagrams of the architecture and sequence diagrams of critical functions accompanied by some prose would be best.

Who to document: I was wondering what would be better, to have him write the documentation or have him explain it to me, so I can write the documentation. I am afraid, that things that are obvious to him but not me would otherwise not be covered properly.

Refactoring using pair-programming: This might not be possible to do due to time constraints, but maybe I could refactor some of his code to make it more maintainable while he was still around to provide input on why things are the way they are.

Please comment on and add to this. Since there isn't enough time to do all of this, I am particularly interested in how you would prioritize.

Update: As the hand-over project is over I have expanded this list with my own experiences in this answer below.

答:
I am in same situation where our Architect moved to Australia and left over lot of legacy as he was with company from last 8 years. He him self inherited legacy stuff from previous Architect who was a contractor.

You and others have  already mentioned good points but here is problems we faced after he left
may be you can prepare better ...

1) (Technical Person) Contact details of the customers he is dealing with.

2) His account under which he bought softwares licences , keys which need be renewed every year and processes/costs to renew them.

3) Document of Setup of third party software libraries/components and products which integrate with your products.
We struggled for 4 days to bring back a machine which was lost due to IT clearing up space and some wrong instruction passed to them.

4) Documents/steps he is used to deposit source code to software Deposit companies eg Escrow.

5) There is still long list but may not be applicable to you also No amount of documentation can replace a real person so Keep his details handy , stay in
nice terms  and good luck :)

Also I dont know if this is first time for you. For me I have worked with 5/6 employers and have always inherited code with bad documentation or no documentation at all.
So along with all the documentation just stay positive :)

OwnerDisplayName: PersonalNexus


答:
As an alternative to Thanos Papathanasiou answer, I've seen some DAO objects unit test using in memory database such as SQLite. It's very fast and safe testing.

An example of it testing nHibernate (ORM) can be found on Ayende blog post. Check the same method with Django.

Title: Should service test classes connect to the database

Body: I want to know if the service test classes should use real DAO objects and connect to the database or it should use mock objects to test only the business logic it do?</p>


问:
When can I be sure a directed graph is acyclic?
The definition for directed acyclic graph is this: "there is no way to start at some vertex v and follow a sequence of edges that eventually loops back to v again."

So far so good, but I am trying to find some premises that will be simpler to test and that will also guarantee the graph is acyclic. I came up with those premises, but they are pretty basic so I am sure other people figured it out in the past (or they are incorrect). The problem is I couldn't find anything related on books/online, hence why I decided to post this question.

Premise 1: If all vertices of the graph have an incoming edge, then the graph can't be acyclic. Is this correct?

Premise 2: Assume the graph in question does have one vertex with no incoming edges. In this case, in order to have a cycle, at least one of the other vertices would need to have two or more incoming edges. Is this correct?

答:
Yes, both of your premises describe necessary conditions for a cyclic graph. However, they only exclude trivial graphs from cycle analysis, and you'll want to use one of the standard algorithms to make sure a given graph is actually cycle-free.

There are actually fairly cheap algorithms for detecting cycles in graphs; if you are performing a topological sort on a graph, for example, you'll detect cycles during the sort. The exact choice of algorithm naturally depends on your graph (one outgoing edge or multiple?) and your requirements.


问:
How to you "sell" support as an career option
We find it relatively easy to hire developers to work on various projects.

The problem arises when the project is finished but still needs to be supported.

We really battle to get people to join the support team. It's seen as dead-end, career-limiting, boring, second-class etc.

Currently, we get round this by getting the project team to assign some of their team to the support team for a while. Part of the assignment is to do a "brain dump" of the project so that the support team understands it. This works as long as the assignment is only for a fixed period.

Trying to hire people to work in support full-time is a problem. There are few applications and the calibre is not particularly high.

(The financial reality though is that support can be very lucrative for a company and once you get a reputation, you get approached by other companies to do their support even though you weren't involved in the original development.)

答:
Make the support job fun and valuable to your developers.

I love to do support for the following reasons:

I talk with people all around the world. I made many friends like that. Few years ago, one of my customer invited me to his wedding! I used to have a map of the world in my office with pins that located them.

Support is almost the best get gratifications for your work. When you make users happy, it really makes you happier too.

Complaints are useful way to improve yourself. I take any complaint seriously, and in most case, I can convert someone angry into an happy customer/user that will eventually spread the word around.

It helps me understand what customers/users need. Then I can build better software.

That's just few reasons.

Regarding support itself, I suggest to implement an easy to manage process.

When we get a support case, we do the following:

If it's a reproducible bug, we add it into the backlog and give its ID to the customer/user. We also take the ID of the customer/user to notify him of resolutions and release personnaly. This is easy if you collect his email directly.

If it's a problem using the software, we take this as an opportunity to improve the documentation. Any answer is written like a knowledge base article that we add in our database afterwards. It takes triple the time to write, but we don't repeat ourselve later (most users prefer browsing in KB).

If it's a feature request we connect the user with the product owner directly. This is very valuable. Of course we use systems like uservoice.com, but talking with the user directly is a lot better.

If it's a complaint we try to manage that outside the process. People that complaint like to be considered as important (even if the complain is trivial).


问:
The perfect crossfade
I find it hard to describe this problem in words, which is why I made a video (45 seconds) to illustrate it. Here's a preview of the questions, please have a look at it on Vimeo: http://vimeo.com/epologee/perfect-crossfade

The issue of creating a flawless crossfade or dissolve of two images or shapes has been recurring to me in a number of fields over the last decade. First in video editing, then in Flash animation and now in iOS programming. When you start googling it, there are many workarounds to be found, but I really want to solve this without a hack this time.

The summary:

What is the name of the technique or curve to apply in crossfading two semi-transparent, same-colored bitmaps, if you want the resulting transparency to match the original of either one?

Is there a (mathematical) function to calculate the neccessary partial transparency/alpha values during the fade?

Are there programming languages that have these functions as a preset, similar to the ease in, ease out or ease in out functions found in ActionScript or Cocoa?

Update: In addition to the video, I've made a sample project (requires Xcode and iOS SDK) and posted it on github. It shows the same animation as the video but this time with squares: https://github.com/epologee/StackOverflow-Example-Code

答:
I don't know what the name might be in the realm of video editing, but I'd call the curve an S-curve or sigmoid curve. It should be very simple to produce the cross-fade you're looking for in iOS using Core Animation's kCAMediaTimingFunctionEaseInEaseOut timing function. Just animate the alpha property of two views in opposite directions (one 0->1, one 1->0) using that timing function:

```<code>[UIView beginAnimations:@"crossfade" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
view1.alpha = 0.0;
view2.alpha = 1.0;
[UIView commitAnimations];
</code>```

Note: You should really use the blocks-based animation methods instead of UIView's convenience methods. I used UIView's methods above because it's very easy to understand, and easy to type from memory. Using blocks isn't much more difficult, though.

Addendum: If you don't like UIViewAnimationEaseInOut, you can create your own timing function as described in Timing, Timespaces, and CAAnimation. That's a bit more advanced than the simple animation illustrated above, but it gives you all the control you want.

Title: The perfect crossfade

Body:
I don't know what the name might be in the realm of video editing, but I'd call the curve an S-curve or sigmoid curve. It should be very simple to produce the cross-fade you're looking for in iOS using Core Animation's kCAMediaTimingFunctionEaseInEaseOut timing function. Just animate the alpha property of two views in opposite directions (one 0->1, one 1->0) using that timing function:

[UIView beginAnimations:@"crossfade" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
view1.alpha = 0.0;
view2.alpha = 1.0;
[UIView commitAnimations];

Note: You should really use the blocks-based animation methods instead of UIView's convenience methods. I used UIView's methods above because it's very easy to understand, and easy to type from memory. Using blocks isn't much more difficult, though.

Addendum: If you don't like UIViewAnimationEaseInOut, you can create your own timing function as described in Timing, Timespaces, and CAAnimation. That's a bit more advanced than the simple animation illustrated above, but it gives you all the control you want.


问:
Is it bad practice for services to share a database in SOA?
I have recently been reading Hohpe and Woolf's Enterprise Integration Patterns, some of Thomas Erl's books on SOA and watching various videos and podcasts by Udi Dahan et al. on CQRS and Event Driven systems.

Systems in my place of work suffer from high coupling. Although each system theoretically has its own database, there is a lot of joining between them. In practice this means there is one huge database that all systems use. For example, there is one table of customer data.

Much of what I've read seems to suggest denormalising data so that each system uses only its database, and any updates to one system are propagated to all the others using messaging.

I thought this was one of the ways of enforcing the boundaries in SOA - each service should have its own database, but then I read this:

https://stackoverflow.com/questions/4019902/soa-joining-data-across-multiple-services

and it suggests this is the wrong thing to do.

Segregating the databases does seem like a good way of decoupling systems, but now I'm a bit confused. Is this a good route to take? Is it ever recommended that you should segregate a database on, say an SOA service, an DDD Bounded context, an application, etc?

答:
I've seen the worst possible nightmares in software architecture due to data integration, and the best weapon against this type of mess that I've encountered so far id DDD-Style Bounded Contexts. Which is not very far away from "SOA done right", on a certain sense.

However, data itself is not the best way to attack the problem. One should focus on the expected/needed behavior and bring the data where it matters. We might end up having some duplication this way, but this is not normally an issue compared with the blocks to system evolution almost always associated with data-integrated architectures.

To put it simple: if you are looking for loosely coupled systems, don't stay coupled on the data. Go for weel encapsulated systems and a well-structured communication channel in between, acting as "lingua franca".


答:
a simple test would be

let S be the set of all nodes with no incoming paths (if there aren't you have a cycle)

take out a node P out of S and add all nodes directly accessible to B and mark P traversed,

if one of the added nodes is marked traversed you have a cycle

find all nodes in B with only incoming  paths from nodes that are marked traversed and add them to S

repeat 2 and 3 until S is empty

if there are nodes that are not traversed you have a cycle

loop invariant: S has only nodes that are proven to not be part of a cycle (only incoming paths form those that are not part of a cycle)

this is O(n*k) with k the average number of outgoing paths from a node

Title: When can I be sure a directed graph is acyclic?

Body:
The definition for directed acyclic graph is this: "there is no way to start at some vertex v and follow a sequence of edges that eventually loops back to v again."

So far so good, but I am trying to find some premises that will be simpler to test and that will also guarantee the graph is acyclic. I came up with those premises, but they are pretty basic so I am sure other people figured it out in the past (or they are incorrect). The problem is I couldn't find anything related on books/online, hence why I decided to post this question.

Premise 1: If all vertices of the graph have an incoming edge, then the graph can't be acyclic. Is this correct?

Premise 2: Assume the graph in question does have one vertex with no incoming edges. In this case, in order to have a cycle, at least one of the other vertices would need to have two or more incoming edges. Is this correct?


问:
Object oriented EDI handling in PHP
I'm currently starting a new sub project where I will:

Retrieve the order information from our mainframe

Save the order information to our web-apps' database

Send the order as EDI (either D01b or D93a)

Receive the order response, despatch advice and invoice messages

Do all kinds of fun things with the resulting datasets.

However I am struggling with my initial class designs.

The order information will be retrieved from the mainframe which will result in a "AOrder" class, this isn't a problem, I am not sure about how to mold this local object into an EDI string.

Should I create EDIOrder/EDIOrderResponse/etc classes with matching decorators (EDIOrderD01BDecorator, EDIOrderD93ADecorator)? Do I need builder objects or can I do:

```<code>// $myOrder is instance of AOrder
$myOrder->toEDIOrder();
$decorator = new EDIOrderD01BDecorator($myOrder);
$edi = $decorator->getEDIString();
</code>```

And it'll have to work the other way around as well. Is the following code a good way of handling this problem or should I go about this differently?

```<code>$ediString = $myEDIMessageBroker->fetch();
$ediOrderResponse = EDIOrderResponse::fromString($ediString);
</code>```

I'm just not so sure about how I should go about designing the classes and interactions between them.

Thanks for reading and helping.

答:
If the only point of the EDIOrderD01BDecorator is to produce an EDI String, then I would create a EDIOrderSerialization class with static methods to deserialize and serialize in the various necessary formats.

Elsewise if there is further processing to do with an EDIOrder object instead of AOrder, then I would go with the decorator pattern.

OwnerDisplayName: Robert van der Linde

Title: Object oriented EDI handling in PHP

OwnerDisplayName: Peter Smith


问:
Is it possible to effectively develop PHP applications on Windows that will be deployed on servers running Linux?
Is it fine to code PHP on Windows and host it later on a server running Linux? Can there be any problems in the migration of such a project?

I would think that there really can't be any problems, especially since I am a beginner in PHP and I won't use any of the advanced functions that may be OS-specific. However, I would like to make sure since I really don't like Linux at all.

答:
You cannot run strftime() with %e in Windows environment, as is noted in the manual page:

Not all conversion specifiers may be supported by your C library, in which case they will not be supported by PHP's strftime(). Additionally, not all platforms support negative timestamps, so your date range may be limited to no earlier than the Unix epoch. This means that %e, %T, %R and, %D (and possibly others) - as well as dates prior to Jan 1, 1970 - will not work on Windows, some Linux distributions, and a few other operating systems. For Windows systems, a complete overview of supported conversion specifiers can be found at » MSDN.


答: As most folks said there really should not be issues. That said, VirtualBox makes it really, really easy to stand up a linux virtual machine that you can test your codebase on to make sure it does work in the production environment without having said production environment handy.</p>

Title: Is it possible to effectively develop PHP applications on Windows that will be deployed on servers running Linux?

Body:
Is it fine to code PHP on Windows and host it later on a server running Linux? Can there be any problems in the migration of such a project?

I would think that there really can't be any problems, especially since I am a beginner in PHP and I won't use any of the advanced functions that may be OS-specific. However, I would like to make sure since I really don't like Linux at all.


问:
How large is ok for a Class?
I’m a long time developer (I’m 49) but rather new to object oriented development. I’ve been reading about OO since Bertrand Meyer’s Eiffel, but have done really little OO programming.

The point is every book on OO design starts with an example of a boat, car or whatever common object we use very often, and they start adding attributes and methods, and explaining how they model the state of the object and what can be done with it.

So they usually go something like "the better the model the better it represents the object in the application and the better it all comes out".

So far so good, but, on the other hand, I’ve found several authors that give recipes such as “a class should fit in just a single page” (I would add “on what monitor size?" now that we try not to print code!).

Take for example a PurchaseOrder class, that has a finite state machine controlling its behavior and a collection of PurchaseOrderItem, one of the arguments here at work is that we should use a PurchaseOrder simple class, with some methods (little more than a data class), and have a PurchaseOrderFSM “expert class” that handles the finite state machine for the PurchaseOrder.

I would say that falls in the “Feature Envy” or “Inappropriate Intimacy” classification of Jeff Atwood's Code Smells post on Coding Horror. I’d just call it common sense. If I can issue, approve or cancel my real purchase order, then the PurchaseOrder class should have issuePO, approvePO and cancelPO methods.

Doesn’t that goes with the “maximize cohesion” and “minimize coupling” age old principles that I understand as cornerstones of OO?

Besides, doesn’t that helps toward the maintainability of the class?

答: When a class definition has a couple of hundred methods, it is too big.</p>

Title: How large is ok for a Class?


答:
The key to avoiding design dead ends is to recognize as early as possible when your design needs to change, and change it then.  The biggest problems come not by continually evolving your design, but by refusing to evolve your design until it is a huge problem.

As an example, Netflix has a profile feature, where different family members can bill to the same plan, but have separate queues.  A few years ago, they announced they would have to cancel that feature, because only some 10% of their users used it, but due to the hacked on implementation, it was eating up an inordinate amount of maintenance work.  After an uproar, they bit the bullet and did an expensive redesign in order to keep those customers.

I'm sure there were some engineers who recognized a suboptimal design when they first added that feature.  If they had changed it back then, it wouldn't have been nearly as big of a deal.

Title: What do you do if you reach a design dead-end in evolutionary methods like Agile or XP?

Body:
As I was reading Martin Fowler's famous blog post Is Design Dead?, one of the striking impressions I got is that given the fact that in Agile Methodology and Extreme Programming, the design as well as programming is evolutionary, there are always points where things need to get refactored.

It may be possible that when a programmer's level is good, and they understand design implications and don't make critical mistakes, the code continues to evolve. However, in a normal context, what is the ground reality in this context?

In a normal day given some significant development goes into product, and when critical change occurs in requirement isn't it a constraint that how much ever we wish, fundamental design aspects cannot be modified? (without throwing away major part of the code). Is it not quite likely that one reaches dead-end on any further possible improvement on design and requirements?

I am not advocating any non-Agile practice here, but I want to know from people who practice agile or iterative or evolutionary development methods, as for their real experiences.

Have you ever reached such dead-ends? How have you managed to avoid it or escaped it? Or are there measures to ensure that design remains clean and flexible as it evolves?


问:
What are some best practices for cookie based web authentication?
I'm working on a small side project using CGI and Python (scalability is not an issue and it needs to be a VERY simple system.)

I was thinking of implementing authentication using cookies, and was wondering if there were any established best practices.

When the user successfully authenticates, I want to use cookies to figure out who is logged on. What, according to the best practices, should be stored in such a cookie?

答:
Best case: A single ID that relates to all the other information you need, which in turn is stored in a database.

There are times when it makes sense to put some other information in there, but they are rare. You always need to ask yourself why, at least five times.

SSL will protect your users from session hijacking but, even then, never store unencrypted sensitive information in a cookie. It is, essentially, stored in plain text on the harddrive.

Finally, and most importantly, protect your user against XSS and CSRF attacks.

XSS protection is generally as simple as being careful where you include Javascript from, because Javascript on another server could be changed without your knowledge, and this Javascript has access to cookie data. So if you're using Evil Corp's content-delivery network to serve your jQuery script, they can suddenly add code to send them your users' cookies. You wouldn't know; your users wouldn't know.

Either download scripts and serve them from your own server or use very well-trusted CDNs such as Google or Yahoo.

CSRF protection is usually done by having a random value in a hidden field in a form. The value is kept in the session so that when the form is resubmitted, you can verify it came from the same computer.

Most web frameworks now have very simple techniques for including that token.


问:
Is it wise to ask about design decisions made on a product during an interview?
I've been thinking about interview questions lately and I've been reflecting on bad interview experiences I've had in the past. One of particular note is where I had asked the interviewer why the team chose to use EJB 3 over Spring in their product. The interviewer pretty much tore my face off, yelling "Because Spring is not the be all and end all of Java software development, do you want this job or not?".  In response to this, I told him that this probably wasn't the job for me and I promptly walked out of the interview.

I was informed at the beginning of the interview that the company had high staff turnover, the product they were working was initially created in Modula-3 then ported to Perl and finally to Java. I was handed a 10 page booklet of technical questions covering Java, EJB, SQL and JDBC and I was asked questions about the technology stacks I've worked with. When prompted to ask questions, I felt it was reasonable to ask them about their technology stack and and get reasonable answers back, not to send the interviewer into flames.

Question:
Is it a good idea to probe on architectural choices taken in an interview? If not, why?

From my own point of view, an interview is a two-way process. If the interviewers are testing me on my technical skills, I've got every right to ask them the same questions to:

1) Figure out what their mindset and attitudes towards developing software are.
2) Determine if their approach is in line with how I would approach problems of that kind.

It's possible that the interviewer who got angry had poor interviewing skills and forgot that an interview is a two-way exchange. If I was asked this, I would have given a reasonable answer, but I certainly wouldn't have tried to put an interviewee in a state of meek capitulation where the head just bobs up and down with no conversation.

答:
Personally, I find interviewing people almost as exhausting and stressful as being interviewed. But that's because I agree with you that the interview process is a two-way exchange.

I don't care how good you are, I don't want to hire you if you're not going to be happy working there. That's an expensive game to play. So I want to answer any concerns you might have and show you the team and product as they are, so that you can make an informed decision.

When I'm looking for a job, I want to work with someone who shares that attitude. And, even if I suspect I know the answers to questions, I will ask them just to see the reaction. Aggression is never a sign of someone comfortable with a situation.

I don't lie in an interview, on either side of the desk, because then they think they're hiring someone different / going to work somewhere different. And I expect the same in return, from the person on the other side of the interview.

Unfortunately, that means that occasionally I run into interviews like the one you described. Are they horrible experiences? Yes. Do I come out of there knowing exactly where the interview went wrong? Yes.

But am I very sure that every horrible experience would have been considerably worse if I'd got the job or hired the wrong person? Hell yes.


答:
Yes, it's ok to ask if you're genuinely curious and if the answer matters. I think asking shows you understand there's more than one way to do things, and it shows you are interested in how the software was written.

That being said, you've got to be very careful in how you phrase the question, and doubly careful about how you continue the conversation. It is easy to come across as challenging their decisions. The last thing you want is for the interviewer to believe you think you're smarter than them. If you're genuinely curious, ask. If you think they made a poor choice, keep your mouth shut.

If I had been in the situation described in the question, instead of walking out I might have said something like "oh yeah, I agree that spring is definitely not the right solution for everything. Thanks for letting me know a bit about your architecture! I'm always looking for insight into how to choose the right tools". (though, your question is odd -- you ask why they chose spring, and they chose it because it was not the be all end all?)

Title: Is it wise to ask about design decisions made on a product during an interview?

Body:
I've been thinking about interview questions lately and I've been reflecting on bad interview experiences I've had in the past. One of particular note is where I had asked the interviewer why the team chose to use EJB 3 over Spring in their product. The interviewer pretty much tore my face off, yelling "Because Spring is not the be all and end all of Java software development, do you want this job or not?".  In response to this, I told him that this probably wasn't the job for me and I promptly walked out of the interview.

I was informed at the beginning of the interview that the company had high staff turnover, the product they were working was initially created in Modula-3 then ported to Perl and finally to Java. I was handed a 10 page booklet of technical questions covering Java, EJB, SQL and JDBC and I was asked questions about the technology stacks I've worked with. When prompted to ask questions, I felt it was reasonable to ask them about their technology stack and and get reasonable answers back, not to send the interviewer into flames.

Question:
Is it a good idea to probe on architectural choices taken in an interview? If not, why?

From my own point of view, an interview is a two-way process. If the interviewers are testing me on my technical skills, I've got every right to ask them the same questions to:

1) Figure out what their mindset and attitudes towards developing software are.
2) Determine if their approach is in line with how I would approach problems of that kind.

It's possible that the interviewer who got angry had poor interviewing skills and forgot that an interview is a two-way exchange. If I was asked this, I would have given a reasonable answer, but I certainly wouldn't have tried to put an interviewee in a state of meek capitulation where the head just bobs up and down with no conversation.


问:
What and all the areas of Linux a PHP developer should know about? (Like just commands of it or something advanced)
I've developed a website using PHP but I implemented it on Windows OS and hosted it on Windows server.
I just searched the PHP job market to know the on-going technology requirement  and to keep my knowledge up-to-date accordingly with the job market.
  I see more are asking for LAMP stack. I understand the sort of skills required for a developer in PHP and MySQL. But coming to the Linux and Apache what kind of the skills exactly companies expect from a developer?

On what should I be focusing in case of Linux, Apache whilst developing my website using these LAMP stack?

I am going to develop a new website and want it to be using LAMP. But I want to know what difference it makes?

Why LAMP stack got more demand in the job market compared to WAMP ?

Edit: Sorry I thought my question is creating confusion ... so I put my question in different words as What and all the areas of a Linux a PHP developer should know about? (Like just commands of it or something advanced)

Note: I am Linux newbie

答:
This is a good question and has been circulating for awhile. The main difference between windows and linux is that the linux filesystem is case sensitive. This can cause issues with people going from windows to linux, because myPage.php and mypage.php are two different documents. With linux you can install extensions for what you need and not for everything. Generally linux has a smaller footprint and you can technically run a web server on a 10 year old machine like it was brand new.

This can be achieved due to linux using a swap drive that works in conjunction with ram. This allows for the system to use harddrive space for simple file tasks and leave the hardware for application/process tasks (generally speaking).

But as far as the technical requirement of programmers varies by company. I have had companies that wanted to make sure I could program in them and others that wanted me to manage the environment.

One link to someone that has put up differences can be found here: http://tips.webdesign10.com/microsoft-hosting-vs-linux-hosting


答:
Here's some advice

Asking why they chose some existing solution might be bad question, because probably the development team was not given chance to change or choose it.

Also the team likely already knows why the technology was not the best choice

But unfortunately, the last thing any development team needs is people trying change the architecture or questioning choices that were made 10 years ago -- it gives impression that their technology is already old legacy stuff and such messages going around in the team can make developers unhappy about the current situation

Thus in an interview, the last thing you should do is give impression that you're going to complain all the time about the choices the team has no control over


问:
How do I avoid the complexity concerns of frameworks while keeping my team marketable?
When deciding upon how to design a software project with my colleagues, most suggestions tend to be for using specific frameworks "because it's popular in the job market" or "that's the framework that gets recruiters on the phone," and never what I'm looking for which is, "because it's a good fit for the project as it makes the system more adaptive to future changes and makes life easier for developers."

I didn't start looking at projects in this way until I started reading up on domain-driven design. I've found that the actual domain is hidden deep under the frameworks used and it's hard to learn the business processes that have been implemented by the software product.

Is there a way to marry the two competing goals: getting exposure as a development team while still being able to avoid complexity? Are frameworks that compromise, or are there other solutions out there?

答:
When choosing frameworks, consider this stuff:

How many dependencies there are in the framework. What other libs, programs, environments, computers or systems it requires. How much effort it takes to maintain all the dependencies? Less effort is better.

Once the original developer of the framework disappears, what will happen? Is maintaining the framework impossible, difficult, requires 1000 people team

Is it popular enough that there will always be people who care about the framework, and volunteer their time and money to maintain it, even if it is boring and/or annoying work while the whole world thinks there are better frameworks (already) available

what is the time before the framework is going to disappear and considered obsolete

what is the size of the interface you're going to use. Small is better.

Does the framework conventions try to divide your code to 22 differently shaped pieces? Does it enforce any conventions on your code? Beware of callbacks that need to be implemented. Beware also naming/memory management/api conventions that spread all around your code.

Did the framework move annoying or burdensome part of the development work to your responsibility, or does it try to handle and simplify it

Can you use the whole framework's functionality, or is what you're planning only using small part of the framework. If you're using small part only, then the framework might be too burdensome to maintain for you.

Which programming languages or environments the framework relies on? Is that environment going to be available in the future? Several vendors providing the environment?

Is there easy way to isolate the framework to a box which can be changed?

How many of your source files need to use the framework? Smaller number is better.

How much effort you save when you decide to use the framework? What problem it solves? How much extra effort you need to do to take it into use, and maintain it forever.


问:
Meaningful concise method naming guidelines
Recently I started releasing an open source project, while I was the only user of the library I did not care about the names, but know I want to assign clever names to each methods to make it easier to learn, but I also need to use concise names so they are easy to write as well.

I was thinking about some guidelines about the naming, I am aware of lots of guidelines that only care about letters casing or some simple notes. Here, I am looking after guidelines for meaningful but yet concise naming.

For example, this could be part of the guidelines I am looking after:

Use Add when an existing item is going to be added to a target, Use
Create when a new item is being created and added to a target.

Use Remove when an existing item is going to be removed from a target,
Use delete when an item is going to be removed permanently.

Pair AddXXX methods with RemoveXXX and Pair CreateXXX methods with
DeleteXXX methods, but do not mix them.

As the above samples show,I would like to find some online material helping me with naming methods and other item complying with English grammar and word meanings.

The above guidance may be intuitive for native English speakers, but for me that English is my second language I need to be told about things like this.

答:
Assume English, unless every developer that ever works on this code will speak the same non-English language.

Study commonly accepted naming conventions and styles.  Your guiding principle should be clarity.  Styles differ by programming language.

There isn't anything you can do with the naming that will make it easier to understand the relationships between the various objects in your code.  For that, you still need well-written comments and documentation.


答:
As far as why LAMP has a bigger mindshare (if not market share) than WAMP: probably because the LAMP components don't have licensing costs.  That makes getting started cheaper.  Cheap Linux hosting has to be cheaper than cheap Windows hosting just for that reason alone.  The free/libre nature of LAMP makes it possible to just try it out for free. From there, everything else is an accident of history, although IIS and Windows have historically had more and more severe security problems than Apache and Linux.

As far as what you need to know as a developer:

Familiar with shell programming.

At least moderate ability to use a
text editor, probably vi or vim

Familiarity with basic Linux
commands ls, ps.  Not just to run them, but to understand them, how to find out information about them.  (man ls, man ps, the "--help" type options).

Familiarity with the user's view of a linux filesystem. Not just things like "hierachical", "single root", but rather where might you find config files, where does HTML live, where do .php files live, what shows up in /proc/.

Familiarity with the command line interface to the database. "M" in LAMP is for "MySQL", but PostgreSQL is common.

Intimate familiarity with ssh, scp, sftp can help.

If you have spare hardware, even 5 or 6 year-old hardware, you can easily install something like Slackware linux distro.  Just getting Slackware up and running will teach a lot, configuring Apache, MySQL and PHP will teach you even more.

Title: What and all the areas of Linux a PHP developer should know about? (Like just commands of it or something advanced)

Body:
I've developed a website using PHP but I implemented it on Windows OS and hosted it on Windows server.
I just searched the PHP job market to know the on-going technology requirement  and to keep my knowledge up-to-date accordingly with the job market.
  I see more are asking for LAMP stack. I understand the sort of skills required for a developer in PHP and MySQL. But coming to the Linux and Apache what kind of the skills exactly companies expect from a developer?

On what should I be focusing in case of Linux, Apache whilst developing my website using these LAMP stack?

I am going to develop a new website and want it to be using LAMP. But I want to know what difference it makes?

Why LAMP stack got more demand in the job market compared to WAMP ?

Edit: Sorry I thought my question is creating confusion ... so I put my question in different words as What and all the areas of a Linux a PHP developer should know about? (Like just commands of it or something advanced)

Note: I am Linux newbie


问:
What's the best way to learn image processing?
I'm a senior in college that hasn't done much image processing before (except for some basic image compression on smartphones). I'm starting a research project on machine learning next semester that would require some biomedical image processing. What's the best way to get up to speed with the basics of image processing in about two months? Or is this impractical?

It's my impression that once I'm good with the basics learning more from other resources would be easier.

答:
I started out by actually making a program from scratch. No books, classes, or math. My math does't go far beyond basic algebra.

I ended up making an effective barcode reader that blows away the commercial trials I tested. Jump in and do it!!!


答:
I have reached dead end my code and others code due to bad design, change in direction, etc.  I've also seen many others run into this problem.  The big mistake (at least it seems like a mistake to me) is the immediate desire to throw away working code and reimplement everything from the ground up.

I approached each case in the same way which seemed to work well:

identify why the current design isn't working

come up with a new design and a transition plan

tag the code that will not be used as deprecated

implement only what I need for the new design in order to get the immediate need fulfilled

remove the code the new code makes obsolete

Costs:

more complexity due to 2 implementations in the code base at the same time

more total cost per feature/bug fix than doing a full redesign/reimplementation assuming good use cases and tests

Benefits:

at least an order of magnitude less risk because you still have the old working design/code

faster to market for any 1 to n-1 features that don't require a full redesign

if the product/code ends up dieing before you've completed the full redesign you will have saved development time difference

iterative approach and all the benefits therein


答:
As developer, the most important skill to focus on is development. There's a lot more differences between Linux and Windows than case sensitivity. A LAMP dev should have a strong server management skill set, but you're not a sys admin.

A couple of concrete goals:
Being comfortable on the command line is a must. Be able to set up, secure, configure and deploy a web server from scratch in your favorite *nix distro from the command line. A solid understanding of how your server daemons run and how they interact with one another goes a long way in diagnosing all manners of problems. Be able to set up and change DNS and NS records. Become comfortable with a version control system such as svn or git.

As far as WAMP vs LAMP: well, for one thing, Windows licensing costs money. And Windows has shipped with a built-in web server called IIS since XP, which can be configured to run PHP in ~3 clicks, and then there's MSSQL, and .NET, which -> ASP, and suddenly web dev is whole different ball game. Because, if you're going to run IIS, you probably have a whole slew of the other Windows-specific tools / suite you want to run (Exchange, AD, etc) so you're probably running them all on Windows Server 2008, not a desktop OS like Windows 7.

WAMP is mainly the stuff of localhost sandbox development. I dare say most experienced developers who run Windows either have *nix as a dual boot or a virtual machine for development purposes. Working on the command line in Windows is a pain to set up and it's clumsy at best, even with PuTTY, Pageant, plink, etc. If your resources permit, setting up a virtual machine locally to learn on would probably be useful to you.

HTH. :)


答:
I feel for you.

A few suggestions:

Tape every conversation you have with the leaving programmer!

Ask for the motivation behind the "big" issues. It's good you understand the API, but dig for the internal decisions - why was the code partitioned as it is? what are the responsibilities.

Make an effort to really study the code. When you assume maintenance and support duties there is sometimes the pressure to "study the code while making progress". Resist if you can, and really study the code.

Look for scenarios. You know the API - see how the code behaves. An example that comes to mind is that of a Fax module. As a user of the API, you preheps had to prepate a page image and send the code a command to transmit the page. Ask the leaving programmer to trace with you on the code to see how this scenario carries through. Then, of course, go the "receiving page" scenario.

80/20 - try to cover the more common scenarios first.

Consider a re-write. If the code is old and the interfaces are well defined, maybe technology has changed enough to justify it.

I hate to say this, but consider looking for a new job.

Title: Best Practices for Handing over Legacy Code

Body:
In a couple of months a colleague will be moving on to a new project and I will be inheriting one of his projects. To prepare, I have already ordered Michael Feathers' Working Effectively with Legacy Code.

But this books as well as most questions on legacy code I found so far are concerned with the case of inheriting code as-is. But in this case I actually have access to the original developer and we do have some time for an orderly hand-over.

Some background on the piece of code I will be inheriting:

It's functioning: There are no known bugs, but as performance requirements keep going up, some optimizations will become necessary in the not too distant future.

Undocumented: There is pretty much zero documentation at the method and class level. What the code is supposed to do at a higher level, though, is well-understood, because I have been writing against its API (as a black-box) for years.

Only higher-level integration tests: There are only integration tests testing proper interaction with other components via the API (again, black-box).

Very low-level, optimized for speed: Because this code is central to an entire system of applications, a lot of it has been optimized several times over the years and is extremely low-level (one part has its own memory manager for certain structs/records).

Concurrent and lock-free: While I am very familiar with concurrent and lock-free programming and have actually contributed a few pieces to this code, this adds another layer of complexity.

Large codebase: This particular project is more than ten thousand lines of code, so there is no way I will be able to have everything explained to me.

Written in Delphi: I'm just going to put this out there, although I don't believe the language to be germane to the question, as I believe this type of problem to be language-agnostic.

I was wondering how the time until his departure would best be spent. Here are a couple of ideas:

Get everything to build on my machine: Even though everything should be checked into source code control, who hasn't forgotten to check in a file once in a while, so this should probably be the first order of business.

More tests: While I would like more class-level unit tests so that when I will be making changes, any bugs I introduce can be caught early on, the code as it is now is not testable (huge classes, long methods, too many mutual dependencies).

What to document: I think for starters it would be best to focus documentation on those areas in the code that would otherwise be difficult to understand e.g. because of their low-level/highly optimized nature. I am afraid there are a couple of things in there that might look ugly and in need of refactoring/rewriting, but are actually optimizations that have been out in there for a good reason that I might miss (cf. Joel Spolsky, Things You Should Never Do, Part I)

How to document: I think some class diagrams of the architecture and sequence diagrams of critical functions accompanied by some prose would be best.

Who to document: I was wondering what would be better, to have him write the documentation or have him explain it to me, so I can write the documentation. I am afraid, that things that are obvious to him but not me would otherwise not be covered properly.

Refactoring using pair-programming: This might not be possible to do due to time constraints, but maybe I could refactor some of his code to make it more maintainable while he was still around to provide input on why things are the way they are.

Please comment on and add to this. Since there isn't enough time to do all of this, I am particularly interested in how you would prioritize.

Update: As the hand-over project is over I have expanded this list with my own experiences in this answer below.


问:
Stuff every programmer needs while working
I've been tasked with creating a fun and relaxing environment, one thing I know that I want is ergonomic mice and keyboards, others have suggested exercise balls and bands.

What is it that every programmer needs while working? What might not be necessary but would be nice to have anyway?

Note: this question was asked previously, but has been recommended to be posted here. See this link for the previous responses: https://stackoverflow.com/questions/3911911/stuff-every-programmer-needs-while-working-closed

答:
Many people have mentioned a quite or silent workplace which is often not only impossible but is actually almost as bad as a noisy one. I can't stand utter silence, it's creepy, so here is my inexpensive suggestion:

A white/pink noise generator

Like a clock that has a white/pink noise generator in it. A lot of them have additional sounds but the beaches have annoying bird noises and rivers make me have to pee so the best ones are the sound modes that simulate rain. My favorite is rain on a tin roof.

OwnerDisplayName: Pickle Pumper


答:
As someone who frequently interviews people, I'd personally welcome a discussion about why particular technology or design choices were made, what we'd do differently now if we either had the luxury of resources or were starting a new project. I'd generally see it as a sign about someone who cares about their craft, and unless their dogmas and ours weren't compatible, I'd probably rate that candidate more highly than someone who just answers technical questions competently.

I'm currently working on a project for a client which has a legacy of some well-meaning but poorly implemented architectural decisions, and candidates who express curiosity about the world as it is, and the path forward as we see it, are usually the types of people we'd like to work with. We want people who are able to do appropriate due diligence and validation on design and implementation decisions on our team. We generally value people who bring something to the table that we don't have, or don't have enough of.

When I've been a candidate in an interview, I take any sign of hostility or defensiveness when these types of discussions happen as a bad sign, as an organization not capable of self-examination is usually also in a technological and process morass that they are incapable of and probably unwilling to work their way out of. If I don't see motivation for continuous improvement on the existing team, there's a good chance I won't be happy there.

If I went in and they said, "Yeah, we've got this legacy app that we're not happy maintaining but it still brings in enough revenue to cover all our paychecks, and we want to make the codebase more maintainable by refactoring the pain points, or migrate component x to technology y" or "we chose technology a over technology b because we had more experience there and technology b was still in its infancy when we started; we're open to change but it's a slow process and we aren't in a position to just throw out our existing codebase", I can believe it's going to be a better experience for me than if I hear "Yeah, we are stuck on Borland C++ Builder version 6 and developers aren't allowed to make technical decisions because they've all already been made by the CEO's brother, who slept with an Oracle salesperson once and decided all future development will be done using Java 1.4 web services, Oracle ERP, and a Borland C++ frontend using mostly discontinued 3rd party GUI components and we'd rather spend $60,000 a month plugging holes to keep customers from jumping ship than revisit any decisions and make permanent improvements that might bring new revenue if we're lucky. Don't rock the boat, what's wrong with you."

Presuming you're in an area with other technology jobs, or you're willing to move, you likely have the luxury of choice. No gig is perfect, but you want to work with people who want to work with you. (I care more about this than the specific technology choices most of the time.) If something smells bad, it probably is.

So yeah, ask away. The more curiosity about our business, our process, and our design, the more seriously I'm likely to take a candidate. But I don't work at a Blub shop, so I can't say whether it'll help you get a Blub job. I can only say that it would work for you if you want to work with other people who care about their craft.


答:
Use the secure and httpOnly flags.

Encode the session cookie data and cryptographically sign the encoded data with a MAC. Check the signature at the server every time, before bothering to decode the session cookie data. (Rails does this by default.)

Title: What are some best practices for cookie based web authentication?

Body:
I'm working on a small side project using CGI and Python (scalability is not an issue and it needs to be a VERY simple system.)

I was thinking of implementing authentication using cookies, and was wondering if there were any established best practices.

When the user successfully authenticates, I want to use cookies to figure out who is logged on. What, according to the best practices, should be stored in such a cookie?


答:
Question: Is it a good idea to probe on architectural choices taken in
  an interview? If not, why?

It absolutely fine, I would view it as a positive.

If your interviewer can not handle that, it says a lot about them - not you.

I would be worried if a junior was NOT interested in design decisions, it would show a lack of curiosity/interest in the subject area, and exhibits no desire to improve themselves.


问:
prism and multiple screens
OK - I am studying Prism a little because of a "free weekend" offer on Pluralsight. As this is proving too complex for me, I went to the Prism book and looked at the forward, and this is what it said:

What comes after “Hello, World?”

WPF and Silverlight developers are
  blessed with an abundance of excellent books... There’s no lack of tutorials on
  Model-View-ViewModel ... But they stop short of
  the guidance you need to deliver a non-trivial application in full.

Your first screen goes well. You add a second screen and a third.
  Because you started your solution with the built-in “Navigation
  Application Template,” adding new screens feels like hanging shirts on
  a closet rod. You are on a roll. Until the harsh reality of real
  application requirements sets in.

As it happens, your application
  has 30 screens not three. There’s no room on that closet rod for 30
  screens. Some screens are modal pop-ups; you don’t navigate to a
  pop-up. Screens become interdependent such that user activity in one
  screen triggers changes that propagate throughout the UI. Some screens
  are optional; others are visible only to authorized users. Some
  screens are permanent, while other screens can be opened and closed at
  will. You discover that navigating back to a previously displayed
  screen creates a new instance. That’s not what you expected and, to
  your horror, the prior instance is gone along with the user’s unsaved
  changes.

Now the issue is, I don't relate to this description. I've never been a UI programmer, but same as everyone else I'm using Windows apps such as MS-Office, and web sites such as Amazon, Facebook and StackExchange. And I look at these and I don't see many "so many screens" issues!

Indeed, the only applications having many windows I can think of is Visual Studio. Maybe also Visio, a little. But take Word - You have a ribbon and a main window. Or take Facebook: You have those lists on the left (Favorites, Lists, Groups etc.), the status middle, the adds and then the Contacts sidebar. But it's only one page.

Of course, I understand that in enterprise scenarios there are dashboad applications where multiple segments of the screen are updated from multiple non-related services. This I dig. But other scenarios?

So - What am I missing? What is the "multiple screens" monster Pirsm is supposed to be the silver bullet solution for? Shoud I invest in studying Prism in addition to learning WPF or ASP.NET MVC?

答:
I guess the problem you are having is not Prism related. The question is about GUI design of an application, specifically, your question is about why use multiple screens (windows, pages, etc.).

You have found a good answer for simplifying user interface in the text of your question, namely many applications use 1 page at a time.

Multiple screen/page is usually, though fancy, is confusing for many users (this of course depends on your users skills) not only for programmers!

The 1 page strategy works for Word, Wizards, Configuration screens, Setup programs and many more.

When you use this approach you greatly simplify the programming of the GUI (in case you are trying to handle concurrency of data showing in many screens). Although 'binding' may be able to take care of part of this, still, it is not very easy in some cases.

My suggestion is that you stop programming and start designing the user interface based on the customer business function. Think of what the user needs to do for each business function. Determine what information is required from the system so the function be complete. Design the flow for this function based on that. Do this for the other functions, then review and refine your flow. Consider different user roles in this process. Eventually you will be able to find the optimal GUI design. Now, this may involve more than 1 page/screen but resist this unless it is necessary.

In short, design first before coding.

Good luck.

Title: prism and multiple screens


问:
Does the ActiveRecord pattern follow/encourage the SOLID design principles?
I'm interested in whether ActiveRecord pattern, made famous from Ruby on Rails, encourages or discourages the use of SOLID design principles.

For example, it seems to me that ActiveRecord objects both contain domain logic, and persistence logic, which is a violation of Single Responsibility.

答:
(I am assuming that the ActiveRecord class is implemented without any possibility for dependency injection).

From personal experience I can say that ActiveRecord pattern becomes a major obstacle for writing unit tests. The coupling of the persistence layer and business logic in a single "ActiveRecord class" makes it impossible to write unit tests (unless you refactor first). Therefore, the only option is writing integration tests; and that is not as effective as unit-tests. This becomes a major issue especially if you take over a project with a lot of ActiveRecord classes; it yields to highly complicated integration tests that are hard to maintain.

So, the ActiveRecord comes pretty much against SRP and creates some maintenance headache; it seems to take away the power to write unit-tests.


问:
What are the common techniques to handle user-generated HTML modified differently by different browsers?
I am developing a website updater. The front end uses HTML, CSS and JavaScript, and the backend uses Python.

The way it works is that
,  and some other HTML elements can be updated by the user. To enable this, I load the webpage and, with JQuery, convert all those elements to <textarea/> elements. Once they the content of the text area is changed, I apply the change to the original elements and send it to a Python script to store the new content.

The problem is that I'm finding that different browsers change the original HTML.

How do you get around this issue?

What Python libraries do you use?

What techniques or application designs do you use to avoid or overcome this issue?

The problems I found are:

IE removes the quotes around class and id attributes. For example,  becomes .

Firefox removes the backslash from the line breaks:
 becomes
.

Some websites have very specific display technicalities, so an insertion of a simple "\n"(which IE does) can affect the display of a website. Example: changing
 to \n
 inserts a vertical gap in IE.

The things I have unsuccessfully tried to overcome these issues:

Using either JQuery or Python to remove all >\n< occurences,
 etc. But this fails because I get different patterns in IE, sometimes a ∙\n, sometimes a \n∙∙∙.

In a Python, parse the new HTML, extract the new text/content, insert it into the old HTML so the elements and format never change, just the content. This is very difficult and seems to be overkill.

答:
What is your goal?

First, why are you doing it? If you providing a possibility for your customers to modify the content of a web page, there are two cases:

Your customers have enough technical background, like users of Stack Exchange. In this case, why not using Markdown, much user friendly and much easier to type?

Your customers don't have enough technical background. In this case, providing them a possibility to handle HTML manually is like if your ISP said that in order to have an internet connection, you first have to do your own wiring from your home to their center, then build your own router which matches their protocols, and then do all the configuration yourself. That's how your customers will perceive your business.

Remember, it's HTML

If you still have a valid reason to use direct HTML editing capabilities, you must remember that you're dealing with HTML. Which means, no string.replace, and no regular expressions (I put it in bold, but imagine I putted it in Arial Black 200 bold blinking red).

You need to parse the input.

Primary, you need to parse it in order to normalize the formatting. It's here that you remove your end lines, replace
 by
 (you're talking about a backslash in your question; is this a typo?), etc.

Also, you need to be sure that it's a valid HTML. What if the user adds a
 which doesn't match any opening tag? Yes, it will probably break the layout of your page.

Remember, it's user input

Last, but most important reason to parse the input as HTML: you need to validate it.

What if I add a

Body:
What is your goal?

First, why are you doing it? If you providing a possibility for your customers to modify the content of a web page, there are two cases:

Your customers have enough technical background, like users of Stack Exchange. In this case, why not using Markdown, much user friendly and much easier to type?

Your customers don't have enough technical background. In this case, providing them a possibility to handle HTML manually is like if your ISP said that in order to have an internet connection, you first have to do your own wiring from your home to their center, then build your own router which matches their protocols, and then do all the configuration yourself. That's how your customers will perceive your business.

Remember, it's HTML

If you still have a valid reason to use direct HTML editing capabilities, you must remember that you're dealing with HTML. Which means, no string.replace, and no regular expressions (I put it in bold, but imagine I putted it in Arial Black 200 bold blinking red).

You need to parse the input.

Primary, you need to parse it in order to normalize the formatting. It's here that you remove your end lines, replace <br> by <br /> (you're talking about a backslash in your question; is this a typo?), etc.

Also, you need to be sure that it's a valid HTML. What if the user adds a </div> which doesn't match any opening tag? Yes, it will probably break the layout of your page.

Remember, it's user input

Last, but most important reason to parse the input as HTML: you need to validate it.

What if I add a <script/> tag with some nasty JavaScript code? What if I want to break your layout just to annoy you? Or to redirect the users from your website to my own? What if...

If you open your HTML code to be modified by a non-trusted source, be prepared that it will hurt soon or later, both you (see, it's never pleasant to see that you've been banned by Google results because your page content contains viruses) and your customers, who will never return.


问:
How to Deliberately Practice Software Engineering?
I just finished reading this recent article. It's a very interesting read, and it makes some great points. The point that specifically jumped out at me was this:

The difference was in how they spent this [equal] time. The elite players
  were spending almost three times more hours than the average players
  on deliberate practice — the uncomfortable, methodical work of
  stretching your ability.

This article (if you care not to read it) is discussing violin players. Of course, being a software engineer, my mind turned towards software ability. Granted, there are some very naturally talented individuals out there, but time and time again, it is those folks who stretch their abilities through deliberate practice that really become exceptional at their craft.

My question is - how would one go about practicing the "scales" of software engineering and computer science? When I practice the piano, I will spend more of my time on scales and less on a fun song. How can I do the same in developing software?

To head off early answers, I don't feel that "work on an open source project," and similar answers, is really right. Sure...that can improve your skills, but you could just as easily get stuck focusing on something that is unimportant to your craft as a whole. It can become the equivalent of learning "Twinkle Twinkle Little Star" and never being able to play Chopin.

So, again, I ask - how would you suggest that someone deliberately practice software engineering?

答:
After you write a block of code that works and passes a test, ask yourself "can this code be better?". In this context, better doesn't necessarily mean faster or more efficient, though that's part of it. Clarity of the code is also important -- can someone look at it and understand what it is doing. Ask yourself if you would submit that code to a potential employer as being representative of your best work.

Don't just do this for your own personal code. Come to sites like this and answer questions that require you to provide a working example. Writing code that may someday be copied and used by people who are just learning can be a powerful motivator. Make sure you do this with your real name so you have no choice but to claim it as your own.

Another way to do this -- and I see that you are -- is to write a blog that requires you to provide code. Again, this forces you to write code that will in the public eye, open to criticism.

When you write code that will be read and scrutinized by others, I think that's the equivalent of practicing scales.


问:
How do I do TDD on embedded devices?
I'm not new to programming and I've even worked with some low level C and ASM on AVR, but I really can't get my head around a larger-scale embedded C project.

Being degenerated by the Ruby's philosophy of TDD/BDD, I'm unable to understand how people write and test code like this. I'm not saying it's a bad code, I just don't understand how this can work.

I wanted to get more into some low level programming, but I really have no idea how to approach this, since it looks like a completely different mindset that I'm used to. I don't have trouble understanding pointer arithmetics, or how allocating memory works, but when I see how complex C/C++ code looks compared to Ruby, it just seems impossibly hard.

Since I already ordered myself an Arduino board, I'd love to get more into some low level C and really understand how to do things properly, but it seems like none of the rules of high level languages apply.

Is it even possible to do TDD on embedded devices or when developing drivers or things like custom bootloader, etc.?

答: What I've done is separate out the device dependent code from the device independent code, then test the device independent code. With good modularity and discipline, you will will wind up with a mostly well-tested codebase.

OwnerDisplayName: Darth

Title: How do I do TDD on embedded devices?


答:
One approach might be to take a relatively non-trivial project (say, over 1000 lines), and port it to other languages. You will find that this highlights many assumptions made for you by your language.

Another approach might be to determine a larger project - at least 10KLoC by your estimate - and start writing it, writing it fast. Keep writing it, and then after it's accomplished its goal, maintain it.  This will teach you about managing codebases mutating over time.

Just some thoughts.

Title: How to Deliberately Practice Software Engineering?

Body:
I just finished reading this recent article. It's a very interesting read, and it makes some great points. The point that specifically jumped out at me was this:

The difference was in how they spent this [equal] time. The elite players
  were spending almost three times more hours than the average players
  on deliberate practice — the uncomfortable, methodical work of
  stretching your ability.

This article (if you care not to read it) is discussing violin players. Of course, being a software engineer, my mind turned towards software ability. Granted, there are some very naturally talented individuals out there, but time and time again, it is those folks who stretch their abilities through deliberate practice that really become exceptional at their craft.

My question is - how would one go about practicing the "scales" of software engineering and computer science? When I practice the piano, I will spend more of my time on scales and less on a fun song. How can I do the same in developing software?

To head off early answers, I don't feel that "work on an open source project," and similar answers, is really right. Sure...that can improve your skills, but you could just as easily get stuck focusing on something that is unimportant to your craft as a whole. It can become the equivalent of learning "Twinkle Twinkle Little Star" and never being able to play Chopin.

So, again, I ask - how would you suggest that someone deliberately practice software engineering?


答:
Two things that come to mind are Project Euler and Google's AI Challenge.  Especially if you do it in a language other than your day job language, these sorts of problems are constrained enough to stretch your abilities, but also simple enough to have clear approaches.

I've been doing the AI challenge this year, and what I find most fascinating about it is that the problem is simple enough to be solved with basic algorithms, but you'll hit the time limit per turn if you do it the naive way.  You have to understand not just the rote part of the basics, but also the underlying reasons behind them in order to make it work within the time constraints.


答:
There's a difference between what we do as software engineers and what a violinist (or anything else that requires physical practice would do).  A violinist spends hours practicing methodically because they are teaching their brain very specific patterns of how to interact with an instrument.

Practicing software engineering also involves learning patterns.  The more projects you do, the more you will learn (hopefully) about what works and what doesn't. There's no standard recipe for writing great software (that's why some people compare our profession to a "craft" rather than pure science). So my advice #1, write code, then write more code. And don't think that if what you are working on is fun, it isn't teaching you as much. I say pick something that IS fun; it'll keep your interest longer and you'll enjoy yourself that much more.

You don't have to join an open source project if you don't want to.  Just set a goal for yourself, something would interest you, and just start coding.  You don't even need to finish it, so don't get disappointed if half way through the project you decide to drop it and go to something else.  Most importantly as you walk away from that project, you need to be walking away with better skills and more knowledge of the technology you used.

Advice #2, read Pragmatic Programmer. Main take away from that book is that just as you think about how to write a piece of software, once in a while you need to step back and review your process for thinking about writing a piece of software. Any time you do work, don't just put it on a shelve and move on, but take another glance at it and think of ways you could've done it better.  You don't have to go and actually redo it, but by thinking about it, you will exercise your brain to recognize the patterns I mentioned in the intro.

Advice #3, talk to other people who are passionate about writing code. Listen to what they've done and how they approached things. And explain to them what you are doing. I have few friends at work and periodically I'd just walk into their cube and quickly sketch out the design of software I'm working on.  Sometimes they'll just nod, but other times, they might say, well if you move this box over here and get rid of this class, you could save yourself 2 days of work and gain advantages A, B and C.

Advice #4, after you've done few projects and found some patterns. Go back and read books like the famous GoF book. If you've already done work, you'll a) recognize some of the things authors are talking about and b) you'll discover different ways you could've approached your projects.

Advice #5, always keep reading and challenging yourself. Don't ever get into the mode that now I know technology X, therefore I'm an expert. No matter how much you think you've learned, just remember, there's infinitely more out there for you to absort, so in grand scheme of things, you still don't know that much. Keep reading blogs; learn a new language. For example I've been reading about F# and functional programming although I mainly program in C++ and I've started applying functional concepts to my object oriented code.  In some places this greatly simplified the use of multiple threads and data synchronization.


问:
What do you do if you reach a design dead-end in evolutionary methods like Agile or XP?
As I was reading Martin Fowler's famous blog post Is Design Dead?, one of the striking impressions I got is that given the fact that in Agile Methodology and Extreme Programming, the design as well as programming is evolutionary, there are always points where things need to get refactored.

It may be possible that when a programmer's level is good, and they understand design implications and don't make critical mistakes, the code continues to evolve. However, in a normal context, what is the ground reality in this context?

In a normal day given some significant development goes into product, and when critical change occurs in requirement isn't it a constraint that how much ever we wish, fundamental design aspects cannot be modified? (without throwing away major part of the code). Is it not quite likely that one reaches dead-end on any further possible improvement on design and requirements?

I am not advocating any non-Agile practice here, but I want to know from people who practice agile or iterative or evolutionary development methods, as for their real experiences.

Have you ever reached such dead-ends? How have you managed to avoid it or escaped it? Or are there measures to ensure that design remains clean and flexible as it evolves?

答: Wasn't it Fred Brooks who said something like "Plan on throwing the first one away"?  Don't feel too glum about it, dead-end designs also pop up in projects that try to do all the design up-front as well.  Redesigns happen in all types of development, whether because it was an unworkable design from the start (that last 20% that gets glossed over- "the devil is in the details") or because a customer changes their focus.  There is no real need for alarm bells, don't be too worried.</p>


答:
There is no reason why you can't. The problem is that there may not be nice "off-the-shelf" unit testing frameworks like you have in other types of development. That's OK. It just means that you have to take a "roll-your-own" approach to testing.

For instance you may have to program instrumentation to produce "fake inputs" for your A/D converters or maybe you'll have to generate a stream of "fake data" for your embedded device to respond to.

If you encounter resistance to using the word "TDD" call it "DVT" (design verification test) that will make the EE's more comfortable with the idea.

Title: How do I do TDD on embedded devices?

Body:
I'm not new to programming and I've even worked with some low level C and ASM on AVR, but I really can't get my head around a larger-scale embedded C project.

Being degenerated by the Ruby's philosophy of TDD/BDD, I'm unable to understand how people write and test code like this. I'm not saying it's a bad code, I just don't understand how this can work.

I wanted to get more into some low level programming, but I really have no idea how to approach this, since it looks like a completely different mindset that I'm used to. I don't have trouble understanding pointer arithmetics, or how allocating memory works, but when I see how complex C/C++ code looks compared to Ruby, it just seems impossibly hard.

Since I already ordered myself an Arduino board, I'd love to get more into some low level C and really understand how to do things properly, but it seems like none of the rules of high level languages apply.

Is it even possible to do TDD on embedded devices or when developing drivers or things like custom bootloader, etc.?


答:
I'm fond of asking an interviewer to tell me about a failed design decision they made, and what was done next.  This gives you some good pieces of information:

If the boss can't admit any form mistake or temporary failure, that's a boss you probably don't want to work for.

You can tell how the company handles a stressful situation.

It might not be popular, but I always have great respect for the managers with the stones to recognize a project is going to fail and kill it to stop wasting money, or that something is headed in the wrong direction and needs to be killed or rebooted.

Ultimately if you're talking about job satisfaction the technology (language/platform/compiler/whatever) doesn't matter so much as the personalities involved and the work environment.


问:
How to work in localhost properly
I am using MAMP (just and example) to develop web applications without having to constantly upload and download via FTP.

I´m sure this is the correct way to test a project but I´m no sure if I´m doing it right.

After I´m satisfied with the project I have to change in every page the MySQL databases and most of the links etc.

Is there a workaround this? How should this be used?

Thanks in advance!

答:
I'd have a configuration file with both the database connection info AND the server URL, you could actually use

```<code>define('SERVER_URL', 'http://' . $_SERVER['SERVER_NAME'] . '/');
</code>```

It's what I use when I work with WordPress :)

Title: How to work in localhost properly

Body:
I'd have a configuration file with both the database connection info AND the server URL, you could actually use

define('SERVER_URL', 'http://' . $_SERVER['SERVER_NAME'] . '/');

It's what I use when I work with WordPress :)