问:
If you use MFC how did find it best to learn the concepts?
I'm currently working with C++ MFC applications in Visual Studio 2008.  I have spent most of my time up to this point working with Java Swing development which seems to be not quite as involved as win32 or MFC are.  I've noticed that there seems to be a lot of little parameters and specifications that go into creating even a simple element like a status bar or menu bar.  I've spent a bit of time working through the MSDN library on the matter but it doesn't seem to explain why many of these parameters and such are needed to set up these elements.  I always find that I'm able to wrap my head around things and remember them if I understand why I'm doing it. If you program using MFC (or a similar framework) what did you find helpful in the learning process? Do you recommend any website, books, or other references?  Any and all advice is appreciated!</p>

答: MFC is hard to use and learn because it is something you could call a windows assembler language. Very very low level and almost not encapsulating anything. When you do serious development you often come up with your own application specific toolkit on top of MFC. </p>


问:
Are certifications worth it?
I am finishing my college degree in programming soon and I'm exploring the next steps to take to further my career. One option I've been considering is getting a certification or a series of certifications in the area of development I want to work in.

Are these certifications worth the time and money? Do employers place a lot of value in them?

答:
I know you are asking about certifications but have you considered contributing to an Open Source project?

A lot of projects need help and some even have issues labeled as 'easy' which make a great starting point for people with minimum/no experience.

That way you can show prospective employers not only that you can code but also that you have a passion for what you do, enough to do it at your spare time.

ContentLicense: CC BY-SA 3.0

Title: Are certifications worth it?


答:
I'm going to address this from the perspective of a potential hiring manager.  Note that I typically operate in and around organizations for whom certifications, and even college degrees, are not a priority -- if you can show me code, demonstrate good development practices, can adapt to different methodologies, and are generally a good, creative team member with an emphasis on sharing/collaboration/contribution, you'll get a shot to do your best work.  This is not the case everywhere.

You say that you have no degree, but you are working on one.  This leads me to believe that you want to continue in school and you are just getting your ducks in a row for when you're done. That you're asking these questions now is a good step toward selecting the "right" jobs to apply for, and trying to get a feel for how developer communities form/interact/have associated norms is a good thing. Stay in school, and work to develop your presence in those communities (Programmers.SE, StackOverflow, GitHub projects, etc).  Not only will you gain experience, but you will also gain contacts.

Remember that you're at the beginning of your career and you have every path available to you -- pick a path that lights you up.  If someone says a certification in XYZ will guarantee you a job (note: it won't), and you just hate XYZ, don't do it.  Focus your time in the areas that spark your creativity and make you want to learn more so that you can contribute more -- for other developers, for the company that eventually pays you, etc.

How valuable are certifications? For some companies, really valuable. For others, not at all. If you have the money and time to devote to studying for and taking a certification exam, and the process of doing so will augment your current coursework in a way that is academically valuable to you, then there's no reason not to pursue one that interests you.

The best way to demonstrate your programming ability is to demonstrate your programming ability.  I'm not being sarcastic...really, just show it.  Contribute to an open source project. Start asking and answering on StackOverflow and gain reputation.  You want to be able to walk into an interview with a good knowledge of programming constructs, so you can answer the FizzBuzz-type questions and their ilk, but mostly you want to be able to say "I can do this thing you're asking because look here: I've done the thing you're asking, here and here and here and here."

Title: Are certifications worth it?

Body:
I am finishing my college degree in programming soon and I'm exploring the next steps to take to further my career. One option I've been considering is getting a certification or a series of certifications in the area of development I want to work in.

Are these certifications worth the time and money? Do employers place a lot of value in them?


问:
Best practice to query data from MS SQL Server in C#?
What is the best way to query data from a MS SQL Server in C#?

I know that it is not good practice to have an SQL query in the code.

Is the best way to create a stored procedure and call it from C# with parameters?

```<code>using (var conn = new SqlConnection(connStr))
using (var command = new SqlCommand("StoredProc", conn) { CommandType = CommandType.StoredProcedure }) {
   conn.Open();
   command.ExecuteNonQuery();
   conn.Close();
}
</code>```

答: As long as you have parametrized your inputs any approach is valid.  Much of the don't have queries in code arguments came from the bad old days when many of the libraries forced you to string-append your statements together and that is where sql injection attacks came from.</p>


答:
First, finish your degree.

Second, work on some sort of programming project. You might make a significant contribution to an open source project -- enough that you can point to code and/or features and say "I did that." Or start your own project and build something useful. It doesn't have to be the best thing in the world, it doesn't have to gain huge popularity. Again, you want something that you can show off and say "here's something significant that I did."

Third, look for jobs where you can leverage the degree that you will have. If you complete a triple major, that's pretty significant in itself. Having skills in math, statistics, and economics will make you desireable in a way that other developers aren't. I'd expect that having a solid knowledge of any one of those fields would be more important than being an expert programmer, and you should be able to use those credentials to help you land a position where you can continue to develop your programming chops.

Fourth, don't rush. Finishing your degree is much more important than landing your first real job. You'll spend the rest of your life working, but after school you're going to have a lot of trouble finding the kind of time and freedom to explore and learn that you you have in school. Take advantage of the time you have now, use it to build up a solid reserve of knowledge that you can draw on for the rest of your career.

Fifth, skip the certifications unless you're going for a particular position that requires one. I've been programming for a long time, and I've never even been asked about any certifications or felt that any would be beneficial. I can see how they might be appealing since your degree isn't in computer science and you don't have any experience, but remember: after you land your first job, you'll have experience, and you only have to find one person out there who's willing to hire you in order to land your first job.

Good luck.

Title: Are certifications worth it?


问:
Is Usage Tracking esoteric or state of the art?
There are several products for tracking the usage of your application. I know at least 10 offers. They tell you which features were used more often than others. Thus, you can identify features that may not make into new versions.

While with Google Analytics, or similar tools, this a standard tool for the web at the "page-level". I just wonder who is already using this analysis for desktop applications?

Big companies like Microsoft of course do it, but do ISVs and small vendors (perhaps < 50 employees) use such tools?

I currently don't know anybody, so I'm really curious about it: Is Usage Tracking esoteric or state of the art?

答:
Logging can be used to help track problems and queried as a way to analyze feature usage. You can gather samples and analyze over time, but I wouldn't go so far as collectiing all of them from every installation (Unless you don't have that many.).

If you feel there are functions no one wants to use, start working on your methodology for gathering user requirements and determine why you're wasting your time adding them in the first place. You'll never be perfect. Needs change over time in very domain.

Make sure you have an open dialogue with your users. You'll learn a lot.

I recall working at a software company where a young dev was so proud of the report he created (not part of the specs) with a worthless pie chart on it. The owner looked at it and told the young dev, "Go back to your computer and make something I can sell."


问:
Do coding puzzles make good interview questions
I am interviewing candidates for Java programmer positions.

My colleague insists in filling more than half of the interview with java coding puzzles.His view is that, if candidates are able to navigate through the loops, then they must be good.

One such example of coding puzzle is

```<code>        i=0;
        for( i=1 ; i< 10 ;i++)
        {
                if(i%3 ==0) i++; break;
                if(i%2 ==0) i++;

         }
          print(i);
</code>```

Follow up: what happens if break is removed ?

答:
I swear one of these days when someone asks me this kind of question I'm going to answer something like "I have a better suggestion. You fire any fool who writes code like this." Code like this should never make it past code review.

OTOH, I like puzzles. I find them fun. It has NOTHING to do with whether I can write decent, maintainable, robust code.


问:
What is the difference between DI and IoC?

Possible Duplicate:

  Difference between Dependency Injection (DI) & Inversion of Control (IOC)

I'm new to Inversion of Control, Dependency Injection and everything related to these stuff, so excuse me if I'm not specific in my question: Is there any magical piece of code, a good explanation or a link, so I can finally distinguish the concepts?

I really think that using Dependency Injection already means using Inversion of Control, but is there any way of using Inversion of Control without using Dependency Injection?

I've already read Martin Fowler's articles but I still find the concepts very confusing.

答:
Dependency Injection is one way that Inversion of Control is often implemented, but there are others.  From the Wikipedia Inversion of control article:

Implementation techniques are influenced by the computer language used.

In Java there are six basic techniques to implement Inversion of Control. These are:

using a factory pattern

using a service locator pattern

using a constructor injection

using a setter injection

using an interface injection

using a contextualized lookup

Constructor, setter, and interface injection are all aspects of Dependency injection.


答:
Inversion of Control is a general concept where normal control flow is “inverted” in some way.

By “normal” flow, I mean a traditional batch application flow: the code runs from beginning to end, creating resources, requesting data and providing output. Control flow is dictated by the application itself, calling into libraries and system facilities as necessary. Any inversion of this — where libraries rather than the application (using these terms somewhat loosely) drive control flow — is in some sense inversion of control.

One of the most common examples of IoC is an event loop. In an event loop, the GUI toolkit (or the operating system) is in control, calling back into your application to handle events and process input. The normal flow — requesting input & processing it — is inverted so that the input processor drives the application, rather than the other way around.

Dependency injection is a specific use of Inversion of Control, where control inversion is applied to the selection and allocation of dependencies. Rather than having a component instantiate the subcomponents it requires, the creating code (either application code, manually, or the DI container) instantiates the required subcomponents and injects them into the component.

Title: What is the difference between DI and IoC?

Body:
Possible Duplicate:

  Difference between Dependency Injection (DI) & Inversion of Control (IOC)

