问:
Why use an interface when the class can directly implement the functions?

Possible Duplicate:

  Why are interfaces useful?

Like most faculty, my java faculty introduced interface without explaining or even mentioning its practical use. Now I imagine interfaces have a very specific use, but can't seem to find the answer.

My question is: a class can directly implement the functions in an interface. eg:

interface IPerson{
    void jump(int);
}

class Person{
int name;
    void jump(int height){
        //Do something here
    }
}
```

<p>What specific difference does</p>

<pre class="lang-java prettyprint-override"><code>class Person implements IPerson{
    int name;
    void jump(int height){
        //Do something here
    }
}
</code>```

?
make

答:
Having an IPerson interface allows you to have multiple implementers (Man, Woman, Employee etc...), but still treat them all through the interface in other classes.

So, in another class you simply state:

void myMethod(IPerson person, Integer howHigh)
{
   person.jump(howHigh);
}
```

You don't have to have a separate method for each implementer.

ContentLicense: CC BY-SA 4.0

Body:
Having an IPerson interface allows you to have multiple implementers (Man, Woman, Employee etc...), but still treat them all through the interface in other classes.

So, in another class you simply state:

void myMethod(IPerson person, Integer howHigh)
{
   person.jump(howHigh);
}

You don't have to have a separate method for each implementer.


答:
I think all developers can understand your confusion - trying to get your head around the use of interfaces isn't always explained well. I began to really understand the use of interfaces when I started working as a developer on real world projects.

There is a great article at BlackWasp, which explains the use of an interface with a brilliant example - have a read and try it out, it really helped me to understand it better:

http://www.blackwasp.co.uk/Interfaces.aspx

Title: Why use an interface when the class can directly implement the functions?

Body:
Possible Duplicate:

  Why are interfaces useful?

Like most faculty, my java faculty introduced interface without explaining or even mentioning its practical use. Now I imagine interfaces have a very specific use, but can't seem to find the answer.

My question is: a class can directly implement the functions in an interface. eg:

interface IPerson{
    void jump(int);
}

class Person{
int name;
    void jump(int height){
        //Do something here
    }
}
```

<p>What specific difference does</p>

<pre class="lang-java prettyprint-override"><code>class Person implements IPerson{
    int name;
    void jump(int height){
        //Do something here
    }
}
</code>```

?
make

ContentLicense: CC BY-SA 3.0


问:
Scrum, DDD, and front-end development in an enterprise environment
So, I've been working for a bank for the past 4 years. My main responsibility has been online banking. Over the past year, we've been implementing the scrum methodology. We've also changed to domain driven design.

Now, my problem is regarding what management is planning on doing. They want to split the online banking team between the domain teams, so one developer from the online banking team will go into each domain team and work on online banking projects that are part of the domains. For example, if software development gets a project to create a new loan overview in the online bank, the loan team will handle it all the way from from database to UI.

My problem with this is that there is no focus on the online bank as a product anymore. There is no way to veto any new feature. The product owners in the domains can just dump any obscure new feature into the online bank that they want to. There is also no work happening to revamp core features that our users use all the time. Every project is to make something new and once it's release, developers have to start working on a new project immediately. There is no teamwork, each web developer has to work on a separate UI for a separate domain. No hardening.

Our suggestion to management is that the online banking team be it's own scrum team focusing on the online bank as a product. That team would have it's own scrum master and the online bank would have a product owner. That product owner would coordinate with the product owners of the domains and prioritize projects that have to happen in the online banks. If a project from one domain has higher priority than a project from another domain, he would explain to the domain PO that we have to work on the higher priority one first.

Management hasn't listened to us.

My question is, what is the right way to do this?

答:
Domain-Driven Design has some interesting informations about how to recognize and deal with emerging team collaboration patterns. You might want to check out the section on Context Mapping about that.

...But the scenario you described has more to do with some organizational antipattern: DDD mandates to achieve an overall vision and to implement a sustainable way of collaborating between different teams in different contexts. At the same time Scrum would establish a coordination level between teams (with Scrum of Scrums, as said above) and also among POs. If there's no shared vision among Product Owners (be it implemented by a "super Product Owner" or by a close collaboration among the PO) ...you'll be very likely to deliver a visionless product.

Interestingly the other roles interested in applying a vision to a complex product are normally Information Architects and Interaction Designers which seem to have a hard time in the situation you described (but that's not uncommon in banking industry). Probably the best candidates to "glue" things together a little better are Enterprise Architects, which should be available in banking industry.


答:
Using an interface allows you to cast a number of different classes as a common type, regardless of how the individual classes might be implemented.

Here's a quick and dirty example:

class Puppet : IMovement { ... }
class Vehicle : IMovement { ... }
class Car : Vehicle { ... }
class Bicycle : Vehicle { ... }

class Person : IMovement { ... }
class Child : Person { ... }
class Adult : Person { ... }
```

<p>As per the example, each of the classes implements the IMovement interface, either directly or indirectly. However, the important thing to note is that any of the classes in the example could be cast as the same common interface type:</p>

<pre class="lang-java prettyprint-override"><code>((IMovement)puppet).Move()
((IMovement)car).Move()
((IMovement)child).Move()
</code>```

Interfaces allow you to easily introduce new behaviour to your classes without altering their existing interfaces. Thus an interface allows for polymorphism independent of inheritance. This is very useful when you are trying to handle a number of completely different types of object in a similar manner.

Body:
Using an interface allows you to cast a number of different classes as a common type, regardless of how the individual classes might be implemented.

Here's a quick and dirty example:

class Puppet : IMovement { ... }
class Vehicle : IMovement { ... }
class Car : Vehicle { ... }
class Bicycle : Vehicle { ... }

class Person : IMovement { ... }
class Child : Person { ... }
class Adult : Person { ... }

As per the example, each of the classes implements the IMovement interface, either directly or indirectly. However, the important thing to note is that any of the classes in the example could be cast as the same common interface type:

((IMovement)puppet).Move()
((IMovement)car).Move()
((IMovement)child).Move()

Interfaces allow you to easily introduce new behaviour to your classes without altering their existing interfaces. Thus an interface allows for polymorphism independent of inheritance. This is very useful when you are trying to handle a number of completely different types of object in a similar manner.


答:
The purpose of an interface is not to relocate or reuse code but more to ensure that some methods that operate on a wide range of types can use these types (which will be passed to them as arguments) in the exact same way even though they may not have common parent classes.

Interface is used to make the contract - the expected functionaity to exist in a certain class.

For example:

interface Transmittable {
     public byte[] toBytes();
}

class Person implements Transmittable {
     public byte[] toBytes() {
         return this.name.getBytes()
    }
}

class Animal implements Transmittable {
     public byte[] toBytes() {
            return this.typeOfAnimal.getBytes()
    }
}

class NetworkTransmitter {
     public void transmit(Transmittable object) {
          byte data[] = object.toBytes();
         //do something....
     }
}

class TestExample {
    public static void main(String args[]) {
           NetworkTransmitter trobj = new NetworkTransmitter();
           trobj.transmit(new Person());
           trobj.transmit(new Animal());
   }
}
```

Note that this is not like inheritance where object of one class inherits (or overrides) a method of the same name from the parent. The classes that implement a interface need not be descendant from the same parent class but other classes that want to ensure a contract exists, can call the same methods on objects of all classes that implement the interface. Interface ensures that this contract is available.

Body:
The purpose of an interface is not to relocate or reuse code but more to ensure that some methods that operate on a wide range of types can use these types (which will be passed to them as arguments) in the exact same way even though they may not have common parent classes.

Interface is used to make the contract - the expected functionaity to exist in a certain class.

For example:

interface Transmittable {
     public byte[] toBytes();
}

class Person implements Transmittable {
     public byte[] toBytes() {
         return this.name.getBytes()
    }
}

class Animal implements Transmittable {
     public byte[] toBytes() {
            return this.typeOfAnimal.getBytes()
    }
}

class NetworkTransmitter {
     public void transmit(Transmittable object) {
          byte data[] = object.toBytes();
         //do something....
     }
}

class TestExample {
    public static void main(String args[]) {
           NetworkTransmitter trobj = new NetworkTransmitter();
           trobj.transmit(new Person());
           trobj.transmit(new Animal());
   }
}

Note that this is not like inheritance where object of one class inherits (or overrides) a method of the same name from the parent. The classes that implement a interface need not be descendant from the same parent class but other classes that want to ensure a contract exists, can call the same methods on objects of all classes that implement the interface. Interface ensures that this contract is available.


答:
There are very interesting use cases of having an interface. Here's one:

Suppose I am creating a OS monitoring system and you tell me what to do after occurrence of a certain event. Say when the disk space is >90% full or cpu usage is very high or when some user has logged in  etc. I am still monitoring it, but it's the responsibility of the client code to provide the what happens now functionality.

