问:
Is MongoDB the right choice in my case?
I'm going to build my first real project in Rails that consist in a web app made of 3 main parts:

The static part where no database is used

The User registration part which will require a database and I can use MySQL since each user's row will have the same fields

The "App" where users will be able to create, organize, edit... items in collections and share them with other users

There will be several item types and each one will have different options for example I may have "video" items with the following options:

id

user_id

collection_id

title

platform (if embedded)

url (if embedded)

file name (if hosted on my app)

file size (id hosted on my app)

and "map" items:

id

user_id

collection_id

title

platform (google maps, bing maps...)

location

url

map size

As you can while for users I may use MySQL for items the flexibility of MongoDB may be useful since each item may need different options then another item

Up to now I've always used PHP and MySQL (always on shared hosting for small projects) and scalability is a totally new word for me.

I have time to learn but I would like to be able to do something concrete in something like 1 month.

I've read a lot about MongoDB and NoSQL vs RDMS and MySQL and after trying it I have to say that I like how MongoDB works: no tables, no rows and its documents JSON like so:

In my situation what would you raccomend? why?

About scalability there may be problems with MongoDB? if yes when (in term of DB size) and may these problems slow down my app considerably?

Edit: how the app will work

Since many asked this is how I'd like the app to work:

A user sign up

He's logged in

He create his first collection iside which he can create infinite items

Items are of various type and each type need different data to be saved in the database and type of items may be added or modified

Users may create other collections and items inside it.

So we have CRUD for collections and items inside of them and each collection/item is referred to a specific user

The main problem with MySQL is that it hasn't a flexible schema, there is way to solve this (a workaround?)?

Thinking about NoSQL the only doubt I have is about join, for example given a certain colection I want to retrieve datas related to the User with id = user_id field in the collection

EDIT: Idea to keep using MySQL

Create a field in the "items" table with optional settings, each setting divided by a | or another symbol.

Then I will save somewhere a structure of each item optional settings, for example the "notes" item type need two optional settings "colour" and "strange_setting", when I get the data from MySQL i will split the field for optional settings into an array knowing that the first item in the array is for "colour" and so on.

What do you think? there are problem with that solution? do you have other ideas?

答:
I would say use the technology you know best, especially if it is a real project and you want to push it out fast.  Using MySQL and Mongo will both come with its own benefits and headaches.  Having worked with both, I would also add it is not very difficult to migrate from MySQL to Mongo if your follow good design principals.

Having that said, one good reason to go with MongoDB in your case is your data.  As you have mentioned, you will have several different types of entry for your collections: map, video, and so forth.  If you were to implement this using RDBMS, you have 3 approaches:

table-per-type: each table contains columns specific to each type of
objects

Disadvantages: N query to search across all data types.

Advantages: good OO design, easily to maintain

single table: one huge table containing all possible attribute for
all types, with most of them null for any particular entry

Disadvantages: Change to any object will require alter table, painful once table becomes large.  Difficult to maintain.

Advantages: Easy to implement.

core table with meta-data: you have a single table with the core
attributes, say title, dates, and a metadata table with key-value
pairs for additional attributes

Disadvantages: Two query to get all data for a single object.

Advantages: Extremely flexible, not very difficult to implement.

I have used each of these approaches before, and I can say none is as natural working with Mongo.  Your data will probably look something like this:

```<code>{_id:"collection1",
 name:"My first Collection",
 owner: "user123243342",
 entries: [
    {type:"video",
     url: "http://www.youtube.com/234324",
     tags: ["roadtrip", "fun", "camera"]
     },
    {type:"map",
     coordinates: [LOC: [38, –102], LOC: [43, –33], LOC: [228, –102]],
     description: "Road trip to nowhere",
 ]
}
</code>```

But you won't really have to worry about the schema design, as your domain objects can be directly persisted as such. MongoDB essentially is your object store which you can query against.

Noticed I have left out any discussion about the performance comparison between MySql and Mongodb.  While you should always keep performance in mind, you won't be able to effectively making decision unless you know the data access pattern.  Any good project will probably go through a few iterations of refactoring as it grow and new challenges emerges.  Don't worry about performance pre-maturely and pick the tool you know best about and start coding.

Edit

To respond to your specific question on using MySQL and keeping attributes in the same field using "|".  Don't do this.  This approach will give you more problem than it solves.  First of all, you will not be able to query against individual attributes using MySql.  Second it adds too much complexity to your data accessing layer.  Use either the type-per-table or the meta-data approach instead.  If you worked with WordPress before, it uses the meta-data approach:

user table + usemeta for user

post table + postmeta table post

This makes the data structure extremely flexible and still query-able with reasonable speed.

Title: Is MongoDB the right choice in my case?

Body:
I would say use the technology you know best, especially if it is a real project and you want to push it out fast.  Using MySQL and Mongo will both come with its own benefits and headaches.  Having worked with both, I would also add it is not very difficult to migrate from MySQL to Mongo if your follow good design principals.

Having that said, one good reason to go with MongoDB in your case is your data.  As you have mentioned, you will have several different types of entry for your collections: map, video, and so forth.  If you were to implement this using RDBMS, you have 3 approaches:

table-per-type: each table contains columns specific to each type of
objects

Disadvantages: N query to search across all data types.

Advantages: good OO design, easily to maintain

single table: one huge table containing all possible attribute for
all types, with most of them null for any particular entry

Disadvantages: Change to any object will require alter table, painful once table becomes large.  Difficult to maintain.

Advantages: Easy to implement.

core table with meta-data: you have a single table with the core
attributes, say title, dates, and a metadata table with key-value
pairs for additional attributes

Disadvantages: Two query to get all data for a single object.

Advantages: Extremely flexible, not very difficult to implement.

I have used each of these approaches before, and I can say none is as natural working with Mongo.  Your data will probably look something like this:

{_id:"collection1",
 name:"My first Collection",
 owner: "user123243342",
 entries: [
    {type:"video",
     url: "http://www.youtube.com/234324",
     tags: ["roadtrip", "fun", "camera"]
     },
    {type:"map",
     coordinates: [LOC: [38, –102], LOC: [43, –33], LOC: [228, –102]],
     description: "Road trip to nowhere",
 ]
}

But you won't really have to worry about the schema design, as your domain objects can be directly persisted as such. MongoDB essentially is your object store which you can query against.

Noticed I have left out any discussion about the performance comparison between MySql and Mongodb.  While you should always keep performance in mind, you won't be able to effectively making decision unless you know the data access pattern.  Any good project will probably go through a few iterations of refactoring as it grow and new challenges emerges.  Don't worry about performance pre-maturely and pick the tool you know best about and start coding.

Edit

To respond to your specific question on using MySQL and keeping attributes in the same field using "|".  Don't do this.  This approach will give you more problem than it solves.  First of all, you will not be able to query against individual attributes using MySql.  Second it adds too much complexity to your data accessing layer.  Use either the type-per-table or the meta-data approach instead.  If you worked with WordPress before, it uses the meta-data approach:

user table + usemeta for user

post table + postmeta table post

This makes the data structure extremely flexible and still query-able with reasonable speed.


问:
How do you handle changes in client focus?
We are working on a large ongoing project that has continual feature changes. These features could take as long as 3 - 4 weeks to complete.

This would of course be fine, except the client is always changing its priorities/focus based on pushes from THEIR clients who may want certain features implemented before others.

So, we often have to shift gears in the middle of a major feature build and start a new feature that all of a sudden has a greater priority. We then of course have the time cost of merging everything together at some point, and also the cost of that lost momentum on the original feature.

Our estimates are out the window at that point.

Is there any good way to handle this?

Some options I've thought of:

assume this is the way things will be, and apply a 'distracted client' factor of up to 100% on all estimates (this is dangerous in the case where we can actually complete a feature without interruption)

educate the client on the costs of shifting gears, and perhaps apply a change premium to previous estimates if they want us to change to working on a different feature

refuse to work on more than one feature/release at a time (aside from bug fixes). This is probably not realistic.

I'm looking forward to hearing about how others have tackled this. It can't be uncommon.

答:
I was just about to ask this same question. I think we've all worked for clients/bosses that constantly shift gears. Here's a typical work week for me (at times):

Monday: Boss says, "Hey, I came up with this great idea over the weekend! Lets do it!" So I spend the rest of the week coding it up and testing it.

Next Monday: I say, "Okay, here's that great idea you had." They say, "Eh, I don't care about that anymore. But I did come up with another great idea over the weekend! Lets do it!"

Rinse and repeat.

I'm at the point now that I just ignore half the crazy stuff my boss comes up with.

ContentLicense: CC BY-SA 2.5


问:
Which style to use for unused return parameters in a Python function call
Is there any recommended/generally accepted coding style for handling situations where a function returns a tuple of values but only one of those values is used afterwards (note that this is mostly meant for library functions I can't change -- writing a wrapper around the call is probably a bit of overkill…)?
Instead of doing

```<code>a, b, c = foo()
</code>```

and then just not using b and c, which of the following variants should be preferred (or is there another one?):

Variant 1 (underscore)

```<code>a, _, _ = foo()
</code>```

(which is very clear and simple but might clash with _ = gettext.gettext used in many applications that use translation)

Variant 2 (dummy name)

```<code>a, unused, unused = foo()
</code>```

(not very appealing, I think, same goes for other names like dummy)

Variant 3 (index)

```<code>a = foo()[0]
</code>```

(to me the ()[0] looks un-pythonic…)

答:
Pylint has gotten me in the habit of doing it this way:

```<code>widget, _parent, _children = f()
</code>```

That is, unused results have a descriptive name prefixed by _. Pylint regards locals prefixed with _ as unused, and globals or attributes prefixed with _ as private.

ContentLicense: CC BY-SA 4.0

Body:
Pylint has gotten me in the habit of doing it this way:

widget, _parent, _children = f()

That is, unused results have a descriptive name prefixed by _. Pylint regards locals prefixed with _ as unused, and globals or attributes prefixed with _ as private.

ContentLicense: CC BY-SA 3.0


问:
Confusion about dual license (MIT/GPL) javascript for use on my website
I've read all of the posts I can find on this and I'm still not sure of the answer.

I'd like to use a jQuery plugin on my website that is dual licensed under MIT and GPL.

Does the dual license mean that as long as one or the other is satisfied I'm fine, or does it have to be both?

I've read that a GPL javascript being loaded on someone's broswer doesn't count as redistribution, so I wouldn't have to use the GPL license for the rest of my site (provide source code). Is this true?

My partner thinks I should remove the copyright altogether and change the variable names, as this is going to be on a commercial website. Is this ethical? I respect the person who took the time to write the code. Should I contact them and see if the plugin is available under a commercial license?

Thank you very much in advance for helping to clarify. As this is my first website, I figure it's better to ask these questions than take a shot in the dark.

答:
1) Does the dual license mean that as long as one or the other is
  satisfied I'm fine, or does it have to be both?

Yes.
Specifically, jQuery makes it explicit that you can use it even in commercial environment.

Why then it is also with GPL?
This is because, if someone wants to make additional javascript library using jQuery, he/she can choose GPL license for himself/herself and distribute further in GPL to protect the freedom (which won't be possible with MIT).

2) I've read that a GPL javascript being loaded on someone's broswer
  doesn't count as redistribution, so I wouldn't have to use the GPL
  license for the rest of my site (provide source code). Is this true?

As of GPLv3 the web page downloading the javascript is NOT distribution because it is NOT usable form. This is actually helpful for the website owners who classify such usage of project as self use rather than distribution and hence they don't have to open their source.

There is a new license GPL Affero - that prohibits this; i.e. if there is a jQuery like library released under GPL Affero, the website owner has to release their own code as well!

3) My partner thinks I should remove the copyright altogether and
  change the variable names, as this is going to be on a commercial
  website. Is this ethical? I respect the person who took the time to
  write the code. Should I contact them and see if the plugin is
  available under a commercial license?