I'm new to Inversion of Control, Dependency Injection and everything related to these stuff, so excuse me if I'm not specific in my question: Is there any magical piece of code, a good explanation or a link, so I can finally distinguish the concepts?

I really think that using Dependency Injection already means using Inversion of Control, but is there any way of using Inversion of Control without using Dependency Injection?

I've already read Martin Fowler's articles but I still find the concepts very confusing.


问:
What is the point of an interface?

Possible Duplicate:

  When to use abstract classes instead of interfaces and extension methods in C#?

  What other reasons are there to write interfaces rather than abstract classes?

This question sounded a bit trivial to me as well, till I gave a it serious thought myself.

What is the point of a Java interface? Is it really Java's answer to multiple inheritance?

Despite using interfaces for a while I never got around to think the point of all this. I know what an interface is, but still pondering on the why.

答:
You program against an interface instead of a concrete implementation in order to make your code flexible.

For example,

You program against IScrewDriver so that you can use PhilipsScrewDriver or FlatScrewDriver, based on your needs.

Usually, you'll use some sort of IoC container to "inject" the appropriate screw driver on your code, but that's not really necessary.

Hope the examples helps.

OwnerDisplayName: hakish

Title: What is the point of an interface?

OwnerDisplayName: Esteban Araya


答:
Java does allow multiple inheritance of interface; single inheritance is for implementation.

Interfaces are important because they separate what a class does from how it does it.  The contract defining what a client can expect leaves the developer free to implement it any way they choose, as long as they uphold the contract.

You see examples of this all over the JDK.  Look at the java.sql package - it's riddled with interfaces.  Why?  So different relational databases can be free to implement those methods for their particular product.  Clients need only deal with the interface reference types.  Changing relational databases is as easy as swapping one JDBC driver JAR for another.  Clients need not change.  (As long as they don't stray from the contract.)

Dynamic proxies and aspect-oriented programming depend on interfaces.  They can replace the implementation at runtime that way.

Title: What is the point of an interface?

Body:
Possible Duplicate:

  When to use abstract classes instead of interfaces and extension methods in C#?

  What other reasons are there to write interfaces rather than abstract classes?

This question sounded a bit trivial to me as well, till I gave a it serious thought myself.

What is the point of a Java interface? Is it really Java's answer to multiple inheritance?

Despite using interfaces for a while I never got around to think the point of all this. I know what an interface is, but still pondering on the why.

OwnerDisplayName: duffymo


答:
This used to puzzle me until I realized something:

Fundamentally, an interface is simply a class that contains only abstract methods.  By making such an entity into an interface you gain some flexibility that you don't have with classes.

Title: What is the point of an interface?


答:
What is the point of a Java interface?

The point is to separate the API (what to do) from the implementation (how to do it).

Interfaces are also necessary when using callbacks, since Java doesn't allow you to pass function references.

Is it really Java's answer to multiple inheritance?

Among other things, yeah. It gives you some of the features of MI, without the nasty complications.

Title: What is the point of an interface?


答:
I think the key is to realize what the puzzle you come up with asks, and what it doesn't.

There's a few, of varying levels of (imo) utility:

Puzzles for the sake of puzzles. Maybe they're meant to test how a candidate thinks under pressure. Maybe they're meant to look for agile learners or the like. I don't really care - I hate them. I'm terrible at puzzles, and honestly if I hit one in an interview that felt very much like I was just being tested on how much I suck at adventure games, I'd probably say something. I'd like to say these don't crop up, but they do.

Code reading puzzles. Like the one in the OP. I'm...not necessarily convinced of their utility. It often seems these are somewhat poorly written code to begin with, follow bad practice, or are really contrived.

"Spot the algorithm" puzzles. The ones you occasionally see in 'Solve this, work here' ads on public transportation, where really you'd just be looking for someone familiar enough with some concepts that get applied in your field. I could see these being useful if your particular application is filled with a particular type of problem.

FizzBuzz and related "do you know a concept" puzzles. These I think are decent for testing basic skills.

