问:
Software development life cycle in the industry
I am taking a module called "Requirements Analysis & Design" in a local university. Common module, I'd say (on software development life cycle (SDLC) and UML). But there is a lot of things I wonder if they are actually (strictly) practiced in the industry.

For example, will a domain class diagram, an not anything extra (from design class), be strictly the output from Analysis or Discovery phase? I'm sure many times you will think a bit about the technical implementation too? Else you might end up with a design class diagram later that is very different from the original domain class diagram?

I also find it hard to remember what diagrams are from Initiation, Discovery, Design etc etc. Plus these phases vary from SDLC to SDLC, I believe? So I usually will create a diagram when I think will be useful. Is it the wrong way?

答:
Practices and SDLC within the industry vary wildly from company to company (or even from team to team within the same company). From your description it sounds like the SDLC as taught in your university is a more formal, heavyweight, non-agile process. There are lots of projects following such processes (using differing terminology, tools and artifacts, e.g. some produce long Word documents as the outcome of analysis, containing pure text, others use some UML diagrams, yet others diagrams in a completely different notation system...). There are also lots with close to zero level of formalized processes. And anything in between these two extremes.

So the bottom line is, there surely is no single Right Way to do this. Once you start working in a concrete project team, you will get to learn and adhere to their local conventions and processes anyway (which, chances are, will be quite different from what you were taught at the university).

But if you have the chance to choose/shape your SDLC, I suggest you be pragmatic. Use what works for you(r team), regularly reflect on the problems/issues you see, and adapt your process/tools accordingly. As a starting point, I recommend investigating some of the low-ceremony, developer-oriented Agile methods.

In these, the various phases aren't strictly separated: it is acknowledged that one can't create the perfect requirements/design up front. As you mention, in practice you will think about the possible design(s) for your domain model, and the possible implementation(s) of your design in advance, and you may even create a quick prototype to verify some assumptions early on. Also, during design you will get new questions and insights into the requirements, and during implementation you will get new realizations which will change and refine your design.


问:
Closest location - Heapify or Build-heap
So lets say we have a set of gps data points and your current location. If asked to give the closest point to your current location we can utilize a heap with the distance being the key. Now if we update the current location, I suspect that only a few of the keys will change enough to violate the heap property. Would it be more efficient to rebuild the heap after recalculating the keys or to run heapify (assuming that only a few of the keys have changed enough). It is assumed that we don't jump around with the new location (new current location is close to the last current location).</p>

答:
I'm pretty sure you can't (mis-)use heaps for your purpose. I suggest you use data structures that are specifically built for your problem instead.

If your set of GPS data points hardly ever changes, KD-trees are probably the best choice for this. If your data points are also moving around, then quad-trees are probably the best. If you're feeling particularly algorithmic, you could even try to employ locality-sensitive hashing.

If you don't want to query your data structure every time your current location changes, you could instead find the two closest points, compute the difference in the distances from you to the two points, and only re-query the data structure if your current location has moved away from its position when you queried the data structure than this difference.

So, if A and B are the two nearest points (A being the nearest) to the current position D, and you then start moving from D again and end up at position C, then you only have to query the structure again if |B-D| - |A-D| <= |C-D|, because only then have you moved away far enough from D to have a different point E become (potentially) interesting.

If your data points and current location can be really far away from each other, you may have to take the rounding of the earth into account. You probably don't have to, but don't forget about it.

ContentLicense: CC BY-SA 3.0


问:
Would this be a good web application architecture?
My problem

Our MVC based framework does not allow us to cache only part of our output. Ideally we want to cache all static and semi-static parts, and run dynamic parts. In addition, we need to consider data caching that reacts to database changes.

My idea

The concept I came up with was to represent a page as a tree of XML fragment objects. Some of the fragments are dynamic, and can pull their data directly from models or other sources, but most of the fragments are static scaffolding.

If a subtree of fragments is completely static, then I imagine that they could unfold into XML that would then be cached as the text representation of their parent element.

This process would ideally continue until we are left with a root element that contains all of the static XML, and has a couple of dynamic XML fragments that are resolved and attached to the relevant nodes of the XML tree just before the page is displayed.

In addition to separating content into dynamic and static fragments, some fragments could be dynamic and cached. A simple expiry time which propagates up through the XML fragment tree would indicate that a specific fragment should periodically be refreshed. A newspaper section or front page does not need to be updated each second. Minutes or sometimes even longer is sufficient.

Other fragments would be dynamic and uncached. Typically too many articles are viewed for them to be cached - the cache would overflow. Some individual articles may be cached if they are extremely popular.

Functional notes

The folding mechanism could be to be smart enough to judge when it would be more profitable to fold a dynamic cached fragment and propagate the expiry date to the parent fragment, or to keep it separate and simply attach to the XML tree when resolving the page.

If some dynamic cached fragments are associated to database objects through mechanisms like a globally unique content id, then changes to the database could trigger changes to the output cache. If fragments store the identifiers of parent fragments, then they could trigger a refolding process that would then include the updated data.

A set of pure XML with an ordered array of fragment objects (that each store the identifying information of the node to which they should be attached), can be resolved in a fairly simple way by walking the XML tree, and merging the data from the fragments.

Because it is not necessary to parse and construct the entire tree in memory before attaching nodes, processing should be fairly fast.

The identifiers of each fragment would be a combination of relevant identity data and the type of fragment object. Cached parent fragments would contain references to these identifiers, in order to then either pull them from the fragment cache, or to run their code.

The controller's responsibility is reduced to making changes to the database, and telling the root XML fragment object to render itself.

I would just like to make it clear that while I say XML, what I really mean is XHTML. The design generates and folds XHTML from the very start, without trying to add an additional step to transform the XML to XHTML. It's just functionally equivalent to XML.

UPDATE:

The design is still essentially MVC. Traditionally in Web applications, controllers make changes to models directly, then load all the data from models, and send it to the view.

The problem with this is that it's hard to do partial page caching.

Most web applications spend most of their time in the DB. If the controller has to load the data from models each time, then caching the view has no point, unless you cache the whole view and do no database queries.

However, in Smalltalk, where the MVC pattern originally came from, views pulled data from models directly. "The view gets its own data from the model." - MVC on Wikipedia

If views pull their data from the models, and views are composed of other views, then it becomes trivial to cache the output of views. If it does not need loading again, then it doesn't load, and it doesn't contact the DB.

I am treating view output as XML/XHTML because we have a couple of tools that allow us to manipulate XML quite well, making the interweaving of static and dynamic fragments fairly simple.

The Question

My question has two parts:

Is this a good design? Are there any obvious flaws I'm missing?

Has somebody else thought of this before? References?

Is there an existing alternative that I should consider? A cool templating engine maybe?

答:
This sounds suspiciously like you're trying to invent output caching. I definitely wouldn't agree that it's hard to do partial page caching in MVC, it's just that you would need to use partial Views with their own Controller actions to do it as opposed to having the View itself call its sub-Views, which can be slightly counter-intuitive. (So in ASP.net MVC you'd want to use Html.RenderAction as opposed to Html.RenderPartial). There's a name for this particular pattern that is currently escaping my recollection.

I would suggest that the main flaw with your design is that Views will have to know things about the architecture of the site. So they'll have to know about where to get their data from AND how to get it, they'll have to know about where to cache it, when to cache it, when not to cache it, etc.

Realistically you should be trying to separate layers away from knowledge of other layers, as the less knowledge each layer has of another the easier it is to change a layer (i.e. switch DB, add a transparent data caching layer, move a DB call across to a web service, etc.).

I would suggest that if you're going to implement such an idea, and there isn't a native output caching system in your MVC-framework-of-choice, that you add the caching layer to the Controller actions. Unless you've got some VERY heavyweight Views that need to do large amounts of recursive rendering of Models (something that's very rare) the actual HTML generation time is miniscule compared to DB calls and client network latency, so take a more pragmatic approach and cache where you need to cache, i.e. in the application layer.

