问:
Are there any good reasons to use, learn, or recommend XSLT?
I am a developer for the last 8 years. We used XSLT primarily to transform XML into HTML. We also used it for XML to XML transformation.

But we have replacement for everything now. HTML can be comfortably created through programming languages such as ASP.Net. XML can be read and manupulated in any standard highlevel languages. As programming in XSLT is a little complex, any one would prefer working on latest programming languages.

Now my question:
Will XSLT be a significant choice in future, not considering the fact of maintaining already developed XSLT? Can I recommend new programmers to study XSLT?

答:
XSLT's biggest failing is it inability (in any real implementation) to minimize the amount of the document that needs to be kept in memory at a time for efficient processing.  Instead the whole document is read into some form of DOM representation and processing is done against that.  If the document is very large, then so are the memory requirements.  Yet many stylesheets clearly only need the current tag and a few others, e.g. the tag's ancestors, at any given time and thus could be processed with minimal memory and efficient streaming.

Yes, in terms of a language it's weird, but that's just a barrier to entry.  If you know XSLT, it's often easier than the alternatives -- but if you will have large documents (or lots of documents being processed at once) the memory impact of XSLT often forces other, more time consuming alternatives.


问:
What makes JVM so much versatile to support so many JVM languages?
JVM supports so many languages other than Java like Groovy,Clojure,Scala etc which are functional languages unlike Java(I am referring to Java before Version 8 where Lambda's are not supported) that doesn't support functional capabilities.On a high level what makes the JVM so versatile that it can support both Object Oriented as well as Functional languages?

答:
I'll add that the JVM supports a well defined and pretty decent Memory Model (JMM) which means good support for consistent (albeit low level) threading behaviour.  It also has a powerful Just In Time compiler (no more useful for dynamic languages thanks to MethodHandles and invokedynamic).

Last but not least is the JVM's Garbage Collection sub-system which (with the right tuning) manages memory for you regardless of the language on top.

ContentLicense: CC BY-SA 3.0


问:
Do I need unit test if I already have integration test?
If I already have integration test for my program, and they all passed, then I have a good feel that it will work. Then what are the reasons to write/add unit tests? Since I already have to write integration tests anyway, I will like to only write unit test for parts that not covered by integration tests.

What I know the benefit of unit test over integration test are

Small and hence fast to run (but adding new unit to test something is already tested by integration test means my total test suit get larger and longer to run)

Locate bug easier because it only test one thing (but I can start write unit test to verify each individual part when my integration test failed)

Find bug that may not be caught in integration test. e.g. masking/offsetting bugs. (but if my integration tests all passes, which means my program will work even some hidden bug exists. So find/fix these bugs are not really high priority unless they start breaking future integration tests or cause performance problem )

And we always want to write less code, but write unit tests need lots more code (mainly setup mock objects). The difference between some of my unit tests and integration tests is that in unit tests, I use mock object, and in integration tests, I use real object. Which have lots of duplication and I don't like duplicated code, even in tests because this add overhead to change code behavior (refactor tool cannot do all work all the time).

答:
I don't see much value in reeimplementing an existing integration-testcase as a unittest.

Integration tests are often much easier to write for non tdd legacy applications because usually the functionalities-to-be-tested are tightly coupled so testing units in isolation (=unittesting) can be difficuilt/expensive/impossible.

```<code>> Then what are the reasons to write/add unit tests?
</code>```

In my opinion test-driven development is most effective if you write the unit tests before the actual code. This way the code that fulfills the tests becomes clearly separated with a minimum of external references that is easy testable.

If the code already exists without the unit tests it is usually a lot of extra work to write the unit tests afterwards because the code was not written for easy testing.

If you do TDD the code automatically is easy testable.

Body:
I don't see much value in reeimplementing an existing integration-testcase as a unittest.

Integration tests are often much easier to write for non tdd legacy applications because usually the functionalities-to-be-tested are tightly coupled so testing units in isolation (=unittesting) can be difficuilt/expensive/impossible.

> Then what are the reasons to write/add unit tests?

In my opinion test-driven development is most effective if you write the unit tests before the actual code. This way the code that fulfills the tests becomes clearly separated with a minimum of external references that is easy testable.

If the code already exists without the unit tests it is usually a lot of extra work to write the unit tests afterwards because the code was not written for easy testing.

If you do TDD the code automatically is easy testable.


问:
Does software reuse preclude process repeatability

Code Reuse as a Problem

I was thinking about this question on software delivery, and I kept coming back to the issue of repeatability and / or reproducibility.  They matter, because if you don’t repeat a project then it becomes more difficult to improve the process you used to build the project.  Engineering involves constantly improving the processes involved with design and construction in order to produce higher quality projects.

Software can rely heavily upon reuse due to its digital form.  Instead of rewriting a module, we just call it again or copy it to the other system.  Some examples are authentication / login or perhaps a logging function.  There are many well known examples for those categories, and conventional wisdom is to reuse what exists instead of rolling your own.

Some Comparisons to Other Disciplines

Construction

In contrast, construction of physical systems (buildings, bridges) is nowhere near as reusable.  It’s true that the blueprint of a house can be reused many times to build the same copy of the house, but the construction must be performed each time.  Cut & paste doesn’t work like that in the analog world.  Bridge blueprints are less reusable that houses because site conditions will vary.

Master builders are experts recognized for having designed and / or built tens, hundreds, or thousands of things in their area.  For example, Frank Lloyd Wright, a world renowned architect and designer designed more than 1,000 structures and completed 532 works.  Contrast that with Anders Hejlsberg who has designed “just” five languages (Turbo Pascal; Delphi; J++; C#; Typescript).  In many ways, it’s an unfair comparison because the domains are different.  But at a broad level, the quantifiable production from two very intelligent people is vastly different.

Martial Arts

Martial artists will say that mastery of a move comes only from thousands of repetitions. After a good portion of those repetitions have been put in, many martial artists are surprised at how a previously perceived to be complex kata or form has become simple. Instructors of those students will also notice how the motion becomes more fluid and purposeful as well as having an economy of motion. Likewise, experienced martial artists are able to pick up more complex katas more quickly than less experienced students. Experience from repetition has given them a framework or process that allows them to learn more quickly.

Woodworking

Woodworkers experience a similar transformation. Hobbyist woodworkers always refer back to their first project that required a lot of drawers. If they complete the project, they gain a new appreciation for the efficiencies that assembly lines produce. There are other benefits such as a better understanding of how to lay out the drawers parts on the sheet stock in order to maximize use of the wood. Compared to hobbyists, professional woodworkers are able to more quickly design, start, and construct items that they have made many times before. They also gain an ability to see inherent issues within someone else's design having made that mistake in their work.

So, does software reuse prevent software developers from becoming more proficient?

In many ways, software design and construction is always new.  We don’t repeat past works, because if we can reuse a module, library, or system then we do.  We’ll preferentially extend an existing system before rewriting the entire thing from scratch.  But repetition is what allows us to find efficiency in the design and the construction. Anyone who has practiced a sport or physical activity will tell you that repetition is the key to becoming a good practitioner.

My question: Does software’s ability to be reused prevent the necessary process improvement and efficiency that comes from repeating a project?

答:
I think the idea that other engineering disciplines don't make use of reuse is wrong. Even when designing buildings/machines you still have components that are used by many other projects. For example, do you design you own screws? Engines? Doors or windows? Of course not. Those are often designed by different people who then use them in different product. And they are quite often standardised, which promotes even more reuse.

I think the problem likes in complexity. You simply cannot compare complexity of even the most complex buildings to complex software. It is a generally accepted idea that software complexity is what makes it hard to approach from the engineering side. The moment you have a process in place that allows you to create software of acceptable quality, you find that the complexity of software you need to create jumps in order of magnitude. So the process cannot be used. So if we had to repeat some part of software multiple times until we are satisfied with the result, we would never finish that software.

That is why clean code is promoted. Ability to change past code based on new experiences can be said to be form of design reuse. So instead of creating different software multiple times, we refactor and refine single piece of software by reusing new experiences and design on old problems. All while trying to make software do the same thing.


问:
Is it legitimate to ask co-workers to use specific browser in an intranet website?
I developed an intranet (local network) ASP.NET web project for my co-workers.

In the development process I used Chrome and Firefox and didn't test much with Internet Explorer.

The website works well with Firefox and Chrome and with IE it had major bugs.

Is it legitimate to ask the users to use Chrome or Firefox?

They are all co-workers (around 15 users).

I don't want to spend time fixing the bugs for IE, some might be related to stuff I can't fix myself (jQuery things), if I wanted to be compatible with all browsers, I would have to make a major re-design,

答:
If your program is worth using, they will choose to use a browser that works, you won't have to ask them.

OTOH, you are putting your code out there for others to use. This is a Good Thing, and is how reputations are built. Keep that in mind when you give tools to your co-workers. Make it the absolute best that you can.


答:
The ability to reuse software does not prevent process improvement.

If you think about the processes that go into building software - developing requirements, designing the system, implementing the system, deploying the system, managing requirements, managing configurations, verifying and validating work product, tracking changes, and a number of others (see the CMMI process areas for one possible breakdown of key activities in software development) - these are repeated on every project regardless of how much reuse you have. In addition, each has some kind of quantitative and qualitative measures that can be used to determine how good that particular process or activity is, and as a result, how good the development process as a whole is.

In one end of the extreme, we can assume a robust software product line. At the other, you can assume greenfield development. There's still a need to perform all of these processes, to varying degrees, although they may happen at different rates or perhaps even in different sequences. For example, in a high amount of reuse, a greater percentage of the allocated time may be spent on integration and verification/validation activities at a system level (requirements V&V, integration tests, system tests, acceptance tests). With new development efforts, a greater percentage of the time may be required at design and implementation. As long as you perform a process at least once during the course of a project, you can measure it (quantitatively and qualitatively). Once you make adjustments, and see how those adjustments impact some measure of either the process area or the overall capability to deliver software, and then refine the process for other projects.

They key to process improvement is to have some kind of logical breakdown of your activities and processes, determine how to measure them (preferably consistently), and how to understand those measurements to make process changes toward some end. It's not about repeating the project, but about consistency in how you repeat the process.

Title: Does software reuse preclude process repeatability

Body:
Code Reuse as a Problem

I was thinking about this question on software delivery, and I kept coming back to the issue of repeatability and / or reproducibility.  They matter, because if you don’t repeat a project then it becomes more difficult to improve the process you used to build the project.  Engineering involves constantly improving the processes involved with design and construction in order to produce higher quality projects.

Software can rely heavily upon reuse due to its digital form.  Instead of rewriting a module, we just call it again or copy it to the other system.  Some examples are authentication / login or perhaps a logging function.  There are many well known examples for those categories, and conventional wisdom is to reuse what exists instead of rolling your own.

Some Comparisons to Other Disciplines

Construction

In contrast, construction of physical systems (buildings, bridges) is nowhere near as reusable.  It’s true that the blueprint of a house can be reused many times to build the same copy of the house, but the construction must be performed each time.  Cut & paste doesn’t work like that in the analog world.  Bridge blueprints are less reusable that houses because site conditions will vary.

Master builders are experts recognized for having designed and / or built tens, hundreds, or thousands of things in their area.  For example, Frank Lloyd Wright, a world renowned architect and designer designed more than 1,000 structures and completed 532 works.  Contrast that with Anders Hejlsberg who has designed “just” five languages (Turbo Pascal; Delphi; J++; C#; Typescript).  In many ways, it’s an unfair comparison because the domains are different.  But at a broad level, the quantifiable production from two very intelligent people is vastly different.

Martial Arts

Martial artists will say that mastery of a move comes only from thousands of repetitions. After a good portion of those repetitions have been put in, many martial artists are surprised at how a previously perceived to be complex kata or form has become simple. Instructors of those students will also notice how the motion becomes more fluid and purposeful as well as having an economy of motion. Likewise, experienced martial artists are able to pick up more complex katas more quickly than less experienced students. Experience from repetition has given them a framework or process that allows them to learn more quickly.

Woodworking

Woodworkers experience a similar transformation. Hobbyist woodworkers always refer back to their first project that required a lot of drawers. If they complete the project, they gain a new appreciation for the efficiencies that assembly lines produce. There are other benefits such as a better understanding of how to lay out the drawers parts on the sheet stock in order to maximize use of the wood. Compared to hobbyists, professional woodworkers are able to more quickly design, start, and construct items that they have made many times before. They also gain an ability to see inherent issues within someone else's design having made that mistake in their work.

So, does software reuse prevent software developers from becoming more proficient?

In many ways, software design and construction is always new.  We don’t repeat past works, because if we can reuse a module, library, or system then we do.  We’ll preferentially extend an existing system before rewriting the entire thing from scratch.  But repetition is what allows us to find efficiency in the design and the construction. Anyone who has practiced a sport or physical activity will tell you that repetition is the key to becoming a good practitioner.

My question: Does software’s ability to be reused prevent the necessary process improvement and efficiency that comes from repeating a project?


问:
When there is no API
When it is necessary to integrate with a web application, and an API is unavailable, is it a viable solution to simulate a web browser interacting with the web application as a real user would interact with it?

UPDATE

Some context.

Web App belongs to a vendor/partner. Their timeline for building a proper API will not meet our needs.

Scraping for data is the least used part. Full CRUD for interacting with the app is required.

As a developer, I can see that it will work, but I want to be able to address concerns that others may raise about this approach.

Would you base a mission critical business application on this approach? Why or why not?

答:
Would you base a mission critical business application on this approach? Why or why not?

No.

The approach is brittle; it's too easy to break, too difficult to maintain and impossible to test. I wouldn't rely on it in any sort of critical mission context.

To get it to work at all, your partner would have to be willing to freeze the UI so that it would not change and break your interface.  Otherwise, you're signing up for an ongoing, never-ending maintenance nightmare.

Title: When there is no API


答:
If the problem is with a third-party vendor/partner that your company has a solid relationship with, then the best person to ask is the vendor. Get in contact with someone at their company, preferably someone associated with the team building the API, and ask their opinion; they will probably know the ins and outs of their application fairly well, and be able to offer good advice.

How viable it is to interact with the webapp by pretending to be a browser is very dependent on the nature of the webapp. If it's a javascript-heavy, AJAXy, stateful app, you may have to do a LOT of testing and extra development to make things work, because without a proper API, you have no guarantee that they aren't doing something really crazy and evil like changing state logic when they see your browser request a particular page's CSS because that signals some particular line of javascript loaded and executed, and it was the only way their junior programmer knew how to get something done.

On the other hand, if it's a fairly stable, well-designed, preferably RESTful webapp, you should be able to send HTTP requests of various types at it, parse the responses, and have it work.

There's also always the old programmer standby of adding another layer of abstraction. Depending on the nature of your company's relationship with the vendor, you may be able to get the actual interface of the API before it's completed, or even just get a general idea of how it will work. At that point, you can write your own "API" internally to emulate theirs using the webapp's existing features. Once the real API arrives, you should be able to quickly convert your implementation into being nothing more than a thin wrapper around the proper API. Then, hopefully, you can ultimately refactor the wrapper layer out of existence, without ever breaking functionality. It's not a very pretty, or purist solution, but if the vendor is willing and able to work closely with you, or even just willing to throw a few pages of API documentation at you, this might be a fairly practical way to get the functionality working now, while being able to quickly and painlessly (as much as is possible) switch over to the proper API when it becomes available.

In any of these cases, if the webapp is being hosted on servers owned by the vendor, you really do need to clear this with them first, especially if your app is going to be hitting theirs for data with any regularity. If the webapp is instead part of something hosted internally in your company, then you should similarly check with your network/system admins, give them an idea how heavy the traffic will be, and make sure they're okay with it. Failure to alert people before slamming their server with traffic is not cool, and may result in things like being IP banned from accessing them, making their company more hostile to yours, or even getting yourself fired when both those things happen, and management starts looking for someone to blame so they can get back in the vendor's good graces.

Title: When there is no API

Body:
When it is necessary to integrate with a web application, and an API is unavailable, is it a viable solution to simulate a web browser interacting with the web application as a real user would interact with it?

UPDATE

Some context.

Web App belongs to a vendor/partner. Their timeline for building a proper API will not meet our needs.

Scraping for data is the least used part. Full CRUD for interacting with the app is required.

As a developer, I can see that it will work, but I want to be able to address concerns that others may raise about this approach.

Would you base a mission critical business application on this approach? Why or why not?


问:
MVVM pattern - Best design approach to manage an application
One year ago, I discovered the WPF technology and I developed a little application, as first experiment, to compare the content of two different directories. The content of each directory is shown in a different DataGrid.
At that time, I didn't develop the application using MVVM pattern, because it was only an experiment, not so good, but it worked.

Now that I've much more experience with WPF and with the design patterns, I'm not so proud of that work, and I want to rewrite the application, improving it and following the recommended MVVM pattern.

Actually, I designed the application in this way:

the MainModel, with the main common algorithm.

the MainView is the unique view of the application with the datagrids where I can show the results of my algorithms.

a MainViewModel, that it will take care of handling the connection between other two ViewModels, the MainModel and the MainView.

One ViewModel for each DataGrid. In this way, I'll separate the behavior and the data of the two DataGrids.

The MainModel contains the main algorithm used to search the files in a given directory, like this:

```<code>public class MainModel
{
    public MainModel()
    {}

    public List<Results> GetFiles(string directoryPath)
}
</code>```

The MainViewModel will instantiate an object for each ViewModel (I have a ViewModel for each datagrid), using some properties to do it:

```<code>public class MainViewModel
{
    public MainViewModel()
    {
        FirstViewModel = new ViewModelDG1();
        SecondViewModel = new ViewModelDG2();
    }

    public ViewModelDG1 FirstViewModel
    {get;set;}

    public ViewModelDG2 SecondViewModel
    {get;set;}
}
</code>```

I wanted to apply a design pattern to help me manage the application, like a Factory Method or Builder, or a Template Method, but I think they're not suitable for my application for the different usages/conditions of those design patterns.

I'm not so sure of this design, I don't know if this a is correct implementation of the MVVM pattern and if it promotes a loose coupling and high cohesion. Can you help me in the design? Is mine a correct implementation of the MVVM? If not, then what is the correct one? What are your opinions?

Thank you.

答:
Alberto, about one and a half years ago I was where you are now, and I've learned a lot about MVVM, WPF and Programming Meta Skills on the way.

For the time being, I will refrain from answering your questions specifically, and like to get a few words out that are of general interest/guidance, if you will.

MVVM is a design/architectural pattern that takes some time getting used to. There is no one right or correct way, MVVM is practiced in many different flavors with strictly no code-behind on the one side, and a more "integrated view model"-like approach (with a certain amount of code-behind allowed) on the other side. As with many things in IT, this topic also borders on personal liking.

Don't make the mistake I made by trying to push in patterns (or someone else's design liking) for patterns' sake. Recognize your specific problems, and try to solve them one at a time. See how other WPF/MVVM experts are solving and buildings things. By recognizing a problem and finding a way to solve it, you learn your MVVM/WPF skill by heart. Many small steps will get you in the right direction faster than any doggedly "I'm trying to get this 100% correct the first time" approach.

Now to your question:

I cannot see any problem with your approach so far. The only things I'd like to comment on are:

Instantiate your VMs via lazy loading, so that they consume memory/processing time only on-demand. Also, if you're allowing re-setting your view model objects (see your setters), please make sure that the container class implements INotifyPropertyChanged.

public ViewModelDG2 SecondViewModel {
    get { return _viewModelDG2 ?? (_viewModelDG2 = new ViewModelDG2()); }
}

As for your "loose coupling" concern: That one is more about providing interfaces to your specific implementation (classes). If the view is created in a different assembly, it might make sense to operate via internal classes and public interfaces.

Resources I can warmly recommend to you:

MVVM Survival Guide for Enterprise Architectures in Silverlight and WPF

Developer's Guide to Microsoft Prism 4 Building Building Modular MVVM Applications

Pro WPF and Silverlight MVVM

Best!


答:
Some of the reasons you've pointed in your question are really important and by themselves could very well make the case in favor of unit testing, but YMMV. For instance, how often do you run your integrated test suite? My experience with integrated tests is that sooner or later they'll get so slow you won't run them every time you make a change and the time between inserting and detecting a bug will increase.

Also, a big mistake you may be making is trusting that

Find bug that may not be caught in integration test. e.g. masking/offsetting bugs.

is not important. Are you expecting that your users find the bugs for you? Trusting coverages obtained from integrated tests is dangerous in my opinion, you can very easily get a high % of coverage but in reality you are testing very little.

I guess the canonical reference against integrated tests are the posts of JBrains:

http://www.jbrains.ca/permalink/integrated-tests-are-a-scam-part-1

in case you haven't read them already.

Finally, IMO the feedback you can get from the unit tests for your design is invaluable. Judging a design by gut feeling and relying on integrated tests may also be a mistake.

Title: Do I need unit test if I already have integration test?

Body:
If I already have integration test for my program, and they all passed, then I have a good feel that it will work. Then what are the reasons to write/add unit tests? Since I already have to write integration tests anyway, I will like to only write unit test for parts that not covered by integration tests.

What I know the benefit of unit test over integration test are

Small and hence fast to run (but adding new unit to test something is already tested by integration test means my total test suit get larger and longer to run)

Locate bug easier because it only test one thing (but I can start write unit test to verify each individual part when my integration test failed)

Find bug that may not be caught in integration test. e.g. masking/offsetting bugs. (but if my integration tests all passes, which means my program will work even some hidden bug exists. So find/fix these bugs are not really high priority unless they start breaking future integration tests or cause performance problem )

And we always want to write less code, but write unit tests need lots more code (mainly setup mock objects). The difference between some of my unit tests and integration tests is that in unit tests, I use mock object, and in integration tests, I use real object. Which have lots of duplication and I don't like duplicated code, even in tests because this add overhead to change code behavior (refactor tool cannot do all work all the time).


答:
If you expect ever to have to modify or refactor your code, having unit tests is essential.  Unit tests exist not only to demonstrate bugs at the time the code is written, but to show when new bugs appear when more code is written.

Yes, it is much better to write your integration and unit tests first, but it there is a lot of value to having them even if they are written later.


问:
"every statement and declaration an expression that yields a value" why?
At the end of the answer to "Can I do ++x and x++ in Python?" on this page: http://norvig.com/python-iaq.html, you can read:

[...] I'm with my fellow Dane, Bjarne Stroustrup, on this one. He said in The Design and Evolution of C++ ``If I were to design a language from scratch, I would follow the Algol68 path and make every statement and declaration an expression that yields a value''.

Why?

答:
The main aims and principles of design of ALGOL 68:

Completeness and clarity of description

Orthogonal design,

Security,

Efficiency:

Static mode checking

Mode-independent parsing

Independent compilation

Loop optimization

Representations - in minimal & larger character sets

0.1.2 Orthogonal design

The number of independent primitive concepts has been minimized in
  order that the language be easy to describe, to learn, and to
  implement. On the other hand, these concepts have been applied
  "orthogonally" in order to maximize the expressive power of the
  language while trying to avoid deleterious superfluities.

“ALGOL 68 was the first (and possibly one of the last) major language for which a full formal definition was made before it was implemented.” — C.H.A. Koster


问:
Should I represent the Database in my use cases?
I am creating use cases for my web application and I was wondering if a representation of the DB should be listed as an actor. For example a user can check his profile and edit it (assuming that he is logged in). The two use cases would be:

- User can view his profile

- User can edit his profile

Would the use cases then be for example:

Actor: User, DB

Use case: View profile

Or can I leave out the DB as an actor? Unfortunately I haven't found any consistent way of drawing the use cases.

答:
According to my point of view I think Use Cases are drawn largely to depict the Interaction between System and External Environment.

Hence, DB is an internal entity comparing to the system, so it's not worthwhile to draw DB as an actor unless it's an external entity. At the same time, it should be mentioned that though it's an external body, accessing it directly can raise security issues, right!

Therefore, unless you have a very special reason for doing it like that, it's not wise to depict DB as an actor in Use Cases. Of course you can do that in Sequence Diagrams: there's no such issue, since it shows the interaction between actors and objects.


答: As with any design, removing exceptional scenarios makes for a cleaner design - those branches interact with the rest of the design causing cascading impacts. By allowing all expressions (and statements) return a value (even if that value is unit) allows the design to be simpler. Further, it allows you to get functionality for "free" without having to make specialized versions for statements versus expressions.

Title: "every statement and declaration an expression that yields a value" why?

Body:
At the end of the answer to "Can I do ++x and x++ in Python?" on this page: http://norvig.com/python-iaq.html, you can read:

[...] I'm with my fellow Dane, Bjarne Stroustrup, on this one. He said in The Design and Evolution of C++ ``If I were to design a language from scratch, I would follow the Algol68 path and make every statement and declaration an expression that yields a value''.

Why?


问:
Migration from a complex C++ application to C# a -- good idea?
We currently have a complex VC++ software application, which uses a library like ObjectARX to build the dll. I feel there are many features in C# like Collections, Generics, and other libraries which can be used to build the current application in a better and efficient way.

I have been thinking about it, but I am not sure on how to present it to my supervisor and colleagues.

I would appreciate any help, to help me think in the right direction and highlight the points to bring it to the team.

Few points that I thought was;

With some current examples, implementing it in C# with the features.

Highlight the development time is comparatively lesser in C# than C++.

Use a Design Architecture.

答:
It sounds like your'e about to make a lot of really bad decisions.

Highlight the development time is comparatively lesser in C# than C++.

That sounds incredibly suspect. It's certainly not true if your team knows C++ but doesn't know C#, for instance.

I feel there are many features in C# like Collections, Generics, and other libraries which can be used to build the current application in a better and efficient way.

C++ definitely has those things and in fact generics are more facile in C++ than any other language. It sounds like you just heard somewhere that C# is better, so want to spend weeks rewriting everything into C#, then not actually be any better at doing things in C# than you are in C++. Start with STL and boost...

Use a Design pattern, which will help us to maintain the application in a better way.

You seem to have no idea what a design pattern is.

Long story short: You cannot make a sound engineering case based on hearsay. You must make it on technical knowledge.


问:
What's with the aversion to documentation in the industry?
There seems to be an aversion to writing even the most basic documentation. Our project READMEs are relatively bare. There aren't even updated lists of dependencies in the docs.

Is there something I'm unaware of in the industry that makes programmers dislike writing documentation? I can type out paragraphs of docs if needed, so why are others so averse to it?

More importantly, how do I convince them that writing docs will save us time and frustration in the future?

答:
When I started my current job and took over a hardware + software project from from the people who had previously been working on it, I was given a hundred or so page ms word document describing the system. It must have taken days to produce. I looked at it maybe twice. Despite the massive amounts of information in there, it rarely answered the actual questions I had about the system, and even when it did, it was faster to look at the code.

After enough experiences like that, you just start to think, why bother? Why spend your time answering questions that people never asked? You start to realize how truly difficult it is to predict what information people will seek in the documentation;  it is inevitably filled with facts that turn out to be useless, unclear or obvious, and lacking the answers to the most pressing questions. Remember, producing useful documentation is an effort in predicting human behavior. Just as a user interface design is unlikely to succeed before it has gone through multiple iterations of testing and debugging, so it is naive to think that it is possible to write useful documentation based only on expectations of how people will interpret the system, and what role the documentation and its language will play in that interpretation.

I tend to think that most of the pressure to write documentation stems from the fact that it is an unpleasant chore and people like guilting each other into doing unpleasant chores ("You haven't eaten your filboid studge!").

HOWEVER

I do not think that documentation is, in all ways, hopeless. I think it is hopeless primarily when people look at documentation as this extra burden that must be fulfilled before a job is finished, as a last bit of cleanup work to be hurried through, and as a box to be checked. Documentation is something you should work into the aspects of your day that you always do anyway. I think email is a particularly good way to do documentation. When you add a new feature, write a few people a quick email saying what it is. When draw a new schematic, generate a PDF and send it to anyone who might be interested. The advantages of email are:

People usually check email, whereas no one wades through a folder called "doc".

Email exists in context, surrounded by other emails discussing the feature and related features and anything else that was going on at the time.

Email is short and focused and has a subject line.

Email allows the people who care to ask questions right away,

Email is highly searchable, because people use it for everything and mail clients have advanced quite a bit over the years.

If it's in an email, at least one other person knows where to find it.

In theory it should seem that comments in code should also be "aspects of your day that you always do anyway", but to be honest, I never read comments in code. I'm not sure why, but they're just not very helpful, maybe because there is a lack of context, which email solves.


问:
Difference between application-level and system-level testing
I heard the terms "application-level testing" and "system-level testing". I think I know the difference, but I am not sure. I tried to do some research on the internet, but the closest explanation of the difference that I can find is this http://en.wikipedia.org/wiki/Software_testing#Unit_testing (unit testing and system level testing).

Does application-level testing mean the same as unit testing? This is not a homework question, I am just wondering if they are the same.

I am a student and still learning, I appreciate your help! Thanks.

答:
I would say that those terms are not set in stone and thus tend to vary depending on who you ask. The only valid version is the version used by the organisation for which you work. Since you are a student that would mean just use whatever your teacher tell you is the definition, if you ever have to think about it in a course.

In my own organisation those term are not much used, and we (internally) use a variation of the test used by the "Growing Object Oriented Software" book (very recommanded read).

We have

Unit test : a single part of your own code cut from every dependencies

Integration test : same as unit test but for the code that must interact with an external component/library

Functional end-to-end test : the whole application tested via the inputs/outputs

We simply don't use at all the terms application testing and system testing.

So to get back to your question : don't stress too much over the definition of those terms. To paraphrase what a software vendor once said "It means whatever the customer think it means". If you ever work for an organization that use those terms, just use their definition.


答:
Short answer

You should consider that it's a very risky and costly idea that may not give you as many benefits as you think it might.

Long answer

You should consider the following:

C++ is a language that can be used at a very high level, that is cross platform (though that depends on how much you used the VC proprietary extensions) and for which many very mature tools exist. C++11 will add even more juicy bit to handle annoying use cases.

If you're thinking about a full rewrite, don't forget that rewriting fully debugged code is time you won't be implementing any new features. If you don't have a clear benefit for using C#, this is throwing money and time through the window.

If the team knows C++, then for a long time writing code in C# will be slower despite any advantage that C# brings.

You have two option for migrating your apps : restart from scratch (and see http://joelonsoftware.com/articles/fog0000000069.html , already posted), or add new features by maintaining a mapping layer between the C++ and C# code. While C# is quite good as far as calling native code go, it's still some pretty complex code to write. If you either use P/Invoke or C++/CLI, both will force you to know much deeper detail about the platform than would be required for a pure C# solution. Also, you'll spend an awful lot of time marshalling data between managed and native code. A better option may be COM, though I hope you like ATL programming.

The biggest benefits of C# are its simplicity and garbage collector that free you from thinking about a lot of corner cases. That mean it can be developed by developers that are less hardcore than what you need for C++. In your case, your team already know C++ so those benefit are much less present. If you use unique_ptr, shared_ptr, RAII and such, much of the dangerous part of C++ can be managed. Yes, you have more options to shoot yourself in the foot, but you avoid the dangerous parts.

But still...

If you're not talking about a full rewrite, yes, it could be possible to develop some part of the application in C#. But always keep it mind the cost of the mapping layer between C++ and C#. I would recommend exporting your C# parts as COM modules and calling that from C++. Be sure it bring a real advantage. If you must constantly convert vector<> to IList<> and must constantly convert your C++ type to C# one, any speed advantage of C# will be lost. You gain most of converting to C# and .NET when everything can stay inside the CLR. Getting everything inside the CLR mean a complete rewrite of a complex application and that is dangerous proposition.

All in all, I wouldn't recommend it.

Title: Migration from a complex C++ application to C# a -- good idea?

Body:
We currently have a complex VC++ software application, which uses a library like ObjectARX to build the dll. I feel there are many features in C# like Collections, Generics, and other libraries which can be used to build the current application in a better and efficient way.

I have been thinking about it, but I am not sure on how to present it to my supervisor and colleagues.

I would appreciate any help, to help me think in the right direction and highlight the points to bring it to the team.

Few points that I thought was;

With some current examples, implementing it in C# with the features.

Highlight the development time is comparatively lesser in C# than C++.

Use a Design Architecture.


问:
Learning basic graphics programming
After learning the basics of computing simple die throwing games and calendar applications, I want to explore simple graphics - drawing and moving around geometric objects is ok to start with, eventually adding pixel graphic of course.

I've taken an introductory Java course but would rather do it in C++, Python or a combination of them (that's what we will eventually be using in school). I also want to learn the principles behind it, not just blindly applying incomprehensible syntax to make the compiler happy.

Some posts seem to imply SFML is a solid choice, so I thought I'd get a book covering it and work through it, but there only seems to be ONE book on SFML available, and that one hasn't been reviewed at all. Not in the mood for a $30 gamble, so I'm feeling kind of lost!

How should I approach learning basic graphics programming?

答:
As a starting point I'd recommend Googling the following keywords:

Transformation Matrix

World Matrix

View Matrix

Projection Matrix (This one is really only valid if you're wanting to do 3D)

Matrices are more of a mathematics thing, but they're crucial to understanding how a system like Direct3D or OpenGL is working, so if you're wanting to do more than just follow instructions I recommend understanding the use of Matricies within code.

You'll probably need to build up a lot of practice with code though to be able to apply all of these principles in code.

You can write graphics code without understanding the underlying math, but I find it a lot more fun (less frustrating) to program when I understand the entirety of the system I'm building.

I don't know what the best way to go about learning the coding side of it specific to Java though.

Title: Learning basic graphics programming


问:
Google App Engine -- should we use it?
I'm considering using Google App Engine for an online matchmaking (and possibly ranking, not sure) of users in a (currently hypothetical) RTS game. However, I just read this bad review, which has made me nervous. Which problems have they solved (or are planning to solve), which might be an issue for me, and are there any alternatives?</p>

答:
Google App Engine uses a NO-SQL data store---you should read up on that concept, and decide if it sounds like a good fit for your needs.  From that review, it sounds like that is the main issue the reviewer had with GAE.

There is a certain amount of vendor-lock-in with GAE.  You end up writing code to target a specific environment.  You could certainly migrate off of GAE in the future, but it would likely require at least some code change.

You should also plan to code import/export features so that you can get your data out of GAE, and into a new system.

Once you understand how GAE differs from a standard environment that you might set up if you were to get a stock linux server or VM, you will be able to decide if it fits your needs.  There are some definite advantages to GAE, especially in the cost arenas (you don't need to pay for hardware or infrastructure management until your site get popular, when hopefully it will be able to pay for those costs).  Just be sure you do the due diligence and research before jumping in.

ContentLicense: CC BY-SA 2.5

Title: Google App Engine -- should we use it?


问:
Could it be possible to add the integer type to the ECMAScript standard?
In JavaScript, every number you will ever use will always be represented with what C programmer would call a double. The official type is I believe number. If I recall correctly, that fact was mentioned by Google as a "fundamental" problem with JavaScript and one of the reason why they wanted to have clean break with Dart. Now, I can't help but wonder :

Can the ECMAScript standard just add that type? Would it be possible to do without breaking existing code?

Anyway, can't a JIT engine watch the integer usage and generate code that is almost as efficient as using a native integer type, by using integer registers and opcodes?

In effect : Could it be done? Why should it be done?

答: As for your second point, yes, integer use can be detected. Firefox does it as part of their asm.js feature. It's not entirely straightforward: for example, adding two integers may overflow. That wont happen if the values were added as double. To account for this, every expression that should produce a true 32 bit int is appended with | 0, which does nothing except forcing the result to be an int.


问:
Can a random number generator ever produce different output given identical seeds?
The title sums it up. I'm interested to know if there exists an algorithm capable of producing variable output given identical input without relying on other sources for randomness such as DateTime.Now or a number generated from a light sensor etc. In addition, the algorithm can not be run in sequence, just two distinct, unrelated runs that produce different output.</p>

答:
No, a pseudo-random number generation algorithm will always produce the same output given the same seed (hence pseudo-random).

I find it interesting that you used the term, "algorithm" rather than "program." This excludes a certain class of yes answers (soft errors in RAM, different thread interleavings in a multi-threaded RNG, etc.).  If you take it as granted that every run of your algorithm takes the same input on each iteration is well-specified with no randomness, then it will generate the same output on each run.

That being said, even basic things like CPU temperature are unpredictable enough to act as an entropy source if they are normalized appropriately.  So, don't think this implies that a "cryptographically secure" random number generator can be predicted if you know what time it was run; many of them make use of system-generated entropy feed.


答:
We currently have a complex VC++ software application, which uses a
  library like ObjectARX to build the dll. I feel there are many
  features in C# like Collections, Generics, and other libraries which
  can be used to build the current application in a better and efficient
  way.

(Remark. ObjectARX is the extension API for AutoCAD. Thus, OP is asking about a domain-specific application known to require deep domain-specialized knowledge.)

Take a deep breath and ask yourself whether the complexity of the software comes from the domain (computer-aided design and computational geometry), or from the choice of language. If the complexity comes from the domain, changing language may not significantly make your job easier.

Case in point, using a dumb example: a Polygon is not the same as IList<Point2>. How would an IList know how to check for repeated points? Self-intersecting segments? Embedding a coplanar 2D polygon into a plane in the 3D space?

Occasionally, the lack of some syntactic sugar in some languages will indeed complicate domain-specific software development. A prime example is lambda function. With C++11, these essential syntactic sugar can be used to simplify and modernize the code. If this is the case, modernizing the C++ code may be a better choice than migrating to C#.

Another remark to other readers: Each release of ObjectARX for Visual Studio is tied to a specific version of Visual Studio, and is neither backward nor forward compatible. As of ObjectARX 2013, use of VS2010 SP1 is required. (Thus, OP cannot easily recommend using VS2012 unless the vendor release a new version of ObjectARX and the customer (OP's employer) upgrades to it.) http://usa.autodesk.com/adsk/servlet/item?id=12257036&siteID=123112

Fortunately, VS2010 SP1 also supports a useful subset (but not all) of the C++11 syntax. In particular the iterator for-loop would simplify newly-written code somewhat. The benefit, however, might not justify modifying old code, though.

I have been thinking about it, but I am not sure on how to present it
  to my Supervisor and colleagues.

The best way is to just informally ask your supervisor (ideally the software architect) for consideration. It is his/her job to keep an eye on every possibility, including platform choices, migrations and the long-term viability of the project.

If you actually find yourself more knowledgeable than your supervisor / software architect (which is highly unlikely), find another job.

I would appreciate any help, to help me think in the right direction
  and highlight the points to bring it to the team.

My suggestion:

Roman wasn't built in a day.

At any point in time in your hypothetical re-implementation, the application as a whole needs to be demonstratable (at least runnable and testable). Thus, it will contain parts written in VC++ and parts written in C#. If you can demonstrate that the application still works in a satisfactory way (no major bugs, issues or inefficiency), you have found a "jungle path" from the project's C++ present to the C# future.

A sample worksheet:

Suppose 5% of the project will be migrated to C#.

Which modules or components in the project would you choose to be migrated to C#?

How do they interoperate with the rest of the application?

Do you foresee any difficulties?

Repeat the question for 20%, 40%, 60%, 80%, and 99%.

Another important question to ask:

Are there other teams in the company (or paying customers) that depend on the application being C++? Will these teams agree to migrate to C# as well, or will your team be able to provide interoperability for that team?

If you have done this, present your findings to the software architect, who will then be responsible for identifying roadblocks ahead in the remaining sections of this jungle path.

If you don't know how C++ and C# can interoperate ... I suggest you close this question ASAP before a torrent of downvotes burn away your hard-earned reputation points ...


答:
Did you know that people work very hard to ensure that, given the same seed, the same sequence of random numbers is produced every time? This is a desirable property for things like Monte Carlo simulation, as it it means that results are fully reproducible. If you don't specify the seed, something like the time will be used, but that exact reproducibility is really wanted.

The only RNGs where this is truly undesired are those used for cryptography, and those typically achieve this by using the operating system's own random number source (which is not rewindable under normal circumstances and which may use fancy hardware) to provide their seed.

Title: Can a random number generator ever produce different output given identical seeds?

Body: The title sums it up. I'm interested to know if there exists an algorithm capable of producing variable output given identical input without relying on other sources for randomness such as DateTime.Now or a number generated from a light sensor etc. In addition, the algorithm can not be run in sequence, just two distinct, unrelated runs that produce different output.</p>


问:
Tools aiding in documenting API requierements for a REST Service
We need to define our requirements for a REST API. What are tools which aid in creating a document which will fully describe the webservice so it can be created by another entity?</p>

答:
I am a RESTful web developer (real, "HATEOAS", Level 3 REST) but I have never come across a tool to help me define a service. For general diagramming purposes however, I do like OmniGraffle.

To be honest, I think a text editor, a knowledge of the domain and of the recipient's level of vocabulary and understanding, are all you really need.

Are you wanting to specify every resource and how it relates to every other resource? How low down into the details are you trying to go?


问:
Extracting user requirements from a person who does not know how to express himself
I had an interview yesterday with a member of our organization who wanted to create a system to help him to do his job, the problem I had with him was that he had only a general idea about what he want. I tried to get more information from him by asking him specific questions which he had no answer to, such as what he expects to see in the first page when he opens the system..I told him that we will meet again in a few days because I wanted to think of a different approach to get clear requirements of him.

My question is what type of questions should I ask to get what he exactly wants, is there a guide that can help me go through this successfully?

答:
Case Study

I recently embarked upon a re-write of our company's primary internal web app. To find out what features of the old app were used and which we not, and which related activities were too disconnected from one another, I logged all activity for three months beforehand, and analysed paths taken through the software. As I work in the same office as the users, I am also aware from past experience of how they tend to operate and what the larger business processes were. (The job shadowing mentioned in another answer, but done passively.)

Armed with knowledge of how the users were using the system, I then conducted user story interviews and produced a list of requirements. I selected a part of the application that had no dependencies as a starting point, and began iterative development using those requirements. The new software is already more testable and has a degree of separation of concerns that the previous software could not hope to achieve.


问:
Can You Use 2 Python Modules Issued Under LGPL and BSD License in a Program?
I'm making a drawing program as my first open-source program merely to get a taste of the open-source community. To make said program, I am using Python 2.7. I'm using the following modules:

EasyGUI 0.96 - Under the 3-clause BSD license

Pygame 1.9.1 - Under the LGPL 2.1 license

All I intend to do is create a program using these modules which depend on it, and upload it to a public GitHub repository for others to freely modify and distribute.  If using my code is allowed in closed source software, or profits to be made by others, I do not want it.  I do not wish to modify Pygame or EasyGUI themselves, either.  They just need to be simply provided to run the software.

Is this possible with the two licenses mentioned above? If I were to do this, what license would I have to issue my program under and why? Are some better choices than others?

Is it also possible release my drawing program code under a reciprocal license so the people contributing send their bug fixes in my script back?

答:
Neither license limits what other libraries you can use in your project, nor do they dictate what license the overall program (the "Application" in the LGPL license) should use.

You are free to release your program under whatever license you choose. All you have to do is list both projects and their licenses in your application documentation (see "4. Combined Works" in the LGPL license for the more detailed rules that license requires of you).

If you want to force people to share any modifications to your application they make, use the GPL license (note, no L at the start) for that program.


答: The only issue I have with GAE is the Data Store. The vendor lock-in of GAE is also a problem but you can get around it by using Django-nonrel (if you're using Python and Django). Aside from that, GAE is viable because it's fast, can serve a lot of users without fail, and is cost-efficient. It's perfect for startups since they don't risk having to buy their own hardware early on.</p>

Title: Google App Engine -- should we use it?

Body: I'm considering using Google App Engine for an online matchmaking (and possibly ranking, not sure) of users in a (currently hypothetical) RTS game. However, I just read this bad review, which has made me nervous. Which problems have they solved (or are planning to solve), which might be an issue for me, and are there any alternatives?</p>


问:
How to tell client I no longer want to work on his project
This is probably going to sound messed up, but here it goes.

I've been working on a project for a client for a while now. I wasn't given any details except for "It has to be an XYZ plugin and interface with ABC product". Which was fine, but now we're towards the end (I think) and it's just dragging out. I don't have any time to spend on it and I'm already over schedule by 3 months. Trying to get the client to describe to me how he would like to be able to navigate the data (a UI issue) is just difficult. I've submitted mock ups on what I think he wants but his latest response is "you should look at XXX product", it has similar functionality.

Of course, I looked at it and it looks similar to what I submitted, but I don't think that the way I've built the framework is going to support what he is now describing to me. We've had good communication throguh out the process but he doesn't know what he wants. I explained how I was going to build the framework and he agreed, so it isn't a bad choice on my part about design.

When I go over what I think are finalized modules, he says, "You should have done it this way" which requires me to go back and rework code and UI. Some smaller items could have been better thought out by me, but the big things are how I interpreted his requirements and I've gone over this module several times during development.

I've already received final funds last month so i'm working for free at this point. I no longer want to deal with this project. I've already received payment. I've done other successful projects with this client before and he has a lot of other projects he wants to do.

What the heck should I do? I don't want to work on this project anymore. I don't want to ask for any more money (money isn't really the issue). I don't want to make him mad either. I know it looks like I want to have my cake and eat it too.

If you think I should call it quits, how should I do it given the circumstances?

答:
Here are a few ideas:

tell the client you're out of estimated hours and to continue to work, you should arrange additional funding.

But maybe you "kind-of" agreed to a fixed price. So try this:

final solution for final funding: tell the client that your hours estimate was based on your solution. If he wants a different one, then you need to put in extra hours which will cost him just a little bit more.

Maybe the client is a leech kind of a client, or he just does not know.

deliver your proposed solution with "slight" changes in his desired way. Then say "yes, if you want additional features, we can setup a new project".

Free-yourself solution:

Quit the project. Tell the client you feel bad working on this project any more. You'll probably not get additional work from him and possibly get some bad advertising, but at least you're free to go to new clients and projects. It may not be ethically correct. But it may be good for you in the long run.

If it was me, I would go with one of the first two, being transparent. And in future, I would get the client to agree on a solution before I agree on a price.


答:
I'm interested to know if there exists an algorithm capable of producing variable output given identical input without relying on other sources for randomness such as DateTime.Now or a number generated from a light sensor etc.

No, that's fundamentally impossible, because the very definition of an algorithm is that it's well-defined and deterministic, i.e. given the same input will always produce the same output. There are randomized algorithms, but they require randomness as input.

Furthermore, determinism is the most important design goal of computer hardware. A CPU that does not produce the same output given the same input would be utterly useless for most purposes.


答:
I would definitely share my feelings with this client, be honest to him and tell him you are very willing to bring the project to a successful and satisfactory end, but that you can't go on changing the UI/code indefinitely. Try not to say this in a way that sounds like you are fed up with the project, but say it is best for him, because he needs a finished product that goes into production and that his users can use. Tell him "we" need to bring this to a production-ready state, like you're on his side (which, as a good freelancer or company, you should be)

I think you should follow Amelvin's advice. Agree on a set of requirements that will take to project to completion, specify them very well and implement them. Also, make sure you client understands you appreciate your relationship and you are making an extra effort to turn this into a successful project. Be explicit and open about the extra effort you are taking so he will remember it.

This is one of those questions that make me realize again how important it is to make a detailed specification on what is going to be implemented.

Title: How to tell client I no longer want to work on his project

Body:
This is probably going to sound messed up, but here it goes.

I've been working on a project for a client for a while now. I wasn't given any details except for "It has to be an XYZ plugin and interface with ABC product". Which was fine, but now we're towards the end (I think) and it's just dragging out. I don't have any time to spend on it and I'm already over schedule by 3 months. Trying to get the client to describe to me how he would like to be able to navigate the data (a UI issue) is just difficult. I've submitted mock ups on what I think he wants but his latest response is "you should look at XXX product", it has similar functionality.

Of course, I looked at it and it looks similar to what I submitted, but I don't think that the way I've built the framework is going to support what he is now describing to me. We've had good communication throguh out the process but he doesn't know what he wants. I explained how I was going to build the framework and he agreed, so it isn't a bad choice on my part about design.

When I go over what I think are finalized modules, he says, "You should have done it this way" which requires me to go back and rework code and UI. Some smaller items could have been better thought out by me, but the big things are how I interpreted his requirements and I've gone over this module several times during development.

I've already received final funds last month so i'm working for free at this point. I no longer want to deal with this project. I've already received payment. I've done other successful projects with this client before and he has a lot of other projects he wants to do.

What the heck should I do? I don't want to work on this project anymore. I don't want to ask for any more money (money isn't really the issue). I don't want to make him mad either. I know it looks like I want to have my cake and eat it too.

If you think I should call it quits, how should I do it given the circumstances?


问:
How to model optional use cases in UML
Let's say, I want to model an application which allows users to model class diagrams. The high level use case can be modelled as UC1:Model Class Diagram, which refines itself into UC11: Model Class, UC12: Model Connection, UC13: Model Composition, etc.

Since UC11, 12, 13 are part of UC 1, I used the include-Association. Unfortunately, the UML specification says that included use cases are essential parts and if you would leave one of them out the high level behavior could not be achieved any more.

But in this example a valid class diagram can be created without modelling a connection or a composition, so these use cases are optional.

To boil it down to an essence: How can optional use cases be modelled in UML while providing a mechanism for reuse (like the include association)?

答:
You could use Extend in this case.

Example include and extend:
UC  “login” includes UC  “sign up”:  The login page can be accesses straight away, but if you haven’t signed up the alt path would lead  you to the sign up page . You must complete this UC to get through. You can assess the sing up page directly as well.  So for reuse you could make this two use cases, instead of an alt path and include the sing up UC.

UC “edit profile” extends UC “login”:  The UC “Login” always has a pop-up when you login to ask if you want to change your profile. You don’t have to do this to accesses the site. You can accesses the profile edit page from several places, with its own UC of course.  You would draw this relationship as an extend because its optional to get through.

Title: How to model optional use cases in UML


问:
How does Google App Engine remote_api work
As I understand it, and I may be wrong, but GAE's remote_api allows one application to access another application's datastore. I'll be blunt I don't understand how this works. I have read the article that everyone likes to point to, but I still don't understand how you can link two applications. Can someone explain it to me, perhaps with a small example or just point me to a tutorial that does this?</p>

答: Think of remote_api as a remote shell to your own application. You're not linking two different applications together — there is no way to do that AFAIK — you're just communicating with a single application using a local shell. Your commands are sent over HTTP to a little handler running on your application, which then executes those commands in your app and returns the results. You need to enable remote_api in your app.yaml to get that handler running.


问:
Restrictive routing best practices for Google App Engine with python?
Say I have a simple structure:

app = webapp2.WSGIApplication([
    (r'/', 'pages.login'),
    (r'/profile', 'pages.profile'),
    (r'/dashboard', 'pages.dash'),
], debug=True)
```

<p>Basically all pages require authentication except for the login. If visitor tries to reach a restrictive page and he isn't authorized (or lacks privileges) then he gets redirected to the login view.</p>

<p>The question is about the routing design. Should I check the auth and ACL privs in each of the modules (<code>pages.profile</code> and <code>pages.dash</code> from example above), or just pass all requests through the single routing mechanism:</p>

<pre class="lang-py prettyprint-override"><code>app = webapp2.WSGIApplication([
    (r'/', 'pages.login'),
    (r'/.+', 'router')
], debug=True)
</code>```

I'm still quite new to the GAE, but my app requires authentication as well as ACL. I'm aware that there's login directive on the server config level, but I don't know how it works and how I can tight it with my ACL logic and what's worse I cannot estimate time needed to get it running. Besides, it looks only to provide only 2 user groups: admin and user.

In any case, that's the configuration I use:

```<code>handlers:
- url: /favicon.ico
  static_files: static/favicon.ico
  upload: static/favicon.ico
- url: /static/*
  static_dir: static
- url: .*
  script: main.app
  secure: always
</code>```

Or I miss something here and ACL can be set in the config file? Thanks.

答:
The login/admin settings in app.yaml are only useful if you're using Google accounts for login. If you're not using Google accounts, you'll have to implement things yourself.

I've done it by having my handlers subclass from a base handler class I've defined. The base handler implements authentication, redirecting, logging, and some other common functionality. By default, the base handler requires that the user be logged in; then I override this in the few subclasses that don't require login (safer than the reverse). My admin-only handlers have their own subclass of the base handler, which handles the admin credential verification and redirection.


问:
Nested entities in Google App Engine. Do I do it right?
Trying to make most of the GAE Datastore entities concept, but some doubts drill my head.

Say I have the model:

class User(ndb.Model):
    email = ndb.StringProperty(indexed=True)
    password = ndb.StringProperty(indexed=False)
    first_name = ndb.StringProperty(indexed=False)
    last_name = ndb.StringProperty(indexed=False)
    created_at = ndb.DateTimeProperty(auto_now_add=True)

    @classmethod
    def key(cls, email):
        return ndb.Key(User, email)

    @classmethod
    def Add(cls, email, password, first_name, last_name):
        user = User(parent=cls.key(email),
                    email=email,
                    password=password,
                    first_name=first_name,
                    last_name=last_name)
        user.put()
        UserLogin.Record(email)

class UserLogin(ndb.Model):
    time = ndb.DateTimeProperty(auto_now_add=True)

    @classmethod
    def Record(cls, user_email):
        login = UserLogin(parent=User.key(user_email))
        login.put()
```

<p>And I need to keep track of times of successful login operations. Each time user logs in, an <code>UserLogin.Record()</code> method will be executed. Now the question — do I make it right?</p>

<p>Thanks.</p>

<hr>

<h3>EDIT 2</h3>

<p>Ok, used the typed arguments, but then it raised this: <code>Expected Key instance, got User(key=Key('User', 5418393301680128), created_at=datetime.datetime(2013, 6, 27, 10, 12, 25, 479928), email=u'al@mail.com', first_name=u'First', last_name=u'Last', password=u'password')</code>. It's clear to understand, but I don't get why the docs are misleading? They implicitly propose to use:</p>

<pre class="lang-py prettyprint-override"><code># Set Employee as Address entity's parent directly...
address = Address(parent=employee)
</code>```

But Model expects key. And what's worse the parent=user.key() swears that key() isn't callable. And I found out the user.key works.

EDIT 1

After reading the example form the docs and trying to replicate it — I got type error:
TypeError('Model constructor takes no positional arguments.'). This is the exacto code used:

user = User('al@mail.com', 'password', 'First', 'Last')
user.put()

stamp = UserLogin(parent=user)
stamp.put()
```

I understand that Model was given the wrong argument, BUT why it's in the docs?

答:
Yes, this method of recording logins should work. I would think about whether you truly need to store login records in the database, though. The other way to do it is to write logins to your log, like this:

```<code>logging.info("User %s logged in" % user.email)
</code>```

You need to use named arguments instead of positional arguments when initializing any Model subclass. Instead of this:

```<code>user = User('al@mail.com', 'password', 'First', 'Last')
</code>```

just create your user like this:

```<code>user = User(email='al@mail.com', password='password', first_name='First', last_name='Last')
</code>```

And it does seem like you uncovered an issue with the documentation regarding Address(parent=employee). Just use the key, I suppose. Good catch.

By the way, App Engine's official support forum is Stack Overflow, so it's better to post questions there.

Body:
Yes, this method of recording logins should work. I would think about whether you truly need to store login records in the database, though. The other way to do it is to write logins to your log, like this:

logging.info("User %s logged in" % user.email)

You need to use named arguments instead of positional arguments when initializing any Model subclass. Instead of this:

user = User('al@mail.com', 'password', 'First', 'Last')

just create your user like this:

user = User(email='al@mail.com', password='password', first_name='First', last_name='Last')

And it does seem like you uncovered an issue with the documentation regarding Address(parent=employee). Just use the key, I suppose. Good catch.

By the way, App Engine's official support forum is Stack Overflow, so it's better to post questions there.


问:
Do I need unit test if I already have integration test?
If I already have integration test for my program, and they all passed, then I have a good feel that it will work. Then what are the reasons to write/add unit tests? Since I already have to write integration tests anyway, I will like to only write unit test for parts that not covered by integration tests.

What I know the benefit of unit test over integration test are

Small and hence fast to run (but adding new unit to test something is already tested by integration test means my total test suit get larger and longer to run)

Locate bug easier because it only test one thing (but I can start write unit test to verify each individual part when my integration test failed)

Find bug that may not be caught in integration test. e.g. masking/offsetting bugs. (but if my integration tests all passes, which means my program will work even some hidden bug exists. So find/fix these bugs are not really high priority unless they start breaking future integration tests or cause performance problem )

And we always want to write less code, but write unit tests need lots more code (mainly setup mock objects). The difference between some of my unit tests and integration tests is that in unit tests, I use mock object, and in integration tests, I use real object. Which have lots of duplication and I don't like duplicated code, even in tests because this add overhead to change code behavior (refactor tool cannot do all work all the time).

答:
Integration tests should only verify that several components are working together as expected. Whether or not the logic of the individual components is accurate should be verified by unit tests.

Most methods have several possible execution paths; think of if-then-else's, input variables with unexpected or just plain wrong values, etc. Usually developers tend to think only about the happy path: the normal path that doesn't go wrong. But as far as those other paths are concerned, you have two options: you can let your end user explore those paths through the actions they take in the UI and hope they don't crash your application, or you can write unit tests that assert the behavior of those other paths and take action where necessary.


答: That review is spot on. I use GAE a lot and it's fantastic for a lot of things. If any of those issues are a deal-breaker then you'll need to move on. If you can deal with those issues then you will have a very scalable application on your hands. I think it may be a good match for your domain, though. If you have any specific questions feel free to ask, just don't try to make bigtable behave like a relational database.</p>

Title: Google App Engine -- should we use it?


问:
What's meant by, "TODO Auto-generated method stub"?
I am using eclipse for android programming, and every here and there i see the statement, "TODO Auto-generated method stub."

I understand that these methods were generated automatically by eclipse upon creation of classes and other trigger activities but I do not understand the need to have it mentioned everywhere.

What's the need to have it mentioned everywhere repeatedly?

答:
Many IDEs, including Eclipse, use "TODO" in a comment to generate task lists. These task lists include the text of the comment and the file and method that the comment is in. This lets everyone using a tool with this functionality generate lists of things that are still open. There are also some other common identifiers, like FIXME or XXX that have similar functionality in some IDEs. This question on Stack Overflow asks about the comment keywords in Eclipse, and provide some additional information.

When you autogenerate some functions, it's expected that you'll be inserting your own implementation. It adds the appropriate stub so that your code will compile, but adds the comments so that you can quickly find methods that need to be implemented. Note that some autogenerated functions, like autogenerated toString and hashcode functions do not contain these comments because it's not expected that you'll modify them.

There are ways to disable the insertion of these by editing the templates used to create autogenerated code, if it bothers you that much. However, they are useful. Simply searching your codebase for things like TODO and FIXME can be the basis of a task list if they are coupled with a decent comment about what needs to be done, especially on smaller projects.


答:
Eclipse creates just empty methods that return null (hence "stub"). The comments are inserted to remind the developer that he'll probably want to do something in those methods, otherwise why should they exist? You're supposed to delete the comments when you've done that.

If you see those comments all over the place, then either (if the actually contain implementations) the developers are lazy or believe the comments have some other purpose and therefore don't delete them, or it's an indication of weak design, usually interfaces that are too big and have implementations (and users) that don't actually use all the methods in the interface.

Title: What's meant by, "TODO Auto-generated method stub"?

Body:
I am using eclipse for android programming, and every here and there i see the statement, "TODO Auto-generated method stub."

I understand that these methods were generated automatically by eclipse upon creation of classes and other trigger activities but I do not understand the need to have it mentioned everywhere.

What's the need to have it mentioned everywhere repeatedly?


问:
Handling large web based processes
I am working on a new function for a ASP.NET MVC website. The execution time is quite long at present so I am considering options.

The function takes an excel spreadsheet, uploads it to the web server. It then needs to select all of the rows and using Entity Framework insert the rows in to a database. Each row matches the required entity model. Currently at only 50000 rows, this process takes a while and I would assume the row count will grow in the future.

I have a few options for processing here and I am wondering if there is a better way to handle it. The two ideas I have just now are

1) Pass the work off to a service, which on completion emails the user. The obvious upside being the user doesn't need to keep that browser window open.
2) Add a progress bar and have the service pass updates back to jquery/javacript to do visual updates.

I will attempt to reduce the time, possibly moving the queries away from relying on Entity Framework. Sometimes stored procedures are a lot faster than Linq To Entities but with that aside, the process may still take more than a few seconds, which I don't really want to burden the user with.

Can anyone think of other/better ways to handle long running processes on a web application? Are there any best practice schools of thought on handling these situations?

答:
Doing the background service or task is correct tactic here -- web servers really are meant to serve brief requests not long running tasks. Best to keep those off the server. You also get the added advantage of making things like bulk processing easier to achieve as it is sitting there waiting to do it's thing. </p>

<p>If it needs to be synchronous some sort of progress bar is in order. Another option would be a simple status panel and notification options, especially if things start taking longer once you have real traffic. </p>

Title: Handling large web based processes

Body:
Doing the background service or task is correct tactic here -- web servers really are meant to serve brief requests not long running tasks. Best to keep those off the server. You also get the added advantage of making things like bulk processing easier to achieve as it is sitting there waiting to do it's thing.

If it needs to be synchronous some sort of progress bar is in order. Another option would be a simple status panel and notification options, especially if things start taking longer once you have real traffic.


问:
Designing a robust architecture for multiple export types?
I'm looking for patterns or architectural guidance for an upcoming feature I'm designing. Basically, it's an export feature with multiple export targets, and I'm looking to find a way to make it generic enough where plugging in new export targets don't require a lot of core changes. By export targets, I'm simply referring to different types of output, whether that be PDFs, PowerPoint presentations, Word documents, RSS, etc. I have a base set of data, which is represented in JSON and XML. This data are used to construct images (using any number or export types [e.g., PNG, JPG, GIF, etc), graphs, textual representations, tables, and more.

I'm trying to find a way to abstract all the rendering and layout into some kind of rendering or layout engine that handles the addition of further export targets. Any help/suggestions/resources as to how to approach this would be greatly appreciated. Thanks in advance.

For a pictorial representation of what I'm trying to achieve.

答:
We solved a similar problem here: https://ergebnisse.zensus2011.de/?locale=en
There we have mostly "tables" and "graphs" to be exported in different formats: pdf, excel, web.
Our idea was to specify each object to be rendered as an own Java class with interfaces to create and read those classes.
In your case there would be 2 implementations for each object for creating (xml, json) and 4 implementations for rendering (reading).

Example: You will need some classes for Tables:
Class Table (handles table structure, validation and contents)
Interface CreateTable(provides table data, cells, spans, content)
Interface ReadTable(getters for all data)

Probably you don't need the interfaces (or only one) but i think it always provides a good decoupling especially useful in testing.


答:
TODO is one of several default keywords which indicate tasks to perform in Eclipse.  Under windows->Preferences->Java->Compiler->Task Tags, you should see these keywords.  It is thought  to add a comment with this keyword to automatically indicate the things that are still to complete, which is convenient if you make use of these task tags.

However, if you don't use them, you should modify the code templates (Preferences->Java->Code Style->Code Templates) to eliminate these comments.

In particular:

Code->Method body

Code->Constructor body

Code->Catch block body


问:
What's the career path for a developer who doesn't like management?
If you're developer (Senior or Lead Developer) and you'd rather stay with code/design than pursue a management career, what are the available career paths at your company, or any you've heard of? How far can you go?

Is it possible to continue being a geek until you bite the dust or is that too naive?

Are people like Uncle Bob for example still considered developers, as they claim?

答: Contracting. There's far more money in freelance work.</p>


问:
Code formatting SQL queries
Should I break SQL queries in different lines? For example in the project I am working on, we have a query that is taking 1600 columns! 1600 + tab chars. I wrote queries like this:

```<code>   "SELECT bla , bla2 , bla FROM bla " .
     "WHERE bla=333 AND bla=2" .
      "ORDER BY nfdfsd ...";
</code>```

But they demanded me to put them in one line and said that my style is bad formatting. Why it is bad practice?

答: The only advantage of single line queries that comes to mind is that those queries may be somewhat easier to grep for.  Other than that, though, I am stumped.  Personally, I prefer the more readable, split up queries.</p>

Title: Code formatting SQL queries


问:
Migration from a complex C++ application to C# a -- good idea?
We currently have a complex VC++ software application, which uses a library like ObjectARX to build the dll. I feel there are many features in C# like Collections, Generics, and other libraries which can be used to build the current application in a better and efficient way.

I have been thinking about it, but I am not sure on how to present it to my supervisor and colleagues.

I would appreciate any help, to help me think in the right direction and highlight the points to bring it to the team.

Few points that I thought was;

With some current examples, implementing it in C# with the features.

Highlight the development time is comparatively lesser in C# than C++.

Use a Design Architecture.

答:
I have done some applications in C++ and some in C#.

Granted, C++ can be more complex than C# and C# has LINQ, garbage collection etc.
However, features like Collections and Generics are also available in C++, please have a look at STL, Boost and C++11.

"Modernizing" your C++ code seems the better choice for me, e.g.

using containers like std::list and std::vector instead of C-arrays

avoiding normal pointers whenever possible and switching to std::shared_ptr etc.

using std::string instead of char*

Boost provides a library for nearly everything

etc.

You should avoid using both C++ and C# in your application (CLR or P/Invoke), unless it's absolutely necessary, e.g. DLL for a device is written in C++ and application has been done in C#. The mapping layer will cause you headaches.


答:
99 times out of 100, it's better to refactor code than to rewrite it from scratch.

As for reimplementing into another language: make damn SURE that the benefits outweigh the costs and risks, both short term and long term. FYI: as the application's size and/or complexity goes up, the chances that this decision makes sense goes down.


答: TODO simply mean "TO DO", stub is generated but developer or programmer need to add code as required.</p>


答:
I think what you're looking for is the Strategy pattern.  You have a variety of classes to output the data in the desired format, and you simply choose the appropriate one at runtime.  Adding a new format should be as simple as adding another class that implements the required interface.  I've done this often in Java using Spring to simply maintain a map of converters, keyed by the format type.

As others have mentioned, this is usually accomplished by having all classes implement the same interface (or descend from the same base class) and choosing the implementation via a factory.

Title: Designing a robust architecture for multiple export types?

Body:
I'm looking for patterns or architectural guidance for an upcoming feature I'm designing. Basically, it's an export feature with multiple export targets, and I'm looking to find a way to make it generic enough where plugging in new export targets don't require a lot of core changes. By export targets, I'm simply referring to different types of output, whether that be PDFs, PowerPoint presentations, Word documents, RSS, etc. I have a base set of data, which is represented in JSON and XML. This data are used to construct images (using any number or export types [e.g., PNG, JPG, GIF, etc), graphs, textual representations, tables, and more.

I'm trying to find a way to abstract all the rendering and layout into some kind of rendering or layout engine that handles the addition of further export targets. Any help/suggestions/resources as to how to approach this would be greatly appreciated. Thanks in advance.

For a pictorial representation of what I'm trying to achieve.


问:
How to make sprint planning fun
Not only are our sprint planning meetings not fun, they're downright dreadful.

The meetings are tedious, and boring, and take forever (a day, but it feels like a lot longer).

The developers complain about it, and dread upcoming plannings.

Our routine is pretty standard (user story inserted into sprint backlog by priority >> story is taken apart to tasks >> tasks are estimated in hours >> repeat), and I can't figure out what we're doing wrong.

How can we make the meetings more enjoyable?

...

Some more details, in response to requests for more information:

Why are the backlog items not inserted and prioritized before sprint kickoff?

User stories are indeed prioritized; we have no idea how long they'll take until we break them down into tasks! From the (excellent) answers here, I see that maybe we shouldn't estimate tasks at all, only the user stories. The reason we estimate tasks (and not stories) is because we've been getting story-estimates terribly wrong -- but I guess that's the subject for an altogether different question.

Why are developers complaining?

Meetings are long.

Meetings are monotonous. Story after story, task after task, struggling (yes, struggling) to estimate how long it will take and what it involves.

Estimating tasks makes user-story-estimation seem pointless.

The longer the meeting, the less focus in the room. The less focused colleagues are, the longer the meeting takes. A recursive hate-spiral develops. We've considered splitting the meeting into two days in order to keep people focused, but the developers wouldn't hear of it. One day of planning is bad enough; now we'll have two?!

Part of our problem is that we go into very small detail (in order to get more accurate estimations). But when we estimate roughly, we go way off the mark!

To sum up the question:

What are we doing wrong?

What additional ways are there to make the meeting generally more enjoyable?

答:
Make estimating easier

Break your sprint planning down.

Do you need to estimate the individual tasks? I've done sprint planning two ways:

Stories are estimated in story points and then tasks are estimated in hours

Stories are estimated in story points and tasks simply fall under that with no estimate

Of the two, I prefer the second option. I find that not estimating tasks gives more freedom to developers to cope with changes. If a task no longer makes sense (how many times have you found out that a task isn't applicable or was already done in a previous sprint) you simply throw it out without any penalty, or you may have to change a current task into something new, possibly breaking it up. You're really being redundant if you estimate both, as the sum of the tasks should represent the story points and vice versa. What value do you really gain by this other than knowing how much time individual tasks will take? If you find yourself with task sizes that really vary enough to make a difference, I would suggest breaking those tasks down into smaller, more homogeneous chunks.

By doing this, you can cut down on the time you spend in sprint planning. Stories get estimated during sprint planning, and when you start the sprint you can put down all the tasks you can think of that make up that story. Obviously if there are points that you come across in estimating the story that you know will have to be dealt with in a task, you can add that onto the story information and put it as a task.

Estimate in Ideal units

Story points are meant to be in ideal units such as ideal man hours or ideal work days. These are meant to mean that given the perfect day every day, where you had no interruptions, no meetings, and everything went according to plan, you could accomplish the task in X days. Now everyone knows that this simply isn't true, but the wonderful thing about statistics is that it doesn't have to be.

What I mean by this is that after a while of estimating these in ideal days, you realize that maybe it takes an extra 25% of the time you estimate on average to complete a story. Lets say you had estimated 4 ideal work days, and instead it took you 5. Over time, you keep track of this and then you have a rough idea of the conversion from ideal days to real days. Your first instinct would be to try and compensate for this by over estimating, and you would likely be wrong. The main thing here is to stay consistent. That way, your long term average remains the same. Sure sometimes, it'll be under and sometimes it'll be over, but the more you estimate, the better off you are. If you find that you still can't get a decent estimate, maybe that means you don't know enough about the story to estimate it properly.

Talk about the stories

When you estimate, everyone should have a rough idea of what will need to be done, from start to finish, of what it will take for this story to be complete. You don't need to know every detail, but enough that you think you, yourself, could undertake the story. If you don't have that level of confidence, you probably shouldn't be estimating it. If you say "Well this story is too big for us to know most of the details" then that's an indication that the story is too big, and should be broken down. Stories, at least in my experience, have been small enough that one person, if need be, could work on it alone and accomplish it within a week or two.

This also will help to solve your second point in the edit, which is too much estimation. Instead of estimating every single task for every single story, you simply estimate the story as a whole, which should help to remove a lot of the estimating. As for making the meetings less monotonous, I would suggest planning poker, which you can see more information about above.

Make planning more engaging

Estimate using Planning Poker

As far as making estimation more fun, have you tried planning poker? It's the way that I've always done planning for all my sprints on multiple teams, and it's a good way to keep everyone involved, as every person has to at least pick SOMETHING. There's also a fair amount of fun involved when everyone on the team picks 3, and someone puts down a 20 and has to explain themselves, or when everyone on the team puts down a 5 but the manager puts down an 8 (who's gonna argue with the boss when he wants to give you more time!).

To do this, all you need are some planning poker cards, which we often make on the back side of index cards, or using normal playing cards with values attached to face cards. Nothing fancy, and it keeps everyone focused. Just remember that trying to do any task for an entire day (including planning poker) takes a toll on productivity. Many sets of cards come with a coffee card for a reason; if someone is feeling burnt out, give the team a break to recharge and pick it up when everyone is fresh!

As an alternative to physical cards, you could also look at electronic cards. The real benefits here are automated tracking of results, tracking user stories to be estimated and allowing everyone to show their cards at once to avoid "cheating" (where one persons estimate is influenced by another's due to being able to see their card). Obviously this requires everyone have a computer and the ability to focus on the task at hand though, so use it at your own discretion.

Title: How to make sprint planning fun