You don't have to do this. Specifically for jQuery license permits all uses (unless you are going to bomb any parliament somewhere) so it is not essentially.

If there was license restriction, you should NOT use this rather than really NOT giving due credit to the original author.

Even if not on ethical ground, legally it would be tough to recreate copyrights by merely changing variable names


问:
Is it a good idea to write requirements specifications by stories?
We're using agile methods in my current project at the moment, and we have heaps of stories like these:

As an assistant, I want to pay a customer a refund so that they can
get some money when they request it

As a customer, I want to pay for a purchase so that I can receive my
item.

How we've done it so far is to pick the most important stories every sprint and elaborate it into a number of formal requirements specs (we group some of the stories that are similar together in the same spec). Depending on the story, it could just be a button on a screen or an entire workflow.

The problem now is that because there's so many stories, it's not immediately clear, for any part of the system which stories relate to it.

It works at the time of developers, every sprint the devs just get a spec outlining what they need to do and the changes they need to make. But in terms of maintaining this story list and for testing, its starting to get really hard tracking bugs and in general just maintaining the specs, because one piece of functionality in the screen might have been documented in a number of different places due to it being split by story.

Is writing specs based on stories a good idea? Have we written the stories in the wrong way?

答:
This might be controversial but here it goes!

We have worked on a real time systems where one of the past bosses of mine suggested that let's do AGILE! It was easy to win management on that really; however, it was easier said than done.

The concept of stories is good - but to be very upfront, it is quite vague. What is a story, really? The real issue is that using stories alone (and much the same holds for Use cases as well) have several issues - as follows:

Requirements cannot be out of context (unless you are making gross repetitions so many times). There are assumptions, background knowledge and other requirements which are linked too a given requirement; they make sense only under a context and only under a specific order. Implementing most important one first makes business sense but when you file them at least - keep a complete referencing right from the beginning when yo collect them. Requirement word itself is complex and is not really limited to Use-Case / Stories. Indeed stories are actionable, but then there are requirements that may not be actionable, such as performance, constraints to be met, business rules etc.

Requirements needs to be appropriate in size and in quantifiable manner   else you can never have a need for more than 1 large story! What forms exactly 1 story?

is it one full detailed scenario? (e.g. one story when ATM rejects a transaction)

is it one set of action that user performs? (e.g. full story about withdrawal)

or is it one screen in the user interface? (e.g. withdrawal screen as a full story).

How do really quantify very crisp business rules with stories?
Honestly, it can be any of the above. The point is how much confined and granular you go is quite a personal style. If it works -it is fine;

Domain knowledge is really requirement!
A simple example, of an Architect who knows various properties of Glass, Steel and Wood. this knowledge is not part of the requirement document for the building per say! Same way, if you are writing a banking software - there are whole bunch of concepts about banking. Stating them, as Requirement itself makes it non-tractable because it doesn't tell you what should software do as opposed to how the world works. Does story includes such domain intricacies? or does it exclude this?

Modeling the world is prerequisite not quite supported by.

There has been a lot of literature on Modeling which focuses on just understanding how the world works is a background knowledge. Modeling forms firm foundation on which requirements gain clear meaning; however such a thing should be upfront. Unfortunately, most of the agile practices refuses value in upfront modeling in the interest of quicker and leaner deliveries; but that i still think is a major show stopper when things has to scale. Many project do succeed not because modeling is irrelevant - but seasoned engineers know them in their head and doesn't need much explicit guidance.

So coming to your question:

Is writing specs based on stories a good idea? Have we written the
  stories in the wrong way?

I think user stories does have value as explicit verdict given by customer. But if they are poorly organized and insufficiently detailed (or vague) there is a problem. Unless you have a larger structure to accumulate the broader understanding (domain knowledge) and scope (total spec). User stories only for segments or elements within larger such system.

PS: I have exact opinion about Use cases (as they are depicted in oval diagrams) that unless you put them in appropriate context and at appropriate granularity they don't do any good job. (I call them useless cases). The only credible source i find to make Use case writing truly scalable and meaningful is Writing effective Use cases by Cockburn


问:
How do you manage feature requests and software changes?
I am a Software Engineer and over the past few years I have become the de-facto software project manager simply because there isn't one. So to keep our sanity in the R&D/Engineering department, customers have become accustomed to coming to me with their requests. I have no experience in this realm so it is my first time acting as a project manager for software projects. I have managed other things but not software.

So, how do you manage software projects and mark priorities? Requests come in at infrequent intervals so we very well could be working on something for someone else and then another person comes in with a "rush" job that needs working on. Is it easier to just say First Come, First Serve or is it the person with the most money?

答:
Here some thoughts ...

There is plenty software in the market that helps you, http://www.fogcreek.com/ with Fogbugz , GeneXus USA with XPM http://www.genexususa.com/xpm , etc.

It's like an art to balance new feature requests with bug fixes and with your own ideas.
You have to get food for the next winter, but you have to eat today too.

You have time, resources and scope, make your best out of it.

Henry Ford also once famously said, “If I’d listened to customers, I’d have given them a faster horse" ...

Personally: be dynamic, don't put rules like the ones you said...
and be careful with other people's rules ... they may work well in their context, but not in yours.


问:
choosing a functional language platform for a new project
I have been writing code for a few years now and I don't believe I can claim to have a complete knowledge in this job yet.

My experience primarily rolls around C# related areas with a decent knowledge on Silverlight and Asp .Net MVC as well. I tend to use Sql server and Postgres for normal RDBMS related tasks with Mybatis or LinqtoSql as ORM (and Cassandra as well for NoSql).

Given that background, I am looking to building a new project which is a normal application using database and user interface screens. It is considerably a big project which we plan to be rolled out as a product.

In recent times, I see a lot of noises being made about functional programming like Haskell and F#. I am wondering
   - if it is worth to build the new system using Haskell
   - or just stick to a regular application building model using Silverlight/Prism with a layering similar to onion architecture

I understand the benefit of staying with the same technology background as it is always good to work on a familiar technology.

I also heard that by moving towards a functional language like Haskell we get cleaner code, improved testability etc.,

Is it really worth considering a move to build new systems in Hasekll? Or it is yet to be proven in production environments?

Simply put would I be safe if I build the new project using Haskell and my preferred database or it is too risky at this point in time to choose Haskell.

Any help appreciated.

Edit: I have already viewed a few other threads like the following and a few more as well, but did not get a definitive answer.
Choosing a functional programming language

