问:
What resources about business should an internal IT department programmer be familiar with
I am developer / analyst in an internal IT department at a medium sized business. I have to deal with business people all the time and many of the things I create can have profound impacts on the business. I am starting to regret not taking any business classes in college because I don't understand the first thing about running a business so I don't always understand what people are wanting, the best I can do is "think through it".

Does anyone have suggested methods of learning this stuff, maybe some resources. And please don't just say to ask people who work here. I have tried that before and I get no where.

答:
Good question. I work for banks mainly, but I got there without taking classes in finance. I wasn't even aware of banks beyond what you find in the high street when I first left college. I do a lot of work directly for the business though, so I have to speak some of the lingo.

Things that will help.

First, ask questions. People won't think you are ignorant or irritating or what ever, just ask the questions, get the information and use that to deliver what they want.

Second, focus on delivery. Always keep in mind that the goal is to get software out to the users that solves what ever problem they first brought to you. Use prototypes, mock stuff up in Excel, you that to get early feedback from the users, use that to learn. If you keep that eye on delivery, when you are talking to the business they will get the impression that you are working towards a solution and they will be able to see evidence of that. They will then be more willing to help, and will pick up on errors before they become a problem.

The obvious one is read a book on your area of business. As I said, I'm in banking, so I have books on everything from options to stock lending. With that in mind,

Third, you don't need to know as much as some would think. You don't need to know how to turn oil in to rubber to be able to change a tyre and software is much the same. Honestly a lot of the stuff is reconciliation, getting numbers from somewhere, extracting others and then finding out why they are different using Excel. That's a skill that will put dinner on the table for the foreseeable future.


答:
I am not convinced any general business information will be much help.  There is a big disconnection between the theory about how businesses should operate and how things are actually done.

The best source for information is from the people who will be using your application.

After that I would suggest starting with the type of industry your business operates in.  There are a lot of highly regulated industries where there are specific guidelines you must follow with the data.

Financial?  Sarbanes–Oxley is good to know.

Healthcare?  read up on HIPAA.

Granted these are very complex topics and it is not practical to learn every in and out, but you would be surprised how just having some basic knowledge helps.

ContentLicense: CC BY-SA 3.0

Title: What resources about business should an internal IT department programmer be familiar with

Body:
I am developer / analyst in an internal IT department at a medium sized business. I have to deal with business people all the time and many of the things I create can have profound impacts on the business. I am starting to regret not taking any business classes in college because I don't understand the first thing about running a business so I don't always understand what people are wanting, the best I can do is "think through it".

Does anyone have suggested methods of learning this stuff, maybe some resources. And please don't just say to ask people who work here. I have tried that before and I get no where.


问:
What happened to the this type of naming convention?
I have read so many docs about naming conventions, most recommending both Pascal and Camel naming conventions. Well, I agree to this, it's ok. This might not be pleasing to some, but I am just trying to get your opinion on why you name your objects and classes in a certain way.

What happened to this type of naming conventions, and/or why are they bad?

I want to name a structure, and I prefix it with "struct". My reason is that, with IntelliSense, I see all structures in one place, and anywhere I see the struct prefix, I know it's a "struct":

```<code>structPerson
structPosition
</code>```

another example is the enum, although I may not prefix it with "enum", but maybe with "enm":

```<code>enmFruits
enmSex
</code>```

again my reason is that in IntelliSense, I see all my enumerations in one place.

Because .NET has so many built-in data structures, I think this helps me do less searching. Note that I used .NET in this example, but I welcome language agnostic answers.

答:
Joel wrote a good article on this

Making Wrong Code Look Wrong

In short, you want to use Apps Hungarian, not Systems Hungarian notation.

Because really, who cares if it's an int, or a long, or whatever, all I care about is the "kind" of value, not it's type.