I think there are two main pitfalls to this approach though. The first is being hard/opaque/clever for its own sake, like some sort of sadistic Dungeon Master. Why are you testing people for their ability to decrypt terribly written code designed not to be read or understood (I'll make an exception for places that already have a terribly written code base)?

The second is spending too much time on puzzles, and not really addressing what these value. Doing well on these types of questions indicate you're good at solving puzzles. Is that the primary talent you want in your employees?

Title: Do coding puzzles make good interview questions

Body:
I am interviewing candidates for Java programmer positions.

My colleague insists in filling more than half of the interview with java coding puzzles.His view is that, if candidates are able to navigate through the loops, then they must be good.

One such example of coding puzzle is

```<code>        i=0;
        for( i=1 ; i< 10 ;i++)
        {
                if(i%3 ==0) i++; break;
                if(i%2 ==0) i++;

         }
          print(i);
</code>```

Follow up: what happens if break is removed ?


问:
Should I intentionally break the build when a bug is found in production?
It seems reasonable to me that if a serious bug is found in production by end-users, a failing unit test should be added to cover that bug, thus intentionally breaking the build until the bug is fixed. My rationale for this is that the build should have been failing all along, but wasn't due to inadequate automated test coverage.

Several of my colleagues have disagreed saying that a failing unit test shouldn't be checked in. I agree with this viewpoint in terms of normal TDD practices, but I think that production bugs should be handled differently - after all why would you want to allow a build to succeed with known defects?

Does anyone else have proven strategies for handling this scenario? I understand intentionally breaking the build could be disruptive to other team members, but that entirely depends on how you're using branches.

答:
While I think you should in some way 'check in' the bug as test, so that when you fix it it does not happen again, and in some way prioritize it, I think it's best not to break the build (/the tests). The reason is that subsequently build-breaking commits will be hidden behind your broken test. So by checking in a broken test for this bug you demand that the whole team sets their work aside to fix this bug. If that does not happen you might end up with breaking commits which are not traceable as such.

Therefore I would say it's better to commit it as a pending test, and make it a priority in your team not to have pending tests.


问:
Developing a mobile interface for Website
I have a website developed in ASP.NET MVC.

Now, I am looking forward to getting up a mobile interface for it. My knowledge in this regard isn't that great, so I will explain what is needed to be done. It's much like on the lines of StackOverflow or Programmers and following are the few points that need to be addressed.

Much like Stack Overflow, if a site is visited from mobile, auto-detection should happen and the mobile version should be displayed.

Do I need to setup some sub-domain like m.mysite.com and should I have the mobile site installed for this domain (SE sites don't do this now but Facebook does that)

Lastly, How to design the website that is easily readable on all sized of screens for mobile.

答:
For 1., see here: http://detectmobilebrowsers.com/

For 2., That's up to you, technically it doesn't make much of a difference.

For 3., Javascript frameworks like jQTouch or Sencha Touch might help. Beyond that, design questions are probably off-topic here.


答:
Re: 1 - Shouldn't (necessarily) be your responsibility to detect mobile devices, as long as yu use the @media type correctly in your stylesheet.

Re: 2 - That would depend on whether the difference between what you want to serve mobile devices as opposed to "normal" viewers is large. If your main site is heavy on JavaScript and you want to serve your mobile users a much simpler view, use a separate subdomain. If it's pretty much the same content, you just want the presentation to be different, you don't need a subdomain, just a different stylesheet (or parts thereof).

Re: 3 - Follow best practices, use em font sizes rather than px, etc... beyond that would take quite a while to answer this part ;-)

Title: Developing a mobile interface for Website

Body:
I have a website developed in ASP.NET MVC.

Now, I am looking forward to getting up a mobile interface for it. My knowledge in this regard isn't that great, so I will explain what is needed to be done. It's much like on the lines of StackOverflow or Programmers and following are the few points that need to be addressed.

Much like Stack Overflow, if a site is visited from mobile, auto-detection should happen and the mobile version should be displayed.

Do I need to setup some sub-domain like m.mysite.com and should I have the mobile site installed for this domain (SE sites don't do this now but Facebook does that)

Lastly, How to design the website that is easily readable on all sized of screens for mobile.


问:
What constitutes "distributing" for LGPL v3
I am considering basing some new software on a LGPL web application. I want to utilize this new software for creating one website for my employer, and we do not intend to sell or distribute the software itself to anybody. Does publishing web pages from LGPL software constitute "distributing" in the license, so I would have to publish our changes to the LGPL code as well?

I understand that none of you are lawyers so IANAL is implied. I also understand that I could contact the developers of the LGPL software and ask for a different license.

答:
There's a variant of the GPLv3 called the "Affero GPL v3". To quote gnu.org,

The GNU Affero General Public License is a modified version of the
  ordinary GNU GPL version 3. It has one added requirement: if you run
  the program on a server and let other users communicate with it there,
  your server must also allow them to download the source code
  corresponding to the program that it's running. If what's running
  there is your modified version of the program, the server's users must
  get the source code as you modified it.

It follows that "running a program on the server" is not distribution; the base GPLv3 already covered that.


答: Another option is to check the failing test into a separate branch in your source control system. Depending on your practices, this may be feasible or not. We sometimes open a new branch for ongoing work, such as fixing a bug that is not trivial.</p>

Title: Should I intentionally break the build when a bug is found in production?

Body:
It seems reasonable to me that if a serious bug is found in production by end-users, a failing unit test should be added to cover that bug, thus intentionally breaking the build until the bug is fixed. My rationale for this is that the build should have been failing all along, but wasn't due to inadequate automated test coverage.

Several of my colleagues have disagreed saying that a failing unit test shouldn't be checked in. I agree with this viewpoint in terms of normal TDD practices, but I think that production bugs should be handled differently - after all why would you want to allow a build to succeed with known defects?

Does anyone else have proven strategies for handling this scenario? I understand intentionally breaking the build could be disruptive to other team members, but that entirely depends on how you're using branches.


答:
A implements B, C is not same as A extends B, C

Although it looks pretty clear, I, too, have always been confused when people say interfaces are answer to the lack of multiple inheritance.

As this link shows there are ways to simulate multiple inheritance while using interfaces. But interface is not directly helping implement multiple inheritance.

Interface, I believe, is for multiple subtyping. In the above example, A is both of type B and C. Hence A can be substituted for either members of B or members of C (see this Wikipedia article).

Since you could have multiple implementations of a single interface, it also helps in dynamic polymorphism. Your code depends on the type (the interface) and not on implementation (which could be substituted dynamically based on context).

Title: What is the point of an interface?


答:
Found this link to be really useful. Couple of excerpts that made sense to me:

...Separation of interface and implementation is one of the primary
ideas behind Java in general. The Java virtual machine (JVM), for
example, is an abstract computer that defines the way your program
"interfaces" with the underlying real computer. A JVM that runs on
Windows is one implementation of that abstract computer. A JVM that
runs on the Macintosh is another. A JVM that runs on your wristwatch
is yet another

Interfaces give you more polymorphism than singly inherited families
of classes, because with interfaces you don't have to make everything
fit into one family of classes.

By using interfaces, you decouple the parts of your system from each
other and generate code that is more flexible: more easily changed,
extended, and customized.

Title: What is the point of an interface?


问:
Google Analytics and customers privacy
I work in a company that sells SaaS web applications for HR and financial issues. Our customers are key accounts to which we guarantee the privacy of their data, for obvious reasons.

We need to make usage statistics of our applications by its customers (which links are clicked the most? Which browsers are used the most? What is the average screen resolutions? etc). I personally use Google Analytics on my sites. GA is a very powerful and complete solution for this. But it raises questions of privacy.

Have you already had this problem?

Were you able to impose on your customers? how?

If not, did you use an alternative? or did you develop your own measurement tools of statistics?

答: You could use Piwik from http://piwik.org . It's essentially an open source, host it yourself, web analytics tool. It has most of the major features of GA and is just as easy to use.</p>

Title: Google Analytics and customers privacy


问:
System Decoupled in the Wrong Places: Meta-Problem?
At a meta level, I often find that when I grow a codebase organically, parts of the system that I eventually find need to know about each other (at least through some interface) have been mercilessly decoupled.  This often occurs in research prototype code, where one tends to frequently think of tweaks and small improvements that weren't planned for in the original codebase.

Usually, some setting or piece of data needs to be plumbed through about 15 zillion layers of function calls in ways that I never anticipated when I designed the code.  This leads to a very ugly dilemma:

Use an ugly hack.  This can be yet another global variable, bolting the data onto a class that it clearly doesn't belong in, putting a bunch of print statements in the middle of code that previously had nothing to do with I/O logic, doing a seemingly straightforward task in a very roundabout way to make it fit in my original codebase, etc.

Shotgun surgery refactoring.  This almost never gets done in practice because the code will likely have to be rewritten anyhow if it is to become production quality, was hard to get working the first time, is hard to test, or I just plain have higher priorities than writing clean, maintainable code when either I have a deadline or I know it's just a prototype for now.  Furthermore, the next tweak may break whatever nice abstractions I come up with.

Are there any good meta-tips or design principles that will help me avoid situations like this in the first place?  I am NOT looking for answers that simply recommend refactoring after the fact, as a nightmarish shotgun surgery refactoring session is exactly the kind of thing I'm trying to avoid.

答:
Using a dependency injection framework can help with adding new dependencies without using global variables or passing values through a bunch of method calls. An AOP framework may help implement new cross-cutting concerns.

For example, logging can be achieved through either AOP and/or a logging object that can be injected at any layer.

An example of a framework that provides both of these concepts is Spring.

EDIT: I know the comment below is against the idea of more dependencies, but I did find this for Python: Spring Python

ContentLicense: CC BY-SA 2.5


答:
Yes, interfaces are Java's answer to multiple inheritance. There is absolutely nothing that an interface can do that an abstract class cannot do, except for the fact that multiple interfaces can take part in the ancestry of a class, while multiple classes cannot.

So, we use an interface instead of an abstract class in order to give descendants the freedom to extend whatever base class they wish, (and implement our interface,) rather than forcing them to extend a specific base class.

Title: What is the point of an interface?


答:
There are many reasons why Java has it's own construct for multiple inheritance, i.e. with interface and abstract classes. Here are three that I can think of:

It reduces boilerplate code (i.e. pure virtual functions)

In languages that don't have the interface construct, you have to do a lot of boilerplate coding. Consider in C++ you need to create a class that have pure virtual functions:

```<code>class MyInterface
{
public:
  virtual void show() = 0;
  virtual int number() = 0;
};

class ConcreteImpl : public MyInterface
{
public:
  void show()
  {
    cout << "Concrete Impl here";
  }
  int number()
  {
    return 1337;
  }
};
</code>```

The equivalent in Java would be less verbose, mostly because methods are virtual (overridable) functions. And it is more apparent that one of the artifacts is the interface.

```<code>interface MyInterface {
  void show();
  int number();
}

class ConcreteImpl implements MyInterface {
   public void show() {
     System.out.println("Concrete Impl here");
   }
   public int number() { return 1337; }
}
</code>```

Java does allow a class with mixed pure virtual and implementation, with the abstract keyword.

It constrains the "diamond inheritance" problem

One of the problems associated with multiple inheritance is the hairy diamond inheritance problem. Consider if you have a language that allows this chain of classes in a language such as C++:

Think of a SuperBaseClass that has two implemented BaseClass, both implementing the SuperBaseClass's method as virtual functions. In turn both BaseClass's are implemented by the MyImplementation class. Consider what will happens if you call super() in MyImplementation.draw()? It is not always apparent what will happen, even in C++, developers who have designed this will find themselves in a weird debugging session.

There is nothing particular wrong with diamond inheritance, so to avoid the problems of calling the super-method, you have to design them either by using pure virtual functions or design them in a smarter fashion. In Java, since all methods are virtual by default, you are constrained by the fact that you can only do multiple inheritance with interfaces since they don't contain any implementation (with the implements keyword). Other classes, even abstract ones, can only be single inherited (with the extends keyword).

Seasoned devs were already using interfaces as a concept (circa 1995)

If you got into Design Patterns by GoF, you will notice that they rely heavily on interfaces to design extensible systems. In fact one of the principles of Design Patterns is:

"Program to an 'interface', not an 'implementation'." (Gang of Four 1995:18)

Interface in the GoF sense means that you should program towards a superclass rather than the implementation. One example would be that you should prefer typing your variable to Collection<T>, Iterable<T>, or List<T> instead of ArrayList<T> in Java if the only methods you use on the object is to iterate it. A pattern example from GoF would be the strategy pattern where the context doesn't need to know the exact strategy it is given to execute, but will execute the set one, regardless of what it was.

Title: What is the point of an interface?

Body:
There are many reasons why Java has it's own construct for multiple inheritance, i.e. with interface and abstract classes. Here are three that I can think of:

It reduces boilerplate code (i.e. pure virtual functions)

In languages that don't have the interface construct, you have to do a lot of boilerplate coding. Consider in C++ you need to create a class that have pure virtual functions:

class MyInterface
{
public:
  virtual void show() = 0;
  virtual int number() = 0;
};

class ConcreteImpl : public MyInterface
{
public:
  void show()
  {
    cout << "Concrete Impl here";
  }
  int number()
  {
    return 1337;
  }
};

The equivalent in Java would be less verbose, mostly because methods are virtual (overridable) functions. And it is more apparent that one of the artifacts is the interface.

interface MyInterface {
  void show();
  int number();
}

class ConcreteImpl implements MyInterface {
   public void show() {
     System.out.println("Concrete Impl here");
   }
   public int number() { return 1337; }
}

Java does allow a class with mixed pure virtual and implementation, with the abstract keyword.

It constrains the "diamond inheritance" problem

One of the problems associated with multiple inheritance is the hairy diamond inheritance problem. Consider if you have a language that allows this chain of classes in a language such as C++:

Think of a SuperBaseClass that has two implemented BaseClass, both implementing the SuperBaseClass's method as virtual functions. In turn both BaseClass's are implemented by the MyImplementation class. Consider what will happens if you call super() in MyImplementation.draw()? It is not always apparent what will happen, even in C++, developers who have designed this will find themselves in a weird debugging session.

There is nothing particular wrong with diamond inheritance, so to avoid the problems of calling the super-method, you have to design them either by using pure virtual functions or design them in a smarter fashion. In Java, since all methods are virtual by default, you are constrained by the fact that you can only do multiple inheritance with interfaces since they don't contain any implementation (with the implements keyword). Other classes, even abstract ones, can only be single inherited (with the extends keyword).

Seasoned devs were already using interfaces as a concept (circa 1995)

If you got into Design Patterns by GoF, you will notice that they rely heavily on interfaces to design extensible systems. In fact one of the principles of Design Patterns is:

"Program to an 'interface', not an 'implementation'." (Gang of Four 1995:18)

Interface in the GoF sense means that you should program towards a superclass rather than the implementation. One example would be that you should prefer typing your variable to Collection<T>, Iterable<T>, or List<T> instead of ArrayList<T> in Java if the only methods you use on the object is to iterate it. A pattern example from GoF would be the strategy pattern where the context doesn't need to know the exact strategy it is given to execute, but will execute the set one, regardless of what it was.


问:
Is the financial sector any different from other sectors in terms of language fragmentation?

Language Choices of Large Corporations

Having spent almost 12 years working in the financial sector, at both large and small companies, my overriding impression, with the exception of Goldman Sachs, is that fragmentation (or, putting a more positive spin on things, diversity) is the name of the game.

Within a single company, we might see C, C++, Smalltalk, Java, J++, Perl, C# and more. Even now, I hear about large swings towards using languages which have been around for 30 years but which are not widespread within the company (i.e. avoidable fragmentation; if the language wasn't appropriate 5 years ago, why now?)

I guess I'm interested by

Are large, technology-focused companies outside the financial sector as fragmented as those within it?

Why has this fragmentation happened?

Are software companies as fragmented?

The position of Java

My impression is that Java largely “won” the first decade of this century in the financial sector, which (probably) saw the biggest historical expansion of systems. By "won", I simply mean that it was the most popular choice for new systems during this decade.

I'd be grateful to be pointed towards any evidence as to these points, and especially sector-comparisons.

PS. My reasons for asking this question are that I will be giving a talk to students in London about building financial IT systems. I would like to be able to place my experiences of financial IT in a wider context, and I do not want to make sweeping generalizations.

答:
In short from what I've seen (I've worked in a fairly wide range of sectors).

Yes, it's just as fragmented

A whole variety of reasons.  Languages are Fads/Fashions like anything else.  Vendors push a particular type of technology.  Sometimes gasp a technology is genuinely chosen because its the correct one for a particular problem domain.  Sometimes its because there are developer resources available for a particular language... The list goes on :-)

