问:
Multithreaded Programming?
Recently I've finished learning about multithreaded programming on single shared objects, but was curious about how different things would be in order to successfully program on multiple shared objects?</p>

答:
The difference is that usually when you have multiple shared objects, they live in some sort of collection (like a hash table, linked list, tree, or whatever). This requires some kind of pattern for how the locking will work.

The simplest solution is to have one lock for the collection. A thread can acquire the lock, find the object in the collection, work on that object, and then release the lock. This is very simple and for some cases is the best solution. But the big downside is that two threads can't work on two different objects in the same collection.

You can also have one lock for the collection itself and one lock for each object in the collection. You then acquire the collection lock, find the object you want, acquire the lock on that object, and then release the collection lock (assuming you aren't going to modify the collection itself). This allows other threads to search the collection and modify other objects in the collection while a thread is working on an object in the collection.

There are all kinds of other "in-between" approaches. But the basic concept is the same -- you still must ensure that a structure cannot be accessed by one thread while another thread is, or might be, modifying it.

Title: Multithreaded Programming?


问:
Couple of questions about sprint in scrum methodology
Its a general title for the question but I have a couple of questions for the Sprint in a SCRUM methodology.

What happens if a HOTFIX comes in the middle of a sprint. e.g - The website crashes or some part of the site that hasnt been worked on for quite some time crashes (like creditcard authorize or webservices etc). How do you incorporate that in the current Sprint(s)?

How to tackle bugs at the end of a Sprint. I know we can have Defect tracking sprint but should I plan for that at beginning? Or do I put that sprint back in the product backlog and start planning that from the next sprint planning.

How to decide how many sprints are required?

thank you for your help

答:
1) Fire fighting or zero point bug.

Fire fighting is where something is just so important that it has to be done now not matter what.

Zero-point bug is reserved for something that was implemented in this or the last sprint, has been claimed as done but subsequently found to be incorrect.

2) Zero point bug. If you claimed it as done and it isn't... you need to make it done. Put a card on the board as soon as you find the bug if it's urgent. If it's big and you can postpone it, it becomes a new story in the backlog to be prioritized along with every other outstanding story.

3) Decide how big an iteration is. Work out how much work you can get done in an iteration. How many times that delivers the whole product backlog?

This is an ongoing thing. You need to be working with a team on the same kind of work, using the same process and tools for a while before you have a stable, predictable velocity and can predict how many iterations it will take to complete the product backlog.

OwnerDisplayName: derrk

ContentLicense: CC BY-SA 3.0


问:
Should there be separate database schemas for each developer or should there be just one that all developers share?
During development, should developers each have their own copy of the database to work on ? Or should there be a common shared development database ?

The former will give developers more flexibility. For ex., they can run their own regression tests during development and unit testing without worrying about corrupting the data for other developers. However, it is difficult to maintain for database adminstrators.

