问:
How to gain understanding of large systems?

Possible Duplicate:

  How do you dive into large code bases?

I have worked as a developer developing C/C++ applications for mobile platforms (Windows Mobile and Symbian) for about six years. About a year ago, however, I changed job and currently work with large(!) enterprise systems with high security and availability requirements, all developed in Java. My problem is that I am having a hard time getting a grip on the architecture of the systems, even after a year working with them, and understanding systems other people have built has never been my strong side. The fact that I haven't worked with enterprise systems before doesn't exactly help.

Does anyone have a good approach on how to learn and understand large systems? Are there any particular techniques and/or patterns I should read up on?

答:
Personally I don't think anything beats just slogging through the code and learning it. There is not quick way to understand. When I go to a new job, I spend a week, doing almost nothing but understanding the design of the database (I'm a database specialist). If diagrams don't exist, I make them. I track things through from the top level of the queries all the way to the tables. I ask questions when something doesn't make sense. I look for the most critical of the queries to understand first (usually the search queries, they will give you a really good idea of the most important tables.). If possible get someone with some expertise to sit down with me for a good half a day and show me what he knows.

Since you are way past your first week (when it is easier to get this time) this is harder. But start with one module you have worked on or are getting ready to work on and read the code, following the paths in the code until you have gone down to the lowest level. Make notes.  Make diagrams if you need to. Just work through one section at a time, but go through it thoroughly. Try to find someone who worked on the design to understand the design choices. Often they chose what was best at the time they did the design but something which five years later looks pretty awful to you. It helps to understand the constraints that caused the design to be the way it is.

Enterprise applications tend to be heavily database centric. Make sure to take the time to understand the database design as well as the structure of the application.

Are there requirements documents from the orginal design on out? Take the time to read some of them.