I've seen them try to standardise, for example Google was heavily a Python and Java shop (+ web front end stack inc GWT) but now they also have Go, Dart, Android....  Oracle I think is primarily a C/C++ and increasingly Java shop (no surprise there), I think their aim is to try an Javaise as much as possible (although since Java's integration with the O/S isn't tight, I think their DB stuff will stay off it for the foreseeable future).


答:
The financial sector is incredibly fragmented software-wise simply because of the cannibalistic nature of those businesses. These businesses often buy and sell full companies, divisions, product lines, et al, on a business level to maximize their profit. In the process, they end up having to provide the tools that manage that product on their systems, and so a company with no Java might inherit a new Java system and have to incorporate it. Extrapolate that paradigm out 20 years, and you have a group of companies who have systems in just about every form factor without the resources to convert them all over to a common system.

Software companies do have some fragmentation but it's less severe because the business decisions there are driven more by the business of technology. So when software company X purchases software company Y, it's usually within the same platform. They might use different languages, but often that entity can remain intact rather than having to integrate into the other product areas or the company will attempt to take the the time/resources to convert the newly acquired pieces into their existing infrastructure. I've seen deals fall through simply because the people leading the business understood that they couldn't support the framework necessary or afford to convert.

I wouldn't say Java won even by a little. There are still too many languages out there that have legacy dominance. Even in the financial sector areas that I've worked personally I didn't see any one dominant technology base. I did, however, see a lot of arguments.

Title: Is the financial sector any different from other sectors in terms of language fragmentation?

Body:
Language Choices of Large Corporations

Having spent almost 12 years working in the financial sector, at both large and small companies, my overriding impression, with the exception of Goldman Sachs, is that fragmentation (or, putting a more positive spin on things, diversity) is the name of the game.

Within a single company, we might see C, C++, Smalltalk, Java, J++, Perl, C# and more. Even now, I hear about large swings towards using languages which have been around for 30 years but which are not widespread within the company (i.e. avoidable fragmentation; if the language wasn't appropriate 5 years ago, why now?)

I guess I'm interested by

Are large, technology-focused companies outside the financial sector as fragmented as those within it?

Why has this fragmentation happened?

Are software companies as fragmented?

The position of Java

My impression is that Java largely “won” the first decade of this century in the financial sector, which (probably) saw the biggest historical expansion of systems. By "won", I simply mean that it was the most popular choice for new systems during this decade.

I'd be grateful to be pointed towards any evidence as to these points, and especially sector-comparisons.

PS. My reasons for asking this question are that I will be giving a talk to students in London about building financial IT systems. I would like to be able to place my experiences of financial IT in a wider context, and I do not want to make sweeping generalizations.


答:
The name of the game in any programming situation is creating a robust application so solve a particular problem. Different languages provide different features, frameworks, and thus different ideal uses.

Where I work, our main language is in fact Java, which as you say is the top language for programming these days. Despite our being a "Java Shop", on a given day you may work with two or three different languages.

To list, I'm my 8 months at my current place of work, I have worked in Java, JSP, PHP, Python, Javascript, bash scripting, and even worked on very large ANT scripts. In addition, I know of or have seen Perl, C, and Groovy. Each of these languages generally provides a feature-set that another lacks, which would ideally be why the language is chosen for use.


问:
Semantic or structure - which should get preference for variable naming?
We've a call stack in our project. The program is written for microcontroller, the language is C. The call stack is basically an array of integers. The variable that represents this call stack ends with the string _stack.

I was reviewing the implementation. The feature is reset recovery, not the call stack, but the call stack is part of the feature. When I first saw the variable, I thought it is used as a stack. So I assumed the following:

No entries other than the last entry can be accessed.

There will be PUSH/POP/CLEAR/TOP operations.

Next, I found that the first entry (index 0) is always checked in a special condition. I also found a function where all elements of the array are read sequentially from index 0 to top. Both of them are invalid stack operation.

I am thinking that the variable name should not contain the string stack as it is not a stack, rather it is used as a list. But the coder is showing valid logic, that according to semantic meaning, it's a stack and there is in fact PUSH operations.

Should the variable be named with *stack*?

答:
In your case, the difference between calling the structure a list which it apparently is and a stack which it is effectively being used as, is the debate between Systems & Apps Hungarian notation.

Depending on the situation and context, one might be more appropriate than the other. Generally Apps Hungarian provides the reader with a greater context of the use of the variable based on the name alone than Systems Hungarian, thus leading so somewhat self-documenting code.


答:
Every sector is fragmented. The choice of language has very little to do with the industry. It can depend on the platform to be used, the libraries available, and when it was started.

Back in the 1980's , or even back in the 70's the DOD wanted everybody to use ADA. Despite being on DOD contracts for more than 20 years I never saw ADA. We used to use FORTRAN or  C, then we moved to C++; now we use C# and ASP. For one customer everything was delivered in VBA because the approval process was faster for spreadsheets compared to a DLL.

In the past year I have used python, php, C++, plus specialized scripting languages for shrink wrapped software. In 25 years of programming I have used almost as many languages as years on the job.


答:
I see the same thing on the telecom business, and it doesn't surprise me at all. Some reasons for that:

Merges and acquisitions potentially increase the number of languages.

IT systems developed outside IT (and then turned to IT when maintenance becomes a burden) are developed in whatever language strikes the fancy of the people writing them.

IT trends push the adoption of new languages, and then die or gets replaced with a new trend before migration from old languages is complete.

Critical projects with tight time constraints often have freedom to choose the "most adequate language" -- whatever is striking the fancy of the top notch programmers assigned to them.

IT evolution of programming happens more often with the creation of new languages than with changes to old ones -- and for good reason. Backward compatibility is strong requirement, which seriously constrains what changes are possible.


答:
Are large, technology-focused companies outside the financial sector as fragmented as those within it?

Yes, most of them are. I'd say, some even more.

Why has this fragmentation happened?

First of all, big companies have many teams, not all opt for the same solutions, as they remain to some degree independent, some originally were other company which was taken over etc. Then 3rd party tools come in. They also use variety of languages/frameworks, often completely different than the ones used internally in the company.

Are software companies as fragmented?

Company creating software are less dependent on having variety of 3rd party software, which would use variety of languages. However, if the company creates software for various platforms, for example mobile platforms, you'll use Java for Android, Objective-C for iOS, C# for WP, something else for your backend etc. Big enough company will have mobile clients, web clients, Win and Mac clients and back-end technologies using 3-5 different languages.


问:
What should I be looking for when evaluating unit testing libraries and tools?
I'm in the process of choosing new unit testing tools for soon to be started project. There are plenty of them!

The basic requirements I have would be that it can run tests on at least Windows and Linux, it is C++/C++03 compatible, it can execute tests in parallel (e.g., to take advantage of multi-core processors), and it is able to be run from the command line. But these are pretty broad requirements, and haven't narrowed down the field.

To try and do that, I'm looking into potential gotchas and pitfalls of different types of implementations. For example, if I wanted to use a unit testing engine in  higher level language like Python, would it still produce output formatted like C unit tests? My main intent here is to use the same storage and report tools for both C++ and Python results tests.

I'm also wondering if it's necessary to have a specific engine to run the tests, or is it enough to have them integrated into our continuous integration engine (buildbot).

Are these two concerns above valid? What else should I be concerned about when evaluating unit testing engines?

答:
I have used both Google Test and Boost Test.  Both are xUnit frameworks, work on Unix and Windows, and are mature.  I ended up using Google Test due to Google Mock since I wanted a mocking framework as well.  Either should work well under buildbot.

Personally, I want the unit test framework to be minimal and fast.  I want many tests and thus want them to run in a reasonable time frame.  I personally like to use the main framework for a language instead of a mega tool but that is personal.  If you wanted, you could look at continuous iteration testing: every time you save a file, it auto-runs the test cases that file depends on.

You could always write an Interface class to your unit test thus allowing a quick and effective change of frameworks.