答: That is Hungarian notation. Its still used but much less so now in languages where the IDE helps you with types. (ie C# Java). In those langagues the information given by the prefix is already provided by the IDE so is deemed unnecessary. </p>

Title: What happened to the this type of naming convention?

Body:
I have read so many docs about naming conventions, most recommending both Pascal and Camel naming conventions. Well, I agree to this, it's ok. This might not be pleasing to some, but I am just trying to get your opinion on why you name your objects and classes in a certain way.

What happened to this type of naming conventions, and/or why are they bad?

I want to name a structure, and I prefix it with "struct". My reason is that, with IntelliSense, I see all structures in one place, and anywhere I see the struct prefix, I know it's a "struct":

```<code>structPerson
structPosition
</code>```

another example is the enum, although I may not prefix it with "enum", but maybe with "enm":

```<code>enmFruits
enmSex
</code>```

again my reason is that in IntelliSense, I see all my enumerations in one place.

Because .NET has so many built-in data structures, I think this helps me do less searching. Note that I used .NET in this example, but I welcome language agnostic answers.


答:
The "type" of types shouldn't matter. class, struct, and enum are only meaninful to the definition - you shouldn't be using something differently just because it's a struct and not a class, nor should you refer to it as one.

I think the most sensible way to use "hungarian notation" is to only seperate types from functions:

types

instances of types

functions


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

答: Keeping them separate does force you to think about the system dependencies when adding new code. This is a good thing.  When you have to think about the  whole architecture, you are less likely to make a decision that tangles it up.  </p>

ContentLicense: CC BY-SA 2.5


问:
Get 100 highest numbers from an infinite list
One of my friend was asked this interview question -

"There is a constant flow of numbers coming in from some infinite list
  of numbers out of which you need to maintain a datastructure as to
  return the top 100 highest numbers at any given point of time. Assume all the numbers are whole numbers only."

This is simple, you need to keep a sorted list in descending order and keep a track on lowest number in that list. If new number obtained is greater than that lowest number then you have to remove that lowest number and insert the new number in sorted list as required.

Then question was extended -

"Can you make sure that the Order for insertion should be O(1)? Is it possible?"

As far as I knew, even if you add a new number to list and sort it again using any sort algorithm, it would by best be O(logn) for quicksort (I think). So my friend told it was not possible. But he was not convinced, he asked to maintain any other data structure rather than a list.

I thought of balanced Binary tree, but even there you will not get the insertion with order of 1. So the same question I have too now. Wanted to know if there is any such data structure which can do insertion in Order of 1 for above problem or it is not possible at all.

答:
A hundred numbers are easily stored in an array, size 100. Any tree, list or set is overkill, given the task at hand.

If the incoming number is higher than the lowest (=last) in the array, run over all entries. Once you find the first that is smaller than your new number (you can use fancy searches to do that), run through the remainder of the array, pushing each entry "down" by one.

Since you keep the list sorted from the beginning, you don't need to run any sort algorithm at all. This is O(1).

OwnerDisplayName: Sachin Shanbhag


答:
The people you work with are your best resource for understanding their business needs. Businesses get and keep a competive advantage by doing things differently than their competitors, you won't find that informtion in books. Perhaps the problem is how you ask them or what you ask them.

First, many developers come across as arrogant idiots who think everyone else is stupid. This attitude tends to make people less than cooperative about helping you learn. So first things first, check your attitude and your body language and your tone of voice when talking to the users to get requirements.

Next, find the person who has the most stake in the product you are tasked with developing. Have him or her give you a Power Point presentation on the business needs the application will meet. Tell him that you need a better understanding of what they do in order to help them do it better. This is not in the terms of the requirements but just in terms of an understanding of what the jobs of the users who will be using the system are. Ask if there are regulartory requirements they have to follow. Ask to get a copy of them or a link to them if it is too much to print out.

Ask about industry trends; subscribe to reading lists about your industry (I read the news in my industry, it helps me make suggestions for possible application changes that can keep us ahead of the competition).

If the product contains data that will need to be audited, talk to some auditors about what they need to see and more importantly why they need to see things that way. Learn something about IT auditing, it is an interesting field that will serve you well in developing business applications. Pay particular attention to the concept and practice of internal controls. These are critical in any financial application.

Spend some time observing the actual users right now as they work. Take notes. You will see many things that no one ever thinks to tell you in a meeting. Don't just talk to managers about what needs to be done. Talk to the actual users where-ever possible. Invariably they will perceive the application differently than managers will. It has to work for them though in order for the managers to see the data they want to see. Ask them what problems they have with the current solution. Again  they will tell you things the managers would never think to tell you.

Getting back to the managers, ask about reporting needs. Business applications tend to have a data entry need and reporting need. You aren't done until both have been discussed. It does no good to put data into a database if it can't be gotten back out in the way the managers need to see it.

When they tell you something needs to happen that you don't understand, ask for further details.  Ask what problem they hope to address with this change. Often you will find that they are suggesting  a solution that won't completely solve their problem. In fact always ask for further details, it is a rare user who will tell you everything you need to know without extensive questioning.

Pay attention to edge cases when you talk to them. If they say something needs a managers approval for instance, ask what needs to happen if the manager doesn't approve.

Ask for reading material or websites that talk about the professional needs of the users. Ask for copies of any corporate regulatiosn that affect the application, any laws or government regulations that affect the application and any paper forms that data entry people will be entering data from (It's amazing how much easier it is to enter data when the form and the paper form have the fields in the same order, I was entering voter application data once and the form was firstname  lastname and the data entry weas last name first name, imagine how many errors that creates.).

Talk about what information the user needs at his or her fingertips at all times to do a good job. Do the tasks need to be done in a set order or can they skip around?

Finally, sketch out prototypes and take them back to the stakeholders and discuss again. Often people can't visualize very well, help them see how the program will work before you spend any time building it. Do this on paper as a very rough sketch, so they don't think that just because you have a pretty page built that the application is finished. Users think the Interface is the whole application, if it looks finished, it is finished in their minds.

Start building a list of questions to ask that show you are thinking beyond the data entry. Ask about security of the data, how private is the data and who should have access to see or change it. Think about how the application will work over time not just what needs to be there for launch. Do you need admin pages to keep the drop down lists up-to-date as the items to pick from change?


答:
Your IT department management should define roles and subject areas. You can be part of a team addressing 1 or more subject areas, then you could focus on those areas. If you define the business to business functions (high-level such as Accounting, Marketing, etc.) and you focus on one of those, then detail the business processes that goes into each of these business areas you can understand the business.

However, this is not a practical way for an individual to cover an entire organization, thus my suggestion to focus on a part of the business.

Once your business areas of interest are defined, you may study the software, the terminology, and the business processes that goes into this area and start going deeper into the details. However, this effort must be organized and coordinated with management otherwise, you will waste your time and other people time for only a small gain.

Also note that it is nice to know, but you must have an objective for acquiring the knowledge. Accordingly set goals of what you have to know and why is it important for you and for the business to spend time on acquiring this knowledge. For example, I would not go to marketing and ask them for hours about how they set up campaigns if I am not going to use this information.

Some companies offer training classes for new business hires. Consider joining one of these courses or using its materials, they are usually focused and short.


答: If the types have appropriate names in the application domain, then the underlying representation is not important.  I much prefer code that reads like either prose or mathematics.  In English we say "Post Office", not "officePost", so I prefer "EmailService" to "serviceEmail".  </p>


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

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

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

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

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

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

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

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

答:
Similar to what Rachel said, my mostly-MVVM application has a Presenter to handle switches between windows or pages.  Rachel calls this an ApplicationViewModel, but in my experience, it generally has to do more than just be a binding target (such as receiving messages, create Windows, etc.) so it's technically more like a traditional Presenter or Controller.

In my application, my Presenter starts with a CurrentViewModel.  The Presenter intercepts all communication between the View and the ViewModel.  One of the things the ViewModel can do during an interaction is return a new ViewModel, which means a new page or a new Window should be displayed.  The Presenter takes care of creating or overwriting the View for the new ViewModel and setting the DataContext.

The result of an action can also be that a ViewModel is "complete", in which case the Presenter detects this and closes the window, or pops this ViewModel off the VM stack and goes back to displaying the previous page.


问:
What should you include in a development approach document?
I'm in the middle of co-producing a "development approach" document for off-shore resources as they ramp up onto our project.

The most recent (similar) document our company has used is over 80 pages, and that does not include coding standards/conventions documents.

My concern is that this document will not be consumable and will therefore fail.

What should be in a development approach document?
Are there any decent guidelines on this topic?

EDIT: The development approach document should detail the practices and techniques that will be used by software developers while software is designed, built, and tested.

答:
What you are calling the "development approach document" is typically called the Software Project Management Plan. (I've also heard it called the Software Project Plan or the Software Development Plan.) With those terms, you should be able to Google for some samples that are out there. As Victor Hurdugaci and Donal Fellows mentioned, the Software Project Management Plan you write will be (1) tailored to your needs and (2) updated as a living document as the situation evolves. That being said, writing one from scratch can be tough if you've never written one before and you don't know what else should go into it.

There is some guidance through IEEE Standard 1058 (IEEE Standard for Software Project Management Plans, 1998). There's a copy of the standard posted here. I find this plan to be pretty heavyweight, but it is a decent place to get ideas - and you might need the extra weight if you want it all in writing for a team that is offshore. There's also a pretty good outline -- and some great narrative on how to plan software projects -- in a book I turn to quite often for traditional (non-agile) software projects: Quality Software Project Management by Futrell, Shafer, and Shafer.


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

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

答:
Ob: IANAL, and for legal advice you should go find one.

That said: to answer the question from the title "Is a program linked against an LGPL library in linux still under GPL?"  The answer is no, because it never was.

Merely running a program on Linux does not make it subject to GPL.  There are all sorts of closed-source programs that run on Linux.

Similarly linking to an LGPL library does not make you subject to GPL, but generally only to LGPL.

So for your case, if you are only using LGPL code, and furthermore linking dynamically as per LGPL section four removes your obligation to supply source code for the library itself.

The summary from the FSF about why you should not in their opinion use the LGPL for a new work is

The GNU Project has two principal licenses to use for libraries. One
  is the GNU Lesser GPL; the other is the ordinary GNU GPL. The choice
  of license makes a big difference: using the Lesser GPL permits use of
  the library in proprietary programs; using the ordinary GPL for a
  library makes it available only for free programs.

Which attempts to make it clear, that LGPL libraries are not infectious like the GPL itself.

If therefore on the other hand, you are linking to full GPL libraries from your own code, then the situation is quite different, and yes you are obligated to open your program, as you should have been supplying (or offering to supply) the code all along.


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

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

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

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

答:
Take a look at Wikipedia page on 8-bit architecture.  Although character sets could have been 5-, 6-, then 7-bit, underlying CPU/memory bus architecture always used powers of 2.  Very first Microprocessor (around 1970s) had 4-bit bus, which means one instruction could move 4-bits of data between external memory and the CPU.

Then with release of 8080 processor, 8-bit architecture became popular and that's what gave the beginnings of x86 assembly instruction set which is used even to these days. If I had to guess, byte came from these early processors where mainstream public began accepting and playing with PCs and 8-bits was considered the standard size of a single unit of data.

Since then bus size has been doubling but it always remained a power of 2 (i.e. 16-, 32- and now 64-bits)  Actually, I'm sure the internals of today's bus are much more complicated than simply 64 parallel wires, but current mainstream CPU architecture is 64-bits.

I would assume that by always doubling (instead of growing 50%) it was easier to make new hardware that coexists with existing applications and other legacy components.  So for example when they went from 8-bits to 16, each instruction could now move 2 bytes instead of 1, so you save yourself one clock cycle but then end result is the same.  However, if you went from 8 to 12-bit architecture, you'd end breaking up original data into halfs and managing that could become annoying. These are just guesses, I'm not really a hardware expert.

ContentLicense: CC BY-SA 4.0


问:
is there a term for doing this: func1(func2(), func3());
I know that obj.func1().func2() is called method chaining, but what is the technical term for:

```<code>func1(func2(), func3());
</code>```

Where return of a function is used as an argument to another.

答:
As @Karl Bielefeldt points, it's called function composition in Math.

There is NO technical term for this thing in programming. And I think this is a Good thing, because it indicates that the operation is normal and Orthogonal.

Orthogonality in programming languages means that you can use an instruction/operation independent of it's context. For example, you can call a function/method in all of the following ways, and it would behave the same...

```<code>f1()(f2(), f3());

x = y + f4();

if ( f5() && !f6() ) doSomething();

f7() = f8() + f9(); // in C++ when a function returns a reference

x = f10() ? f11(f12(f13(x))) : f14();
</code>```

You can read more on Orthogonality in Programming on Wikipedia, and there's a question on StackOverflow on this.

Body:
As @Karl Bielefeldt points, it's called function composition in Math.

There is NO technical term for this thing in programming. And I think this is a Good thing, because it indicates that the operation is normal and Orthogonal.

Orthogonality in programming languages means that you can use an instruction/operation independent of it's context. For example, you can call a function/method in all of the following ways, and it would behave the same...

f1()(f2(), f3());

x = y + f4();

if ( f5() && !f6() ) doSomething();

f7() = f8() + f9(); // in C++ when a function returns a reference

x = f10() ? f11(f12(f13(x))) : f14();

You can read more on Orthogonality in Programming on Wikipedia, and there's a question on StackOverflow on this.


答:
According to my information the word byte itself was derived from the phrase by-eight which was eight (8) bits words.
the convenience we find in 8 bits words is the conversion to hexadecimal values since the value 00000000 = 00 & 11111111 = FF (Dec 255 for unsigned and -127 for signed)
it is easy to do all arithmetic operations on such structure including bit-wise operations.

I see bytes (8 bits words) as a natural evolution of word sizes from catastrophically small 3 bits up to ridiculously big 60 bits words

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

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

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

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

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


答:
The LGPL exists specifically to allow you to use GPLed source code, without the more restrictive terms of the full GPL.

This is usually applied to Macros,scripts libraries, and complex header files where without including the source in your code the rest of the GPLed library would be unusable.

Title: Is a program linked against an LGPL library in linux still under GPL?

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

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


答: In mathematics, it's called function composition.  I don't think I've heard the term applied to programming, though.  That may be because the usage is largely avoided for a few reasons.  It can introduce strange bugs when the functions have side effects, due to compilers being free to evaluate func3 before func2.  It's more difficult to debug because you can't set breakpoints on or print out intermediate results, and most people just plain find it harder to read.</p>

Title: is there a term for doing this: func1(func2(), func3());

Body:
I know that obj.func1().func2() is called method chaining, but what is the technical term for:

```<code>func1(func2(), func3());
</code>```

Where return of a function is used as an argument to another.


问:
What's the difference between MariaDB and MySQL?
What's the difference between MariaDB and MySQL? I'm not very familiar with both. I'm primarily a front end developer for the most part.

Are they syntactically similar? Where do these two query languages differ?

Wikipedia only mentions the difference between licensing:

MariaDB is a community-developed branch of the MySQL database, the
  impetus being the community maintenance of its free status under GPL,
  as opposed to any uncertainty of MySQL license status under its
  current ownership by Oracle.

答:
It's a fork - two separate projects starting from the same original codebase but moving in separate directions.  This has happened quite frequently with the open source projects where Oracle has bought the sponsoring companies.

To my understanding MariaDB is maintained and enhanced by the original MySQL developers, and MySQL is maintained and enhanced by Oracle.  It depends on who you want to do that job.


问:
Inversion of Control in ASP.NET MVC
I was going to refactor my ASP.NET MVC application and inject some IoC.  Last time I was using IoC, Unity was all the rage, but I hated it.  It was difficult to setup and had very nondescript errors.

Does anyone have any suggestion or preferences?

答:
I'm surprised nobody mentioned Spring.NET ? It's been available for a long time now, and it has the advantage of being based on the Java Spring Framework (based on the IOC "idea", and separation of packages/namespaces, there is no Java in Spring.NET) as for its maturity and ease of use. Also, if you happen to use both languages in your professional environment, it's great to have some common tools/API's between both.

It integrates pretty well with NHibernate, provides AOP programming tools and you can easily make it work with ASP.NET MVC 2/3.

As for Unity, I've never used it so I can't say.

I may just add that there also is the LinFu Framework, which is a bit more lightweight than Spring. There is a great tutorial on how to integrate LinFu with ASP.NET MVC courtesy from Thomas Weller. I also used LinFu for one of my personal projects and it was really easy to work with.

Title: Inversion of Control in ASP.NET MVC


答:
You don't 'inject' IoC into anything. Inversion of Control, or more specifically Dependency Injection, is a technique where you inject services into consumers - preferably via Constructor Injection.

In ASP.NET, all you need in order to do that is a custom IControllerFactory. You can, however, implement that IControllerFactory with a DI Container to make things a little easier. Here's a list of various DI Containers for .NET.

Title: Inversion of Control in ASP.NET MVC

Body:
I was going to refactor my ASP.NET MVC application and inject some IoC.  Last time I was using IoC, Unity was all the rage, but I hated it.  It was difficult to setup and had very nondescript errors.

Does anyone have any suggestion or preferences?


问:
Quick and Good: ( Requirement -> Validation -> Design ) for self use?
How to casually do the required Software Engineering and designing?

I am an inexperienced developer and face the following problem:

My company is a start up and has no fix Software engineering systems.

I am assigned tasks with not very clear and conflicting requirements.

I don't have to follow any designs or verify requirements officially.

Problem:

I code all day and finally get stuck where requirement conflicts and I have to start over again.

I can-not spend a lot of time doing proper SRS or SDD.

How should I:

List out Requirements for myself. (Not an official document)

How to verify and validate the requirements?

How to visualize them?

How to design them with minimum effort? (As its going to be with me only)

I don't want to waste my time coding something that's gonna collapse according to requirement conflict or something!

I don't want to compromise with quality but don't want to re-write everything on some change that I didn't expected.

I imagine making a diagram for my thought process that will show me conflict in the diagram itself, then finally correcting the diagram - I decide my design and structure my code in terms of interfaces or something.

And then finally start implementing my design.

I am able to sense the lack of systematic approach, but don't know how to proceed!

How can I have diagram that I talked about for requirement verification?

答:
Just because you are working alone doesn't mean you may neglect proper engineering techniques, as you seem to have already experienced for yourself.

There is absolutely no way that you can avoid thinking and documenting a proper architecture and design for your components (considering anything but a trivial component). You will have to face changes, your design will have to evolve and you will fail to do so at some point if it only exists somewhere in-between your brain and your code.

What I would suggest in your case is a sort of agile approach. You are not required to create documentation of something for the sake of having it document because some process demands it. So instead, concentrate on what is really important to you. Document only, if you think it will make problems later if left undocumented.

You also cannot avoid managing your requirements. For this several tools exists and you should use one that allows you to spend the least amount of time to get up and running. Tools will also help you in visualization and verification (test coverage, interdependecies, etc..), but they won't help you in validation. Validation is only possible if you have some kind of customer (who may just be your boss in your case).

Finally, the most important point. Your statement "I can-not spend a lot of time doing proper SRS or SDD." is a major flaw in your thought process. Think about the time you waste by re-implementing your work. Think about all the problems you encountered that eventually lead to you posting here. Then think again, if you really are unable to spend time on proper engineering techniques. If your boss tells you to not waste time on that, then it's high-time you sit down for a lengthy discussion, because then you are both on a road to nowhere.


答:
I don't think it's function composition. Function composition means taking two or more functions and turning them into a new function, like f . g . h in Haskell. Note that no function is called at this point.

Personally, I would refer to constructs like func1(func2(), func3()) as "nested function calls".


答:
In one of the companies that i worked, we had this whole process oriented approach with lots of documents (most of which were asked to be filled in by Project Manager). However, in spite of the length and explanations, i realized that it hardly used to help people -the real developers.

So i decided to pull on of myself with a specific objective of "helping the developers". The most important thing i started is to collect most basic questions - the real FAQs.

What i learned is that following matters to most people when they want to adopt certain process, and many things that they may not have prior idea but would appreciate right away if they understand the logic.

Here are the key topics that such a documentation should help:

The process of development to deployment -
How should the code be organized, compiled, published (in the form of DLLs, libraries, executables, installers, web pages and how will they be deployed and tested)?

How should we do version control? (and why if there are newbies).
Understand how the structure of the repository, the code of conduct - when a check-in acceptable and when not, when a version/tag is announced, how the patch, merges will be applied, and what are the cleanliness expectations when a patch or release is declared done

Executing the Methodology -
are we agile, do we do up-front design, which methodology we use? Now given this, it might be a fixed for a given company. Now, for most people, they want to know how we are going to implement it for the given project. This is very specific about the project that will allow people to visualize different milestones and what is potentially important. In a research oriented project - we would want indicate "always validate critical algorithms before building on top of it" in a shrink wrap I would focus on the correctness and importance of features.

Communication responsibilities -
Defining how do you make formal communication - this is not done with whether specific people can talk to each other - but people must have a sense as to what is important enough (problems, design decisions, feature freeze) to be either announce or even debated before proceeding on implementation.

Finally, we must all have a common understanding of code-quality, coding standard and in general what we think is ok or below hygiene level.

I wish I would start off every project with such documents - however, it's not quite easy. But important thing is to address all issues that relate to day-to-day behavior and choices of developers. This goes long way when multiple releases to market needs to be delivered.

Finally, I would also suggest that try to be informal as possible. Usually, the process oriented guys don't quite like informal documents which can potentially be misunderstood outside the context. However, it should be done such a way that it connects the developers.

Title: What should you include in a development approach document?

Body:
I'm in the middle of co-producing a "development approach" document for off-shore resources as they ramp up onto our project.

The most recent (similar) document our company has used is over 80 pages, and that does not include coding standards/conventions documents.

My concern is that this document will not be consumable and will therefore fail.

What should be in a development approach document?
Are there any decent guidelines on this topic?

EDIT: The development approach document should detail the practices and techniques that will be used by software developers while software is designed, built, and tested.


答: In object oriented programming languages, this "Systems Hungarian Notion" hardly has any place at all. Consider languages where everything is an object. You could rightfully use a prefix like "obj" for every variable, since everything is an object. But even if you use "int" and "dbl" for integer and double variables, what about the zillions of other objects? Would you invent a prefix for each and every class in your program and all the libs it uses? Or would you use a completely meaningless prefix like "obj"? Neither option makes much sense.


答:
If you don't take the time for proper development, you will spend 10 times that time fixing the software in production. Worse, you could loose the job and cost your company.

Most of the trouble developers face can be attributed to commitments made about delivery time of a project. Be clear with your management about the need for time.

If the company has no resources, maybe they could:

1-Give priority to the most required parts of the system and ask you to do the top ones in the given time
2-Hire more people to help
3-Buy a ready-made software that works, even if it does not do all the work required

Your questions cover the entire litrature of software engineering and requirements management as well other parts of the software spectrum, so it is impossible to give you a complete answer but here is a quick one.

How should I :

1- List out Requirements for myself. (Not an official document)
     2- How to verify and validate the requirements ?
     3- How to visualize them ?
     4- How to design them with minimum effort ? (As its going to be with me only)

Answer 1: You have to break the business area into smaller ones (if it is big) - document input data and business rules clearly for each in clear and concise language and present it as a readable list. Try to build some use cases for critical activities.

Answer 2: The deliverables of answer 1 above together with the questions you will come up with during finishing the above task will help you ask the customer to work with you on verifying the requirements.

Answer 3: Convert results from 1 and 2 into a class diagram and/or ERD, Use Cases and Sequence Diagrams or BPM diagrams.

Answer 4: Use tools such as ORM, 3rd party GUI components and Code Generators if you could.

You must clearly understand:

System objectives

Different types of users of your system and security implications

What is the best platform for the solution

Documentation is not a waste of time

User communication is a must - Involve them early

Management involvement and communication is a must - Involve them early

Realistic goals and estimations are a must

Good luck

Title: Quick and Good: ( Requirement -> Validation -> Design ) for self use?

Body:
How to casually do the required Software Engineering and designing?

I am an inexperienced developer and face the following problem:

My company is a start up and has no fix Software engineering systems.

I am assigned tasks with not very clear and conflicting requirements.

I don't have to follow any designs or verify requirements officially.

Problem:

I code all day and finally get stuck where requirement conflicts and I have to start over again.

I can-not spend a lot of time doing proper SRS or SDD.

How should I:

List out Requirements for myself. (Not an official document)

How to verify and validate the requirements?

How to visualize them?

How to design them with minimum effort? (As its going to be with me only)

I don't want to waste my time coding something that's gonna collapse according to requirement conflict or something!

I don't want to compromise with quality but don't want to re-write everything on some change that I didn't expected.

I imagine making a diagram for my thought process that will show me conflict in the diagram itself, then finally correcting the diagram - I decide my design and structure my code in terms of interfaces or something.

And then finally start implementing my design.

I am able to sense the lack of systematic approach, but don't know how to proceed!

How can I have diagram that I talked about for requirement verification?


答:
There is always a typical conflict to be balanced when it comes to effort an approaches to documentation. And i would quote your words to say where it is -

I can-not spend a lot of time doing proper SRS or SDD.

vs.

I don't want to waste my time coding something that's gonna collapse
  according to requirement conflict or something !!

This is a common pattern that almost all people face. And when you remove the criteria that there are no other people to share this with, it becomes even more inevitable that we dont go towards documentation. But you have put a light of the question in good spirit - "how to do documentation" than "whether to do documentation"

The point i wanted to make is essentially of balance -between effort and clarity. The simpler approaches might just help.

avoid needless formalism - that makes many people go faster. It's not that typing makes it slow, but search for a formal sentence to put, bothers many.

put things more as bullet points and notes - occasionally, you can do more essay like stuff outside and link it.

Keep dumping all your reading material, thoughts, questions in place, and rapidly evolve into notes and then into topics. Keep organizing. for example initially you may have some idea of what elements should be there in protocol and some other in the classes. over time, grouping and putting all elements related to protocol in a section by itself. Such a way you will keep evolving a formal document.

Keep noting down why. Most important reason why you are documenting (for yourself) is to go back and check why some decisions were made. What alternatives you have when you need this. So that makes it very important when you need to question them.

Last but most important, keep going to same place. most often we don't worry about notes when we get to some speed with. Try to be yourself, than formal but be discipline.


问:
Should a primary key be immutable?
A recent question on stackoverflow provoked a discussion about the immutability of primary keys. I had thought that it was a kind of rule that primary keys should be immutable. If there is a chance that some day a primary key would be updated, I thought you should use a surrogate key. However it is not in the SQL standard and some RDBMS' "cascade update" feature allows a primary key to change.

So my question is: is it still a bad practice to have a primary key that may change ? What are the cons, if any, of having a mutable primary key ?

答:
It is not bad practice to have a key whose values may change.

The properties of a good key include stability. Immutability is ideal but not a prerequisite. Introducing an artificial key for the sake of immutability is bad practice.

Take the example of the International Standard Book Number (ISBN). It is very stable but not immutable: sometime book publishers make mistakes and -- horror! -- duplicate ISBN numbers can occur. Does this mean that ISBN should not be accepted as a candidate key in a computerized database? Of course not. One of the advantages of ISBN is that it has a trusted source that will resolve problems for all users globally.

There are other properies of a good key ISBN has that a meaningless auto-incrementing integer key will lack, e.g. familiarity (everyone in the book trade knows or is familiar with ISBN), verifiable (the ISBN is printed on all modern books), can be validated with reference to the DBMS (ISBN is fixed width and includes a checksum), etc.

Title: Should a primary key be immutable?


问:
Is it good practice to use functions just to centralize common code?
I run across this problem a lot. For example, I currently write a read function and a write function, and they both check if buf is a NULL pointer and that the mode variable is within certain boundaries.

This is code duplication. This can be solved by moving it into its own function. But should I? This will be a pretty anemic function (doesn't do much), rather localized (so not general purpose), and doesn't stand well on its own (can't figure out what you need it for unless you see where it is used). Another option is to use a macro, but I want to talk about functions in this post.

So, should you use a function for something like this?
What are the pros and cons?

答:
It's generally a good idea to use functions to remove duplication in code.

However it can be taken too far. This is a judgement call.

To take the example of your null buffer check, I'd probably say that the following code is clear enough and shouldn't be extracted into a separate function, even if the same pattern is used in a few places.

```<code>if (buf==null) throw new BufferException("Null read buffer!");
</code>```

If you include the error message as a parameter to a generic null checking function, and also consider the code required to define the function, then it's not a net LOC saving to replace this with:

```<code>checkForNullBuffer(buf, "Null read buffer!");
</code>```

Additionally, having to dive into the function to see what it is doing when debugging means that the function call is less "transparent" to the user, and hence can be considered to be less readable / maintainable.

Body:
It's generally a good idea to use functions to remove duplication in code.

However it can be taken too far. This is a judgement call.

To take the example of your null buffer check, I'd probably say that the following code is clear enough and shouldn't be extracted into a separate function, even if the same pattern is used in a few places.

if (buf==null) throw new BufferException("Null read buffer!");

If you include the error message as a parameter to a generic null checking function, and also consider the code required to define the function, then it's not a net LOC saving to replace this with:

checkForNullBuffer(buf, "Null read buffer!");

Additionally, having to dive into the function to see what it is doing when debugging means that the function call is less "transparent" to the user, and hence can be considered to be less readable / maintainable.


答:
If you see it duplicated, you should find a way to centralize it.

Functions are a good way ( maybe not the best but that depends on the language )
Even if the function is anemic as you say that doesn't mean it will stay that way.

What if you have to check for something else as well?

Are you going to find all the places you have to add the extra check or just change a function?

Title: Is it good practice to use functions just to centralize common code?

Body:
I run across this problem a lot. For example, I currently write a read function and a write function, and they both check if buf is a NULL pointer and that the mode variable is within certain boundaries.

This is code duplication. This can be solved by moving it into its own function. But should I? This will be a pretty anemic function (doesn't do much), rather localized (so not general purpose), and doesn't stand well on its own (can't figure out what you need it for unless you see where it is used). Another option is to use a macro, but I want to talk about functions in this post.

So, should you use a function for something like this?
What are the pros and cons?


答:
This is a great use of functions.

This will be a pretty anemic function (doesn't do much)...

That's good. Functions should only do one thing.

rather localized...

In an OO language, make it private.

(so not general purpose)

If it handles more than one case, it is general purpose. Moreover, generalising isn't the only use of functions. They are indeed there to (1) save you writing the same code more than once, but also (2) to break code up into smaller chunks to make it more readable. It this case it is achieving both (1) and (2). However, even if your function was being called from just one place, it might still help with (2).

and doesn't stand well on its own (can't figure out what you need it for unless you see where it is used).

Come up with a good name for it, and it stands fine on its own. "ValidateFileParameters" or something. Now stands fine on its own.


答:
IMO, code snippets are worth being moved to their own functions whenever this makes the code more readable, regardless of whether the function will be very short or will be used only once.

There are of course limits dictated by common sense. You don't want to have the WriteToConsole(text) method with the body being simply Console.WriteLine(text), for example. But erring in the side of readability is a good practice.


问:
When is the right time to join open source project for programmer?
Most of the newcomers in programming start with basic projects to start with programming. Most of the C++ progammers spend some time with puzzles and contests but this is not always helpful. Sometimes you've to spend some time on real projects. Starting your own open source project could be a problem in self-learning for newbie cause of lack of mentors and peers who can't look at your code and give suggestions.  Open source projects can solve this problem, some projects could be best suited for new programmers. Besides everybody is newbie at some point. So i'll try and make this question a bit from beginners perspective.

I tried few questions on stack overflow before asking this like How do i join & Bare minimum you need and how to get involved  with open source and what level of programming etc. But this is not helping me when it comes to self-evaluating with skills. How to find that out ?  How can i check what it takes to join open source project and am i really that comfortable with huge source code etc.

My question is when to consider yourself comfortable joining open source programming ? I mean how will you test yourself that you're ready to take burden of big/small projects of open source ? how will you test yourself to see if you could work with version control/other programmers/tight schedule etc ?

答:
when to consider yourself comfortable
  joining open source programming ?

The best answer to that question, in my opinion, is "When you think you can bring something to the project".

You're using an application / library and something is missing, or you found a bug ? Report it, try to correct it, send a patch ; et voila ;-)

Maybe your patch will be accepted, if it's OK ; keep doing that a couple of times : correcting bugs is something (even bugs you didn't report -- see the bugtracker of the project you choose) that will allow you to know the project.

And, after a while, maybe you'll get commit rights to the projects ;-)

It's not necessarily a question skills or whatever : you can participate in a big open source project without having to modifiy the core of the project or whatever : even small patches (like translation, minor modifications to the UI, minor bug corrections, ...) are usefull to the project, and they won't require you to be a rock start ; instead, they'll be a perfect start either for you to know the project, and others to see that you are doing well.

About version control / other programmers / tight schedule : I'm guessing that, when you have (professionnaly speaking) worked for a couple of years, you are more than ready for all that ; open source projects are maybe even a bit more forgiving about that, in some ways -- for instance, there might be less presure than when you have a client on your back ^^

As a final note : whatever you do, if done well, will be useful : what matters is that you do it for the project, and not just "to do open source" !

OwnerDisplayName: Mahesh

OwnerDisplayName: Pascal MARTIN


答:
When I feel comfortable getting paid nothing to work on someone else's project, it's time.

My goal as a newcomer to software was to get paid by someone to do what I like.  Since then I've taken on some proprietary work that I sponsored, and made some profits from that.

I'm no Anders Hejlsberg, but I've made a pretty good living.  Given that the talent bar for being a professional developer in software is so much lower than being a professional athlete or musician, is there any special reason why you've set your sights on being an amateur?

Title: When is the right time to join open source project for programmer?

Body:
Most of the newcomers in programming start with basic projects to start with programming. Most of the C++ progammers spend some time with puzzles and contests but this is not always helpful. Sometimes you've to spend some time on real projects. Starting your own open source project could be a problem in self-learning for newbie cause of lack of mentors and peers who can't look at your code and give suggestions.  Open source projects can solve this problem, some projects could be best suited for new programmers. Besides everybody is newbie at some point. So i'll try and make this question a bit from beginners perspective.

I tried few questions on stack overflow before asking this like How do i join & Bare minimum you need and how to get involved  with open source and what level of programming etc. But this is not helping me when it comes to self-evaluating with skills. How to find that out ?  How can i check what it takes to join open source project and am i really that comfortable with huge source code etc.

My question is when to consider yourself comfortable joining open source programming ? I mean how will you test yourself that you're ready to take burden of big/small projects of open source ? how will you test yourself to see if you could work with version control/other programmers/tight schedule etc ?

OwnerDisplayName: John Lockwood


答:
There is a simple logical answer to this.

You can download the open source project.

Make a change to the project or fix a bug that was on the list.

Compile it and test it.

Submit the code.

There really is nothing in your heart or mind that will tell you when you're ready to contribute to open source society.  There is no test other than actually trying it.

Once you try it you can check these areas of feedback.

Your feelings on what you did.

Your feelings or thoughts on what you can improve about your own approach

How comfortable you are in soliciting feedback or incorporating any feedback you received.

These are the areas to improve and work on (above and beyond any technical skills that was demonstrated or not demonstrated by your changes).   Get super comfortable following all of these areas and make sure that you are making the changes for yourself.

Good luck and welcome!

OwnerDisplayName: Shaun F


答:
Anytime! Really, open source projects live of their users using the project. The basic idea is not to join the project to learn but to use the code and contribute back enhancements, changes in behavior, etc. Even the reporting of a bug is contribution or answering questions for others or documenting a how to guide. So don't sit on the fence but jump right in.

Off course this turns the "question" into "What project should I immerse myself in?" Well, the best project for you is one where you really get some use out of it. If the software scratch some kind of itch for for you. Weather it is building a web site with content and community, morphing images in artful ways, enjoying all the bells and whistles on that Mac OS X IM app, or ... If the software does something for you beyond just learning to program, it will keep you much more and much longer motivated.

OwnerDisplayName: PlanBForOpenOffice


答:
It so totally should be a function.

```<code>if (isBufferValid(buffer)) {
    // ...
}
</code>```

Much more readable, and more maintainable (if the check logic ever changes, you only change it in one place).

Besides, things like these get inlined easily so you don't even need to worry about function call overheads.

Let me ask you a better question. How is not doing this a good practice?

Do the right thing. :)

Body:
It so totally should be a function.

if (isBufferValid(buffer)) {
    // ...
}

Much more readable, and more maintainable (if the check logic ever changes, you only change it in one place).

Besides, things like these get inlined easily so you don't even need to worry about function call overheads.

Let me ask you a better question. How is not doing this a good practice?

Do the right thing. :)


答:
Centralizing the code is usually always a good idea. We must re-use the code as much as possible.

However, it is important to note how to do that. For example, when you have a code that does compute_prime_number() or check_if_packet_is_bad() it is good. Chances are that the algorithm of functionality itself will evolve that will be benefited.

However, any piece of code which repeats as a prose doesn't qualify to get centralized right away. This is bad. You may hide arbitrary lines of code inside a function just to hide a code, over time, when multiple parts of the application begins to use, they all must remain compatible to the needs of all callee of the function.

Here are some questions you should ask before asking

Has the function you are creating its own inherent meaning or is it just a bunch of lines?

Which other context will require the use of the same functions? Is it likely that you may require slightly generalize the API before using this?

What will be the expectation of (different parts of the) applications when you throw exceptions?

What are the scenarios to see that functions are going to evolve?

You should also check whether there already exists stuff like this. I have seen so many people always tending to redefine their macros MIN, MAX rather than searching for what already exists.

Essentially, the question is, "Is this new function really worthy of re-use or is this just a copy-paste?" If it is first, it is good to go.


答:
Code dupliaction should be avoided. Each time you anticipate it, you should avoid code duplication. If you didn't anticipate it, apply the rule of 3 : refactor before the same piece of code is duplicated 3 times, anotate the quirk when its duplicated 2 times.

What is a code duplicattion ?

A routine that is repeated at several places in the codebase. This tourine must be more complex than a simple function call (otherwize, you'll gain nothing by factorizing).

A very common task, even a trivial one (often a test). This will improve encapsulation and semantic in the code.

Consider the exemple below :

```<code>if(user.getPrileges().contains("admin")) {
    // Do something
}
</code>```

becomes

```<code>if(user.isAdmin()) {
    // Do something
}
</code>```

You improved the encapsulation (now you can change the conditions to be an admin transparently) and the semantic of the code. If a bug is discovered in the way you check that the user is an admin, you don't need to go throw your whole codebase and make a fix everywhere (whith the risk of forgotting one and get a security flaw in your application).

Body:
Code dupliaction should be avoided. Each time you anticipate it, you should avoid code duplication. If you didn't anticipate it, apply the rule of 3 : refactor before the same piece of code is duplicated 3 times, anotate the quirk when its duplicated 2 times.

What is a code duplicattion ?

A routine that is repeated at several places in the codebase. This tourine must be more complex than a simple function call (otherwize, you'll gain nothing by factorizing).

A very common task, even a trivial one (often a test). This will improve encapsulation and semantic in the code.

Consider the exemple below :

if(user.getPrileges().contains("admin")) {
    // Do something
}

becomes

if(user.isAdmin()) {
    // Do something
}

You improved the encapsulation (now you can change the conditions to be an admin transparently) and the semantic of the code. If a bug is discovered in the way you check that the user is an admin, you don't need to go throw your whole codebase and make a fix everywhere (whith the risk of forgotting one and get a security flaw in your application).


答:
The fundamental gist of LGPL is that its code can be linked against any license software without affecting its license, as long as it's done in such a way that the LGPL'd code can be tinkered with, modified, and the code linked against will be possible to get to work with the modified version. The license of the program using LGPL'd pieces can be arbitrary and doesn't change, but the way it is written or distributed must enable replacing the LGPL'd part. And you must provide all the code necessary for the replacement: the code of the LGPL'd part and anything necessary to integrate it in your program.

That means:

if you use dynamic linking, provide just the LGPL code, allowing easy replacement of the Free .so/.dll

if you use static linking, you must provide object files that can be linked with the library to provide a working executable.

if it integrates deeply, compilation units (object files) containing both your and the library code, you must provide your code, at least as much as necessary to compile the ready program after modifying contents of the library.

if you modified the library itself to suit your needs - even if the changes are extensive and far beyond scope of the original library - you must provide sources to the new, modified library as LGPL. If you want to keep the changes proprietary, they must land elsewhere outside the library, either as a wrapper/abstraction layer, or as a separate library.


问:
Dynamic Class Inheritance For PHP
I have a situation where I think I might need dynamic class inheritance in PHP 5.3, but the idea doesn't sit well and I'm looking for a different design pattern to solve my problem if it's possible.

Use Case

I have a set of DB abstraction layer classes that dynamically compiles SQL queries, with one DAL class for each DB type (MySQL, MsSQL, Oracle, etc.). Each table in the database has its own class that extends the appropriate DAL class. The idea is that you interact with the table classes, but never directly use the DAL class. If you want to support a different DB type for your app, you don't need to rewrite any queries or even any code, you simply change a setting that swaps one DAL class out for another...and that's it.

To give you a better idea of how this is used, you can take a look at the DAL class, the table classes, and how they are used on this StackExchange Code Review page. To really understand what I'm trying to do, please take a look at my implementation first before suggesting a solution.

Issues

The strategy that I had used previously was to have all of the DAL classes share the same class name. This eliminated autoloading, so I had to manually load the appropriate DAL class in a switch statement. However, this approach presents some problems for testing and documentation purposes, so I'd like to find a different way to solve the problem of loading the correct DAL class more elegantly.

Update to clarify the issue

The problem basically boils down to inconsistencies in the class name (pre-PHP 5.3) or class namespace (PHP 5.3) and its location in the directory structure. At this point, all of my DAL classes have the same name, DBObject, but reside in different folders, MySQL, Oracle, etc. My table classes all extend DBObject, but which DBObject they extend varies depending on which one has been loaded.

Basically, I'm trying to have my cake and eat it too. The table classes act as a stable API and extend a dynamic backend, the DAL (DBObject) classes. It works great, but I outsmarted myself and because of the inconsistencies with the class names and their locations, I can't autoload the DBObject, which makes running unit tests and generating API docs impossible for the DBObject classes because the tests and docs rely on auto-loading.

Just loading the appropriate DBObject into memory using a factory method won't work because there will be times when I need to load multiple DBObjects for testing. Because the classes currently share a name, this causes a class is already defined error. I can make exceptions for the DBObjects in my test code, obviously, but I'm looking for something a little less hacky as there may future instances where something similar would need to be done.

Solutions?

Worst case scenario, I can continue my current strategy, but I don't like it very much, especially as I'll soon be converting my code to PHP 5.3.

I suspect that I can use some sort of dynamic inheritance via either namespaces (preferred) or a dynamic class extension, but I haven't been able to find good examples of this implemented in the wild.

In your answers, please suggest either an alternate pattern that would work for this use case or an example of dynamic inheritance done right. Please assume PHP 5.3 with namespaced code. Any code examples are greatly encouraged and I'm definitely open to different approaches.

The preferred constraints for the solution are:

DAL class can be autoloaded.

DAL classes don't share the same exact same namespace, but share the same class name. As an example, I would prefer to use classes named DbObject that use namespaces like Vm\Db\MySql and Vm\Db\Oracle.

Table classes don't have to be rewritten with a change in DB type.

The appropriate DB type is determined via a single setting only. That setting is the only thing that should need to change to interchange DB types. Ideally, the setting check should occur only once per page load, but I'm flexible on that.

Final Update

Thanks to NikiC's suggestion, I created an abstract factory class that loads the proper DBObject and then wraps its public methods on a 1:1 basis. The table classes now extend the factory instead of the DBObject class.

This setup will now allow me to test and use each DBObject class without worrying about conflicts and it lets me use multiple DBMS's at a time. It also allows me to retain the code hinting in an IDE for each table class because they each extend the factory wrapper. Using wrapping methods may not be the perfect solution, but it doesn't rely on dynamic class inheritance, it solves my design problem, it meets my requirements, and it works.

答:
It looks like you are having a design issue here: Tables should not extend the Database Abstraction Layer. Instead the DAL should be injected into the table as a dependency.

```<code>abstract class Table {
    protected $dal;

    public function __construct(DAL $dal) {
        $this->dal = $dal;
    }

    // whatever else all tables have in common
}

class Table_User extends Table {
    public function someMethod() {
        $this->dal->someOtherMethod();
    }
}

$table = new MyTable($dal);
$table->someMethod();
</code>```

That way you will create a DAL at some upper scope and pass it down. This will also allow you to use multiple different database engines at the same time.

Additionally you obviously should not create your tables directly in your controller but let a specialized class do that. For example you could use a factory:

```<code>class TableFactory {
    protected $dal;

    public function __construct(DAL $dal) {
        $this->dal = $dal;
    }

    public function createTable($name) {
        $className = 'Table_' . $name;
        return new $className($this->dal);
    }
}
</code>```

That way you can create a table factory at some point with an injected DAL and pass that table factory around.

```<code>$table = $factory->createTable('User');
</code>```

Title: Dynamic Class Inheritance For PHP

Body:
It looks like you are having a design issue here: Tables should not extend the Database Abstraction Layer. Instead the DAL should be injected into the table as a dependency.

abstract class Table {
    protected $dal;

    public function __construct(DAL $dal) {
        $this->dal = $dal;
    }

    // whatever else all tables have in common
}

class Table_User extends Table {
    public function someMethod() {
        $this->dal->someOtherMethod();
    }
}

$table = new MyTable($dal);
$table->someMethod();

That way you will create a DAL at some upper scope and pass it down. This will also allow you to use multiple different database engines at the same time.

Additionally you obviously should not create your tables directly in your controller but let a specialized class do that. For example you could use a factory:

class TableFactory {
    protected $dal;

    public function __construct(DAL $dal) {
        $this->dal = $dal;
    }

    public function createTable($name) {
        $className = 'Table_' . $name;
        return new $className($this->dal);
    }
}

That way you can create a table factory at some point with an injected DAL and pass that table factory around.

$table = $factory->createTable('User');


答:
MariaDB is a backward compatible, binary drop-in replacement of MySQL. What this means is:

Data and table definition files (.frm) files are binary compatible.

All client APIs, protocols and structs are identical.

All filenames, binaries, paths, ports, sockets, and etc... should be the same.

All MySQL connectors work unchanged with MariaDB.

The mysql-client package also works with MariaDB server.

In most common practical scenarios, MariaDB version 5.x.y will work exactly like MySQL 5.x.y, MariaDB follows the version of MySQL, i.e. it's version number is used to indicate with which MySQL version it's compatible.

MariaDB originated as a fork of MySQL by Michael "Monty" Widenius, one of the original developers of MySQL and co-founder of MySQL Ab. The MariaDB Foundation acts as the custodian of MariaDB.

The main motivation behind MariaDB was to provide a floss version of MySQL, in case Oracle goes all corporate with MySQL. It's worth noting that Monty was vocal against MySQL acquisition (via Sun's acquisition) by Oracle.

Although MariaDB is supposed to be compatible with MySQL, for one reason or the other there are quite a few compatibility issues and different features:

MariaDB includes all popular open source engines,

MariaDB claims several speed improvements over MySQL, and

there are a few new floss extensions that MySQL lacks

Finally, the name comes from Monty's daughter Maria (the other one being My), as MySQL is now a registered trademark of Oracle Corporation.

Body:
What's the difference between MariaDB and MySQL? I'm not very familiar with both. I'm primarily a front end developer for the most part.

Are they syntactically similar? Where do these two query languages differ?

Wikipedia only mentions the difference between licensing:

MariaDB is a community-developed branch of the MySQL database, the
  impetus being the community maintenance of its free status under GPL,
  as opposed to any uncertainty of MySQL license status under its
  current ownership by Oracle.


答: DRY is about simplifying code manipulation. You've just touched on a fine point about this principle: It's not about minimizing the number of tokens in your code, but rather creating single points of modification for semantically equivalent code. It sounds like your checks always have the same semantic, so they should be put into a function in case you need to modify them.


答:
Personally, I really like Ninject.

It's simple, yet powerful and allows you to achieve the "easy" parts of DI easily, whilst still giving plenty of scope for more advanced DI scenarios.

It's also fairly lightweight and easy to set-up within your project/application.

This is especially true for ASP.NET MVC applications if you're using NuGet, as there is a Nuget package for the Ninject assembly itself (Ninject), along with another Nuget package which tightly integrates Ninject with ASP.NET MVC 3 (Ninject.MVC3) (which uses such things as WebActivator to allow assemblies to execute start-up code etc.)

There's a few blog posts out there to help get started with all this, too.

Title: Inversion of Control in ASP.NET MVC


问:
Database source control
Should database files(scripts etc.) be on source control?
If so, what is the best method to keep it and update it there?

Is there even a need for database files to be on source control since we can put it on a development server where everyone can use it and make changes to it if needed. But, then we can't get it back if someone messes it up.

What approach is best used for databases on source-control?

答:
DataGrove solves some of the problems mentioned here (by jfrankcarr, for example).

It tracks all the changes to a DB and allows you to save a version of the entire DB's state to a repository. It then allows you to spawn multiple virtual copies of the same DB, so each developer or DBA can have his own separate copy (each virtual copy can be spawned from a different version). It'll make sure no one overrides someone else's code/ changes. Each one of the virtual copies is also tracked into the same repositories so all the DB states can be easily shared and recreated.

Title: Database source control


问:
Is there a name for "More events than expected" bug?
Is there a name for a family of bugs, that are caused by assumption, that user would generate only 1 event during the execution of the handler ?

Simplest example is: animation triggered by click, which can run several copies of itself, if user rapidly clicks several times.

答:
In electronic design, the problem is referred to as contact bounce.

The correction for the problem when it happens with events is sometimes referred to as de-bouncing, named after bits of electronic circuitry that do the same thing.  So I suppose you could call the problem event bounce.


问:
Should one comment differently in functional languages?
I'm just getting started with functional programming and I'm wondering about the correct way to comment my code.

It seems a little redundant to comment a short function as the names and signature already should tell you everything you need to know. Commenting larger functions also seems a little redundant since they are generally comprised of smaller self-descriptive functions.

What is the correct way to comment a functional program? Should I use the same approach as in iterative programming?

答: The reason we document a function is that readers don't want or can't read the body of the function. For this reason, one should document large functions, even in functional languages. It does not matter if it's easy to understand what the function does by looking at its implementation.</p>


问:
How do I display copyright correctly when using components with multiple permissive licenses?
I am writing a commercial application that will make use of some open libraries licensed under different licenses.

For example one library will be licensed under the Apache 2.0 license, another will use the LGPL license. Both licenses allow usage in commercial applications, but differ in the way the attributions of licensed work is given.

It is my first commercial application that uses 3rd party libraries and I want to do the right thing so that the 3rd party licenses are satisfied. I am not only asking what I should do, but also what I must not do.

What is the best way to go about displaying these licenses?

答:
In case of Apache 2.0 as well as LGPL (if the code is only linking to your code without modification), you can distribute your product (for a charge) without having to open up your code of that product.

In this case, you have to make a list of libraries are included, and for each, the actual license files that your dependent libraries have provided in their source/object code. Credits to these libraries must be given.

As LGPL license puts it,

a) Give prominent notice with each copy of the object code that the
  Library is used in it and that the Library and its use are covered by
  this License.

b) Accompany the object code with a copy of the GNU GPL and this (the
  LGPL) license document.

As Apache 2.0 puts it,

any Derivative Works that You distribute, all copyright, patent,
  trademark, and attribution notices from the Source form of the Work,
  excluding those notices that do not pertain to any part of the
  Derivative Works;

Also some of the other things you cannot use, is to use the Trademark, Logo of those libraries in part of your product. for example you should not:

use phrasing such as 'based on Apache', 'powered by Apache', or 'based
  on Apache technology'

Further, if there is a warranty issue i.e. if the system doesn't function as intended because of software issue, the said libraries (under Apache) do not come with WARRANTY. Hence, you need to fix problems for the clients without pointing them to copy write owners of those libraries.

Refer to this:
http://www.inteist.com/2010/05/how-to-use-apache-2-0-in-commercial-products-explained-in-simple-terms/

and

http://answers.google.com/answers/threadview/id/439136.html


答:
I think you are touching two categories of bugs:

Assuming unity in the presence of multiplicity, and

race conditions.

I just came up with those names, I don't think they are standard.

Edit: I like the answer by Kevin, which mentions reentrance. This is a standard term. Lack of reentrance is assuming a function can only happen once in any stack trace.

Title: Is there a name for "More events than expected" bug?

Body:
Is there a name for a family of bugs, that are caused by assumption, that user would generate only 1 event during the execution of the handler ?

Simplest example is: animation triggered by click, which can run several copies of itself, if user rapidly clicks several times.


问:
At what point should you switch to release build?
One of the practices set out in Jez Humble's Continuous Delivery is that you should build one package and then release it to each environment you deploy to, so that the deployment and the artifacts have themselves been tested multiple times before going to production.

I fully support this idea.

On the other hand, debug-mode builds that give you stack traces with line numbers are incredibly useful in test environments, as is the ability to remote-debug. But, you want to send a release build to production.

So, for people following the first principle, at what point do you switch from debug to release builds?

Is it before the first deployment to a test environment, figuring the cost of losing debug mode is worth paying to ensure you are testing the actual release candidate early? Or do you build again at some point in the promotion process, figuring that you'll trust the build process over the software? Or do you just screw it all and deploy debug versions to production?

Note: I know this doesn't really apply to interpreted languages because you can usually flick the switch in configuration rather than doing it at build time.

答:
In our environment, the code gets deployed at many sites. And hence there should be different context applied to each instance of deployment. Usually, we deploy it in a key "lesser risky" places and see the experience.

This deployment still are in production hence, this is not 'debug' mode. But it also assumes that testing is done well.

Of course, with debug mode off, quick debug of the code (on site) might be difficult. But if the release has failed, the production switches back to fall back release.

However, we try to maintain or create an identical environment, which can reproduce such an environment to test again. (I know this is not alway trivial to do) but all we need sometimes is to reproduce the transactions/inputs.

The point is, how much ever the temptation, debug mode release should not be in production. Though, i won't say this is a rule.

Another thing is, the release is still called trial till it has established (by running for significant time) other premises don't accept it yet.

There are other few practices to ensure that build process itself not quite faulty. See this:
A simple ways to improve the release quality in RAD environment


问:
Programming and Ubiquitous Language (DDD) in a non-English domain
I know there are some questions already here that are closely related to this subject but none of them take Ubiquitous Language as the starting point so I think that justifies this question.

For those who don't know: Ubiquitous Language is the concept of defining a (both spoken and written) language that is equally used across developers and domain experts to avoid inconsistencies and miscommunication due to translation problems and misunderstanding. You will see the same terminology show up in code, conversations between any team member, functional specs and whatnot.

So, what I was wondering about is how to deal with Ubiquitous Language in non-English domains.

Personally, I strongly favor writing programming code in English completely, including comments but ofcourse excluding constants and resources.

However, in a non-English domain, I'm forced to make a decision either to:

Write code reflecting the Ubiquitous Language in the natural language of the domain.

Translate the Ubiquitous Language to English and stop communicating in the natural language of the domain.

Define a table that defines how the Ubiquitous Language translates to English.

Here are some of my thoughts based on these options:

1) I have a strong aversion against mixed-language code, that is coding using type/member/variable names etc. that are non-English. Most programming languages 'breathe' English to a large extent and most of the technical literature, design pattern names etc. are in English as well. Therefore, in most cases there's just no way of writing code entirely in a non-English language so you end up with mixed languages anyway.

2) This will force the domain experts to start thinking and talking in the English equivalent of the UL, something that will probably not come naturally to them and therefore hinders communication significantly.

3) In this case, the developers communicate with the domain experts in their native language while the developers communicate with each other in English and most importantly, they write code using the English translation of the UL.