答:
I use haskell in production to build web application interfacing with MS Sql Server.
I love it, i am very productive with it. And i feel much safer because compiler is extremely helpful in catching my mistakes. Much more so than java/c#

Having said that, if you phrase your question as "will i be safe with this choice" instead of "what do i get from it", then you certainly should stick with c# or java.

Haskell is very different. You will spend much more time learning it than learning any other imperative language.

Haskell still does not have neither adequate tooling (lack of IDE) nor many useful libraries (for example no good pdf library)

You are asking is it worth it to build new systems with haskell. But are you building them alone ? What about other members of your team ? What about future members of your team ? Where will you find haskellers ? How will you persuade dotnet or java programmers to embark on a hard and long learning process with a completely new and alien language ?

Haskell is definitely worth it, if you love programming and not just do it for money.
But you are not working alone in a vacuum. A lot of decisions have to be made with your environment in mind, people you work with etc.


答:
If in your entire project, you're only doing this this once or very rarely wrt the particular function, I would use Variant 1 if you know gettext isn't a problem in that module, and otherwise Variant 3.

On the other hand, if you were doing this a lot - and especially if each time you want a different subset of the return values (making a wrapper to just return the ones you care about unviable), it might be beneficial to write a wrapper that puts the results into a named tuple, or an instance of some other descriptive class, which would let you do:

```<code>bar = foo()
</code>```

And then work with bar.a, bar.b and bar.c.

Title: Which style to use for unused return parameters in a Python function call

Body:
Is there any recommended/generally accepted coding style for handling situations where a function returns a tuple of values but only one of those values is used afterwards (note that this is mostly meant for library functions I can't change -- writing a wrapper around the call is probably a bit of overkill…)?
Instead of doing

```<code>a, b, c = foo()
</code>```

and then just not using b and c, which of the following variants should be preferred (or is there another one?):

Variant 1 (underscore)

```<code>a, _, _ = foo()
</code>```

(which is very clear and simple but might clash with _ = gettext.gettext used in many applications that use translation)

Variant 2 (dummy name)

```<code>a, unused, unused = foo()
</code>```

(not very appealing, I think, same goes for other names like dummy)

Variant 3 (index)

```<code>a = foo()[0]
</code>```

(to me the ()[0] looks un-pythonic…)

Body:
If in your entire project, you're only doing this this once or very rarely wrt the particular function, I would use Variant 1 if you know gettext isn't a problem in that module, and otherwise Variant 3.

On the other hand, if you were doing this a lot - and especially if each time you want a different subset of the return values (making a wrapper to just return the ones you care about unviable), it might be beneficial to write a wrapper that puts the results into a named tuple, or an instance of some other descriptive class, which would let you do:

bar = foo()

And then work with bar.a, bar.b and bar.c.


问:
is it programmer's duty to disable directory listing?
Recently I have project in which a directory listing is enabled, due to which some scripts can be seen by outside world. I asked website administrator and he said it's not his responsibility, its the programmer's job. I also asked programmer about this and he said that the script is actually a cron job, and according to him, he has to test the script on webserver as there is a difference between development and production environment, so he placed there to test that. According to him, there was no direct link as he assumed directory listing is disabled and taken care by administrator.

Who is the right person to do this?

答:
It's duty and responsibility of both

The basic problems with security tend to have something to do with comfort and overconfidence (e.g. security through obscurity). If you know a way to cover a security hole, do it, there's no such thing as "too much security".

...it's not that hard

For example, the Joomla! project team places an empty index.html file on each directory to prevent directory listing and frameworks like Symfony and Ruby on Rails have a single public directory to which you must link on the public end of the server account.

Never ever be lazy when it comes to security


问:
How do I review my own code?
I'm working on a project solo and have to maintain my own code. Usually code review is done not by the code author, so the reviewer can look at the code with the fresh eyes — however, I don't have such luxury. What practices can I employ to more effectively review my own code?</p>

答: I usually print out all my code and sit down in a quiet environment and read through it, I find a lot of typos, issues, things to refactor, cleanup by doing that. It's a good self-check that I think everyone should do.</p>

Title: How do I review my own code?


问:
Programming IDEs feature to add a forgotten open parentheses?
I very often find myself in situations where I should have opened a parentheses, but forgot and end up furiously tapping the left arrow key to get to the spot I should have put it, and doing the same to get back to where I was - that, or removing one hand from the keyboard to do it with the mouse. Either way, it's a stupid mistake on my part and a poor use of time going back to fix it.

For example, if typing something like

```<code>var x = 100 - var1 + var2;
</code>```

I might get to the end of the statement and realize I wanted to subtract the sum of var1 and var2 from 100 and not add var2 to the difference of 100 and var1.

I can't really expect an IDE to prevent my mistakes, but I was thinking there could be a simple enough feature that would save time when they're made. Specifically, some kind of function that, after a closing parenthesis is added where there isn't an opening one, would start ghosting in an opening parenthesis at different statements and allow the user to switch between them.

For example:

Say you have the following statement:

```<code>var x = oldY * oldX + newY / newX - left - right;
</code>```

If you put a closing parenthesis after right and pressed the shortcut, the IDE would do:

var x = oldY * oldX + newY / newX - ( left - right);

press left, and then:

var x = oldY * oldX + newY / ( newX - left - right);

...then:

var x = oldY * oldX + ( newY / newX - left - right);

Anyway... Does this feature exist? If not, should it exist? What do senior programmers do when this happens?

答:
Does this feature exist?

No, IDE should not (and can not) automatically fix your code, because it has no way to know whether the formula you use has this or that arithmetic operation.

What do senior programmers do when this happens?

Serious programmers (not only senior) write proper unit tests, where such mistakes are easily detected.


问:
Does giving a developer a slower development machine result in faster/more efficient code?
Suppose I give my developers a screaming fast machine.  WPF-based VS2010 loads very quickly.  The developer then creates a WPF or WPF/e application that runs fine on his box, but much slower in the real world.

This question has two parts...

1) If I give a developer a slower machine, does that mean that the resulting code may be faster or more efficient?

2) What can I do to give my developers a fast IDE experience, while giving 'typical' runtime experiences?

Update:

For the record, I'm preparing my even-handed response to management. This isn't my idea, and you folks are helping me correct the misguided requests of my client.  Thanks for giving me more ammunition, and references to where and when to approach this.  I've +1'ed valid use cases such as:

- specific server side programming optimizations

- test labs

- the possibly buying a better server instead of top of the line graphics cards

答:
I am convinced that having slower computer for development results in faster code, but this comes at a price. The rationale is that I have experienced this first hand: having long commute time, I bought a netbook to work in the train, netbook which is slower than any computer I have bought in the 5 last years. Because everything is so slow, I see very quickly when something is unbearably slow on this netbook, and I am aware of slow spots much more quickly (no need to benchmark all the time). Working on a netbook really changed how I developed.

That being said, I am not advocating doing this, especially in a profesional environment. First, it is demoralizing. The very fact that almost everybody said the idea did not even make sense show that programmers react badly to the idea.

Secondly, having everything slower means that things you may want to do on a fast machine (takes say 1 minute) are not really doable anymore on a slow machine, because of lazyness, etc... It is a question of incentive.

Finally: the produced code may be faster, but it almost certainly takes longer to produce.


答:
You mentioned a problem and the way how you solve it but you forget to mention some example of your specs and grouping and how it is related to the way how you develop your product.

Writing specs by stories? a good idea?

Agile doesn't forbid it. In agile you can do whatever you need to deliver maximal business value in sustainable pace. So if writing specs is something you need to deliver more business value it is absolutely OK to do that.

Your example shows two user stories. They are perhaps somehow related in your business logic but that is very common scenario.

If you need to bactrack functionality to user stories you can again use whatever suits you best including documentation, some diagrams or your "spec" but you must be prepared that maintaining these artifacts will cost you more as your complexity of the developed application increase. So the only question you must answer in this case is: If I don't use my specs will it cost us more? If the answer is yes you chose a better option.

The agile works best for small to medium projects with small team were whole architecture is held as tacit knowledge shared in the team. During iteration planning you will go through your picked stories, discuss an impact on the current implementation and write some tasks needed to complete the story. The real documentation in such case will be the test suite holding automatic acceptance and integration/unit tests. Once your SW or team grows the tacit knowledge will have to partially move to some documentation.

Title: Is it a good idea to write requirements specifications by stories?

Body:
We're using agile methods in my current project at the moment, and we have heaps of stories like these:

As an assistant, I want to pay a customer a refund so that they can
get some money when they request it

As a customer, I want to pay for a purchase so that I can receive my
item.

How we've done it so far is to pick the most important stories every sprint and elaborate it into a number of formal requirements specs (we group some of the stories that are similar together in the same spec). Depending on the story, it could just be a button on a screen or an entire workflow.

The problem now is that because there's so many stories, it's not immediately clear, for any part of the system which stories relate to it.

It works at the time of developers, every sprint the devs just get a spec outlining what they need to do and the changes they need to make. But in terms of maintaining this story list and for testing, its starting to get really hard tracking bugs and in general just maintaining the specs, because one piece of functionality in the screen might have been documented in a number of different places due to it being split by story.