The latter is easier to maintain (less integration overheads as everyone's working on the same schema) but requires more effort to ensure data sanctity (developers should be careful and not make changes that will impact others).

答:
Well, there needs to be a central copy of the database to maintain the official schema.

For regression and unit testing, there should be available a sample database containing fictional, but reasonable data, and a blank database, both fully up to date with the latest schema from the master database.  Scripts can be used to create these copies.  The sample database is useful for testing, while the blank database is useful for new installations.

Ideally, unit tests should be designed using database transactions, so that tests which add, change or delete records can roll back the transaction to revert the database to its original state.

Many programs provide a mechanism for altering the database schema on-the-fly, which would be a requirement for deploying an update of the software to any customer who already has data in their database.


答:
Each developer should have their own copy of the database for development. Period. Anything else gets in the way and can cause obstacles in the development environment. IMO, there is nothing worse than chasing down a bug for hours that was caused by a change somebody else made to some data you are using in your debugging.

As far as this being more work for the DBA's, you should handle all schema changes with scripts and automate the deployment of those scripts. There are tons of tools around to help with that (and many of them are free).

Title: Should there be separate database schemas for each developer or should there be just one that all developers share?

Body:
During development, should developers each have their own copy of the database to work on ? Or should there be a common shared development database ?

The former will give developers more flexibility. For ex., they can run their own regression tests during development and unit testing without worrying about corrupting the data for other developers. However, it is difficult to maintain for database adminstrators.

The latter is easier to maintain (less integration overheads as everyone's working on the same schema) but requires more effort to ensure data sanctity (developers should be careful and not make changes that will impact others).


答: Just an addition: There needs to be a central db. If one of the developer misses something, chances are high that the same problem (within the same db) would be caught by another developer. And yes, you need to make sure that the db transactions are ACID-ized.</p>


问:
What factors can make mid-project join successful?
It's not entirely uncommon in IT that programmers are added to an existing project somewhere in the middle, or closer to finish.

Unfortunately, I've seen that people quickly get disillusioned and leave the job.

So, is there an actual problem? If there is a problem, is there some research in or are there best practices for avoiding this mid-project-join syndrome?

Is this common in industry?

答: Pairing can make getting up to speed on a new development project much easier. Personally, I believe it can make me get up to speed on the project 3 or 4 times faster than doing the work on my own. This is helped a lot because you can get a lot of history/decisions of the project at the same time you are getting familiar with the code.</p>


答:
The right answer is probably "both".  This fits into the production/staging/development separation used in many development cycles.

Development/testing servers are available, as needed, to developers so that they can design new features and do regression testing with total freedom and impunity; nothing can break so bad that you can't just start over and be up and running again for the next test in no more time than a VM snapshot rollback.

Staging servers exist for the purpose of combining all of the features from all of the different developers and doing more extensive testing on real or reasonable models of real data.  Having a separate staging system means that you can test out the deployment of the new features without risking real data;  You can test on the staging machine until deployment becomes totally routine.

Production servers are usually off limits completely to developers.  Knowledge learned on the staging systems means that IT staff can follow a piece by piece procedure.  IT staff are often much better at keeping logs of what changes have been made to the production server than devs, and that's A-OK!  At most, developers have just enough credentials on production servers to watch logs, but even that may be better left to IT.


问:
What do you do to improve your logical programming skills?
Do you think that only the programming pratice will help you to improve your logical programming skill or do you train your brain with puzzle games, trying imagine how universe works, playing instruments and so on?

Devoting more time with programming, will do you get logical programming skills more fast?

答:
I read this: What is the single most effective thing you did to improve your programming skills?

More seriously, I guess you can try:

to train your brain and solve puzzles and other games (as suggested by others),

to learn logic theory, and get back to the hard-core maths that comes with it.

But mostly, i think you should:

have a look at an algorithm bank and hand-pick a few,

try to implement solutions for the problems they address,

then look at the reference implementations,

publish a paper if you beat them :)

The NIST Dictionary of Algorithms and Data Structures should keep you busy for a while...

Then find a pet project that involves solving something.

ContentLicense: CC BY-SA 2.5


问:
Is there any formal research in FizzBuzz Question Effectiveness?
After seeing this question today on variation of the FizzBuzz interview question, as well as seeing other questions related to it around, I have to ask: is there any formal research on how effective this is as an interview technique? There are plenty of folks who say that it filters out some crazy-sounding percentage of candidates (95%+ in some cases) but how good is it for finding good programmers/developers?

There has been some research that shows that soft skills might be better indicators than hard skills for choosing a good candidate for a job role. As well, there might be some intermediate reasons for so many candidates failing this test (nervousness, thinking "it's a trick", etc).

Based on the comments so far, it looks like the idea behind FizzBuzz questions is to determine whether or not the person has good (enough) coding skills to be further considered. I'm not totally convinced FizzBuzz actually does this. Also, remember that FizzBuzz filters a very large percentage of candidates very early in the hiring process, which could mean that significant numbers of good candidates are being removed early on because they can't solve silly problems fast enough.

Also, I'll point out that looking at FizzBuzz effectiveness is something that can completely be done in a quantitative manner. This is unlike looking at "fit" or "passion" which are highly variable and highly unscientific (but still quite important for new hiring decisions).

答: FizzBuzz isn't about identifying good programmers, it's about eliminating bad ones/fakers. If a candidate can't pass the FizzBuzz test then they don't know how to program and shouldn't be applying for a programming position.</p>


问:
Supporting multitenancy
What are the typical challenges that arise when converting a single-tenant app into a multitenant app? Security and data isolation strike me as the most significant. What are some others?

I'm one of the architects for a fairly significant automation effort, and historically it's just been our company using it. We want to make it possible for others to use it as well. Every time we talk about "making it multitenant", the conversation revolves around keeping users with one tenant away from the data that another tenant owns, and making sure that users with one tenant can't (either intentionally or inadvertently) create impacts in another tenant's environments. What I'm wondering is whether security/data isolation are really the only major concerns here, or whether there are some other major concerns that we're just not thinking about.

答: The biggest problem in multi-tenancy in my opinion is customization. This happens routinely if you are selling a business application to enterprises. It could vary from something as simple as every customer wanting their own skins to the ability to configure additional fields, rules,forms and reports. The level of customization that you need to support plays a critical part in the architecture.</p>

Title: Supporting multitenancy


问:
Writing java doc comments for unit test cases
In my opinion, the unit test cases itself serve as a documentation for the code. My company wants me to write detailed java doc comments on top of unit test cases. Is it necessary to do so? Do you write comments like that ?</p>

答:
Javadoc comments can be extracted and formatted in a separate reference document, unit tests cannot. Also, bear in mind that what you write in words can be different from the actual code, and usually you are describing in words the actual expected behavior. One of the ways to find bugs is to compare documentation to the actual code, if they don't match - it's a bug (in either of them, and sometimes - both).

Unit test is for testing, not for documentation. Using unit test as documentation is wrong and shouldn't be done.


答:
What I do is JAVADOC-comment :

the class, indicating which class is unit tested (even though it should me obvious since the best practice on that subject suggests that the name of the test case should be the name of the class + "Test" or + "TestCase"). This is done using the {@link XXXClass} JAVADOC comment

the methods, indicating which method is tested ({@link XXXClass#method1}). Sometimes I need to have multiple test methods for one method of a class to properly test all paths. When it happens, I write one additional line stating what path I am testing inside (but I never stray away from my one-line convention)

Apart from that, no other comment. To take their attention elsewhere maybe you could use something like Cobertura to generate pretty code coverage graphics and make them happy that way :-)

Additional note: I am referring to unit test cases, if we're talking about integration test cases, then one or two more lines to explain what is going on may indeed be necessary...

Title: Writing java doc comments for unit test cases

Body: In my opinion, the unit test cases itself serve as a documentation for the code. My company wants me to write detailed java doc comments on top of unit test cases. Is it necessary to do so? Do you write comments like that ?</p>


答:
Documentation requirements for any code are fairly completely covered in the answers to this question: My boss wants a narrated line-by-line English explanation of our code

As a summary of the answers you'll see there, "It depends on your situation". There are cases where it is reasonable (and encouraged), and others where it is a waste of your time.


答:
This is a very hot current research topic. The question of how to properly share data between multiple, concurrent, processing units, doesn't have obviously good answers yet.

Some of the issues that change and you should think about:

With multiple shared objects, you'll want to have different threads being able to work with different objects at the same time. If two objects are different, but related, you'll need to have a way of deciding whether they can be worked on independently of each other

Objects may end up moving around in memory more, as they get moved closer to where they are being used (physically closer, or logically closer)

Multiple related objects may end up cached in multiple, un-related, caches. Those caches are going to want to know when they've become invalid, which they might if one of a set of related objects is changed. Imagine, for example, a thread which draws to the screen, while other threads go about modifying the data that's being drawn. How do you make sure that what you see on the screen makes sense?

There are different ways for objects to be accessed, some with side effects, some without. The patterns of access can heavily influence performance - optimization techniques can become intractably complex

Title: Multithreaded Programming?

Body: Recently I've finished learning about multithreaded programming on single shared objects, but was curious about how different things would be in order to successfully program on multiple shared objects?</p>


答:
I'd say do whichever the developers want.  Each application is different.  Some may call for one, some may call for the other, some may call for both.

So ... if the programmer wants their own database, let them set one up (assuming space/resources are available, of course).  If they'd rather use a shared development database for whatever reason, let them do that.

Basically, restricting developers to one or the other is not helping the development process.


问:
Do I need to license my code as GPLv2 if I only read/write to a database and pipe?
I'm writing an API for an open source network monitoring system which is licensed under the GPLv2. I also intend to open source this API but would like to license it under the BSD License.

I don't re-use or link to any of the code in this system and I don't use any header files.

I will not be re-distributing any part of the network monitoring code.

Part of my application will install into the network monitoring installation folders, but not replace, remove or modify any of its files

My hook into the system is via:

existing MySQL databases belonging to the service, my API reads and writes to these databases directly. My concern here would be that whilst I am not copying their SQL statements, there are some complex operations. I've found that in a couple of cases I've arrived at SQL statements or sequences of work that aren't too dissimilar to theirs, it's hard not to.

I talk to a pipe to issue various commands and submit data directly into the checking engine. This pipe is documented by the author as an official mechanism to communicate with the checking engine. The command pipe uses single line strings to issue commands, the pipe does not return any data, it's "fire and forget".

There are a number of HTTP CGI scripts in the system from which I can scrape status information. I may use these in a future release.

Is this considered "arms length" enough for me to license my code under a different license? i.e.

http://www.gnu.org/licenses/gpl-faq.html#MereAggregation

However, in many cases you can distribute the GPL-covered software
  alongside your proprietary system. To do this validly, you must make
  sure that the free and non-free programs communicate at arms length,
  that they are not combined in a way that would make them effectively a
  single program.

Would reading and writing rows to a database be considered "exchanging complex internal data structures"?

http://www.gnu.org/licenses/gpl-faq.html#MereAggregation

By contrast, pipes, sockets and command-line arguments are
  communication mechanisms normally used between two separate programs.
  So when they are used for communication, the modules normally are
  separate programs. But if the semantics of the communication are
  intimate enough, exchanging complex internal data structures, that too
  could be a basis to consider the two parts as combined into a larger
  program.

答:
Check with a lawyer.

Your description does show a system which can be licensed independently of the original system. That said, check with a lawyer to be sure, since things change depending on your jurisdiction.

In practical terms, though, since you're not selling your API, you're not at great risk of being sued or otherwise getting into trouble. If you end up having to change licenses farther down the road, that's probably ok.

However, we're not lawyers. If this is really a source of concern for you, then check with a lawyer.


问:
What is the standard /an acceptable period of time to support a particular version of software?
Let's say version 2.4.x of Software Package X was released 2 years ago, and was sold up until about 6 months ago. Version 3.1.0 is now out (which fixes a lot of the issues with version 2.4.x), and is the only version actively being sold.

In this case, the software is being sold to large businesses, not individuals, so the maintenance effort required is substantial.

For how long should the company offer support for version 2.4.x?

答: If your clients are large and institutional, then your answer is however long they're paying you for it. This is a business, not a technical decision. Do the math, comparing the support/maintenance fees with the cost, and keep the support around for as long as it's still making you money.


问:
Randomly Accessing Data Packets in a Compressed File
In my line of work I deal with very large files, hundreds of Gigabytes in size.  The nature of the data in these files is such that compression would greatly reduce their size.  The problem is, the records/data packets within the file must be individually accessible.

Is there a way to apply some home-grown techniques to these records to individually compress them and, once compressed, place them in a data stream such that the byte offset locations of each compressed packet is still known?

Would this kind of fragmentation of the packet data substantially affect the efficiency of the compression/decompression cycle?  Are zip algorithms suitable for this, or are there better methods of compression that are designed specifically for this?

答:
A lot of this depends on the types of files you're dealing with, and their internal structure.

Is there a structural/logical reason for the files being as large as they are?

How interconnected is the data within each file?

Is it likely that once you start reading, you'll finish your read locally, or will you find yourself skipping around the file to finish the read?

Under the assumption that your reads are mostly local, and relatively small, a modified LZ compression algorithm should do the trick. You can roll your own, or use one of the examples available on the web, and get fairly decent compression while allowing for random access.

If you're dealing with more complex architectures and contents, though, you'll have to get more creative. You might want to look into parsing the contents of each file and then storing them into a database which comes with built in compression algorithms, like Oracle, for example, since it can save you significant headaches.


问:
How "commercially savvy" should software developers be?
I have been watching answers to many questions on this site, and have come to the conclusion that commercial pragmatism does not factor into many software development discussions. As a result, I seriously wonder at the commercial skills within the industry, specifically the ability to deliver projects on time and to a budget. I see no indication from the site that commercially successful project delivery is a serious concern, yet the industry has a reputation for poor performance in this.

Rarely, if ever, does the cost of time factor into discussions. I have never seen concepts such as opportunity cost, time to market, competitive advantage or cash flow mentioned, let alone discussed in technical answers to questions.  How can you answer virtually any question without understanding the commercial background on which it is asked?

Even Open source projects have a need to operate efficiently and deploy their limited resources to providing the most value for effort.  Typically small start-ups have cash flow issues that outweigh longevity concerns, yet they are typically still advised to build for a future they probably won’t have if they do.

Is it fair to say that these problems are solely the Managers and Project managers to solve, or are we, as developers, also responsible for ensuring successful on time, within budget delivery of projects, even if those budgets do not allow use to achieve engineering excellence?

答:
Joel Spolsky has a view on this here which makes a lot of sense ... </p>

<p>"... a programmer who understands the fundamentals of business is going to be a more valuable programmer, to a business, than a programmer who doesn't. That's all there is to it. I can't tell you how many times I've been frustrated by programmers with crazy ideas that make sense in code but don't make sense in capitalism. If you understand this stuff, you're a more valuable programmer, and you'll get rewarded for it ..."</p>

Body:
Joel Spolsky has a view on this here which makes a lot of sense ...

"... a programmer who understands the fundamentals of business is going to be a more valuable programmer, to a business, than a programmer who doesn't. That's all there is to it. I can't tell you how many times I've been frustrated by programmers with crazy ideas that make sense in code but don't make sense in capitalism. If you understand this stuff, you're a more valuable programmer, and you'll get rewarded for it ..."


问:
How to Avoid Fragile Unit Tests?
We have written close to 3,000 tests -- data has been hard coded, very little reuse of code. This methodology has began to bite us. As the system changes we find ourselves spending more time fixing broken tests. We have unit, integration and functional tests.

What I'm looking for is a definitive way to write manageable and maintainable tests.

Frameworks

FakeItEasy

nUnit

AutoFixture

答:
I am sure others will have a lot more input, but in my experience, these are some important things that will help you:

Use a test object factory to build input data structures, so you don't need to duplicate that logic. Perhaps look into a helper library such as AutoFixture to cut down on the code needed for test setup.

For each test class, centralize creation of the SUT, so it will be easy to change when things get refactored.

Remember, that test code is just as important as production code. It should also be refactored, if you find that you are repeating yourself, if the code feels unmantainable, etc, etc.

OwnerDisplayName: Chuck Conway

ContentLicense: CC BY-SA 4.0

Title: How to Avoid Fragile Unit Tests?

OwnerDisplayName: driis


问:
I will be delivering a lecture on Android development tomorrow. Any topics I should cover?
I have been asked by my local Association for Computing Machinery chapter to give a lecture on Android development, and while I already have some topics to cover, I was curious if the community of SO had any suggestions of things that would be interesting to hear about.

Thus selected:

OpenGL

Using hardware features (camera, audio, accelerometer, multitouch)

Good UI practices

Social media integration

答:
Here are my two cents:

Threading: AsyncTask, Handler/Looper

Database: sqlite, DatabaseHelper, versioning

OwnerDisplayName: MizardX


答:
Cover android application components like

1.Activities

 2.Services

 3.Broadcast receivers

 4.Content providers

Title: I will be delivering a lecture on Android development tomorrow. Any topics I should cover?

Body:
I have been asked by my local Association for Computing Machinery chapter to give a lecture on Android development, and while I already have some topics to cover, I was curious if the community of SO had any suggestions of things that would be interesting to hear about.

Thus selected:

OpenGL

Using hardware features (camera, audio, accelerometer, multitouch)

Good UI practices

Social media integration

OwnerDisplayName: Vijay


答: You might consider going at this from a different direction.  How about storing the files on a compressed drive?  They'll be accessible as regular files, but take up less space on the drives.</p>

Title: Randomly Accessing Data Packets in a Compressed File

Body:
In my line of work I deal with very large files, hundreds of Gigabytes in size.  The nature of the data in these files is such that compression would greatly reduce their size.  The problem is, the records/data packets within the file must be individually accessible.

Is there a way to apply some home-grown techniques to these records to individually compress them and, once compressed, place them in a data stream such that the byte offset locations of each compressed packet is still known?

Would this kind of fragmentation of the packet data substantially affect the efficiency of the compression/decompression cycle?  Are zip algorithms suitable for this, or are there better methods of compression that are designed specifically for this?


答:
I see no indication from the site that commercially successful project delivery is a serious concern ...

Comment:  I think you are being rather selective in your reading.  People often bring the business aspects of software development into their answers.  But having said that, this site is intended for discussion of the programming side of our industry, so it is not surprising that that is what is mostly talked about.

Is it fair to say that these problems are solely the Managers and Project managers to solve, or are we, as developers, also responsible for ensuring successful on time, within budget delivery of projects, even if those budgets do not allow use to achieve engineering excellence?

The latter, IMO.  And experienced / seasoned developers recognize this.  But that's not the whole story because a less-than-excellently engineered product is frequently pushing costs (of various kinds) off into the future.  And manager types frequently either don't understand this or downplay it with higher management, clients, etc.  (And guess who gets blamed for the poor quality work ...)

But "So what?!".  What do you propose to do about it?  Make an MBA a mandatory qualification for Java programmers?

The way that I see it, the business side of the software development is primarily the responsibility of the managers.  We (programmers) can help them do their job by understanding what the users need, asking the right questions, providing the right advice, etc.  And having business knowledge is going to help us do that.

But the bottom line is that the managers are typically the ones with the business experience and the qualifications, and it is primarily their responsibility.  (And if not, why does the company employ them in the first place?)

And when we get that experience, we'll get to wear the "manager" hat ... unless we work hard to avoid it.

Title: How "commercially savvy" should software developers be?

Body:
I have been watching answers to many questions on this site, and have come to the conclusion that commercial pragmatism does not factor into many software development discussions. As a result, I seriously wonder at the commercial skills within the industry, specifically the ability to deliver projects on time and to a budget. I see no indication from the site that commercially successful project delivery is a serious concern, yet the industry has a reputation for poor performance in this.

Rarely, if ever, does the cost of time factor into discussions. I have never seen concepts such as opportunity cost, time to market, competitive advantage or cash flow mentioned, let alone discussed in technical answers to questions.  How can you answer virtually any question without understanding the commercial background on which it is asked?

Even Open source projects have a need to operate efficiently and deploy their limited resources to providing the most value for effort.  Typically small start-ups have cash flow issues that outweigh longevity concerns, yet they are typically still advised to build for a future they probably won’t have if they do.

Is it fair to say that these problems are solely the Managers and Project managers to solve, or are we, as developers, also responsible for ensuring successful on time, within budget delivery of projects, even if those budgets do not allow use to achieve engineering excellence?


问:
Complexity vs maintainability in modern hardware
Today with the modern hardware and memory coming cheap, how much sense does it make to spend effort to analyze algoriths or data structure complexity?

Wouldn't it be better instead, to focus on clean, maintainable code, readable code than on optimizations for complexity?

Note:I not talking about embedded systems or systems with similar kinds of constraints.

答:
Yes, it is always recommendable to focus on correctness first, then readability and maintainability, then - if ever - on performance. In the majority of cases nowadays, performance is not a significant constraint.

That said, it is still a best practice to choose your algorithms and data structures correctly. If this means just calling the right kind of standard library sorting method, or using the right type of container for a given usage pattern, that is usually easy to change later. But anytime you need to really implement some kind of nontrivial algorithm, it is well worth thinking about performance requirements in advance. It may be that there aren't much performance requirements, like if a string search algorithm will be called 10 times a day with a few dozen characters of text. Then it obviously isn't worth spending a lot of time researching/designing algorithm options and tuning its performance. However, if it is called thousands of times a day with a million characters each time, the lack of performance by a badly chosen/implemented algorithm may indeed bring your program to a halt.

So you need to look out and identify potential performance hot spots early enough, and design them carefully if there are such hot spots. Do back-of-the-envelope calculations to estimate the performance, throughput, response time etc. during the analysis and design phase. These may help uncover unrealistic expectations / assumptions about the system. Build an end-to-end skeleton of the system as early as possible, then you can conduct some rough measurements (with dummy data, simplistic workflows, whatever) to get a sense of the real vs expected performance. You also need to take into account expected short / long term increase in traffic. A web site may work well initially with 50 users, but it may get into serious trouble when its user base grows to thousands a year later. It is very painful and risky to try to solve performance problems when the system is already fully congested. Very often it is not obvious that the system is getting closer to its point of congestion - its performance may look acceptable all the time, then all of a sudden drops dramatically. If you can't foresee and prevent these problems in due time, you will need to solve them while angry users' calls are flooding the support lines and your boss is breathing into your neck waiting for the instant solution...


答:
Mike's answer is very good, and a lot of the points there almost underplay their complexity due to how short they are, so take those to heart.

One point I would add is that you should have good management tools for creating (and later on, managing) new tenants.  Depending on the physical architecture you go with, this can be far from trivial, and is something that is often overlooked.  The benefits of a software as a service product only really come into play when there are a large number of tenants, so a fair amount of effort should go into catering for this.

To extend on Sriram's answer; per-tenant customisation is pretty much forbidden, everything that a tenant might want to change should be configurable.  E.g. if your solution doesn't cater for the dynamic addition of data fields in at least a few key areas, you will likely be inundated with requests for customisation.  It's one of the few cases where a little additional complexity upfront does actually pay off (let's say it goes against YAGNI, or at least, this level of configuration is almost a key requirement, so you are gonna need it).

Title: Supporting multitenancy

Body:
What are the typical challenges that arise when converting a single-tenant app into a multitenant app? Security and data isolation strike me as the most significant. What are some others?

I'm one of the architects for a fairly significant automation effort, and historically it's just been our company using it. We want to make it possible for others to use it as well. Every time we talk about "making it multitenant", the conversation revolves around keeping users with one tenant away from the data that another tenant owns, and making sure that users with one tenant can't (either intentionally or inadvertently) create impacts in another tenant's environments. What I'm wondering is whether security/data isolation are really the only major concerns here, or whether there are some other major concerns that we're just not thinking about.


答:
Today with the modern hardware and memory coming cheap, how much sense does it make to spend effort to analyze algoriths or data structure complexity?

it still makes sense today.

perhaps the best example i can give is that of cpus' growth in numbers (moreso than in frequency). choosing the right algorithms and structures are still important because you still have these physical maximums - a well written program can take a fraction of the cpu time or resources.

one obvious alternative to choosing the right algos/implementations is to use parallel execution (PE). although it is fine in some cases, PE is not always a good solution:

it can become very complex to write.

it can be very difficult to debug, test, and maintain.

while many problems are good candidates for PE, many do not extend into the domain well.

given the effort it takes to implement PE correctly, the right algos and structures are still important and much simpler and powerful solutions for many cases.

so, let's say you have hit that ceiling: would you prefer to retrofit that program for PE, or would you prefer to use (or verify that your program is using) the proper types/algos/implementations?

even if you choose PE, your program will (in the majority of cases) end up consuming more peak/total resources in its execution = =.

Wouldn't it be better instead, to focus on clean, maintainable code, readable code than on optimizations for complexity?

the two can coexist. (although some languages or runtimes can affect this adversely, such that there is less overlap -- the question is language-agnostic)

Title: Complexity vs maintainability in modern hardware

Body:
Today with the modern hardware and memory coming cheap, how much sense does it make to spend effort to analyze algoriths or data structure complexity?

Wouldn't it be better instead, to focus on clean, maintainable code, readable code than on optimizations for complexity?

Note:I not talking about embedded systems or systems with similar kinds of constraints.


答:
First, I question the premise of your question. Nobody deliberately performs "optimizations for complexity". Optimizations are performed to beat performance or resource constraints, and complexity is tolerated if it gets the job done. When done well, analysis of algorithms and data structures enables you to recognize redundant information, needless work, and allows you to write simpler, more easily maintainable code, which also happens to perform better.

Second, while more powerful hardware might allow you to solve yesterday's problem in more obvious and straightforward ways, most of us have to move on to newer and harder problems. Your word processor is finally fast enough? Great, now  make it work entirely in a scripting language inside a web browser. You want to do a deep indexing of the entire internet every month? Fine. Google could do that ten years ago. Unfortunately, if you want to keep up with Google, you have to increase the number of page you crawl by an order of magnitude every year. It took us ten years to sequence the first copy of the human genome, now we want to be able do it in a day.

As powerful as hardware is getting, the difficulty of the problems we want to tackle is growing even faster.


问:
Website development from scratch v/s web framework
Do people develop websites from scratch when there are no particular requirements or they just pick up an existing web framework like Drupal, Joomla, WordPress, etc.

The requirements are almost similar in most cases; if personal, it will be a blog or image gallery; if corporate, it will be information pages that can be updated dynamically along with news section.

And similarly, there are other requirements which can be fulfilled by WordPress, Joomla or Drupal.

So, Is it advisable to develop a website from scratch and why ?

Update:

to explain more as got commentt from @Raynos (thanks for comment and helping me clearify the question), the question is about:

Should web sites be developed and designed fully from scratch?

Should they be done by using framework like Spring, Zend, CakePHP?

Should they be done using CMS like Joomla, WordPress, Drupal (people in east are using these as frameworks)?

答:
or using existing frameworks like Drupal, Joomla, WordPress is the norm now?

Certainly not for me; I think if you have reasonably complex business logic it is advantageous to develop from scratch. Well, when I say scratch I am using Spring.


答:
Is it fair to say that these problems are solely the Managers and Project managers to solve...

In a perfect world, yes.

I've been at few projects where managers were good enough to handle these problems themselves, distracting programmers only with minimal mostly educational side-steps into "business area". Have to admit at these projects I felt myself most productive as programmer.

The world is far from perfect though. If the manager / company aren't top-notch, developers would better learn to handle / discuss business and cost-related stuff.

"If your management doesn't know how to manage a successful engineering project, or your marketing department doesn't know how to access the customers, or doesn't tell you what the customer wants, or if your lawyers don't handle your intellectual property correctly, or if the chief architect doesn't have the ability to create a consistent and simple architecture, then your work can be for naught, and you can spend years building things that never see the light of day."

(The Things I Wish I Learned in Engineering School)


问:
How do random number generators work?
I was just pondering about php rand() function, and thinking about how I could remake it, and I came up completely stupified.

How do random number generators work?

答:
There are many ways to attempt to emulate a "random" sequence of numbers. Your first stop should be to read about linear congruential generators, for sure. This is how most basic random number generators work, and I'd bet it's how PHP's rand() function works.

The more interesting next question to ponder is how does it seed itself? time? IP address? etc.

OwnerDisplayName: Korvin Szanto

Title: How do random number generators work?

OwnerDisplayName: Sean Owen


答:
They're usually not truly random, but are called pseudo-random because they generate a number sequence that appears random. This is done with some interesting mathematical formulas. One of the most common is the Linear Congruential Generator.

Pseudo-random numbers do have one useful property that true random numbers don't: if you use the same seed when you start you will get back an identical sequence. This can be very handy for testing.

Title: How do random number generators work?

Body:
I was just pondering about php rand() function, and thinking about how I could remake it, and I came up completely stupified.

How do random number generators work?

OwnerDisplayName: Mark Ransom


答:
Random Number Generators(RNGs) are really generating pseudorandom numbers, since it's impossible to actually generate a TRULY random number. The only really truly random things are acts of God, like lightning.

This wikipedia article might be able to help you out in the explanation: http://en.wikipedia.org/wiki/Random_number_generators

From what I understand, there are basically two parts of an RNG: the seed, and then the random number chosen from that seed. When you seed the RNG, you are giving it an equivalent to a starting point. That starting point then has a bunch of numbers that are "inside" of it that the program chooses from. In PHP, you can use srand() to "shuffle" the seeds, so you almost always get a different answer. You can then use rand(min, max) to go into the seed and choose a number between the min and the max, inclusive.

WARNING, POSSIBLE CHEESY ANALOGY AHEAD!

Think of each 'seed' as an ice chest, and then the random numbers as ice cubes. Let's say you have 1000 ice chests and each chest has 1000 ice cubes inside. At the county fair, they'll choose an ice chest to start using for drinks, and they can only use one ice cube. However, they only need ice cubes bigger than 1 cubic inch. So they'll choose a chest at random between those 1000 chests, and then they'll choose an ice cube inside that chest at random. If it works for the size they want, they use it. If it's not, they put it back in the chest with the others. If they want to make it a little more fun they change chests beforehand for total obliviousness, if you will!

As for how PHP actually physically chooses the seed and the random number, I don't have enough knowledge for that(which is probably what you were wondering the most about!). I wouldn't try and redo the rand() function; for most web based applications that you'll make, rand() should suffice for any random number you'll need.

Also check out linear congruential generators, this might be more of what you're looking for if you want the dirty details: http://en.wikipedia.org/wiki/Linear_congruential_generator

Hope this helps!

Title: How do random number generators work?

OwnerDisplayName: Mr. Starburst


答:
It really depends on the goals of the site, and what they're trying to present.

Yes, a lot of sites are using frameworks if they're making sites that sit well with that kind of thing, but (especially at the moment) a lot of companies want to do more with their pages (or think they're doing more) so will develop everything completely from scratch.