问:
What's the benefit of avoiding the use of a debugger?
Over the course of my career, I've noticed that some developers don't use debugging tools, but do spot checking on erroneous code to figure out what the problem is.

While many times being able to quickly find errors in code without a debugger is a good skill to have, it seems it's less productive to spend a lot of time looking for issues when a debugger would easily find little mistakes like typos.

Is it possible to manage a complex without a debugger? Is it advisable? What benefits are there to be had by using "psychic debugging?"

答:
I Think they're being a bit too hardcore.
Personally when I run into a bug, I recheck the code, try to trace it in my mind from the program logic, because that sometimes helps me uncover other problems or side effects easier than just using the debbuger and fixing the bug where it manifests itself.

Even when I think I've nailed it, I usually debug it to make sure I'm right. When the problem is a bit more complex, I believe debugging is absolutely essential.

Also... just my opinion but, there is no excuse for not taking a decent advantage of the tools a modern IDE can bring to the table. If it helps you complete your job faster and in a more reliable way, you should use it.


答:
Hard to tell. Debugging by guessing might work if you already have an idea about what the bug is (incorrect value passed to a library function, possibly invalid SQL, etc). I admit I do it sometimes when the error itself seems small or obvious, such as "character buffer too small" - the stack trace shows me the line it failed and I don't need a debugger to solve that one.

Doing this all the time can be counterproductive and if the first few "guesses" fail, guessing is probably the wrong problem-solving strategy and a real debugger should be called in. Normally, I'd say there's absolutely nothing wrong with using the debugger.

That being said, I've worked with tools and environments where the debugger was so difficult to get working right, or so minimal and useless that guessing was unfortunately often a better approach. I've worked with some proprietary tools that didn't even have proper debuggers. I suppose it's possible that if a person worked in such environments too long they'd eventually lose their trust in debuggers and rely soley on the guessing approach.

Title: What's the benefit of avoiding the use of a debugger?

Body:
Over the course of my career, I've noticed that some developers don't use debugging tools, but do spot checking on erroneous code to figure out what the problem is.

While many times being able to quickly find errors in code without a debugger is a good skill to have, it seems it's less productive to spend a lot of time looking for issues when a debugger would easily find little mistakes like typos.

Is it possible to manage a complex without a debugger? Is it advisable? What benefits are there to be had by using "psychic debugging?"


问:
After writing code, why do I feel that "I would have written better" after some time?
I have been working on my hobby project in C++ for more than 2 years. Whenever I write a module/function, I code it with lot of thinking. Now see the problem,

```<code>do {
  --> write the code in module 'X' and test it
  --> ... forget for sometime ...
  --> revisit the same piece of code (due to some requirement)
  --> feel that "This isn't written nicely; could have been better"
} while(true);
</code>```

Here 'X' is any module (be it small/large/medium). I am observing that, this happens no matter how much effort I put while coding. So mostly, I refrain myself from seeing a working code. :)

Is this a common feeling for many people ? Is this language specific phenomena ? (Because in C++ one can write the same thing in different ways).

What should I do, if I get this re-factoring feeling for a real world production code, where changing the working code will not earn me much accolades but rather it may invite troubles if it fails.

答:
I get the same feeling whenever I read most code written by myself in the past. This is a good thing, it means that your knowledge and coding style has improved over the years.

As for changing working production code, that is a big no-no unless you have spotted obvious bugs. Not only because it might be a waste of time, but more importantly since the vast majority of software bugs created are of the kind that is introduced when changes are made to released programs. Statistically it is likely that you will introduce unforeseen bugs. If it ain't broken don't fix it.


答:
Yes, I've been in your situation.  In no way did we impose our choice on clients when that choice of analytics tool had implications for both privacy of data transfer and storage but also external/third-party use of the data.

Our legal counsel's recommendations (and you should absolutely check with yours) were the following:

tell clients what you're tracking

tell users what you're tracking (basic privacy policy & terms of use stuff)

make it clear who owns the data -- is it you? the client? does it depend on different parts of the application?

make it clear internally and to the client how that data will be used (here you get into issues of audit trails and compliance)

make it clear to the client how they can access their own data

store and manage the data in-house

I realize the last point is actually your question, but the lead-up is crucial (& did I mention you should really talk to your lawyer?).  We wanted more flexibility for reports and user access to those reports than just offline log analysis tools would offer.  Basically, we wanted the GA experience without GA.  We evaluated Open Web Analytics and Piwik and eventually went with Piwik.

Title: Google Analytics and customers privacy

Body:
I work in a company that sells SaaS web applications for HR and financial issues. Our customers are key accounts to which we guarantee the privacy of their data, for obvious reasons.

We need to make usage statistics of our applications by its customers (which links are clicked the most? Which browsers are used the most? What is the average screen resolutions? etc). I personally use Google Analytics on my sites. GA is a very powerful and complete solution for this. But it raises questions of privacy.

Have you already had this problem?

Were you able to impose on your customers? how?

If not, did you use an alternative? or did you develop your own measurement tools of statistics?


问:
What are the best-practice / norms to order functions in files or classes?

Possible Duplicate:

  How do you normally layout a class's regions?

It often happens that I'm stuck in front of my code editor searching the best place to put a new function.

I've no norm nor rules to do that. My question is simple : does some exists, if not how would order your function to structure your files or classes : by type (private, public, ...), by relations or by something else ?

答:
Honestly, I don't think this matters too much. Most modern IDE's will give you a listing on some panel somewhere of your function and you can usually choose multiple sort orders, includes alphabetic, scope (public/private/etc...) or as-is in the file.

If you are putting a lot of effort into this, relax! It's not worth it. The only place it might matter is languages where private functions must be delcared before they can be used. or maybe some tool/IDE that doesn't give you any nice and sorted file outline.

If you don't want to rely on your tools/IDEs, I sometimes do the layout by type (such as member variables, structs/user-defined-types, properties, functions, methods) and then by scope. Also, I tend to put the constructors (public OR private) right before the first public method. When there's overloads, I list them in order of the fewest arguments to most. So it might go something like this;

private member

protected member

private type

public type

protected enum

private function

public constructor

public property

public function

I don't know exactly where I picked this method up over the years, but I see similar layouts often in other people's code. I don't always strictly enforce it because sometimes it's just easier to use tools to navigate my code.


问:
Which websites to use for presenting free open source applications?
After releasing a new free open source application, I would like to present it to as many people as possible.

What are web sites (directories) which one should use to present free open source applications?

Looking for a list of sites like Freshmeat, Sourceforge, ...

答:
if you're going to release a web based application like an e-commerce, CMS or blog of sorts, you could try to get it on opensource cms, http://www.opensourcecms.com/ i love to use this site to quickly showcase forum and ecommerce alternatives :)

take care with the ratings though , they are not really impartial.


答:
Any job requires using the right tools the right way. If you have a debugger then use it to see what is actually happening. Most bugs are caused by assumptions.

I've worked with developers who refuse to use debuggers because they knew better. The classic response I got once was 'the crash isn't being caused by me, I spent all day inspecting the code [where it was crashing] and there's nothing wrong'. (What about that null value that was read in from the db?) The boss seemed to think it was a great reply but the customer didn't.

I got off that team as fast as I could. Their purpose was to featherbed the job and make a simple 10 minute problem into an all-day-looking-busy problem.


答:
They may not be bad programmers, but they are probably terribly inefficient troubleshooters.

I tend to follow the advice from Debugging: The 9 Indispensable Rules for Finding Even the Most Elusive Software and Hardware Problems (David Agans), and this one falls squarely under the guidance of "Quit thinking and look"