Is writing specs based on stories a good idea? Have we written the stories in the wrong way?


问:
Becoming a Better Bug-Fixer
I love being a programmer. There, I said it. However, with that said, I've realized lately that I really can't stand bug-fixing. At all.

In fact, while I'm developing something, my productivity is extremely high. Even when writing unit-tests and doing self testing of my development, I'm generally really productive. I can focus well, and I can get tasks done.

However, when QA time comes around and I'm working on fixing bugs, my inspiration takes a massive nosedive. I have to force myself with pretty extreme measures (you know, high BPM music, excessive amounts of caffeine, etc.) to get anything done. My job is usually involved with stepping into an existing massive project and adding new features or fixing bugs, so I can't exactly tell my employer that I need a couple weeks to write unit tests for all of their code :) In addition, the server technology that we often use is very prohibitive to both unit and integration testing, as it has quite a few Java classloader issues. I'm not completely against bug-fixing, sometimes it can be fun, but it's not fun at all when you have to make minor changes and wait 30 seconds to 3 minutes to be able to see if they worked or not (due to the way the system works).

How can I improve my productivity and motivation when bugfixing? Is this something that most programmers deal with?

答:
Bug fixing usually feels like a chore because it can make you feel like bugs are taking up all of your time and keeping you away from the fun new stuff.  The reality is however that bug fixing is a very large part of what we do, and it starts as early as writing the first line of code and executing the compiler. When you release code for the first time, you have probably already spent hours fixing bugs, only it doesn't seem that way because you've been fixing them as part of the process of implementing features.  Realistically speaking, no matter how good a programmer you are, bugs will creep into your system.

So how do you make it fun? Well, I can't really answer that for you as I really can't imagine what it is that floats your individual boat.  For me, I'm a bit of a tool junkie, so the answer has been in having a very reliable tool chain, and a flexible development process that all contribute to making bug fixing less of a chore, and more simply a problem to solve quickly. I'm presently developing mostly in C#, and I am always on the lookout for tools that will remove the tedious time wasting parts of writing software. I use a test first development approach supported with a very good BDD API called StoryQ. I use Resharper to automate much of my refactoring and StyleCop to keep a lid on things like coding style. My latest addition to the tool chain has been to include NCrunch which runs my tests continuously and concurrently in the background while I code, and it's really been NCrunch which has proven to be the game changer.

The combination of all of these tools has seen my productivity go through the roof lately, as I waste very little time waiting for things to compile or execute.  I get instant feedback visually within my IDE to let me know that I have issues to fix, and I lay out my test code in such a way that I can pinpoint to within a only a few lines of code the exact place where not only the failure occurs, but to where the cause of the failure occurs due to the lovely verbose reporting that I get from StoryQ which tells me exactly which parts of my test pass, which fail, and where in the code the failures are.  With all of the time wasters removed from my development time, I spend very little time actively debugging, and more time solving problems and writing tests and code. The high turnover off issues keeps me busy, and brings a lot of variation in my tasks. It has also given me lots of time to pursue other areas of interest during my work day so that I can inject new and innovative ideas into our product line, and our processes.

Title: Becoming a Better Bug-Fixer


问:
What did Ruby do right (or was it Rails)?
Most programming languages have some design decisions that influence their usage and applicability.

For example:

Python focused on maintainability/readability of code and had indentation be a part of the language itself.

Java's intention was to be cross platform OOP 'easier' and 'friendlier' than C++

Objective-C was built as an OO wrapper around C not knowing the future of C++ at the time

Erlang is designed for highly fault tolerant and concurrent systems

PHP designed for handling dynamic creation of web pages

CoffeeScript designed to expose the good parts of Javascript and adding OOP syntactical sugar and hiding the nuances (globals etc.) of JS 'behind the scenes' etc.

Each programming language tried to exploit and capitalize on a particular niche IMHO. The above are my perspectives on what were the founding principles of the programming languages and that governed their evolution and widespread adoptability. Of course, there are many more, but the list is only intended as an example

However, I've struggled to understand the founding principles on which Ruby is based and its growing popularity. What were the founding principles of Ruby that makes it popular today? Or is it the genius of one man who designed the Rails framework? If the latter was it that Ruby made the designing of Rails better/easier/faster? In what sense?

The most commonly cited reason as per its creator is '...wanted a fun weakly typed programming language' - I don't see that as a reason for creating a new programming language altogether! Programming is sheer fun IMHO irrespective of the language (each language has some bad parts, but one either gets around it or lives with it).

So what niche did (or does) Ruby exploit that isn't exploited by the current languages? What is the 'strong point' (USP) of Ruby that has led to its widespread adoptability? What did Ruby do that wasn't done before (or was extremely difficult)?

I'm not a Ruby programmer, but just a Ruby noob and hence the confusion.

Disclaimer: This is NOT a flame war and I'm not looking for Ruby vs Programming language type of answers. I am looking for the design decisions on which Ruby is based that has led to widespread adoption. What niche does Ruby satisfy to have become popular or is that purely attributed to Rails?

答:
Ruby (togehter with rails) made the convention over configuration popular.

The old (non ruby on rails) way was

Define a database table "persons" with a field named "birthday"

Define a business class "person" with a property "birthday"

write a helperclass for transfer data between database and businessclass

create a gui that how persons in a list

create a gui to edit one persons properties

With convention over configuration the base work for this is done automatically:

you define a person in code

database table, mapping, gui-elements, are automatically created for you by a powerfull interpreter or codegenerator

contras: you have to learn all the cenventions so learning ruby on rails on the first run is harder.

pros: once you know the conventions it is quite easy to understand code of other ruby on rails developpers because every one is forced to follow the same conventions.

meanwhile convention over configuration has entered into many coding eco-systems


问:
How to deal with bad code?

Possible Duplicate:

  Techniques to re-factor garbage and maintain sanity?

  Code maintenance: keeping a bad pattern when extending new code for being consistent, or not?

I was hired about 6months by a company that uses Agile, but after learning the code I've realized that it's bad code - methods with over 100 lines of code, duplicate code, methods that says it does one thing but does a few other unrelated things.  It works, but the more we update it, the more it become like a house of cards. Refactoring one little thing requires changing lots of others, which can make program unworkable. What did go wrong and is it possible to fix it? I thought agile was supposed to make a good code.

答:
There could be so many reasons why the code looks like it is. Like other comments have suggested, Agile is not a medicine for all illness in software.

Is it possible to fix it?

No one can judge this more than you. If you have the skills, resources and if the system is continually changing or if it is critical to your business, may be you MUST fix it.

The major reason I am writing this is to make you aware of an important fact. Don't mess around with this system unless you really know how it works well and you really have to.
Forget about the beauty of the code and focus on functionality and performance.

If you want to do a real change, make sure it is planed for and that you are ready for it.

Sometimes it is hard to resist the say "if it ain't broken don't fix it" but that it is not professional of course.

No one gets credit for breaking a system even if it is a bad one.

Title: How to deal with bad code?


答:
You have to live with it.

Had been in a similar position. Rewriting the whole code can often be underestimated and is a huge undertaking. It will need your supervisor approval. I haven't rewrote my code it but had experimented rewriting part of it. By doing that I made my life easier, at least I found what was going on. I left the original code as it is. After cleaning up part of it for myself, I had more confidence dealing with the code. Although with mine, the logic of the code was fine, it was the styling that was extremely badly written and that made changing the code very hectic. But I have learned to live with it and I have adopted the same bad coding style to get thing done :)

Title: How to deal with bad code?

Body:
Possible Duplicate:

  Techniques to re-factor garbage and maintain sanity?

  Code maintenance: keeping a bad pattern when extending new code for being consistent, or not?

I was hired about 6months by a company that uses Agile, but after learning the code I've realized that it's bad code - methods with over 100 lines of code, duplicate code, methods that says it does one thing but does a few other unrelated things.  It works, but the more we update it, the more it become like a house of cards. Refactoring one little thing requires changing lots of others, which can make program unworkable. What did go wrong and is it possible to fix it? I thought agile was supposed to make a good code.


答: I think that your #2 is the way to go. Such problems can only be solved by talking to the customer. Tell them that changes are costly - both in time and money. Show them your estimations and indicate where their new changes interfere.</p>

Title: How do you handle changes in client focus?

Body:
We are working on a large ongoing project that has continual feature changes. These features could take as long as 3 - 4 weeks to complete.

This would of course be fine, except the client is always changing its priorities/focus based on pushes from THEIR clients who may want certain features implemented before others.

So, we often have to shift gears in the middle of a major feature build and start a new feature that all of a sudden has a greater priority. We then of course have the time cost of merging everything together at some point, and also the cost of that lost momentum on the original feature.

Our estimates are out the window at that point.

Is there any good way to handle this?

Some options I've thought of:

assume this is the way things will be, and apply a 'distracted client' factor of up to 100% on all estimates (this is dangerous in the case where we can actually complete a feature without interruption)

educate the client on the costs of shifting gears, and perhaps apply a change premium to previous estimates if they want us to change to working on a different feature

refuse to work on more than one feature/release at a time (aside from bug fixes). This is probably not realistic.