Which way is better really depends, again, on the goals of the site. Neither way is worse, exactly, but simply a decision the companies need to make on a per-site basis.

Title: Website development from scratch v/s web framework

Body:
Do people develop websites from scratch when there are no particular requirements or they just pick up an existing web framework like Drupal, Joomla, WordPress, etc.

The requirements are almost similar in most cases; if personal, it will be a blog or image gallery; if corporate, it will be information pages that can be updated dynamically along with news section.

And similarly, there are other requirements which can be fulfilled by WordPress, Joomla or Drupal.

So, Is it advisable to develop a website from scratch and why ?

Update:

to explain more as got commentt from @Raynos (thanks for comment and helping me clearify the question), the question is about:

Should web sites be developed and designed fully from scratch?

Should they be done by using framework like Spring, Zend, CakePHP?

Should they be done using CMS like Joomla, WordPress, Drupal (people in east are using these as frameworks)?


问:
Forgetting stuff I've done before and how do you fix this
I'm not sure if it's just me or if this is common in our field.

The past year has been a bit intense for me. I've been learning a few different technologies to get some tasks done and sometimes I've had to completely focus on that one new technology I'm learning.

What I noticed though when I go back to using everything together in the full project is that I forgot how to do things that I already knew how to do before I started focusing on learning that other new technology. Sometimes I find that I forget even simple things like the syntax for selecting a div in jquery, that I have to go back to old files to get a quick peek.