答:
The more I know a code base, the less I need a debugger (but I'd still check the reported error, it is an important clue in any reasoning).

It is a fine tool to understand some dynamic behavior of small to medium complexity, but I often find out that it focus me on the details instead of the bigger picture. And after a while, that's where the problems are: in wider scope interactions whose dynamic behavior tend to be more easily understandable with other tools (logging of input and outputs at module boundaries for instance).


问:
Who does test-driven development?
I've been working in the enterprise space for the past 4½ years and have noticed that generally speaking, enterprises are not conducive environments for the test-first style of development. Projects are usually fixed-cost, fixed-timeline and waterfall style. Any unit testing, if done at all, usually comes after development in the QA phase and done by another team.

Prior to working for an enterprise, I consulted for many small to medium sized companies, and none of them were willing to pay for a test-first style of development project. They usually wanted development started immediately, or after a short design stint: i.e., something more akin to Agile, though some clients wanted everything mapped out similar to waterfall.

With what types of shops, companies, and clients does test-driven development work
best? What types of projects tend to be conducive to TDD?

答:
I do, but generally only for non ui components, and when I know I cannot keep the whole algorithm for a module in my head at a single time, or when it the module is a new part of whatever system I'm working on, so I can't rely on the majority of libraries I'm using to have have the been highly debugged.

Essentially, I do when the complexity of requirement means I could otherwise get lost in the code.

It is a difficult habit to start, and does require management buy-in, but, when your tests start breaking half way through development, it can be a life saver!

Title: Who does test-driven development?


答:
Debugging is just a tool that a good developer should use proficiently.

Certainly sometimes you can know by heart where the bug can be if you know the code base. But you can also lose an entire day or week to find a pesky bug just by looking into the code.

In dynamically typed languages without some kind of debugging (even if it's just dumping values to the console) guessing sometimes becomes impossible.

So to answer your question - maybe they are brilliant programmers, but their troubleshooting skills and their proficiency when hunting bugs are bad.


答:
What looks like guessing from the outside often turns out to be what I call "debugging in your mind". In a way, this is similar to grandmasters' ability to play chess without looking at a chess board.

It is by far the most efficient debugging technique I know, because it does not require a debugger at all. Your brain explores multiple code paths at the same time, yielding better turnaround than you could possibly get with a debugger.

I was not conscious about this technique before briefly entering the world of competitive programming, where using a debugger meant losing precious seconds. After about a year of competing, I started using this technique almost exclusively as my initial line of defense, followed by debug logging, with using an actual debugger sitting at the distant third place. One useful side effect of this practice was that I started adding new bugs at a slower pace, because "debugging in my mind" did not stop as I wrote new code.

Of course this method has its limitations, due mostly to the limitations of one's mind at visualizing multiple paths through the code. I learned to respect these limitations of my mind, turning to a debugger for fixing bugs in more advanced algorithms.


答: Use the debugger whenever possible. The debugger will either simply nail the issue (oh look, we didn't check for this value), or provide a great deal of context that is useful when analyzing the relevant code (wow, the stack is totally messed up, I'll be it's a buffer overflow issue).</p>


问:
Should I be wary of signing a non-disclosure agreement with someone I just met?
1/22/12 update in case you were puzzled as to why I haven't accepted an answer: Pretty much all of the answers make the obvious point that working for him would have been silly, but none of them seemed to answer the question.

tl;dr: Some guy I just met says he wants me to join his company. Before he shows me what they do, he wants me to sign a non-disclosure agreement. Is this weird?

I'm traveling right now. Someone who saw me coding seemed to think I was smart or something and started talking with me. He explained that he owns a software company, told me a bit about what it does and told me that he was looking for a programmer who would work for a stake in the company. He explained that the company's product is being developed rather secretly, so he couldn't tell me much. But he did tell enough about the product to convince me that he's not completely making this up, which is a decent baseline.

He suggested that he show me more of what he's been working on and, after seeing that, I decide whether I want to join. Because of the secrecy behind the product, he wants me to sign a non-disclosure agreement before we talk.

I'm obviously somewhat skeptical because of the random nature by which we met.

In the short term, I'm wondering if I should be wary of signing such an agreement. He said it would be easier to show me the product in person rather than over the internet, and I'm leaving town tomorrow, so I'd have to figure this out by tomorrow. If I decide to talk with him, I could decide later whether I trust that it's worth spending any time on this company.

The concept of being able to avoid telling a secret seems strange to me for the same reason that things like certain aspects of copyright seem strange. Should I be wary of signing a non-disclosure agreement? Is this common practice?

I don't know the details of the agreement of which he was thinking, (If I end up meeting with him, I'll of course read over the agreement before I decide whether to sign it.) so I could consider alternatives according to the aspects of the agreement. Or I could just consider the case of an especially harsh agreement.

This question seems vaguely related.
Do we need a non-disclosure agreement (NDA)?

Thanks

答:
Yes Sign it:

What is the worst that could happen if you sign?

You can't tell anyone about it.

What is the worst that could happen if you don't sign?

He will not let you work on this project.

based on the above, regardless of circumstances you met him, its not unreasonable.

That individual believes he has something of value, but wants to make sure its protected.


问:
How do you describe the way LinkedIn handles URL links?
I'm trying to figure out what all is happening in the LinkedIN links URL. A link from LinkedIN community opens with a window shade (?) containing the LinkedIN site tools much like the alerts here at SE. The target link is embedded in a LinkedIN url as a GET variable.

This is a LinkedIN link in three parts (the middle part is the target URL),

http://www.linkedin.com/news?viewArticle=&articleID=5567246644694487049&gid=87719&type=member&item=90729979&articleURL=+

http%3A%2F%2Fwww.nypl.org%2Fblog%2F2011%2F03%2F24%2Fprecarity-readers-guide
+

&urlhash=mQ1h&trk=group_most_recent_rich-0-b-shrttl

What is this GUI widget I called "window shade" commonly referred to
as?

What is the technical code reference?

What is the term I can use to describe the way LinkedIN uses GET
data?

答:
1.) I would consider that some kind of notification bar. But I'm not sure if that is commonly what it is referred as.

2.) This would be implemented using javascript and css. You make a div and give it a class name and when an event triggers then you would use the javascript to show that div and have a link on the div that would trigger javascript to hide the div.

3.) The way that LinkedIn uses GET data is called using the Query String. One thing to note is that it can expose some security problems since it is easily editable by the user.

EDIT in response to xtian's comment:

So, what is happening in the link is that LinkedIn is redirecting to whatever is the articleURL. Chances are that it is performing some sort of database queries off of the article ID and the gid to ensure that the link is valid (and possibly perform analytics for the link) and then it just redirects to the articleURL.

It could be as simple as just calling:

```<code>window.location.href=$ArticleURL
</code>```

from a javascript function, where $ArticleURL is the articleURL from the Query String.

I hope that clears things up. If not, let me know and I'll try to expand more.

Body:
1.) I would consider that some kind of notification bar. But I'm not sure if that is commonly what it is referred as.

2.) This would be implemented using javascript and css. You make a div and give it a class name and when an event triggers then you would use the javascript to show that div and have a link on the div that would trigger javascript to hide the div.

3.) The way that LinkedIn uses GET data is called using the Query String. One thing to note is that it can expose some security problems since it is easily editable by the user.

EDIT in response to xtian's comment:

So, what is happening in the link is that LinkedIn is redirecting to whatever is the articleURL. Chances are that it is performing some sort of database queries off of the article ID and the gid to ensure that the link is valid (and possibly perform analytics for the link) and then it just redirects to the articleURL.

It could be as simple as just calling:

window.location.href=$ArticleURL

from a javascript function, where $ArticleURL is the articleURL from the Query String.

I hope that clears things up. If not, let me know and I'll try to expand more.


问:
Why use try … finally without a catch clause?
The classical way to program is with try ... catch. When is it appropriate to use try without catch?

In Python the following appears legal and can make sense:

```<code>try:
  #do work
finally:
  #do something unconditional
</code>```

However, the code didn't catch anything. Similarly one could think in Java it would be as follows:

```<code>try {
    //for example try to get a database connection
}
finally {
  //closeConnection(connection)
}
</code>```

It looks good and suddenly I don't have to worry about exception types, etc. If this is good practice, when is it good practice? Alternatively, what are the reasons why this is not good practice or not legal? (I didn't compile the source. I'm asking about it as it could be a syntax error for Java. I checked that the Python surely compiles.)

A related problem I've run into is this: I continue writing the function/method, at the end of which it must return something. However, it may be in a place which should not be reached and must be a return point. So, even if I handle the exceptions above, I'm still returning NULL or an empty string at some point in the code which should not be reached, often the end of the method/function. I've always managed to restructure the code so that it doesn't have to return NULL, since that absolutely appears to look like less than good practice.

答:
The finally block is used for code that must always run, whether an error condition (exception) occurred or not.

The code in the finally block is run after the try block completes and, if a caught exception occurred, after the corresponding catch block completes. It is always run, even if an uncaught exception occurred in the try or catch block.

The finally block is typically used for closing files, network connections, etc. that were opened in the try block. The reason is that the file or network connection must be closed, whether the operation using that file or network connection succeeded or whether it failed.

Care should be taken in the finally block to ensure that it does not itself throw an exception. For example, be doubly sure to check all variables for null, etc.


答:
It depends on whether you can deal with the exceptions that can be raised at this point or not.

If you can handle the exceptions locally you should, and it is better to handle the error as close to where it is raised as possible.