I'm looking forward to hearing about how others have tackled this. It can't be uncommon.


答:
Well i think you are mistaken about Agile being the culprit, Its more to do with how sound you are with coding and most important the one touching the code knows what its intended to perform.

Without this its most of the time hacking into a piece of code so that you get the things on the plate cleared off and then later stumble upon another block which you would have created since you didn't really figure/know as what the code was doing.

Maybe at times it would be good if you could refactor a few methods as and when you encounter problems (i am not saying rewrite) and try clear the mess up a bit, at this point you should definitely know what the code should do and iteratively after a period of time you can see some positive results.

In the meanwhile you can also introduce review (if it exists check why its not effective) and help out the lesser non mortal coders and share with them good practices and give company to your code with some relevant comments.

Hope it turns around n some time but you need to give it some time.

Title: How to deal with bad code?


答: Agile doesn't make bad code, leave that to bad programmers. You should start off by writing inline comments pointing out the problems, then go about fixing them one by one. It's hard work, but that's what you were partly hired to do anyway.</p>

Title: How to deal with bad code?


问:
How to write functionally in a web framework
I love Rich Hickey, Clojure and Haskell and I get it when he talks about functions and the unreliability of side-effecting code.

However I work in an environment where nearly all the functions I write have to read from the database, write to the database, make HTTP requests, decrement a user's balance, modify a frontend HTML component based on a click action, return different results based on the URI or the POST body. We also use PHP for the frontend, which is littered with functions like parse_str(), which modifies an object in place. All of these are side-effecting to one degree or another.

Given these constraints and the side-effecting nature of the logic I'm coding, what can I do to make my code more reliable and function-able?

答:
Immutable objects go a long way to supporting no-side-effect function calls.

Here's some ways you can model immutables in your coding at various tiers:

PHP functions: you need to find an alternative, or write your own wrapper to make a copy of the string before updating it

Write to the database: don't do updates, always insert. Your select then needs to pull the latest object. Numerous ways to do this.

HTTP requests: depends really on the backend system, I'll assume out of scope.

Decrement a user's balance: Assume same as write to database. It may help to reframe mentally the "balance" as a first class attribute in your model to become a pre-calculated and cached point in time position of all prior transactions.

Modify a frontend component: Replace the component, don't change it.

Return different results based on URI: Not sure how you expect this to change; functions will perform differently depending on different data inputs.

These are just examples to get you started. The key I think is that immutables and "no side effect" transactions achieve the same outcome.

Side note - this is a powerful technique and can actually be used to avoid the need for locks in multithreaded programs but does have associated memory / garbage collection impacts. All depends what you need.


问:
How to read thousands lines of code without any documentation?
Previously I was searching for a good TimeLine control for a WPF project. I found an answer in Here which direct me to this CodePlex project.

Now I want to change code to feed my culture needs. But there are some mismatches!

My question is:

How you interact with such thousands lines of code?

EDIT:

Any shortcut will be great!

答:
I use tools like doxygen, to generate an overall class diagram, than adds my understanding of what each of the classes do.

Then I pick up some easy bug from the bug queue (before my manager assign a hard one to me :P), then run through that functionality into debugger and try to generate a rough data flow or code flow model.

For example export functionality in some software: so I try to understand how the source data is read, from where in the code (base interface) can I evaluate the data is read correctly using my class and code flow diagrams, which classes are responsible for which type of exports, etc. I think half of the understanding is done, once you have the class diagrams and flow charts.


答: It's the programmers duty to fix anything that affects their application. If directory listing is a security concern for your application, then take steps for correct that. Good applications must not rely too much on the reliability of administrators.</p>

Title: is it programmer's duty to disable directory listing?

Body:
Recently I have project in which a directory listing is enabled, due to which some scripts can be seen by outside world. I asked website administrator and he said it's not his responsibility, its the programmer's job. I also asked programmer about this and he said that the script is actually a cron job, and according to him, he has to test the script on webserver as there is a difference between development and production environment, so he placed there to test that. According to him, there was no direct link as he assumed directory listing is disabled and taken care by administrator.

Who is the right person to do this?


问:
What are the warning signs of impending doom to watch out for on a project?
Having worked on a failed project is one of the few things that most programmers have in common, regardless of language used, industry or experience.

These projects can be great learning experiences, soul-crushing disasters (or both!), and can occur for a multitude of reasons:

upper management change of heart

under-skilled / under-resourced team

emergence of superior competitor during dev cycle

over/under management

Once you've worked on a couple of such projects, is it possible to recognise at an early stage exactly when a project is doomed to fail?

For me, a big sign is having a hard & fast external deadline combined with feature creep. I've seen projects which were well planned out and proceeding right on schedule go horribly off the rails once the late feature requests started to roll in and get added to the final "deliverable". The proposers of these requests earned the nickname of Columbo, due to rarely leaving the room without asking for "just one more thing".

What are the warning signs you look out for that set off the alarm bells of impending doom in your head?

答:
To me the single biggest problem, and one you can spot immediately, is when business considers written requirements as a waste of time.

So basically; No Written Requirements

It's the kiss of death.


答:
I've found that the more a customer complains about how urgent their request is, unless they are also a developer in their own right, it's usually a good sign that the request isn't urgent at all.  One of my professors in college always used to tell us not to let the urgent interrupt the important.

I usually classify requests in this order (YMMV):

Issues related to a recent upgrade or migration (most important).

Security fixes.

Broken functionality of the existing system.

Broken functionality in RC and beta features.

Paid feature requests.

R&D feature requests from a large part of the user base.

R&D feature requests from only one or two users.

This last one actually takes a lot more time because they tend to be those "urgent, I need it yesterday" requests.  In reality, the user has rarely thought completely through what they actually need or how it will support their business model.  Most often, these urgent requests, once delivered, end up being used once or twice and forgotten about.  And once forgotten, they become an endless headache of security holes and unintended consequences.

Title: How do you manage feature requests and software changes?

Body:
I am a Software Engineer and over the past few years I have become the de-facto software project manager simply because there isn't one. So to keep our sanity in the R&D/Engineering department, customers have become accustomed to coming to me with their requests. I have no experience in this realm so it is my first time acting as a project manager for software projects. I have managed other things but not software.

So, how do you manage software projects and mark priorities? Requests come in at infrequent intervals so we very well could be working on something for someone else and then another person comes in with a "rush" job that needs working on. Is it easier to just say First Come, First Serve or is it the person with the most money?


问:
Right Amount of Security on Machine
I am basically asking this question to see if I am being unreasonable.  My current employer has locked down the machines of all developers so that we do not have access to the root or c: drive.  For example, I cannot write a directory under C:.  I also cannot install any software which touches the registry.  Is this an extreme action or am I overreacting to common security measures?

What is the extent of security on your company provided machine?  To add some scope to this question, I am a web application developer and I'm talking about a laptop owned by the company.

答:
It depends a lot on your work environment. In bigger firms, it may be unfeasible for everyone to get their custom configuration, and your employer may do this to simplify assistance.

Where I work, I changed the OS the day I arrived, and have always been mantaining my computer since.

Title: Right Amount of Security on Machine


答:
This is not unusual as the default position for many large companies.  The attitude is quite understandable as there may be many thousands of machines connected to a "secure" company network and the consequences of having a rogue machine can be severe.  </p>

<p>You may be able to negotiate an exemption for your machine if you can demonstrate a real need for additional privileges but if it is a company laptop that you take off site and connect to external/public networks then this may be difficult.  </p>

Title: Right Amount of Security on Machine

Body:
I am basically asking this question to see if I am being unreasonable.  My current employer has locked down the machines of all developers so that we do not have access to the root or c: drive.  For example, I cannot write a directory under C:.  I also cannot install any software which touches the registry.  Is this an extreme action or am I overreacting to common security measures?

What is the extent of security on your company provided machine?  To add some scope to this question, I am a web application developer and I'm talking about a laptop owned by the company.

Body:
This is not unusual as the default position for many large companies.  The attitude is quite understandable as there may be many thousands of machines connected to a "secure" company network and the consequences of having a rogue machine can be severe.

You may be able to negotiate an exemption for your machine if you can demonstrate a real need for additional privileges but if it is a company laptop that you take off site and connect to external/public networks then this may be difficult.


答:
Basically the action to  write a clean code should start right from design.
If we are coding in OOP language come up with a UML ,share with peers and get convinced that design is not ambigous . In any case we developers should get convinced that design solves the problem and not ambiguos.

When it comes to coding we have to make sure the design is getting converted to code i.e. an Entity to a class or struct , an operation to function etc.

And i went through a white paper http://queue.acm.org/detail.cfm?id=2063168  which talks about coding style or how we can use space, indentation , Font variation as most IDEs do we can use to write MUCH CLEANER code where we humans can understand as much as machines do. It stresses more on writing comment free code so that our code will appear as paragraphs itself.

Title: How to read thousands lines of code without any documentation?

Body:
Previously I was searching for a good TimeLine control for a WPF project. I found an answer in Here which direct me to this CodePlex project.

Now I want to change code to feed my culture needs. But there are some mismatches!

My question is:

How you interact with such thousands lines of code?

EDIT:

Any shortcut will be great!