I'm sure I don't want to go for the first option and I think option 3 is much better than option 2. What do you think? Am I missing other options?

UPDATE

Today, about year later, having dealt with this issue on a daily basis, I have to say that option 3 has worked out pretty well for me.

It wasn't as tedious as I initially feared and translating in real time while talking to the client wasn't a problem either.

I also found the following advantages to be true, based on my experience.

Translating the UL makes you pay more attention to defining the UL and even the domain itself, especially when you don't know how to translate a term and you have to start looking through dictionaries etc. This has even caused me to reconsider domain modeling decisions a few times.

It helps you make your knowledge of the English language more profound.

Obviously, your code is much more pleasant to look at instead of being a mind boggling obscenity.

答:
I've faced this issue often, and in my opinion the answer is: "there is no single answer valid for all of the scenarios."

But keep in mind that Ubiquitous Language is not a goal per se. It's a tool to reinforce communication among the team and the Domain Experts and to enforce conceptual coherence of the implemented model in code, tests and conversation.

If you can speak UL unambiguously you're on the right path. If you and your peers are continuously translating from code to conversation or from concept to concept, then you're probably off track.

In practice, not all domains are equal, nor domain experts. Some domain have a lot of English terminology anyway (tech-driven domains, for example) and it sounds reasonable to opt for a full-English choice. However, some cultures might influence this choice (French comes to mind) and diffusion of English terminology varies from country to country. In some other domains (Legal, to name one) there's no way to translate some terms. Or translating would make it absolutely harder for Domain Expert to follow the conversation.