It is never easy to understand a large Enterprise system. There are alot of different little designs at different time periods involved in it so there is often very little consistency. It is likely that no one on the team understands the whole system completely. If you do have someone who is the acknowldeged expert in the system, listen to him or her very carefully, ask lots of questions, ask why they made the choices they did.  BUt do it respectfully, nothing will shut the expert onteh system up faster than asking questions in a way that makes them feel defensive. While you may or may not agree with all the choices they made (about a 100% chance you won't agree with all of them in my experience) at least understanding the whys helps you start to see the pattern of how this group of people approach design which will clue you in to how they did the next thing you look at as well.


问:
Tips for going from personal projects to enterprise scale projects
I wanted to know if anyone had any tips for transitioning from small personal projects and coursework, to a large enterprise scale project?

Im in my second year at university and have attained a placement with a large tech company, to work on a pretty large project, I'm just a little apprehensive about 'finding my way around' such a large project.

答: Learn about source control, and how to follow 'house style' if there is one, i.e. don't fight the man if the man wants you to use tabs over spaces, put in or leave out semicolons, and so on.</p>

ContentLicense: CC BY-SA 3.0


问:
Should large or old codebases be expected to be easy to navigate?
I'm an Undergraduate Computer Science Student currently on a placement year at a company that produces and supports a large enterprise web application. I'm loving the experience of seeing how software is produced in the real world, and feel very lucky to find a company that offers a chance to not only maintain and extend existing functionality but also develop entirely new features for the product.

All that said, though, I'm very conscious that this is very, very unlikely to be a perfect example of how to develop correctly. Far from it, in fact. I feel I'm learning a massive amount from my experience here, and I don't want to learn the wrong things or pick up bad habits from colleagues that could be hard to shake off further down the road. Mostly it's easy to tell what's good and what's not - for example the Unit Test coverage here is practically non-existent for various reasons (mostly poor excuses mixed in with one or two valid points). Lately, though, I've been noticing a regular occurrence that I'm just not sure about.

Whenever we start a new project, naturally we need to find any relevant code that needs to be extended, altered, or removed. It seems to me that, the vast majority of the time, anything not within the most commonly used sections of the application takes people an age to find within the codebase. There are one or two tech leads who know their section of the code well, but even they get stumped sometimes and have to spend a long time searching for what they require, or turn to someone who has been editing that part of the code recently (if anyone) for help. When I say a long time, I don't mean hours (usually) but it seems to me that a good codebase would be navigable to any point within a few minutes at worst, to anyone even vaguely familiar with the system.

So, my question. Is the above problem due to poorly structured code? Alternatively, is it down to developers not having enough knowledge of the codebase? Or is it simply unavoidable in large applications, regardless of how much work goes into keeping the file structure clear?

Or, indeed...am I just wasting my time on a topic that really doesn't matter?

答:
Large code bases aren't designed, they evolve.  A lot of things that don't make sense when looking at a current snapshot, make perfect sense when you take history into account.  And I don't just mean the individual history of the code base, I also mean the history of software engineering practices in general.

Unit testing pretty much always existed to some degree, but didn't really come into widespread usage until extreme programming and test driven development were "invented," around the years 1999 to 2003.  A lot of code bases predate that, and consequently were not designed in a manner that made unit testing easy.

There is similar history behind other software engineering practices.  For example, the DVCS revolution of 2005 changed the way people think about workflows and branching models, even with non-distributed version control.  For another example, even though it existed, almost no one had heard of the MVC design pattern until Microsoft created a framework with that name, and now failure to separate model and view is much more highly discouraged than it used to be, even in projects that don't use Microsoft's framework.

Creation and popularization of online peer review tools essentially ended the practice of a peer review being a formal meeting, and made them much easier to perform, and therefore more ubiquitous.  Popularization of garbage collected languages prompted memory management innovations in C++ like smart pointers and RAII, which are now considered standard practice, but were unheard of when many current code bases were started.  I could go on and on.

As companies grow, they try to take advantage of code reuse as much as possible, so a code architecture that was ideal for one product might be pulled into another project with little modification, even though the architecture might be a little awkward in the new context.  When this happens multiple times over possibly decades, the big picture stops making sense.

It's not that companies don't want to change with the times, but code bases are like ocean liners.  They take a long time and careful planning to turn around.  Therefore, it is highly unlikely you will ever find a large code base that wouldn't be redesigned a different way if starting from scratch today.  The important thing to look for is if a company is striving to turn in the right direction.


答: Certainly there is a limit to the complexity the human mind can grasp. You cannot expect somebody to know his way around millions of lines of code. That is why you should structure and document it in a reasonable and comprehensible way. Usually, chances to structure code are left out. You won't find a database class in the package for a graphical user interface. But you might find a database class doing something quite different (e.g. reporting) as well. Classes and modules tend to grow almost organically. Organizing code in more but smaller classes with single responsibilities is preferable too make code easier to understand. Easy to understand code is key in achieving the goals of software engineering e.g. correct, robust, reusable and extendable software.</p>

Title: Should large or old codebases be expected to be easy to navigate?

Body:
I'm an Undergraduate Computer Science Student currently on a placement year at a company that produces and supports a large enterprise web application. I'm loving the experience of seeing how software is produced in the real world, and feel very lucky to find a company that offers a chance to not only maintain and extend existing functionality but also develop entirely new features for the product.

All that said, though, I'm very conscious that this is very, very unlikely to be a perfect example of how to develop correctly. Far from it, in fact. I feel I'm learning a massive amount from my experience here, and I don't want to learn the wrong things or pick up bad habits from colleagues that could be hard to shake off further down the road. Mostly it's easy to tell what's good and what's not - for example the Unit Test coverage here is practically non-existent for various reasons (mostly poor excuses mixed in with one or two valid points). Lately, though, I've been noticing a regular occurrence that I'm just not sure about.

Whenever we start a new project, naturally we need to find any relevant code that needs to be extended, altered, or removed. It seems to me that, the vast majority of the time, anything not within the most commonly used sections of the application takes people an age to find within the codebase. There are one or two tech leads who know their section of the code well, but even they get stumped sometimes and have to spend a long time searching for what they require, or turn to someone who has been editing that part of the code recently (if anyone) for help. When I say a long time, I don't mean hours (usually) but it seems to me that a good codebase would be navigable to any point within a few minutes at worst, to anyone even vaguely familiar with the system.

So, my question. Is the above problem due to poorly structured code? Alternatively, is it down to developers not having enough knowledge of the codebase? Or is it simply unavoidable in large applications, regardless of how much work goes into keeping the file structure clear?

Or, indeed...am I just wasting my time on a topic that really doesn't matter?


问:
How to introduce your team to functional style of coding?
I have a situation where most people in my group come from an object oriented programming background with little to no understanding of functional programming. Not even basics like closures.

Any suggestions about what might be a good way to introduce them to functional coding style? A lot of coding that we do can be shortened if we do the functional way for our specific cases.

I have already given couple of presentations about functional and coding paradigms. Unfortunately we don't use a proper functional programming language like Haskell (basically legacy code is in C, C++, Java) so we have to do whatever is there with these.

答:
Luca Bolognese made this fantastic presentation where he introduces functional programming (to present F#) using a coffee example which is really great and helped me a lot to introduce Functional Programming to friends and colleagues.

You can also look a Real World Functional Programming by Petricek which is an excellent way to start thinking functionally in my opinion.


答:
You won't find any developer who wants to write a lot of code. The idea is to write only as much and have it written in a way that's extensible.

Unfortunately, developers have to gather the s/w requirements from business/sales/marketing and they are usually never specific. So you have use cases that have to be patched in some code which was never meant to do what it is doing in the first place.

There is no way to alter this situation, unless you have a way with human minds. What can save you is mandatory documentation, strong unit and integration testing framework, bug tracking system, developer mailing list within the company which can archive mails, peer review and learning generic programming techniques.

Also, consider using as much as you can from open source components since they generally have a good user base and moderate levels of documentation. More importantly, you have people to ask questions to if your tech lead is on vacation.

Large scale software design related books are also a welcome addition.


问:
Noobie wants to use source control, how would you guide them?
Let's say you know of an anonymous noobie that wants to be lead upon the path of righteousness.  This noobie wants to use some sort of source control tools simply for the experience of using source control tools (and possibly for whatever benefits they bring along with them).

To constrain things further (and to make this possibly even more noobie-tastic), let's say they're stuck in windows developing in visual studio.

How would you guide your neophyte?

答:
If your developing in a Windows environment and targeting Visual Studio as an IDE, I would highly recommend Mercurial for source control.

Use TortoiseHg as for managing
repositories.

Use VisualHg for an in editor
interface to TortoiseHg.

For the actual storage of the
repository, you have two choices:

Using the built in server hg serve.

Use a hosted solution like Bit Bucket (highly recommended)

ContentLicense: CC BY-SA 2.5


答:
Do your colleagues code outside of work?

Considering that you don't do any FP at your company, then getting anyone to learn a new language/paradigm when they don't do anything outside of their direct work tasks will be next to impossible.

If they do, then find interesting projects that they'll like that are related to functional programming and show them. You're not in a position to mandate a change, so you'll have to sow the seeds if interest on a personal level. This is how I was introduced to it - granted, by my best friend who happens to work with me.

Outside of that, most people write in-house tools to make small tasks easier. Try to write some of them in a functional language. Anyone who wants to see the code will be exposed to the (hopefully/possibly) beauty of the code and will likely ask you about it when they do. That is an opportunity to sell the idea.

Remember, there are functional languages that will work on your stack (scala/closure both run on the JVM). It's not "purely functional" like Haskell is, but it's a good start on a long journey.

If you have any control over hiring, hire people who have some functional experience (or are at least interested in functional programming).

And finally... you might be at the wrong company if you're that passionate about writing functional code. You're not going to change the way your entire company writes software - especially if they're making money and even more especially not in any reasonably short amount of time.

This is all about selling it to the devs... management is a whole other beast entirely.

Title: How to introduce your team to functional style of coding?

Body:
I have a situation where most people in my group come from an object oriented programming background with little to no understanding of functional programming. Not even basics like closures.

Any suggestions about what might be a good way to introduce them to functional coding style? A lot of coding that we do can be shortened if we do the functional way for our specific cases.

I have already given couple of presentations about functional and coding paradigms. Unfortunately we don't use a proper functional programming language like Haskell (basically legacy code is in C, C++, Java) so we have to do whatever is there with these.


问:
What benefits for the developer does the Ruby language offer that C# does not have?
What benefits for the developer does the Ruby language have that are not available in C# (preferably with code examples)?</p>

答: Check this articles: What Is So Great About Ruby?, also don't miss Poor Man's Singleton Methods via Dynamic Wrappers in C# as answer to first article.</p>


答: Switching from imperative to pure functional programming is a big change with a steep learning curve. I would suggest to try a less rapid transition, and in that case you have many options. For example Python supports list comprehensions and generator expressions, Ruby supports higher-order functions through code blocks, etc. Since you mentioned Java, if all of you have a Java background and you want full functional programming support, you can try Scala.</p>


问:
Real-world examples of apps written with TDD and good test coverage?
Are there any open source applications that are developed using test driven development that serve as models of how good unit testing should work?

I'd prefer to see examples in C# and .NET. (Note that I mentioned applications, not just libraries.)

I'm a mid-tier programmer who really wants to believe in and practice TDD. The app I work on in my day job is pretty complicated--about 1 million lines of code--and I would love to introduce more unit testing. We have some unit tests in place, but my efforts at TDD and with working on code that's already under test have not been encouraging.

In my admittedly limited experience, TDD seems to encourage a lot of complexity in the name of decoupling. The bits of the app that are hard to test--and which coincidentally tend to be critical--get pushed out to the periphery, into the realm of integration tests that may or may not ever get written. (I'm thinking of the usual suspects here, file system access, hydrating objects from a database, asynchronous web calls, etc.)

The code that's under test tends to involve lots of collaboration among objects, and maybe some simple flow logic, all of which happens in memory and which could arguably be written in a simpler, more understandable way if everything didn't have to be totally decoupled for testing.

I understand the techniques for mocking dependencies and such, but in my experience heavy use of mocking leads to very brittle tests. If my first instinct upon seeing a bunch of tests go red is, "Great, now I have to fix all the mocks," then my tests have become a drag rather than a safety net.

I'm trying to get past this mental barrier, and as part of that I'm reading Michael Feathers' book, Working Effectively with Legacy Code. I it hope will show me some of what I'm missing.

I'd also like to study some nontrivial .NET applications with good code coverage, maybe a  content management system, or a CRUD app. The FitNesse testing framework that Uncle Bob talks about is something I'll probably look at, but it would be nice to see something written in the language I'm most familiar with.

Any suggestions or words of wisdom would be appreciated.

答:
The Orchard project might be what you're looking for.. It's a .NET / MVC / TDD app that is fairly complex, but not too bad and it demonstrates some good practices and patterns..

http://orchard.codeplex.com/wikipage?title=solution

and I guess the updated link:

http://docs.orchardproject.net/


问:
Are there guidelines on how many parameters a function should accept?
I've noticed a few functions I work with have 6 or more parameters, whereas in most libraries I use it is rare to find a function that takes more than 3.

Often a lot of these extra parameters are binary options to alter the function behaviour. I think that some of these umpteen-parametered functions should probably be refactored. Is there a guideline for what number is too many?

答:
Personally, more than 2 is where my code smell alarm triggers. When you consider functions to be operations (that is, a translation from input to output), it is uncommon that more than 2 parameters are used in an operation. Procedures (that is a series of steps to achieve a goal) will take more inputs and are sometimes the best approach, but in most languages these days should not be the norm.

But again, that's the guideline rather than a rule. I often have functions that take more than two parameters due to unusual circumstances or ease of use.


答:
I've never seen a guideline, but in my experience a function that takes more than three or four parameters indicates one of two problems:

The function is doing too much. It should be split into several smaller functions, each which have a smaller parameter set.

There is another object hiding in there. You may need to create another object or data structure that includes these parameters. See this article on the Parameter Object pattern for more information.

It's difficult to tell what you're looking at without more information. Chances are the refactoring you need to do is split the function into smaller functions which are called from the parent depending on those flags that are currently being passed to the function.

There are some good gains to be had by doing this:

It makes your code easier to read. I personally find it much easier to read a "rules list" made up of an if structure that calls a lot of methods with descriptive names than a structure that does it all in one method.

It's more unit testable. You've split your problem into several smaller tasks that are individually very simple. The unit test collection would then be made up of a behavioral test suite that checks the paths through the master method and a collection of smaller tests for each individual procedure.

Title: Are there guidelines on how many parameters a function should accept?

Body:
I've noticed a few functions I work with have 6 or more parameters, whereas in most libraries I use it is rare to find a function that takes more than 3.

Often a lot of these extra parameters are binary options to alter the function behaviour. I think that some of these umpteen-parametered functions should probably be refactored. Is there a guideline for what number is too many?


答:
No, there is no standard guideline

But there are some techniques that can make a function with a lot of parameters more bearable.

You could use a list-if-args parameter (args*) or a dictionary-of-args parameter (kwargs**)

For instance, in python:

```<code>// Example definition
def example_function(normalParam, args*, kwargs**):
  for i in args:
    print 'args' + i + ': ' + args[i]
  for key in kwargs:
    print 'keyword: %s: %s' % (key, kwargs[key])
  somevar = kwargs.get('somevar','found')
  missingvar = kwargs.get('somevar','missing')
  print somevar
  print missingvar

// Example usage

    example_function('normal parameter', 'args1', args2,
                      somevar='value', missingvar='novalue')
</code>```

Outputs:

```<code>args1
args2
somevar:value
someothervar:novalue
value
missing
</code>```

Or you could use object literal definition syntax

For example, here's a JavaScript jQuery call to launch an AJAX GET request:

```<code>$.ajax({
  type: 'GET',
  url: 'http://someurl.com/feed',
  data: data,
  success: success(),
  error: error(),
  complete: complete(),
  dataType: 'jsonp'
});
</code>```

If you take a look at jQuery's ajax class there are a lot (approximately 30) more properties that can be set; mostly because ajax communications are very complex. Fortunately, the object literal syntax makes life easy.

C# intellisense provides active documentation of parameters so it's not uncommon to see very complex arrangements of overloaded methods.

Dynamically typed languages like python/javascript have no such capability, so it's a lot more common to see keyword arguments and object literal definitions.

I prefer object literal definitions (even in C#) for managing complex methods because you can explicitly see which properties are being set when an object is instantiated. You'll have to do a little more work to handle default arguments but in the long run your code will be a lot more readable. With object literal definitions you can break your dependence on documentation to understand what your code is doing at first glance.

IMHO, overloaded methods are highly overrated.

Note: If I remember right readonly access control should work for object literal constructors in C#. They essentially work the same as setting properties in the constructor.

If you have never written any non-trivial code in a dynamically typed (python) and/or functional/prototype javaScript based language, I highly suggest trying it out. It can be an enlightening experience.

It's can be scary first to break your reliance on parameters for the end-all, be-all approach to function/method initialization but you will learn to do so much more with your code without having to add unnecessary complexity.

Update:

I probably should have provided examples to demonstrate use in a statically typed language but I'm not currently thinking in a statically typed context. Basically, I've been doing too much work in a dynamically typed context to suddenly switch back.

What I do know is object literal definition syntax is completely possible in statically typed languages (at least in C# and Java) because I have used them before. In statically typed languages they're called 'Object Initializers'. Here are some links to show their use in Java and C#.

Body:
No, there is no standard guideline

But there are some techniques that can make a function with a lot of parameters more bearable.

You could use a list-if-args parameter (args*) or a dictionary-of-args parameter (kwargs**)

For instance, in python:

// Example definition
def example_function(normalParam, args*, kwargs**):
  for i in args:
    print 'args' + i + ': ' + args[i]
  for key in kwargs:
    print 'keyword: %s: %s' % (key, kwargs[key])
  somevar = kwargs.get('somevar','found')
  missingvar = kwargs.get('somevar','missing')
  print somevar
  print missingvar

// Example usage

    example_function('normal parameter', 'args1', args2,
                      somevar='value', missingvar='novalue')

Outputs:

args1
args2
somevar:value
someothervar:novalue
value
missing

Or you could use object literal definition syntax

For example, here's a JavaScript jQuery call to launch an AJAX GET request:

$.ajax({
  type: 'GET',
  url: 'http://someurl.com/feed',
  data: data,
  success: success(),
  error: error(),
  complete: complete(),
  dataType: 'jsonp'
});

If you take a look at jQuery's ajax class there are a lot (approximately 30) more properties that can be set; mostly because ajax communications are very complex. Fortunately, the object literal syntax makes life easy.

C# intellisense provides active documentation of parameters so it's not uncommon to see very complex arrangements of overloaded methods.

Dynamically typed languages like python/javascript have no such capability, so it's a lot more common to see keyword arguments and object literal definitions.

I prefer object literal definitions (even in C#) for managing complex methods because you can explicitly see which properties are being set when an object is instantiated. You'll have to do a little more work to handle default arguments but in the long run your code will be a lot more readable. With object literal definitions you can break your dependence on documentation to understand what your code is doing at first glance.

IMHO, overloaded methods are highly overrated.

Note: If I remember right readonly access control should work for object literal constructors in C#. They essentially work the same as setting properties in the constructor.

If you have never written any non-trivial code in a dynamically typed (python) and/or functional/prototype javaScript based language, I highly suggest trying it out. It can be an enlightening experience.

It's can be scary first to break your reliance on parameters for the end-all, be-all approach to function/method initialization but you will learn to do so much more with your code without having to add unnecessary complexity.

Update:

I probably should have provided examples to demonstrate use in a statically typed language but I'm not currently thinking in a statically typed context. Basically, I've been doing too much work in a dynamically typed context to suddenly switch back.

What I do know is object literal definition syntax is completely possible in statically typed languages (at least in C# and Java) because I have used them before. In statically typed languages they're called 'Object Initializers'. Here are some links to show their use in Java and C#.


答:
If the domain classes in the application are designed correctly, the number of parameters that we pass into a function will be automatically reduced - because the classes know how to do their job and they have enough data to do their work.

For example, say you have a manager class which asks a 3rd grade class to complete the assignments.

If you model correctly,

```<code>3rdGradeClass.finishHomework(int lessonId) {
    result = students.assignHomework(lessonId, dueDate);
    teacher.verifyHomeWork(result);
}
</code>```

This is simple.

If you don't have the correct model, the method will be like this

```<code>Manager.finishHomework(grade, students, lessonId, teacher, ...) {
    // This is not good.
}
</code>```

The correct model always reduces the function parameters between the method calls as the correct functions are delegated to their own classes (Single responsibility) and they have enough data to do their work.

Whenever I see the number of parameters increasing, I check my model to see if I designed my application model correctly.

There are some exceptions though: When I need to create a transfer object or config objects, I will use a builder pattern to produce small built objects first before constructing a big config object.

Body:
If the domain classes in the application are designed correctly, the number of parameters that we pass into a function will be automatically reduced - because the classes know how to do their job and they have enough data to do their work.

For example, say you have a manager class which asks a 3rd grade class to complete the assignments.

If you model correctly,

3rdGradeClass.finishHomework(int lessonId) {
    result = students.assignHomework(lessonId, dueDate);
    teacher.verifyHomeWork(result);
}

This is simple.

If you don't have the correct model, the method will be like this

Manager.finishHomework(grade, students, lessonId, teacher, ...) {
    // This is not good.
}

The correct model always reduces the function parameters between the method calls as the correct functions are delegated to their own classes (Single responsibility) and they have enough data to do their work.

Whenever I see the number of parameters increasing, I check my model to see if I designed my application model correctly.

There are some exceptions though: When I need to create a transfer object or config objects, I will use a builder pattern to produce small built objects first before constructing a big config object.


答:
A lot of third-party, open-source libraries are TDDed. Hibernating Rhinos' libraries, such as RhinoMocks and NHibernate, are TDDed by their developers using XUnit as the unit-testing framework.

Now, with OSS, you usually can't guarantee that EVERYTHING in the product has been TDDed. The community may have standards including this practice, and they may even use a build-bot that performs code coverage metrics, but TDD is a mentality that must be bought into by the developer, and with the public at large able to commit to open-source VCS trunks like those on GitHub, anyone can commit any change with any amount of test coverage (or if coverage is required the tests could have been written after the fact, which is a violation of the spirit of TDD but there really isn't a good way to catch it on commit).

Title: Real-world examples of apps written with TDD and good test coverage?

Body:
Are there any open source applications that are developed using test driven development that serve as models of how good unit testing should work?

I'd prefer to see examples in C# and .NET. (Note that I mentioned applications, not just libraries.)

I'm a mid-tier programmer who really wants to believe in and practice TDD. The app I work on in my day job is pretty complicated--about 1 million lines of code--and I would love to introduce more unit testing. We have some unit tests in place, but my efforts at TDD and with working on code that's already under test have not been encouraging.

In my admittedly limited experience, TDD seems to encourage a lot of complexity in the name of decoupling. The bits of the app that are hard to test--and which coincidentally tend to be critical--get pushed out to the periphery, into the realm of integration tests that may or may not ever get written. (I'm thinking of the usual suspects here, file system access, hydrating objects from a database, asynchronous web calls, etc.)

The code that's under test tends to involve lots of collaboration among objects, and maybe some simple flow logic, all of which happens in memory and which could arguably be written in a simpler, more understandable way if everything didn't have to be totally decoupled for testing.

I understand the techniques for mocking dependencies and such, but in my experience heavy use of mocking leads to very brittle tests. If my first instinct upon seeing a bunch of tests go red is, "Great, now I have to fix all the mocks," then my tests have become a drag rather than a safety net.

I'm trying to get past this mental barrier, and as part of that I'm reading Michael Feathers' book, Working Effectively with Legacy Code. I it hope will show me some of what I'm missing.

I'd also like to study some nontrivial .NET applications with good code coverage, maybe a  content management system, or a CRUD app. The FitNesse testing framework that Uncle Bob talks about is something I'll probably look at, but it would be nice to see something written in the language I'm most familiar with.

Any suggestions or words of wisdom would be appreciated.


答: I don't know whether TDD was used, but a stellar example of testing is sqlite which has a remarkable 100% branch coverage, and has more than 1000 times more test code and scripts than product code.</p>


问:
Desktop GUI loading slow
I am developing desktop based GUI (single form) using wxPython and loads it using remote citrix access from client private network.

Suppose, the GUI has certain group of select and text boxes which are loaded together when application starts. The value of select boxes come from database and on the basis of selection of select box value, corresponding text boxes (which are initially blank) are populated from database.

Now the problem is, due to slow remote access, we have to wait for long time (approximately 5-7 minutes ) before all controls are loaded. Is there any suggestion, if we can reduce this time ?

One way coming in first thought is to divide the GUI in multiple tabs and divide the controls among tabs. This way I need to load less controls when application starts for showing first tab. Other controls load, only after user click corresponding tab.

Any other way or this one is the best approach?

答:
7 minutes? This must be megabytes worth of data. Even over a 56K modem you could download a megabyte or more in that time. If it isn't megabytes of data, then you are using a bad access pattern like a fetch-one cursor, and should change to a batch download pattern. If it is a lot of small individual queries, fire them off simultaneously on threads or write a database procedure to collect all of the data server-side and send it in one query.

If the values for the select boxes change infrequently, then cache the values in a text file or local database and use those until the real values arrive.

Or, write the values into the application or a shared library. Then check for an application update on start, the way that tax applications work.

If the data does change frequently, track the changes and provide a way to download patches to update the local data caches.

Finally, set it up so that any mistakes because of out-dated data will be caught during data submission to the real database.

Title: Desktop GUI loading slow


答:
According to "Clean Code: A Handbook of Agile Software Craftsmanship", zero is the ideal, one or two are acceptable, three in special cases and four or more, never!

The words of the author:

The ideal number of arguments for a function is zero (niladic). Next comes one (monadic), followed closely by two (dyadic). Three arguments (triadic) should be avoided where possible. More than three (polyadic) requires very special justification—and then shouldn’t be used anyway.

In this book there is a chapter talking only about functions where parameters are large discussed, so I think this book can be a good guideline of how much parameters you need.

In my personal opinion, one parameter is better than no one because I think is more clear what is going on.

As example, in my opinion the second choice is better because is more clear what the method is processing:

```<code>LangDetector detector = new LangDetector(someText);
//lots of lines
String language = detector.detectLanguage();
</code>```

vs.

```<code>LangDetector detector = new LangDetector();
//lots of lines
String language = detector.detectLanguage(someText);
</code>```

About a lot of parameters, this can be a sign that some variables can be grouped into a single object or, in this case, a lot of booleans can represent that the function/method is doing more that one thing, and in this case, is better refactoring each one of these behavior in a different function.

Body:
According to "Clean Code: A Handbook of Agile Software Craftsmanship", zero is the ideal, one or two are acceptable, three in special cases and four or more, never!

The words of the author:

The ideal number of arguments for a function is zero (niladic). Next comes one (monadic), followed closely by two (dyadic). Three arguments (triadic) should be avoided where possible. More than three (polyadic) requires very special justification—and then shouldn’t be used anyway.

In this book there is a chapter talking only about functions where parameters are large discussed, so I think this book can be a good guideline of how much parameters you need.

In my personal opinion, one parameter is better than no one because I think is more clear what is going on.

As example, in my opinion the second choice is better because is more clear what the method is processing:

LangDetector detector = new LangDetector(someText);
//lots of lines
String language = detector.detectLanguage();

vs.

LangDetector detector = new LangDetector();
//lots of lines
String language = detector.detectLanguage(someText);

About a lot of parameters, this can be a sign that some variables can be grouped into a single object or, in this case, a lot of booleans can represent that the function/method is doing more that one thing, and in this case, is better refactoring each one of these behavior in a different function.


问:
Do non-pure interpreters still make the guarantees of functional programming?
I am assuming the implementations/compilers/generated C code (referred to hereinafter as generic, 'interpreter') for most functional programming languages are written in non-pure functional languages.

If this is the case, the underlying interpreter for any given functional programming language exhibits destructive updates and is referentially opaque. Functional constructs are designed to make certain guarantees, such as concurrency and provability.

If the interpreter is indeed an imperative program, how is it able to guarantee the 'no side-effects' properties of pure functional programs? Surely optimisations to functional code by the interpreter include changing the nature of recursive functions to imperative ones? My question is:

How do imperative interpreters still make guarantees about the functional program they are executing without being inherently functional themselves?

答:
By way of illustration, let's walk through a trivial example of a computer language called "ALL-CAPS."  This language has the peculiar quality (and language rule) of only being writable in all capital letters.

Can I write my compiler or interpreter in a language like C#?  Of course I can.  Does C# use lower-case letters?  Of course it does.  Can I still require my source input to be all capital letters?  Absolutely.

Someone with better deductive logic skills than I can probably logically prove that requiring all caps in your program source code is morally equivalent to requiring purely functional constructs in your source code.

OwnerDisplayName: Daniel Levin

OwnerDisplayName: Robert Harvey


答:
Everything in your machine runs on a CPU which loads and stores memory words, and performs comparisons and goto-like branches.

Functional programming means that mutation is hidden under the rug, not that it goes away.

It is not feasible, with current technology, for a functional language to be implemented purely all the way down. This is because you cannot keep allocating new hardware. Functional programs generate garbage as they execute, and the implementation has to identify the garbage and then reuse its storage for new objects. That is a form of mutation.

If this mutation is not done, then it means you do not serially re-use memory.

If you do not reuse memory, you have to keep getting new memory from somewhere.

Also, you are not allowed to restart the computer. You must use a new one.

Its CPU has to keep allocating new registers, because you can't load a new value into an existing register. Et cetera.

As you can see, functional programming is a silly pipe dream that is only made possible by the pragmatism of mutation.

There is inherent mutation in functional programming itself (in the abstraction). It's just conveniently ignored.

Fact is that when you construct a new object, the world has changed: there was no such object before, and there is now. Same thing when a new variable binding comes into life.

You can pretend that a whole new universe was allocated which is just like the old one, except for the difference that a new element now exists in it, but that's not reality. (If the old "world" was not mutated/destroyed by the creation of a new object, show me where that old one is.)

Also, in functional programs, object are destroyed all the time! Variable bindings (which are not captured in some closure) go out of scope, and objects fall out of the reachability graph (if there is no mutation, how can something be in a graph in one moment, and be not in that graph the next moment?)

You know that the old copy of the world is not being preserved, because those unreachable objects are stomped over to make new ones.

In other words, the destructiveness of functional programming reveals itself by the inability to revisit all past states of computation and inspect every object that was ever created.

Title: Do non-pure interpreters still make the guarantees of functional programming?

Body:
I am assuming the implementations/compilers/generated C code (referred to hereinafter as generic, 'interpreter') for most functional programming languages are written in non-pure functional languages.

If this is the case, the underlying interpreter for any given functional programming language exhibits destructive updates and is referentially opaque. Functional constructs are designed to make certain guarantees, such as concurrency and provability.

If the interpreter is indeed an imperative program, how is it able to guarantee the 'no side-effects' properties of pure functional programs? Surely optimisations to functional code by the interpreter include changing the nature of recursive functions to imperative ones? My question is:

How do imperative interpreters still make guarantees about the functional program they are executing without being inherently functional themselves?

OwnerDisplayName: Kaz


答:
Well, it's not a contradiction. You can build whatever you like in both paradigms. Guaranty is achieved by testing and proving, and surely, there are implementation bugs in every start.

The interesting thing occurred to me while reading your question was, that almost every language is C powered underneath, lisp, scheme, python...

OwnerDisplayName: CodeChords man


问:
Should You Log From Library Code?
If I am developing a Java library, is it good practice to issue log statements from within the library's code?

Having logging within the library will make debugging and troubleshooting more transparent. However, on the other hand, I do not like littering my library code with logging statements. Are there any performance implications to consider as well?

答:
Yes you should. Using a logging facade like SLF4J gives you flexibility without burdening your users with a particular logging framework.

Authors of widely-distributed components and libraries may code against the SLF4J interface in order to avoid imposing an logging framework on the end-user of the component or library. Thus, the end-user may choose the desired logging framework at deployment time by inserting the corresponding slf4j binding on the classpath, which may be changed later by replacing an existing binding with another on the class path and restarting the application. This approach has proven to be simple and very robust.

Also, if your users don't include an SLF4J jar (from the user's guide):

As of SLF4J version 1.6.0, if no binding is found on the class path, then slf4j-api will default to a no-operation implementation discarding all log requests.

If you're concerned about performance implications of logging, check out this SLF4J FAQ entry. The idea is that you provide parameters to log statements instead of adding them into a String inline:

The following two lines will yield the exact same output. However, the second form will outperform the first form by a factor of at least 30, in case of a disabled logging statement.

```<code>logger.debug("The new entry is "+entry+".");
logger.debug("The new entry is {}.", entry);
</code>```

Is SLF4J yet another logging facade?

SLF4J is conceptually very similar to JCL. As such, it can be thought of as yet another logging facade. However, SLF4J is much simpler in design and arguably more robust. In a nutshell, SLF4J avoid the class loader issues that plague [Jakarta Commons Logging].

Title: Should You Log From Library Code?

Body:
Yes you should. Using a logging facade like SLF4J gives you flexibility without burdening your users with a particular logging framework.

Authors of widely-distributed components and libraries may code against the SLF4J interface in order to avoid imposing an logging framework on the end-user of the component or library. Thus, the end-user may choose the desired logging framework at deployment time by inserting the corresponding slf4j binding on the classpath, which may be changed later by replacing an existing binding with another on the class path and restarting the application. This approach has proven to be simple and very robust.

Also, if your users don't include an SLF4J jar (from the user's guide):

As of SLF4J version 1.6.0, if no binding is found on the class path, then slf4j-api will default to a no-operation implementation discarding all log requests.

If you're concerned about performance implications of logging, check out this SLF4J FAQ entry. The idea is that you provide parameters to log statements instead of adding them into a String inline:

The following two lines will yield the exact same output. However, the second form will outperform the first form by a factor of at least 30, in case of a disabled logging statement.

logger.debug("The new entry is "+entry+".");
logger.debug("The new entry is {}.", entry);

Is SLF4J yet another logging facade?

SLF4J is conceptually very similar to JCL. As such, it can be thought of as yet another logging facade. However, SLF4J is much simpler in design and arguably more robust. In a nutshell, SLF4J avoid the class loader issues that plague [Jakarta Commons Logging].


答:
Yes, you should log from your library code. It not only helps you develop, but the people who use the library will find it useful. Remember that you can always set the logging levels to only show the log statements you need - and they can do the same.

Recently I was using Mybatis, an open source ORM tool. I was debugging an issue where a query I thought should have been correct was returning no results. It was a parameterized query, and since Mybatis has logging within its library code, I was able to turn it on and see the actual query being run. It was easy to tell that I swapped two parameters. Without logging in the library I couldn't have found the problem nearly as quickly.

Title: Should You Log From Library Code?

Body:
If I am developing a Java library, is it good practice to issue log statements from within the library's code?

Having logging within the library will make debugging and troubleshooting more transparent. However, on the other hand, I do not like littering my library code with logging statements. Are there any performance implications to consider as well?


答:
Ideally zero.  One or two are ok, three in certain cases.

Four or more is usually a bad practice.

As well as the single responibility principles that others have noted you can also think of it from testing and debugging perspectives.

If there is one parameter, knowing it's values, testing them and finding error with them is 'relatively easy as there is only one factor.  As you increase the factors, the total complexity increases rapidly.  For an abstract example:

Consider a 'what to wear in this weather' program.
Consider what it could do with one input - temperature.  As you can imagine, the results of what to wear are pretty simple based on that one factor.  Now consider what the program might/could/should do if it is actually passed temperature, humidity, dewpoint, precipitation, etc.  Now imagine how hard it would to debug if it gave the 'wrong' answer to something.


问:
Do real-world algorithms that greatly outperform in the class below exist?
Last night I was discussing with another programmer that even though something may be O(1), an operation which is O(n) may outperform it if there are is a large constant in the O(1) algorithm. He disagreed, so I've brought it here.

Are there examples of algorithms which greatly outperform those in the class below it? For example, O(n) being faster than O(1) or O(n2) being faster than O(n).

Mathematically this can be demonstrated for a function with an asymptotic upper bounds, when you disregard constant factors, but do such algorithms exist in the wild? And where would I find examples of them? What types of situations are they used for?

答:
The simplex method for linear programming can be exponential in the worst case, while relatively new interior point algorithms can be polynomial.

However, in practice, the exponential worst case for the simplex method doesn't come up -- the simplex method is fast and reliable, while early interior point algorithms were far too slow to be competitive.  (There are now more modern interior point algorithms which are competitive -- but the simplex method is, too...)


答: Since this was tagged as Scala, I'd like to add that Scala is written largely in Scala itself, with very little in Java. Then again, it does use some libraries written in Java, and it runs (mainly) on a JVM that is written mainly in C/C++.


问:
When to stop inheritance?
Once upon time ago I asked a question on Stack Overflow about inheritance.

I have said I design chess engine in OOP fashion. So I inherit all my pieces from Piece abstract class but inheritance still goes. Let me show by code

```<code>public abstract class Piece
{
    public void MakeMove();
    public void TakeBackMove();
}

public abstract class Pawn: Piece {}

public class WhitePawn :Pawn {}

public class BlackPawn:Pawn {}
</code>```

Programmers has been found my design a little bit over engineering and suggested to remove colored piece classes and hold piece color as a property member like below.

```<code>public abstract class Piece
{
    public Color Color { get; set; }
    public abstract void MakeMove();
    public abstract void TakeBackMove();
}
</code>```

In this way Piece can know his color. After implementation i have seen my implementation goes like below.

```<code>public abstract class Pawn: Piece
{
    public override void MakeMove()
    {
        if (this.Color == Color.White)
        {

        }
        else
        {

        }
    }

    public override void TakeBackMove()
    {
        if (this.Color == Color.White)
        {

        }
        else
        {

        }
    }
}
</code>```

Now I see that keep color property causing if statements in implementations. It makes me feel we need specific color pieces in inheritance hierarchy.

In such a case would you have classes like WhitePawn, BlackPawn or would you go to design by keeping Color property?

Without seen such a problem how would you want to start design? Keep Color property or having inheritance solution ?

Edit: I want to specify that my example may not completely match real life example. So before try to guess implementation details just concentrate the question.

I actually simply asking if using Color property will cause if statements better to use inheritance ?

答:
Inheritance is not as useful when the extension does not affect the object's external capabilities.

The Color property does not affect how a Piece object is used. For example, all pieces could conceivably invoke a moveForward or moveBackwards method (even if the move isn't legal), but the Piece's encapsulated logic uses the Color property to determine the absolute value that represents a forward or backwards movement (-1 or +1 on the "y axis"), as far as your API is concerned, your superclass and subclasses are identical objects (since they all expose the same methods).

Personally, I'd define some constants that represent each piece type, then use a switch statement to branch into private methods that return possible moves for "this" instance.

Title: When to stop inheritance?


答:
Hire (or get the boss to hire) a functional programmer

Eventually, this is going ot rub off on the rest of your team.

Also, as stated before, encouraging them to write code in a functional language during their off-time wouldn't hurt either.


答:
+1 to faif for mentioning Scala: this started as a comment on that answer but got too big...

I wanted to learn something about functional programming (coming from C/C++, some Python & rusty Java); I tried diving in at the deep end with Ocaml and then Haskell and Just Didn't Get It.  Then I tried Scala and found it let me start using functional things in a comfortable OOP/Java-ey environment where I could easily fall back to familiar imperative style when a functional approach eluded me.  Some might complain the "multiparadigm", "hybrid" nature of the language means you're never forced to stretch yourself to go "pure functional", but I'd say it does mean you can be pragmatic about things and know you'll be able to get real stuff done easily somehow when you need to.

A couple of years on (and 200+ Project Euler Scala solutions in Scala later) the encounter with functional has definitely influenced my Python (much more use of map, filter, reduce, lambdas, itertools, list comprehensions and passing functions around than I'd ever contemplated before) and to a lesser extent C++: maybe a bit more attempt to use STL's functional trappings, but the main impact is I'm a lot more comfortable using TBB's map/reduce constructs and really like how exploiting immutability can tame complexity in multithreaded code.

So personally, if I was you, I'd be making a case for introducing Scala into some of your Java-world development, preferably by showing some examples of it enormously simplifying something and producing the benefits you claim.  What happens next is down to the whole business of "championing" new ideas and driving change... which sounds like it may be a much bigger problem.


问:
Should a new programmer focus on a single technology until he's proficient at it?
Ok, I've been teaching a buddy how to program for a while now. He's a very fast learner, and he's quite good at programming so far. However, he has one "issue" I keep trying to correct.

He jumps in and starts doing highlevel programming without learning some of the basics (He's created a full blown web application but still doesn't know pagination or session management).

This isn't the problem though. He keeps jumping around to new technology (Node.js, MongoDB, EC2, etc). I tried telling him that he should learn some of the basics about his RDMS of choice (MySQL) as he uses it everyday before investing a bunch of time into learning the basics of MongoDB (And probably moving to something new).

Am I the one in the wrong here, or should he try to focus on one thing at a time and get really good at it?

答:
It's not bad if he is a beginner in programming.

He will see how some stuff work's. But if he doesen't understand the what he is doing it's better not to do it at all.

I had that problem with myself i want to know it all Java, C, C++, C#, Phyton, ASP.NET...etc
but  i realized i can't know it all, so i focused on couple of things's and it's much better.

So what should he do(advise him):

Think what stuff you want to do

Explore all the options

Find what fits you

Learn it

Never stop learning

I would not agree with @arnaud if you always explore and learn new stuff when a new project is in front of you(well not completely).
It takes too much time to explore and learn new stuff again and again and some projects have a time limit. But on the other hand if you need to learn some simple new stuff it's ok :D .


答:
I will now, via the magic of the Internet, demonstrate a pure functional program free of side effects, written in C, a decidedly impure programming language:

```<code>int main()
{
    return 0;
}
</code>```

C programs do not create side effects unless you tell them to.  Therefore, creating C code without side effects is relatively easy:  don't put them in!

Body:
I will now, via the magic of the Internet, demonstrate a pure functional program free of side effects, written in C, a decidedly impure programming language:

int main()
{
    return 0;
}

C programs do not create side effects unless you tell them to.  Therefore, creating C code without side effects is relatively easy:  don't put them in!


问:
How to code on a very tight schedule?
I'm working on a project that has very tight schedule. I don't have much time to code and test (even though I work more than 12 hours everyday, it's still delayed), and the result is very fragile. Its code is also very dilemma.

This program is used by all offices in our customer's company, which is located in many countries. I regularly get phone calls at midnight about errors from our user/tester or about them not knowing how to use some features.

After three years on this project, I feel very stressed and I can't sleep well because I'm very worried about errors and phone calls.

I have a few questions:

For three years, all the code I've written is just the perfect usage scenario code (so it break easily). It's poorly designed and doesn't have any unit tests. I have lots of problems because of this fact. Therefore, I want to know whether is it's feasible to write code that works when the project has a very tight schedule?

How can I write better code in the same amount of time?

How can I clear my mind and don't get worried about work when I go to sleep?

答:
For the love of god, where's your project manager?

If you don't have a project manager to help you establish productive time, you need one. You need a person dedicated to sticking up for your development time, limit scope creep, manage expectations, etc...

You do a creative job for a living. If you don't have a barrier between your customers/users and you, how can you effectively focus on your development?

A good PM can be good for a lot of things...

1. To play the 'Higher Power' card:

Your users are bugging you for new features but you really need some time to focus on a bug-fix release. Who said you have to talk to the users? Is it your responsibility to write the contracts? Is it your job to manage customer expectations? Do you have final decision power to dictate the terms of the contract?

No? Then why are you solely responsible for interacting with the customer? Development is hard and takes a lot of concentration. You need the ability to reclaim development time and you can do so with a good PM and a good excuse.

Regardless of what your PM makes compared to you, if customers start bothering you about modifications outside of the spec just say.

"Negotiating changes outside of the specification is above my pay grade..."

It's a polite way of saying, I don't give a s***.

Follow that up by sicking the 'Scope Creep Dog' on them.

"If you want to make changes to the spec you'll have to get in touch with my PM"

Now, leave me alone. A user's ability to directly interact with the developers is allowed as a privilege that can be taken away. If that's not the case, your management is failing you.

2. Managing Expectations 101

Who in their right mind thinks you can work such a crazy schedule and handle 24/7 tech support. You need somebody to stand up for you because your time is valuable and should be dedicated to your craft.

This applies to customers as well as the company you work for. For customers, if they are overstepping you can always ask...

"Is this service written into the contract?"

If it's not, you have the right to reject requests then. Don't get me wrong, it's nice to go above-and-beyond to make your customers happy but it's equally important to let them know the difference between what's expected and what you're giving to them as a favor.

For the company you work for, you need somebody to carry the message...

"Is the work I'm being asked to do equal to my pay-grade?"

Ie, are they paying you 60k a year to spend 50% your time doing phone tech support which is a much lower paying position. This is a dangerous topic to broach so you need a PM you can trust to make a good case for you. The argument you should make to him is...

"I get paid 60K a year but half of my potential productivity is being wasted on menial work."

Or, you guys hired me and are willingly losing money on that investment by having me spend half my time filling a low grade position. Believe it or not, by maximizing your potential they can make more money in the long-run.

When it comes to business, it's a hell of a lot easier to get the company to change their position if you can present a win-win situation. You don't have to be a master of negotiation for this one to stick. Of course, if the company resources are limited then this may backfire on you.

3. Everybody could use a cheerleader sometimes

A good PM will naturally be a people-person. The core of what they do is people relations. A good PM will have the ability to tell your customer what they don't want to hear and still have them walk away happy.

They can also be a great source of moral support when times get tough. A simple morale boost shouldn't be too much for a good PM to handle if you ask. You need somebody on your side, or else your morale drops and the work feels overwhelming.

If you don't have somebody higher up in the organization that is responsible for managing expectations, your management is failing and the higher-ups are probably not even aware of how bad the project is doing.

That's the main reason I avoid working for corporations like the plague. I have been fortunate enough to work for smaller companies where I have somebody higher up I can honestly discuss problems with who will hold what I have to say in confidence and take action if necessary.

You need somebody on your side to help keep you in line with business requirements and manage distractions. If you don't have that and there's no hope of finding it in the future, good luck...

Title: How to code on a very tight schedule?


问:
How do I get my open-source idea started?
I have an idea for an open source project. It's about building developing tools for software developers. Yet I have never  joined a development team and now I don't know much about these teams except the fact that they exist ;)

My questions are:

Is there c# open source projects team? Where?

How can I offer my idea / code

If the groups exist ... should I be the project manager in the sense of offering the scope , versions etc. or let others do it?

I know that java and other languages are better starting point for open-source but... I feel more comfortable with C# and the vs developing environment.

答:
"Is there c# open source projects team? Where?"

Yes, if you're not planning to start your own project you need to find a community what aligns with your interests. There are plenty of Open Source C# projects, most of them are named something like [projectName].NET.

If you aren't familiar with Linux and MonoDevelop, you may need to be. Open Source projects are usually developed in Linux and made to work on all platforms. It's just the nature of Open Source. Fortunately, the MonoDevelop IDE is very good.

"How can I offer my idea / code

You don't. Chances are, in the larger scope of the project, your idea is insignificant. Keep in mind that, on Open Source projects, the other developers aren't there to work as your personal employees. They're providing a valuable service for free and likely already have a plan of what they want to pursue.

If you have an idea, the absolute first thing you should do is submit a feature request. If your idea is deemed useful by the development team then you can start development. But don't start writing code assuming it will automatically be integrated into the project because you'll likely be wasting your time.

Also keep in mind that your personal style preferences may not match what the project uses. If it's a stable enough project, they may have some coding guidelines posted somewhere.

Either way, whatever you submit will be critiqued and you'll most likely be asked to revise further before it's included in a release.

"If the groups exist ... should I be the project manager in the sense of offering the scope , versions etc. or let others do it?"

If the group exists, you don't 'let' anybody do anything. You don't automatically get benevolent dictator status because you think you deserve it.

If a project is established and development is stable, they will most likely already have a list of feature requests, roadmap for feature inclusion, and a pretty good support team for dealing with bug fixes.

Not just that but, Open Source developers put a lot of time and effort into their work. Not only that but you'll probably be working at some point with people who are much more skilled than you.

Gaining their trust is a slow process, and you will only make progress if you put the same amount of skill and effort into what you offer.

You will likely start with submitting patches, followed by submitting pull requests if your working on something bigger. Don't expect write-access to the main repository because.  Contrary to popular belief, Open Source code is closely scrutinized before being merged into the main repository and even then, the submissions will likely fall on a pre-planned release schedule anyway.

Just from your initial approach I'd say, learn some humility before you attempt to join an Open Source project. They're not going to willing hand over the reins just because you think you're a talented developer.

It takes time to earn trust and if you're good you'll eventually earn the respect of the other contributors.


问:
Why are virtual machines required?
Instead of compiling the source code for the respective OS (on which it is targeted), you compile once and run everywhere.

For the sake of this question, I would call it VM (for example, both for Java and .NET). So this the execution of programs becomes something like

```<code> ------------       ----      ----
| Executable |  -> | VM | -> | OS |
 ------------       ----      ----
</code>```

It perfectly makes sense, the compiler remain generic for the respective VM. However, the implementation of VM may vary depending on the machine it is going to be installed i.e. (*nix, windows, mac) x (32 bit, 64 bit).

My question is, instead of writing VM for respective machines, why isn't the compiler is written for that specific machine? By this, instead of downloading respective VM you download the respective compiler and that compiler will take care of the machine-code+OS for that specific machine. End result, the execution of native code for any machine. Definitely, each source code would need compilation for that specific machine but now a days, the automated systems, scm builds can help us do this thing.

Do my reasons of being confused are right or I am missing some bits of technicalities here?

Edit:

PORTABILITY:

Yes, it is one reason but is portability a big issue in today's automated systems? how often do we have to worry about the fact that we don't have to compile it for other machines? Having a code compiled for native machine would give much better performance. Take Java for instance, you can't do low level programming on Windows and you have to choose JNI.

Take automated systems like TeamCity/Jenkins or others. We could have such an automated system setup where code submitted through version control would result in the executable.

答:
My question is, instead of writing VM for respective machines, why isn't the compiler written for that specific machine?

Because then you would no longer have a portable executable; you would have one executable for each platform.  The user would have to either download a specific executable for their platform, or compile the code themselves, on their specific platform.

With a VM, each platform just needs its platform-specific VM, and then you can distribute the same executable to every platform.

Title: Why are virtual machines required?


答:
You are missing something huge with these VM's. They do exactly what you say, but automatically. It's call a Just-In-Time Compiler and it is why .NET (On Windows) and Java are extremely close to the speed of natively compiled C++ code.

The Java/C# Source code is converted into byte code. This byte code is then compiled into machine code on the machine it is currently running on. For the most part, the VM will run the native code instead of reprocessing the byte code.

I have skipped over quite a bit and oversimplified the process, but VM's do a substantial amount of work.

Title: Why are virtual machines required?

Body:
Instead of compiling the source code for the respective OS (on which it is targeted), you compile once and run everywhere.

For the sake of this question, I would call it VM (for example, both for Java and .NET). So this the execution of programs becomes something like

```<code> ------------       ----      ----
| Executable |  -> | VM | -> | OS |
 ------------       ----      ----
</code>```

It perfectly makes sense, the compiler remain generic for the respective VM. However, the implementation of VM may vary depending on the machine it is going to be installed i.e. (*nix, windows, mac) x (32 bit, 64 bit).

My question is, instead of writing VM for respective machines, why isn't the compiler is written for that specific machine? By this, instead of downloading respective VM you download the respective compiler and that compiler will take care of the machine-code+OS for that specific machine. End result, the execution of native code for any machine. Definitely, each source code would need compilation for that specific machine but now a days, the automated systems, scm builds can help us do this thing.

Do my reasons of being confused are right or I am missing some bits of technicalities here?

Edit:

PORTABILITY:

Yes, it is one reason but is portability a big issue in today's automated systems? how often do we have to worry about the fact that we don't have to compile it for other machines? Having a code compiled for native machine would give much better performance. Take Java for instance, you can't do low level programming on Windows and you have to choose JNI.

Take automated systems like TeamCity/Jenkins or others. We could have such an automated system setup where code submitted through version control would result in the executable.


问:
Real-time Dataflow Programming

Background

Recently, I have been fascinated about the possibilities of dataflow-based programming approaches - in particular, signal/event-based concepts as realized by functional reactive programming, Boost::Dataflow::Signals, and the like.

Sample scenario:

Consider a car that has four speed sensors, one at each of its tires. Let's simplify things and say that these sensors are analog sensors providing the measured speed at that tire. The car further has individual brakes on the four tires (the actuators) that one can program to break more or less strongly.

There is no concrete task, but imagine having to realize things like detecting tires not turning due to aqua-planing, or ABS-support, or or or... In short: you have to evaluate the speed sensor data and control the actuators according to some logic.

From a programming point of view, one could think of realizing this via a signal-network of the following sort:

```<code>timer ------------\
sensor1/2/3/4 -> logic -> brakes1/2/3/4
</code>```

(That is, the timer triggers the logic, which takes the latest analog values of the sensors)

Like this, the timer can be programmed to trigger in fixed intervals (especially important to ensure the real-time constraints).

The advantage of the dataflow-approach here is that the above diagram is directly realized in the code, i.e. you have a logical wiring of signals and just need to provide an implementation that turns your actual hardward sensor's data into a signal (of the corresponding library you are using).

When it comes to real-time requirements, the maximal signal path length can also be computed (or at least more easily derived from the source).

The question

Of course, all of this is just an application idea and I am sure several brilliant people have come up with this before. What I am looking for is the follow-up. Are there any hard problems with this scenario which make it unrealizable in practice? Are there experiences from real-world projects on following such a line of thought? Is there even existing literature on this?

To make things clearer and more objective, I am looking for an answer that either shows an inherent fault in my line of thinking or provides reference to existing work/literature along with evaluations. Bonus points if real-time constraints are taken into account.

答:
I've seen this type of thing in Flight Simulation

I used to do hardware (specialty being electrical wiring and IO) but I have a basic understand of how the software architecture worked.

In such a system, there are a lot of complex components. For sensors, there are IO computers that handle all the hardware, calibration, networking components necessary to convert analog/digital signals to scalar values.

Basically, every input/output in the whole system can be described as a variable and the table of all possible values in the system lives in a global address space. In fact, on the really old simulators (80s) there's no such thing as dynamic memory allocation. Every time a new variable was assigned the whole system's software needed to be re-compiled.

To avoid that, the developers had built in a ton of spare variables that could simply be re-named, re-purposed if necessary.

The other major software component was the scheduler. The host computer was extremely slow by today's terms. To keep stimulus response latency numbers within standard limits (ie 33.3ms or 30hz max per frame on older gen hardware) they need to set prioritization levels for certain systems. If the latency for any of the sub-systems fell outside of the FAA specified minimum requirements, the simulator would lose its certification until it was fixed.

If I remember right the priorities were setup as:

Controls - Highest because control inputs need to be acted on as soon as possible

Visual - People respond quickest to visual feedback, if the delay is too long people notice

Instrumentation - Pilots spend a lot of time staring at instruments, they need to respond relatively fast

Motion - Motion is more subtle and slower to respond in real life so it has a lower priority

Believe it or not, you could fly a sim off of motion and it would still feel like your moving. When you're starting at a 150-180 degree projection on a curved mylar mirror, the visual will trick your mind into thinking that you're moving when you're sitting completely stationary. I have done wiring in the mirror compartment before; it's very important that you pause and gain your bearing while standing directly in front of one of those mirrors or it can throw you off balance sending you falling into the mirror (at the cost of 30K+ to fix). FYI, if you don't know what mylar is, it's the reflective material they make helium balloons with.

For the task scheduler, like I stated, each step is given priority and an iteration is based on a timed interval. The amount of processing that is done in an iteration depends on the inputs/outputs of that interval.

The subsystems each had their hardware. Visual Image Generator, Motion Control, Control Loading, I/O (had it's own network sub-system), the Host, and maybe an IOS (Instructor Operating System) which comprised of a touch screen interface to control the sim.

The way we'd measure input response on the different subsystems was based on hooking up a chart recorder and physically mapping the output response on the different signals. Nowadays, most of that stuff has been replaced by digital charts but (being only 27 now) it was fascinating to see the way things were done in the old days.

Like I said, my knowledge is limited to what I witnessed but as far as I can tell the system had a few important details.

All of the higher level memory abstractions (ex virtual memory, dynamic allocation) didn't exist on the real-time system.

Communications to/from the host were kept to the bare minimum possible. It was actually possible to upgrade the sub-systems as long as they were talking the same networking protocol.

A traditional Round Robin scheduler doesn't work because you need to be able to give priority to specific subsystems based on a fixed time-scale.

The concept of a fixed time-scale itself is the core of what real-time programming is. In fact, most of these old systems were built on multi-processor architectures with shared memory. SMP is a lot older than people think, it's just new to the desktop market.

With all that said, I think the solution to your problem is to break it into two systems. One for real-time processing that is capable of doing all its work in a fixed time schedule. One for foreground processing that can deal with processing tasks that exist longer than an iteration.

For something like breaking you need a very low latency controls input system. The specialty for controls is very specialized but there should be decades of material on how it's done out there. For foreground processing something that is fast enough to handle the processing part but stay within limits. If you want to do more comprehensive number crunching you'll probably also want a background processing unit that can process very long running tasks.

I'm not sure if I answered the question you were asking effectively but I hope it was a good read anyway. It's rare that I'm afforded an excuse to talk about this stuff in context.

Aside:

I have survived a couple of FAA baseline certifications and I don't use the term 'survive' lightly. On those old systems, a baseline certification could mean that a small team of highly skilled individuals is guaranteed to spend a full 2-3 day cycling through shifts 24 hours a day to bring everything up to spec as closely as possible. If it misses, the delay before another check can take place will most likely be months.

Title: Real-time Dataflow Programming


问:
Biggest mistake you've ever made
Similar to the question I read on Server Fault, what is the biggest mistake you've ever made in an IT related position. Some examples from friends:

I needed to do some work on a production site so I decided to copy over the live database to the beta site. Pretty standard, but when I went to the beta site it was still pulling out-of-date info. OOPS! I had copied the beta database over to the live site! Thank god for backups.

And for me, I created a form for an event that was to be held during a specific time range. Participants would fill out the form for a chance to win, and we would send the event organizers a CSV from the database. I went into the database, and found ONLY 1 ENTRY, MINE. Upon investigating, it appears as though I forgot an auto increment key, and because of the server setup there was no way to recover the lost data.

I am aware this question is similar to ones on Stack Overflow but the ones I found seemed to receive generic answers instead of actual stories :)

What is the biggest coding error/mistake ever…

答:
This happened to a colleague this month.

He was fixing a bug that occurred when you send an SMS to a lot of cellphones. Usually these messages won't actually be sent to save on costs but due to a misconfiguration in our database they did get sent.

Cost: one months wage of SMS traffic.

Title: Biggest mistake you've ever made


答: "Functional programming" is an abstraction, just like "Object-oriented programming". Your "interpreter" doesn't have to use objects in order to implement objects. Likewise, it doesn't have to use pure functions in order to implement pure functions.</p>


问:
Is Perl still a useful, viable language?
I know it may have been asked before, but here goes nothing...

Is Perl still something that would be considered useful? If someone was a new programmer (either completely new to programming or just a few month/years of experience) would Perl be something to be considered worthwhile to learn?

Is Perl still used with frequency? Is it still popular?

Or is Perl dying out compared to languages like Python, Ruby, PHP, ASP.NET, etc.?

Basically it boils down to this:

Is it still used/is it still used frequently? If yes, is it dying? If no, will it make a come back?

Is it something that would be worth learning?

How does it compare in demand to languages like Python in both popularity and usability/viability? Could languages like Python or Ruby be considered replacements for Perl?

Also, will newer versions of Perl really bring a large improvement to the Perl community, and perhaps bring Perl back to centerstage compared to other languages?

EDIT:

Okay, I suppose here's a better, reworded question:

Is Perl still growing, or is it "dying"? Is it still a language worth learning and using? What projects does it really "shine" in compared to other languages? What makes Perl a language to choose? Essentially: is Perl growing obsolete compared to other languages, and if so, do you expect that to change, or to continue?

And thank you to everyone who has answered so far, the discussion has been really interesting!

答:
I got most of my professional web experience with PHP but as I grew as a developer things got a bit more challenging, many tasks PHP simply could not do or does grossly inefficiently. I could have thrown my hands up but instead (thanks to google) I found myself in ssh sessions taking advantage of libreoffice, ffmpeg, imagemagick to write post process functions for PHP. Never using it before I went right for PERL.. mostly because Perl sits perfectly underneath the LAMP stack. </p>

<p>(1)it is preinstalled on all LAMP servers or at least has a fresh rpm.
(2)has an awesome CPAN repo to save you lots of time.
(3)faster/safer to perform tasks where PHP running on apache fails.
(4)very similar to PHP and easy to learn. </p>

<p>Mix ideas with PHP, bake with PERL using BASH as desired, flip according to MySQL then serve up with HTML5 and a dash of jQuery. Its a great recipe.  </p>

Body:
I got most of my professional web experience with PHP but as I grew as a developer things got a bit more challenging, many tasks PHP simply could not do or does grossly inefficiently. I could have thrown my hands up but instead (thanks to google) I found myself in ssh sessions taking advantage of libreoffice, ffmpeg, imagemagick to write post process functions for PHP. Never using it before I went right for PERL.. mostly because Perl sits perfectly underneath the LAMP stack.

(1)it is preinstalled on all LAMP servers or at least has a fresh rpm.
(2)has an awesome CPAN repo to save you lots of time.
(3)faster/safer to perform tasks where PHP running on apache fails.
(4)very similar to PHP and easy to learn.

Mix ideas with PHP, bake with PERL using BASH as desired, flip according to MySQL then serve up with HTML5 and a dash of jQuery. Its a great recipe.


问:
I can't draw. How can I make polished applications?
I'm not a graphic designer. I'm pretty bad at drawing anything. I struggle to build things that look even as nice as "sample" applications bundled with development tools; primarily because I don't have squat in the way of art assets.

What strategies might I take to mitigate this?

答:
My art ability is about 5th grade on a good day:). I employ a graphic designer, either
professionally when at work, or my wife, who has excellent art skills and loves using them.

Note that in my mind Graphics design is not UI/UX design. I either do a majority of UX, or employ a UX expert to retain control of UX, who then works with the GD to make it look pretty. Although I am sure there are good combined UX/GD professionals, I have had very bad experiences with GDs doing stuff that looked pretty, had very bad UX, and was outdated in a couple of months, and won't take that risk until I have worked with the GD for a couple of projects.


答:
What you might be looking for is "UI/UX Design for Developers".  One book related to this topic is User Interface Design for Programmers

If you're not looking for UI/UX design but looking to improve graphic design skills, I would recommend finding a class on how to use Adobe Photoshop or Adobe Illustrator (if not, at least some tutorials on the internet).  By learning a few techniques and looking at other people's work for inspiration, you would be surprised how little artistic creativity you need.

For example, you could learn the Gradient Tool in Photoshop, along with the Rounded Rectangle tool, and you could make something similar to the "Sign up for the newsletter" button on the right (although in this case it's done with pure CSS).

Title: I can't draw. How can I make polished applications?

Body:
I'm not a graphic designer. I'm pretty bad at drawing anything. I struggle to build things that look even as nice as "sample" applications bundled with development tools; primarily because I don't have squat in the way of art assets.

What strategies might I take to mitigate this?


答:
You can hire specialists for this sort of thing, but you don't need innate artistic ability to learn some basic techniques.  My undergrad degree actually required a semester of "art for engineers."  Taking a class or two at your local community college could be very beneficial.  You still won't be as good as people specially trained in the field, but you can definitely improve to the point where your programs look more professional.

There are also books geared toward relative amateurs.  One book I found useful for web design is The Principles of Beautiful Web Design by Jason Beaird.  Even if your designs don't improve much, getting a little education can help you better verbalize what's wrong with a design.  Instead of always saying, "I know it looks bad, but I can't figure out why," you'll be able to pinpoint problems like bad kerning or a lack of negative space, and defining the problem is half the battle.


答:
I personally do not think you have to be good artistically to create pleasing user interfaces.

What makes a good UI is not up to creativity, but is more related to a couple of well-established guidelines. If you follow these guidelines and practice some you can create great interfaces yourself.

I would suggest doing the following...

Read about what makes a good user interface. (online mostly)

Research and find some user interfaces that are pleasing to you.

Compare several good designs and try to pick out things that are similar between them.

Now look at your own design and see if you have those elements.

Try to recreate your user interface to be similar to the ones you liked.

I forecast that if you do this exercise for a week or two (and if you ask me, a week or two to learn how to design good interfaces is not such a long time), you will learn most of what makes a good user interface.

Just a couple of things I found that make user interfaces pleasing:

Simplicity

Consistency (colors, fonts, usage of buttons, links, etc...)

Spacing

Less is more (hide as much as you can from the user without diminishing usability)

Do not use white background and black font. Make sure the contrast is good enough, but usually change your background to a light shade of gray while your font to be dark gray.

Also... do not start with the design. Start with functionality and let the design evolve. Also, experiment! Do not get upset if it does not look perfect after 1-2 'iterations'. It gets better over time. But most importantly, you have to try.


答:
Let others "do the work for you" in the form of using frameworks, templates and pre-built gui components. For example I can't draw or design are either so for every new web project I do I start off with a css template (from the many free css template sites) for the layout and design and then 'tweak' it from there.
These templates include a complete design that can help you address this gap.

I agree with c_maker in that good usability is good design, although it sounds you are being more specific on the 'arty' designy end.

If you are doing web design and layout work here are some of those css sites:

http://www.freecsstemplates.com/

http://www.templatemo.com/

http://www.free-css.com/

http://www.oswd.org/

http://www.openwebdesign.org/


答:
When the parameter list grows to more than five, consider defining a "context" structure or object.

This is basically just a structure that holds all the optional parameters with some sensible defaults set.

In the C procedural world a plain structure would do. In Java, C++ a simple object will suffice. Don't mess with getters or setters because the sole purpose of the object is to hold "public"ly settable values.


问:
How do you track bugs in your personal projects?
I'm trying to decide if I need to reassess my defect-tracking process for my home-grown projects.  For the last several years, I really just track defects using TODO tags in the code, and keeping track of them in a specific view (I use Eclipse, which has a decent tagging system).

Unfortunately, I'm starting to wonder if this system is unsustainable.  The defects I find are typically associated with a snippet of code I'm working on; bugs which are not immediately understood tend to be forgotten, or ignored.  I wrote an application for my wife which has had a severe defect for almost 9 months, and I keep forgetting to fix it.

What mechanism do you use to track defects in your personal projects?  Do you have a specific system, or a process for prioritizing and managing them?

答: I use the $10 starter license for Jira.  It's cheap and I already know it well from work.</p>