答:
We are using linux on our development PCs - that means that only people with root access are allowed to update PCs and to handle requests to install custom software.

That goes with linux philosophy, and it makes perfect sense, since it is so easy to screw up the system. Who are you going to call in that case?

Title: Right Amount of Security on Machine


问:
Is performance testing applicable to a QA or business user testing?
Performance testing is something that I, as a developer do when optimizing. However, if the change is purely optimization, should the QA or business user perform their own performance testing? I would reckon they should, aside from testing that the functionality remains the same. If that's the case, is it acceptable for them to test via manually timing the response time from the screen? </p>

答:
Any change you make should be as a result of a requirement from the customer. This could be an initial requirement or an enhancement/bug report made when then they find that the application can't handle 10,000,000 records (or whatever).

As such any change should go through QA with the pass criteria being a) that it works and b) that it works in the required timescale.

If performance is a high priority then I would expect the customer to do their own testing as well either prior to initial acceptance or as soon as any enhancement/bug fix is deployed.


问:
Abstract base classes and copy construction, rules of thumb
Often times it's a good idea to have an abstract base class to isolate the interface of the object.

The problem is that copy construction, IMHO, is pretty much broken by default in C++, with copy constructors being generated by default.

So, what are the gotchas when you have an abstract base class and raw pointers in derived classes?

```<code>class IAbstract
{
    ~IAbstract() = 0;
}

class Derived : public IAbstract
{
    char *theProblem;
    ...
}

IAbstract *a1 = new Derived();
IAbstract a2 = *a1;//???
</code>```

And now do you cleanly disable copy construction for the whole hierarchy? Declare copy construction as private in IAbstract?

Are there any rules of three with abstract base classes?

答:
By making ctor and assignment private (or by declaring them as =delete in C++11) you disable copy.

The point here is WHERE you have to do that.
To stay with your code, IAbstract is not an issue.
(note that doing what you did, you assign the *a1 IAbstract subobject to a2, loosing any reference to Derived. Value assignment is not polymorphic)

The issue comes with Derived::theproblem.
Copying a Derived into another may in fact share the *theproblem data that may be not designed to be shared (there are two instances that may call delete theproblem in their destructor).

If that's the case, it is Derived that must be non-copyable and not assignable.
Of course, if you make private the copy in IAbstract, since the default copy for Derived needs it, Derived will also be not copyable.
But if you define your own Derived::Derived(const Derived&) without calling IAbtract copy, you can still copy them.

The problem is in Derived, and the solution must stay into Derived: if it must be a dynamic-only object accessed only by pointers or references, it is Derived itself that must have

```<code>class Derived
{
    ...
    Derived(const Derived&) = delete;
    Derived& operator=(const Derived&) = delete;
};
</code>```

Essentially it is up to the designer of the Derived class (that should know how Derived works and how theproblem is managed) to decide what to do with assignment and copy.

Body:
By making ctor and assignment private (or by declaring them as =delete in C++11) you disable copy.

The point here is WHERE you have to do that.
To stay with your code, IAbstract is not an issue.
(note that doing what you did, you assign the *a1 IAbstract subobject to a2, loosing any reference to Derived. Value assignment is not polymorphic)

The issue comes with Derived::theproblem.
Copying a Derived into another may in fact share the *theproblem data that may be not designed to be shared (there are two instances that may call delete theproblem in their destructor).

If that's the case, it is Derived that must be non-copyable and not assignable.
Of course, if you make private the copy in IAbstract, since the default copy for Derived needs it, Derived will also be not copyable.
But if you define your own Derived::Derived(const Derived&) without calling IAbtract copy, you can still copy them.

The problem is in Derived, and the solution must stay into Derived: if it must be a dynamic-only object accessed only by pointers or references, it is Derived itself that must have

class Derived
{
    ...
    Derived(const Derived&) = delete;
    Derived& operator=(const Derived&) = delete;
};

Essentially it is up to the designer of the Derived class (that should know how Derived works and how theproblem is managed) to decide what to do with assignment and copy.


答:
If it is inside the application, it is programmers responsibility

If it is outside the application, it is admin responsibility


问:
Web Development Algorithms
While searching for jobs online I noticed that most PHP web developer jobs ask you to know about algorithms and data structures.While I don't know PHP yet I have started to learn it in order to obtain a job in that field.

While I have seen some similar questions on the forum I don't feel like the answers satisfied my needs.

I already have some knowledge of the quicksort algorithm and how to use a stack from when I was working in Java and Javascript , but I am guessing it is not enough.What I would like is a list of the most common used algorithms in web development.

答:
There aren't necessarily a set of algorithms that are specific to web development.  More like algorithms common to all programming.  I think the job postings that want you to have a knowledge of algorithms are just looking for someone with a solid background in Computer Science or the theoretical side of things.

You can think of your quest to obtain one of these jobs as two separate goals:

Become knowledgeable about commonly used algorithms.

Become proficient in one or two web programming languages.

For the first goal, I would recommend learning the basics of at least the following set of algorithms:

Sorting algorithms

Searching algorithms

Simple recursive algorithms

Backtracking algorithms

Divide and conquer algorithms

Dynamic programming algorithms

Greedy algorithms

Brute force algorithms

For the second goal, I would recommend picking two web programming languages, say PHP and ASP.NET, and finding some tutorials that help you learn the basics of these.  Then, try to build something useful using these and before you know it, you'll be ready to make a contribution to a software development team!

Title: Web Development Algorithms


问:
How to avoid halting of the JVM due to a deadlock in java?
I have read many websites talking about how to avoid and how to design etc. I completely understand those strategies.

My question is based on the following preconditions:

You have a company with 1000's of developers.

There are different teams working on the same product but as modules.

New developers writing new code not knowing the overall system, please consider an Enterprise application.

High available software development where a downtime of 15 mins is considered as an SLA violation.

I could write few more preconditions but I thought these could be strong enough to support my question about why I might need a recovering strategy for a "Deadlock" in a software.

Please note that re-designing the modules whenever we find a deadlock is not realistic.

Now this being said.

Can someone take sometime to provide an input or brainstorm on an idea of how to resolve a deadlock if at all it happens, so that we can report it and move forward, instead of halting completely.

Run a deadlock detector that runs periodically to look for deadlocks in the system.

If a deadlock is detected, notify with an event to resolve the deadlock.

The deadlock event listener will then kick in and act upon the deadlocked threads.

For each thread identify the contention.

Write an intelligent algorithm that could either release the locks and kill the thread or release the locks and re-evaluate the thread.

In step 2 we handle the notification in multiple ways, out of which logging is one of the listener.

I know how to go about steps 1,2,6. Will need help with 3,4 and 5.

I know that Oracle RDBMS already has a deadlock detection and resolution strategy in place, I wonder if they would ever share their strategies in this thread :)

Can't add my comment as an answer so adding it as a comment here.

=================================================================

I completely understand the risk of killing the threads. I was 100% certain that I would get answers like this but I was also hoping that someone would suggest something new. I'll keep the thread open as there is no answer in here that I already do not know, thank you very much for trying though.

答:
One option would be to never wait for a lock without a timeout, thus your system will never get stuck.

Another way is custom locks everywhere. Enforce that by static checking. Then:

If your lock class(es) register themselves in some DeadlockManager,

that same manager knows which locks are held by which thread

Threads report at regular interval that they're running properly

If a thread fails to report, check what locks are held/waiting by it and other threads.

What you could do to resolve this is to have the manager unlock the lock and have the lock throw and exception (DeadLockException). That gives the surrounding code a chance to recover and retry whatever it did.

Note that it is hard to figure out which locks and what order caused the deadlock (A,B), in general.

However, if you do know what locks you will be locking and in what order, the DeadLockManager could check that it's possible. I suppose the locking order could be "reserved" and checked for so that no other thread causes a deadlock.

It will be tricky to do, and maybe impossible to coordinate on a large project, but if you can't change the architecture much, this is one option.

OwnerDisplayName: Aravind Chennuru


问:
Could JQuery and similar tools be built into the browser install?
After reading another question about JQuery and CDN's, is it feasible for tools like JQuery to "come with" the browser, thus reducing/eliminating the need for the first download from a CDN, or from your own host server.

JQuery files specifically are pretty small, so you could easily have a number (all?) of the different versions as part of a browser install. Now fair enough, this would increase install footprint, download time for the browser itself.

Then sites could check "local" first, before CDN (which then caches), before finally defaulting to downloading from the website server itself.

If this is feasible, has it been done, and if not, why hasn't it be done?

答:
There's no technological reason why they couldn't. However, it's not necessary and it's against the web's fundamental philosophy. It's not necessary, because you can achieve almost the same thing with a far future expires header. It's against the web's philosophy because it causes there to be a top-down, centralized authority on which libraries should/shouldn't be bundled with the browser.

Edit: JS libraries are there, primarily, to make dealing with the DOM easier. I don't think bundling third-party libraries with the browser is the right way to make the DOM API more pleasant.


答:
Browser caching provides something very much like what you are talking about. It should be the case that jQuery or any other JS library would be downloaded once and then retrieved from the cache on further requests.

