答:
My advice will be not to scrap the entire code entirely. This is the day-to-day life issue, every development team face. Attack one part of the code at a time. Fix it, clean it, document it. And then move to the other part. The main thing is always keep some shipable code at the hand. Rewriting the entire code from the scratch will take the amount of the time that has been spent till now and there won't be any guarantee that it will be nicer than the current.

But then also the people should avoid writing the code in this manner. Spend some more time in code reviews. Adapt to some uniform coding style. Discuss the design first and then write the code. Such simple things will make big changes.

Nice Blog telling why Netscape loose

Title: Organizing uncommented, dirty code?


问:
How can I explain object-oriented programming to someone who's only coded in Fortran 77?
My mother did her college thesis in Fortran, and now (over a decade later) needs to learn c++ for fluids simulations. She is able to understand all of the procedural programming, but no matter how hard I try to explain objects to her, it doesn't stick. (I do a lot of work with Java, so I know how objects work) I think I might be explaining it in too high-level ways, so it isn't really making sense to someone who's never worked with them at all and grew up in the age of purely procedural programming.

Is there any simple way I can explain them to her that will help her understand?

答:
When I was first migrating to an object oriented language from my initial training in Pascal, the '.' issue was the biggest hurdle for me too. It took me years to get over it.

It's actually really unintuitive for a variable to belong to another variable, especially when you're used to thinking of them as pointers. The stumbling block for me was:

What does it mean for something that is basically a pointer, to have
a another pointer pointing to it, that resolves to a different thing
than the parent pointer?

The aha moment for me was when I realised that the top level pointer was basically just a namespace.

I'd suggest getting her to write a bunch of code which requires her to namespace her functions, ideally without using the dot notation to start with. Then get her to try and rewrite it using dot notation.

Doing that exercise a should get her over the initial "What witchcraft is this?" hurdle.

ContentLicense: CC BY-SA 3.0


问:
Why do we have to use divs?
This morning, as I was writing some html and haml, it occurred to me that the way divs are used is ridiculous.
Why are divs not implied? Imagine if this:

```<code><div class="hero-img">
   <img src="http://whatever.com/this.jpg">
</div>
</code>```

was this:

```<code><hero-img>
   <img src="http://whatever.com/this.jpg">
</hero-img>
</code>```

If the "div class" portion of the element was assumed, HTML would be more semantic, and infinitely more readable with the matching closing tags!

This is similar to HAML, where we have:

```<code>.content Hello, World!
</code>```

Which becomes:

```<code><div class='content'>Hello, World!</div>
</code>```

It seems to me the only thing that would have to happen for this to work in browsers is that the browsers could start interpreting every element without an existing html element definition as implying <div class="<element name>">.

This could be completely backward compatible; for CSS and jQuery selectors etc, "div.hero-img" could still work, and be the required syntax to select the elements.

I know about the new web components specification, but that is significantly more complicated than what is suggested here. Can you imagine how pleasant it would be to look at a website's source and see html that looked like that?!

So why do we have to use divs?

If you look at Mozilla's html5 element list, every element has a semantic meaning, and then we get to
 and it says:

"Represents a generic container with no special meaning."

..and then they list the arbitrary elements they are adding to html5 like .

Of course, if this concept of implied divs was added to the html spec, it would take ten years to become standard, which is a million years in web time.

So I figure there must be a good reason this hasn't happened yet. Please, explain it to me!

答:
We use
 instead of whatever tickles your fancy because it makes processing and rendering by the browser easier to accomplish.

As a counter-example, XML allows the creation of any tag-name that you want.  The ability to create arbitrary tag-names comes with a processing cost.  XML parsers have to build a dictionary of the tags used within a document as part of / while it is parsing the document.

By using
 browsers know that there is a container there and that it can ignore the container or pass it along to some other tool in the chain that may do something with the container.

Title: Why do we have to use divs?

Body:
We use <div> instead of whatever tickles your fancy because it makes processing and rendering by the browser easier to accomplish.

As a counter-example, XML allows the creation of any tag-name that you want.  The ability to create arbitrary tag-names comes with a processing cost.  XML parsers have to build a dictionary of the tags used within a document as part of / while it is parsing the document.

By using <div> browsers know that there is a container there and that it can ignore the container or pass it along to some other tool in the chain that may do something with the container.


答:
One of the key elements of HTML is actualy having predefined tag-elements. That's why.

The div class= is a way to get around this "limitation".

And that's why you don't see those "implied" constructions.

Title: Why do we have to use divs?

Body:
This morning, as I was writing some html and haml, it occurred to me that the way divs are used is ridiculous.
Why are divs not implied? Imagine if this:

```<code><div class="hero-img">
   <img src="http://whatever.com/this.jpg">
</div>
</code>```

was this:

```<code><hero-img>
   <img src="http://whatever.com/this.jpg">
</hero-img>
</code>```

If the "div class" portion of the element was assumed, HTML would be more semantic, and infinitely more readable with the matching closing tags!

This is similar to HAML, where we have:

```<code>.content Hello, World!
</code>```

Which becomes:

```<code><div class='content'>Hello, World!</div>
</code>```

It seems to me the only thing that would have to happen for this to work in browsers is that the browsers could start interpreting every element without an existing html element definition as implying <div class="<element name>">.

This could be completely backward compatible; for CSS and jQuery selectors etc, "div.hero-img" could still work, and be the required syntax to select the elements.

I know about the new web components specification, but that is significantly more complicated than what is suggested here. Can you imagine how pleasant it would be to look at a website's source and see html that looked like that?!

So why do we have to use divs?

If you look at Mozilla's html5 element list, every element has a semantic meaning, and then we get to
 and it says:

"Represents a generic container with no special meaning."

..and then they list the arbitrary elements they are adding to html5 like .

Of course, if this concept of implied divs was added to the html spec, it would take ten years to become standard, which is a million years in web time.

So I figure there must be a good reason this hasn't happened yet. Please, explain it to me!


答:
It is a matter of definedness. If using XHTML, which is pure XML, hence fully defined, then you could use your own namespace, here for instance via a prefix q::

```<code><q:hero-img>
    <img src="http://whatever.com/this.jpg">
</q:hero-img>
</code>```

If you would use XML to convert to (X)HTML you would be entirely free to generate from your free-tag "HTML" real HTML with
.

In some tag a namespace attribute with your own (dummy) URL:

```<code>xmlns:q="http://..."
</code>```

Title: Why do we have to use divs?

Body:
It is a matter of definedness. If using XHTML, which is pure XML, hence fully defined, then you could use your own namespace, here for instance via a prefix q::

<q:hero-img>
    <img src="http://whatever.com/this.jpg">
</q:hero-img>

If you would use XML to convert to (X)HTML you would be entirely free to generate from your free-tag "HTML" real HTML with <div class="hero-img">.

In some tag a namespace attribute with your own (dummy) URL:

xmlns:q="http://..."

ContentLicense: CC BY-SA 4.0


问:
Generic object construction - Inherited Classes
Basically I am writing a MSMQ based multi-threaded messaging pattern utility library. It's like a set of components all inherited (directly or indirectly) one class that's called my base component class.

Each of these messaging components have the ability to listen to multiple queues via multiple threads and to process messages via multiple threads.

So I have a worker base class that executes itself on a thread, but in implementation you would inherit this class, and fill in the gaps. So I want to be able to basically construct a generic object that inherits this class on the fly, and then put it to work. So far I have this which works, but I am just wondering if there is a better way to do it out there.

My current code...

```<code>public class EzQBaseComponent<TWorker> : IEzQComponent where TWorker : EzQWorker
{
    /// LOTS OF CODE YOU DON'T NEED TO KNOW :"D

    private void Listener_MessageRecieved(Guid listenerID, MessageQueue queue, Message msg, MessageQueueTransaction myTransaction)
    {
        try
        {
        lock (m_MessageRecievedLocker)
        {
            if(myTransaction == null)
            {
                // YAWN
            }
            if(msg.Label == c_CustomComponentMessageCommandLabel)
            {
                // YAWN
            }
            else if(Workers.Count < DelegatedWorkers)
            {
                Type t = typeof(TWorker);
                ConstructorInfo[] conInfos = t.GetConstructors();
                ConstructorInfo correctConstructor = null;
                foreach (ConstructorInfo cInfo in conInfos)
                {
                    if (cInfo.GetParameters().Count() < 1)
                    {
                        correctConstructor = cInfo;
                    }
                }

                if (correctConstructor == null)
                {
                    throw new Exception("Generic TWorker class does not contain a consturctor with '0' arguments. Cannot Construct class.");
                }

                TWorker worker = (TWorker)correctConstructor.Invoke(null);

                // YAWN
            }
            else
            {
                // YAWN
            }
        }
    }
    catch (Exception Ex)
    {
        // NOOOO EXCEPTION!!
    }
}
</code>```

Basically, my base class has a no-parameter constructor. So I look for the one without parameters via reflection, and then use that constructor.

Any thoughts on the construction of the generic object? Is that the best way?

答:
It seems like it would be easier to use the Activator class' CreateInstance  method instead:

```<code>T worker = (T)Activator.CreateInstance(typeof(T));
</code>```

It essentially does the same thing. CreatInstance uses the default/parameterless constructor for the type and returns an object (thus the casting). If one doesn't exist, it will throw an exception.

Quick Edit: For your example code, the block would look more like:

```<code>else if(Workers.Count < DelegatedWorkers)
{
    try
    {
        TWorker worker = (TWorker)Activator.CreateInstance(typeof(TWorker));
    }
    catch (MissingMethodException ex)
    {
         throw new Exception("Generic TWorker class does not contain a consturctor with '0' arguments. Cannot Construct class.");
    }
}
</code>```

Body:
It seems like it would be easier to use the Activator class' CreateInstance  method instead:

T worker = (T)Activator.CreateInstance(typeof(T));

It essentially does the same thing. CreatInstance uses the default/parameterless constructor for the type and returns an object (thus the casting). If one doesn't exist, it will throw an exception.

Quick Edit: For your example code, the block would look more like:

else if(Workers.Count < DelegatedWorkers)
{
    try
    {
        TWorker worker = (TWorker)Activator.CreateInstance(typeof(TWorker));
    }
    catch (MissingMethodException ex)
    {
         throw new Exception("Generic TWorker class does not contain a consturctor with '0' arguments. Cannot Construct class.");
    }
}


问:
Unified Team Dev Enviroment
Where I work we have a number of teams that are converting over to having a team dev environment.  Basically a couple members of the team are putting together an image that is then installed on everyones computer.  It includes an OS, an IDE (with source control managed from it), a couple of server systems they need for testing and a test server image.  Ostensibly the imagine is being compiled based on everyones input, so everyone is, again, ostensibly, happy with the environment in question.

The team leaders claim that this will be more efficient because whenever anyone has a problem everyone else on the team can help fix it (as opposed to, say, the other 2 who are still using vim.)  But, at the same time, it seems like this approach would have a negative effect on people who don't excel at working in the majorities paradigm.

So my question is this: is the trade off worthwhile?  Are the "team support" gains likely to overcome the "individual efficiency" loses?  Tangentially, is there a halfway point?  Perhaps if everyone had the same OS and the same server image but were allowed different IDEs, that might be better?

答:
Where i work we use the same policy - one main image, that is installed on all development computers (in our case windows, visual studio with plugins like R#, ghost doc, editors, regex tools, and so on).

I don't think anyone of our team members has ever experienced any drawbacks regrading the image policy, quite the contrary:

we have the same directory structure for our project mappings, so local references in source codes are always the same

we have the same applications settings

we have same key mappings, so changing workplaces (if needed or for example to do pair programming) won't affect our productivity

changing the hardware won't be a breaking change to any dev member

if someone needs help, for example extending a regular expression - the regex per email will suffice, everyone has the same tool for testing

same (product) updates apply on every machine / machines are in sync

this also means same behaviour on all machines (how nice if this would have been true :-)

On the other side, we can always adjust / extends some settings resp. add new software locally

for example i have added my own R# keymappings

i was for a long time (about 1 year or so) the only one using/having LINQPad

IMO we have a great benefit from that policy and i don't see how this approach would have a negative effect on people who don't excel at working in the majorities paradigm.

At the moment we have two trainees that started about 6 months ago. Since for them everything is new, learning the same tools and shortcuts that we use is not a bad habit. One day (after they know how everything works and can be set) they can always decide to define their own settings and / or try new and different tools.

The individual efficiency loss can be IMO neglected - the same image policy can be compared IMO with the coding guidelines - the team is more efficient, when everyone has the same style and also everyone adapts a bit. It is after all also a continuous learning process.

Title: Unified Team Dev Enviroment


问:
Which language features are considered harmful?
Please, explain why and list which languages have the (mis)feature implemented As far you know.

Post what you consider a harmful feature, not what you dislike.

答:
Allow Null by default, the "trillion"* dollar mistake. Sorry Tony Hoare.
Almost every language available on planet.

Tony Hoare explains

*I adjusted the expression coined by Tony Hoare to reflect actual loss on these days :-)

ContentLicense: CC BY-SA 2.5


问:
Organizing uncommented, dirty code?
I would like to ask you some questions about dirty code. There are some beginners who coded on a medium project. The code is a very huge ball of mud. They are not advanced programmers. They just know how to use keyboard an a little about java. They just wrote code with 12 000 lines in their main class, though, 6 000 lines belongs to NetBeans itself.

My job is to analyze the code and suggest a good way to maintain the code. My idea is to scrap the project and start a new one with OOP methodology. Recently I collected some notes and ideas about the problem, from this site and some others.

Now, I have the followings questions:

Should we repair the code, and change it to a OOP? We are now debugging it.

The code has no comments, no documentation, no particular style of programming, and so forth. Changing it is really expensive and time consuming. What do we can do about this?

How can I teach them to follow all the rules (commenting, OOP, good code quality, etc.)?

The code is erroneous and error prone. What can we do? Testing? We almost write two or three A4 papers for correction, but it seems endless.

I should have to say that I am new with them. I think I have broken the rules about adding people too late to the project, as well. Do you think I have to leave them?

答:
My suggestion is a combination of @duros's & @Manoj R's answers.

Start from scratch, keeping in mind to create good code/OOP/commented/etc this time, refer/copy&paste from your old code. As you meet the bad parts of your old code, rewrite/refactor them.

If your developers are not well trained, I think its good to send them for courses. Its important for regular retraining in the fast changing IT industry

Title: Organizing uncommented, dirty code?


问:
gnu lesser general public license question
I have a question about Thingiviews license. I have a site that has to do with 3D Printing, it is not done yet but I was wondering if I would be able to use it on my site,

The big reason I am asking is because it will be used to show 3D models that will eventually be made and sold, like shapeways kinda, so I am not selling Thingiview but it would be used to show something that will eventually make money.

Thingiview is currently licensed under:

GNU LESSER GENERAL PUBLIC LICENSE

and from what I can gather, it seems that what I want to do should be okay, do I just need to give the creator of it credit? I will either way but it seems that is all that is required.

Is what I want to do okay (by ok I mean legal)?

Also if I want to change it I can do that too right, I have some ideas to add to it. Is there anything I would need to do if I change it a little bit?

答:
I am not a laywer and this is not legal advice. I recommend consulting with an IP lawyer if you are concerned about possible legal issues.

Software licenses typically govern the distribution and modification of the software, not any artifacts the software may create.

The GIMP software uses the GNU GPL (which if anything is more restrictive than the LGPL) and you are allowed to create images and distribute them how you choose, right?

You are most likely okay here assuming the license is not modified or extended.

Caveat: the word "typically" in the first paragraph. Some licenses do restrict what you can do with the created artifacts. For example, the free and student editions of Microsoft Visual Studio explicitly forbid selling the programs you create in a commercial setting. However, my understanding is that OSI-approved licenses, which the GPL and LGPL are, do not restrict what you can do with the artifacts created by the licensed software.


问:
Making applications build system-aware
Build systems for web applications are great: they give dependency management, code minification, and the ability to use tech like SASS or CoffeeScript that require pre-processing.

However, I find actually using build systems to be ugly and annoying... you need to make sure developers have the build tools installed, that the versions they have installed are compatible with your configurations, and that any dependencies of the build tools(SASS compiler, jsmin, etc) are met. Getting a new developer onboarded now requires a suite of tools to be installed on their local system.

We can fight this by using virtualization: a system like Vagrant can allow the setup of developer systems to be codified. There's a clear series of steps to create a developer environment with all dependencies, or a machine image that's already set up and can simply be installed and run.

My goal is to make the build system non-intrusive. I would like developers to not even necessarily have to be aware of the build system in order to hack on a project. This might be unrealistic.

With Vagrant, you might accomplish this by having a "watch" service of your build system automatically run and re-build the files whenever they change. That's good, but what about a local-system developer who doesn't want to run Vagrant? They have to remember to run a separate process whenever they sit down to develop.

One approach I've not seen is to make the application build system aware. It seems to violate a separation of concerns, however with modern web development it seems we are already tightly coupled to our build systems: without running the build script, will you be able to run your web app and see anything meaningful? Will your static assets be in place?

Is there a compelling reason not to have your application look at its build status and rebuild itself when necessary, when in development mode? When running the development server, the application could be build-system aware and build its assets if needed.

This doesn't get away from the dependency requirements on the developer system. I don't have a concrete idea of what I'm looking for yet, but I feel like build systems for web apps aren't quite "worked out" yet. I hope to can have a good brainstorm here.

答:
That's exactly what happens for small projects. LESS or Sass are converted to CSS on the fly by the web application itself, and JavaScript is minified by the web app as well.

This approach for example became the default one with ASP.NET MVC: CSS (or any preprocessor, if you have the required library for it) and JavaScript code is combined into a single CSS and a single JavaScript files and then served; if you change one of the CSS files, you don't have to recompile: just refresh the page, and the bundle is regenerated automatically.

It's great for small projects. Change the LESS file. Switch to the browser. Press F5. Get the result. Immediately.

It's not so great for large projects.

First, you don't get the immediacy you can have with a small project, simply because there are too many files to transform, and it just takes time. It's not like you have to wait for a few minutes, but even five seconds become quickly annoying if you have to make hundreds of small changes in your stylesheets.

If the task is to make lots of small changes to CSS while getting a nearly-immediate visual feedback, there are better ways to do it than the change-build-refresh workflow. A basic one is to modify CSS directly in browser; any decent browser enables to do that.

Then, you're less concerned about how your new style is appearing in a browser, and more about passing the tests. With thousands of tests to pass, you simply can't do it locally. You have to dedicate this hard work to a build server, and by server, I mean more a farm of powerful machines capable of running in less than five minutes what would waste days if ran locally.