Sometimes I could be coding something that I recognize I did before in another project, but can't quite remember which project it was for, so I have to go through several projects and look through the code to try and remember where I did that.

What ways have you invented to prevent yourself from forgetting things you've done before, or to easily access code you've written in the past?

答:
I keep a work log. It's just a plain text file. Every day I make notes on stuff I'm working on: what I did, what sort of problems I encountered, how I solved them, who I talked to, what we discussed, what decisions we made, relevant files/classes/webpages, etc.

So any time I have a problem and I have a deja-vu feeling about it I just search in my work log and in most cases I can quickly find what I'm looking for.

Work log also makes it easier to keep track of how you spend your time, write weekly/monthly reports, prepare for performance reviews.


答:
Handle tests like you do it with source code.

Version control, checkpoint releases, issue tracking, "feature ownership", planning and efforts estimation etc etc. Been there done that - I think this is the most efficient way to deal with problems like you describe.

Title: How to Avoid Fragile Unit Tests?

Body:
We have written close to 3,000 tests -- data has been hard coded, very little reuse of code. This methodology has began to bite us. As the system changes we find ourselves spending more time fixing broken tests. We have unit, integration and functional tests.

What I'm looking for is a definitive way to write manageable and maintainable tests.

Frameworks

FakeItEasy

nUnit

AutoFixture


问:
"Gödel, Escher, Bach" still valid today?
I have just completed a course on computability and logic which was an interesting course. The lecturer recommend a few books on his slides, which include "Gödel, Escher, Bach". I can see the book is quite famous, and looks very interesting. But I have a few questions to ask regarding its content.