While jQuery may be the most ubiquitous JavaScript library, it isn't the only one and it seems to me that making it a an installed component of the browser would be bad for the JS ecosystem. Competition is healthy and generally leads to innovation, and we developers and software users would not be well-served by giving jQuery a special position.

Once you take caching into account, the advantage that you gain is very, very minimal. The minified version of jQuery is only 31K. That's no rationale for changing anything.

Title: Could JQuery and similar tools be built into the browser install?

Body:
After reading another question about JQuery and CDN's, is it feasible for tools like JQuery to "come with" the browser, thus reducing/eliminating the need for the first download from a CDN, or from your own host server.

JQuery files specifically are pretty small, so you could easily have a number (all?) of the different versions as part of a browser install. Now fair enough, this would increase install footprint, download time for the browser itself.

Then sites could check "local" first, before CDN (which then caches), before finally defaulting to downloading from the website server itself.

If this is feasible, has it been done, and if not, why hasn't it be done?


答:
It depends on your organization's security policies. At some companies, usually smaller ones, I had to do everything. At others, I wasn't even allowed access to the production web servers and the admins had to install my apps and do all the server configuration, sometimes while I looked over their shoulder to make sure everything is done correctly.

Basically, if your employer says it's your duty, it's your duty. Likewise, if they say developers can't access the production boxes, it's not your duty beyond making sure the admin knows what to do.


答:
Don't forget that jQuery is a js library, it seems to have become the de facto one and seen as a panacea (to the point of becoming memeworthy on SO), but it is just a js library.

Everything that is standardised for scripting (EMCAScript) is included in the browser already, anything else added to other browsers would become non-standard and you'd end up with the cross-browser issues for non-standard browsers (like the IE event model) that influence part of the reason why libraries like jQuery have been created in the first place.

Short answer: they could be included, but they shouldn't.


答:
You tried to resolve it yourselves, but here is an impasse. The person in charge needs to: step in, make a decision, and enforce the decision.

There should have been some specification that this was needed or not needed (This may be based on the person in charge's decision). This is a good candidate to put on a website security checklist. The admin should know whether or not this is set correct.

Good catch by the programmer. Keep up the fight.


问:
Models per database table?
I am using codeigniter, and have found myself in a similar situation where I have repeated Model methods.
I am creating a Model per Controller. But I would creating a Model per database table be considered good practice? That way methods aren't written twice.

Instead of Model per Controller or Several small Models that  are shared.

Example if I have a model method get_user($user_id) I could write it on users_models.php ...

One of the downsides I see of this is that I might have to call several models, rather than just controllername_models.php .

Could loading several models where several methods might not be used from a controller affect performance and speed? What could be the best way to tackle this down?

Note: There are similar question, but they do not cover the ground of Model per database table.

答:
In general you should create your models not per table or per controller but per business object. Sometimes it maybe a 1:1 relationship with your tables structure or with your controllers, but not necessary.

In your example you may have one users_model class that is called from several controllers. This is fine and sometimes even desirable. However in most cases the users_model class will get its data from several tables.

For example, last_login_date property of the users_model class can (not must) be obtained from a separate user_audit table that has one-to-many relationship with the main users table.

And I would say if you have one SQL table per business object then it is most likely that your database structure is not normalized.

Title: Models per database table?


答:
Actually, what you're describing exists already for years. It's called caching. And it's available not only for JQuery, but for everything your browser may download.

Then sites could check "local" first, before CDN, before finally defaulting to downloading from the website server itself.

This is exactly what every browser does. It checks local cache first, then downloads one from CDN if need. With proper cache configuration, there is even no roundtrip to the server (to check for newer version) for months.

Including JQuery into the browser setup would:

Add unnecessary complexity to the browser application and setup,

Add unnecessary complexity to update process,

Increase the number of updates in order to keep the up-to-date version of JQuery, even for people who don't need it,

Add confusion: why JQuery and not Prototype, or some other framework, image, CSS file, etc.?

etc.

Increasing the complexity of a software product with no benefit in terms of features, performance, etc. is an extremely bad idea.


答:
QA for sure, often both.

Now, my company generally works with large companines producing B2B software so the client almost always does their own test pass after we deliver something to them.

What they test is up to them, but if there are performance requirements (or performance change requests) then we must do perf testing to know that we actually met those requirements. Often the client does as well (though I've seen them just run through a scenario and say 'fast enough' - which it was).

So the straight forward answer is: QA always, and the client can decide if they want to as well.

Title: Is performance testing applicable to a QA or business user testing?

Body: Performance testing is something that I, as a developer do when optimizing. However, if the change is purely optimization, should the QA or business user perform their own performance testing? I would reckon they should, aside from testing that the functionality remains the same. If that's the case, is it acceptable for them to test via manually timing the response time from the screen? </p>


答: It sounds like developers need a second PC to use as testing sandbox. This can be inconvenient to test development tools, but it is safer. Think of your main PC as you would a production server. If you blow it up the test PC, you fix it. This way you can continue working on the corporate standard machine maintained by the staff.</p>

Title: Right Amount of Security on Machine


问:
REST - Tradeoffs between content negotiation via Accept header versus extensions
I'm working through designing a RESTful API.  We know we want to return JSON and XML for any given resource.  I had been thinking we would do something like this:

```<code>GET /api/something?param1=value1
Accept:  application/xml (or application/json)
</code>```

However, someone tossed out using extensions for this, like so:

```<code>GET /api/something.xml?parm1=value1 (or /api/something.json?param1=value1)
</code>```

What are the tradeoffs with these approaches?  Is it best to rely on the accept header when an extension isn't specified, but honor extensions when specified?  Is there a drawback to that approach?

答:
The proper official RESTful approach is to use Accept: header.

However, you have to be careful not to break cacheability, which is one of REST's requirements. You need to have Vary: Accept header and cache which understands it. In ideal world you'd have it, but in real life your millage may vary. So the second solution isn't as clean, but it might be more practical.

Also, note that some very old browsers used to ignore headers, relying on the extension instead.


答:
Technically it doesn't really matter - your web server will be able to pass process it appropriately as it looks like. (I am assuming this but doesn't look like a showstopper).

However, philosophically - the first approach is the only approach. In REST, the URL actually only points to a URI - which is only a resource. Think for a moment this resource same as object in object oriented programming. You talk to this resource through only 4 methods (aka GET/POST/PUT/DELETE -or if anything that transport allows) but that method doesn't become description of object. Same way, the aspects the return value is not the URI. The object is still something and not something.xml or something.json

Suppose if you don't want to use Accept header, but if you still want to be truly REST philosophically, i wont mind something like:

```<code>GET /api/something?parm1=value1&return_type=xml
</code>```

as opposed to

```<code>GET /api/something.xml?parm1=value1 (or /api/something.json?param1=value1)
</code>```

But as i said, this difference is only philosophical.

Title: REST - Tradeoffs between content negotiation via Accept header versus extensions

Body:
I'm working through designing a RESTful API.  We know we want to return JSON and XML for any given resource.  I had been thinking we would do something like this:

```<code>GET /api/something?param1=value1
Accept:  application/xml (or application/json)
</code>```

However, someone tossed out using extensions for this, like so:

```<code>GET /api/something.xml?parm1=value1 (or /api/something.json?param1=value1)
</code>```

What are the tradeoffs with these approaches?  Is it best to rely on the accept header when an extension isn't specified, but honor extensions when specified?  Is there a drawback to that approach?

Body:
Technically it doesn't really matter - your web server will be able to pass process it appropriately as it looks like. (I am assuming this but doesn't look like a showstopper).

However, philosophically - the first approach is the only approach. In REST, the URL actually only points to a URI - which is only a resource. Think for a moment this resource same as object in object oriented programming. You talk to this resource through only 4 methods (aka GET/POST/PUT/DELETE -or if anything that transport allows) but that method doesn't become description of object. Same way, the aspects the return value is not the URI. The object is still something and not something.xml or something.json

Suppose if you don't want to use Accept header, but if you still want to be truly REST philosophically, i wont mind something like:

GET /api/something?parm1=value1&return_type=xml

as opposed to

GET /api/something.xml?parm1=value1 (or /api/something.json?param1=value1)

But as i said, this difference is only philosophical.


问:
is it programmer's duty to disable directory listing?
Recently I have project in which a directory listing is enabled, due to which some scripts can be seen by outside world. I asked website administrator and he said it's not his responsibility, its the programmer's job. I also asked programmer about this and he said that the script is actually a cron job, and according to him, he has to test the script on webserver as there is a difference between development and production environment, so he placed there to test that. According to him, there was no direct link as he assumed directory listing is disabled and taken care by administrator.

Who is the right person to do this?

答:
I've dealt with similar situations before. Here's what you do:

Call a meeting. Invite everyone possibly involved, including a manager.

Run the meeting: Lay out the situation for everyone, and suggest a couple of possible solutions.

Make sure that SOMEONE commits to solving the problem during the meeting.

Email notes after the meeting to all attendees reminding them who will be fixing the problem.


答:
If it can be done programmatically, then it should be written into the app by the programmer.

If it has to be done through an administrative process, and you have an 'administrator', then the administrator should do it.

Either way, the two roles should be complementary, not adversarial.