If you can't handle them locally then just having a try / finally block is perfectly reasonable - assuming there's some code you need to execute regardless of whether the method succeeded or not. For example (from Neil's comment), opening a stream and then passing that stream to an inner method to be loaded is an excellent example of when you'd need try { } finally { }, using the finally clause to ensure that the stream is closed regardless of the success or failure of the read.

However, you will still need an exception handler somewhere in your code - unless you want your application to crash completely of course. It depends on the architecture of your application exactly where that handler is.

Title: Why use try … finally without a catch clause?

Body:
The classical way to program is with try ... catch. When is it appropriate to use try without catch?

In Python the following appears legal and can make sense:

```<code>try:
  #do work
finally:
  #do something unconditional
</code>```

However, the code didn't catch anything. Similarly one could think in Java it would be as follows:

```<code>try {
    //for example try to get a database connection
}
finally {
  //closeConnection(connection)
}
</code>```

It looks good and suddenly I don't have to worry about exception types, etc. If this is good practice, when is it good practice? Alternatively, what are the reasons why this is not good practice or not legal? (I didn't compile the source. I'm asking about it as it could be a syntax error for Java. I checked that the Python surely compiles.)

A related problem I've run into is this: I continue writing the function/method, at the end of which it must return something. However, it may be in a place which should not be reached and must be a return point. So, even if I handle the exceptions above, I'm still returning NULL or an empty string at some point in the code which should not be reached, often the end of the method/function. I've always managed to restructure the code so that it doesn't have to return NULL, since that absolutely appears to look like less than good practice.


答:
Catching errors/exception and handling them in a neat manner is highly recommended even if not mandatory.

The reason I say this is because I believe every developer should know and tackle the behavior of his/her application otherwise he hasn't completed his job in a duly manner. There is no situation for which a try-finally block supersedes the try-catch-finally block.

I will give you a simple example: Assume that you have written the code for uploading files on the server without catching exceptions. Now, if for some reason the upload fails, the client will never know what went wrong. But, if you have caught the exception, you can display a neat error message explaining what went wrong and how can the user remedy it.

Golden rule: Always catch exception, because guessing takes time


问:
What is the name of ** in python?
When programming Python I sometimes do a ** to make a conversion. I understand what it does but what data structures am I manipulating? A dict and what is the other? An array? Is there a name for the ** operator?

答:
I don't think it has a name. In the Python Docs under "Unpacking Argument Lists", it's just referred to as "the **-operator."

I'm not sure what you mean by "the other" data structure. When you do f(**kwargs) you unpack the dictionary kwargs as a sequence of key-value pairs. I don't see that there's another structure involved.

I'll copy the example in the above documentation for clarity.

```<code>>>> def parrot(voltage, state='a stiff', action='voom'):
...     print "-- This parrot wouldn't", action,
...     print "if you put", voltage, "volts through it.",
...     print "E's", state, "!"
...
>>> d = {"voltage": "four million", "state": "bleedin' demised", "action": "VOOM"}
>>> parrot(**d)
-- This parrot wouldn't VOOM if you put four million volts through it. E's bleedin' demised !
</code>```

See also: What does *args and **kwargs mean?

Title: What is the name of ** in python?

Body:
I don't think it has a name. In the Python Docs under "Unpacking Argument Lists", it's just referred to as "the **-operator."

I'm not sure what you mean by "the other" data structure. When you do f(**kwargs) you unpack the dictionary kwargs as a sequence of key-value pairs. I don't see that there's another structure involved.

I'll copy the example in the above documentation for clarity.

>>> def parrot(voltage, state='a stiff', action='voom'):
...     print "-- This parrot wouldn't", action,
...     print "if you put", voltage, "volts through it.",
...     print "E's", state, "!"
...
>>> d = {"voltage": "four million", "state": "bleedin' demised", "action": "VOOM"}
>>> parrot(**d)
-- This parrot wouldn't VOOM if you put four million volts through it. E's bleedin' demised !

See also: What does *args and **kwargs mean?


问:
design pattern for describing a variable subpart of a config file
Suppose I have an XML config file like the following:

```<code><myapp>
    <settings/>

    <output>

        <mailto>mail service configuration parameters</mailto>
                           OR
        <smsto>sms service configuration parameters</smsto>

    <output>
</code>```

While the settings node will have always the same structure, the output node may have different structures, depending on whether it is a mail or an SMS output.

The Java classes will be:

```<code>class MyAppConfig {

    String settingXXX;

    {what type?} output;

}
</code>```

Obviously I will have a class MailTo {} and a class SmsTo {}.

Since output may either be a MailTo or a SmsTo object, it can be:

an Object type, since MailTo and SmsTo don't have any superclass in
common.

an Output interface, that in turn is implemented by MailTo and
SmsTo. Since MailTo and SmsTo don't have anything in common, Output interface will be empty and will "collapse" to a marker interface.

I think that, given this situation, this is the only implementation possible.

The client code will typecast Object or Output to MailTo or SmsTo, that must be handled differently.

Nevertheless, I'm puzzled because design patterns (GoF book) seem not consider this kind of situations.

What is the "real world" pattern that you would apply in this case?

答: Your question looks like a textbook example of the benefits of polymorphism, I don't think there is a named pattern to implement this functionality as this is a fairly basic OO principle.  Your idea to create an interface for both classes to implement is the best idea allowing you to call myInterface.doStuff to handle both types of communication and allow for more to be added if necessary.</p>


问:
I'm working on a PaaS similar to Heroku or Google App Engine, and was curious which pricing structure users prefer. Ideas?
My current project is a cloud deployment platform similar to GAE or Heroku. I'm trying to figure out what pricing method works best for us and the users. Assuming that I cannot currently provide a free plan, here are the options:

1) Have fully unlimited scaling (GAE-like), and charge for usage ($5 per project + x cents per CPU hour the project uses on our system, also charge a certain amount for bandwidth in/out, database storage + I/O, r/w data store, memcached, etc.)

This ends up being cheaper (around $20 for a moderately loaded website) and more "fair" for the user (pay only for what you use), but much more complicated with the many different factors that affect final price. This type of architecture is more resilient to what you throw at it, so if you get a traffic spike, it will work perfectly fine, you'll just get charged more.

2) Pay for "application readiness"/specific scalability (have a specific amount of processes per user available to accept requests, maybe $20 a month (3 cents per hour) per process), and for a specific tier of a database. No bandwidth/IO charges (within fair use, of course). Add-ons like email and memcached are extra. (Heroku-like)

This option is a lot more simple, and much easier to project costs on. However, the pricing curve is rather steep. You do end up likely paying more (probably $40-$60 a month for a moderately-loaded website), but all of those miscellaneous costs are completely abstracted.

Which would you more likely pay for? Also, is there another option I may be overlooking?

答:
I realized I can't go with infinite autoscaling because that would require a very large amount of idle servers on hand, which I can't provide at this point. Google has a large amount of slack capacity on their servers, so they can easily do so.

Here's what I will probably end up going with:

Each user pays a few cents (around 2-3) an hour per instance that they have running. There will be an autoscaling option in place (user can set the maximum the platform can increase the running processes to in times of high load). By default, each project will get bandwidth, disk storage, memcached, and a database (at no additional cost). If the project needs more, they can upgrade each of those components at a reasonable rate. Also included would be cron, web-based monitoring, mobile apps, alerting, development/staging environment, backups, redundancy, failover and so on, all as part of the service. Sounds fair?


答:
I think the direction should be a Creational Pattern, page 33 in GoF book presents a help table for building a variable design. From the page:

```<code>Design Pattern         Aspect(s) That Can Vary
--------------         -----------------------
Abstract Factory (68)  families of product objects
Builder (75)           how a composite object gets created
Factory Method (83)    subclass of object that is instantiated
Prototype (91)         class of object that is instantiated
</code>```

From this table, Prototype seems to fit the best it basically lets you to

specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.

EDIT: nice detailed info here: http://sourcemaking.com/design_patterns/prototype

Please elaborate on your problem if this design is not enough...

Title: design pattern for describing a variable subpart of a config file

Body:
Suppose I have an XML config file like the following:

```<code><myapp>
    <settings/>

    <output>

        <mailto>mail service configuration parameters</mailto>
                           OR
        <smsto>sms service configuration parameters</smsto>

    <output>
</code>```

While the settings node will have always the same structure, the output node may have different structures, depending on whether it is a mail or an SMS output.

The Java classes will be:

```<code>class MyAppConfig {

    String settingXXX;

    {what type?} output;

}
</code>```

Obviously I will have a class MailTo {} and a class SmsTo {}.

Since output may either be a MailTo or a SmsTo object, it can be:

an Object type, since MailTo and SmsTo don't have any superclass in
common.

an Output interface, that in turn is implemented by MailTo and
SmsTo. Since MailTo and SmsTo don't have anything in common, Output interface will be empty and will "collapse" to a marker interface.

I think that, given this situation, this is the only implementation possible.

The client code will typecast Object or Output to MailTo or SmsTo, that must be handled differently.

Nevertheless, I'm puzzled because design patterns (GoF book) seem not consider this kind of situations.

What is the "real world" pattern that you would apply in this case?

Body:
I think the direction should be a Creational Pattern, page 33 in GoF book presents a help table for building a variable design. From the page:

Design Pattern         Aspect(s) That Can Vary
--------------         -----------------------
Abstract Factory (68)  families of product objects
Builder (75)           how a composite object gets created
Factory Method (83)    subclass of object that is instantiated
Prototype (91)         class of object that is instantiated

From this table, Prototype seems to fit the best it basically lets you to

specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.

EDIT: nice detailed info here: http://sourcemaking.com/design_patterns/prototype

Please elaborate on your problem if this design is not enough...


问:
Java GNU Licensing

Possible Duplicate:

  Can we use Java for commercial use?

I am a college student learning how to program in Java. I really like Java's simiplicity and portability and I would like to one day develop a commercial application in Java. What I am trying to understand is Java's GNU license.

With the recent litigation between Java and Google, I am a little bit skittish on developing any commercial applications in Java. As I understand it, I can only release my Java programs under the GNU license and I must release the source code. Do I have to buy a license from Sun to develop and release commercial applications in Java?

答:
Simple answer:

NO ! You don't have to buy any license from anyone

and this is why: It is true that Java is open source (till you try to modify the language itself) but you can copyright all the custom source code you have written. GNU license (now BCL under Oracle) is only for source code of the language itself and not for application specific java code you have written.

Related answer : Can we use Java for commercial use?

Title: Java GNU Licensing


答: I agree with Ryathal that this is basic polymorphism and therefore you will not find a design pattern for it.  Although you could use something like a factory pattern to create the appropriate class based on the configuration settings.  I disagree that the email and sms service do not have anything in common.  The base class could be something like "communications service" and these services would always have a location for the service (ex: smtp server location or url for web service or API) and some credentials for authentication.  The "email" class and "sms" class would inherit from the "communications service" class.  The method for sending a message would differ in the derived classes.</p>


答:
It's not an operator as such, so it doesn't really have a name, but it is defined as a "syntactic rule". So it should be called:

"the keyword argument unpacking syntax"

If you have a list of arguments, *args, it's called "argument unpacking", in the same manner **kwargs is called "keyword argument unpacking".

If you use it on the left hand side of an =, as in a, *middle, end = my_tuple, you'd say "tuple unpacking".

In total, there are three types of (single parameter) arguments:

```<code>def f(x)  # x: positional argument
def f(x, y=0)  # y: keyword argument
def f(x, *xs, y=0)  # y: keyword-only argument
</code>```

The *args argument is called the "variable positional parameter" and **kwargs is the "variable keyword parameter".
Keyword-only arguments can't be given positionally, because a variable positional parameter will take all of the arguments you pass.