In general, we are more interested in what the Domain Expert has to say. So we want to make things easy for them. Otherwise they could just take a UML class and read our diagrams (that was a joke). So the only real recommendation here is: "pay attention to the Domain Expert behavior", if they're engaged in the conversation and the conversation goes on smoothly, you're probably on track, keep that language. It might cause a little extra work on the team, but that's fine. As developers we are somewhat trained to learn words with specific meaning in a context.

Strangely, this question always is accompanied by the assumption that all the code needs to speak one language. That might be challenged too. I am not a native English, and knowledge of a foreign language is not flat: my brain goes fast when talking about name, surname, car and the like, misses some details when talking about zipcode, slows down when talking about loan and definitely asks for a reassuring explanation when talking about mortgage.

So, again, choose the best combination that will make the key conversation flow and provide the highest amount of information and feedback from the Domain Expert.


答:
I take the same approach to documenting all of my code:

Use descriptive names,

Add comments before any reasonably complicated logic if complicated logic can't be avoided,

Write an overview of the entire system,

If the name and type signature doesn't tell you exactly what the function does, you're usually doing it wrong.

Title: Should one comment differently in functional languages?

Body:
I'm just getting started with functional programming and I'm wondering about the correct way to comment my code.

It seems a little redundant to comment a short function as the names and signature already should tell you everything you need to know. Commenting larger functions also seems a little redundant since they are generally comprised of smaller self-descriptive functions.