If you really need custom output caching then you probably want to just slip in a caching layer above your Controller actions with either a wrapping class (if you're using a dynamic language) or a different implementation of an interface (if in a static language) that can hijack the calls to the Action and react accordingly.

As for caching that reacts to DB changes, you'd be better off with a caching layer that takes into account both loading and saving in your repository class, with each save call flushing the cache (or part of the cached set) and each load being gracefully degraded from cache to DB when needed (i.e. use the cache when the cached data is available). That way you keep the database driven behaviour close to the database.


问:
Is it typical for a provider of a web services to also provide client libraries?
My company is building a corporate Java web-app and we are leaning towards using GWT-RPC as the client-server protocol for performance reasons.  However, in the future, we will need to provide an API for other enterprise systems to access our data as well.  For this, we were thinking of a SOAP based web service.  In my experience it is common for commercial providers of enterprise web applications to provide client libraries (Java, .NET, C#, etc.).

Is this generally the case?

I ask because if so, then why bother using SOAP or REST or any standard web services protocol at all?  Why not just create a client libraries that communicate via GWT-RPC?

答:
It depends on the clients needs for the web-app.  Two common scenarios are clients with little or no IT resources, and clients who have their IT teams working on a larger overall project.

Providing client libraries helps with adoption. Typically a more capable IT team develops something, a web-app in this case, to keep their customers from having to put the resources into developing it. But this implies they may not have the resources to build client side code as well.

Then there are some clients who will have resources, and may want to integrate your web-app into something more comprehensive. This is where SOAP or REST can make this easier for them.

OwnerDisplayName: HDave

OwnerDisplayName: Chris


答:
In addition to the excellent points that Chris makes, adopting an open-standards-based API means that even though you can create libraries to help clients that are using a particular platform (.NET, Java, etc.), you are still open to people who intend to use your API from other platforms.

Also, just because you're willing to create a client library now doesn't mean you will want to commit to maintaining it for years to come. Amazon put together some client libraries for their API, but by the time I tried using them they were hopelessly out of date and Amazon appeared to have no interest in fixing them. That's unfortunately the way business works. Having an open standard allows people to keep using the service even if your company fails to put resources into maintaining the client libraries.

Title: Is it typical for a provider of a web services to also provide client libraries?

Body:
My company is building a corporate Java web-app and we are leaning towards using GWT-RPC as the client-server protocol for performance reasons.  However, in the future, we will need to provide an API for other enterprise systems to access our data as well.  For this, we were thinking of a SOAP based web service.  In my experience it is common for commercial providers of enterprise web applications to provide client libraries (Java, .NET, C#, etc.).

Is this generally the case?

I ask because if so, then why bother using SOAP or REST or any standard web services protocol at all?  Why not just create a client libraries that communicate via GWT-RPC?

OwnerDisplayName: StriplingWarrior


答:
It's a matter of opinion... I think that SOAP and REST are so standard that there's little point in providing client libraries. Generating client stubs from the WSDL should be trivial and allows full flexibility, so why shouldn't the customers do it themselves?

Unless, of course, the clients are not trivial - if you're doing something tricky or non-standard, then it would make sense for you to provide the client libraries for your service.

I think that whether you supply clients or not, the most important thing is to publish comprehensive documentation of your service.

OwnerDisplayName: Eli Acherkan


答:
Don't use GWT-RPC for "open APIs": a client would break as soon as you change a class on your server.

RequestFactory could be an option though, as you can use ServiceLayerDecorator to provide a "migration path" for old clients when you update your server (plus, you won't break a client if you change your server classes but not your proxies, and even if you change your contexts or proxies, you'll only break clients if you made, er, breaking changes to them), and a Java client is built-in (RequestFactorySource with UrlRequestTransport)

That being said, if you really want an "open API", then go the "REST" road. Using things like JAX-RS or Restlet, you can leverage the code you wrote for your GWT app (using GWT-RPC or RequestFactory).

OwnerDisplayName: Thomas Broyer


问:
Is anyone doing "real" TDD with Visual-C++, and if yes, how do they do it?
Test Driven Development implies writing the test before the code and following a certain cycle:

Write Test

Check Test (run)

Write Production Code

Check Test (run)

Clean up Production Code

Check test (run)

As far as I'm concerned, this is only possible if your development solution allows you to very quickly switch between the production and test code, and to execute the test for a certain production code part extremely quickly.

Now, while there exist lots of Unit Testing Frameworks for C++ (I'm using Bost.Test atm.) it does seem that there doesn't really exist any decent (for native C++) Visual Studio (Plugin) solution that makes the TDD cycle bearable regardless of framework used.

"Bearable" means that it's a one-click action to run a test for a certain cpp file without having to manually set up a separate testing project etc. "Bearable" also means that a simple test starts (linking!) and runs very quickly.

So, what tools (plugins) and techniques are out there that make the TDD cycle possible for native C++ development with Visual Studio?

Note: I'm fine with free or "commercial" tools.

Please: No framework recommendations. (Unless the framework has a dedicated Visual Studio plugin and you want to recommend the plugin.)

Edit Note: The answers so far have provided links on how to integrate a Unit Testing framework into Visual Studio. The resources more or less describe how to get the UT framework to compile and get your first Tests running. This is not what this question is about. I'm of the opinion that to really work productively, having the Unit Tests in a manually maintained(!), separate vcproj from your production classes will add so much overhead that TDD "isn't possible". As far as I am aware, you do not add extra "projects" to a Java or C# thing to enable Unit Tests and TDD, and for a good reason. This should be possible with C++ given the right tools, but it seems (this question is about) that there are very little tools for TDD/C++/VS.

Googling around, I've found one tool, VisualAssert, that seems to aim in the right direction. However, afaiks, it doesn't seem to be in widespread use (compared to CppUnit, Boost.Test etc.).

Edit: I would like to add a comment to the context for this question. I think it does a good summary of outlining (part of) the problem: (comment by Billy ONeal)

Visual Studio does not use "build scripts" that are reasonably
  editable by the user. One project produces one binary. Moreover, Java
  has the property that Java never builds a complete binary -- the
  binary you build is just a ZIP of the class files. Therefore it's
  possible to compile separately then JAR together manually (using e.g.
  7z). C++ and C# both actually link their binaries, so generally
  speaking you can't write a script like that. The closest you can get
  is to compile everything separately and then do two linkings (one for
  production, one for testing).

答:
I use MSTest for testing native C++ code.

Here is the great blog post about this way: Link

Yes, there will be at least two projects - one for application itself, one for tests.

Instead of making third project with static library, I just add application's source to test project, so solution looks like this:

```<code>[-] Solution 'Foo'      Foo\Foo.sln
 |-[-] Foo              Foo\Foo\Foo.vcproj
 |  |-[-] include
 |  |  |- foo.h         Foo\Foo\foo.h
 |  |  |- bar.h         Foo\Foo\bar.h
 |  |
 |  |-[-] source
 |     |- foo.cpp       Foo\Foo\foo.cpp
 |
 |-[-] Foo.Tests        Foo\Foo.Tests\Foo.Tests.vcproj
    |                        (Additional include directory: "..\Foo")
    |-[-] include
    |  |- FakeBar.h     Foo\Foo.Tests\FakeBar.h
    |
    |-[-] source
       |-[-] app
       |  |- foo.cpp    Foo\Foo\foo.cpp    -- not in Foo.Tests\
       |
       |-[-] unit-tests
          |- foo_Tests.cpp   Foo\Foo.Tests\foo_Tests.cpp
          |- bar_Tests.cpp   Foo\Foo.Tests\bar_Tests.cpp
</code>```

Body:
I use MSTest for testing native C++ code.

Here is the great blog post about this way: Link

Yes, there will be at least two projects - one for application itself, one for tests.

Instead of making third project with static library, I just add application's source to test project, so solution looks like this:

[-] Solution 'Foo'      Foo\Foo.sln
 |-[-] Foo              Foo\Foo\Foo.vcproj
 |  |-[-] include
 |  |  |- foo.h         Foo\Foo\foo.h
 |  |  |- bar.h         Foo\Foo\bar.h
 |  |
 |  |-[-] source
 |     |- foo.cpp       Foo\Foo\foo.cpp
 |
 |-[-] Foo.Tests        Foo\Foo.Tests\Foo.Tests.vcproj
    |                        (Additional include directory: "..\Foo")
    |-[-] include
    |  |- FakeBar.h     Foo\Foo.Tests\FakeBar.h
    |
    |-[-] source
       |-[-] app
       |  |- foo.cpp    Foo\Foo\foo.cpp    -- not in Foo.Tests\
       |
       |-[-] unit-tests
          |- foo_Tests.cpp   Foo\Foo.Tests\foo_Tests.cpp
          |- bar_Tests.cpp   Foo\Foo.Tests\bar_Tests.cpp

ContentLicense: CC BY-SA 4.0


答:
These are just my experiences: I've never worked for a company that strictly followed an SDLC. I've worked for many companies that had an SDLC, but never one that followed it even remotely.

IT groups tend to grow organically with the business, releasing software quickly and responding to customer demand. Eventually IT grows 'big enough' to have multiple layers of management and a CTO (IT is 'important' now).

Then something goes wrong - under pressure from customers, IT ship a buggy version of an important application, and the bottom line is impacted. The wider business reacts: "How could you allow that to happen?"

After fixing the issue, IT need to be seen as responding to make sure it never happens again. So they introduce policies and bureaucracies, and SDLC's are documented. The SDLC isn't actually intended to improve IT's ability to deliver quality software on-time, but to placate the CXO's at the next board meeting. So it's full of bluster and pomp designed to impress the CFO and CMO and any external analysts that anyone decides to bring in. Everyone involved knows it's a pretentious waste of time and won't be followed, but they go along with it like bogans testing the wine at a restaurant ("mm... it's red!").

Developers of course go back to working in agile ways, building things users ask for and short-cutting the red-tape where possible. Some parts of the SDLC are followed - release sign-offs for example - but most of it is done simply because that's The Policy and questioning it is too politically sensitive.

Developers do tend to draw diagrams and design object models, but they happen very organically and where necessary, not strictly as part of a Phase, unless that's The Policy in which case it's usually rushed just to get it out of the way so real work can begin.

Title: Software development life cycle in the industry

Body:
I am taking a module called "Requirements Analysis & Design" in a local university. Common module, I'd say (on software development life cycle (SDLC) and UML). But there is a lot of things I wonder if they are actually (strictly) practiced in the industry.

For example, will a domain class diagram, an not anything extra (from design class), be strictly the output from Analysis or Discovery phase? I'm sure many times you will think a bit about the technical implementation too? Else you might end up with a design class diagram later that is very different from the original domain class diagram?

I also find it hard to remember what diagrams are from Initiation, Discovery, Design etc etc. Plus these phases vary from SDLC to SDLC, I believe? So I usually will create a diagram when I think will be useful. Is it the wrong way?


问:
How can I justify a technology over another? (Java over .NET)
We are working in a Java/.NET company and my team and I are planning a project for a client.

One of the requirements is that the project has to be done in .NET

I've asked about this requirement, and the client said that it doesn't matter, and that if I have a good reason we can use other technology. But, I have to justify the decision.

As a Project Manager / Analyst I'm interested in making the project in Java because:

The team knows java much better, regarding the language and frameworks

I don't know anything about .NET technology (and maybe we could make bad decisions thinking in a Java way to do things)

There are other people in company that have more skills in .NET but they have other projects with more priority.

For experience, I'm sure that if we use Java, the project will have much more quality. But this arguments could be weak from the client perspective.

How can I justify making the project in Java?

EDIT: I'm not asking if one technology is better than other. "It's not a technology war" question.

答:
I don't think there is a client on this planet who would consider quality to be a weak argument.

However, as a project manager / analyst, I don't really think you should be the one making this decision. Ask the team what they want to use and why -- make it clear that it has to be a reason that you can explain to the customer (i.e. something more beneficial to them than "I want .NET on my CV"). Autonomy is the number one motivator for software developers and allowing them to make technical choices is important. They're the ones most qualified to decide and they're the ones who will have to live with the decision.

If they have good reasons to choose .NET then let them. Your lack of knowledge of the technology is irrelevant. But it is more likely that they'll choose the one they're most comfortable with, which is a perfectly good reason to choose Java.


答:
Why is the argument that you'll produce a better quality product in Java weak?

Assuming that the technology you are familiar with can be used to (relatively) easily implement the solutions you require you should go with the technology you (as developers) know for several reasons:

You are more familiar with the libraries, frameworks and tools so you'll work faster.

You'll produce a higher quality product for the same reason and this will lead on to:

A more stable product therefore less support calls.

Easier development of enhancements

Conversely, using an unfamiliar technology will lead to the development

taking longer

be more likely to have errors and hence require more support

be harder to extend in the future

Obviously this only holds true if there is isn't a business case for using one technology rather than another. Such an case would be where the customer has the infrastructure and IT skills for .NET and not Java (or vice versa).

Title: How can I justify a technology over another? (Java over .NET)

Body:
We are working in a Java/.NET company and my team and I are planning a project for a client.

One of the requirements is that the project has to be done in .NET

I've asked about this requirement, and the client said that it doesn't matter, and that if I have a good reason we can use other technology. But, I have to justify the decision.

As a Project Manager / Analyst I'm interested in making the project in Java because:

The team knows java much better, regarding the language and frameworks

I don't know anything about .NET technology (and maybe we could make bad decisions thinking in a Java way to do things)

There are other people in company that have more skills in .NET but they have other projects with more priority.

For experience, I'm sure that if we use Java, the project will have much more quality. But this arguments could be weak from the client perspective.

How can I justify making the project in Java?

EDIT: I'm not asking if one technology is better than other. "It's not a technology war" question.


问:
Design review for application facing memory issues
I apologise in advance for the length of this post, but I want to paint an accurate picture of the problems my app is facing and then pose some questions below;

I am trying to address some self inflicted design pain that is now leading to my application crashing due to out of memory errors.

An abridged description of the problem domain is as follows;

The application takes in a “dataset” that consists of numerous text files containing related data

An individual text file within the dataset usually contains approx 20 “headers” that contain metadata about the data it contains. It also contains a large tab delimited section containing data that is related to data in one of the other text files contained within the dataset. The number of columns per file is very variable from 2 to 256+ columns.

The original application was written to allow users to load a dataset, map certain columns of each of the files which basically indicating key information on the files to show how they are related as well as identify a few expected column names. Once this is done, a validation process takes place to enforce various rules and ensure that all the relationships between the files are valid. Once that is done, the data is imported into a SQL Server database. The database design is an EAV (Entity-Attribute-Value) model used to cater for the variable columns per file. I know EAV has its detractors, but in this case, I feel it was a reasonable choice given the disparate data and variable number of columns submitted in each dataset.

The memory problem

Given the fact the combined size of all text files was at most about 5 megs, and in an effort to reduce the database transaction time, it was decided to read ALL the data from files into memory and then perform the following;

perform all the validation whilst the data was in memory

relate it using an object model

Start DB transaction and write the key columns row by row, noting the Id of the written row (all tables in the database utilise identity columns), then the Id of the newly written row is applied to all related data

Once all related data had been updated with the key information to which it relates, these records are written using SqlBulkCopy. Due to our EAV model, we essentially have; x columns by y rows to write, where x can by 256+ and rows are often into the tens of thousands.

Once all the data is written without error (can take several minutes for large datasets), Commit the transaction.

The problem now comes from the fact we are now receiving individual files containing over 30 megs of data. In a dataset, we can receive any number of files. We’ve started seen datasets of around 100 megs coming in and I expect it is only going to get bigger from here on in. With files of this size, data can’t even be read into memory without the app falling over, let alone be validated and imported. I anticipate having to modify large chunks of the code to allow validation to occur by parsing files line by line and am not exactly decided on how to handle the import and transactions.

Potential improvements

I’ve wondered about using GUIDs to relate the data rather than relying on identity fields. This would allow data to be related prior to writing to the database.  This would certainly increase the storage required though. Especially in an EAV design. Would you think this is a reasonable thing to try, or do I simply persist with identity fields (natural keys can’t be trusted to be unique across all submitters).

Use of staging tables to get data into the database and only performing the transaction to copy data from staging area to actual destination tables.

Questions

For systems like this that import large quantities of data, how to you go about keeping transactions small. I’ve kept them as small as possible in the current design, but they are still active for several minutes and write hundreds of thousands of records in one transaction. Is there a better solution?

The tab delimited data section is read into a DataTable to be viewed in a grid. I don’t need the full functionality of a DataTable, so I suspect it is overkill. Is there anyway to turn off various features of DataTables to make them more lightweight?

Are there any other obvious things you would do in this situation to minimise the memory footprint of  the application described above?

Thanks for your kind attention.

答:
GUID's can be a good idea for uniquely identifying a single record, especially in cases of EAV or where a record needs to be unique across schemas, databases and environments.  They may actually cause performance problems in a typical RDBMS however as comparing a string of characters against other strings of characters is much more expensive than comparing numerical data.  This could negatively impact queries but then the effect might be negligible or not applicable for you.  So use your best judgement.

Staging tables are a great idea if applications depending on this data do not have explicit requirements for 100% real-time data.  You can always offload the heavy processing and memory usage involved with processing this data into your main tables during off-peak hours.  They also allow you to perform data validation at a later time as well.


问:
How can I best study a problem to determine whether recursion can/should be used?
In some cases, I fail to see that a problem could be solved by the divide and conquer method. To give a specific example, when studying the find max sub-array problem, my first approach is to brute force it by using a double loop to find the max subarray. When I saw the solution using the divide and conquer approach which is recursion-based, I understood it but ok. From my side, though, when I first read the problem statement, I did not think that recursion is applicable.

When studying a problem, is there any technique or trick to see that a recursion based (i.e. divide and conquer) approach can be used or not?

答:
When studying a problem, is there any technique or trick to see that a
  recursion based approach can be used or not?

Yes, sure, though I would not call it a trick.
It should be basic knowledge that in imperative languages there is really only one kind of loop, the while loop (every other loop is merely syntactic sugar).
But a while loop corresponds directly to a recursive pattern I give her in a haskell like notation:

```<code>loop False action = return ()
loop True  action = action >> loop nextCondition nextAction
   where
       nextCondition = .....
       nextAction    = .....
</code>```

So, the conclusion is: a recursion based approach can be used for every problem. Like it or not.

Body:
When studying a problem, is there any technique or trick to see that a
  recursion based approach can be used or not?

Yes, sure, though I would not call it a trick.
It should be basic knowledge that in imperative languages there is really only one kind of loop, the while loop (every other loop is merely syntactic sugar).
But a while loop corresponds directly to a recursive pattern I give her in a haskell like notation:

loop False action = return ()
loop True  action = action >> loop nextCondition nextAction
   where
       nextCondition = .....
       nextAction    = .....

So, the conclusion is: a recursion based approach can be used for every problem. Like it or not.


答:
I put myself in your shoes and I would definitely go for Java but as far as I understood, you already made the decision. your problem is how to explain the decision to the client. (correct me if I am wrong).

I would tell him/her/them that your team is more experienced in Java than in .Net.

Don't make a cheap marketing decision for one client and tell him/her/them that Java would suit better for that project because that would be a big lie. not because .Net is better than Java, because you are not experienced in .Net and don't know if it would suit well for this project or not.


问:
Why are cyclic imports considered so evil?
Seriously, what's the big deal about having a few cycles in one's import graph?  I see it as a lesser evil than having super fine grained imports that make keeping track of where to look for what code an absolute nightmare.</p>

答: One reason is that it can be, but isn't always, a warning sign of a bad design decision somewhere.

ContentLicense: CC BY-SA 2.5


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

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

答:
Even though I'm fairly comfortable on the Linux command-line and with Linux editing tools like vim, I do most of my PHP development on a windows machine.

I have a virtual server on the internet (runs me about $20 a month) that I use as a development server, and I connect to it using FileZilla. FileZilla downloads the files I'm editing to a temp directory and keeps track of saves and when I save it throws it back up on to the dev server, and I test it from there.

It's a little cumbersome, but allows me to do the development pretty much anywhere; using FileZilla and a simple editor on a thumb drive I can even connect from another computer and make changes.  All the testing is always on the Linux server, so I catch any problems I might have caused out of the box - fewer unpleasant surprizes when I throw the code onto the server.

You could do the same thing with a cheap hosting account (although depending on what sort of application you're developing you might run into performance issues since cheap hosting accounts are typically fairly underpowered) and other many FTP applications also have the edit-and-upload functionality.


问:
Would it be possible to create an open source software library, entirely developed and moderated by an open community?
Call it democratic software development, or open source on steroids if you will.

I'm not just talking about the possibility of providing a patch which can be approved by the library owner. Think more along the lines of how Stack Exchange works. Anyone can post code, and through community moderation it is cleaned up and eventually valid code ends up in the final library.

For complex libraries an elaborate system should probably be created, but for a simple library it is my belief this is already possible e.g. within the Stack Exchange platform.

Example

Take a library of extension methods for .NET for example. Everybody goes their own way and implements their own subset of what they feel is important, open-source library or not. People want to share their code, but there is no suitable platform for it. extensionmethod.net is the result of answering this call for extension methods, but the framework hopelessly falls short; there is no order, or structure at all.

You don't know whether an idea is any good until you try it, so I decided to create an Extension Methods proposal on Area51. I belief with proper moderation, it could be possible for the site to be more than a Q&A site, and that an actual library (or subsets of it) could be extracted from it.

Feel free to give feedback to this particular idea on it's proposal page on area51, but it is just meant to be an example. This question is meant to find an answer to the general idea of creating an open source software library moderated by an open community.

Questions

Is it possible? What would be the main problems to such an approach?

Has anything like this been attempted before?

Are there platforms better suited for this?

答:
As a direct response to this quote from the original question:

Everybody goes their own way and implements their own subset of what
  they feel is important, open-source library or not.

My two cents: Design by committee is a failure to start with. Do you really want to have to import every single feature every single person on the internet thinks is a requirement ( am looking at you Jakarata Commons ) just because you want one of them that may be useful for you? It becomes a race to the bottom of mediocrity at best!

Imagine a code base edited like a wiki. Every time someone reformats the code or renames a variable a war would start: that sounds really productive.

Yeah I really want to moderate that crap, oh wait, moderation, that isn't community driven or "social" anymore, whats the point?

Voting doesn't magically make the best answer pop to the top, I have answers I wrote that got ZERO votes and accepted with the checkmark as correct, where other incorrect in the worst way answers had 10+ votes.

Popularity != Quality or Correctness!

Just because 42 CS students up vote some horribly naive empirically bad implementation out of ignorance and 2 down votes from seasoned veterans doesn't make it the best just because it got the most votes!


问:
Should I keep separate client codebases and databases for a software-as-a-service application?
My question is about the architecture of my application. I have a Rails application where companies can administrate all things related to their clients. Companies would buy a subscription and their users can access the application online. Hopefully I will get multiple companies subscribing to my application/service. What should I do with my code and database?

Seperate app code base and database per company

One app code base but seperate database per company

One app code base and one database

The decision involves security (e.g. a user from company X should not see any data from company Y) performance (let's suppose it becomes successful, it should have a good performance) and scalability (again, if successful, it should have a good performance but also easy for me to handle all the companies, code changes, etc).

For the sake of maintainability, I tend to opt for the one code base, but for the database I really don't know. What do you think is the best option?

答:
I'd recommend the third option for a few reasons.

One code base will make maintenance easier. You may also be able to leverage requests from clients into features other clients would benefit from. If you have a fragmented code base, this will be much more difficult to do and maintain. Not only that, but if you have separate code bases, as soon as you are in a rush, any discipline you had of applying fixes to each individual code base is likely to be forgotten or neglected in your haste.

As for the database, while having multiple databases per client sounds pretty good at this point in the project, as the product grows and matures, you may have one company outpacing the others in terms of usage. This will cause you to have to scale up each individual database separately. If you were using one database for all customers, you only need to scale when overall usage increases. You may run into an issue if one client is MUCH larger than the others, but that can be fixed by sharding your database when the time comes. That could give you the benefit of having a database per client, without the hassle of actually maintaining separate databases.

Another issue with having a single database per customer is -- what happens when you need to change the structure of the database for some reason? Would need to migrate each individual database? While Ruby has tools that help you update databases, I still view multiple migrations as an unnecessary risk.

Unless you have a need to have everything separate, keep everything as similar as possible. For security purposes, just make sure that all calls to the database include a reference to the client that is requesting the data. As long as that rule is enforced (and proper security measures are taken) you won't have to worry about companies seeing each others' data.


答:
I think it would/will be extremely difficult to do this well. As Brooks pointed out decades ago, the primary strength of a product (and it applies equally to an operating system or a library) is not the individual features, but the "conceptual integrity" that defines the difference between mediocrity and greatness.

At least for my use of a library, the kind of development you're envisioning would probably lead to more bad than good. In particular, I want a library that I can quickly and easily compile and use, without spending time or effort on the individual parts. What you envision seems like it would probably require me to go through and pick which versions of which parts of the library I want, then (probably) spend a fair amount of effort getting those pieces to work together nicely. At least in most cases, that's a large part of what I'm trying to avoid by using a library in the first place.

In short, somebody has to set and enforce standards and guidelines for how the library will fit together -- and if nobody else does, I'll almost certainly have to do so myself. If I have to do so myself, I'm not really getting a library, but a loose collection of snippets that I need to turn into a library myself.

Title: Would it be possible to create an open source software library, entirely developed and moderated by an open community?

Body:
Call it democratic software development, or open source on steroids if you will.

I'm not just talking about the possibility of providing a patch which can be approved by the library owner. Think more along the lines of how Stack Exchange works. Anyone can post code, and through community moderation it is cleaned up and eventually valid code ends up in the final library.

For complex libraries an elaborate system should probably be created, but for a simple library it is my belief this is already possible e.g. within the Stack Exchange platform.

Example

Take a library of extension methods for .NET for example. Everybody goes their own way and implements their own subset of what they feel is important, open-source library or not. People want to share their code, but there is no suitable platform for it. extensionmethod.net is the result of answering this call for extension methods, but the framework hopelessly falls short; there is no order, or structure at all.

You don't know whether an idea is any good until you try it, so I decided to create an Extension Methods proposal on Area51. I belief with proper moderation, it could be possible for the site to be more than a Q&A site, and that an actual library (or subsets of it) could be extracted from it.

Feel free to give feedback to this particular idea on it's proposal page on area51, but it is just meant to be an example. This question is meant to find an answer to the general idea of creating an open source software library moderated by an open community.

Questions

Is it possible? What would be the main problems to such an approach?

Has anything like this been attempted before?

Are there platforms better suited for this?


答:
Below is my own view of things. It is based on my experience as someone who worked in a company that had a successful SDLC long time ago. Funny, I left another large company, because their miss-use of SDLC! I can't say that all what is here is currently valid in today's methodologies and techniques though.

Conceptually SDLC is a set of consistent and integrated processes to deliver a product. The primary goals of a methodology are to:

1 - Define work phases and deliverable so that project management becomes possible.

2 - Define a conceptual platform that the organization could enhance as it grows up using industry best practices.

3 - Stop the organization from re-inventing the wheel with every project by identifying inputs and outputs of each task/stage

4 - Minimize the state of chaos in the development process minimize the dependency on a single or a specific set of people in the organization to know everything - This is achieved by good documentation and involving different levels in the process

5 - Enhances the communication among the product development, management and other parties in the organization by establishing a set of agreed terms, KPIs and tools of communication.

The SDLC achieves its goals by utilizing the best suitable practices and tools at each of its processes.

Setting up/choosing an SDLC is not trivial and performing SDLC tasks is valuable.

UML is not SDLC and vice versa. UML is one of the tools that may be adopted by a given SDLC for producing software products but then again it might not. You will not find too many Mainframe CICS developers using UML for example.

as per your point:

Blockquote
  For example, will a domain class diagram, an not anything extra (from design class), be strictly the output from Analysis or Discovery phase? I'm sure many times you will think a bit about the technical implementation too? Else you might end up with a design class diagram later that is very different from the original domain class diagram?
  Blockquote

You are correct in some of this. A domain mdoel is not necessarily a design model. The difference between the two is that a domain model (called different things depending on the methodology you use) is supposed to collect important facts and rules for business during the business analysis stage. The concept of an object in analysis is very wide. The objective of such a model would be to store the collected information in a form that can be used by the designers. It is usually built by analysts so if the two class diagrams look similar, then either the subject is trivial, or has one solution only. The objectives of the technical model is different. It inherits the rules, data and business objectives from the analysis model but shapes it toward code generation, specific database requirements, and performance. It is completed by software engineers and not analysts. As a result it is different. For example a Customer Number may be a good key for Customer Enitty in analysis, but in the database it ends to be implemented as a column with unique index and a sequence number is used instead. It is also not uncommon to see the customer class converted to an abstract class and different types of customers get their own classes (or vice versa)!

Regarding your question:

I also find it hard to remember what diagrams are from Initiation,
  Discovery, Design etc etc. Plus these phases vary from SDLC to SDLC, I
  believe? So I usually will create a diagram when I think will be
  useful. Is it the wrong way?

The methodology should define the stages of the development process and which diagrams should be produced by which professionals and which tools to be used for doing this.

For example, should analysis sessions include prototyped web pages? A prototyped web page is definitely not a UML diagram! In general, you need to define and refine your:

Use Case Diagrams

Class Diagrams

Activity Diagrams

State-Machine Diagrams

Each of the above diagrams have a purpose. If you study the purposes well, it will be clear to you when to use it.

and don't forget your Data Model diagram (ERD) - But ERD is not part of UML. Again, UML is not enough, at least, almost always it is not enough. You need integrated tools and a methodology and above all people to get the work done right.

So, you create a diagram when it is useful, that is OK but if you are working in a team with a methodology you need to follow that and don't forget to allocate time for it in a project plan too.

At the end of all this, please distinguish between SDLC, UML, Project Management - They are different things (at least to me!).

Good luck.


问:
Suggestions for getting an open source electron beam tracking code going
I work in the field of accelerator physics and synchrotron radiation. High energy electrons circulating in large rings of magnets produce x-rays that are used for a variety of different kinds of science.

Running and improving these facilities requires controlling and modelling the electron beam as it circulates in the ring. A code to model this basically requires trackers to follow the electrons through the elements (something called a symplectic integrator), and then the computation of different parameters associated with this motion. The problem with these codes is that every facility has there own (maybe 4-5 different codes, some with multiple versions). In principle the code is not so complex. And as a modelling project, one might think it has some general interest.  Who doesn't want to be able to create a track in space out of magnets and watch the electrons circulate?

There is a Matlab based code to do this called Accelerator Toolbox, but the creator of the code is no longer in the field. I put the code in Sourceforge under the name atcollab. The basic resource is a set of symplectic integrators written in C. These are then compiled into mex code and interfaced via Matlab. It has been useful to put the code on Sourceforge in order to exchange code, but the community of users is quite small and most are too busy to put that much time into collaboration. So in terms of really improving the code, I don't think it has been so successful.

Any piece of this picture could be recreated without that much difficulty, but overall it is a bit complex, and because each lab has their own installation with lots of added-on code and locally developed tools, people find it hard to really work together and share code. Somehow I think we need to involve a wider community in our development, or just use some standard tools. But for that, I suppose it needs to be of some general interest. I think symplectic integrators may have some general interest. And the part about a plug-in architecture to build up the ring ought to fit other patterns. Or the other option is to just accept that this is not a problem of general interest, and work harder within our small community.

Suggestions or anecdotes of analogous experience would be appreciated.

答:
I think that one way to break down such a project into something manageable is to first think about a common way to describe the metadata of your models in a declarative way. In other words, I mean some type of common schema or markup language for describing what a model "is" (the input) and what the results of the analysis are (the output).

I am guessing that each facility has wildly different ways of representing the input to their codes and likewise wildly different ways of representing the results of their analysis? I would even say that this is mainly what keeps people from being flexible about trying new implementations.

If you can introduce a usable information interchange format, it makes it a lot easier for folks to try your implementations. By the same token, folks writing/improving new implementations can use the mark-up schema as a starting point.

Something like this has been going on in the spectroscopy community for a long time. They have introduced markup languages for analytical spectroscopy (animl). I can't vouch for how successful the effort was, but the idea is sound.


答:
One previous employer started the One app code base but separate database per company model to support different clients, and the clients ended up wanting (and paying for) enough different features that they quickly ended up with Seperate app code base and database per company. So, based on past experiences, I think you'll follow the similar progression. Don't fork customer code bases until you have to, as it is a headache, but rather think about how your practices are and how you'd handle it, then when you are forced into that corner, you already have an idea how to do it.

I'd recommend staying away from One app code base and one database as you may find that customerX wants to take their data and go somewhere else (this might also be a subpoena or search warrant where you have to hand over data in a criminal case and you might not be able to cut out other customers' data). Many companies will prefer this route for risk management because this way a bug in your code will not expose data from other companies (like if you forgot a join, or  company ID in one where clause).

Title: Should I keep separate client codebases and databases for a software-as-a-service application?

Body:
My question is about the architecture of my application. I have a Rails application where companies can administrate all things related to their clients. Companies would buy a subscription and their users can access the application online. Hopefully I will get multiple companies subscribing to my application/service. What should I do with my code and database?

Seperate app code base and database per company

One app code base but seperate database per company

One app code base and one database

The decision involves security (e.g. a user from company X should not see any data from company Y) performance (let's suppose it becomes successful, it should have a good performance) and scalability (again, if successful, it should have a good performance but also easy for me to handle all the companies, code changes, etc).

For the sake of maintainability, I tend to opt for the one code base, but for the database I really don't know. What do you think is the best option?


问:
Production-safe SQL stored procedure debugging
We have an enormous number of nested SQL stored procedures, and a number of different ways of debugging them (varying from developer to developer).

So far, our methods include:

An optional @debug parameter, that
causes the procedure to
printmessages as it runs (passing
the variable down to called
procedures).

Checking @@servername against a
table of test server names, and
printing as above

Writing everything the procedure
does to a log table (in production
and test)

Which of these is preferable (and why), or is there a better method we've overlooked?

答:
I use an @debug or @test flag as the input variable for all complex stored procs.

What I do with it then depends on the proc.  Normally, I issue a rollback if in test mode. I may also show the results of various inserts before the rollback to see if what I expected was what I got.

If I have dynamic SQL that when I use the @debug and in this case I print the sql instead of executing it, so I can check the SQL statement produced.

Of course I can have an @test (used only when I am affecting data and want to be sure I can roll it back) and an @debug (to print out dynamic SQl) in the same proc although I usually don't run in both modes at once.

I have also used an @print to print the steps as I go if I am debugging (helps alot to see where the thing failed!) or alternatively, you can use a table variable to hold the steps processed or any error codes and then select from the table variable after the rollback when in test mode to see what actually happened. You can even insert the values from the table variable into a permanent table if you need to see the data over time (we do this for complex imports so we can show the client how often their crappy data broke the import and caused us to have to do work to fix the issue.) It's important to use a table variable and not a temp table for this because it stays in scope after the rollback, a temp table rolls back.

(Note the table variable temp table stuff is SQL Server specific, I don't know if this will work with other databases.)

A profiler can also provvide the actual sql that was sent to the database and should be used especially if you are not using stored procs.


答:
i would go with option no. 1 because

backup & restore per customer is possible out of the box

no risk of exposing customer A`s data to customer B due a bug e.g. missing FK in query

you can easily scale up or scale out (http://www.codinghorror.com/blog/2009/06/scaling-up-vs-scaling-out-hidden-costs.html), no load-balancer or replicated DB`s needed

it is possible to have clients with different versions installed, which comes in handy when you roll out updates. you could/should update 1% of our customers first, if everything goes fine, update the next 10% and after that you update the rest.


答:
Quick short answer:

Java is a good, stable, up to date, programming framework (technology), and we have years of experience with them. (You can say that to your customer)

Long, boring, descriptive, philosophical answer:

As mentioned in other posts, you already have the answer, your team have more experience in Java "technology" than ".NET" "technology".

Both technologies have good features, but, it requires time & skills to learn them. ".NET" have some enhanced features.

You cannot discard any of them for been "obsolete" or without "enough libraries", or "not supporting international languages", or other stuff.

Propose Java framework.

Nevertheless, You may consider to put some of your developers to practice with ".Net" with a "real world", not books, requirement.

For example, in some free time, let them make some forms or web pages that have identical purpouse, using a copy of the same D.B. Even, if its seems waste of time. This way, you'll be prepare when another customer arrive and want a similar app., but with ".NET"

Oracle, it starting to put Java on the track.

Just my 2 cheseburguers (2 cents).


问:
Suggestion for setting web application parameters
I'm creating a web application on GWT. I'm using MVP pattern with activities and places. I have a xml config file containing some parameters to be used by the application. Content of this xml file is sent to the client using HttpRequest; I'm using a singleton class to hold the  information from the xml file.

Right now, the application is getting the data when the user starts the application in the home page, that is working well. Now, since I'm using activities and places, a user can bookmark a page and starts the application in any other page (Place). And here comes the problem: Since I'm using some of the information from the xml file to set some ui widgets, I have to check if the xml config file was read and the application already has the parameters (I do this by checking the singleton class). But the xml file is read by using an HttpRequest, so I got errors 'cause the application needs some parameters to initialize some ui widgets, but these parameters aren't ready on time.

I was thinking on using an synchronous request to fix the problem, but it seems complicated and not recommendable to do that. So, I'd like to hear some other suggestions.

Thanks.

答: I don't know GWT, but I think that an asynchronous request is OK. Client looks for its prefs. If they are missing, it request them. As simple as that.</p>


问:
Interviewing Process (using blank paper etc)

Possible Duplicate:

  What are the pros and cons for the employer of code questions during an interview?

I am curious to know why do companies hand you a blank paper and ask you to write code? This confuses me, because these days intellisense, google, stackoverflow etc are common sources to look up syntax and / or IDE gives you a colored indicator if your syntax is wrong.

I usually get stressed out during these situations. I am curious to know opinions of other developers. I am posting this on this forum, hoping to get helpful feedback from other experienced developers.

答:
Few companies I know of are too particular about syntax. They don't expect you to write pseudo code, but they don't expect you to write syntactically flawless code either. Its to see you know what how to proceed.

If a company expects you to write compilable code on paper, its probably not a company you want to work for.

OwnerDisplayName: MJH

OwnerDisplayName: xbonez


答:
It shows how much you actually know.

Auto-completing intellisense / google / other sites - are just tools.

Although i must admit that knowing what to look for, and doing it fast is also a skill, it's a different one than what is required in that type of test.

A person who can write a program without looking it up first will usually be more productive because he's not wasting time looking for it.

Title: Interviewing Process (using blank paper etc)

Body:
Possible Duplicate:

  What are the pros and cons for the employer of code questions during an interview?

I am curious to know why do companies hand you a blank paper and ask you to write code? This confuses me, because these days intellisense, google, stackoverflow etc are common sources to look up syntax and / or IDE gives you a colored indicator if your syntax is wrong.

I usually get stressed out during these situations. I am curious to know opinions of other developers. I am posting this on this forum, hoping to get helpful feedback from other experienced developers.

OwnerDisplayName: Yochai Timmer


答: I think they are not so interested in checking your syntax but the logic that are trying to put. They need problem solvers and it is important to know what approach you are trying to implement to solve a problem. Correct syntax would be a plus but not necessarily what they are looking for. </p>

OwnerDisplayName: Vini-T


问:
Why do we study Java at university?
Java is often found in academia. What is the reason behind that? </p>

答:
Sorry, long boring answer only:

(1) Did you mean:

"Why do we study Java at university, as a first programming language ?"

(2) Or do you mean:

"Why do we study Java at university, anyway, even if we learn other programming languages, before Java ?"

Sounds like you really mean both questions.

In case of (1):

I don't think Java (or .NET C# and  Visual Basic) should be teach as first programming languages. Structured & Modular Pascal should be first, even if it sounds old & obsolete.

Many people think we should teach people Object Oriented programming or Functional programming inmediatly, just because its "hype" or "trend".

I learn Structured Pascal as a small version of "Object Oriented Programming", not as something similar. I see an structured program as a single small object.

After that, I suggest continue Functional languages and Object Pascal.

And later, C, C++, C#, VB.Net, Java.

The main reasons I don't like Java or C#, as a first programming language, its that they have mix "pointers", "pointers to objects" and "objects" themselves ("references") concepts.

I believe that students should have in mind, the differences & similarities among those concepts. The comparison of Strings objects in Java is a good example of that odditie:

```<code>String A = "Mars";
String A = "Venus";

// pointer comparison or object comparison ???
if (A == B)
{
  DoSomething();
}
</code>```

In case of (2):

I think Java or C# should be teach in school, because they have several updated good features, and at the same time, they have real world use.

Title: Why do we study Java at university?

Body:
Sorry, long boring answer only:

(1) Did you mean:

"Why do we study Java at university, as a first programming language ?"

(2) Or do you mean:

"Why do we study Java at university, anyway, even if we learn other programming languages, before Java ?"

Sounds like you really mean both questions.

In case of (1):

I don't think Java (or .NET C# and  Visual Basic) should be teach as first programming languages. Structured & Modular Pascal should be first, even if it sounds old & obsolete.

Many people think we should teach people Object Oriented programming or Functional programming inmediatly, just because its "hype" or "trend".

I learn Structured Pascal as a small version of "Object Oriented Programming", not as something similar. I see an structured program as a single small object.

After that, I suggest continue Functional languages and Object Pascal.

And later, C, C++, C#, VB.Net, Java.

The main reasons I don't like Java or C#, as a first programming language, its that they have mix "pointers", "pointers to objects" and "objects" themselves ("references") concepts.

I believe that students should have in mind, the differences & similarities among those concepts. The comparison of Strings objects in Java is a good example of that odditie:

String A = "Mars";
String A = "Venus";

// pointer comparison or object comparison ???
if (A == B)
{
  DoSomething();
}

In case of (2):

I think Java or C# should be teach in school, because they have several updated good features, and at the same time, they have real world use.


问:
Who should control navigation in an MVVM application?
Example #1: I have a view displayed in my MVVM application (let's use Silverlight for the purposes of the discussion) and I click on a button that should take me to a new page.

Example #2: That same view has another button that, when clicked, should open up a details view in a child window (dialog).

We know that there will be Command objects exposed by our ViewModel bound to the buttons with methods that respond to the user's click.  But, what then?  How do we complete the action?  Even if we use a so-called NavigationService, what are we telling it?

To be more specific, in a traditional View-first model (like URL-based navigation schemes such as on the web or the SL built-in navigation framework) the Command objects would have to know what View to display next.  That seems to cross the line when it comes to the separation of concerns promoted by the pattern.

On the other hand, if the button wasn't wired to a Command object and behaved like a hyperlink, the navigation rules could be defined in the markup.  But do we want the Views to control application flow and isn't navigation just another type of business logic?  (I can say yes in some cases and no in others.)

To me, the utopian implementation of the MVVM pattern (and I've heard others profess this) would be to have the ViewModel wired in such a way that the application can run headless (i.e. no Views).  This provides the most surface area for code-based testing and makes the Views a true skin on the application. And my ViewModel shouldn't care if it displayed in the main window, a floating panel or a child window, should it?

According to this apprach, it is up to some other mechanism at runtime to 'bind' what View should be displayed for each ViewModel. But what if we want to share a View with multiple ViewModels or vice versa?

So given the need to manage the View-ViewModel relationship so we know what to display when along with the need to navigate between views, including displaying child windows / dialogs, how do we truly accomplish this in the MVVM pattern?

答:
Navigation should always be handled in the ViewModel.

You're on the right track with thinking that the perfect implementation of the MVVM design pattern would mean you could run your application entirely without Views, and you can't do that if your Views control your Navigation.

I usually have an ApplicationViewModel, or ShellViewModel, which handles the overall state of my application. This includes the CurrentPage (which is a ViewModel) and the code for handling ChangePageEvents. (It's often also used for other application-wide objects such as the CurrentUser, or ErrorMessages too)

So if any ViewModel, anywhere, broadcasts a ChangePageEvent(new SomePageViewModel), the ShellViewModel will pickup that message and switch the CurrentPage to whatever page was specified in the message.

I actually wrote a blog post about Navigation with MVVM if you're interested


答:
Yes, it can be done, but several stuff you must consider. Check answers for more info.

Its one of those things, sometimes developers have to do, due to resources, not because they like it.

You may have a local web server (apache, cherokee, even M$), in your PC, and PHP server installed. And your PC, may not have a Internet connection, or only can connect for short periods of time.

Later you can update a real website, updating your file to the real server, with ftp tools, with the same PC or another PC, connected to the internet.

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

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

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


问:
What's the benefit of object-oriented programming over procedural programming?
I'm trying to understand the difference between procedural languages like C and object-oriented languages like C++. I've never used C++, but I've been discussing with my friends on how to differentiate the two.

I've been told C++ has object-oriented concepts as well as public and private modes for definition of variables: things C does not have. I've never had to use these for while developing programs in Visual Basic.NET: what are the benefits of these?

I've also been told that if a variable is public, it can be accessed anywhere, but it's not clear how that's different from a global variable in a language like C. It's also not clear how a private variable differs from a local variable.

Another thing I've heard is that, for security reasons, if a function needs to be accessed it should be inherited first. The use-case is that an administrator should only have as much rights as they need and not everything, but it seems a conditional would work as well:

```<code>if ( login == "admin") {
    // invoke the function
}
</code>```

Why is this not ideal?

Given that there seems to be a procedural way to do everything object-oriented, why should I care about object-oriented programming?

答:
(+1) Asking a question of something you don't understand, its good, even if it sounds silly.

The difference is Object & Class Oriented Programming. "Plain C", works with data & functions. "C++" adds "object & classes" concepts, plus several related secondary concepts.

However, I advocate developers to learn "Plain C" before "C++". Or "Procedural Pascal" before "Object Pascal".

Many developers think students should be teach only one stuff.

For example, old teachers that doesn't get O.O., and teach only "Plain Structured C".

Or "hipster" teachers that teach only O.O., but not "Plain C", because "you don't need it". Or both, without caring about the teaching order.

I rather think, students should be taught both the "Structured Plain C" and "Object Oriented C (C++)". With "Plain C", first, and "C++", later.

In real world, you need to learn both paradigms (plus other paradigms, like "functional").

Thinking structured programs as a big, singleton "object", may help.

You also should put emphasis in namespaces ("modules"), in both languages, many teachers just ignore it, but, its important.


问:
design of 'game engine' for small javascript games?
I'm making a group of two or three simple javascript games for fun. After someone finishes one game, they'll be presented with a harder or easier version of another game depending on whether the original game was won or lost. I have a high-level question about the design of things:

So far I've created a class for one game type that manages the interaction with the UI and the state of the game itself. But for tracking how many of the subgames have been won, or for understanding whether the next game presented should be more or less difficult, are there arguments to be made for making a 'game engine' class? How does the engine communicate to the games? For instance, when a game is won, how is that information relayed to the engine? Is there a better or more common design?

(If you want to see what I have so far, the games are slowly taking shape here: https://github.com/yosemitebandit/candela and can be viewed at http://yosemitebandit.com/candela)

答:
Think about N games, not only two. Now, take out everything that is repeated across every implementation, that is your 'game engine'. An engine should offer you common implementation solutions, like giving you the coords clicked, rendering shapes, etc. and not storing states.

For more information about how games are structured, I would recommend reading:
Quake 2 Source Code Review it's complex, but you'll get an idea how a real game works, and the Irrlicht Engine tutorials should give you an idea how game engines are commonly used.


答:
If you are talking about libraries of any size, a good library will have many internal dependencies, since code will be reused.  It will also have a consistent public API that can evolve while being backward compatible, and if backward compatibility must be broken it will have a long period of supporting the old feature while it's in deprecated status.

Ideally it will have a consistency that makes it easier to learn, in small things like naming conventions extending to the architectural level.  It should also have a clear purpose, so someone deciding whether to use the library can know if it's appropriate.

These things are all difficult, and even good, widely used, libraries don't get them all perfect.   They require a high level of collaboration, agreement about goals, and some tough editing of features that have value in and of themselves but which collectively make the library lose focus.

These are difficult features to achieve by the process you describe.  It isn't impossible, but I think if it worked then "through moderation" would likely end up meaning that you are close to the situation you described where you provide a patch to the library owner -I mean the ruling council -I mean the moderators.

I suppose there might be some value to having some kind of stack exchange-ish system where rejected patches are publicly visible in addition to patches that make it into source control, and have some sort of chance to get up-voted and gain visibility, but I'm skeptical that great patches languishing unnoticed is really an important problem in practice.


答:
This could be percieved as a good way of identifying the candidates true understanding and experience of a language.

Im not a fan however, programmers today use IDE's and tools because they improve productivity. If a candidate can do great things using just Notepad i wouldn't value them over someone who can do great things using intelisense, why would i?.

You may be the greatest digger in the world with a shovel in your hand, but i would hire the guy whos great with the excavator if i wanted to dig a big hole.

From personal experience though, im astonished at how many times ive tried to jot down solutions to simple problems and been stuck trying to remember basic syntax. It can be really good way of solidifying your understanding by trying "think in code".


答: Framework recommendation:  At our office, we use TestDriven.NET which integrates with Visual Studio.  The unittest classes are written in C++/CLI, which can then call out to exercise whatever native code you need to test.  Yes, the C++/CLI classes go into their own assembly, thus a "testing" project added to the solution(s).</p>

Title: Is anyone doing "real" TDD with Visual-C++, and if yes, how do they do it?

Body:
Test Driven Development implies writing the test before the code and following a certain cycle:

Write Test

Check Test (run)

Write Production Code

Check Test (run)

Clean up Production Code

Check test (run)

As far as I'm concerned, this is only possible if your development solution allows you to very quickly switch between the production and test code, and to execute the test for a certain production code part extremely quickly.

Now, while there exist lots of Unit Testing Frameworks for C++ (I'm using Bost.Test atm.) it does seem that there doesn't really exist any decent (for native C++) Visual Studio (Plugin) solution that makes the TDD cycle bearable regardless of framework used.

"Bearable" means that it's a one-click action to run a test for a certain cpp file without having to manually set up a separate testing project etc. "Bearable" also means that a simple test starts (linking!) and runs very quickly.

So, what tools (plugins) and techniques are out there that make the TDD cycle possible for native C++ development with Visual Studio?

Note: I'm fine with free or "commercial" tools.

Please: No framework recommendations. (Unless the framework has a dedicated Visual Studio plugin and you want to recommend the plugin.)

Edit Note: The answers so far have provided links on how to integrate a Unit Testing framework into Visual Studio. The resources more or less describe how to get the UT framework to compile and get your first Tests running. This is not what this question is about. I'm of the opinion that to really work productively, having the Unit Tests in a manually maintained(!), separate vcproj from your production classes will add so much overhead that TDD "isn't possible". As far as I am aware, you do not add extra "projects" to a Java or C# thing to enable Unit Tests and TDD, and for a good reason. This should be possible with C++ given the right tools, but it seems (this question is about) that there are very little tools for TDD/C++/VS.

Googling around, I've found one tool, VisualAssert, that seems to aim in the right direction. However, afaiks, it doesn't seem to be in widespread use (compared to CppUnit, Boost.Test etc.).

Edit: I would like to add a comment to the context for this question. I think it does a good summary of outlining (part of) the problem: (comment by Billy ONeal)

Visual Studio does not use "build scripts" that are reasonably
  editable by the user. One project produces one binary. Moreover, Java
  has the property that Java never builds a complete binary -- the
  binary you build is just a ZIP of the class files. Therefore it's
  possible to compile separately then JAR together manually (using e.g.
  7z). C++ and C# both actually link their binaries, so generally
  speaking you can't write a script like that. The closest you can get
  is to compile everything separately and then do two linkings (one for
  production, one for testing).


答:
Speaking from experience on having been on the interviewee and interviewer side of things: Problems where you're asked to use a piece of paper or white board is done because your potential employer essentially wants to know two (2) things about you:

Are you a problem solver? It might sound elitist and harsh but if you can't solve my problems then why should I hire you?

Are you able to communicate well about how you solve a problem? You will be working together with a team, the management and sales. Failure to communicate is problematic in a team environment, there are a lot of times during software crafting/development where making one solution may wreak havoc on another. I can't stress enough how important a simple chat would've saved you and your team from dealing with the havoc and come up with an even better solution.

When the problem you're given is done right by the interviewer then you should be able to answer some questions and solve problems without the need of IDE's or other tools. Usually the problems you're given should be answerable regardless of intellisense/autocomplete knowledge as they won't help you anyway on software and algorithm design anyway, so it is a bogus statement if anyone tells you otherwise as those tools only aid your productivity. I wouldn't be surprised if candidates that complain about the lack of IDE are red flagged as copy-and-paste/wizard users rather than "real" coders/programmers.

So if you're in a situation where you have to write code then do the following:

Take a deep breath. Get that blood circulating in your head.

Focus on the problem at hand. Everything else is irrelevant.

And whatever you do: Don't panic! Always assume good intentions. Just so you know: freaking out is a bad sign.

Usually you won't be gauged on syntax correctness anyway. As long as you know what variables, arrays, loops and conditionals are, you should be able to solve problems on paper. Bonus points if you can remember some computer structures and algorithms. Sometimes the interviewer might probe you on typos and it would help to recognize your own mistakes; in such situations just apologize, correct and move on.

And if you want practice, there is Project Euler... or you could just work on real problems writing real applications.


答:
Why?

Because too many people with nice looking resumes can't code their way out of a paper bag.

Also, there are people who maybe can code, but can't communicate what or why they are doing it that way, which is a big detriment in team coding situations.

And don't worry about punctuation coloring and the other stuff that the IDE can fix; because if it's someone you want to work for, that's not the part of the answer in which they're really interested.


问:
Is a program linked against an LGPL library in linux still under GPL?
If I were to write say, an embeded linux video server, how much of the code do I have to offer to someone who requests the source? Do I have to offer the code that directly links against the GPL covered code or do I have to offer all code? For instance, if I use gstreamer, or any other LGPL code, on a linux platform in my program, does all of my code become under GPL simply because somewhere in the chain, the LGPL program had to link agaist GPL code?

I guess this is an extension of the question. Can you write a C library that compiles in linux that does not become subject to GPL?

答: You really should just read the LGPL, sections 4, 5 and 6. No attempt to simplify those words will preserve their meaning. You will also find that there are multiple positions on some of these questions and the only way to get an authoritative answer you can legally rely on is to get your own written opinion from a lawyer.</p>


答:
There is a way to do everything with a Turing machine, or at minimum in an assembly language for the machine code that a C or C++ program will eventually compile down to.

So the difference is not about what the code can do, but about what people can do.

People make mistakes.  Lots.

OOP introduces a paradigm and a syntax that helps reduce the size and probability density of the space of possible human coding mistakes.  Sometimes by making the mistake illegal for a certain class of data object (such as it's not a method declared for that object).  Sometimes by making the mistake more verbose, or stylistically odd looking compared to canonical usage of the language.  Sometimes by requiring an interface with far less possible inconsistant or entangled usages (public vs. private).  etc.

The bigger the project, the higher the likelihood of mistakes.  Which a new coder might not be exposed to if only experienced with small programs.  Thus the potential puzzlement at why OOP is valuable.

Title: What's the benefit of object-oriented programming over procedural programming?

Body:
I'm trying to understand the difference between procedural languages like C and object-oriented languages like C++. I've never used C++, but I've been discussing with my friends on how to differentiate the two.

I've been told C++ has object-oriented concepts as well as public and private modes for definition of variables: things C does not have. I've never had to use these for while developing programs in Visual Basic.NET: what are the benefits of these?

I've also been told that if a variable is public, it can be accessed anywhere, but it's not clear how that's different from a global variable in a language like C. It's also not clear how a private variable differs from a local variable.

Another thing I've heard is that, for security reasons, if a function needs to be accessed it should be inherited first. The use-case is that an administrator should only have as much rights as they need and not everything, but it seems a conditional would work as well:

```<code>if ( login == "admin") {
    // invoke the function
}
</code>```

Why is this not ideal?

Given that there seems to be a procedural way to do everything object-oriented, why should I care about object-oriented programming?


问:
Which .NET REST approach/technology/tool should I use?
I am implementing a RESTful web service and several client applications that are mostly in Silverlight. I am finding a litany of options for developing both the server-side and client-side of the API but am not sure which is the best approach. I'm concerned about stability as well as a platform that will continue to exist a few months from now.

We started using the REST Starter Kit with .NET 3.5 but moved to the new WCF Web API when updating to .NET 4.0. All of their documentation indicates that WCF Web API is the replacement for the RSK. However, Web API is only in Preview 4 and does not include support for Silverlight or Windows Phone 7 clients (yet).

WCF Web API looks like a wrapper on top of the WCF WebHttp Services stuff provided in the System.ServiceModel.Web library which makes me think that maybe it would be simpler to just go with the built-in stuff but Web API does offer some nice features.

I am specifically tied-up trying to determine the best course for the client-side. My main requirement is that I need to support deserializing into my client-side objects quickly and easily. The Web API offers a nice client library but doesn't have a Silverlight version.

I'd like to use the latest approach and the toolset that is being actively developed and supported.

Is the REST Starter Kit really obsolete?

Has anyone had any success implementing the WCF Web API toolkit?

Is there merit to using either of these over the built-in WCF WebHttp Services features found in System.ServiceModel.Web?

Is there a single solution that works for any client (web, Silverlight, etc.)?

What suggestions do you have?

答:
Just to follow-up and close out the post, with Preview 5, the WCF Web API took a huge leap forward making it incredibly simple to create REST APIs.  And while the current codebase on Codeplex does not include a Silverlight client, there is a toolkit out there and I was able to easily strip out the Async-CTP parts from the open source code and create a SL version.

I strongly recommend anyone interested in getting into REST with WCF look into the framework: http://wcf.codeplex.com.

FYI - It will be an integrated part of .NET 4.5 and is currently being rewritten to run on the same core framework as ASP.NET MVC (although I am told it will definitely support self-hosting still).


问:
Can all code be represented as a series of Map / Filter / Reduce operations?
I have recently been refactoring large chunks of code and replacing them with Linq queries.

Removing the language bias - Linq is essentially a set of Map / Filter and Reduce operations that operate on a sequence of data.

This got me thinking, how far would I theoretically be able to take this. Would I be able to rewrite the whole code base into a series (or even a single) of Map / Filter and Reduce operations.

Unfortunately I get paid to do useful stuff, so I haven't been able to experiment much further, but I can't think of any code structure that couldn't be re structured as such. Side effected code can be dealt with via monads.. Even output is essentially mapping memory addresses to screen addresses.

Is there anything that couldn't be (theoretically) rewritten as a Linq query?

答: It's called functional programming, and is considered by many to be a foundational concept. here's a good intro on Joel On Software. The more technical answer is no, there is no currently known way of asking your computer questions (in a well defined way) that cannot be answered via SKI calculus.</p>


问:
Massive vehicular network simulator
I am interested in making a vehicular network simulator (vehicular network as in vehicles can be equipped with radios and when they come in range they can talk with each other). I want to be able to scale to 1000s of nodes if not more. I am quite frankly torn on how to do, or even which language to use or whether I should instead be using some other piece of software/code.

I know that this should depend on a lot of design decisions that I may have, but it would be great if somebody can point me towards the right direction. I was planning to use a multi-threaded architecture, but not sure whether it will add to the complication or make it easier. Also if I go for a multi-threaded architecture, do you think that the Go language will be a good choice?

I have a few years of experience in Java, but haven't done any big project, and essentially no experience in Go.

答: You can also enhance existing network simulators. OMNET++ is a famous network simulation framework. Similarly simple Google search reveals many links like the Veins Network and Road Traffic Simulation. You can explore them and see which one can be easily extended by you</p>

Title: Massive vehicular network simulator


问:
What is the history of why bytes are eight bits?
What were the historical forces at work, the tradeoffs to make, in deciding to use groups of eight bits as the fundamental unit?

There were machines, once upon a time, using other word sizes. But today, for non-eight-bitness, you must look to museum pieces, specialized chips for embedded applications, and DSPs. How did the byte evolve out of the chaos and creativity of the early days of computer design?

I can imagine that fewer bits would be ineffective for handling enough data to make computing feasible, while too many would have lead to expensive hardware. Were other influences in play? Why did these forces balance out to eight bits?

(BTW, if I could time travel, I'd go back to when the byte was declared to be 8 bits, and convince everyone to make it 12 bits, bribing them with some early 21st century trinkets.)

答: A byte doesn't have to be 8 bits, but it appears that C and C++ define a byte as being at least 8 bits (although it could be more). This question on Stack Overflow mentions a few systems where 1 byte is not 8 bits.</p>


答: Seven bits for ASCII information, and one for error-detecting parity.</p>

Title: What is the history of why bytes are eight bits?

Body:
What were the historical forces at work, the tradeoffs to make, in deciding to use groups of eight bits as the fundamental unit?

There were machines, once upon a time, using other word sizes. But today, for non-eight-bitness, you must look to museum pieces, specialized chips for embedded applications, and DSPs. How did the byte evolve out of the chaos and creativity of the early days of computer design?

I can imagine that fewer bits would be ineffective for handling enough data to make computing feasible, while too many would have lead to expensive hardware. Were other influences in play? Why did these forces balance out to eight bits?

(BTW, if I could time travel, I'd go back to when the byte was declared to be 8 bits, and convince everyone to make it 12 bits, bribing them with some early 21st century trinkets.)


答:
A lot of really early work was done with 5-bit baudot codes, but those quickly became quite limiting (only 32 possible characters, so basically only upper-case letters, and a few punctuation marks, but not enough "space" for digits).

From there, quite a few machines went to 6-bit characters. This was still pretty inadequate though -- if you wanted upper- and lower-case (English) letters and digits, that left only two more characters for punctuation, so most still had only one case of letters in a character set.

ASCII defined a 7-bit character set. That was "good enough" for a lot of uses for a long time, and has formed the basis of most newer character sets as well (ISO 646, ISO 8859, Unicode, ISO 10646, etc.)

Binary computers motivate designers to making sizes powers of two. Since the "standard" character set required 7 bits anyway, it wasn't much of a stretch to add one more bit to get a power of 2 (and by then, storage was becoming enough cheaper that "wasting" a bit for most characters was more acceptable as well).

Since then, character sets have moved to 16 and 32 bits, but most mainstream computers are largely based on the original IBM PC. Then again, enough of the market is sufficiently satisfied with 8-bit characters that even if the PC hadn't come to its current level of dominance, I'm not sure everybody would do everything with larger characters anyway.

I should also add that the market has changed quite a bit. In the current market, the character size is defined less by the hardware than the software. Windows, Java, etc., moved to 16-bit characters long ago.

Now, the hindrance in supporting 16- or 32-bit characters is only minimally from the difficulties inherent in 16- or 32-bit characters themselves, and largely from the difficulty of supporting i18n in general. In ASCII (for example) detecting whether a letter is upper or lower case, or converting between the two, is incredibly trivial. In full Unicode/ISO 10646, it's basically indescribably complex (to the point that the standards don't even try -- they give tables, not descriptions). Then you add in the fact that for some languages/character sets, even the basic idea of upper/lower case doesn't apply. Then you add in the fact that even displaying characters in some of those is much more complex still.

That's all sufficiently complex that the vast majority of software doesn't even try. The situation is slowly improving, but slowly is the operative word.


答:
Because I want to know if you can go up to the board during one of our brainstorming sessions and convey your ideas to the rest of the team.

I don't even care if you know how to spell your name, as long as you can get up in front of the team and convey your ideas to the rest of us.


答:
As many said any program, once compiled, is turned into a binary code and, as a binary string might be used to represent an integer, any program is eventually just a number. However defining the number you need could be pretty hard and that is why high level programming languages came up. Programming languages are just models of the assembly code they eventually produce.  I would like to explain you the difference between procedural and OO programming by means of this very nice paper about Context Oriented Programming http://www.jot.fm/issues/issue_2008_03/article4/

as you can see from this picture,  depicted in the paper, Procedural programming provides only one dimension to associate a computational unit with a name. Here, procedure calls or names are directly mapped to procedure implementations. In Figure-a calling m1 leaves no choice but the invocation of the only implementation of procedure m1.

Object-oriented programming adds another dimension for name resolution to that of procedural programming. In addition to the method or procedure name, message dispatch takes the message receiver into consideration when looking up a method. In Figure-b we see two implementations of method m1. The selection of the appropriate method not only depends on the the message name m1, but also the receiver of the actual message, here Ry.

This indeed allows encapsulation and modularization.

Figure-c is finally about subject-oriented programming extends object-oriented method dispatch by yet another dimension.

Hope this helped you thinking at OOP from a different perspective.