Most of this can be found in PEPs 0362 and 3102, as well as in the Control Flow section of the docs. It should be noted though that the function signature object PEP is only a draft, and the terminology might just be one person's idea. But they are good terms anyway. :)

So the * and ** arguments just unpack their respective data structures:

```<code>args = (1, 2, 3)  # usually a tuple, always an iterable[1]

f(*args) → f(1, 2, 3)

# and

kwargs = {"a": 1, "b": 2, "c": 3}  # usually a dict, always a mapping*

f(**kwargs) -> f(a=1, b=2, c=3)
</code>```

[1]: Iterables are objects that implement the __iter__() method and mappings are objects that implement keys() and __getitem__(). Any object that supports this protocol will be understood by the constructors tuple() and dict(), so they can be used for unpacking arguments.

Title: What is the name of ** in python?

Body: When programming Python I sometimes do a ** to make a conversion. I understand what it does but what data structures am I manipulating? A dict and what is the other? An array? Is there a name for the ** operator?

Body:
It's not an operator as such, so it doesn't really have a name, but it is defined as a "syntactic rule". So it should be called:

"the keyword argument unpacking syntax"

If you have a list of arguments, *args, it's called "argument unpacking", in the same manner **kwargs is called "keyword argument unpacking".

If you use it on the left hand side of an =, as in a, *middle, end = my_tuple, you'd say "tuple unpacking".

In total, there are three types of (single parameter) arguments:

def f(x)  # x: positional argument
def f(x, y=0)  # y: keyword argument
def f(x, *xs, y=0)  # y: keyword-only argument

The *args argument is called the "variable positional parameter" and **kwargs is the "variable keyword parameter".
Keyword-only arguments can't be given positionally, because a variable positional parameter will take all of the arguments you pass.

Most of this can be found in PEPs 0362 and 3102, as well as in the Control Flow section of the docs. It should be noted though that the function signature object PEP is only a draft, and the terminology might just be one person's idea. But they are good terms anyway. :)

So the * and ** arguments just unpack their respective data structures:

args = (1, 2, 3)  # usually a tuple, always an iterable[1]

f(*args) → f(1, 2, 3)

# and

kwargs = {"a": 1, "b": 2, "c": 3}  # usually a dict, always a mapping*

f(**kwargs) -> f(a=1, b=2, c=3)

[1]: Iterables are objects that implement the __iter__() method and mappings are objects that implement keys() and __getitem__(). Any object that supports this protocol will be understood by the constructors tuple() and dict(), so they can be used for unpacking arguments.


问:
Dual licensing with GPL library
I have a question concerning derivative works of GPL'ed software. Imagine the following situation: A company writes a software (A) using a library (B) which is released under the terms of the GPL. Now of course, software (A) has to be released under a compatible license to the GPL. But what about dual-licensing? If software (A) is released under two licenses, GPL and a commercial one, is this in violation with the terms of library (B)?

To rephrase the question, does the GPL force exclusivity for derivative works?

答:
Does the GPL force exclusivity for derivative works?

Yes, but the key is the definition of derivative.

The license of library (B) only comes into play if you distribute library (B) with software (A). If you release your software (A) independently of library (B) you can do whatever you want with it (though I guess making the library optional would limit the fnctionality of the software when not compiled with the library).

As such, you could release software (A) under GPL, bundled with library (B).

You could also, since you are copyright holder over software (A), release it under whatever other licenses you prefer. But in those cases your customers would have to download library (B) and compile it into your software themselves.

A better solution overall though, would be to ask the copyright owners of library (B) to offer it with a dual licenses themselves. Offering Lesser GPL could encourage commercial support for developing the library and the option of a commercial license could bring in money to support the community in lieu of contributing code back to the project.

OwnerDisplayName: lucas clemente

Title: Dual licensing with GPL library


问:
How to introduce a new pattern into an existing codebase?
In my quest to better my development skills I learn new design patterns. In sample projects or personal projects it's really easy to adapt new patterns into my code.

However at work I have a large code base that I am responsible for architecting and maintaining. This question is focused on writing consistent and maintainable code will still providing business value.

When I learn new patterns I find myself conflicted on how to proceed moving forward on an existing codebase.

Do I go back update my code to use my new pattern ?

This has the downside of not providing a ton of business value and
might not be the best way to efficiently utilize my time.

Do I move forward and use my new pattern/technique in any new code ?

This has the downside of being inconsistent, thus making my code less maintainable and setting a poor precedent for new team members.

Optionally I could just catalog the new technique in my head but not implement it. I really dislike this option though.

答: First, find a section of code that would greatly benefit from going from a group of adhoc functions to a better defined pattern. Then, wait until you can make a concrete case that the amount of time saved in terms of future bug fixes or upcoming feature additions will outweigh the time necessary to redesign the code. Just keep in mind that there might be a lot of cases where the existing code is good enough and the rewrite is never justified.</p>


问:
How to make code writing more accurate?
I am trying to practice writing code for a long period of time before compiling and write unit test (if possible) for what I wrote (the language is C++). Of course, I got the IDE support (Emacs or Eclipse for on the fly error detection and code completion) with minimal or no error. I practice this ability because the pattern "trial and error" in which a bit of code is written and then build/run to check the correctness is not productive as I feel.

However, isn't what I am doing counter the purpose of testing? Maybe, the point of my practice is not to assure 100% logic correctness, but rather, 100% or close to 100% syntax correctness, in order to vastly improve productivity. I will try to practice with the small piece of code first, and then improve gradually as time passes.

What's your opinion on code writing and productivity in general? Do you practice like I do or do you have much better method? (Aside from being in the "flow", or extremely concentration). I concern this matter because I heard that some people are an actual human compiler, and it seems like they can directly translate the logic to code as their natural language.

Edit: I was a bit wrong when I mentioned not to improve logical correctness. Yes, logical correctness counts as well. What I want is to practice programming to the point where I can keep writing code for a long period of time with minimal mistakes (such as I can write 1000 lines of code,a and only a few trivial errors occur).In case of C++ or any language, using external libraries require you to understand many dependencies of the libraries to use it correctly in your code. For example, if you use Spring framework in Java, you have to make sure the xml, the server etc... are set up correctly. I consider this is also a form of syntax, and one way to achieve "syntax correctness" is to practice it frequently to the point when you can minimize the most mistakes written by hands. This is similar to when we first start learning programming, sometimes/often we miss the semicolon. Then we learn the mistake and improve it.

答:
I've found if that if I know the resources/tools/classes I'm using, I can write whole large programs without trying anything.  (These new-fangled IDE's that point out your mistakes instantly do help a lot.)  And the program usually works as intended, too.  (Okay, after a few NullPointerExceptions are fixed.)  Whether my intent was any good is quite a different question, but I needed to run the whole program to find that out anyway.

But when I don't know for sure how the tools work, or how it's going to look to the user, I'm always testing things.  When I'd never used a socket before, I wanted to see data flow before I wrote 1000's of lines of code on the assumption it would.  And I have never gotten comfortable with graphics.  For me graphics code is endless short cycles of change a bit of the code, try it, change the code, try it,....

I don't think I'm trying to write lots of code without testing it.  I'm just trying to spec out the program.  I could do it in English, or pseudo-code, or in diagrams.  I prefer, these days, Java or C#.  That way, when I've got my program thoroughly specced, it's ready to be shipped.  Er, I mean I can test and check the design.

I've always felt a bit like Wile E. Coyote.  I code flat out, but I've become extremely sensitive to that feeling you get when you're standing on thin air.  The trick is to get back to solid ground--test the code--before gravity kicks in.  I'm better at this than Wile E. was.

Interestingly, most of large chunks of bad code I've had to throw away I tossed long before I ever tested them.  They resulted from flaws in my design that became obvious when I tried to code the details.

In your case, just do what you're comfortable with.  If your tests aren't telling you anything interesting, start skipping them.  If you finish a big program that depends on the OS doing five key things for you, and it turns out the OS can't do any of them--well, test a bit more in the future.  Trying to push yourself in either direction is a bad idea.

I think I'm disagreeing somewhat with DXM here, but if he hadn't written it already I'd finish with his last paragraph ("As far as training yourself to make less mistakes...").

Title: How to make code writing more accurate?


答: Any good design pattern should provide business value.  Now it may not be business value in the sense of new features, but it should provide value in reducing maintenance costs through easier to understand code, separation of concerns (decoupling) to make the code less fragile to change, and more scalable.  The less time spent on maintenance allows for more time in feature enhancements.  Pick areas of the code that could benefit the most from refactoring and implementing new design patterns first.  This will be an ongoing process that should not be tackled all at once and handled as one massive project.  I would not hesitate to use design patterns in new code where you can learn more about actually implementing them and which ones actually provide value.  So the short answer is yes to both.  </p>

Title: How to introduce a new pattern into an existing codebase?

Body:
In my quest to better my development skills I learn new design patterns. In sample projects or personal projects it's really easy to adapt new patterns into my code.

However at work I have a large code base that I am responsible for architecting and maintaining. This question is focused on writing consistent and maintainable code will still providing business value.

When I learn new patterns I find myself conflicted on how to proceed moving forward on an existing codebase.

Do I go back update my code to use my new pattern ?

This has the downside of not providing a ton of business value and
might not be the best way to efficiently utilize my time.

Do I move forward and use my new pattern/technique in any new code ?

This has the downside of being inconsistent, thus making my code less maintainable and setting a poor precedent for new team members.

Optionally I could just catalog the new technique in my head but not implement it. I really dislike this option though.