Imagine you have to change how a piece of information appears on a web app. What's your primary concern?

Change the code.

True. If you need visual feedback, do it in browser, and then reflect the change in the source code.

Ensure the new code matches coding conventions.

This is what a pre-commit hook does, so you actually have to either commit your code and wait for the version control server to respond, or do the check locally, which means installing the checkers.

Ensure you haven't introduced regressions.

This is the most important part. You changed the styles, and it works on the particular page you were looking at at the moment of change. But what about thousands of other pages? What if your change broke another page you weren't even aware of?

Here comes the build server. It will do the pdiff and show you the visuals of the changes. Hey, watch that! It seems that your change affected a page which is now totally broken. You couldn't know that when working locally.

For JavaScript, it goes further: one have to unit-test, to run functional tests, to generate the new version of the documentation. All those steps make a build server crucial.

Also, large projects simply can't afford doing LESS and CoffeeScript transforms during run time, for two reasons.

The first one is performance. You can't let an end user wait for five seconds while you rebuild your JavaScript files.

The second one is that it adds complexity, and the sort of complexity which can easily be mitigated by moving it to the build. More complexity means more chance to have bugs and more tests to run.

Finally, having two systems (the build which runs tests and the post-build first-run which builds CSS and JavaScript) just looks awkward. Keeping everything in the same place and doing all the hard work on a build server after each commit makes things much easier.

Conclusion

Your idea is great for small-scale projects. It's already popular in Microsoft community, and I expect that other communities use the same approach as well. It enables the developer to get the nearly-immediate response without having to recompile the app or to install additional components on the machine.

For large-scale projects, on the other hand, the workflow is centered around a build, which is both the heartbeat of the project and the mean to check that the changes are correct and if they are, move them into production. Watching the effect of the changes locally makes no sense, because the most important part—regression testing, takes days on an ordinary desktop machine, and because even transforming CSS and JavaScript takes too long compared to the nearly-immediate response you would expect.

Title: Making applications build system-aware


问:
Different scoring algorithms for different competition elements
I am creating a scoring system for a competition that is somewhat obscure, but it resembles the Olympics in terms of its high-level structure. Therefore, I will ask my question in terms of an abstracted, fictional version of the Olympics, since everyone can relate to that to some degree.

Assume the following hierarchy of classes and score rollups:

Event class has one or more Sports (e.g., the 2012 Olympics has Decathlon, IndividualMedley, etc.) and one or more EventScores (one EventScore per Team per Event calculated by adding up the team's SportScores for a particular Event)

Sport class has one or more Elements (e.g., Decathlon has Shotput, Javelin, etc.) and one or more SportScores (one SportScore per Team per Sport calculated by adding up the team's ElementScores for a particular Sport)

Element class has one or more Rounds (e.g., Shotput has Throw1, Throw2, etc.) and one or more ElementScores (one ElementScore per Team per Element calculated by adding up the team's RoundScores for a particular Element)

The scoring algorithm (let's call it the CalculateRoundScore() method) of a particular RoundScore depends on the Element to which the Round belongs. Examples:

Shotput element: CalculateRoundScore(double ThrowDuration, double ThrowDistance, double GruntVolume) { algorithm; }

Javelin element: CalculateRoundScore(double ThrowDuration, double ThrowDistance, double GruntVolume) { algorithm (different from Shotput algorithm even though parameters are the same, which would seem to eliminate overloading as a viable option); }

100MeterDash element: CalculateRoundScore(double Time, bool FalseStart) { algorithm; }

Although I am seeking general architecture guidance, here are some of my specific questions:

How do I associate different CalculateRoundScore methods to different Elements?

Should I use interfaces, inheritance, overloading, or some other approach?

In which class(es) should the various CalculateRoundScore methods be located?

Conceptually, I can imagine each Element being an ICalculateRoundScore interface. However, that only makes sense if I create a different class for each different element, which doesn't seem right. It feels like I need some kind of a lookup in which the Round class picks its particular CalculateRoundScore method depending on the Element to which it belongs, but I'm not sure what would be the correct object-oriented way to do this.

答:
However, that only makes sense if I create a different class for each different element, which doesn't seem right

To me, this feels perfectly right, since, it is just an application of the classic "strategy" pattern (in this case a RoundScoreCalculationStrategy). I would design this in a way like this:

```<code> interface RoundScoreCalculationStrategy
 {
     double Calculcate(Measurements m);
 }
</code>```

Strategy objects can easily be put into any kind of lookup table. Measurements will be a base type (or interface) for encapsulating the possible results of one round in one of your sport events (like the tuple ThrowDuration, ThrowDistance, GruntVolume) - so you can separate the supply of those values from the score calculation.  You still have to construct different Measurement objects with different constructor parameters, but now you can

construct those objects at the place in code where you "run the round" (which can be a completely different place from where the scoring takes place)

reuse the same Measurement objects if they contain the same parameter tuples (for example, for Shotput and Javelin), even if the scoring calculation is a different one

Of course, you may consider to use delegate functions instead of different RoundScoreCalculationStrategy objects (which may result in less code if each of your score calculation algorithms is just a small function), but the main idea keeps the same.

One thing to add: maybe it is sufficient not to distinguish between the Strategy classes and the "Element" classes at all. Your different disciplines (which you called Elements above) could get a common virtual base class Discipline - (could be also an interface), where CalculateScore(Measurements m) is just a virtual method of that base class, and Shotput, Javelin etc. are subclasses of Discipline with different implementations of that method.

Body:
However, that only makes sense if I create a different class for each different element, which doesn't seem right

To me, this feels perfectly right, since, it is just an application of the classic "strategy" pattern (in this case a RoundScoreCalculationStrategy). I would design this in a way like this:

 interface RoundScoreCalculationStrategy
 {
     double Calculcate(Measurements m);
 }

Strategy objects can easily be put into any kind of lookup table. Measurements will be a base type (or interface) for encapsulating the possible results of one round in one of your sport events (like the tuple ThrowDuration, ThrowDistance, GruntVolume) - so you can separate the supply of those values from the score calculation.  You still have to construct different Measurement objects with different constructor parameters, but now you can

construct those objects at the place in code where you "run the round" (which can be a completely different place from where the scoring takes place)

reuse the same Measurement objects if they contain the same parameter tuples (for example, for Shotput and Javelin), even if the scoring calculation is a different one

Of course, you may consider to use delegate functions instead of different RoundScoreCalculationStrategy objects (which may result in less code if each of your score calculation algorithms is just a small function), but the main idea keeps the same.

One thing to add: maybe it is sufficient not to distinguish between the Strategy classes and the "Element" classes at all. Your different disciplines (which you called Elements above) could get a common virtual base class Discipline - (could be also an interface), where CalculateScore(Measurements m) is just a virtual method of that base class, and Shotput, Javelin etc. are subclasses of Discipline with different implementations of that method.


问:
How does one deliver messages to (and query from) sites with possibly bad connectivity, having numerous WCF Soap and Web API services?
My company is investigating using a service bus. Currently we have running prototypes of NServiceBus and Microsoft Service Bus (on premise).

I'm quite happy with the pub-sub and topic messaging capabilities the bus provides but I'm getting lost in one of the requirements they are referring to.

For example: They want to query the service bus and "GetAccountInformation()" and expect a result back ala WCF service style and expect the bus to answer them sufficiently to display the result in a UI.

Now, with the above I mentioned the following :

The bus cannot be used for querying as the inherit pattern involves a "high latency" as we cannot be guaranteed that any subscriber would be listening at that point.

It sounds like they want to use the bus as a "hub" for all communications. To me that's sounds like they need WCF relays.

To complicate matters, the reason why they are looking into it, we need to be able deliver messages to (and query from)  geographically dispersed sites some of which has absolute horrible connectivity issues. So, for this case messaging fits.

Also, all different sites have numerous WCF Soap and Web API services.

How to achieve this?

答:
You may be conflating Reliable Messaging, Service Buses, and Pub-Sub.  That's not too uncommon as they often get discussed together and I've yet to find a good definition for a Service Bus.

First, let's start with what seems to be the motivator in your situation:  Connectivity issues.

In cases where connection reliability is bad but you need 100% reliable communication (and you're willing to sacrifice synchronous communication) you can resort to using Reliable Messaging technologies.  A few I've looked into are MSMQ and RabbitMQ.

When you're simply publishing messages and you don't care about a response then this kind of asynchronous communication is useful.

Second, your question about Querying.  Although your Service Bus may use Reliable protocols, that's not the main benefit of the Service Bus.  I may be wrong here, because I've found many conflicting definitions of what SB are, but my understanding is as follows:

A Service Bus is a middleware system that acts as an abstraction layer for your inter-system communication.  Instead of System A knowing about System B and it's communication protocols all System A needs to know about is the Service Bus.

Your Service Bus should expose all your System Services in an easy to use and system gnostic fashion.  This ensures loose coupling between the systems in your network.

That said, your Service Bus should be able to offer you synchronous communication.  So, your call to GetAccountInformation() would be just a regular webservice query.

Finally, I can't promise you if this is a recommended way of doing things, but in my last workplace we combined Reliable Message, Service Buses, and Pub-Sub in the following way:

We had a Service Bus acting as an abstraction layer around many of our system webservices.

The Service Bus also exposed a Messaging Service.

Whenever an application needed to Publish a message to the world it would do so by calling the Service Bus' Messaging Service.

Because it was absolutely vital that none of these messages got lost the communication to the Messaging Service was done using a Reliable Messaging Queue.

Our Service Bus was aware of all the Message (topic) Subscriptions and dutifully notified all the downstream systems (again, using a Reliable Messaging Queue)

Hopefully this helps... though I can't guarantee we didn't get it completely backwards!


问:
Rewriting code under BSD license
I am currently studding OpengGL with OpenGL Supebible 5th edition. I've found interested for me some C++ code that is distributed with the book (see also on google code). That code is under New BSD License. I am writing my software on C# with SharpGL wrapper and I'd like to know following things:

Can I rewrite that C++ to C#? edid: I'am interesting in using such things like GLBatch, GLShaderManager and some other thing from GLTools. Problem is that library is on C++, but I use C#.

How do I have to mark my source code if I put it somewhere like to my github account?

What disclaimer should be?

Original disclaimer looks like:

```<code>/* GLShaderManager.h

Copyright (c) 2009, Richard S. Wright Jr.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this list
of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.

Neither the name of Richard S. Wright Jr. nor the names of other contributors may be used
to endorse or promote products derived from this software without specific prior
written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
</code>```

Edit:
Should my copyright looks like after rewriting something like that?

```<code>Copyright (c) 2014, My Name

Copyright (c) 2009, Richard S. Wright Jr.
All rights reserved.

Redistribution...................
</code>```

答:
That's the original 3-clause BSD license, not the newer 2-clause.  The key difference is the requirement for attribution.

Redistribution and use in source and binary forms, with or without modification,
  are permitted provided that the following conditions are met:

Means do whatever you want, so long as you provide a copy of that copyright notice and don't use Richard's name in promoting the software.

So what should you do?

Copy / re-write whatever code you need.

In your copyright.txt file, include the same block as you listed in the question and then put your copyright statement above Richard's.

If you have any documentation, you'll need to include that same copyright statement because that's what he wrote in his version of the license.  A great way to do this is in an acknowledgements section.

Don't advertise your version as being endorsed or super-duper-wonderful because you borrowed the code from their project.  (That's the "endorse or promote" clause).

Title: Rewriting code under BSD license


问:
What is the pattern for a safe interface in C++
Note: the following is C++03 code, but we expect a move to C++11 in the next two years, so we must keep that in mind.

I'm writing a guideline (for newbies, among others) about how to write an abstract interface in C++. I've read both articles of Sutter on the subject, searched the internet for examples and answers, and made some tests.

This code must NOT compile!

```<code>void foo(SomeInterface & a, SomeInterface & b)
{
   SomeInterface c ;               // must not be default-constructible
   SomeInterface d(a);             // must not be copy-constructible
   a = b ;                         // must not be assignable
}
</code>```

All the behaviors above find the source of their problem in slicing: The abstract interface (or non-leaf class in the hierarchy) should not be constructible nor copiable/assignable, EVEN if the derived class can be.

0th Solution: the basic interface

```<code>class VirtuallyDestructible
{
   public :
      virtual ~VirtuallyDestructible() {}
} ;
</code>```

This solution is plain, and somewhat naive: It fails all our constraints: It can be default-constructed, copy-constructed and copy-assigned (I'm not even sure about move constructors and assignment, but I have still 2 years to figure it out).

We can't declare the destructor pure virtual because we need to keep it inline, and some of our compilers won't digest pure virtual methods with inline empty body.

Yes, the only point of this class is to make the implementers virtually destructible, which is a rare case.

Even if we had an additional virtual pure method (which is the majority of the cases), this class would be still copy-assignable.

So, no...

1st Solution: boost::noncopyable

```<code>class VirtuallyDestructible : boost::noncopyable
{
   public :
      virtual ~VirtuallyDestructible() {}
} ;
</code>```

This solution is the best, because it is plain, clear, and C++ (no macros)

The problem is that it still doesn't work for that specific interface because VirtuallyConstructible can still be default-constructed.

We can't declare the destructor pure virtual because we need to keep it inline, and some of our compilers won't digest it.

Yes, the only point of this class is to make the implementers virtually destructible, which is a rare case.

Another problem is that classes implementing the non-copyable interface must then explicitly declare/define the copy constructor and the assignment operator if they need to have those methods (and in our code, we have value classes that can still be accessed by our client through interfaces).

This goes against the Rule of Zero, which is where we want to go: If the default implementation is ok, then we should be able to use it.

2nd Solution: make them protected!

```<code>class MyInterface
{
   public :
      virtual ~MyInterface() {}

   protected :
      // With C++11, these methods would be "= default"
      MyInterface() {}
      MyInterface(const MyInterface & ) {}
      MyInterface & operator = (const MyInterface & ) { return *this ; }
      MyInterface(MyInterface && ) noexcept {}
      MyInterface & operator = (MyInterface && ) noexcept { return *this ; }
} ;
</code>```

This pattern follows the technical constraints we had (at least in user code): MyInterface cannot be default-constructed, cannot be copy-constructed and cannot be copy-assigned.

Also, it imposes no artificial constraints to implementing classes, which are then free to follow the Rule of Zero, or even declare a few constructors/operators as "= default" in C++11/14 without problem.

Now, this is quite verbose, and an alternative would be using a macro, something like:

```<code>class MyInterface
{
   public :
      virtual ~MyInterface() {}

   protected :
      DECLARE_AS_NON_SLICEABLE(MyInterface) ;
} ;
</code>```

The protected must remain outside the macro (because it has no scope).

Correctly "namespaced" (that is, prefixed with the name of your company or product), the macro should be harmless.

And the advantage is that the code is factored in one source, instead of being copy pasted in all interfaces. Should the move-constructor and move-assignment be explicitly disabled the same way in the future, this would be a very light change in the code.

Conclusion

Am I paranoid to want the code to be protected against slicing in interfaces? (I believe I'm not, but one never knows...)

What is the best solution among the ones above?

Is there another, better solution?

Please remember that this is a pattern that will serve as a guideline for newbies (among others), so a solution like: "Each case should have its implementation" is not a viable solution.

Bounty and results

I awarded the bounty to coredump because of the time spent to answer the questions, and the relevance of the answers.

My solution to the problem will probably go to something like that:

```<code>class MyInterface
{
   DECLARE_CLASS_AS_INTERFACE(MyInterface) ;

   public :
      // the virtual methods
} ;
</code>```

... with the following macro:

```<code>#define DECLARE_CLASS_AS_INTERFACE(ClassName)                                \
   public :                                                                  \
      virtual ~ClassName() {}                                                \
   protected :                                                               \
      ClassName() {}                                                         \
      ClassName(const ClassName & ) {}                                       \
      ClassName & operator = (const ClassName & ) { return *this ; }         \
      ClassName(ClassName && ) noexcept {}                                   \
      ClassName & operator = (ClassName && ) noexcept { return *this ; }     \
   private :
</code>```

This is a viable solution for my problem for the following reasons:

This class cannot be instantiated (the constructors are protected)

This class can be virtually destroyed

This class can be inherited without imposing undue constraints on inheriting classes (e.g. the inheriting class could be by default copiable/moveable)

The use of the macro means the interface "declaration" is easily recognizable (and searchable), and its code is factored in one place making it easier to modify (a suitably prefixed name will remove undesirable name clashes)

Note that the other answers gave valuable insight. Thank you to all you who gave it a shot.

Note that I guess I can still put another bounty on this question, and I value enlightning answers enough that should I see one, I would open a bounty just to assign it to that answer.

答:
The problem of slicing is one, but certainly not the only one, introduced when you expose a run-time polymorphic interface to your users. Think of null pointers, memory management, shared data. None of these are easily solved in all cases (smart pointers are great, but even they are no silver bullet). In fact, from your post it doesn't seem like you are trying to solve the problem of slicing, but rather sidestep it by not allowing users to make copies. All you need to do to offer a solution to the slicing problem, is add a virtual clone member function. I think the deeper problem with exposing a run-time polymorphic interface is that you force users to deal with reference semantics, which are harder to reason about than value semantics.

The best way that I know of to avoid these problems in C++ is to use type erasure. This is a technique where you hide a run-time polymorphic interface, behind a normal class interface. This normal class interface then has value semantics and takes care of all the polymorphic 'mess' behind the screens. std::function is a prime example of type erasure.

For a great explanation of why exposing inheritance to your users is bad and how type erasure can help to fix that see these presentations by Sean Parent:

Inheritance Is The Base Class of Evil (short version)

Value Semantics and Concepts-based Polymorphism (long version; easier to follow, but sound is not great)

OwnerDisplayName: paercebal


问:
Commercial use for embedded system
I am developing a embedded system (computer + os + programs) to sell it to a company.
I am confused about the licensing and the softwares I wanted to use to develop the system.So I want to know if I can use these programs free of charge and without distributing the source code for commercial use.I wanted to use:

A linux distro o custom linux build:I thought Arch Linux

A Web Server + PHP + MySQL: I thought XAMMP,they says that is free of charge for commercial use but I don't know if the components are also.

A QT backend and frontend,but I don't know if I can use the LGPL version for commercial use or I need to use the Commercial License.

jQuery (I saw that if I maintain the notice,I can use it)

Thanks for your response

答:
I can't give legal advice, but I can point you at some starting points:

First, if you are shipping GPL software such as Linux, you cannot escape the obligation to offer source. For a detailed breakdown of your obligations, read A Practical Guide to GPL Compliance. Many companies ship embedded Linux systems while complying with these guidelines.

One important point is that to comply with these licenses you need to know what packages you ship, and be prepared in advance for a source code request. There is no substitute for building a list of all software you plan to distribute, including packages incidentally installed as part of the Linux distribution, and reading each license.

For most of the open-source licenses, commercial use is not a relevant distinction. Item 6 of the Open Source Definition is that an open source license should not discriminate based on field of endeavor. Most open source licenses follow this rule (except for JSON, assuming that evil is a field of endeavor).

The LGPL packages have conflicting interpretations for embedded systems. Under the Webkit interpretation it is sufficient to offer source code, but under the Mono/QT interpretation it is also necessary to provide the end-user with the ability to rebuild the package and install the new version on to the embedded system. Obviously each side has a strong commercial reason for its opinion.

Title: Commercial use for embedded system


问:
What is "using namespace" pollution?
I was looking at the google coding guide [here] and they do not recommend that one use the using namespace or namespace::function - if I did not misinterpret it.

Does this apply to std as well? cout<< does not work without it. This book, recommends the same. So how do I go about using cout<< without using namespace std; or std::cout<< ?

What is the recommended way? std::cout<<? Most c++ text books teach beginners with using namespace std; are they propagating poor coding practice?

答:
As I read the Google standard, you cannot use the using namespace foo; directive anywhere. This directive brings in everything declared in the namespace and is a common cause of collisions and unexpected behavior. Others have cited a very common one: you have your own max or min method somewhere and it collides in a src file where someone includes a header with your method and then says using namespace std;

In certain places, it is permitted to have a using declaration, which is of the form using ::foo::bar;

People like to put using directives in their code because it saves a lot of typing, but it comes with risk.  If you have a file with a lot of cout statements, I can understand not wanting to have to type std::cout a hundred times, but you can simply say using ::std::cout. I treat these like variable declarations: scope them where they are needed. If one function in a file of 10 needs to write output, don't declare the cout way at the top, put it in that function that is doing the actual output.

```<code>#include <ostream>
//using namespace std; // NO!
//using ::std::cout;   // less bad than using namespace, but I prefer to scope it

int main(int argc, char** argv)
{
   int rc = do_some_stuff(argc, argv);
   using ::std::endl;
   if (rc) { // print the success report
      using ::std::cout;
      cout << "The test run completed. The return code was " << rc << '.' << endl;
    } else {
      using ::std::cerr;
      cerr << "Unable to complete the test run." << endl;
    }
    return 0 == rc;
}
</code>```

That's a little extreme with just a couple of lines doing output, but you get the idea.

Another thing one can do is alias or typedef to minimize the typing. I don't find std::whatever to be that bad, but we have a huge set of source with several dozen modules and sometimes we have to write code like console_gui::command_window::append("text"). That gets tedious after a while and causes a lot of long lines. I am all for something like

```<code>typedef console_gui::command_window cw;
cw::append("text");
</code>```

as long as the aliases are done in a local scope and keep enough context to make the code readable.

Title: What is "using namespace" pollution?

Body:
As I read the Google standard, you cannot use the using namespace foo; directive anywhere. This directive brings in everything declared in the namespace and is a common cause of collisions and unexpected behavior. Others have cited a very common one: you have your own max or min method somewhere and it collides in a src file where someone includes a header with your method and then says using namespace std;

In certain places, it is permitted to have a using declaration, which is of the form using ::foo::bar;

People like to put using directives in their code because it saves a lot of typing, but it comes with risk.  If you have a file with a lot of cout statements, I can understand not wanting to have to type std::cout a hundred times, but you can simply say using ::std::cout. I treat these like variable declarations: scope them where they are needed. If one function in a file of 10 needs to write output, don't declare the cout way at the top, put it in that function that is doing the actual output.

#include <ostream>
//using namespace std; // NO!
//using ::std::cout;   // less bad than using namespace, but I prefer to scope it

int main(int argc, char** argv)
{
   int rc = do_some_stuff(argc, argv);
   using ::std::endl;
   if (rc) { // print the success report
      using ::std::cout;
      cout << "The test run completed. The return code was " << rc << '.' << endl;
    } else {
      using ::std::cerr;
      cerr << "Unable to complete the test run." << endl;
    }
    return 0 == rc;
}

That's a little extreme with just a couple of lines doing output, but you get the idea.

Another thing one can do is alias or typedef to minimize the typing. I don't find std::whatever to be that bad, but we have a huge set of source with several dozen modules and sometimes we have to write code like console_gui::command_window::append("text"). That gets tedious after a while and causes a lot of long lines. I am all for something like

typedef console_gui::command_window cw;
cw::append("text");

as long as the aliases are done in a local scope and keep enough context to make the code readable.


答:
I've gone from assembler and COBOL to Ruby.

What helped me initially was actually ignoring the concept of classes creating instances.

Just start with code.  Have a class but just have class level methods.  Within methods a lot of stuff is about parameters, variables, conditionals, arrays, strings, Booleans etc.  This stuff should be familiar.

So at this point the class can be seen as just serving the purpose as a place to put all your related methods in.  Call it a container or a library will be more familiar to her.

Obviously code has to be segmented to be manageable so you'll have one of these each area.  For example, for managing a set of utility programs on a pc, you might have a calculator class where you could put all the code for a calculator in one place.   If you only have 1 calculator on your pc then class level methods are enough.

That's a start.

ok now consider the fact that you want to open up multiple calculators and change how each one looks and where it is on the screen.  So now you can't just have a calculator method like 'screen_location' because you have several of them and each instance has its own location... each instance... ok, so we need instances.

Note: my terms are from ruby not c++ so you may need to translate.

Title: How can I explain object-oriented programming to someone who's only coded in Fortran 77?

Body:
My mother did her college thesis in Fortran, and now (over a decade later) needs to learn c++ for fluids simulations. She is able to understand all of the procedural programming, but no matter how hard I try to explain objects to her, it doesn't stick. (I do a lot of work with Java, so I know how objects work) I think I might be explaining it in too high-level ways, so it isn't really making sense to someone who's never worked with them at all and grew up in the age of purely procedural programming.

Is there any simple way I can explain them to her that will help her understand?


问:
Why are more programmers not freelance these days?
Leaving the whole pie to only a few of them, amplifying the huge differences between the two status. Pay is a (huge) one, not having to do overtime is another.

I leave the question open to hopefully get many great answers on all the different subjects that affects that feeling and decision not to go.

While this question is really global, I'll be interested in any studies, facts, articles, opinions regarding local markets such as US, India and even Australia in which I'm in love with.

答: Here in Italy for two main reasons: too much bureaucracy and high taxes


问:
JSF problems due to shared server-side state
On it's latest technology radar, the guys at ThoughtWorks recommended avoiding JSF because it's attempt to create statefulness over HTTP ends up "causing a whole host of problems involving shared server-side state".

I've been using JSF 2.x for almost a couple years now, I like it and I can't say I've encountered any problems like that. But I don't have that much experience with it and much less with alternatives, so I would like to understand what are those "whole host of problems"?

Questions about JSF usually raise some heated discussions, so I think it pays to be clear: this is about JSF 2.x, but not about it being better or worse than X or Y, whether it's architecturally right to put state in HTTP, or anything like that. I'd just like to know what are those problems since the radar doesn't go on specifics.

答:
I've managed to find some useful facts about problems in the stateful HTTP model. The original "whole host of problems involving shared server-side state" still sounds vague to me, but some of the references I've gathered do cover it up to some extent (and interpretation).

First comes performance issues, one of the most common complaints. JSF has to create, manage and send the view state back and forth, between the client and the server, and that's quiet costly. This cost may be minimized to some degree by:

Using a different implementation. I've found a 2012 blog post that points out that 2.1.7 MyFaces is less resource intensive than it's Mojarra counterpart. Keep in mind that, as it always is with performance issues, this may change in future versions.

Disable state saving, which should actually fix all those problems, but the performance is still not optimal. This answer shows that JSF 2.2 with disabled state is still slower than plain servlet. Notice that an user questions whether that's a valid comparison or not.

Second, delivering a RIA experience may be harder when the state does not belong to the client. This also boils down to performance, but it seems to be more than that. To simulate a desktop-like experience in a stateful HTTP application, developers end up dealing with the complexity of view state directly. I believe implementing some kind of UI flow is a nice way to see that. It works, but it's quite messy. JSF 2.2 provides the flow scope to make the developer job easier, but I found it still a little rough around the edges.
This post gives a simple example of this kind of problem.

Finally, relying on the session to hold view state makes the job of clustering your application harder since you'll have to share that session between instances. Application servers do provide mechanisms to do that, but you'll end up using more resources. Also, some PaaS providers will charge for session replication. Using that just because of JSF does not strikes as a good idea.


问:
What is (or where can i find) the algorithm to decode FLAC to PCM?
I'm trying to program a very basic FLAC player using 100% C# completely from scratch. My understanding of this type of thing is very limited, so I'm using this project as a way to learn about compression and decompression. I'm a computer science and math major currently in university, so I'm not adverse to learning whatever math may be involved.

I've looked up the format specifications on xiph.org and I understand how the headers and all are structured, but I can't seem to find a concise explanation of how the audio compression works. How do I go about converting the frames to pcm?

Sadly,  my knowledge of C/C++ is extremely limited, as I only have experience with Java and C#. As such, trying to navigate the c++ code already out there is not a great starting point. I looked at FlacBox and learned quite a bit from it, but it's barely commented at all and I am lost trying to figure out how the conversion from flac to pcm works.

So what should I read as far as math goes so I can get started with this? Where can I find a basic algorithm for converting the audio frames to wav? Thanks.

答:
You need to look a little closer at the format page on the FLAC website.  The "prediction" paragraph leads to this article, which describes the AudioPak algorithm in detail, and also Shorten.

You should learn and understand these algorithms and the associated math before digging into the source code.  That might take awhile.


问:
How to design this better?
I'm developing a system using .NET which will be used by multiple users. Because of that, I need to identify on the database which data belongs to each user. Explaining with an example, imagine I have the entity Product. Then each user has its own products, and so in the database on the table of products we must be able to distinguish between products of each user.

Saying that, my solution was to add on the database an extra column for each table for the user id. Now, on my code this was the same as adding on my repositories a parameter to receive the id of the user so that the repository would be able to locate the correct data. The  concrete implementation of the repository to deal with relational databases just check those columns.

The problem is that to be able to get those columns available on my repository, and on my ORM (in the case EF) I needed to add on each entity one property UserID. The problem is that if I think for a while this doesn't seem like a good solution. I'm coupling domain entities with details of how to persist data. More than that, I'm coupling each entity with the way I manage the access to the data and this seems a bad approach.

So, concearning this, is there a better way to plan this? A way to make sure we can relate data to users and in the same time avoid those properties on the domain entities?

答:
If each user truly has their own products, and user Joe's product named 'Foo' has nothing to do with user Jane'e product named 'Foo' (too, by pure coincidence), then the user ID does belong to your problem domain.

I don't see why you have to add a user ID column to every table that references a product. A product may have an (artificial) unique PK, and a product's user ID can be looked up in the product table using it.

If, on the other hand, your products make sense when separated from users, I assume there's an M:N relationship between products and users. A table of pairs (product_id, user_id) would suffice then.

Title: How to design this better?


答: The law of inertia, may be. Most of them are already working for some company and are well settled. They may not want to change the line and dig into new territory. </p>

Title: Why are more programmers not freelance these days?

Body:
Leaving the whole pie to only a few of them, amplifying the huge differences between the two status. Pay is a (huge) one, not having to do overtime is another.

I leave the question open to hopefully get many great answers on all the different subjects that affects that feeling and decision not to go.

While this question is really global, I'll be interested in any studies, facts, articles, opinions regarding local markets such as US, India and even Australia in which I'm in love with.


问:
At what point does data access\manipulation logic becomes business logic?
Consider a service which updates PersonDetail tables in database. I am Using EF which maps the table to this Entity. When a record is updated, it is not actually updated but a new record is created and old one is made history by setting HistoryCode to 0

```<code>Class PersonDetail
{
  int age;
  Date birthDate;
  DateTime effectiveDate;
  int sequenceNumber; //An incremental number.
  int HistoryCode; //0 represents history record and 1 current record
}
</code>```

Now we have a service that updates the person details

```<code>if(newPersonDetail.effectiveDate < currentPersonDetails.effectiveDate)
{
  //update sequence number of currentPersonDetails by 1
  //insert a new Person Details record and assign its sequenceNumber as the sequence number
  //of currentPersonDetails and HistoryCode as 0 to represent this is an history record
}
else
{
   //Make the currentPersonDetails HistoryCode to 0 from 1
   //Insert a newPersonDetail with sequence number incremented by 1 and HistoryCode set to 0
}
</code>```

Logic? I am trying to move the data-access logic out of service layer to repository layer but not able to clearly figure out what part of this is considered as business logic and what is considered as Data Access logic.

答:
Your question cannot be answered in general, but your example shows one thing : difference between business logic or requirement and implementation of that business logic.

In your example, but business requirement might be "Always keep history of changes to all Personal details." Just because it is implemented as flag inside table and not separate table or some other way is implementation detail. Your business analyst doesn't need to know how this history tracking is implemented. So the code in your case can be described as "manipulation logic, that implements a business requirement".


答:
In this case you should have userid in entities (Categories, Customers, etc) as a FK. Instead of creating separate table for each and every user, use one table and have a FK in that table which will be linked to User main table. </p>

<p>However if you have customer main table then you just can have a transaction table between User and Customer. </p>

Title: How to design this better?

Body:
I'm developing a system using .NET which will be used by multiple users. Because of that, I need to identify on the database which data belongs to each user. Explaining with an example, imagine I have the entity Product. Then each user has its own products, and so in the database on the table of products we must be able to distinguish between products of each user.

Saying that, my solution was to add on the database an extra column for each table for the user id. Now, on my code this was the same as adding on my repositories a parameter to receive the id of the user so that the repository would be able to locate the correct data. The  concrete implementation of the repository to deal with relational databases just check those columns.

The problem is that to be able to get those columns available on my repository, and on my ORM (in the case EF) I needed to add on each entity one property UserID. The problem is that if I think for a while this doesn't seem like a good solution. I'm coupling domain entities with details of how to persist data. More than that, I'm coupling each entity with the way I manage the access to the data and this seems a bad approach.

So, concearning this, is there a better way to plan this? A way to make sure we can relate data to users and in the same time avoid those properties on the domain entities?

Body:
In this case you should have userid in entities (Categories, Customers, etc) as a FK. Instead of creating separate table for each and every user, use one table and have a FK in that table which will be linked to User main table.

However if you have customer main table then you just can have a transaction table between User and Customer.


问:
Unit Testing Wrapper (Facade?) Method
I have to write unit tests for some classes my group is developing.  The classes are fairly simple, and I'm not sure how to best test them.

```<code>public class MyObjectRegistry
{
    private myDataSetMapper = new MyDataSetMapper();

    public boolean StoreObjects(list<MyObject> myObjectList)
    {
        myDataSetMapper.StoreObjects(myObjectList);
    }
}

public class  MyDataSetMapper
{
    public boolean StoreObjects(list<MyObject> myObjectList)
    {
        for(MyObject myObj: myObjectList)
        {
            boolean result = StoreObject(myObj);
        }
    }

    private boolean StoreObject(MyObject myObject)
    {
        //Store the object in a database
    }
}
</code>```

So my question is how to test the MyObjectRegistry.StoreObjects and MyDataSetWrapper.StoreObjects methods since there's no real logic other than a foreach loop and calling out to another method.

I've looked around the web and found that I think I'm looking at a "facade" class/method, but I'm still unclear on what would I should test/assert in the test method.

答:
The problem is that MyObjectRegistry creates a new MyDataSetMapper, instead of having that dependency injected. The appearence of "new" creates a hard, compile-time dependency on MyDataSetMapper. There are two ways to go:

Use a reflection utility (Like ReflectionTestUtils) to forcibly set that variable to a mock instance of MyDataSetMapper. Yuck!

Change the class so that instead of instantiating MyDataSetMapper, it gets injected as a dependency instead:

public MyObjectRegistry(MyDataSetMapper mapper) {
    this.myDataSetMapper = mapper;
}

Now you can instantiate the registry with an injected mock instance, and you're testing the unit under test (the registry object) and not the MyDataSetMapper.

If MyDataSetMapper talks directly to the database, then there's no point in testing it in isolation, since it's by nature an integration object. You can test that out in integration tests, or just by running and exercising the application.

Title: Unit Testing Wrapper (Facade?) Method


问:
How can I explain object-oriented programming to someone who's only coded in Fortran 77?
My mother did her college thesis in Fortran, and now (over a decade later) needs to learn c++ for fluids simulations. She is able to understand all of the procedural programming, but no matter how hard I try to explain objects to her, it doesn't stick. (I do a lot of work with Java, so I know how objects work) I think I might be explaining it in too high-level ways, so it isn't really making sense to someone who's never worked with them at all and grew up in the age of purely procedural programming.

Is there any simple way I can explain them to her that will help her understand?

答: One key insight that has helped me in explaining before is the fact that you can have multiple instances of a class. Try to explain that in terms of "drawings" or "moulds" and "copies" and see if it leads anywhere.</p>


答:
People start working for companies because of other benefits you get from salaried jobs, social activities, girls, regular pay rise and of course tried and tested path for the most of us.

When you are freelancing, you are on your own, irregular project orders may be, bidding for projects can be confusing as in how much to bid, is it very high or very low. After some experience you start bidding accurately but that takes some time. While not having projects, loneliness makes you start thinking negatively. Many people who are freelancing I am sure are well organized and they know how to get the most of them. They are busy bees most of the day   and they get to enjoy their flexible timings


问:
Programming PHP without MVC, classes or framework: rewrite or continue on new features?
I have been programming for several years now, and back then (learning PHP) I've didn't learn to program using classes, MVC-logic or using any frameworks. I found my self solving my problems very well using my own functions.

Eight months ago I was recruited to a start-up, to develop a huge social platform. I have been working there for several months now, and built up a huge website with various complicated features (+35k lines of code I guess), and I could see my self continue like this. Everything is coded without any framework, no classes or with MVC-logic, since I didn't have the time to learn it (we had to move fast).

I do write everything in functions, and put a lot of effort in well documenting/describing my code as well as organizing it beautifully and easy-to-read.

However, it is top of my list to learn Classes > MVC > Laravel (or any other) framework. But I just can't see my self stopping now, learning above list, and then rewrite all code. This would simply push us back in time, and in the start-up we're moving fast and have many deadlines for new features/ideas/development.

I've spoken with many people regarding this, and people say a lot of different things. Some say it's a matter of taste, and you'll be able to move on with it. Others say it's incredibly stupid, you're not scaleable, you're never get serious funding, you're the only one who ever be able to work on the project, you should stop and start learning it now, etc.

Am I doomed? I feel lost. My personal opinion on this is, that even though it is a huge system already, it is still a MVP and I guess at some point in the future we would rewrite the code anyways. This is, if we're at such a successful stage in our venture and growing very fast / getting funding / etc.

答:
Rewriting a large system such as yours just to organize the code in classes at first doesn't seem too bad, but unless you are going to be rewarded for your efforts by then having a system that has much less bugs, is easier to extend, more optimal and so on, I would say that your time is better spent maybe thinking about writing extensions to your application using classes at the very most.

It is true that most frameworks and large applications favour oop code organisation, but it certainly isn't a requirement. Having learned to love functional programming languages, especially ocaml, I personally feel that classes are inferior to functions, and now that php offers better use of functions and closures, there really is no damning reason to use classes at all. This may be blasphemy for most, but I believe it to be the case.

Classes do have their uses but they are not a necessity. Let's look at some use cases where the traditional use of classes and their equivalents, namely static methods and instances.

Static Methods.

Using namespaces, it is more than possible to have the same functionality as a static class method, and since it is possible to have different namespaced methods grouped across different files, arguably much more flexible and extendible.

Instance State.

An instance of a class contains it's own internal state. This has always been touted as one of the benefits of using OOP. It is equally viable to use closures to do the same just as equally and has been used successfully in many other languages to great success.

So, my advice is to keep trail-blazing. You may me grateful over time as people start migrating to your coding style.


答:
Don't know about others, but thinking about myself:

I have a job that I'm currently happy with. I work regularly and get paid regularly. Of course there's always too much things to do, but still, the work is mostly interesting and the workload is approximately constant and predictable. Hardly so with freelancing (think of work requests as a Poisson process, and how the stability of frequency depends on the average frequency; a cafeteria with 10 customers and 1 toilet is not linearly proportional to a cafeteria with 100 customers and 10 toilets, i.e. the queue is not similar).

Going freelance would require me to do all the marketing, selling, bureaucracy etc. boring and scary (but admittedly, important) stuff. Actually I don't think I could do it successfully. At least I would hate it.


问:
What does "mockable" mean?
I came across this term when looking into PHP's "traits" (which are apparently bad, since, among things, they're not mockable), but I can't really find a definition for this "mockability". It might be related to polymorphism? There isn't even a Wikipedia entry I could find!</p>

答:
Huh. I found this after looking at stackexchange's description of the "mocking" tag. Since you, reader, might be like me, check this out: http://en.wikipedia.org/wiki/Mock_object

In object-oriented programming, mock objects are simulated objects
  that mimic the behavior of real objects in controlled ways. A
  programmer typically creates a mock object to test the behavior of
  some other object, in much the same way that a car designer uses a
  crash test dummy to simulate the dynamic behavior of a human in
  vehicle impacts.

Title: What does "mockable" mean?


问:
What is the most productive way to handle development-related failures?
We've all been there:

Your project failed or got cancelled.

The code you spent days working on got rejected by your team.

The design pattern you introduced to the team created chaos.

Everyone ignores your ideas.

My question is, what is the most productive way for a programmer to handle development-related failures such as these?

答:
Oh boy, that's a lot if you really meant everything happened to you!

WARNING: In many of the points below you might feel like I criticize you and that I want to make you responsible for the mis-happs and not consider external factors. I don't. It's just that you don't give much details, and I just provide check-lists of actions to undertake to ensure that things don't go awry. I know I've done lots of mistakes myself (everybody does) and we only get better if we learn from them. And to learn from them, we need to start to see them as mistakes in the first place, and accept responsibility for what went wrong on our part. Hell, accept responsibility for what went wrong in other people's parts, you can learn from that as well.

Your project failed

Not much you can do to mitigate it now.

However you can do a lot to avoid that to reproduce in the future. I'd suggest trying to improve your project and time management skills.

One of the books with the best ratio ((valid advice) / pages) I've read on the subject, while maybe not the best, it Rob Thomsett's Radical Project Management.

You don't really specify what your project failed, but I'd assume a combination of thing which brought unbalance in the usual cost/time/qualiy triangle. The most important factor in my eyes is to lead the project and the development while being always in touch with both your technical actors (devs and testers) but also your stakeholders. Far too many projects fail because they don't listen to sponsors or stakeholders and don't push them to get involved in the process.

If they're not involved, you cannot know what they want. If you cannot know what they want, you cannot deliver it. If you don't deliver it, they'll be unhappy. That's a failure.
Furthermore, if you don't involve your stakeholders, they're disconnected from the reality of software engineering, meaning they don't understand your issues. If they are often in touch with you, they get a better grasp of what you have to deal with. They'll be more able  to understand when you tell them that a "small" [laughter] feature will take months. They can trust your planning better because they helped building it. A project cannot succeed with just "specs at the beginning, dev, testing, delivery at the end". It just never does. You might deliver what was asked for in the specs, but not what the customer really wanted.

Most important as well, do a retrospective, and ensure it is ego-less and not a blame-game. Just identify issues.

What you have spent days coding was rejected by your team

I have been in that situation. Again, not much you can do to mitigate that except:

Keep it in the SCM for later.

Maybe try to push small bits and pieces progressively into the major code base instead of a huge refactoring.

But there are things again you can do to prevent this sort of situation:

Why did it happen? What's the reason of the rejection?

Most of the time when I see this happen (and that was the case for me too), it means the developer went solo or in cow-boy-coding mode and produced things that were never asked for. Code that doesn't come from business requirement might be fancy and "better", but often a waste of time and money. Plus, it will cost even more if you integrate it as it will need testing again. Think like the people who deal you the money: you have to be efficient on that level as well.

Was the quality of the software produced satisfying? Did it comply to standards and conventions in activity at your company?

Did you periodically (and frequently!) report to direct managers about this? Did you occasionally exchange with other developers of the team? If not, they don't know anything about it, it will be a huge time cost for them to assess and review it now. It does NOT account to the same time in the end. It's like always trying to put off cleaning your rental apartment and then trying to clean it only when you move out: It's a crappy job, it's exhausting, it's harder than it would have been if done regularly, and it often won't be done right.

Did you produce produce tests? Units tests? Integration tests?

Was your code checked into the SCM regularly? Was it in a different branch? Did it need a different branch or could it have been done in trunk? Putting off committing code is usually a bad sign. Obviously sometimes you're tempted to do it, but you just shoot yourself in the foot.

Nobody listens to your ideas in your company

Well, there are 2 options here, and we'll look at both:

You're ideas were bad.

You're ideas were good.

Let's start assuming they were bad (again, self-reflecting on that and accepting your idea was just plain bad might be difficult, I know). What do you do to change that?

Why did you come up with the idea? What's the rationale? Is there a real need to what your idea tries to bring to the table?

How did you come up with the idea? Did you do it on your own? Did you share? Brainstorm? Plan? Prototype? (do these in the right order. If it fails on the way, then discard the idea, don't keep going. Or at least not on your work schedule.)

Ideas are only ideas. If you just suggest them as ideas and they are rejected, I don't see why you would feel bad about it. If however you act up on them without notifying anyone and THEN only submit your ideas and they get rejected, obviously I feel the frustration at the time wasted. And your managers do to!

Assuming your ideas were good:

Was your presentation good?

Was your way of delivering the presentation good? (I'm a developer, I know what I'm talking about: We're grumpy, arrogant, pedantic PITAs who are always right and with whom it's hard to work with because often of our disproportionate egos).

Do you have a plan to implement it? Did you think about the cost and time? Did you think
how it benefits users/customers? Did you think how it impacts sales? Did you think how working on that idea might impact other projects and priorities? You're going to tell me, "why should I do all these, they're the job of my manager and the marketing or sales teams?!" Except right now, you are trying to do part of all their jobs.

The design pattern you introduced with force in your team created a mess

Why did you introduce the pattern?

If it created a mess, then it probably either:

wasn't the right pattern,

wasn't implemented right,

wasn't integrated right.

How did you introduce it? How exactly do you define the state "mess"?

less readable code?

less maintainable?

builds are broken?

There are different kinds of "mess". Knowing what the mess is might help to know what the failure in there was, and if it was the design pattern's fault.

Also, I am a bit surprised by the approach itself. You had to actually push for a design pattern to be introduced? That seems rather odd. A pattern is either there already, or you need to refactor a part of your solution according to the pattern. You don't push it like you would the adoption of a framework or technology (like people pushed really hard to have XML everywhere, and now like people start pushing to be able to write HTML5 on their product cover in big bright letters).

Why did you have to push? Why was there resistance? Maybe it was justified.

Were you able to you provide examples that this particular pattern would help to improve your code base in significant ways (for instance, by matching it with an example of Refactoring to Patterns).

Completely off-topic note but that's what I first thought of when I read the question's title as I thought it referred to software failures... I had a software who implemented a BlackHole class to manage a very special kind of exceptions in one of the components. It may seems like (and really is) an obviously weird and dirty hack, but the naming itself was so superb we all appreciated it for a fairly cool way to handle a failure! :)


答:
So unit tests are there to test logic, not plumbing. You don't have any logic in your (albeit small) example so it dosent need testing.

Generally speaking it should be obvious what needs testing in a method since it does one thing and its name tells you what it does. If that isnt the case you should probably look into breaking your code into smaller components.

Title: Unit Testing Wrapper (Facade?) Method

Body:
I have to write unit tests for some classes my group is developing.  The classes are fairly simple, and I'm not sure how to best test them.

```<code>public class MyObjectRegistry
{
    private myDataSetMapper = new MyDataSetMapper();

    public boolean StoreObjects(list<MyObject> myObjectList)
    {
        myDataSetMapper.StoreObjects(myObjectList);
    }
}

public class  MyDataSetMapper
{
    public boolean StoreObjects(list<MyObject> myObjectList)
    {
        for(MyObject myObj: myObjectList)
        {
            boolean result = StoreObject(myObj);
        }
    }

    private boolean StoreObject(MyObject myObject)
    {
        //Store the object in a database
    }
}
</code>```

So my question is how to test the MyObjectRegistry.StoreObjects and MyDataSetWrapper.StoreObjects methods since there's no real logic other than a foreach loop and calling out to another method.

I've looked around the web and found that I think I'm looking at a "facade" class/method, but I'm still unclear on what would I should test/assert in the test method.


问:
Best practice for configuration files in a website
I am creating something similar to a Content Management System, that can be downloaded and used by everyone that needs it. I've been working in web-development for a couple of years (mainly as a hobby, i.e. creating personal homepages for acquaintances), but have never had the need of a user to enter his own configurations (let it be database connection, meta-data about his site, desired behaviour of the website).

Therefore I have no experience with custom configuration file handling. That's where my question lies: What is the best practice to handle custom website-wide configuration files and handle them in PHP?

I have thought of creating INI-files, that can be customized from within the admin panel and that are hidden to the user by .htaccess for security purposes. However I don't know if INI is the best method to do this considering that the page is being developed to be extensible through plugins (which may lead to another question soon).

So what is my best bet to handle configurability? For instance do I want to store database configuration in files somehow and have other configurations outsourced to the database itself? Or do I store everything in INI-files (also considering configurability for plugins: Should everyone of these have their own config-file)?

答:
Have you looked at other CMS and how they approach the problem?

For example, Drupal configuration responds to all your current needs and shows one possible way to not being limited by the constraints of INI.

You may also consider:

Ordinary PHP files (pros: simple, no parser needed; cons: the end user can screw the file and break the entire app),

INI (pros: still simple; cons: the flat structure is limiting),

XML (pros: no limits of INI; cons: not user-friendly, too much markup),

JSON (pros: less markup compared to XML; cons: still not user-friendly),

YAML (pros: humanly-readable; cons: the end-user can still screw the structure),

Custom page which allows the user to configure every aspect of the application though web interface (pros: user-friendly; cons: the excessive cost of developing the solution).

If you're working with end-users who don't have technical background, the last solution is the only one viable.

Applications like PHPBB show how to make two-step configuration: when the application runs for the first time, it executes setup.php which asks for the connection string, the root password, etc. Once the app is installed, the administrator can log in to access the administration panel.


问:
How can I team up two MVC frameworks without having them fight each other?
I'm creating a CRUD-based web project, and am thinking about using a server side MVC framework (such as CodeIgniter or Laravel) in tandem with a client side MVC framework (such as AngularJS). Is this a fairly common approach? After all, it's clear that I need something on the server, and that doing MVC on the client as well can enhance my application. But I feel that two MVC frameworks on the same project would just get in the way of each other and lead to disproportionate complexity and repetition.

What kind of approach or architecture would help me get the best out of both MVC frameworks when using one on the client, the other on the server?

答:
Disclaimer: I am not familier with PHP.

For ASP.NET, it is a common practice to use ASP.NET MVC (+ Web API) and AngularJS together.

The routing should not be an issue, as

all the routing requests will first be received by AngularJS.

Only the service calls from Angular JS would reach Server side MVC.

Typically, Serverside MVC will handle Authentication / Authorization for all routes, and everything else would be handled by AngularJS application.


答:
There are different configurations for any decent web application. Some of them has to be stored on the file system, because at the initialization time you don't have access to the Data Storage, unless you hard-code it inside the source code.

You can store those configuration which are mostly database connection and encoding settings into any format that could be later feed into your application.

An INI file is good because it is simple. So if a non-technical user has to go and manually edit the configuration, it is less likely that they broke it, however there is a very small overhead in terms of parsing it. The INI files are one of the most common way of storing configuration data.

Another option is to make use of JSON to store the data. In this case it will harder to modify the file manually, however JSON is kinda established as an standard way of dealing with data. That meant to be like this in fact.

A PHP file containing any form of valid PHP code could be another option. You can define your options as Constants then you will have all of them in the global scope -- it could be a good thing at development time or a potential security hole in the production, specially if you're allowing third-party code to be included by user in your application.

A PHP Array of settings or a Serialized string of an array are other options. You can have an instance of your configuration class as well, inside your configuration file, that could provide you with extra functionality as well.

After your application is initialized, then you can connect to the data storage and load or store the rest of work in there which is more convenient for most cases.

P.S. There are dozens of other formats like XML, etc. that you can use them as a way to store the application configuration, but they are almost same as JSON and INI files in terms of explanation, so I'm not going to list all of them. You should eventually choOse a format that is more suitable for your end-user or offer them couple of ways and let them choose how they want to store the configuration -- I know that it sounds like an overkill but at some projects it's necessary to support different formats.

Title: Best practice for configuration files in a website

Body:
I am creating something similar to a Content Management System, that can be downloaded and used by everyone that needs it. I've been working in web-development for a couple of years (mainly as a hobby, i.e. creating personal homepages for acquaintances), but have never had the need of a user to enter his own configurations (let it be database connection, meta-data about his site, desired behaviour of the website).

Therefore I have no experience with custom configuration file handling. That's where my question lies: What is the best practice to handle custom website-wide configuration files and handle them in PHP?

I have thought of creating INI-files, that can be customized from within the admin panel and that are hidden to the user by .htaccess for security purposes. However I don't know if INI is the best method to do this considering that the page is being developed to be extensible through plugins (which may lead to another question soon).

So what is my best bet to handle configurability? For instance do I want to store database configuration in files somehow and have other configurations outsourced to the database itself? Or do I store everything in INI-files (also considering configurability for plugins: Should everyone of these have their own config-file)?


答:
The use of mock objects in unit testing is fairly commonplace. Mock objects are, as you've said, controlled objects that mimic behavior of some other objects you don't want to touch. A good example would be a method that writes something in the database - instead of using actual database records, you are far better off using mock objects to mimic the database adapter and provide mock result sets, in order not to touch the database at all (if you're inserting into a database, at the end of the test you would need to alter the tables back to their initial form, but if you stop the test mid-process the database would remain affected by the test and you would get inconsistencies, other units might be affected further down the road in the test case so it would break the context of unit testing and so on).

The problem with traits not being mockable is that they are not concrete objects - in the inheritance chain they sit somewhere between the child and the parent, out of your control through the unit testing framework (without altering the actual code of the application to provide specific functionality, which I don't think I need to say it's utterly pointless). A somewhat distant analogy would be to the decorator design pattern, where particular objects are augmented at runtime with various other injected behavior which can differ from the implementation of the original class - but in the case of decorators, you know what to expect and can destroy the context after each unit is executed.

Because a trait can alter the objects's context (calling a method implemented in the trait that does database operations, for example, or having a trait that overrides an internal class variable from the parent class, that's not controlled in the child class), you can get unexpected behavior which can exist outside the scope of unit testing and which you cannot control using a mock. To continue the analogy with the crash test, you would have a crash test dummy that can pull the parking brake or unbuckle its seat-belt without you being able to control that part of the behavior.

Title: What does "mockable" mean?

Body: I came across this term when looking into PHP's "traits" (which are apparently bad, since, among things, they're not mockable), but I can't really find a definition for this "mockability". It might be related to polymorphism? There isn't even a Wikipedia entry I could find!</p>


答:
MVC/MVVM Frameworks on the client-side are totally separated from the frameworks that you're using on the server-side. Without a back-end for AngualJS for example you won't get that much functionality for your application. The back-end could be NodeJS app or Laravel or Zend Framework or anything else.

Your approach is totally valid to make use of an MVC frameowork on the server-side and an MVC/MVVM on the client-side, however there isn't any general best practices to mention here as your question is to broad in that sense.

Title: How can I team up two MVC frameworks without having them fight each other?

Body:
I'm creating a CRUD-based web project, and am thinking about using a server side MVC framework (such as CodeIgniter or Laravel) in tandem with a client side MVC framework (such as AngularJS). Is this a fairly common approach? After all, it's clear that I need something on the server, and that doing MVC on the client as well can enhance my application. But I feel that two MVC frameworks on the same project would just get in the way of each other and lead to disproportionate complexity and repetition.

What kind of approach or architecture would help me get the best out of both MVC frameworks when using one on the client, the other on the server?


问:
How can I promote software reuse in a large company?
Take a large company, formed through many iterations of mergers and reorganizations. This company produces lots of different products that are all targeted to a specific industry. Most products share similar characteristics, such as communication standards and certification and safety requirements. But there is no unified development platform or model for the company. Each product has its own distinct hardware, and software is created in any number of languages. Most new products will be updates to older versions or target the same industry. What strategies would you use to promote software reuse?</p>

答:
Don't look for the big revolution - look for small but cumulative evolutionary steps. Look for the opportunities where some positive change is relatively easy.

Don't push the idea so hard you're seen as a crank.