问:
What is meant by a primitive data type?
My understanding of a primitive datatype is that

It is a datatype provided by a language implicitly (Others are user defined classes)

So different languages have different sets of datatypes which are considered primitive for that particular language. Is that right?

And what is the difference between a "basic datatype" and "built-in datatype". Wikipedia says a primitive datatype is either of the two.

PS - Why is "string" type considered as a primitive type in SNOBOL4 and not in Java ?

答:
Primitives are fundamental data types provided by the language itself. Example in C language are int, float, char data types. It is provided as fundamental part of the language.

Non primitives are user defined variables or objects. For example you can define an object which store data or you can use struct in C to define you own variables. These are not primitive because you had to define them first in order to used them.

Examples: Employee, Student,
  a_very_large_number_that_you_defined_yourself

Edit with more explanation and addressing the comment
I think of primitive as variables that came originally with the language and not variables like String in C++ which you have to declare using the New keyword. That makes it an object so a String would not be a primitive.

Answer you comment: It probably has to do with implementation of the variable. If it was part of language core, it is primitive. If not it is not. Example is String in C++. This is not a core variable and is declared using New keyword. So it is not primitive.

Title: What is meant by a primitive data type?


答:
A 'primitive' data type means that you have a value stored in memory--this value has no methods or internal structure. A primitive can only be operated on by external operations.

In Java, primitives are numbers (int, long, etc.) and char. http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

If your value has structure (I'm thinking of struts here) then it is not a primitive. If it has methods (an object or class) it is not a primitive.

Title: What is meant by a primitive data type?

Body:
My understanding of a primitive datatype is that

It is a datatype provided by a language implicitly (Others are user defined classes)

So different languages have different sets of datatypes which are considered primitive for that particular language. Is that right?

And what is the difference between a "basic datatype" and "built-in datatype". Wikipedia says a primitive datatype is either of the two.

PS - Why is "string" type considered as a primitive type in SNOBOL4 and not in Java ?


答:
It kind of depends on the language.

For example, in languages like C and C++, you have a number of built-in scalar types - int, float, double, char, etc.  These are "primitive" in the sense that they cannot be decomposed into simpler components.  From these basic types you can define new types - pointer types, array types, struct types, union types, etc.

Then you have a language like old-school Lisp, where everything is either an atom or a list.  Again, by the above definition, an atom is "primitive" in the sense that it cannot be decomposed into something simpler.

Edit

As far as I'm concerned, the terms "primitive", "basic", and "built-in" are pretty much interchangeable.  If you want to get really pedantic, though, you can distinguish between types that are "built-in" (those explicitly provided by the language definition) and types derived from the built-in types that are still "primitive" or "basic" in that they cannot be decomposed into simpler elements.  C's typedef facility allows you to create new type names for existing types.  Ada allows you to create new scalar types that have constraints on them.  For example, you can derive a Latitude type from the built-in floating type, with the constraint that it can't take on values outside the range [-90.0, 90.0].  It's still a primitive or basic type in that it cannot be broken down into any simpler components, but since it's user-defined, it's not considered a "built-in" type.

Again, these concepts are a little fuzzy, and it really depends on context.  For example, the notion of a "built-in" type is meaningless for a typeless language like BLISS.

Title: What is meant by a primitive data type?


答:
A primitive is a basic data type that's not built out of other data types.  It can only represent one single value.  All primitives are built-in data types by necessity, (the compiler has to know about them,) but not all built-in data types are primitives.

In some languages, the compiler has built-in knowledge of certain types that are built out of other things, because it has to be able to treat them in a special way.  Examples would be the Variant in Delphi and Visual Basic (and the Boo equivalent, "Duck") and the base object class in most OO languages.

Title: What is meant by a primitive data type?


问:
Is it a good idea to write requirements specifications by stories?
We're using agile methods in my current project at the moment, and we have heaps of stories like these:

As an assistant, I want to pay a customer a refund so that they can
get some money when they request it

As a customer, I want to pay for a purchase so that I can receive my
item.

How we've done it so far is to pick the most important stories every sprint and elaborate it into a number of formal requirements specs (we group some of the stories that are similar together in the same spec). Depending on the story, it could just be a button on a screen or an entire workflow.

The problem now is that because there's so many stories, it's not immediately clear, for any part of the system which stories relate to it.

It works at the time of developers, every sprint the devs just get a spec outlining what they need to do and the changes they need to make. But in terms of maintaining this story list and for testing, its starting to get really hard tracking bugs and in general just maintaining the specs, because one piece of functionality in the screen might have been documented in a number of different places due to it being split by story.

Is writing specs based on stories a good idea? Have we written the stories in the wrong way?

答:
```<code>> Writing specs by stories? a good idea?
</code>```

Yes if you can manage interdependencies and priorities of your stories.

Here is an article about story maps that can help you to order and mange many userstories.

Body:
> Writing specs by stories? a good idea?

Yes if you can manage interdependencies and priorities of your stories.

Here is an article about story maps that can help you to order and mange many userstories.


答:
From the Java perspective:

In Java, there is a very clear distinction between primitive and non-primitive types.

A variable of a primitive type directly contains the value of that type (in other words, they are value types).

A variable of a non-primitive type doesn't contain the value directly; instead, it is a reference (similar to a pointer) to an object. (It is not possible in Java to create user-defined value types).

Java has eight primitive types: byte, short, int, long, char, boolean, float and double. Anything else is a non-primitive type.

Title: What is meant by a primitive data type?


答:
Now this is where abstraction plays a major role. You need to look at the stories wwith respect to the relevant perspective. Gather the nouns and verbs in the statements and confirm them. You cannot base your models upon personal assumptions.Also pay attention to detail.

Writing specs based upon user stories cannot be accurate. You need to dig extra detail and sometimes ignore detail which is not relevant. Specs should be written when your model is complete and accurate upon confirmation of your analyst.


问:
What's the best way to modularize a User schema so it's generic
I have a database design question. Basically I want to be able to create a schema for a User model, then use this User model in other models that extend User but I want to design it in such a way that it's generic enough to be used in every application.

For example a Profile or Account model might extend User, and in both cases they will be different based on the web application you are designing but the core credentials of User should never be different across any web application.

What fields do you think should be in the User model?

I think the bare minimum to successfully handle authentication would be:

email (the login unique identifier)

salt (obviously!)

password (duh)

lostToken (a hash to verify lost password functionality)

role (member, admin, editor, etc.. IMO this list of roles would differ between sites however it's too important to the User model not to have here?)

Now we get into other interesting fields that are still very very useful:

createdAt (when the account was created)

ipAddress (track the ip when the account was created)

refererUrl (which site it came from)

lastLoggedIn (the last time the user logged in)

isOnline (is the user currently online)

And even more fields that are still pretty useful:

username (might not be used on every site)

number of consecutive logins (similar to the stack network)

I think anything else like social data (likes, votes, profile views), badges/achievements, the last time they updated their profile/account/whatever, and other info like their name belong in the per-site Profile model.

What do you think?

Edit:
I fully understand that this question is partly subjective but I do think there's definitely room for discussion.

答: My first instinct would be to reuse an existing user authorization mechanism, rather than writing one.  Then I would skip the rest until I had firm requirements.  Premature generalization is just as bad as premature optimization.</p>


问:
Is there a performance benefit to using immutable objects in a scripting language?
As I understand it, writing your objects in an immutable style can help the performance of your program for compiled languages, as the compiler tends to rewrite your code in single static assignment form under the hood anyway.

Is there a performance benefit to using immutable objects in an interpreted language like Python or PHP?

I understand there may be readability or code quality benefits from immutability, but I am asking specifically about performance.

答:
In Python there is nothing in the language itself to mark an object as immutable so no hints can be given to the interpreter for optimization.

If the process is threaded and the object has "protected" properties then programmers don't need to worry about synchronization when using that object so there could be a performance gain.


答:
In CPython, allocation of tuples (basically immutable lists) can be slightly faster than an allocation of the equivalent mutable type with the same items. I vaguely remember similar rumors about immuable sets, but timeit didn't confirm it. Tuples can also be smaller than lists, from a few bytes to 50% (if you hit a spot where the list had to resize, and doubled its capacity to speed up future growth). Moreover, tuples and sets are - in some contexts - subject to peephole optimizations which allow creating the object once and re-using it instead of re-building it every time.

But that's mostly peanuts. It's not why we use these types, at least usually. If ever, these differences are only invoked when seriously optimizing. It's not an aspect I usually consider when deciding for either, especially since there are other benefits, not to mention the enormous semantic impact.

Title: Is there a performance benefit to using immutable objects in a scripting language?

Body:
As I understand it, writing your objects in an immutable style can help the performance of your program for compiled languages, as the compiler tends to rewrite your code in single static assignment form under the hood anyway.

Is there a performance benefit to using immutable objects in an interpreted language like Python or PHP?

I understand there may be readability or code quality benefits from immutability, but I am asking specifically about performance.


答:
Approach a trivial defect, e.g., a NullPointerException.  Avoid anything regarding concurrency at first, anything that by its nature will involve understanding a lot of the code at once.

Once you've fixed a few bugs you'll probably have a pretty good idea.  Works for me, at any rate.