Is the content still valid today? I guess most theoretical stuff doesn't change over night, but are there any major points which no longer hold today that I should be aware of?

I assume we actually HAVE made some progress in the last 30 years or so. Can any of you recommend a book on the subject which includes this progress (logic, AI, computability)?

Another question: Do I have to know about Escher and Bach?

答: It is an interesting read (and a difficult one at times), but it won't make you a better programmer/developer/etc. As donroby said, it is still valid because it's about math and logic (and a lot more).</p>


答:
From a user's perspective what matters is reactivity. Having a notebook or a tablet being ready as soon as it is switched on is very important. This is not achieved only with huge CPU frequencies and tiny memory latencies.

If by complecity you mean also algorithmic complexity, the important point is scalability. Hardware performance is a limited solution when your problem is O(exp N).


问:
How do I convince my fellow devs to WANT to add comments to source code commits?
I know that Subversion (what we're using at work) can be configured to require comments on commits, however I'm not in a position of power to simply turn this on.  I know that my reason for commenting my commits is because it is useful, if only as a memory-jogger, to quickly understand the reason behind the commit.  However, this doesn't seem to be enough to combat the two responses I always get:

It takes too long and I just want to get my changes into the repo.

It's easy enough to just look at the diffs.

I even show them the value of simply putting in a JIRA issue ID and how it automatically gets tied to the issue, but still no dice with them.

Worst of all, the person who can make the call is in the same camp: doesn't want to bother and is fine with looking at diffs.

I know it's the right thing to do, but how can I make them see the light?  Even if I can't convince my fellow devs, how can I convince management that it's the right thing to do for the business?

答:
Ask and get your fellow developers to do some merges and to look up history and compare a few files from the history.

Chances are that they will ask you to put comments the next day onwards.


答:
I often forget things after not using them for a while - syntax, keywords, techniques, etc. To help, I read this book by Dominic O'Brein (8 times World Memory Champion). There are some techniques and tips from that book which I use to help me remember things. It's not always easy to apply these to programming, but with some creativity, you can begin to link things together to help you recall them better. It's not perfect, but it might help over time.

Also, have a read of this article. It's an interesting read that gave me some ideas on how to improve my recall for my development work.

By fa the most useful tool for me has been mind maps. I use them for allsorts:

Documenting test cases.

Visually describing the architecture
of a project I'm working on.

Notes and links to websites on a
technology I'm interested in.

Mind maps can be used for many different scenarios. Certainly has made a difference for me when learning new things.

Cheers.
Jas.

Title: Forgetting stuff I've done before and how do you fix this

Body:
I'm not sure if it's just me or if this is common in our field.

The past year has been a bit intense for me. I've been learning a few different technologies to get some tasks done and sometimes I've had to completely focus on that one new technology I'm learning.

What I noticed though when I go back to using everything together in the full project is that I forgot how to do things that I already knew how to do before I started focusing on learning that other new technology. Sometimes I find that I forget even simple things like the syntax for selecting a div in jquery, that I have to go back to old files to get a quick peek.

Sometimes I could be coding something that I recognize I did before in another project, but can't quite remember which project it was for, so I have to go through several projects and look through the code to try and remember where I did that.

What ways have you invented to prevent yourself from forgetting things you've done before, or to easily access code you've written in the past?


问:
Scrum meeting - dealing with the last question
In the 5/15 minute scrum meeting the 3 questions are asked.

For the last question
"what impediments are getting in your way"

If a dev has problems - the xyz is going to have problems, this is likely going to draw the meeting out past 15 mins and could go into a hour long discussion.

Is it the scrum masters job to help this user, is there something to stop this from going on more than 15 mins.

Thoughts?

答:
Remind everyone that the daily scrum meeting needs to be short, and ask them to briefly list their impediments during the meeting.

Then, if any impediments need a lot of discussion, schedule a meeting with those involved immediately after the scrum to discuss the details. Everyone else can get on with their day while you work out how to remove the impediment.

OwnerDisplayName: Wizzard

OwnerDisplayName: GraemeF


答: In our dailies, if someone says that he has a problem that may require a long time to investigate\ solve, the scrum master just refers to the relevant person (who can help), from\ outside of the scrum team, and suggests to close the issue out of the meeting. Dailies, as the scrum methodology, are intended for the WHOLE team. A specific problem which can't contribute to others, should be managed out of the scrum meetings.</p>

Title: Scrum meeting - dealing with the last question

Body:
In the 5/15 minute scrum meeting the 3 questions are asked.

For the last question
"what impediments are getting in your way"

If a dev has problems - the xyz is going to have problems, this is likely going to draw the meeting out past 15 mins and could go into a hour long discussion.

Is it the scrum masters job to help this user, is there something to stop this from going on more than 15 mins.

Thoughts?


答:
If the impediments can be resolved quickly (in a couple of min) - deal with it at the stand-up meeting, if it requires more time to resolve - park it and deal with it after the meeting in the order to priority. </p>

<p>Stand-ups should be time-boxed and kept under 15min in order to be effective for the whole scrum team. When the team gets into routine of ~15 min daily standups, then having a longer one once in a while is not a big deal... </p>

Body:
If the impediments can be resolved quickly (in a couple of min) - deal with it at the stand-up meeting, if it requires more time to resolve - park it and deal with it after the meeting in the order to priority.

Stand-ups should be time-boxed and kept under 15min in order to be effective for the whole scrum team. When the team gets into routine of ~15 min daily standups, then having a longer one once in a while is not a big deal...

OwnerDisplayName: ratkok


答:
Seems to me like your unit testing works like a charm.  It is a good thing that it is so fragile to changes, since that's sort of the whole point.  Small changes in code break tests so that you can eliminate the possibility of error throughout your program.

However, keep in mind that you only truly need to be testing for conditions which would make your method fail or give unexpected results.  This would keep your unit testing more prone to "break" if there is a genuine problem rather than trivial things.

Though it seems to me that you're heavily redesigning the program.  In such instances, do whatever you need to and remove the old tests and replace them with new ones afterwards.  Repairing unit tests is only worthwhile if you're not fixing due to radical changes in your program.  Otherwise you may find that you're dedicating too much time towards rewriting tests to be applicable in your newly written section of program code.

Title: How to Avoid Fragile Unit Tests?


问:
When, if ever, can code standards be ignored?
My company has decided to use stored procedures for everything dealing with the database (because they didn't know of any other way besides raw SQL), and as the saying goes "When in Rome..." so I try to follow.  Recently I had to add a hack fix that required grabbing a database value, and since it was a single value from a single table I wrote it as inline SQL (parameterized, of course) since there didn't seem to be a need for a stored procedure for one trivial line of code used in a single part of the application as a kludge.

Of course, I've now been told to fix it and only ever use Stored Procs for anything related to the database.  This feels just a bit too much like blindly following dogma instead of using common sense.  Don't get me wrong, I understand the purpose of having coding standards but I am also a proponent of ignoring standards when they don't make sense, not just blindly following them as though they were Gospel.

答: It is always OK to violate coding standards; however, when you do so you should always write a comment mentioning that the violation was deliberate, and provide some sort of justification.</p>


答:
What you describe may actually not be such a bad thing, but a pointer to deeper problems your tests discover

As the system changes we find ourselves spending more time fixing broken tests. We have unit, integration and functional tests.

If you could change your code, and your tests would not break, that would be suspicious to me. The difference between a legitimate change and a bug is only the fact that it is requested, an what is requested is (TDD assumed) defined by your tests.

data has been hard coded.

Hard coded data in tests is imho a good thing. Tests work as falsifications, not as proofs. If there is too much calculation, your tests may be tautologies. For example:

```<code>assert sum([1,2,3]) == 6
assert sum([1,2,3]) == 1 + 2 + 3
assert sum([1,2,3]) == reduce(operator.add, [1,2,3])
</code>```

The higher the abstraction, the closer you get to the algorithm, and by that, closer to comparing the acutal implementation to itself.

very little reuse of code

The best reuse of code in tests is imho 'Checks', as in jUnits assertThat, because they keep the tests simple.
Besides that, if the tests can be refactored to share code, the actual code tested likely can be too, thus reducing the tests to the ones testing the refactored base.

Title: How to Avoid Fragile Unit Tests?

Body:
What you describe may actually not be such a bad thing, but a pointer to deeper problems your tests discover

As the system changes we find ourselves spending more time fixing broken tests. We have unit, integration and functional tests.

If you could change your code, and your tests would not break, that would be suspicious to me. The difference between a legitimate change and a bug is only the fact that it is requested, an what is requested is (TDD assumed) defined by your tests.

data has been hard coded.

Hard coded data in tests is imho a good thing. Tests work as falsifications, not as proofs. If there is too much calculation, your tests may be tautologies. For example:

assert sum([1,2,3]) == 6
assert sum([1,2,3]) == 1 + 2 + 3
assert sum([1,2,3]) == reduce(operator.add, [1,2,3])

The higher the abstraction, the closer you get to the algorithm, and by that, closer to comparing the acutal implementation to itself.

very little reuse of code

The best reuse of code in tests is imho 'Checks', as in jUnits assertThat, because they keep the tests simple.
Besides that, if the tests can be refactored to share code, the actual code tested likely can be too, thus reducing the tests to the ones testing the refactored base.


答:
If your audience doesn't know Android but are interested in Android development and want to take the first steps I'd go with:

A bit on Android history

Briefly introduction to: Activities, Services, Broadcast receivers, Content providers

Good UI practices

Social media integration

You could use a simple Twitter or whatever sample client as an example to be used throughout your presentation.

--

If your presentation is aimed at making the students be interested on Android, I'd go a totally different way:

Brief history of Android

Social media integration

OpenGL

Using hardware features (camera, audio, accelerometer, multitouch)

Native Development

I'd go for a showcase like presentation style with snippets of code here and there to show that their knowledge of Java is still applies and the kind of cool things you can do with the platform.


问:
Difference between complexity and performance guarantee
I'm a bit confused with the performance guarantee and complexity of selection sort.

I checked through internet and the complexity of selection sort is O(n^2). This O(n^2) is in terms of time complexity, am i right?

So how about performance guarantee? Is the performance guarantee in my case measured in terms of swapping or in time complexity as well? If the performance guarantee is in terms of swapping, so best case of swapping is zero swaps (the array is already sorted) and the worst case of swapping is n-1 step? The performance guarantee is then equal to (n-1)/0=undefined, am I correct?

Please correct me if im wrong...or is the performance guarantee is in terms of running time? Then performance guarantee will be (n-1)/(n-1) = 1?

Can someone please clear my doubts?

答:
"performance guarantee" is not a term typically used in analyzing algorithms.

Time complexity is measured in terms of whatever you want. You're stumbled on a dirty secret of CS - Big-O notation is often used rather sloppily without specifying what exactly increases with the input size in that manner. It's generally the number of some primitive operation that's assumed to dominate others in the implementation, and assumed to take constant time itself. Both of these assumptions are often not universally true. For example, for sorting algorithms time complexity is usually based on the number of comparisons. But comparing numbers is actually not a constant time operation itself if the numbers get realy big


答:
I'm a bit confused with the performance guarantee and complexity of
  selection sort.

I checked through internet and the complexity of selection sort is
  O(n^2). This O(n^2) is in terms of time complexity, am i right?

Right. It's the total number of constant factor * constant time operations dependent on the input size (this is still simplified).

So how about performance guarantee? Is the performance guarantee in my
  case measured in terms of swapping or in time complexity as well? If
  the performance guarantee is in terms of swapping, so best case of
  swapping is zero swaps (the array is already sorted) and the worst
  case of swapping is n-1 step? The performance guarantee is then equal
  to (n-1)/0=undefined, am I correct?

I don't know what you consider a performance guarantee, but the big O notation guarantees us, that an O(n^2) algorithm won't run slower than this bound indicates. A performance guarantee should not only be given in terms of swapping, you have to look at the whole algorithm. But you can explicitly ask for a performance guarantee for swapping in a specific algorithm, if that is of interest to you (for whatever reason). For selection sort this is Theta(n) as you always swap n-1 times with classic selection sort, the algorithm somtimes swaps an item with itself (which is still not a zero time operation, because I doubt the compiler can optimize it away in every case).

Please correct me if im wrong...or is the performance guarantee is in
  terms of running time? Then performance guarantee will be (n-1)/(n-1)
  = 1?

In my opinion, performance guarantee is a measurement for the grade of solutions of heuristic algorithms. You simply compare the approximated solution to the known optimal solution and calculate how close it really is. I am not completely sure about this, though.

If I had to apply this to sort of thinking to sorting algorithms that swap, then I'd argue that the best case for swapping is always O(n). And as selection sort swaps Theta(n) times the "performance guarantee for swapping" is probably 1. When I want to guarantee something, then I am usually concerned about the worst kinds of behaviour. So in the worst case an optimal solutions swaps n-1 times and so does selection sort. It'd be pointless to take the best case of an optimal solution.

Title: Difference between complexity and performance guarantee

Body:
I'm a bit confused with the performance guarantee and complexity of selection sort.

I checked through internet and the complexity of selection sort is O(n^2). This O(n^2) is in terms of time complexity, am i right?

So how about performance guarantee? Is the performance guarantee in my case measured in terms of swapping or in time complexity as well? If the performance guarantee is in terms of swapping, so best case of swapping is zero swaps (the array is already sorted) and the worst case of swapping is n-1 step? The performance guarantee is then equal to (n-1)/0=undefined, am I correct?

Please correct me if im wrong...or is the performance guarantee is in terms of running time? Then performance guarantee will be (n-1)/(n-1) = 1?

Can someone please clear my doubts?


答:
It looks like you can use a BSD license as you are just using the GPLed system and not modifying the source of that system.

Why you would want to use the BSD license at all is another matter. The BSD license is equivalent to no license at all. If you distribute your code under BSD, and, it looks like a good product I can, under the terms of the BSD license, take your code, shrink wrap it and sell it as my own without consulting you or giving you any share of the profits. I can even make some minor changes to the code and sell it under a proprietary license.

If you don't believe me take a look at the license for MAC/OS. Considering that 90% of the code is BSD Unix their are some pretty Draconian terms in there.

Title: Do I need to license my code as GPLv2 if I only read/write to a database and pipe?

Body:
I'm writing an API for an open source network monitoring system which is licensed under the GPLv2. I also intend to open source this API but would like to license it under the BSD License.

I don't re-use or link to any of the code in this system and I don't use any header files.

I will not be re-distributing any part of the network monitoring code.

Part of my application will install into the network monitoring installation folders, but not replace, remove or modify any of its files

My hook into the system is via:

existing MySQL databases belonging to the service, my API reads and writes to these databases directly. My concern here would be that whilst I am not copying their SQL statements, there are some complex operations. I've found that in a couple of cases I've arrived at SQL statements or sequences of work that aren't too dissimilar to theirs, it's hard not to.

I talk to a pipe to issue various commands and submit data directly into the checking engine. This pipe is documented by the author as an official mechanism to communicate with the checking engine. The command pipe uses single line strings to issue commands, the pipe does not return any data, it's "fire and forget".

There are a number of HTTP CGI scripts in the system from which I can scrape status information. I may use these in a future release.

Is this considered "arms length" enough for me to license my code under a different license? i.e.

http://www.gnu.org/licenses/gpl-faq.html#MereAggregation

However, in many cases you can distribute the GPL-covered software
  alongside your proprietary system. To do this validly, you must make
  sure that the free and non-free programs communicate at arms length,
  that they are not combined in a way that would make them effectively a
  single program.

Would reading and writing rows to a database be considered "exchanging complex internal data structures"?

http://www.gnu.org/licenses/gpl-faq.html#MereAggregation

By contrast, pipes, sockets and command-line arguments are
  communication mechanisms normally used between two separate programs.
  So when they are used for communication, the modules normally are
  separate programs. But if the semantics of the communication are
  intimate enough, exchanging complex internal data structures, that too
  could be a basis to consider the two parts as combined into a larger
  program.


答:
The algorithm complexity is in terms of whatever operation has the highest complexity. So, for example, if a sort requires O(n^2) comparisons and O(n log n) exchanges, the algorithm overall is O(n^2).

The rationale for this is simple -- big-O notation is about what happens as 'n' goes to infinity. As 'n' goes to infinity, whatever operation has the worst order will eventually dominate the execution time.

So is an algorithm requires O(n^2) of any sub-operation inside it, it's overall complexity cannot possibly be less than O(n^2).


答:
Don't think of them as "broken unit tests", because they are not.

They are specifications, which your program no longer supports.

Don't think of it as "fixing the tests", but as "defining new requirements".

The tests should specify your application first, not the other way around.

You can't say you have a working implementation until you know it works. You can't say it works until you test it.

A few other notes that might guide you:

The tests and the classes under test should be short and simple. Each test should only check for a cohesive piece of functionality. That is, it doesn't care about things which other tests already check.

The tests, and your objects, should be loosely coupled, in a way that if you change an object, you're only changing its dependency graph downwards, and other objects which use that object are not affected by it.

You might be creating and testing the wrong stuff. Are your objects built for easy interfacing, or easy implementation? If it's the latter case, you're going to find yourself changing a lot of code that uses the old implementation's interface.

In the best case, strictly adhere to the Single Responsibility principle. In the worse case, adhere to the Interface Segregation principle. See SOLID Principles.

Title: How to Avoid Fragile Unit Tests?


问:
Good Design and how to achieve Low Coupling?
what do you think about this design?

In this image i have reported the dependencies between packages. I would like to reduce the coupling between them, but do you have any idea about how to do this? I think it is impossible to reduce it more than this. The Preferences package is responsible to manage program options, Persistence instead to save them in storage. Applogic and model are in domain layer.

Thanks in advance!

答:
From my point of view, the first thing is to apply an appropriate packaging strategy.
This one can help really a lot to design/organize your classes/packages and solve dependencies between them. One rule: only Top to Bottom dependencies are allowed .

Around packages, having a modular approach (even if you don't use OSGI) is the best thing you can do.

Firstly: Packaging Strategy

Package by feature, not layer

Secondly: Modularity

Fun With Modules

[...] Tight coupling between modules is a bad idea, and the worst form of
  coupling is cyclic dependencies between modules. Fortunately, there
  are a few techniques we can use to break the cycle [...]

Applied Modularity: part 1, part 2, part 3, part 4

This article explains how to "apply modularity" on a concrete and tight coupled Billing app.


答:
If you want to get a prototype fast, you use a CMS (drupal, joomla etc.).

If you want to complete a project for a client you use a framework so you don't have to reinvent the wheel. Be it Django, Ror, symfony, spring etc.

For a personal project which are usually made to learn things, you can start from scratch. It's useful to try doing some things yourself to appreciate the power of those frameworks.


答:
The requirements are almost similar in most cases

Interactive web site or web application development is mostly a solved problem and this is evident in the powerful tools that exist today to support rapid development that didn't exist even 10 years ago.

The similarity in requirements usually fall under the typical boilerplate concerns that most web applications carry (Eg. Authentication, Authorization, Instrumentation, Data Access/ORM, Transaction Management, etc...).

We have today combinations of AOP (Aspect Oriented Programming) with DI (Dependency Injection) to help turn cross-cutting concerns from codes into configurations.  See Spring for a practical implementation of such frameworks.

So when you talk about developing a website "from scratch" then you need to be more specific about that.  I can build a website from scratch from tested and verified components or I could reinvent the wheel and design and build each one of my components individually which would be a rookie mistake.  If I wanted to build a car, I would find and buy components like tires and radiators and assemble a car, I wouldn't start forming tires from moulds or forging steel.  Those problems were solved long ago.


答:
Just a suggestion, you can't cover everything. You don't have enough time, so instead of trying to talk a little bit about a lot of things, spend your time on one facet that you think is most compelling. </p>

<p>I have found that talks that did that were often the most compelling. </p>

Body:
Just a suggestion, you can't cover everything. You don't have enough time, so instead of trying to talk a little bit about a lot of things, spend your time on one facet that you think is most compelling.

I have found that talks that did that were often the most compelling.


问:
How to Properly Google for C
The problem with trying to use Google to find tutorials or answers for the C programming language is that C is not an expressive enough name to narrow down the searches. Even coupled with keywords like "Programming" and/or "Language" yields results mostly for C++, C#, and Objective-C.

Is there a way to more effectively search for specific C resources using Google?

答:
There is a google-page called http://codesearch.google.com/ where you can specify a language like

searching for printf in C means

```<code>printf lang:^c$
</code>```

Title: How to Properly Google for C

Body:
There is a google-page called http://codesearch.google.com/ where you can specify a language like

searching for printf in C means

printf lang:^c$


问:
Secure cloud based code storage and syncing across multiple computers
I've been thinking recently about how and where I keep my code - I work across multiple locations, with at least three different computers and I'm considering how I manage my code across these machines.

I've got a dropbox account, which I use. For non sensitive files this is fine, and I do keep some sensitive files in there, but in a TrueCrypt file - this won't work large scale as the entire TrueCrypt file would need to be uploaded for any change.  I don't feel safe putting my, or my employers, code on DropBox because of several security issues and news that they can access everyones' files.

I have a github account where I store my code (open and closed source), but I don't want to have to always push up to GitHub, also I work a lot on the train so I can't push as I don't have a stable data connection and chances are that I'll forget to push or grab data at some point and then I'll be stuck!

So - with that in mind, I'd like a discussion about storing code in the cloud:

Is keeping source code in the cloud dangerous?

I understand the implications of keeping employers code in the cloud, but are there alternatives, given that a good number of VPN/RDC solutions that I've used are slow to the point of unusable? (this may be a point against my/my employers network speeds rather than the actual programs - but it's a impediment)

Is there a good cloud based service with good encryption, good uptime, diff, auto
sync?

Is there one aimed solely at developers?  If not, does anyone want to start one with me? (joking but at the same time, it could be a good business venture - drop me a line if interested)

What do you use?  Does it work? how would you change it?

答:
First of all, cloud computing comes at a cost and it's not that cheap as of now. There are numerous provider of cloud computing service. One that comes to my mind is Amazon.

As far as the security is concerned, they are pretty secure until the Service provider isn't the culprit. Working with them isn't that simple, you will definitely need to go through a learning curve to make better use of them


答:
Should web sites be developed and designed from scratch fully?

No.

Should they be done by using framework like spring,zend, cakephp?

Yes.

Should they be done using CMS like joomla,wordpress,drupal?

Yes.

Here's the rule.

Write Less Code.  Get things done sooner.

Create value as quickly as possible, writing as little code as possible.


问:
What is the standard /an acceptable period of time to support a particular version of software?
Let's say version 2.4.x of Software Package X was released 2 years ago, and was sold up until about 6 months ago. Version 3.1.0 is now out (which fixes a lot of the issues with version 2.4.x), and is the only version actively being sold.

In this case, the software is being sold to large businesses, not individuals, so the maintenance effort required is substantial.

For how long should the company offer support for version 2.4.x?

答:
When you sell a software, the support document specifies up to when the company commits to provide support for the system. In case there is no written course for the support in the manual or document supplied with the software, then the provider is not liable to provide support at any time. </p>

<p>It's just out of the good leap that companies provide support even after the said period. In your case, i think you can provide the support for next six month and then kill that. In between try to make clients know of your move and ask to upgrade before withdrawing support after six months. </p>

Body:
When you sell a software, the support document specifies up to when the company commits to provide support for the system. In case there is no written course for the support in the manual or document supplied with the software, then the provider is not liable to provide support at any time.

It's just out of the good leap that companies provide support even after the said period. In your case, i think you can provide the support for next six month and then kill that. In between try to make clients know of your move and ask to upgrade before withdrawing support after six months.


答:
One solution I can think of (especially if I was in your position) is to just set up a private server somewhere and completely edit / save / test your code there via RDP to a VM or something. This way, even if your connection is spotty, you don't risk anything happening to the code. But this might be overkill and unnecessary.

Also, not a cloud solution per se, but a somewhat viable alternative if you plan on copious amounts of off-site programming.

Title: Secure cloud based code storage and syncing across multiple computers

Body:
I've been thinking recently about how and where I keep my code - I work across multiple locations, with at least three different computers and I'm considering how I manage my code across these machines.

I've got a dropbox account, which I use. For non sensitive files this is fine, and I do keep some sensitive files in there, but in a TrueCrypt file - this won't work large scale as the entire TrueCrypt file would need to be uploaded for any change.  I don't feel safe putting my, or my employers, code on DropBox because of several security issues and news that they can access everyones' files.

I have a github account where I store my code (open and closed source), but I don't want to have to always push up to GitHub, also I work a lot on the train so I can't push as I don't have a stable data connection and chances are that I'll forget to push or grab data at some point and then I'll be stuck!

So - with that in mind, I'd like a discussion about storing code in the cloud:

Is keeping source code in the cloud dangerous?

I understand the implications of keeping employers code in the cloud, but are there alternatives, given that a good number of VPN/RDC solutions that I've used are slow to the point of unusable? (this may be a point against my/my employers network speeds rather than the actual programs - but it's a impediment)

Is there a good cloud based service with good encryption, good uptime, diff, auto
sync?

Is there one aimed solely at developers?  If not, does anyone want to start one with me? (joking but at the same time, it could be a good business venture - drop me a line if interested)

What do you use?  Does it work? how would you change it?


答:
Given your statement that "I work across multiple locations, with at least three different computers", I'm going to assume that DVCS is pretty much a requirement here as you don't say it explicitly.  At least it is for me as I'm in the same boat.  I know this may seem like a "duh!" statement, but I wanted to get that established first.

So to your questions:

This is really going to be up to you, or at least I don't have any hard facts to persuade you to either choose or avoid a specific service.  You say that you use GitHub.  Although I do not use Git (I use Mercurial), I would call that a safe bet from what I read about the service.  (Sorry, I know this answer may not give you much to go on.)

I use BitBucket (Mercurial) and can say that it offers what you want, except for auto sync.  Wouldn't auto sync be a function of your client though?  Unless you write your own DVCS (at which you admittedly hint), I don't think you'll find that solution as a function of the cloud-based service you seek.

As I said in #2, I use BitBucket (as well as a secondary machine at home which I also push to as a backup).  It works wonderfully and, given my current needs I wouldn't change a thing.


答:
The cloud is an abstracted group of shared resources, with the benefit that you can quickly and easily scale. You do not need rapid scaling just for code storage, so "cloud storage" is not the right solution for your problem. You are just looking for remotely accessible storage, which you're already using.

It would be useful to define what you actually mean by "cloud-based storage", since there are many definitions:

What is "The Cloud"? What do I say when people ask if my web service is "on the cloud"?


问:
Controller vs Model: Where do I put the processing of user input?
I'm new to MVC and I'm not using a framework (and I'm not going to).

I'm designing my new web application using MVC.

I have the user input received in Controller. Suppose I have form data and an action to do with it, which can be "insert", "delete" or "update".

Must I have process that action in Controller or in the Model? That is: must I do:

```<code># Controller
if (action == "insert") Model.insert(data)
</code>```

or

```<code># Controller
Model.process(data, action)

# Model.process
if (action == "insert") self.insert(data)
</code>```

(language-agnostic example).

What is the "MVC way" to do it?

答:
You should do it in the controller, definitely.

The model should only represent the current state of your application. Any control of the applications behavior should be handled by the controller, that's it's purpose.


问:
Is code like this a "train wreck" (in violation of Law of Demeter)?
Browsing through some code I've written, I came across the following construct which got me thinking. At a first glance, it seems clean enough. Yes, in the actual code the getLocation() method has a slightly more specific name which better describes exactly which location it gets.

```<code>service.setLocation(this.configuration.getLocation().toString());
</code>```

In this case, service is an instance variable of a known type, declared within the method. this.configuration comes from being passed in to the class constructor, and is an instance of a class implementing a specific interface (which mandates a public getLocation() method). Hence, the return type of the expression this.configuration.getLocation() is known; specifically in this case, it is a java.net.URL, whereas service.setLocation() wants a String. Since the two types String and URL are not directly compatible, some sort of conversion is required to fit the square peg in the round hole.

However, according to the Law of Demeter as cited in Clean Code, a method f in class C should only call methods on C, objects created by or passed as arguments to f, and objects held in instance variables of C. Anything beyond that (the final toString() in my particular case above, unless you consider a temporary object created as a result of the method invocation itself, in which case the whole Law seems to be moot) is disallowed.

Is there a valid reasoning why a call like the above, given the constraints listed, should be discouraged or even disallowed? Or am I just being overly nitpicky?

If I were to implement a method URLToString() which simply calls toString() on a URL object (such as that returned by getLocation()) passed to it as a parameter, and returns the result, I could wrap the getLocation() call in it to achieve exactly the same result; effectively, I would just move the conversion one step outward. Would that somehow make it acceptable? (It seems to me, intuitively, that it should not make any difference either way, since all that does is move things around a little. However, going by the letter of the Law of Demeter as cited, it would be acceptable, since I would then be operating directly on a parameter to a function.)

Would it make any difference if this was about something slightly more exotic than calling toString() on a standard type?

When answering, do keep in mind that altering the behavior or API of the type that the service variable is of is not practical. Also, for the sake of argument, let's say that altering the return type of getLocation() is also impractical.

答:
Demeter's law is a design guideline, not a law to be followed religiously.

If you feel that your classes are enough decoupled than there's nothing wrong with the line this.configuration.getLocation() especially if, as you say, it is impractical to change other parts of the API.

I'm pretty sure that the client will be perfectly happy even if you make the Demeter's Law to pieces, as long as you deliver what he wants and on time. Which is not an excuse to make bad software, but a reminder to be pragmatic when developing software.


答:
I will try to explain by definitions :-

Models contain or represent the data that users work with. These can be
simple view models, which just represent data being transferred between views
and controllers; or they can be domain models, which contain the data in a
business domain as well as the operations, transformations, and rules for
manipulating that data.

Views are used to render some part of the model as a UI.

Controllers process incoming requests, perform operations on the model,
and select views to render to the user.

So, you should do this in Controller.

Title: Controller vs Model: Where do I put the processing of user input?

Body:
I'm new to MVC and I'm not using a framework (and I'm not going to).

I'm designing my new web application using MVC.

I have the user input received in Controller. Suppose I have form data and an action to do with it, which can be "insert", "delete" or "update".

Must I have process that action in Controller or in the Model? That is: must I do:

```<code># Controller
if (action == "insert") Model.insert(data)
</code>```

or

```<code># Controller
Model.process(data, action)

# Model.process
if (action == "insert") self.insert(data)
</code>```

(language-agnostic example).

What is the "MVC way" to do it?


答:
The controller is just the middle man between the view and the model.  The example you provided is a poor example of "user input".  The example is of CRUD operations required to perform the logic requested by the user from the view.

In this very simple case, the View needs to perform a database action, CRUD.  So, in this simple case the controller simply passes the duty to the Model which handles the DB operations.

User input comes into play when you ask "what am I creating?".  The user provides information that may need to run through a BL and data input verification process.  This is when you need other layers to assist MVC.


答:
My recommendation, which I am planning on doing myself, Is setting up a subversion repository on a FREE TIER at amazon or azure and working from there.

Once the free tier is over, I can just upgrade to a small instance and remember, the instance does not need to be up all the time, only when I am either checking in or checking out the code. This will keep costs down, and keep me in complete control of my repository and my security.

For work stuff I prefer doing it like this rather than using github or the likes. You can even set up a VPN to access your repository. Its actually pretty cool the choices it gives you.


答:
Are you asking for Pseudorandom or Random? Others answered about pseudorandom, let me talk about Random.

There were (are?) actual hardware-based Random Number Generators in sale. They were based on a chip with a small radio measuring white noise of deep space radiation, or a small radioactive sample and measuring periods between its decay. The problem with them was the bandwidth - the amount of entropy they could generate wasn't very high so they were used for seeds of pseudorandom algorithms. They were used in bank systems, high-security and the likes.

OTOH, if you meet any embedded systems developer, they will laugh at these. For common purposes in programming a microcontroller, reading low 4 bits of any 16-bit Analog-Digital Converter woth a floating (unconnected) pin will produce a perfectly good random noise, at more than sufficient bandwidth (the shorter the polling period the more "noisy" the readout), and easier than writing actual RNG routine. And considering ADCs are commonly found implemented in silicon of microcontrollers, commonly implemented, and often implemented with 8 channels from which you need maybe 5 for your application, it's practically free.

And even if you don't have an ADC, couple of elements connected to a digital GPIO pin will produce a pretty good noise. In embedded, noise is ever-present (and constantly fought), and so obtaining some true randomness is very easy.

Title: How do random number generators work?


问:
A testing environment for JavaScript other than browser?
When I want to test something in JavaScript, I open up a new browser window (mostly Firefox) and start writing code in the provided console (mostly Firebug).

However, this tends to be really tedious and slow. Is there an environment, like an IDE with self-execution capability for example, in which we can test JavaScript?

Guide: I'm looking for something like jsfiddle, but not in the browser, and not online. I'd like to have an execution environment which is both off-line, and is not a browser.

All I'm asking is to have something like the Firebug Console as a separate applications (preferably Windows application) which can be opened by double-clicking, and in which, you can write JavaScript code and hit execute. That's all.

In simpler terms, all I want is Firebug's console, without Firefox. Do we have such a thing on the market?

答: When it comes to core-javascript testing you can consider about Rhino, a Mozilla project. It's much lighter than nodejs because Rhino is an implementation of core language only. But Rhino won't come handy for HTML manipulation as Firebug.</p>


答:
Your first example is the right one.

```<code>if (action == "insert") Model.insert(data)
</code>```

But you should try to think of it this way:
You have an application, and any interface to it (UI, tests, CLI, etc) is simply that - just an interface.

Interfaces to an application tell it what to do, and get data back from it. That's all they do.

So your interface in this example is the controller. The fact that the controller takes the application's output and renders it inside an HTML template is allegedly "coincidental".

On another note, I know you said you're not going to use any existing framework, but you should at least keep the following in mind:

Learning how to use a framework is not always smooth and easy, but it's going to take you less time than trying to implement the set of features yourself.

You might not be aware yet of all the pitfalls you're going to encounter. These are all covered, in one way or another, in big MVC frameworks.

You might not (and probably don't) know all of the current or future requirements for your application. But frameworks already let you develop something simple today and make it easy to add new features tomorrow (because they're built-in, and built so they'll be easily integrated at any point).

I saw your "language-agnostic" examples were pretty much Python. If you like the language, you should know that Django is one of the biggest and most documented MVC frameworks (in general, not just in Python).

Body:
Your first example is the right one.

if (action == "insert") Model.insert(data)

But you should try to think of it this way:
You have an application, and any interface to it (UI, tests, CLI, etc) is simply that - just an interface.

Interfaces to an application tell it what to do, and get data back from it. That's all they do.

So your interface in this example is the controller. The fact that the controller takes the application's output and renders it inside an HTML template is allegedly "coincidental".

On another note, I know you said you're not going to use any existing framework, but you should at least keep the following in mind:

Learning how to use a framework is not always smooth and easy, but it's going to take you less time than trying to implement the set of features yourself.

You might not be aware yet of all the pitfalls you're going to encounter. These are all covered, in one way or another, in big MVC frameworks.

You might not (and probably don't) know all of the current or future requirements for your application. But frameworks already let you develop something simple today and make it easy to add new features tomorrow (because they're built-in, and built so they'll be easily integrated at any point).

I saw your "language-agnostic" examples were pretty much Python. If you like the language, you should know that Django is one of the biggest and most documented MVC frameworks (in general, not just in Python).


问:
Should there be separate database schemas for each developer or should there be just one that all developers share?
During development, should developers each have their own copy of the database to work on ? Or should there be a common shared development database ?

The former will give developers more flexibility. For ex., they can run their own regression tests during development and unit testing without worrying about corrupting the data for other developers. However, it is difficult to maintain for database adminstrators.

The latter is easier to maintain (less integration overheads as everyone's working on the same schema) but requires more effort to ensure data sanctity (developers should be careful and not make changes that will impact others).

答:
I think developer's having separate databases causes more problems than it avoids. First, our databases are large, there is no way that they will fit on developer machines. Developing against a small subset is sure way to get code that won't work on prod (because it times out) which is a waste of time and effort on everyone's part.

Next, if my change is going to conflict with someone else's change, the sooner we find that out the better. That way neither one of us spends a lot of time devloping against a change that won't or can't happen and we can see that what we each are working on is realted and thus talk about how to integrate things as soon as possible. People see this as a minus in working with a shared database (because it is inconvenient), to me it is one of the biggest plusses (because it prevents redoing work in the long run).

We do have scratch database where people can play with concepts before they are ready to put them into the real databases.