What is the correct way to comment a functional program? Should I use the same approach as in iterative programming?


问:
Is a code review subjective or objective (quantifiable)?
I am putting together some guidelines for code reviews. We do not have one formal process yet and are trying to formalize it. And our team is geographically distributed.

We are using TFS for source control (we used it for tasks/bug tracking/project management as well, but we migrated that to JIRA) with Visual Studio 2008 for development.

What are the things you look for when doing a code review?

These are the things I came up with

Enforce FxCop rules (we are a Microsoft shop)

Check for performance (any tools ?) and security (thinking about using
OWASP - code crawler) and thread safety

Adhere to naming conventions

The code should cover edge cases and boundaries conditions

Should handle exceptions correctly (do not swallow exceptions)

Check if the functionality is duplicated elsewhere

A method body should be small (20-30 lines), and methods should do one
thing and one thing only (no side
effects and avoid temporal coupling -)

Do not pass/return nulls in methods

Avoid dead code

Document public and protected methods/properties/variables

What other things should we generally look out for?

I am trying to see if we can quantify the review process (it would produce identical output when reviewed by different persons) Example: Saying "the method body should be no longer than 20-30 lines of code" as opposed to saying "the method body should be small".

Or is code review very subjective (and would differ from one reviewer to another)?

The objective is to have a marking system (say -1 point for each FxCop rule violation, -2 points for not following naming conventions, 2 points for refactoring, etc.) so that developers would be more careful when they check in their code. This way, we can identify developers who are consistently writing good/bad code. The goal is to have the reviewer spend about 30 minutes max, to do a review (I know this is subjective, considering the fact that the changeset/revision might include multiple files/huge changes to the existing architecture, etc., but you get the general idea, the reviewer should not spend days reviewing someone's code).

What other objective/quantifiable system do you follow to identify good/bad code written by developers?

Book reference: Clean Code: A handbook of agile software craftmanship by Robert Martin.

答:
Most of the points you described are only a matter of code-formating or "surface" stuff:

Adhere to naming conventions

Avoid dead code

Document

...

All this could be checked using some automated tool: there isn't any need to have an experienced developper spend time going through the code to watch for that.

I don't know at all about .NET, but, for PHP, we have tools to check that kind of stuff; considering .NET is often said to be "more industrial" than PHP, I would be surprised to hear that there isn't any tool to check that kind of stuff.

The automated tool can both:

Be integrated in some automatic build process, that runs every nights

Send e-mails reporting

warnings (for instance, a method is longer than 20 lines)

errors (for instance, a method is longer than 50 lines)

The mail can be sent to either all the team, or the guy who committed the code that doesn't pass a test -- or you could use some reporting web-interface (same note about .NET and PHP)

I would also add that automated testing can help a lot, to detect a certain number of errors before the code is used in production. And automated tests can also help with some metrics, I suppose.

Code reviews done by an experienced developpers also have another great advantage that you didn't talk about:

An experienced developper can often detect a wide variety of bugs by just looking at the source code (I quite often find bugs when I do code reviews)

A code review done by an experienced developper will allow him to make comments and recommendations to the team:

He will try to understand the algorithms that are used in the code and possibly suggest betters solutions.

Just reading the code, there is often stuff you can see that an automated tool will not detect.

But for a code-review that goes deeper than just code-formatting, you'll need more than half an hour...

OwnerDisplayName: ram


答:
It depends.

Some parts of the review are easily quantifiable (no FxCop problems, no StyleCop errors, no CAT.NET errors, etc.)

Style, however, can be subjective - but as you say, once you start being more specific (no method >20 lines) then you can measure it, and tools like NDepend can do that automatically. Some things will never be automatic though - checking edge case handling would require tests to do so, which brings up code coverage, and 100% is an unreachable ideal in a lot of cases. Duplication checking is hard to do automatically. Null checks, well not sure I agree with you, but you may be able to write NDepend rules, or FxCop rules for that one.

The more tools the better, and if the tools allow developers to check their work before committing changes and for checks to be performed as part of the CI process then you're going to minimise the need for reviews.

Title: Is a code review subjective or objective (quantifiable)?

Body:
I am putting together some guidelines for code reviews. We do not have one formal process yet and are trying to formalize it. And our team is geographically distributed.

We are using TFS for source control (we used it for tasks/bug tracking/project management as well, but we migrated that to JIRA) with Visual Studio 2008 for development.

What are the things you look for when doing a code review?

These are the things I came up with

Enforce FxCop rules (we are a Microsoft shop)

Check for performance (any tools ?) and security (thinking about using
OWASP - code crawler) and thread safety

Adhere to naming conventions

The code should cover edge cases and boundaries conditions

Should handle exceptions correctly (do not swallow exceptions)

Check if the functionality is duplicated elsewhere

A method body should be small (20-30 lines), and methods should do one
thing and one thing only (no side
effects and avoid temporal coupling -)

Do not pass/return nulls in methods

Avoid dead code

Document public and protected methods/properties/variables

What other things should we generally look out for?

I am trying to see if we can quantify the review process (it would produce identical output when reviewed by different persons) Example: Saying "the method body should be no longer than 20-30 lines of code" as opposed to saying "the method body should be small".

Or is code review very subjective (and would differ from one reviewer to another)?

The objective is to have a marking system (say -1 point for each FxCop rule violation, -2 points for not following naming conventions, 2 points for refactoring, etc.) so that developers would be more careful when they check in their code. This way, we can identify developers who are consistently writing good/bad code. The goal is to have the reviewer spend about 30 minutes max, to do a review (I know this is subjective, considering the fact that the changeset/revision might include multiple files/huge changes to the existing architecture, etc., but you get the general idea, the reviewer should not spend days reviewing someone's code).

What other objective/quantifiable system do you follow to identify good/bad code written by developers?

Book reference: Clean Code: A handbook of agile software craftmanship by Robert Martin.

OwnerDisplayName: blowdart


答:
Cyclomatic complexity (CC) is one way to evaluate code that's 'not bad'.

In actual code that has high CC, I have a high "what's going on here, I don't remember" factor. Lower CC code is easier to figure out.

Obviously, the usual caveats apply for metrics.

OwnerDisplayName: Paul Nathan


答:
Code reviews are both subjective and objective.  Rules like "the method body must be 20-30 lines" are subjective (some people might think 100 lines is OK) but if your company has decided that 20-30 lines is the limit, that's fine and you can measure that.  I think that the point system you've come up with is a great idea.  You'll need to re-evaluate it periodically as you find that certain rules need to have more or less weight in the scoring but as long as everyone knows the rules, it looks like a good system.

Other things I would look for:

clearness of code - sometimes a piece of code can be written in one line or several lines.  The average programmer shouldn't have to spend several minutes trying to figure out what a line of code does.  If he does, maybe the code should be rewritten in a simpler way.  This is subjective but the key point is that the code should be immediately understandable by most programmers in your company.

check function input parameters - there should be some code to check that input parameters fall within acceptable ranges.  This should also match the function documentation.

descriptive variable names - except in a few special cases (loop indices, etc), variable names should be descriptive.  One resource you might want to take a look at for naming conventions, etc. is Code Complete

OwnerDisplayName: TLiebe


答: As a rule of thumb, avoid spending any time in a code review doing something that could be done by machine. For example, your first item is to "enforce FxCop rules", but presumably that can be done by FxCop without humans having to also do it.</p>

OwnerDisplayName: Greg Hewgill