In my code (that's the OS monitoring system), I will expect you to provide me an Object with certain methods implemented. Say some method like void OnDiskUsageHigh() etc. In my code I'd simply call this method of yours when disk space goes down.

This is a callback mechanism, and without the interface and the defined set of policies between you and me my code won't be able to service a general set of clients.

Here's the interface you should implement (i.e. make a concrete class):

interface Callback {
  void OnDiskUsageHigh();
  void OnCpuUsageHigh();
  ...
}
```

<p>And you initialize my <code>OSMonitoring</code> class with an object whose class implements <code>Callback</code> as in</p>

<pre class="lang-java prettyprint-override"><code>new OSMonitoringTool(new ConcreteCallbackClass());
</code>```

You should read some more about policy/contract based programming.

Body:
There are very interesting use cases of having an interface. Here's one:

Suppose I am creating a OS monitoring system and you tell me what to do after occurrence of a certain event. Say when the disk space is >90% full or cpu usage is very high or when some user has logged in  etc. I am still monitoring it, but it's the responsibility of the client code to provide the what happens now functionality.

In my code (that's the OS monitoring system), I will expect you to provide me an Object with certain methods implemented. Say some method like void OnDiskUsageHigh() etc. In my code I'd simply call this method of yours when disk space goes down.

This is a callback mechanism, and without the interface and the defined set of policies between you and me my code won't be able to service a general set of clients.

Here's the interface you should implement (i.e. make a concrete class):

interface Callback {
  void OnDiskUsageHigh();
  void OnCpuUsageHigh();
  ...
}

And you initialize my OSMonitoring class with an object whose class implements Callback as in

new OSMonitoringTool(new ConcreteCallbackClass());

You should read some more about policy/contract based programming.


问:
How to synchronize web page refresh with file upload from windows application?
I have a rather simple app in  .net which uploads images in fixed intervals in an ftp server.

The file name is specific.

I need to have a web page that refreshes but i want this to happen only when the upload finishes.

How i find a way to determine that the upload has finished? And if the solution has to do with renaming and deleting temp files, should i do this from the windows app or server side?

Thanks

update: What if i could find a way to check if a filename is a valid jpg? I mean if the transfer is not over this check should return false..ideas?

答:
JPEG files use a marker 0xFF 0xD9 to indicate end of image. If that marker is not present in the file, either the upload failed or did not yet finish. Scanning the file for this marker should be sufficient to check for incomplete upload.

This won't however detect any corruption within the image data itself. A way to ensure the integrity of the data would be to generate a CRC checksum before the upload in the desktop app, pass the checksum to the ftp (in the image filename or a separate file) and then compare the checksum of the uploaded file in the server-side code.

This assumes the web app would attempt to autonomously update in fixed intervals. Alternatively you could use a webservice or a dummy page to trigger the update from the desktop app.


问:
How not to degenerate into only a programmer who stitches together APIs?
This one I heard when I was recently interviewing a person and asked him why he was looking for a change within an year of joining his previous company. Particularly a company which is known to be in the business of processing high volume transactions, 100s of 1000s of orders flowing through the system every minute etc., etc. (you know what sells, so lets cut it)

What the candidate told me was interesting -- he had joined originally hoping to be able to get into the lower layers of the system, understanding the secret sauce that binds a high volume reliable system etc. What he ended up doing was using a lot of tools - open source and commercial, and was in the business of just glueing it all together, which never gave him any understanding of the real deal. There were tight work deadlines too, so he couldn't really get into the hang of at least the open source stuff either.

I had to agree here. But tell me then, how would you prevent yourself from degenerating into an API stitching kind of a programmer in this specific situation? Are there any signs in the job interview process itself that signal you of this degeneration?

答:
In many organizations this boils down to their appetite for the build side of build vs buy and how effectively they integrate the things they choose to buy.

A few organizations are heavily on the build side, but most have a fair bit of buy involved.  The difference in the latter is how thoroughly and completely they integrate what they choose to buy.

The warning signs for an organization that ends up turning their devs into system integration ops are varied, but a shop with a lot of vendor consulting, no Sr devs that are low-level guys, a large process for architecture decisions, lots of non-technical management within IT or a heavy reliance on paid research like Gartner can all be warning signs that an organization is likely to follow this path.

If you are in an organization that follows these patterns there is little you can do other than try to keep current in your chosen technology outside of work, but discussing soe of these issues with some of the devs during the interview can give you a rough feel if you are walking into a place you feel may be a career dead end.


问:
Is it recommended to use SQL Server as database for massively scalable applications?
Let's say you are planning to create a website of the scale of Facebook (If I am going to cite a website's name then why not Facebook?!). Is it recommended to use SQL Server as your database for such applications?

I am asking this question because many colleagues of mine say that SQL server should not be used such applications. They prefer Oracle or MySQL instead.

答:
You shouldn't be using traditional database engines if you need genuine massively scalable capabilities.

Traditional SQL databases do scale pretty well (you'll find plenty of examples of big sites using MySQL, SQL Server or Orcale) but at a certain point you will hit the scalability limit. Exactly when this happens will depend on the level of demand, the complexity of your application requirements, how much you are willing to spend on expensive servers and how well you are able to optimise the database usage. Many sites will never hit this limit, but if you do then it's pretty painful and you will be faced with a big engineering challenge to fix the problem.

Beyond this point, you really need a fully distributed NoSQL database - e.g. something like Cassandra, which was in fact developed at Facebook to solve some of their big data challenges. NoSQL databases explicitly sacrifice some of the traditional SQL database capabilities (usually around transactions, locking and eventual consistency) in order to allow effectively unlimited horizontal scalability.

Overall my advice would be to figure out if you really need massive scalability, and choose your technology path accordingly.

ContentLicense: CC BY-SA 2.5


答:
Even though I have edited this answer to take into account the OPs edits. I still find myself puzzled at the choice of the word degeneration. Bringing together the various aspects of different (and sometimes incompatible) APIs forms a large part of what software developers do. If on the other hand your question is to ask how to avoid getting yourself shoe-horned into a role that you feel is limiting your options to find other work, then perhaps either the parameters you have defined are too narrow, or the view of your role is itself also too narrow. I myself have worked on projects where I was responsible for specific specialist tasks without ever needing to work beyond those "limits", and I have never felt that these jobs were limiting in any way, as I could use them as examples in order to up-sell my skills to the next employer, with appropriate anecdotes about the lessons learned, and the skills earned.

Having myself interviewed many people over the years, I don't see signs that people degenerate into certain aspects of a role.  I do see that people sometimes specialize, and that sometimes the specialization is presented as a limitation. This to me is a warning sign that the candidate is not very open minded, and likely doesn't really understand the development process as a whole, or hasn't the capacity to push beyond the roles that the candidate feels safe and comfortable in.

I would find any employer who saw the sort of work that I have done as a degeneration would themselves be likely to have a very narrow view of the capabilities of a good software developer.  Software development is more than just being able to code for new GUIs or APIs, and a good software developer knows that there really aren't many opportunities to work on new projects, and that it is rare that you can walk into a new job and get to work on the exciting stuff, because you are generally being hired because there are a bunch of tasks that the established staff don't have the time to complete. Regardless, you will often find that "stiching APIs" together requires the implementation of new API layers to provide greater flexibility and compatibility between the existing layers being brought together. The real questions that should be asked of developers, is do they know how to manage and prioritize their tasks, or how to choose an appropriate methodology for testing and implementation, and whether they understand which tools/technologies to apply in order to achieve outcomes which deliver value to the customer. Essentially asking them if they know HOW to write software, and also how to handle tasks that may not necessarily be as glamorous as they might have hoped.

So to answer what I believe your question really should be about, I don't see that there is anything to fear from finding yourself being directed into a particular aspect of software development, but that if you feel it isn't the appropriate career path for you, you have the option of either discussing options with your boss, or leaving for a different role. If you do leave, then you need to avoid glossing over the work you didn't like, and find a way to draw useful experiences from the work you did.

Title: How not to degenerate into only a programmer who stitches together APIs?

Body:
This one I heard when I was recently interviewing a person and asked him why he was looking for a change within an year of joining his previous company. Particularly a company which is known to be in the business of processing high volume transactions, 100s of 1000s of orders flowing through the system every minute etc., etc. (you know what sells, so lets cut it)

What the candidate told me was interesting -- he had joined originally hoping to be able to get into the lower layers of the system, understanding the secret sauce that binds a high volume reliable system etc. What he ended up doing was using a lot of tools - open source and commercial, and was in the business of just glueing it all together, which never gave him any understanding of the real deal. There were tight work deadlines too, so he couldn't really get into the hang of at least the open source stuff either.

I had to agree here. But tell me then, how would you prevent yourself from degenerating into an API stitching kind of a programmer in this specific situation? Are there any signs in the job interview process itself that signal you of this degeneration?


答:
Degenerate is a loaded term that implies that using API's somehow make you less of a programmer. The truth is, in software you can't escape using some form of interfaces to access the other layers of the system. Interfaces are everywhere, from the instruction set of whatever processor you're working on to the collection of high-level scripts provided by some tool. Good programmers can be effective at any level -- there's nothing inherently wrong with working at any given level.

It's hard to know exactly what your interviewee's situation was. Perhaps he or she was promised one thing and then got stuck doing another with little chance for advancement or change. The politics of advancement vary from one workplace to another, but generally a good strategy for getting to do what you want is to do a great job at whatever you're currently doing.

Your "why are you leaving?" question in the interview wasn't unreasonable, especially in light of the interviewee's short track record, but it seems like one where the answer doesn't tell you much. You don't have any way to know what the real situation was. A more interesting question might be "what have you done in the short time that you've been at your current job?"


答:
I think your confusion comes down to badly named classes and interfaces in the the example.

Personally I think it would be less confusing if you named the interface better as IJumper.  This is the interface that allows things to Jump (as a distinct group which may be larger than the Person group).

If you wanted to stay with the same analogy. I would rename Person to EarthPerson. Then you can have alternative classes that implement the IPerson interface such as MarsPerson, JupitorPerson etc..

All of these different people will be able to Jump but how they jump will depend on how they evolved. Yet your code will work for people from other planets without any modification as you provided a generic interface that works with IPerson rather than a person from an explicit planet.

This also makes it easier to test your code.

If for example the Person object is very expensive to create (it looks up all the details of a person in the Earth Wide DB). When testing you don't want to use a real Person object as the data (take a while to create) and may change over time and break your test. But you can create a TestPerson (which implements the IPerson interface) object (a mock of a Person) and pass that to any interfaces that accept a person and make sure they do the correct thing.


问:
iphone app- is it possible to invoke a local app after user visits a website or a web app
I have a scenario where a local app is used to take snaps using the iphone camera and the local app can send the photo to a web server...

Now when the user visits a website or another web app using his iphone, then the website/webapp invokes the local app to do its work.

Do security/other restrictions on iphone prevent such a scenario from being implemented? Can I create a local app with the above scenario in mind? Is there something I should be aware of, before I start creating such an app? And should the user visit a web app or a website, so that the local app is correctly invoked to do its job?

答:
You can not automate it (that would be a security problem).

But you can provide a link on the website with a specific format myapp://<resource>. When the user clicks the link the browser will then start your application and pass it <resource>.

To make this work as part of you iApp you need to register your application as being interested in URI with a schema of myapp://. (No you can not use http:// or https as these are already taken by the browser etc).

see: http://iphonedevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html


问:
Adapter Pattern to expose different aspects of an object -- Is this a correct use?
Quite frequently, I use an Adapter-like design to expose different aspects of data objects.

For example, in a 3D modelling application I use an object hierarchy to represent the 3d models in the scene. This hierarchy contains lots of internal information and is quite complex to traverse.

For exporting the 3D model data to different file formats (which involves quite significant transformation and omitting or converting some objects), I have a separate class called ModelAdapter. It extracts the important information of a 3D model and provides them in a different format, usable for export. The export plugins, in turn, read the data from the ModelAdapters and have nothing to do with the internal scene data structure.

For Example:
```<code>class 3DModelAdapter
{
private 3DModel internal_model;
public List GetTriangles()
{
 internal_model.Do_Some_Complex_Thing_To_Retrieve_The_Triangles();
}
...
}
```

Is this a valid use of the Adapter pattern?
Is there a better way to accomplish the same thing?

答: Yes. This is exactly when you want to use the adapter pattern.</p>


问:
How to get a list of valid addresses?
I need to get a list of valid addresses in 4 or 5 clusters (cities) in both the UK and US. It's to generate sample data for an application that will do geolocation and searching. At the moment I'm generating the addresses more or less randomly, which means I hit postcodes that don't exist and obviously the street and number never match the postcode.

Any recommendations on how to programatically obtain a list of addresses to build test data?

答:
Random valid addresses are easy. Go to the website for a big organization, like the post office, McDonald's, Federal Express, and scrape store locations from their webpage.

You could also use local government sites for schools, recreation centers, red light cameras...

Title: How to get a list of valid addresses?


问:
Webkit as GUI in .Net/Mono
I want to make a cross platform application, which will also have a website where the desktop applications (Windows, iOS, Linux) will talk to the server and keep the users data in sync.

So far the options I see are:

Write a native GUI for each of the 3 OS, so I would have 3 GUI codebases (and a single backend system)

Use something like GTK so I can use one system with support in all the mention platforms.

But the third which I have not been able to find much info on (maybe I'm not searching for the right terms as I'm still new to C# and .Net), is to have a window with an embedded WebKit instance built in, which would allow me to use the same GUI system that I would use for the website. Which would make the client app and the website look as close as possible to each other so the users are familiar with the interface.

Is this last option with WebKit plausible? I already know JavaScript/HTML well and if I can use that knowledge to make the interface, that would be great. Also would be a great way to allow users to customize the interface with plugins and they could keep in sync any UI preferences from local to web.

答:
I've been working on an application framework for projects such as yours. It's based on the chromium content framework. It allows the GUI of an application to be implemented with html/css/js/svg, etc and the application logic to be implemented in javascript or c#.

My goal is to be able to develop rich, full featured 'thick' desktop applications using web technologies, that are cross platform and do not require anything server side.

Title: Webkit as GUI in .Net/Mono


答:
What you accomplish is exactly correct.

However...

Adapter is primarily when you have an existing expected interface that you need to which you need to adapt: "Convert the interface of a class into another interface clients expect. Adpater lets the classes work together that couldn't otherwise because of incompatible interfaces"

Facade is primarily when you have want to abstract the complications of a subsystem to make it easier to consume: "Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use"

If your intent is to be able to use a 3d modeling subsystem but its actual interface differs from the interface that you expect (perhaps because you are able to swap out 3d modeling subsystems at run-time) then I would call it an adapter.

If your intent is really that you want to make the actual 3d modeling subsystem easier to use, I would call it a facade.

Just semantics (and one of the benefits of patterns is the power that a single word carries in its ability to communicate intent), what you did is a good way to accomplish your goal.

Title: Adapter Pattern to expose different aspects of an object -- Is this a correct use?

Body:
Quite frequently, I use an Adapter-like design to expose different aspects of data objects.

For example, in a 3D modelling application I use an object hierarchy to represent the 3d models in the scene. This hierarchy contains lots of internal information and is quite complex to traverse.

For exporting the 3D model data to different file formats (which involves quite significant transformation and omitting or converting some objects), I have a separate class called ModelAdapter. It extracts the important information of a 3D model and provides them in a different format, usable for export. The export plugins, in turn, read the data from the ModelAdapters and have nothing to do with the internal scene data structure.

For Example:
```<code>class 3DModelAdapter
{
private 3DModel internal_model;
public List GetTriangles()
{
 internal_model.Do_Some_Complex_Thing_To_Retrieve_The_Triangles();
}
...
}
```

Is this a valid use of the Adapter pattern?
Is there a better way to accomplish the same thing?


答:
I tend to view using APIs and Frameworks as the Engineering side of building software, as opposed to the computer science side. I take the analogy of the difference between pure theoretical or research science and applying that science into an engineering discipline (different physics into Mechanical, Civil or Electrical Engineering, or Chemistry into Chemical engineering).

Given that analogy, you have a choice: stagnate in your career, just doing what is enough to get by, or get a better understanding of how the science really applies to your discipline, get an appreciation for it, and it will assuredly improve your skill-set regardless if you lean more toward the engineering or pure-science aspect.

Check out this matrix on competencies. If you lean toward the 2^n or n^2 side, you certainly can get good at being a middle of the road developer, and can build software. If you start to head toward the log(n) side, you'll start to see more quickly how good some frameworks are, or even better, start writing your own that makes up for those that fall short.


答:
I'm currently in the process of reading Agile Software Requirements: Lean Requirements Practices for Teams, Programs, and the Enterprise. I've read several other books on agile/scrum before this one, but one thing I find unique about this book is that author takes the agile process and extends far beyond a single team (100+ within organization)

This books points out that when there are many teams working on the same product, someone has to make a decision on how those teams are structured. The two approaches are:

Feature Teams - Team consists of members from different layers of the product (DB, Web, Business logic, etc.). And the whole team is working on a single feature.

Component Teams - Team consists of members who all work on a single layer. This team is especially preferred where same component is shared by many different features. To ensure that the code stays consistent you wouldn't want 20 different people modifying the same code base over and over.

The author points out that whenever possible, organizations should be leaning toward feature teams because when you have one team working on a full feature, everyone is aligned to delivering end-user value.  If you only have component teams, you run the risk of each team performing local optimization, potentially at the expense of the feature itself.  Furthermore since component teams only see part of a feature, now you need to have system-level integration/QA teams to assemble the components.

It seems that your management is taking the approach of making everyone part of a feature team. However, as the book is pointing out this decision should never be black and white. In the end, most organizations should have some combination between feature and component teams and structure them in such a way that benefits from having both are maximized. This needs to be a balance and there are many factors that would shift the balance toward one side or another (for example, absence of comprehensive unit tests would shift it towards component teams).

Having said all that, I think your management is going down the same path as many other companies which tried to go Agile only to fail miserably.  I'm saying this based on this:

```<code>Management hasn't listened to us.
</code>```

Traditional methodology has quite some overhead and when traditional companies move to Agile they introduce more overhead of the agile process without giving up the traditional way of doing things. The cornerstone of agile and what actually makes it tick is that you have engaged, self-thinking team members. And in the end the only way that is going to work is if THE TEAM decides that feature or component team would be a better fit and the management simply acts on THE TEAMS recommendation. Otherwise, why would you strive to deliver anything or work any harder than bare minimum when in your eyes the management already set you up for a failure by mandating a decision that you believe is wrong.

Title: Scrum, DDD, and front-end development in an enterprise environment

Body:
So, I've been working for a bank for the past 4 years. My main responsibility has been online banking. Over the past year, we've been implementing the scrum methodology. We've also changed to domain driven design.

Now, my problem is regarding what management is planning on doing. They want to split the online banking team between the domain teams, so one developer from the online banking team will go into each domain team and work on online banking projects that are part of the domains. For example, if software development gets a project to create a new loan overview in the online bank, the loan team will handle it all the way from from database to UI.

My problem with this is that there is no focus on the online bank as a product anymore. There is no way to veto any new feature. The product owners in the domains can just dump any obscure new feature into the online bank that they want to. There is also no work happening to revamp core features that our users use all the time. Every project is to make something new and once it's release, developers have to start working on a new project immediately. There is no teamwork, each web developer has to work on a separate UI for a separate domain. No hardening.

Our suggestion to management is that the online banking team be it's own scrum team focusing on the online bank as a product. That team would have it's own scrum master and the online bank would have a product owner. That product owner would coordinate with the product owners of the domains and prioritize projects that have to happen in the online banks. If a project from one domain has higher priority than a project from another domain, he would explain to the domain PO that we have to work on the higher priority one first.

Management hasn't listened to us.

My question is, what is the right way to do this?

Body:
I'm currently in the process of reading Agile Software Requirements: Lean Requirements Practices for Teams, Programs, and the Enterprise. I've read several other books on agile/scrum before this one, but one thing I find unique about this book is that author takes the agile process and extends far beyond a single team (100+ within organization)

This books points out that when there are many teams working on the same product, someone has to make a decision on how those teams are structured. The two approaches are:

Feature Teams - Team consists of members from different layers of the product (DB, Web, Business logic, etc.). And the whole team is working on a single feature.

Component Teams - Team consists of members who all work on a single layer. This team is especially preferred where same component is shared by many different features. To ensure that the code stays consistent you wouldn't want 20 different people modifying the same code base over and over.

The author points out that whenever possible, organizations should be leaning toward feature teams because when you have one team working on a full feature, everyone is aligned to delivering end-user value.  If you only have component teams, you run the risk of each team performing local optimization, potentially at the expense of the feature itself.  Furthermore since component teams only see part of a feature, now you need to have system-level integration/QA teams to assemble the components.

It seems that your management is taking the approach of making everyone part of a feature team. However, as the book is pointing out this decision should never be black and white. In the end, most organizations should have some combination between feature and component teams and structure them in such a way that benefits from having both are maximized. This needs to be a balance and there are many factors that would shift the balance toward one side or another (for example, absence of comprehensive unit tests would shift it towards component teams).

Having said all that, I think your management is going down the same path as many other companies which tried to go Agile only to fail miserably.  I'm saying this based on this:

Management hasn't listened to us.

Traditional methodology has quite some overhead and when traditional companies move to Agile they introduce more overhead of the agile process without giving up the traditional way of doing things. The cornerstone of agile and what actually makes it tick is that you have engaged, self-thinking team members. And in the end the only way that is going to work is if THE TEAM decides that feature or component team would be a better fit and the management simply acts on THE TEAMS recommendation. Otherwise, why would you strive to deliver anything or work any harder than bare minimum when in your eyes the management already set you up for a failure by mandating a decision that you believe is wrong.


问:
Modern programming language with intuitive concurrent programming abstractions
I am interested in learning concurrent programming, focusing on the application/user level (not system programming). I am looking for a modern high level programming language that provides intuitive abstractions for writing concurrent applications. I want to focus on languages that increase productivity and hide the complexity of concurrent programming.

To give some examples, I don't consider a good option writing multithreaded code in C, C++, or Java because IMHO my productivity is reduced and their programming model is not intuitive. On the other hand, languages that increase productivity and offer more intuitive abstractions such as Python and the multiprocessing module, Erlang, Clojure, Scala, etc. would be good options.

What would you recommend based on your experience and why?

EDIT: Thanks everybody for your interesting answers. It's hard to make a conclusion without actually trying since there are many good candidates: Erlang, Clojure, Scala, Groovy, and perhaps Haskell. I voted the answer with the most convincing arguments, but I'll try all the good candidates before deciding which one to pick :)

答:
Scala has been mentioned several times in the questions and in answers, but I have seen no reference to Akka which is an actor implementation that
can be used with both Scala and Java.</p>


答:
It starts with a dog. In particular, a pug.

The pug has various behaviors:

public class Pug
{
    private String name;

    public Pug(String n)
    {
        name = n;
    }

    public String getName()
    {
        return name;
    }

    public String bark()
    {
        return "Arf!";
    }

    public boolean hasCurlyTail()
    {
        return true;
    }
}
```

<p><img src="https://i.stack.imgur.com/53yY4.jpg" alt="Labrador Retriever" title="Labrador Retriever"></p>

<p>And you have a Labrador, who also has a set of behaviors.</p>

<pre class="lang-java prettyprint-override"><code>public class Lab
{
    private String name;

    public Lab(String n)
    {
        name = n;
    }

    public String getName()
    {
        return name;
    }

    public String bark()
    {
        return "Woof!";
    }

    public boolean hasCurlyTail()
    {
        return false;
    }
}
</code>```

We can make some pugs and labs:

Pug pug = new Pug("Spot");
Lab lab = new Lab("Fido");
```

<p>And we can invoke their behaviors:</p>

<pre class="lang-java prettyprint-override"><code>pug.bark()           -> "Arf!"
lab.bark()           -> "Woof!"
pug.hasCurlyTail()   -> true
lab.hasCurlyTail()   -> false
pug.getName()        -> "Spot"
lab.getName()        -> "Fido"
</code>```

Let's say I run a dog kennel and I need to keep track of all the dogs I'm housing. I need to store my pugs and labradors in separate arrays:

public class Kennel
{
    Pug[] pugs = new Pug[10];
    Lab[] labs = new Lab[10];

    public void addPug(Pug p)
    {
        ...
    }

    public void addLab(Lab l)
    {
        ...
    }

    public void printDogs()
    {
        // Display names of all the dogs
    }
}
```

<p>But this is clearly not optimal. If I want to house some poodles, too, I have to change my <code>Kennel</code> definition to add an array of <code>Poodles</code>. In fact, I need a separate array for each kind of dog.</p>

<p><strong>Insight:</strong> both pugs and labradors (and poodles) are types of dogs and they have the same set of behaviors. That is, we can say (for the purposes of this example) that all dogs can bark, have a name, and may or may not have a curly tail. We can use an interface to define what all dogs can <em>do</em>, but leave it up to the specific types of dogs to implement those particular behaviors. The interface says "here are the things that all dogs can do" but doesn't say <em>how</em> each behavior is done.</p>

<pre class="lang-java prettyprint-override"><code>public interface Dog
{
    public String bark();
    public String getName();
    public boolean hasCurlyTail();
}
</code>```

Then I slightly alter the Pug and Lab classes to implement the Dog behaviors. We can say that a Pug is a Dog and a Lab is a Dog.

public class Pug implements Dog
{
    // the rest is the same as before
}

public class Lab implements Dog
{
    // the rest is the same as before
}
```

<p>I can still instantiate <code>Pug</code>s and <code>Lab</code>s as I previously did, but now I also get a new way to do it:</p>

<pre class="lang-java prettyprint-override"><code>Dog d1 = new Pug("Spot");
Dog d2 = new Lab("Fido");
</code>```

This says that d1 is not only a Dog, it's specifically a Pug. And d2 is also a Dog, specifically a Lab.

We can invoke the behaviors and they work as before:

d1.bark()           -> "Arf!"
d2.bark()           -> "Woof!"
d1.hasCurlyTail()   -> true
d2.hasCurlyTail()   -> false
d1.getName()        -> "Spot"
d2.getName()        -> "Fido"
```

<p>Here's where all the extra work pays off. The <code>Kennel</code> class becomes much simpler. I need only one array and one <code>addDog</code> method. Both will work with any object that <em>is</em> a dog; that is, objects that implement the <code>Dog</code> interface.</p>

<pre class="lang-java prettyprint-override"><code>public class Kennel
{
    Dog[] dogs = new Dog[20];

    public void addDog(Dog d)
    {
        ...
    }

    public void printDogs()
    {
        // Display names of all the dogs
    }
 }
</code>```

Here's how to use it:

 Kennel k = new Kennel();
 Dog d1 = new Pug("Spot");
 Dog d2 = new Lab("Fido");
 k.addDog(d1);
 k.addDog(d2);
 k.printDogs();
```

<p>The last statement would display:</p>

<pre class="lang-java prettyprint-override"><code> Spot
 Fido
</code>```

An interface give you the ability to specify a set of behaviors that all classes that implement the interface will share in common. Consequently, we can define variables and collections (such as arrays) that don't have to know in advance what kind of specific object they will hold, only that they'll hold objects that implement the interface.

Body:
It starts with a dog. In particular, a pug.

The pug has various behaviors:

public class Pug
{
    private String name;

    public Pug(String n)
    {
        name = n;
    }

    public String getName()
    {
        return name;
    }

    public String bark()
    {
        return "Arf!";
    }

    public boolean hasCurlyTail()
    {
        return true;
    }
}

And you have a Labrador, who also has a set of behaviors.

public class Lab
{
    private String name;

    public Lab(String n)
    {
        name = n;
    }

    public String getName()
    {
        return name;
    }

    public String bark()
    {
        return "Woof!";
    }

    public boolean hasCurlyTail()
    {
        return false;
    }
}

We can make some pugs and labs:

Pug pug = new Pug("Spot");
Lab lab = new Lab("Fido");

And we can invoke their behaviors:

pug.bark()           -> "Arf!"
lab.bark()           -> "Woof!"
pug.hasCurlyTail()   -> true
lab.hasCurlyTail()   -> false
pug.getName()        -> "Spot"
lab.getName()        -> "Fido"

Let's say I run a dog kennel and I need to keep track of all the dogs I'm housing. I need to store my pugs and labradors in separate arrays:

public class Kennel
{
    Pug[] pugs = new Pug[10];
    Lab[] labs = new Lab[10];

    public void addPug(Pug p)
    {
        ...
    }

    public void addLab(Lab l)
    {
        ...
    }

    public void printDogs()
    {
        // Display names of all the dogs
    }
}

But this is clearly not optimal. If I want to house some poodles, too, I have to change my Kennel definition to add an array of Poodles. In fact, I need a separate array for each kind of dog.

Insight: both pugs and labradors (and poodles) are types of dogs and they have the same set of behaviors. That is, we can say (for the purposes of this example) that all dogs can bark, have a name, and may or may not have a curly tail. We can use an interface to define what all dogs can do, but leave it up to the specific types of dogs to implement those particular behaviors. The interface says "here are the things that all dogs can do" but doesn't say how each behavior is done.

public interface Dog
{
    public String bark();
    public String getName();
    public boolean hasCurlyTail();
}

Then I slightly alter the Pug and Lab classes to implement the Dog behaviors. We can say that a Pug is a Dog and a Lab is a Dog.

public class Pug implements Dog
{
    // the rest is the same as before
}

public class Lab implements Dog
{
    // the rest is the same as before
}

I can still instantiate Pugs and Labs as I previously did, but now I also get a new way to do it:

Dog d1 = new Pug("Spot");
Dog d2 = new Lab("Fido");

This says that d1 is not only a Dog, it's specifically a Pug. And d2 is also a Dog, specifically a Lab.

We can invoke the behaviors and they work as before:

d1.bark()           -> "Arf!"
d2.bark()           -> "Woof!"
d1.hasCurlyTail()   -> true
d2.hasCurlyTail()   -> false
d1.getName()        -> "Spot"
d2.getName()        -> "Fido"

Here's where all the extra work pays off. The Kennel class becomes much simpler. I need only one array and one addDog method. Both will work with any object that is a dog; that is, objects that implement the Dog interface.

public class Kennel
{
    Dog[] dogs = new Dog[20];

    public void addDog(Dog d)
    {
        ...
    }

    public void printDogs()
    {
        // Display names of all the dogs
    }
 }

Here's how to use it:

 Kennel k = new Kennel();
 Dog d1 = new Pug("Spot");
 Dog d2 = new Lab("Fido");
 k.addDog(d1);
 k.addDog(d2);
 k.printDogs();

The last statement would display:

 Spot
 Fido

An interface give you the ability to specify a set of behaviors that all classes that implement the interface will share in common. Consequently, we can define variables and collections (such as arrays) that don't have to know in advance what kind of specific object they will hold, only that they'll hold objects that implement the interface.


问:
How to set up a one-man research in the difference between BDD and Waterfall?
Earlier, I asked a question about how to measure the quality of a project. The outcome of that question was that the quality of the project can be divided into two parts:

Internal quality (code quality, measurable by code quality metrics)

External quality (Acceptance test, how well the software meets the requirements)

So based on that, I want to set up some research and validate the outcome of the project. The problem is, I will conduct this research on my own, so it's not possible to run the project once in BDD style and the other one in waterfall by myself. It's also not possible to compare BDD and waterfall projects on a larger scale, due to the fact that there are not enough BDD projects that can be measured because of the age of BDD.

So, my question is: did anybody face this problem? How could I execute my experiment in such a way that it is of scientific value?

答:
It's impossible to generate large enough data sets in a research lab, let alone all by yourself, for validating development processes. Your options are:

Partnering with industry. For starters, you'll need to coach them on BDD at the onset of the project and they must be willing to adopt it -- a tall order! You'll also need a few years to run your experiments on several projects and possible in several companies, possibly spanning different industries! For the control Waterfall projects, you could just rely on existing data.

Using student projects. This option is practical, but it's not as reliable as the scale of projects have to be small. Hey, you gotta do what you gotta do! Perhaps if you have access to graduate students -- it might better.

If you must continue, option 2 seems to be the only practical option. However, you might want to reconsider your research topic!

Good luck!


答: In addition to the comments of others, interfaces make it easier to do testing since you've clearly defined what the critical parts of the interface should be for any mock/stub classes.  TDD should be doing interfaces all over the place.</p>


答:
There is no need to do so, unless you want to be able to have more than one class providing that behavior.

A good example is the JDBC Connection interface which represents a connection to an SQL database, where you as the programmer can send SQL commands and get the result back.  You do not care how the underlying driver talks to the database but you do care that the implementation implements the Connection interface, so you can just use any connection that the DriverManager choose to give you.


问:
Procedure or Event Driven Language For Education
I am here to ask a question that has been asked many times before.  What programming language should I learn to become a intelligent conceptual programmer?

Many people agree, you do not have to learn any one programming language; you need to learn programming as a concept itself (Most of us can become semi proficient in a language under a few weeks).

Would it be better to learn procedure or event driven languages for conceptual purposes?  Why?

Let me be even more precise with my question above on this. I have written lots of basic code and program examples.  I feels I have a firm root on basic concepts and now am ready to try some more complicated task like programming a graphic rendering engine or compiler.  From what I understand C/C++ should teach me more of the important principles that I may carry over to fields like electrical engineering.

答:
Learn the C programming language.

Why should I learn C?

C is one of the most used programming languages in the world. It is used in Universities (to learn), and workplaces (to use ;-).

C also inspired many other programming languages, which will make it easier to learn other languages in the future.

But most importantly, it will teach you all of the major concepts you should know in a regularlized syntax. That's why C is a great learning tool. If you write to equivalent programs, one in C and one in Perl, the Perl script will be shorter, but the C approach will be quicker and much more structured.

How do I learn C?

Read a book. Not just any book. Read the book. The C Programming Language, in my opinion, is the book for learning C. After you read that book, you will not be a C programmer yet. Take the following steps:

Get a book on Data Structures in C.

Get a book on Algorithms in C.

Get Code Complete.

Finally read Structure and Interpretation of Computer Programs

Hey guess what! You still not a good C programmer. Do you want to know why? You haven't coded enough. The best way to learn is by doing.

In my opinion, this is the best approach you can take to learn procedural programming. And if you can go through this, you will, in my book, be concidered a C programmer, and a programmer in general. After this, all other languages will come easy.


答:
You've misquoted somebody. It's not "you do not have to learn any one programming language", it's "you do not have to learn only one programming language." Learn ALL the languages. Every one you can get your hands on, every one you can find a book for, every one you can download a dev environment for.

C gives you a good low-level understanding of the machine. Lisp gives you the notion of "little languages," of starting from a tiny thing and building huge structures out of it. Java tells you about living in an environment you don't 100% control, SQL or Haskell free you from thinking about time, Javascript lets write code anywhere you can fire up a web browser. (I solved a dozen of the problems from Project Euler sitting a public library.)

No computer language is complicated; they average about thirty "words," and twenty of those words are the same everywhere. (Think about "if," or "while," or "+".) You can learn any of them in a week, get skilled in two or three months.

Title: Procedure or Event Driven Language For Education

Body:
I am here to ask a question that has been asked many times before.  What programming language should I learn to become a intelligent conceptual programmer?

Many people agree, you do not have to learn any one programming language; you need to learn programming as a concept itself (Most of us can become semi proficient in a language under a few weeks).

Would it be better to learn procedure or event driven languages for conceptual purposes?  Why?

Let me be even more precise with my question above on this. I have written lots of basic code and program examples.  I feels I have a firm root on basic concepts and now am ready to try some more complicated task like programming a graphic rendering engine or compiler.  From what I understand C/C++ should teach me more of the important principles that I may carry over to fields like electrical engineering.


问:
Turning in code you developed in your company as homework assignments
I'm currently running a start-up with a buddy and I noticed that some of my university assignments could be finished by simply copying some code from some of the programs we've developed. Are there any legal troubles I could run into? Or is this just a bad idea in general(as it is starting to feel right now)?

Sorry if this is in the wrong place I wasn't sure whether to place this here or in stackoverflow.

答: As long as you developed the code exclusively yourself you might be OK, like if you are the sole developer for the startup.  If you collaborated with another student or non-student that could present problems for you.  I mean, you obviously know how to do it, so it shouldn't take that long to do again either.</p>


答:
Remember, Java is finicky about type.

Let's extend your example a bit and rename the class to Jumpable.

interface Jumpable {
    void jump(int);
}

class Person extends Mammal implements Jumpable {
    //other stuff
    void jump(int howHigh) {
        //jump method
    }
}

class Dog extends Mammal implements Jumpable {
    //other stuff
    void jump(int howHigh) {
        //jump method
        //also make him bark when he jumps
    }
}

class Cat extends Mammal implements Jumpable {
    //other stuff
    void jump(int howHigh) {
        //jump method
        //make it stretch its legs as well
    }
}

class FlyingFish extends Fish implements Jumpable {
    //other stuff
    void jump(int howHigh) {
        //jump method
        //make it come out of water
    }
}

class Mantis extends Insect implements Jumpable {
    //other stuff
    void jump(int howHigh) {
        //jump method
        //make it come out of water
    }
}

class Ant extends Insect { //Cannot jump
    //other stuff
}

class Whale extends Mammal { //Cannot jump (hopefully)
    //other stuff
}
```

<p>Note that here we have a variety of classes, organised in some hierarchy. Not all of them can jump, and jump-ability is not universally applicable to any category--each parent class (<code>Animal</code>, <code>Mammal</code>, <code>Insect</code>, <code>Fish</code>).</p>

<p>Lets say we want to hold a jumping competition. <strong>Without interfaces</strong>, we would have to do something like this:</p>

<pre class="lang-java prettyprint-override"><code>void competition(
    Person[] pCompetitors,
    Dog[] dCompetitors,
    Cat[] cCompetitors,
    FlyingFish[] fCompetitors,
    Mantis[] mCompetitors
) {
    for(int i=0; i<pCompetitors.length; i++) {
        pCompetitors[i].jump((int)Math.rand() * 10);
    }
    //Do the same for ALL the other arrays.
}
</code>```

Here, since there is no "enveloping class" that holds all classes that can jump, we have to invoke them individually. Remember, we cannot just have an Animal[] or Mammal[] array, since the compiler won't allow us to invoke jump(); and not all Animals/Mammals can jump().

Also, this becomes impossible to extend. Lets say you want to add another jumping class.

class Bob extends Animal { //Bob is NOT a human. Bob is something....else....
    void jump(int howHigh) {
        //...
    }
}
```

<p>Now, you have to modify <code>competition(.........)</code> to accept a <code>Bob[]</code> parameter as well. You also have to modify all instances of <code>competition[]</code> to either create their own <code>Bob[]</code>s, or pass empty <code>Bob[]</code> parameters. And it gets icky.</p>

<hr>

<p>If you used interfaces, your competition method becomes thus:</p>

<pre class="lang-java prettyprint-override"><code>void competition(Jumpable[] j) {
    for(int i=0; i<j.length; i++) {
        j[i].jump((int)Math.rand() * 10);
    }
}
</code>```

This can be extended without any hassle as well.

Basically, interfaces let the compiler know the expected behavior of the object -- what methods/data the compiler can assume exist. That way we can write general programs.

Also you can multiple-inherit interfaces, you can't do that with extends in Java.

Some real-world examples: The first one that comes to mind is the event handlers of AWT. These allow us to pass a method as a parameter and make it an event handler. This will only work if the compiler is certain that the method exists, and thus we use interfaces.

Body:
Remember, Java is finicky about type.

Let's extend your example a bit and rename the class to Jumpable.

interface Jumpable {
    void jump(int);
}

class Person extends Mammal implements Jumpable {
    //other stuff
    void jump(int howHigh) {
        //jump method
    }
}

class Dog extends Mammal implements Jumpable {
    //other stuff
    void jump(int howHigh) {
        //jump method
        //also make him bark when he jumps
    }
}

class Cat extends Mammal implements Jumpable {
    //other stuff
    void jump(int howHigh) {
        //jump method
        //make it stretch its legs as well
    }
}

class FlyingFish extends Fish implements Jumpable {
    //other stuff
    void jump(int howHigh) {
        //jump method
        //make it come out of water
    }
}

class Mantis extends Insect implements Jumpable {
    //other stuff
    void jump(int howHigh) {
        //jump method
        //make it come out of water
    }
}

class Ant extends Insect { //Cannot jump
    //other stuff
}

class Whale extends Mammal { //Cannot jump (hopefully)
    //other stuff
}

Note that here we have a variety of classes, organised in some hierarchy. Not all of them can jump, and jump-ability is not universally applicable to any category--each parent class (Animal, Mammal, Insect, Fish).

Lets say we want to hold a jumping competition. Without interfaces, we would have to do something like this:

void competition(
    Person[] pCompetitors,
    Dog[] dCompetitors,
    Cat[] cCompetitors,
    FlyingFish[] fCompetitors,
    Mantis[] mCompetitors
) {
    for(int i=0; i<pCompetitors.length; i++) {
        pCompetitors[i].jump((int)Math.rand() * 10);
    }
    //Do the same for ALL the other arrays.
}

Here, since there is no "enveloping class" that holds all classes that can jump, we have to invoke them individually. Remember, we cannot just have an Animal[] or Mammal[] array, since the compiler won't allow us to invoke jump(); and not all Animals/Mammals can jump().

Also, this becomes impossible to extend. Lets say you want to add another jumping class.

class Bob extends Animal { //Bob is NOT a human. Bob is something....else....
    void jump(int howHigh) {
        //...
    }
}

Now, you have to modify competition(.........) to accept a Bob[] parameter as well. You also have to modify all instances of competition[] to either create their own Bob[]s, or pass empty Bob[] parameters. And it gets icky.

If you used interfaces, your competition method becomes thus:

void competition(Jumpable[] j) {
    for(int i=0; i<j.length; i++) {
        j[i].jump((int)Math.rand() * 10);
    }
}

This can be extended without any hassle as well.

Basically, interfaces let the compiler know the expected behavior of the object -- what methods/data the compiler can assume exist. That way we can write general programs.

Also you can multiple-inherit interfaces, you can't do that with extends in Java.

Some real-world examples: The first one that comes to mind is the event handlers of AWT. These allow us to pass a method as a parameter and make it an event handler. This will only work if the compiler is certain that the method exists, and thus we use interfaces.


答:
I can't see how there would be any legal issues where you would be in trouble; it's your code. Although you might want to make sure that the university doesn't claim that your homework belongs to them (I would be amazed if anywhere credible did this).

Your university/professor might have a problem with it, though. Most places don't let you submit something you did in the past or for another class (under the absurd banner of "self-plagarism"). Ask your professor if it's ok, it might depend what you're copying (some library code you wrote might be ok while copying the entire assignment wholesale might not).

tl;dr: Ask your professor if it's ok.

Title: Turning in code you developed in your company as homework assignments

Body:
I'm currently running a start-up with a buddy and I noticed that some of my university assignments could be finished by simply copying some code from some of the programs we've developed. Are there any legal troubles I could run into? Or is this just a bad idea in general(as it is starting to feel right now)?

Sorry if this is in the wrong place I wasn't sure whether to place this here or in stackoverflow.


答:
The point of any homework exercise is two-fold. First, learn any new techniques or methods related to the coursework. Second, practice those techniques!

If you have previously solved the same problem before, you've already completed the first point. Great! Now for the second point: it still matters. See this as an opportunity to master the material even further.

Now, I wouldn't say you can't refer to your own code that you have the rights to as a reference. Only use it as such though. Map out a new approach without referring to your old code. Code the challenging aspects again. Then, only after you've solved the essential aspects of the assignment, refer to whatever resources you have at your disposal. Go ahead and make adjustments, but at that point it's probably unnecessary to copy and paste anything, you'll only need to tweak your new code. You might improve on your original material!

Now, there is a rule in programming: Don't reinvent the wheel. I would say that takes a backseat when education is involved. You are reinventing all the time, that's the point of learning. If it is a lot of work and you really want to re-use some code, make sure it's OK with your professor, and explain what would be re-used.


答:
Yes, it's legal, but universities play by their own set of rules, so I wouldn't push it.  One of those rules is making you do assignments it seems you don't need.  Were I in your position (and I was once or twice back in the day), I would tell your professor the assignment is trivial due to your past work, and if it's not okay to reuse that code, could he give you a more interesting assignment instead?  Have a suggestion ready in case he asks for one.  You can score some interesting projects that way.

Yes, it's more work, but you might accidentally learn something while checking off the bullet points of a degree.


问:
REST Service Authentication/Authorization
I have a WCF rest service that will be consumed by multiple clients.  The information returned by the client requires me to know who they are, so that I can return information specific to them.

Is the best way to approach this type of design to authenticate them and return a token for their session, then pass this token along with every request?

Thanks.

答:
I lean towards HTTPS and Basic Auth because web client support is ubiquitous.  I also prefer not implementing a session if I don't have to.  It's unnecessary complexity and it's not really RESTful. REST requests should be standalone, so you send your credentials and whatever other information is required to create your request.  However, there may be reasons/requirements that necessitate compromising on OAuth rather than HTTPS and Basic Auth.

Resources should have the appropriate acls set to control who can and cannot access them.  A request is received from an authenticated user it is only successfully fulfilled if the user has access to the resource.


答:
Ask you professor then if he agrees, ask your company lawyer. If both agree it's OK.  Decide if you are prepared to lose ownership rights to that code, and maybe more. Get your lawyer to tell you how much of the company the university will end up owning (or having claims to), and decide if you are prepared for it. If you make the next Facebook - will you lose it all?

Or, just do the assignment.

Or call me paranoid and just ask the professor.


问:
How a freelancer can learn industry standards?
Being a freelancer, I don't have access to corporate training programs where employees learn best practices. Most of the time I am advised to look into the available code on the Internet. Ideal places would be: CodePlex and SourceForge.

But this proves to be of limited rather very little help. I want my existing code to be analyzed and a better solution be suggested to improve the quality of the code.

How to learn coding that matches standards?

答:
If you are doing development in .NET you can get inexpensive or free static analysis of your code with a tool like FxCop (http://www.microsoft.com/downloads/en/details.aspx?FamilyID=917023f6-d5b7-41bb-bbc0-411a7d66cf3c&displaylang=en). This does not cover best practices for the PROCESS of creating software but it does cover a lot of things that tend to wind up in best practices documents.

You did say "I want my existing code to be analyzed and a better solution be suggested to improve the quality of the code." so I think that FxCop would be a good place to start IF you are doing .NET development. I would imagine that there are similar static analysis tools for Java or other environments.

Good luck!


问:
Will adopting a DVCS mean there will be a positive impact on development speed?
I was wondering how safe is to say that —because developers are free to version and have better and more organic workflows— code will be delivered faster.

A big factor here is team size of course, and I'd say the team is big enough to see this benefit (10-15 core devs, and maybe 5 to 15 more contributors to the common codebase).

Edit: How development speed can be affected:

Merging hell could be one of the cases that slow down people (DVCSs are much better at merging).

Better workflows that can pretty much only work work more naturally on a DVCS

Integration Manager

Dictator & Lieutenants

Ability to use version control (i.e. committing) without inflicting potentially unstable changes to everybody

I just want to know if anyone has seen such things help the overall speed of teams/projects as a whole.

答:
If your CVCS is slowing you down (would be he corollary from your question) then your workflow is broken not your VCS.

Edit:  (text to long for comment)

I think you are missing the point. If your procedures regarding VCS's can slow you down only if they make up a significant amount of your development time. This would be true if either the VCS or your process requires a huge amount of ceremony. I have never used perforce so I don't know how "bad" its ceremony is. I have used MKS and found its ceremony really bad, but it would still only account for a couple of minutes per day. With git my ceremony is maybe a couple of seconds a day. So my gain is less pain, but not much more speed, because if my day is 8h long it does not really matter if I save 10 minutes.

BUT: The pain is much (very much) smaller than with MKS and git makes things possible I could not do before. That is the real gain of DVCS.


答:
Yes. In day to day coding, there is not much of a difference time-wise whether you use one or other source control. </p>

<p>As for the learning curve of a new methodology in a group: the larger the group the steeper the curve. </p>

Title: Will adopting a DVCS mean there will be a positive impact on development speed?

Body:
I was wondering how safe is to say that —because developers are free to version and have better and more organic workflows— code will be delivered faster.

A big factor here is team size of course, and I'd say the team is big enough to see this benefit (10-15 core devs, and maybe 5 to 15 more contributors to the common codebase).

Edit: How development speed can be affected:

Merging hell could be one of the cases that slow down people (DVCSs are much better at merging).

Better workflows that can pretty much only work work more naturally on a DVCS

Integration Manager

Dictator & Lieutenants

Ability to use version control (i.e. committing) without inflicting potentially unstable changes to everybody

I just want to know if anyone has seen such things help the overall speed of teams/projects as a whole.

Body:
Yes. In day to day coding, there is not much of a difference time-wise whether you use one or other source control.

As for the learning curve of a new methodology in a group: the larger the group the steeper the curve.


问:
My colleague doesn't understand things he works with. What to do?
I've spent 3 days debugging one very obscure bug in a library made by my colleague, this bug happens very infrequently. After all I found that this bug happens due to cross-thread access to an object without any lock. Actually this is not a first bug of this kind, there were similar bugs before. He just runs his unit tests, and if something fails puts somewhere a lock. And if nothing fails, ughm, then his code is perfect. It seems he has no idea about threading safety. I'm 100% sure there are many similar bugs that just haven't surfaced yet. It seems PM doesn't understand threading stuff too.

The problem is, he works much more time in the company than I do. Anyway, I can't just say "this guy is incompetent in this area", because this always shows you as a "bad team player", etc.

Any ideas, what I can do?

答: Write a unit test that shows the bug and ask him to fix it.</p>


答: Convince PM that to avoid such bugs, the know-how of the team about threading stuff should be improved, and tell them that you are willing to organize something like a workshop or a presentation about it. Don't make it a personal thing between you and your colleague.</p>

Title: My colleague doesn't understand things he works with. What to do?

Body:
I've spent 3 days debugging one very obscure bug in a library made by my colleague, this bug happens very infrequently. After all I found that this bug happens due to cross-thread access to an object without any lock. Actually this is not a first bug of this kind, there were similar bugs before. He just runs his unit tests, and if something fails puts somewhere a lock. And if nothing fails, ughm, then his code is perfect. It seems he has no idea about threading safety. I'm 100% sure there are many similar bugs that just haven't surfaced yet. It seems PM doesn't understand threading stuff too.

The problem is, he works much more time in the company than I do. Anyway, I can't just say "this guy is incompetent in this area", because this always shows you as a "bad team player", etc.

Any ideas, what I can do?


答: This really depends on your development processes, build process, release management, and branch management.  You need to pick the best VCS to support these without worrying about if it's centralized or distributed.  The VCS should support your processes and you should not have to mold your processes to the VCS (within reason).</p>


问:
Don't structure data all the way down
In the blog post Don't structure data all the way down, the author discusses different ways to structure a circle datatype and how to implement the parameters to a Radius function.

```<code>area({circle, {point,0,0}, 17.4})
</code>```

Kind of messy. What about a function to build a circle for us? Then we could do this:

```<code>area(make_circle(0, 0, 17.4))
</code>```

We could also have a shorter version of make_circle that only takes a radius, defaulting the center point to 0,0. Okay, stop, we're engineering ourselves to death. All we need is a simple function to compute the area of a circle:

```<code>area(R) -> math:pi() * R * R.
</code>```

He is talking about the functions in the Erlang language, which is functional and not object oriented (OO).  My question is, does this argument hold for OO languages, and does it hold for functional languages?

答: The point is "You ain't gonna need it" (aka YAGNI) and therefore you should not implement it. This has nothing to do with the programming paradigm (OO or functional).</p>

Title: Don't structure data all the way down


答:
I think the answer depends entirely on context.   It nearly always makes sense to build abstractions for anything which potentially recurrs all over the place in an application, even if that abstraction is only lightweight it's more likely to provide cleaner code further up

For example, your logic layer might need to build a more complicated algorithm which determines whether two circles are touching or intersecting, and determine the points at which they touch; this kind of code would benefit IMO with the ability to condense two sets of X,Y,Radius into a single structure.  - The user of the algorithm is probably dealing specifically with circles in this case, and the circle itself may end up with a larger interface than simply Get/Set.

At the other end, sometimes a structure is simply overkill if the abstraction ends up being a one-off use "throwaway" - if the circle has no other potential use except for a single localised scenario calculating the area, then a very simple area calculation would do just fine

Title: Don't structure data all the way down

Body:
In the blog post Don't structure data all the way down, the author discusses different ways to structure a circle datatype and how to implement the parameters to a Radius function.

```<code>area({circle, {point,0,0}, 17.4})
</code>```

Kind of messy. What about a function to build a circle for us? Then we could do this:

```<code>area(make_circle(0, 0, 17.4))
</code>```

We could also have a shorter version of make_circle that only takes a radius, defaulting the center point to 0,0. Okay, stop, we're engineering ourselves to death. All we need is a simple function to compute the area of a circle:

```<code>area(R) -> math:pi() * R * R.
</code>```

He is talking about the functions in the Erlang language, which is functional and not object oriented (OO).  My question is, does this argument hold for OO languages, and does it hold for functional languages?


答:
Using an OO language or OO style, you have a hierarchy of structure elements. For example (intentionally very simplified):

statements, variables

functions / member functions

classes/objects

libraries/components  -

So you typically build more or less complicated classes from simpler building blocks like functions and variables. And it seems to me that's all what the blog post is all about: keep the lower level building blocks (like a function for calculating the circle area) simple, and the data structure "one layer up", which could be a "class" in an OO language. This may pretty obvious to someone who is used to design data structures in an OO manner, but may be not so obvious when using a pure functional style.

In fact, that does not mean you should ever implement something like an area function outside the scope of a circle class - you just should not give it parameters it won't need anyway (like the X/Y coordinates).

Title: Don't structure data all the way down


答:
I think this can be summed up as don't create an object only to call a single method on it and then destroy it and this is sound advice in the OOP world. I remember seeing a pycon video on it infact.

In the functional world, especially in Haskell (as its lazy), the opposite is often true. A common pattern is to build up a huge data structure, only to immediately break it down. Being lazy and if done right, Haskell doesn't use much memory doing this.

Title: Don't structure data all the way down


答:
It's a senior developer's job to review his code and suggest improvements.

You are not there to check after his work, I would personally hate if somebody was re-checking all my changes to see if anything broke

If he doesn't accept your advise, then it's PM's job to fix the communication issue.

Threading issue in a unit test makes me wonder whether this test is actually a unit test, rather than integration or component test.


答:
It is your company's intellectual property.

Generally it's a good idea to put re-usable code that you have written in a shared assembly, so that you can re-use it later in your career, assuming it doesn't conflict with any signed contracts.

What might happen if your buddy will use the same code in his work?

What if your buddy makes a contribution to your API and you will no longer be able to explain certain aspects of the API?


答:
Problem is that he didn't have enough patience.

Nobody will let you work on a framework or a platform of a large enterprise system right away.

You'll have to do the following:

Show the urge to learn

Make yourself familiar with business by working with a finished system

Make the right friends and make it clear that eventually you wish to work on a platform, rather than "sticking APIs"

Gain people's trust

All this doesn't come after a year, especially for a large enterprise system. Yes, it's great the the employee wants to do big boy's job, but there are always plenty others who have already spent years and are more qualified.


问:
Should I contract someone to help me with an existing project?
I have a paid Android app that I made by myself this past summer and I've been working on it throughout the year. The app is geared toward a professional niche market (but there are people all around the world who would buy it,) so it's priced highly. It is

Mostly C++, some Java

Built heavily on Qt (in the C++ code)

15,000+ lines of code

Well commented in some places but not others

I enjoy working on it, but find I no longer have time to slog through the more "menial" coding work of maintaining it, and instead want to focus on building new components and taking it to the next level, where I think I would really get bigger returns. In order to do that, I'm looking at contracting out some programming work to someone else.

My app makes some money, but not enough to hire anyone steadily - instead I'll have to just give them smaller jobs to do at a time. I might have to hire someone in a lower economic status country as well, because I expect that rates, say, here in the U.S. won't be affordable to me. My knee-jerk reaction is to go to vWorker.com (formerly RentACoder) where I did a lot of work several years ago. Is this going to help me or cause more headache than help?

Here are some more specific questions I have - feel free to answer any that you have thoughts on. Also, please let me know how I can improve this question. Thanks in advance.

How can I find a person with the right skill set? Is asking for Qt and Android SDK experience going to increase the price a lot?

How can I protect my copyright? Is this enforceable in less economically developed countries? Or can someone easily get away with stealing my code and selling it themselves?

Are there any other issues you foresee in hiring this person, and how might I address those?

答:
How can I find a person with the right skill set? Is asking for Qt and
  Android SDK experience going to increase the price a lot?

Somebody with a right skill set will have a good portfolio and recommendations from reasonably good companies. These are contractors that I would partially trust. They are normally very expensive.

I wouldn't trust anybody with my API if they are not from my country and if I don't meet them in person. There are too many things that can go wrong, even if you have a formal contract and a lawyer.

How can I protect my copyright? Is this enforceable in less
  economically developed countries? Or can someone easily get away with
  stealing my code and selling it themselves?

Yes, it'll be very easy for somebody in a third world country to disappear with your API. Even if you have a contract signed in a presence of a lawyer.

Are there any other issues you foresee in hiring this person, and how
  might I address those?

Have you considered offering a percentage of your business to some of your friends? There must be some people that you can trust?

Assuming your project has some academic aspect to it, you could try speaking to a local university to see whether final year students might be interested in doing some work no it. From my personal experience students might do some good work, but their main emphasis will be on a report, rather than code deliverable, so once again, this is not such a good solution.

Apart form these two, I don't see any other low risk alternatives.


问:
Are any companies moving from DVCSs to CVCSs?
Are there any actual business cases that have made any company move from a DVCS to a CVCS (regardless of whether they were on a CVCS originally)?.

Other than having a closed mind and rejecting the paradigm shift altogether (for the particular case of companies coming from a CVCS) I cannot think of any cause for this happening.

Double chocolate cookie for anyone with empiric evidence.

答:
The two aren't exclusive alternatives.

CVCS tools provides strong authorization features.

Some have their own built-in authentication mechanism (SVN with svnserve, RTC and its user registry, Perforce and its P4Admin): they can have their own internal user database, dedicated for their tools.

DVCS tools don't. See "Can we finally move to DVCS in Corporate Software?".

No built-in authentication and authorization mechanism.

DVCS: No authentication:
While CVCS can interface themselves with external authentication sources (like an LDAP), DVCS have no choice but to interface themselves to external authentication sources, using only external processes (openssh, httpd, ... since they own internal lightweight server has no authentication contrary to a SVN svnserve).

DVCS: No authorization:
If you have access to the repo path (through file, ssh or http), then you have all privileges on it (read, write, delete, ... on any branch).

If you need a finer-grained access control, you need to add an extra layer to the tool (RhodeCode for Mercurial or Gitolite for Git).

Those constraints mean that a DVCS has usually different use cases than a CVCS within a large company.

For instance, I have put in place both, with DVCS used to allow third-party enterprises to collaborate on a restricted shared code-base with the company.

Considering a DVCS allows for cloning a all repo with its complete history, that meant we had to come up with an import-export mechanism allowing us to export and publish in the DVCS only certain part of the CVCS (large) repo, in order for said third-parties to access  only what they need to work on.


答:
I do Mercurial consulting and my experience is that big companies spend a lot of time up-front to investigate the pros and cons of DVCS. So when they finally take the jump, they've already been using DVCS for one or two pilot projects and so they're pretty certain that it will work for the rest of the group.

However, I do know of one example where Mercurial was tested in production but then abandoned. It was a client that do hardware design and that involves a huge number of binary files that don't compress or merge very well. We're talking about 10,000+ files, each maybe 10 MB in size. So a checkout alone is more than 100 GB in size.

Before contacting us, the client spend a lot of effort on writing an extension for Mercurial that would externalize the storage of these files. The idea was that files would be downloaded on demand when you do a checkout — not when you do a hg clone. That was the history of each file would be stored on a central storage server and the clients would only download what they really need. Very much like Subversion, but with the advantages of DVCS for all the other project files. (Mercurial now ships with a largefiles extension that implements this idea.)

However, despite their efforts, they were not able to make their extension run efficiently and the hardware team eventually went away from Mercurial and started evaluating more traditional systmes such as Perforce. I don't know all the details and I feel that we should have been able to make it work, especially by using the now-standard largefiles extension. Granted, the extension will not be perfect for 10,000 files as it is now (the per-file overhead is too big), but that is something that can be solved one problem at a time by batching queries and stream-lining things.

So my advice is:

Make sure to do extensive testing before deploying a DVCS. Find a small group of developers that think DVCS is cool and let them run a project or two.

Contact someone who knows what works well and what works less well. Above, we were only called in pretty late in the process and at that point the client had committed themselves to a non-optimal choices. There is a number of support options for Mercurial and I will encourage you to use them.

Title: Are any companies moving from DVCSs to CVCSs?

Body:
Are there any actual business cases that have made any company move from a DVCS to a CVCS (regardless of whether they were on a CVCS originally)?.

Other than having a closed mind and rejecting the paradigm shift altogether (for the particular case of companies coming from a CVCS) I cannot think of any cause for this happening.

Double chocolate cookie for anyone with empiric evidence.


问:
For what reasons should I keep "using" section clean in C#?
Once when I was refactoring my code, I went up the IDE to the using section of my C# class, and cleaned unused namespaces and duplicate namespaces, and sorted them all.

My pair (pair programming) asked me the reason. I had no idea why I did that. I did it out of my habit to keep all of my code clean and tidy. I mean, I told him that having a cleaner code is a good idea in general, but of course that reason was not a good justification, as I won't even bother to spend my time in the using section of any C# code page.

Since many times you move a class or an enum (or a type in general) from one namespace to another namespace, and this adds new using statements to your code (either manually by going up the code window and writing the using statement yourself, or through the editor using Alt+Ctrl+F10 combination), and since these new using statements would be added to the end of using section, which makes them not sorted alphabetically, and since compiler never complaints about any of these problems, why should we care to make this section clean and tidy? What reasons might we have?

答:
There is no performance difference, no matter how many using directives you have.

But I think it makes sense to keep them clean for two reasons:

If you look at the usings, you can see what dependencies does the file have. This can help you figure out what the type(s) in the file do. If you do this, having the usings in a specific order helps you see it faster.

If you have too many usings, it may indicate that you have poor separation of concerns and that the type(s) in the file do too much.

Both of these aren't very important, so you shouldn't worry about it too much. But personally, I think it makes it worth keeping the usings clean.


问:
Functional Programming vs. OOP
I've heard a lot of talk about using functional languages such as Haskell as of late. What are some of the big differences, pros and cons of functional programming vs. object-oriented programming?</p>

答:
There is no real versus. They can be perfectly complementary. There are FP languages, which support OOP. But the communities differ in the way they handle modularity.

Users of FP languages tend to achieve modularity through mathematical laws. And prefer proofs to show compliance with their laws.

In imperative OOP users tend to capture the behaviour of the object in test-cases, which can be rerun if the object has changed and achieve in this way modularity.

It is just a small aspect, but I think it is worth mentioning.

Title: Functional Programming vs. OOP


问:
What is your approach to multi-paradigm programming?
I have been learning some Ruby recently and I had the following experience.
I had written a small tool of about 200 lines of code and, as an inexperienced Ruby programmer, I had used several loops to build arrays from other arrays.
E.g.

```<code>gs = ... # Some array of input data.
l  = gs.size
i  = 0
r  = Array.new
while (i < l) do
  if (cond(gs[i]))
    r.push(gs[i])
  end
  i = i + 1
end

# r contains the result now.
</code>```

Then I discovered that I can do it in a functional style:

```<code>gs = ... # Some array
r  = gs.select { |g| cond(g) }

# r contains the result now.
</code>```

So I immediately replaced most of my loops in the code with constructs like each, select, take_while, drop_while, and so on. I have decided to use a functional style in Ruby whenever possible and try to avoid an imperative style.

As another example, in C++ I tend to use classes and methods everywhere and use functions only for small utility tasks that are private to the implementation of some class. So I tend to think object-oriented when working in C++ and avoid
a procedural style almost completely.

More in general, when working on a given project in a given language, I tend to pick one paradigm and stick to it throughout the project: I find this makes my code more uniform, easier to read and to debug, which, IMO, is very important, especially for production code.

Yet, I often think that maybe I should explore more and try out different possibilities offered by a language, e.g. use different paradigms and try out different solutions. For me this involves some overhead both while coding (should I make it procedural or object-oriented? imperative or functional?) and when reviewing or debugging code (what did I want to do here?) because of the increased complexity.

So my question is: do you also tend to select a preferred programming paradigm
when coding and stick to it, or do you tend to explore more and mix different paradigms?

If you mix different paradigms, do you have the feeling that there is some overhead in terms of how fast you can write and debug code (added complexity, switching between different mindsets) or is it just a matter of learning how to do it and then you can even be more productive?

Or do you mix different paradigms in a more structured way, e.g. you apply each paradigm to a specific class of problems (e.g. functional for queries, object-oriented for architectural aspects, and so on)?

答:
I tend to think less in "paradigms" and more in terms of using the most appropriate (i.e. - simple, readable and maintainable) tool for the job.   I don't believe in sticking rigidly to paradigms because I feel that often results in going out of your way to write code in a certain manner just for the sake of adhereing to the "rules".
However it's certainly good to learn many different techniques for using your chosen language (and learning different languages can often open your eyes up to brand new ideas which perhaps you'd not have considered before)

for example, a "pure" OO approach is to wrap everything as an object; sometimes that's appropriate if you're writing a framework full of reusable components, but for a simple specific problem, the end result of doing that might just be unwieldy, bloated and over-complicated.

Likewise, a "pure" functional programming approach implies strict conditions of lazy evaluation - using completely stateless function-objects everywhere - this is simply impractical for 99% of problems, but the style of passing functions around can sometimes result in some very elegant and simple solutions.

in C++ (my main language), for example - I find that passing functionoids around can help build very clean code when dealing with situations which might otherwise be solved by passing references to objects everywhere (e.g. the standard library containers/algorithms, and for anything event-driven), but there's very often some kind of state associated with those functionoids so it doesn't truly qualify as being "functional".

At the same time, C++ templates can be used for interface-driven programming - templates are typically part of the generic programming paradigm, but I find myself using them as a way of handling compile-time Dependency Injection (a.k.a "Policy Based" classes), with the result being a fairly loosely coupled generic-OO hybrid allowing very easy unit testing.

This all varies between languages - I'm fully aware that C# programmers do not achieve Dependency Injection via generics (even though generics are the closest equivalent to templates), but that's because C# has a totally different set of rules - so again, it comes down to the most appropriate language tool instead of sticking to a paradigm.  One of the reasons a lot of general-purpose languages are usually labelled "multi paradigm" is the fact that people who use those languages tend to avoid ideology and aim for solutions using a wide variety of different tools.