答:
The risks of using a third party are the same regardless of it being open-source or commercial closed source.  things to check for when choosing a third party :

Licence : is the licence compatible with the product you are building.  for closed source look for royalties and redistribution rights.  for open source look for attribution and viral licencing that could force you to go open source (GPL family).

Active support and development.  How stable is the development of this application (company or community) Is there an active support platform (support hotline, forums or mailing lists), can you see activity lately on them if they are available.

How risky is getting stuck with library.  If you are stuck with a library that is no longer supported, can you take over the support ?  here having the source can save your ass at least temporarily until you find a replacement.  Some closed source product will have means for you to acquire the source code, usually with extra expenses.

these are the three main points I look for in a third party.  Of course I have no legal background whatsoever so if you work in a very sensitive product / domain best you ask legal competent persons first.

Title: In what situations is it a bad idea to use open source code for a corporate project?

Body:
Are there any situations where it may not be a good idea to use the code of an open source project, even if your company might allow you to do so?

Some cases that I think might be valid include:

The code may be implemented in a different languages.

It is not portable

It may need some other close-source libraries

What might be some other reasons?


问:
Are 70% of programs/business applications/something based in COBOL?
I heard this number and a quick google search reveals a whole lot of touting this number and absolutely zero data (honestly most articles promoting COBOL read like 95% propoganda). Perhaps it's true in an extremely limited context of banking software or something, but with millions of applications coded in dozens of languages and near-zero new COBOL projects I don't see how this is possible.

Is this a myth from the 70s (when it would have seemed entirely plausible) or is there some limited definition where this is actually true? I know there is a great deal still being maintained and I'm sure a large % of businesses have at least one COBOL program around, but this invisible 70% seems absurd.

答:
Depending on how you define the 100%, that number might be correct. For example, it might very well be that 70% of the programs written for banks and financial institutions until 2010 is based in COBOL. Wouldn't be surprised.

But I don't think that it is a fair statement to say that out of all the software in the world, 70% would be written in COBOL. Frankly, I don't know if you can even measure it.

ContentLicense: CC BY-SA 3.0


答:
the Gartner Group reported that 80% of the world's business ran on COBOL with over 200 billion lines of code in existence and with an estimated 5 billion lines of new code annually. Source is: COBOL-1.

I have no idea how do they count these numbers. I worked in several companies where no one actually tried to count all lines of code in one shop accurately, even when it was used as a measure of complexity. So how did they come up with these numbers?

COBOL is alive and well. It is not true to say that there are zero projects starting using COBOL. Remember that lots of the enterprise projects are interdependent. Unless there is a reason to extend a project in a different language you use the original architecture and software. Remember that most of such systems are large and re-writing them in a different language is risky, expensive and usually adds little or no value to the business.

There are many resources on the net that tells us that COBOL is alive and well.

Title: Are 70% of programs/business applications/something based in COBOL?

Body:
I heard this number and a quick google search reveals a whole lot of touting this number and absolutely zero data (honestly most articles promoting COBOL read like 95% propoganda). Perhaps it's true in an extremely limited context of banking software or something, but with millions of applications coded in dozens of languages and near-zero new COBOL projects I don't see how this is possible.

Is this a myth from the 70s (when it would have seemed entirely plausible) or is there some limited definition where this is actually true? I know there is a great deal still being maintained and I'm sure a large % of businesses have at least one COBOL program around, but this invisible 70% seems absurd.


问:
ternary or something similar for choosing function?
I posted this question on stackoverflow and it got a poor reception. In reality, the problems I'm facing are minor and any workaround can be considered impractical. However, I believe it might be of general interest in the abstract computer science domain, so I'm giving it a go here.

I'm working with Drupal's automated testing in PHP. It's a class that has two methods I'm concerned about: pass() and fail(). Each one produces a separate line on a results page indicating whether a particular operation passed or failed, e.g.

```<code>if ( $value == "expected_value" ) {
  $this->pass("Name of Test");
} else {
  $this->fail("Name of Test");
}
</code>```

(The reason drupal does it this way is so that in the results, you can see "Name of Test" in a green bar if it passed, and in a red bar if it failed. In other words "Testing Feature A: failed" or "Test of Feature A: passed". Of course you can put two different messages in there, but in my situation, I want to put the same message in)

What I notice about the above is that it seems verbose, in that I repeat the same message twice. It seems to me that there should be a way of expressing this where I only declare the message once. Of course I could put it in a variable, but that takes up extra space and I pass it twice, also.

I'd like to do something like ternary assignment, only instead where I decide which function to call. Is there a way I can define this logic while only expressing Name of Test one time?

Something like:

```<code>$function = ($value == "expected_value") ? "pass" : "fail" ;
$this->$function("Name of Test");
</code>```

Is this the most concise, elegant way I can phrase this logic? I tried

```<code>$this->(($value == "expected_value") ? "pass" : "fail")("Name of Test");
</code>```

But I got a parse error. Is there a way to get it down to one line, like ternary assignment?

Edit Here's the best formulation of my question to date: "What's a syntax I can use, in any language or pseudo-code , to express this without saying Name of test twice?"

I feel like I should be able to express this logic without saying Name of Test twice (anywhere -- including within another function that I call elsewhere in code). It seems that PHP does not allow me to express this in this way, so I'm looking for examples in other languages (and people have already posted C, javascript, and python examples) that allow you to concisely express this without repeating yourself.

答:
If your language support first class functions that it can be done as simple as below Pseudo code:

```<code>function handleTest (bool result, string testName,Function pass, Function fail)
{
    result ? pass(testName) : fail(testName);
}
</code>```

//Usage

```<code>handleTest($value == "expected_value","Name of Test", $this->pass,$this->fail);
</code>```

Body:
If your language support first class functions that it can be done as simple as below Pseudo code:

function handleTest (bool result, string testName,Function pass, Function fail)
{
    result ? pass(testName) : fail(testName);
}

//Usage

handleTest($value == "expected_value","Name of Test", $this->pass,$this->fail);


问:
What is the single most effective thing you did to improve your programming skills?
Looking back at my career and life as a programmer, there were plenty of different ways I improved my programming skills - reading code, writing code, reading books, listening to podcasts, watching screencasts and more.

My question is: What is the most effective thing you have done that improved your programming skills? What would you recommend to others that want to improve?

I do expect varied answers here and no single "one size fits all" answer - I would like to know what worked for different people.

答:
Touch typing. Learnt touch typing during the first month of employment because I was bored.

Switching to Linux comes as a close second. It helped me understand the the background of the C programming language.

OwnerDisplayName: Oded

ContentLicense: CC BY-SA 2.5


问:
Are 9 to 5 programmers looked down upon?
I would consider myself a 9 to 5 programmer.  What I mean by this, is that I have a programming job, but after I leave work, I leave my work there and do not take it home.  I very much enjoy my career choice, and I enjoy the work that I do at my current job.  I also enjoy learning new things in my field, such as new technologies and advancements in the programming industry.  It's just that outside of my job I have other hobbies that I feel are more important and I'd like to devote more of my time and energies to.  I also feel that devoting >40 hours a week to a single subject is a little exhausting, so are there really that many programmers that want to come home from their programming job and do more programming?

Maybe it's just my current employer, but I feel like they leave little time for career development.  The only way for me to keep up on the newest technologies and programming techniques is to do so on my own time, because my employer does not allocate time during work hours to do these sorts of things (deadlines == $$$).  Does anyone else feel the same way about their employer?

From your experience, do managers and people who hire programmers see 9 to 5 programmers as a less valuable resource?  I know that I could improve my resume by contributing to and open source project etc, but I just feel like I don't have the time to spare.

Could the opposite be said, such that devoting your spare time to other subjects such as the arts show a well-rounded-ness that could be a desirable trait to the company?

答:
I'm a little confused by your question - you say that you enjoy learning about new technologies and advancements, which leads me to think that you are at least a little more passionate about being a programmer than someone who goes in, does what they're required to do, and completely turns off when they're done.

In any field, I think it is great to hire people that truly love what they are doing. In my experience, they tend to be enthusiastic, resourceful, and overall happy people. I mean, if you love programming and that is what you get to do every day of your life, you're going to be much happier and get much more accomplished.

At the same time, I think it is great to be into other hobbies as well, and even to gain a proficiency at them. That could be sports, the arts, home improvement, any of those - to me, having other hobbies makes me a better problem solver and keeps me on my toes.

As far as your company situation, if you want to learn more, there is absolutely nothing stopping you. If you're waiting for your job to expand your experience, I think you need to find another job where you get that sort of flexibility. Good luck - many are simply driven by the bottom line.


问:
How to learn C in two days (if I already know C++)?
I've been programming in C++ for a few years, and I've done a school project or two in C (as well as several other languages).  However, I don't know C very well at all.  I have a programming interview in two days, and I just realized that this interview will be in C.

How do I approach this?  How do I learn C well enough to succeed in a programming interview? This job is not looking for a "C expert" or anything like that, so I think they'll be somewhat understanding if I explain that I have not programmed much in C.  They just choose to host their interviews in C.

Buying and reading a textbook is not feasible, so my resources will have to be on the internet.

答:
If they're hosting the interviews in C, they want someone who knows C, not someone who can cram for a test.  If you're truly serious about this, pick up a copy of K&R. (co-written by the guy who actually designed the language, may he rest in peace)  I can't think of any faster way to learn C.

Alternatively, you could try this.


答:
It's been a while since I've looked at PHP, but this should give you what you're looking for:

```<code>class Tester
{
    public function pass($s) {
        echo "pass $s\n";
    }

    public function fail($s) {
        echo "fail $s\n";
    }

    public function test($e, $v) {
        call_user_func($e == $v ? array($this, "pass") : array($this, "fail"), "my test");
    }
}
$t = new Tester();
$t->test(1, 1);
$t->test(2, 1);
</code>```

ideone test here

Having said that, generally it's nice to have unit tests (and their associated framework as readable as possible. What you already have is more readable than the code above. If you're worried about duplication of the string, why not just store it in a local variable and pass it to pass or fail?

Title: ternary or something similar for choosing function?

Body:
I posted this question on stackoverflow and it got a poor reception. In reality, the problems I'm facing are minor and any workaround can be considered impractical. However, I believe it might be of general interest in the abstract computer science domain, so I'm giving it a go here.

I'm working with Drupal's automated testing in PHP. It's a class that has two methods I'm concerned about: pass() and fail(). Each one produces a separate line on a results page indicating whether a particular operation passed or failed, e.g.

```<code>if ( $value == "expected_value" ) {
  $this->pass("Name of Test");
} else {
  $this->fail("Name of Test");
}
</code>```

(The reason drupal does it this way is so that in the results, you can see "Name of Test" in a green bar if it passed, and in a red bar if it failed. In other words "Testing Feature A: failed" or "Test of Feature A: passed". Of course you can put two different messages in there, but in my situation, I want to put the same message in)

What I notice about the above is that it seems verbose, in that I repeat the same message twice. It seems to me that there should be a way of expressing this where I only declare the message once. Of course I could put it in a variable, but that takes up extra space and I pass it twice, also.

I'd like to do something like ternary assignment, only instead where I decide which function to call. Is there a way I can define this logic while only expressing Name of Test one time?

Something like:

```<code>$function = ($value == "expected_value") ? "pass" : "fail" ;
$this->$function("Name of Test");
</code>```

Is this the most concise, elegant way I can phrase this logic? I tried

```<code>$this->(($value == "expected_value") ? "pass" : "fail")("Name of Test");
</code>```

But I got a parse error. Is there a way to get it down to one line, like ternary assignment?

Edit Here's the best formulation of my question to date: "What's a syntax I can use, in any language or pseudo-code , to express this without saying Name of test twice?"

I feel like I should be able to express this logic without saying Name of Test twice (anywhere -- including within another function that I call elsewhere in code). It seems that PHP does not allow me to express this in this way, so I'm looking for examples in other languages (and people have already posted C, javascript, and python examples) that allow you to concisely express this without repeating yourself.

Body:
It's been a while since I've looked at PHP, but this should give you what you're looking for:

class Tester
{
    public function pass($s) {
        echo "pass $s\n";
    }

    public function fail($s) {
        echo "fail $s\n";
    }

    public function test($e, $v) {
        call_user_func($e == $v ? array($this, "pass") : array($this, "fail"), "my test");
    }
}
$t = new Tester();
$t->test(1, 1);
$t->test(2, 1);

ideone test here

Having said that, generally it's nice to have unit tests (and their associated framework as readable as possible. What you already have is more readable than the code above. If you're worried about duplication of the string, why not just store it in a local variable and pass it to pass or fail?


答:
I wouldn't necessarily call you a 9-5 programmer based on your description.

The 9-5 programmer that I look down on has absolutely NO passion or interest in honing their craft but just plods away day-in day-out never showing any interest whatsoever in improving what they do.

Since fatherhood took over I have a lot less time to spend on major home coding projects so I know where you're coming from but I still spend some time here & there learning about new techniques & tools that I could bring to work.

Title: Are 9 to 5 programmers looked down upon?

Body:
I would consider myself a 9 to 5 programmer.  What I mean by this, is that I have a programming job, but after I leave work, I leave my work there and do not take it home.  I very much enjoy my career choice, and I enjoy the work that I do at my current job.  I also enjoy learning new things in my field, such as new technologies and advancements in the programming industry.  It's just that outside of my job I have other hobbies that I feel are more important and I'd like to devote more of my time and energies to.  I also feel that devoting >40 hours a week to a single subject is a little exhausting, so are there really that many programmers that want to come home from their programming job and do more programming?

Maybe it's just my current employer, but I feel like they leave little time for career development.  The only way for me to keep up on the newest technologies and programming techniques is to do so on my own time, because my employer does not allocate time during work hours to do these sorts of things (deadlines == $$$).  Does anyone else feel the same way about their employer?

From your experience, do managers and people who hire programmers see 9 to 5 programmers as a less valuable resource?  I know that I could improve my resume by contributing to and open source project etc, but I just feel like I don't have the time to spare.

Could the opposite be said, such that devoting your spare time to other subjects such as the arts show a well-rounded-ness that could be a desirable trait to the company?


答:
The only way for me to keep up on the newest technologies and
  programming techniques is to do so on my own time, because my employer
  does not allocate time during work hours to do these sorts of things
  (deadlines == $$$).

You employer pays you to produce, not to learn. Very few companies other than Google or perhaps Amazon (or other companies of that magnitude) can justify paying someone to possibly produce nothing.

Could the opposite be said, such that devoting your spare time to
  other subjects such as the arts show a well-rounded-ness that could be
  a desirable trait to the company?

Sure, they're called technical artists and yes, they can be very valuable as someone who possesses left and right brained strengths are fairly tough to come by.

Having said that, during my 10+ year career thus far, I have yet to meet a 9-5er (meaning that the only time that person does work-related stuff is at work).

Edit:

Apparently I wasn't clear in my first point, so I'll attempt to clarify. Learning is an integral part of daily life for an engineer. If you're not learning, you're not getting better. If you're not getting better, you get stuck in a rut. If you're stuck in a rut, more times than not, you have both an unhappy employer and employee.

The intention of my point was simply that (in my own experience), learning in a context that is relevant to your employment is usually easy to come by. Time allocation for (potentially) irrelevant technologies is harder to come by and therefore, more times than not, needs to be done on your own time (thus breaking the 9-5).


答:
This might be a difficult question but, I'll give it a run.

From where I stand, it seems to depend on the company's business model. Some companies operate with the view allowing employees time to grow in the way that they would choose will ultimately benefit the company since an employee with greater understanding has more to offer. Not to mention that doing such things potentially leads to a happier employee-base.

I know of a lot of programmers who code by day and code by night. For most of them it is because they are bent on programming, not because it looks good (though it usually pays off in their work life).

For these types of things, you really have to consider your own situation. Where do you need/want to be in n units of time? Does getting there require more coding or a greater understanding of some other augment?

Again, to answer your question: it depends on the company. There are those who also look down on people who spend too much time programming. We have a mix of both sorts of management at my company.


答:
The K&R book is a good recommendation. Since you did not want a book for an answer:

Convert a somewhat complex program that you wrote and understand to C. The larger and more complex, the better - it comes down to what you have available to convert, and the time you have available.

You already know the syntax, operators, etc. - just remove the features which aren't available and convert them to the C equivalent. You may have some questions, so search (and ask, if needed) at StackOverflow.

Choosing a project you wrote allows you to focus on the task, not the program.

Title: How to learn C in two days (if I already know C++)?

Body:
I've been programming in C++ for a few years, and I've done a school project or two in C (as well as several other languages).  However, I don't know C very well at all.  I have a programming interview in two days, and I just realized that this interview will be in C.

How do I approach this?  How do I learn C well enough to succeed in a programming interview? This job is not looking for a "C expert" or anything like that, so I think they'll be somewhat understanding if I explain that I have not programmed much in C.  They just choose to host their interviews in C.

Buying and reading a textbook is not feasible, so my resources will have to be on the internet.


问:
What are some good practices when trying to teach declarative programming to imperative programmers?
I offered to do a little bit training in F# at my company and they seemed to show some interest. They are generally VB6 and C# programmers who don't follow programming with too much passion. That being said I feel like it is easier to write correct code when you think in a functional matter so they should definitely get some benefit out of it.

Can anyone offer up some advice on how I should approach this?

Ideas

Don't focus on the syntax, instead focus on how this language and the idioms it promotes can be used.

Try and think of examples that are a pain to write in an imperative fashion but translates to elegant code when written in a declarative fashion.

答:
Many imperative programming languages (Ada, C/C++, Turbo Pascal, FoxPro) have the ability to define pointer to functions or procedure name literals that can be evaluated (and the procedures named after the literal invoked) at run time.

The traditional example is qsort in C. Build on that the notion that you can define algorithms that execute other algorithms on data structures. Obviously this is just a fraction of what functional programming is. But I've found that this is a good starting point to get the idea to sink in.

Once that sinks in, then you can start delving into other things (immutability, share-nothing, etc.)


答:
Get a C compiler, write some code. You heard of C++ being C with classes? Just drop classes and templates then write a bunch of code and check if syntax works or not. You'll may want to look at actual C source to see some library calls they make since stl wont be available (but i am sure you heard of memcpy, strlen, sprintf and etc) so you probably know enough "C" as it is.

Also remember operator, function overloading does not exist along with no references.


答:
Looking through your question I think I see three questions:

Are there many programmers that actually come home and do more programming?

Do companies who hire programmers see 9-5 programmers as a less valuable resource?

Is well-roundedness a desirable trait? (Yes, absolutely, but just having hobbies doesn't necessarily make a person well-rounded)

However, I think all of these questions are motivated by a single slight error in trying to diagnose your symptoms:

Acting like a 9-5 programmer is a surface symptom, not a root cause.

What is a 9-5 programmer?

In my haste previously I neglected to describe what I am referring to by "9-5 programmer" in this answer.  It seems that I've offended some by doing so.  So, I'll add this attempt at a definition: Someone who spends zero time on extra-curricular activities that enhance their day job.  In other words, someone who spends all their time producing and none investing in learning and growth.

By definition almost no one who spends any time here on Programmers would fit into that group.  There are many things that one can do other than actual coding that enhance a programming career outside your 9-5:

StackOverflow or Programmers

Reading (Programming or Software engineering books)

Studying new technologies

Etc.

Why might I be acting like a 9-5 programmer?

The question you need to be really asking yourself is why you feel like a 9-5 programmer.  I can think of a few possible reasons (I still have probably missed some).

1) You are actually a 9-5 programmer — You don't necessarily enjoy programming but can perform it competently enough to be paid.  You do your work and get out.  Technology/programming isn't interesting enough to you to study outside work hours.

Prognosis: This is like the factory worker of programmers.  You'll probably make it through life with a decent salary, a nice retirement, and, heaven forbid things get much worse in the economy, you'll retire at 65-ish.  However, if you feel like you have more potential for yourself or for others, then you ought to find your passion.  Nobody gets to the "top of their game" (any game) without passion.

2) Your 9-5 work satisfies the coding need and so you explore other hobbies —  You enjoy coding and you are good enough at it.  You don't think about programming at home, but you still feel invigorated to learn and grow in other ways outside of work hours.

Prognosis: This is like the factory manager of programmers.  It's still a 9-5 but your job gives you enough opportunities to keep your skills sharp, and you have enough passion to utilize those opportunities. Your work will be recognized accordingly.  In this situation it's still possible to end up behind where you wanted to be in your job, or with others passing you up unexpectedly.  To prevent that, I suggest you find other ways to enhance your programming skills in part of your extra time. Or, it's possible that pure programming is not the best fit for you.  You might be better in a different job where the things you want to do outside your 9-5 better complement your day-job.

Note that this is a sliding scale.  The point is simply that your success in your 9-5 is enhanced by the level of time you spend developing and sharpening related skills in your own free time.

3) Your job has you burnt out from programming —  Not all programming is created equal.  This job kills the passion for your craft.  It's like being a photographer and being assigned to take photos of a crime scene.  There's no art in it.  Consequently, the last thing you want to do more of is programming.

Prognosis: If this is you, you need a new job.  If you still love programming, top of your list when looking for a new job is that the subject matter (or programming specialty) be a better fit.

4) Your full-time job has you burnt out in general — You actually do enjoy programming, and if you received a healthy inheritance and quit your job today, you'd probably end up writing your own software.  The only problem is that by the time you've done your job for the day you are mentally burned out.  When you get home, you don't want to do much besides [insert your favorite form of vegetation here].

Prognosis: It may or may not be your job/company's fault.  Sometimes a full-time job is just that demanding.  However, the danger of this stage, similar to the above, is that you will stagnate.  While anyone can understand why you leave work at 5, and don't think about the job till you are back in the morning, over time you will notice that you've stayed in the same place while others with more passion came in and whipped up a storm and got some crazy stuff done.  It may not have even been because they are a better programmer, but just because they had passion — about something.

The solution isn't easy and is probably different for everyone.  When I've felt like I was getting to this stage before, the best thing that I've found to solve the full-time-job blues is to simply find and take in inspiration wherever it is — I.E. find people doing cool stuff.  For example, I enjoy reading articles by or interviews with the founders of software startups.  Maybe that inspiration is not even in programming — photography, painting, music, whatever.  If it takes you far enough away from programming, maybe you found your real passion.

And, it might even be your employer's fault.  Employee personal development can greatly benefit a company.  You might suggest your employer make it a focus, with some dedicated time to give the programmers an opportunity to slow down, figure out why deadlines are always such a stress, and have a little time to learn new things.  You might even find out that production is faster in a less stressful environment.

The common thread through all of this is that you need to figure out a couple of things about yourself:

Is passion important to you?  Is satisfaction about reaching some unknown potential or simply living a comfortable, stable life?

Is programming a passion for you?  If not, but you don't need passion, does it at least not bring unhappiness?

To answer your original question, there are plenty of opportunities for workers who are not necessarily passionate, but competent.  But you won't find any of them working at the top jobs.  You won't find them being asked to co-found companies.  And those jobs are not at the top of the payscale.  None of that may be important to you, and it's not important to all employers — so you can still be respected as long as the job is a good fit for you.

If any of that is important, I suggest you find a way to bring the passion back into your career.

Note

In response to comments

I am not claiming that one would ideally spend more than 40 hours a week coding.  However, jobs are about producing and most require you to spend nearly all of that time coding.  In most programming jobs, that will only keep certain skills sharp.  If you want to stay passionate (i.e. not burnt out) and not stagnate, you will need to find the extra time somewhere to enhance your skills to excel in a programming job.

Some people are certainly lucky enough to have a job that values personal development enough for them to keep a variety of skills sharp during their 9-5.  It doesn't sound like the original poster was in this camp.  If you are, stay there!  Use your extra time to be productive, but don't think that it has to be "coding".  If you come home feeling "exhausted" then I doubt you are in this camp.  A job like this would leave you feeling invigorated.

The Point

You spend 40 hours a week doing something.  That's not insignificant.  I believe that you should make the most of it.  To make the most out of it, some of your free time should be spent enhancing the skills you use during the day.

Most jobs require enough "production" (attention devoted to output that does not contribute greatly to personal learning and growth) out of the 40 hours (or more) that there is little time for personal development.  I believe that the amount of attention a person spends in their own learning and growth is directly correlated with their personal success.  This is the point I was trying to address here.

If you don't want to enhance your programming skills directly or indirectly outside of work hours, then it's quite possible that you'd be better off with a job where you can use more of the skills that you do enjoy improving and sharpening in your time off.


问:
What is the best method to start understanding BIG project source code?

Possible Duplicate:

  How do you dive into large code bases?

Sometimes before developing new products we need to understand some existing products or existing source code.

Sometimes to write another small module of that big project we need to understand that big source code.

In our case we need to study and understand a project with lots of files and folders. What is the easiest and most comfortable way to do it ? (especially for C and C++ and under Linux)

答:
All big projects have some sort of documentation usually Doxygen which can help a lot in understanding the code.

You can also use code browsing tools like SourceInsight to study the code.

Last but the best approach is run the code and debug use cases.

OwnerDisplayName: Als


答:
I think these figures date to about around 1997 when the Y2K "problem" was the hot topic in IT (especially sales people out to make a quick buck!). At the time there were some serious attempts to find out how much COBOL/C/C++/Java/VB etc. code was actually running to get a grip on how much work was required. It came as a shock to people how much of the worlds code base was COBOL. </p>

<p>I would expect this figure to be a lot less now, partly because of the long slow decline of the COBOL but mostly because there is a lot of code been written in other languages since then. Just think, php, barely existed in 1997. </p>

Body:
I think these figures date to about around 1997 when the Y2K "problem" was the hot topic in IT (especially sales people out to make a quick buck!). At the time there were some serious attempts to find out how much COBOL/C/C++/Java/VB etc. code was actually running to get a grip on how much work was required. It came as a shock to people how much of the worlds code base was COBOL.

I would expect this figure to be a lot less now, partly because of the long slow decline of the COBOL but mostly because there is a lot of code been written in other languages since then. Just think, php, barely existed in 1997.


答:
Als have already mentioned doxygen which is used for documentation in many projects.

For source browsing: vim along with plugins, cscope & ctags work very well. These can be installed easily on Linux environment and work very well in tandem.

Hope this helps!

Title: What is the best method to start understanding BIG project source code?

Body:
Possible Duplicate:

  How do you dive into large code bases?

Sometimes before developing new products we need to understand some existing products or existing source code.

Sometimes to write another small module of that big project we need to understand that big source code.

In our case we need to study and understand a project with lots of files and folders. What is the easiest and most comfortable way to do it ? (especially for C and C++ and under Linux)

ContentLicense: CC BY-SA 4.0


答:
There are different approaches. Documentation if present should help, but in the real world sadly there are quite a few poorly documented code bases. In many cases you can ask some senior developer in the company for guidance, make sure to ask for some high level view of what and how are things done in each module.

You can use a UML analysis tool to extract information from the code base, I suggest BoUML, it is not pretty, but it does a good job at processing C++, and you can create class diagrams by just pulling one class and expanding from there.

An IDE or a similar set of tools that help you navigate through code will also help, as they will allow you to navigate through code much easier than with a plain editor.

While doing the analysis, make sure that you take notes on what you believe each part of the code does, or where you have doubts, then ask a senior in the company to confirm your understandings or to fill in the gaps.


答:
While reading and documentation can be helpful, writing helps too!

Write some tests (nothing serious) which use common features of the codebase, or focus on the components you will need to use.

Try to document some of the things you did not expect, issues you had, and deviations from your team's practices.

You may be surprised by how some programs operate, and how they are expected to be used.


答:
You just need hard work.

Getting familiar with a large codebase is like disentangle a skein. You start somewhere, understand nothing. Then start again elsewhere, still understand nothing.

Start after start, some parts get less obscure. Starting again where you started the first time now provides some clues.

Then the strategy is divide and conquer. Isolate modules and understand them one after the other.

Possible starts are: Makefiles, main() function, file hierarchy, existing documentation (at least a README file) or whatever Doxygen is able to extract even if it was not planned.


问:
Why has C prevailed over Pascal?
My understanding is that in the 1980s, and perhaps in the 1990s too, Pascal and C were pretty much head-to-head as production languages.

Is the ultimate demise of Pascal only due to Borland's neglect of Delphi? Or was there more, such as C being a more robust language? If the latter, what were the perceived advantages of C over Pascal?

I'm interested in historical facts and observations one can back up, rather than likes and dislikes.

答: C is the base of Unix. In the 80s and 90s, Unix got more and more attention. Today some flavour of Unix is in your smartphone.</p>

Title: Why has C prevailed over Pascal?


答:
Although it wasn't the exclusive use, Pascal was designed for teaching programming, not to be actually used as a primary language.

Delphi and Object Pascal changed that. But at that time, it was already to late.

Title: Why has C prevailed over Pascal?

Body:
My understanding is that in the 1980s, and perhaps in the 1990s too, Pascal and C were pretty much head-to-head as production languages.

Is the ultimate demise of Pascal only due to Borland's neglect of Delphi? Or was there more, such as C being a more robust language? If the latter, what were the perceived advantages of C over Pascal?

I'm interested in historical facts and observations one can back up, rather than likes and dislikes.


答:
To dumb it down: C is a portable assembler, PASCAL is an educational language.

This section on the wikipedia covers it well in fact.

edit:

It would seem, that some here misunderstand my answer. Or actually rather the question.

This question is about popularity. And the reason why C is ultimately more popular than PASCAL is, that one was designed and marketed as a portable language runnning close to the metal, while the other one was designed and marketed as an educational language, enforcing a lot of safety and clarity.

Ultimately, it doesn't even really matter, whether either language failed the goals set for it, or made  unanticipated achievements. And anybody trying to deduce the difference in popularity from superiority of C over PASCAL is just plainly wrong.

The key to this question lies in history and the hysteria involved in it.

Title: Why has C prevailed over Pascal?


答:
Focus on the differences. C and C++ use the same bits & pieces, but there are some things where they differ:

typing discipline - C++ uses strong static typing, C has weak static typing. Consequently, you can (and often have to) cast a lot more freely in C than you would in C++.

different struct syntax - declaring and defining structs works differently in C than it does in C++; make sure you know how to use structs properly in C.

no STL - this means you have to do I/O the C way (printf and its family), as well as string handling. Be sure to know the most important libc functions for string handling and for converting between strings and numeric types.

malloc/free vs. new/delete - get used to using malloc and free correctly, as well as typical idioms for initializing heap-allocated structures.

no references - where you would pass by reference in C++, you use pass-by-pointer in C

There are more differences (such as lack of namespaces, heavy reliance on the preprocessor, encapsulation at the module level, etc.), but I doubt you're going to be programming at a scope where these are relevant.

In any case, from the job description it seems they are more interested in the algorithm part (how do you approach a particular problem) than the language part (how well do you know the syntax of language X). C is probably considered the common denominator to all programming languages, and the most likely candidate for any serious programmer to have had some exposure to.


答:
If i was interviewing and setting an interview question in C, there would be two things I would expect to differentiate the good candidates from the bad ones.

Can you design a sensible algorythm, and then write the code that reflects that design? 90% of candidates fail at this stage.

Can you manage memory, think freeing memory, use pointers effectively etc..

(1) would eliminiate the no hopers from the recruitment process.  (2) would diferentiate the best from the good, and would influence salary levels.

Yes, there is much more than just memory managment in C, but other C stuff such as function pointers, pedantic code writing to catch errors etc but in my experience if a programmer can understand pointers properly then they can be taught other stuff in C quickly and painlessly on the job.  Trying to teach pointers to someone is a gamble. They may never grasp the concept.


答:
I really understand your situation, I used to work nearly 40 hours a week with .NET. It was pretty cool, but once I was at home, I had had my time in front of a computer.

Unfortunately, it's difficult to get "recognized" as a programmer if you do stuff for a boss under an invisible name, and especially under .NET or other of Microsoft's proprietary technologies. It's like using someone else's code to do something that nobody knows you did.

If you are creative, like to deal with new tendencies, and have some marketing and communication skill I suggest you to start personnal projects. It's incredible how it gets you up to date in what you do.


问:
Does this licensing clause allow redistribution of this application?
As a software developer, I find a frequent need to create icons for my applications. Nothing has ever worked as well as IcoFX for this purpose. Unfortunately, the program is no longer free - but I still have the installer for an older version.

My question is whether or not I can distribute copies of the installer. The license agreement contains the following pertinent clauses:

```
6. All redistributions of the Software's files must retain all
   copyright notices and web site addresses that are
   currently in place, and must include this list of
   conditions without modification.

7. None of the Software's files may be redistributed for
   profit or as part of another Software package without
   express written permission of the Author.

10. The Author reserves his rights to modify this agreement
    in the future.
```

The first two clauses would seem to suggest that I can legally distribute verbatim copies of the installer but the last clause has me confused. If the author modifies the agreement and removes the ability to distribute copies, does it apply to my copy that I downloaded a while back?

答: You can distribute this version on installer, while pp.1-2 not violated


答:
Python

```<code>(self.pass if value == "expected_value" else self.fail)("Name of Test")
</code>```

Some languages have functions as first-class objects as well as class methods.

[The answer is short because the question isn't really a question, it's a review of the limitations of PHP with a "it might be of general interest" remark that somehow makes a long statement about PHP into a question about other languages.  Since the question is unclear, it's hard to provide more answer.  This short answer does not seek to dismiss your question.  Moderators have warned me that short answers are dismissive.  Since I can't provide more answer, I can only apologize in advance and hope that everyone understands that I'm not being dismissive.  The question is difficult to to understand and answer.]

Body:
Python

(self.pass if value == "expected_value" else self.fail)("Name of Test")

Some languages have functions as first-class objects as well as class methods.

[The answer is short because the question isn't really a question, it's a review of the limitations of PHP with a "it might be of general interest" remark that somehow makes a long statement about PHP into a question about other languages.  Since the question is unclear, it's hard to provide more answer.  This short answer does not seek to dismiss your question.  Moderators have warned me that short answers are dismissive.  Since I can't provide more answer, I can only apologize in advance and hope that everyone understands that I'm not being dismissive.  The question is difficult to to understand and answer.]


问:
Do you need to buy Visual Studio to develop/deploy an ASP.NET web application?
Since the .NET Framework SDK is free, is Visual Studio anything more than an IDE? If yes, do I need to buy Visual Studio to deploy my ASP.NET web application (written in C#)? I'm using MySQL for the database.

I'm a student that is going to graduate college soon, and I'm exploring technologies for a web application that I'm building for a startup.

答:
http://www.asp.net/ is also a good landing point: there's a download icon with a "free" banner in the middle, at the top. These 'all-in-one' downloaders are excellent for getting you going easily with everything you need, all tied together nicely.

Good Luck!


答:
The essay Why Pascal is not My Favorite Language by Brian W. Kernighan covers the main points of critique. (PDF)

C is much more versatile and extendable. Some people even found out how to do (a kind of) object-oriented programming with C! Also, the inline assembler and other low-level features made it an important language for systems programming.

Title: Why has C prevailed over Pascal?


问:
At what point does a company need a system engineer?
I'm 8 months into my first job as a developer at a mid-small company.  The four development teams have about 7 developers each, the design team consists of about the same number, and the administration / sales / marketing / hr team is 4 people.

We mostly develop web apps, a one-time deal, to run on the client's (usually existing) environment.  I'm finding myself setting up development environments to match, usually things I've never used before (from C#.NET 1.1 and MS-SQL to a regionally developed WAS called JEUS), which takes a significant amount of time.

Sometimes I get help from other developers but mostly I follow online tutorials until it seems to work, and then I spend more time fixing my code when it breaks because the settings aren't exactly the same as the actual environment.

I'm starting to think that one guy who specializes in this stuff would make it much easier for the developers to actually do what they're paid to do.  When does it make sense for a company to get a dedicated systems engineer?  Or am I wrong and should just suck it up and learn to do it?  I do realize that being familiar with different environments would improve my employability...

答:
When does it make sense for a company to get a dedicated systems engineer?

Logically, when enough of this type of work exists to occupy one FTE

Off course the consequence would be that the might be able to do with one less programmer


问:
When and how much should we validate input when working with (C)AP storage?
Herein, we consider a server-client architecture. Suppose we keep the details flexible, but there's more than one layer of servers supporting our hypothetical service. The general question is "When and how much do I validate client data?".

From other questions and answers I've read, the answer may be summarized as one of the following strategies (or a combination thereof).

Validate all data as soon as it arrives from the client. Other servers trust each other.

Validate all data on every server in the system. (this is not heavily favored)

Validate all data rigorously when it reaches the database, and optionally elsewhere as required by the application.

At all levels, validate exactly as much data as that particular server needs to do its job.

Number 3 seems particularly popular.

In the answers I've seen, however, there seems to be an implicit assumption of the classical RDBMS ("OldSql") centralized data storage. These are the MySQLs and Postgres's of the world. Taking cues from the CAP theorem, let's call these CP databases, as they tend to provide tools for consistency at the expense of some class of availability: usually, only a delegated master can write to a particular partition.

Recent alternatives to the classical RDBMS (specifically Voldemort, Riak, and Cassandra, which are modeled after the Dynamo storage system) are better classified as AP databases. These tools allow natural inconsistencies to appear upon data retrieval (e.g. multiple data values with vector clocks) in exchange for "always writeable" availability. Given that these data stores have rather unique properties, I pose the question:

Does the client data validation story change when we use AP datastores? How much of my client data should I validate before and after insertion to an AP database?

答:
In any system (CP or AP) I would go for option 1.

There are many advantages to validating as early as possible.

You have the whole transaction, you know all about it and who initiated it. You can provide meaningful error messages.

You can check for a lot more.

You should be "read only" until the entire request is validated. No complex roll backs to worry about!


答:
IMO there are two issues here:

Should you learn to setup / maintain all these different tools / environments? Needing to call the IT helpdesk whenever there is some configuration issue with a web server slows you down a lot. So in the long run you are probably better off learning these tools, at least to some level. You don't need to become a guru, but you should be able to e.g. spot common setup issues. As you note, it may also increase your market value.

Do you need reproducable development / deployment environments? Absolutely. Even a system guru isn't a very effective help if your development / test / staging / production environments are set up in an ad hoc way, so you can't reproduce a production bug in your debug environment.

Your team(s) need(s) to develop standards / procedures to achieve reliable, deterministic builds and deployments. E.g. put all (or as much as possible of) your tool configuration and/or install packages under source control, and write scripts to deploy it to a specific host at the press of a button. Existing build / continuous integration tools might also help in these tasks.

Last but not least, this also reduces the developers' workload of environment setup related tasks, alleviating your (and everyone else's) problem.

Title: At what point does a company need a system engineer?

Body:
I'm 8 months into my first job as a developer at a mid-small company.  The four development teams have about 7 developers each, the design team consists of about the same number, and the administration / sales / marketing / hr team is 4 people.

We mostly develop web apps, a one-time deal, to run on the client's (usually existing) environment.  I'm finding myself setting up development environments to match, usually things I've never used before (from C#.NET 1.1 and MS-SQL to a regionally developed WAS called JEUS), which takes a significant amount of time.

Sometimes I get help from other developers but mostly I follow online tutorials until it seems to work, and then I spend more time fixing my code when it breaks because the settings aren't exactly the same as the actual environment.

I'm starting to think that one guy who specializes in this stuff would make it much easier for the developers to actually do what they're paid to do.  When does it make sense for a company to get a dedicated systems engineer?  Or am I wrong and should just suck it up and learn to do it?  I do realize that being familiar with different environments would improve my employability...


问:
Redundant code ok?
Using C#/.Net, I have a page where the user can enter data and save these data by clicking a button.

To save data, the user needs to enter a valid date, this means a date which has a certain format.

The page contains amongst others two modules.

The ValidateDate-Event has the responsibility two check the format of the date-field. So it checks the format and displays a message if the date is not well formed.

The Save-Event has to save user entries. To successfully complete the task, a well formed date is needed. So I designed the module to check the date format. This has the advantage that the module can never crash and is not dependent of the Validation-module. But I realized that in fact I do the same thing twice, in two modules.

I am just curious, how do you handle this matter? What do you think is the best way to do it?

1) ValidateDate

Reponsibility: Check format of date field (, inform user)

Sub-Task: Check format of date field

2) Save

Reponsibility: Save data

Sub-Task: Check format of date field

答:
Doing the same thing twice is nearly always a bad idea. (see DRY) You have to change it in two places if your validation changes increasing your chance of bugs.

My advice would be have both Save and Validate call another method that validates the input. Its still a good idea to check on save as well as validate as you should never trust user input. They could for example be  malicious or there could be some bizzare browser bug causing/allowing them to submit bad data.

Title: Redundant code ok?


答:
My take is that C and major languages derived from it, C++, Java and C#, were embraced by the largest software companies, such as Microsoft and Sun/Oracle, and across the various development stacks. As a result, it became the 'mother language' of Windows, Apple OS's and Unix.

Pascal, in spite of Borland's best and often misguided efforts, didn't achieve that level of market penetration.

Title: Why has C prevailed over Pascal?


问:
Is coding and unit testing violating the DRY principle
The dry principle states:

"Every piece of knowledge must have a single, unambiguous,
  authoritative representation within a system."

However when writing tests for code you are describing the expected behavior for the system twice (once in the code and once in the test). I know both descriptions are from a different perspective but share a great deal of the underlying idea.

Any thoughts on this?

In general I think both unit tests and the DRY principle are good ideas and I try to apply them as much a possible. This question is more on a philosophical level, but I wondered if anyone had also thought of this.

答: No, it doesn't violate the DRY principle because unit tests don't reproduce the functionality, they only make sure the functionality (re: responsibility) operates properly. In the case of a unit test, the method you're testing still maintains authoritative representation. Your test code may look very similar to code that implements the method in the production version, but it has its own unambiguous purpose (to assert the test).


答:
You are operating on a faulty premise.

The code is not a description of the expected behavior, only the requirements and test cases are. And even then, the requirements and tests define two sides of the behavior. The requirements define the characteristics and functionality of the software system as a whole and test defines what the expected results should be and is matched against requirements. The code is a developer's interpretation of those requirements and the architecture of the system.

Title: Is coding and unit testing violating the DRY principle

Body:
The dry principle states:

"Every piece of knowledge must have a single, unambiguous,
  authoritative representation within a system."

However when writing tests for code you are describing the expected behavior for the system twice (once in the code and once in the test). I know both descriptions are from a different perspective but share a great deal of the underlying idea.

Any thoughts on this?

In general I think both unit tests and the DRY principle are good ideas and I try to apply them as much a possible. This question is more on a philosophical level, but I wondered if anyone had also thought of this.


答:
However when writing tests for code you are describing the expected behavior for the system twice (once in the code and once in the test).

Not quite. The code is not the description of the expected behaviour, but its implementation. Which can contain errors, that's why we need the tests.

Implementing even a fairly simple algorithm or abstraction is much trickier than describing it. Any decent programmer can describe in a few sentences how binary search works - still, Jon Bentley reported that in his experiments, over 70% of the experienced programmers participating in his course failed to implement it correctly.

This is why we need unit tests. Noone likes to work twice as much to achieve the same results, but all those developers who formulated and evangelised this practice realised from their own hard-earned experience that they need them. They were clever folks who wanted to develop software as fast as possible - which requires removing all duplicated and useless chores from the development process. Unit tests are not a duplicate job.


答:
Kind of.  If they're too similar, then yes, that's a bad thing.  Your test shouldn't be coded the same way as the code it's testing.  So you should be defining (1) an expectation and (2) an implementation.

I like to think that it's similar to double entry accounting.  An accounting system always makes at least 2 entries (a debit and a credit).  This is an error checking measure.  At the end of the day, the debits and the credits have to balance, or else there was an error.  You can't have an error detection system without some form of redundancy.

Consider a CRC for example.  Your CRC byte is a form of redundancy.  It's enough to detect any small error in the signal.  Similarly, audio CD's have a lot of redundant information so they still play perfectly if they're scratched.  Does that violate the DRY principle?  Probably, but that's how you get reliability.

There's another way to look at it too:

Your test is the authoritative answer.  The code it tests is just auto-generated by you, the code monkey.  If we could do auto-generation of code based on unit tests (like we auto-generate data access layers based on a database schema) then we wouldn't be violating the DRY principle (or at least not the OAOO principle).


问:
Is it possible to combine XPath and CSS selectors?
Just came through XPath.

I got curious about this. Why is there a different way to select tags in XPath and CSS(selectors).

Why cant there be a common way in both XPath and CSS?

答:
My assumption:

XPath is much more powerful when it comes to selecting nodes, allowing some very complex conditions

while CSS selectors aren't that powerful, they are powerful enough

XPath is newer than CSS


答:
Pascal has lost the battle mostly because of:

Verbosity (if ... then begin ... end, var A: array[0..15] of Integer)

Mutually incomprehensible dialects and the official standard

Less than impressive object-oriented extensions

The most successful and practical dialect - Turbo Pascal - has never been ported to platforms other than DOS/Windows. Plus Borland never opened the sources of the compiler.

Pascal's "last hope" - Delphi - was positioned by Borland as a database development platform targeted at corporate environments. This was an unfortunate marketing move (made by marketing people I suppose), because creative engineers hate both databases and corporate environments. Then the failure of Delphi for Linux, Kylix.

Apple switched to C and subsequently to Objective-C and thus it killed Pascal as an OS language

Title: Why has C prevailed over Pascal?


答:
My experiences working at a company with less than 20 people are that as a software developer I have to be top of the food chain and wear many hats.

When I say top of the food chain, I mean that I am expected to excel at any IT problem thrown at me and surpass the abilities of my IT peers who work in a non software development role.  By wear many hats I mean that I do need to play many different IT roles from time to time.

My peers consist of tech support, pc support specialists and a webmaster/network administrator/QA.  Besides QA, if the network goes down and the guy responsible is not in the office that day I am not only expected to fix the problem but do it better than the guy who was hired to do it.  Same thing if the website goes down and same thing if all the tech support people are on the other line and a password needs reset for a user.

They don't view it that my skill sets are just coding/developing, but that these other IT professionals are there to shelter me from the daily grind of running a successful business so that I have time to work on projects with minimal distractions.

Whatever you are struggling with, take the time to learn it and be happy you are learning a new skill because if the company falls into bad times and they have to let half the team go, they are going to get rid of the software developers who only code/develop and who only code/develop exactly what is written on a spec without question.


问:
Which functional language is good for a beginner?

Possible Duplicate:

  Choosing a functional programming language

I am a C++ programmer looking to learn a functional language as a hobby and out of sheer curiosity. I am not looking to be an expert, but just to get a grasp on functional programming. This language should be simple to learn and have good tutorials and resources for beginners. Are there any such languages?

答:
I've found that Haskell has a number of good resources available. It's also a purely functional language, meaning that any identifiers are immutable. As far as resources to learn the language, it has a comprehensive website and a highly recommended tutorial that is also available for purchase as a book. Real World Haskell is also another good book available for purchase or online for free. Haskell is also somewhat common on Stack Overflow, with over 4000 questions asked and many answered.

However, one of your requirements is "simple to learn". That's hard to judge. Coming from a C++ background, I suspect that you have a strong object-oriented and/or procedural background. Functional programming requires a totally different thought process - it will warp your mind, but it will also make you a better engineer if you are able to think in a new and very different way. You might be interested in the answers to this question about learning functional programming to become a better object-oriented programmer.


答:
Let us bring some balance to this argument.

For the record, I am a 9-5 programmer in the strictest sense of the word.  I have coded for many many years and I will probably be coding for many more.  I do have a strong passion for development and love seeing all those classes giving each other hugs and kisses.  I'm all for fluffy bunny designs and FOR loops...

BUT... and it's a big but...

I refuse to sacrifice my other responsibilities as a husband and father to become better at one thing... software development.  You see, when you lie on your death bed, you will look deep into your wife's eyes, and think of all those lovely moments you spend in Visio drawing UML diagrams and writing clean, simple and maintainable code... I think not.

It's not about balance.  If I have to choose, I WILL be poor and be with my family.  It's not about the money or job satisfaction or the stuff I want.

Agreed, my answer is probably only relevant to some of the married developers out there but for what it's worth, I'll try to represent those of us who are compelled to look after our families as real men do.  Taking responsibility.

Don't give me the excuse "My wife married me as I am, she knows my passion for programming and willingly sacrifices every last second of my free time for the computer because she loves me".  Dude... I won't even go there.

SO, to cut a already long story short.

I code from 9 to 5, I occasionally read articles on software development at home.  I value time with my family and will not be an absent father or husband.  The world has enough of those.

You only have 80 odd years to live on this planet, what do you want your scoreboard to look like once you're done.  Like this:

Software developer - 8/10

Husband - 2/10

Father - 3/10

Go for it.  Not me.

In fact, I go as far as to not work for companies that expect regular overtime.  I am willing to do overtime on occasion although still see it as a lack of managing expectations.  Period.  A delivery date can in most cases be flexible if issues are detected/reported ahead of time.

Companies tend to start with the "crunch time" excuse which conveniently turns into a regular occurrence.  It makes business sense, unpaid effort.  If you give me time in lieu (yay!  You know where I'll be spending mine!) I would do crunch time, any time.

If not, go get yourself one of those developers who think software development is all there is to life.  There are many of them.

Regrettably this appears like some sort of rant, which it isn't.

Summary:  Review your current working hours.  Look at your other responsibilities in life and give them appropriate attention.  Do not waste your life on becoming great at only one thing in life, it's too huge a sacrifice with too small a pay-off.


答:
'Simple to learn' is always going to be relative - the biggest burden is making the jump from imperative to functional programming, the syntax is of much less importance. In fact, a radically different syntax might make it easier to pick up the new concepts and approach programming from a completely different angle.

The language itself is probably less important than its surrounding ecosystem - you want to pick one that has an active community, a rich set of libraries, and most of all, good development tools. However, I'd go for a language that was designed for functional programming, rather than a multi-paradigm one that happens to be suitable for functional programming - javascript, for example, has many FP aspects, but it doesn't invite or urge you to use them.

Here's a list of languages you might want to try:

Haskell

Scheme

Common Lisp (CL)

ML

F# (if you're into .NET)

Clojure (if you're familiar with the Java ecosystem)

Of these, Haskell is probably the most radically different from what you're used to.

Title: Which functional language is good for a beginner?

Body:
Possible Duplicate:

  Choosing a functional programming language

I am a C++ programmer looking to learn a functional language as a hobby and out of sheer curiosity. I am not looking to be an expert, but just to get a grasp on functional programming. This language should be simple to learn and have good tutorials and resources for beginners. Are there any such languages?


问:
How to test the tests?
We test our code to make it more correct (actually, less likely to be incorrect). However, the tests are also code -- they can also contain errors. And if your tests are buggy, they hardly make your code better.

I can think of three possible types of errors in tests:

Logical errors, when the programmer misunderstood the task at hand, and the tests do what he thought they should do, which is wrong;

Errors in the underlying testing framework (eg. a leaky mocking abstraction);

Bugs in the tests: the test is doing slightly different than what the programmer thinks it is.

Type (1) errors seem to be impossible to prevent (unless the programmer just... gets smarter). However, (2) and (3) may be tractable. How do you deal with these types of errors? Do you have any special strategies to avoid them? For example, do you write some special "empty" tests, that only check the test author's presuppositions? Also, how do you approach debugging a broken test case?

答:
There must be a point when one should stop trying to unit test. Should know when to draw the line. Should we write test cases to test test cases? What about the new test cases written to test test cases? How will we test them?

```<code>if (0 > printf("Hello, world\n")) {
  printf("Printing \"Hello, world\" failed\n");
}
</code>```

Edit: Updated with explanation as suggested by comment.

Title: How to test the tests?

Body:
There must be a point when one should stop trying to unit test. Should know when to draw the line. Should we write test cases to test test cases? What about the new test cases written to test test cases? How will we test them?

if (0 > printf("Hello, world\n")) {
  printf("Printing \"Hello, world\" failed\n");
}

Edit: Updated with explanation as suggested by comment.


答:
Historically, both standards grew independently, and the design goals were quite different - XPath is for selecting node sets from an XML document, while CSS is for defining layout properties of documents in various markup languages, including HTML, XHTML and SGML. Obviously, there is quite some functional overlap, but not enough to make them arbitrarily exchangeable, and the syntax is partially incompatible.

If an effort were made to unify them both, implementors would have to support both XPath and CSS selectors, and each one is complicated enough on its own (just to give you an idea, see how much of CSS3 current browsers implement, and how long that took them).

Title: Is it possible to combine XPath and CSS selectors?

Body:
Just came through XPath.

I got curious about this. Why is there a different way to select tags in XPath and CSS(selectors).

Why cant there be a common way in both XPath and CSS?


问:
Are 70% of programs/business applications/something based in COBOL?
I heard this number and a quick google search reveals a whole lot of touting this number and absolutely zero data (honestly most articles promoting COBOL read like 95% propoganda). Perhaps it's true in an extremely limited context of banking software or something, but with millions of applications coded in dozens of languages and near-zero new COBOL projects I don't see how this is possible.

Is this a myth from the 70s (when it would have seemed entirely plausible) or is there some limited definition where this is actually true? I know there is a great deal still being maintained and I'm sure a large % of businesses have at least one COBOL program around, but this invisible 70% seems absurd.

答:
First of all, these estimates are dubious. Secondly even if you'd assume that the numbers are correct, the estimates are based on lines of code (LoC) metric. COBOL is extremely verbose, so you need an order of magnitude more code to achieve same thing. Consider "hello world" in 3 programming languages:

Python:

```<code>print "Hello world!"
</code>```

C:

```<code>#include <stdio.h>

int main() {
    printf("Hello world!\n");
}
</code>```

COBOL:

```<code>000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. HELLOWORLD.
000300
000400*
000500 ENVIRONMENT DIVISION.
000600 CONFIGURATION SECTION.
000700 SOURCE-COMPUTER. RM-COBOL.
000800 OBJECT-COMPUTER. RM-COBOL.
000900
001000 DATA DIVISION.
001100 FILE SECTION.
001200
100000 PROCEDURE DIVISION.
100100
100200 MAIN-LOGIC SECTION.
100300 BEGIN.
100400     DISPLAY " " LINE 1 POSITION 1 ERASE EOS.
100500     DISPLAY "Hello world!" LINE 15 POSITION 10.
100600     STOP RUN.
100700 MAIN-LOGIC-EXIT.
100800     EXIT.
</code>```

Body:
First of all, these estimates are dubious. Secondly even if you'd assume that the numbers are correct, the estimates are based on lines of code (LoC) metric. COBOL is extremely verbose, so you need an order of magnitude more code to achieve same thing. Consider "hello world" in 3 programming languages:

Python:

print "Hello world!"

C:

#include <stdio.h>

int main() {
    printf("Hello world!\n");
}

COBOL:

000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. HELLOWORLD.
000300
000400*
000500 ENVIRONMENT DIVISION.
000600 CONFIGURATION SECTION.
000700 SOURCE-COMPUTER. RM-COBOL.
000800 OBJECT-COMPUTER. RM-COBOL.
000900
001000 DATA DIVISION.
001100 FILE SECTION.
001200
100000 PROCEDURE DIVISION.
100100
100200 MAIN-LOGIC SECTION.
100300 BEGIN.
100400     DISPLAY " " LINE 1 POSITION 1 ERASE EOS.
100500     DISPLAY "Hello world!" LINE 15 POSITION 10.
100600     STOP RUN.
100700 MAIN-LOGIC-EXIT.
100800     EXIT.


问:
How does a developer set up an environment to hack on an OS like Linux, Plan9 or BSD?
I've always found it daunting and confusing how an OS hacker sets up their workflow. As a web-developer I find it easy to set up a workflow because web-sites run on servers and as such my OS is never touched. But an OS programmer, how do you do it? Do you develop on one machine and then somehow transfer code to the other machine? Do you develop on the OS you are developing, that last option seems rife with paradoxes? So how you do it?

P.S.

My similar Quora question still has no answer to this question...

答: While I don't do this personally, it seems like what would make the most sense is using a Virtual Machine (such as VM Player). This would allow you to make changes right away and then fire up the VM and load it to see those almost immediately instead of having to go through the whole process of putting it on a separate machine.</p>


答:
I've never poked at Plan 9, but for Unix-type OSes (Linux, BSD), I just setup a system running the kernel I want to hack on, get the compiler toolchain installed (not very difficult on most modern Linux distros), and start building kernels.

If I'm fooling with the kernel itself, I rig the boot setup menus (grub or whatever I'm using) to have an extra option for my dev kernels, and reboot into the kernel under development.

For hardware hacking it's a bit easier, as I usually work with loadable modules, and so I can just load and unload the module I'm developing.

Debugging isn't the easiest thing in the world when working on the kernel, but that's when you learn to read the system log files.

Title: How does a developer set up an environment to hack on an OS like Linux, Plan9 or BSD?

Body:
I've always found it daunting and confusing how an OS hacker sets up their workflow. As a web-developer I find it easy to set up a workflow because web-sites run on servers and as such my OS is never touched. But an OS programmer, how do you do it? Do you develop on one machine and then somehow transfer code to the other machine? Do you develop on the OS you are developing, that last option seems rife with paradoxes? So how you do it?

P.S.

My similar Quora question still has no answer to this question...


答:
I have previously worked at a (largish) bank, and there COBOL was used for all core banking logic, with anything outside of that being done in either Java or C#.  Although it's impossible for me to be sure about exact lines of code, I believe the 70% claim to be extremely dubious, in my experience.  It is possible COBOL is more verbose as vartec points out above, but in terms of functionality implemented, the Java and C# "auxiliary" software was handling far more.

As a a typical example, the COBOL code was in charge of actually creating accounts, calculating interest, generating basic statements, as well as business rules around managing of the state of an account (access / valid actions).  To be fair, that's not an insignificant amount of code - but compared to this, the "auxiliary" software was in charge of everything from receiving faxes, document splitting indexing, document storage / management, routing work to individuals, several thousand (sadly, yes) screens for data capture and managing the lengthy lifecycle of various processes that end in account creation, electronic interfaces to other companies and legal services, integration with the telephony platform, and many, many more functions.

Looking at it from this angle, I am fairly sure that the number would have been in favour of the Java / C# code, but again, I don't have any hard numbers to back up this claim.

Body:
I heard this number and a quick google search reveals a whole lot of touting this number and absolutely zero data (honestly most articles promoting COBOL read like 95% propoganda). Perhaps it's true in an extremely limited context of banking software or something, but with millions of applications coded in dozens of languages and near-zero new COBOL projects I don't see how this is possible.

Is this a myth from the 70s (when it would have seemed entirely plausible) or is there some limited definition where this is actually true? I know there is a great deal still being maintained and I'm sure a large % of businesses have at least one COBOL program around, but this invisible 70% seems absurd.


答:
CSS is not designed to be used as a selector. It's purpose is to mark similar items in markup, so that they can be styled in the same way across the document. Because jQuery (et al) is also related to styling, and functionality is often attached to similar items in markup, CSS selectors have become commonplace in that arena.

If this doesn't explain it then imagine what an XPath Stylesheet sould look like. Perhaps something like this:

```<code>/html/body/div/table/tr/td[3]/div {
    background-color: #800;
}
</code>```

Now, if you add a column to the table, or add a div into the structure, or maybe redefine the first div using HTML5's
 tag, you're going to have to go and redefine your style's path.

Or, in reverse, imagine having to put a CSS tag on everything, just so that you can find it. What a PITA that would be.

Body:
CSS is not designed to be used as a selector. It's purpose is to mark similar items in markup, so that they can be styled in the same way across the document. Because jQuery (et al) is also related to styling, and functionality is often attached to similar items in markup, CSS selectors have become commonplace in that arena.

If this doesn't explain it then imagine what an XPath Stylesheet sould look like. Perhaps something like this:

/html/body/div/table/tr/td[3]/div {
    background-color: #800;
}

Now, if you add a column to the table, or add a div into the structure, or maybe redefine the first div using HTML5's <article> tag, you're going to have to go and redefine your style's path.

Or, in reverse, imagine having to put a CSS tag on everything, just so that you can find it. What a PITA that would be.


答:
Ever since virtual machines like VMWare, KVM/Qemu or Virtualbox are widely (and freely for most) available, the job has become a lot easier.

Before that, boot managers like GRUB or LILO allowed control over what binaries to boot on (allowing you to keep at least one 'stable' OS on your machine).

I guess that before that, you'd have to dedicate a whole machine for your developments.


问:
ternary or something similar for choosing function?
I posted this question on stackoverflow and it got a poor reception. In reality, the problems I'm facing are minor and any workaround can be considered impractical. However, I believe it might be of general interest in the abstract computer science domain, so I'm giving it a go here.

I'm working with Drupal's automated testing in PHP. It's a class that has two methods I'm concerned about: pass() and fail(). Each one produces a separate line on a results page indicating whether a particular operation passed or failed, e.g.

```<code>if ( $value == "expected_value" ) {
  $this->pass("Name of Test");
} else {
  $this->fail("Name of Test");
}
</code>```

(The reason drupal does it this way is so that in the results, you can see "Name of Test" in a green bar if it passed, and in a red bar if it failed. In other words "Testing Feature A: failed" or "Test of Feature A: passed". Of course you can put two different messages in there, but in my situation, I want to put the same message in)

What I notice about the above is that it seems verbose, in that I repeat the same message twice. It seems to me that there should be a way of expressing this where I only declare the message once. Of course I could put it in a variable, but that takes up extra space and I pass it twice, also.

I'd like to do something like ternary assignment, only instead where I decide which function to call. Is there a way I can define this logic while only expressing Name of Test one time?

Something like:

```<code>$function = ($value == "expected_value") ? "pass" : "fail" ;
$this->$function("Name of Test");
</code>```

Is this the most concise, elegant way I can phrase this logic? I tried

```<code>$this->(($value == "expected_value") ? "pass" : "fail")("Name of Test");
</code>```

But I got a parse error. Is there a way to get it down to one line, like ternary assignment?

Edit Here's the best formulation of my question to date: "What's a syntax I can use, in any language or pseudo-code , to express this without saying Name of test twice?"

I feel like I should be able to express this logic without saying Name of Test twice (anywhere -- including within another function that I call elsewhere in code). It seems that PHP does not allow me to express this in this way, so I'm looking for examples in other languages (and people have already posted C, javascript, and python examples) that allow you to concisely express this without repeating yourself.

答:
Why not make a function that handles both cases, with a boolean argument to choose between them?  In the case of Simpletest, it appears you can just say this:</p>

```<code>$this->assertTrue($value == "expected_value", "Name of Test");
</code>```

Body:
Why not make a function that handles both cases, with a boolean argument to choose between them?  In the case of Simpletest, it appears you can just say this:

$this->assertTrue($value == "expected_value", "Name of Test");


问:
Are 9 to 5 programmers looked down upon?
I would consider myself a 9 to 5 programmer.  What I mean by this, is that I have a programming job, but after I leave work, I leave my work there and do not take it home.  I very much enjoy my career choice, and I enjoy the work that I do at my current job.  I also enjoy learning new things in my field, such as new technologies and advancements in the programming industry.  It's just that outside of my job I have other hobbies that I feel are more important and I'd like to devote more of my time and energies to.  I also feel that devoting >40 hours a week to a single subject is a little exhausting, so are there really that many programmers that want to come home from their programming job and do more programming?

Maybe it's just my current employer, but I feel like they leave little time for career development.  The only way for me to keep up on the newest technologies and programming techniques is to do so on my own time, because my employer does not allocate time during work hours to do these sorts of things (deadlines == $$$).  Does anyone else feel the same way about their employer?

From your experience, do managers and people who hire programmers see 9 to 5 programmers as a less valuable resource?  I know that I could improve my resume by contributing to and open source project etc, but I just feel like I don't have the time to spare.

Could the opposite be said, such that devoting your spare time to other subjects such as the arts show a well-rounded-ness that could be a desirable trait to the company?

答:
Using the amount of time someone spent at work as a measurement for production just seems like another lines of code that can easily be gamed. Many people just start doing personal things at work. They wait for better traffic, so they come to work sooner and leave later. Or they work in a downtown area and waste time until the pubs fill up.

I didn't get into the IT industry because I wanted to punch a time clock. The work I do is much easier on my body than the work my father did. Constantly being in a tit-for-tat with your employer is a bad sign. Even at 40 hrs a week, it's still too much time to waste in life doing something you don't enjoy.

There is time in life for family, friends and other interests. Some you can share with others, some you can't. There are others in my life that want to do things outside of their work day that don't involve me, so I can work or play. Sometimes my current job can offer both.

My career positively addresses many but not all needs in my life and I expect those around me to respect this. Oh, and I watch a lot of football.


问:
Is an ASP.NET site in a Linux environment possible?
I found some software a while ago that claimed to execute ASP.NET applications on a Linux server, I remember that the information said that takes the code and converts it to Java. I never downloaded or tested the software. Does anyone know the name of this software?

Also, is possible to execute ASP.NET on a Linux server in the first place?

答:
Yes, it is entirely possible to use ASP.NET in a linux environment using Mono. I've never done it, but I know it is possible.

I haven't heard of the software that you are talking about, however, so maybe somebody else can shed some light on that.


答:
The bipolar discussion here is simply ridiculous. It seems that there are only two options.

You're a 9-5 programmer

You're a dedicated life-long developer with no life.

Frankly, this is BS. There is an in-between. And it is a perfectly reasonable one. It is certainly possible to raise a family and be a good parent and spouse while still spending some time outside of normal working hours honing your craft.

Unless you are an unskilled laborer you should plan on spending time outside of working hours with some sort of continuing education. Doctors do it, teachers do it, programmers do it. You cannot expect to get through an entire career as a programmer without taking the initiative to learn new things, on your own. Technology changes. You need to change with it.  And if you think that it is your employer's responsibility to make sure you get the education you need to continue to be productive, then you are cracked. If that were true then employers would need to pay for our college degrees.

Some employers are better than others, of course. Some offer tuition assistance and other incentives to get you to learn more. But even then, most of that continuing education happens outside of working hours.

Skilled professional need to maintain their skills if they want to maintain their work. It is their responsibility to do that. It's much cheaper for an employer to hire a new worker with the appropriate skills than to pay an existing worker to learn the skills.

Yes, I look down on 9-5 programmers, or what I call "Daytime Developers" who have no interest in getting better at what they do on their own time. I am not suggesting that you need to neglect family or eat-breathe-drink programming. But spending a few hours a week reading, taking a night class, or practicing a new skill is not an unreasonable expectation.  I do it and I still have a great relationship with my wife and two children. We even have a third child on the way.

There is no reason that you can't be both a dedicated, skilled programming professional and a family-oriented person.


问:
Is Visual Studio Express suitable for commercial application development?
If I were to develop a Silverlight game and publish it to a site where you can play it for free is the use considered to be commercial or personal?

What about if the site has adverts on, is it then considered to be commercial if the program is free but its hosted on a site that makes money?

My reason for asking this is Visual Studio Express can only be used for personal or non-commercial use so I want to check what the limits for the use are.

答:
The Express editions of Visual Studio allow commercial use, so this is not a problem, one way or another.

I believe the only commercial use not allowed is using VS Express in a hosting service.

The original FAQ article that said so seems to have gone AWOL and this forum thread seems to be the next best thing (thanks @Anna Lear).


问:
Thread class design?
I have a method like this in my UI code:

```<code>void MyDialog::OnCommandSaveData()
{
    std::list<MyClass*> objects;
    service_->GetAll(objects);
    dataService_->SaveObjects(objects);
    AddMessage("Saved data.\n");
}
</code>```

Because this method can take some time, I want to kick off a thread to do this.  I'm using C++ and I plan on using Boost.Thread.  So my question is how to best do this.  My understanding is that I need to create a static function, static method, or functor which will contain the above code.  Where should this live, in the dialog class?  That just seems wrong, but then again maybe not.

And then I will need a mutex and lock around at least the SaveObjects method.  Where should the mutex live and where do I put the lock?

Most examples of threading, as with examples of so many things, don't show the threading in the context of a real application.  They show a main method with a global function and that's it.  So if you can point me to example of a class that manages threading for an operation that would be great.

I buy the logic in the accepted answer to this question: Is It "Wrong"/Bad Design To Put A Thread/Background Worker In A Class? However, the answer only tells you why to do it, not how.

UPDATE

I've refactored my code using MVP (Model View Presenter)/Humble Dialog Box pattern:

```<code>void MyDialog::OnCommandSaveData()
{
    presenter_->SaveData();
}
</code>```

So now I will need to look at adding multi-threading in the context of MVP.

UPDATE 2

I found this article which talks about creating mulithreaded winforms using MVP.  It's in C# so I'll have to translate it into C++ but it looks good:

http://aresterline.wordpress.com/2007/04/17/multi-threaded-winforms-application-mvp/

Basically it involves 1) creating a ThreadSafeView which is a wrapper or proxy around your view that allows your view to be updated from a worker thread. And 2) creating a ThreadedPresenter which allows presenter methods to spawned in a new thread.  I really like how this isolates the threading code from the view and the presenter code.

答:
My understanding is that I need to create a static function, static method, or functor which will contain the above code. Where should this live, in the dialog class?

It doesn't have to live anywhere; you can simply create a functor and pass it to the thread. To spawn a thread that executes that member function on the current object, and then exits:

```<code>boost::thread thread(boost::bind(&MyDialog::OnCommandSaveData, this));
</code>```

And then I will need a mutex and lock around at least the SaveObjects method. Where should the mutex live and where do I put the lock?

It's usually best to keep a mutex next to the object it's protecting; in this case, a member of MyDialog.

Title: Thread class design?

Body:
My understanding is that I need to create a static function, static method, or functor which will contain the above code. Where should this live, in the dialog class?

It doesn't have to live anywhere; you can simply create a functor and pass it to the thread. To spawn a thread that executes that member function on the current object, and then exits:

boost::thread thread(boost::bind(&MyDialog::OnCommandSaveData, this));

And then I will need a mutex and lock around at least the SaveObjects method. Where should the mutex live and where do I put the lock?

It's usually best to keep a mutex next to the object it's protecting; in this case, a member of MyDialog.


答:
I'm going to answer the question:

Yes, programmers who program only 9-5, or whatever hours are necessary to complete their job, are looked down on by a substantial number of programmers.

As to why this should be, I have no idea. No other profession that I know of has this strange idea. We don't expect policemen to go hunting criminals on their own time, or firefighters to put out extra fires. Nor is it a good thing. Plenty of excellent programmers do their job extremely well, and then go home to their families.

However in my experience managers actually understand this better than programmers. Almost no hiring managers will look on lack of outside projects as a negative. They will look on outside projects as a positive only in the sense that skills learned through those projects improves someone's hireability. The mere willingness to do outside projects isn't a positive.

Note that I'm not talking about improving your skills or learning outside of work. Almost every profession - doctors, teachers, lawyers - expects its practitioners to put in some extra time learning outside of strict work hours. That's part of being a professional rather than an assembly line worker. But some programmers seem to have this bizarre idea that if you don't have side-projects then you are not a real programmer.

Body:
I would consider myself a 9 to 5 programmer.  What I mean by this, is that I have a programming job, but after I leave work, I leave my work there and do not take it home.  I very much enjoy my career choice, and I enjoy the work that I do at my current job.  I also enjoy learning new things in my field, such as new technologies and advancements in the programming industry.  It's just that outside of my job I have other hobbies that I feel are more important and I'd like to devote more of my time and energies to.  I also feel that devoting >40 hours a week to a single subject is a little exhausting, so are there really that many programmers that want to come home from their programming job and do more programming?

Maybe it's just my current employer, but I feel like they leave little time for career development.  The only way for me to keep up on the newest technologies and programming techniques is to do so on my own time, because my employer does not allocate time during work hours to do these sorts of things (deadlines == $$$).  Does anyone else feel the same way about their employer?

From your experience, do managers and people who hire programmers see 9 to 5 programmers as a less valuable resource?  I know that I could improve my resume by contributing to and open source project etc, but I just feel like I don't have the time to spare.

Could the opposite be said, such that devoting your spare time to other subjects such as the arts show a well-rounded-ness that could be a desirable trait to the company?


问:
Why is naming a table's Primary Key column "Id" considered bad practice?
My t-sql teacher told us that naming our PK column "Id" is considered bad practice without any further explanations.

Why is naming a table PK column "Id" is considered bad practice?

答:
There are some answers that approach what I would consider the most important reason for not using "id" as the column name for the primary key in a table: namely consistency and reduced ambiguity.

However, for me the key benefit is realized by the maintenance programmer, in particular one who was not involved with the original development.  If you used the name "PersonID" for the ID in the Person table and consistently used that name as a foreign key, it is trivial to write a query against the schema to find out what tables have PersonID without having to infer that "PersonID" is the name used when it is a foreign key.  Remember,  right or wrong, foreign key relationships are not always enforced in all projects.

There is an edge case where one table may need to have two foreign keys to the same table, but in such cases I would put the original key name as the suffix name for the column, so a wildcard match, %PersonID, could easily find those instances as well.

Yes, much of this could be accomplished by a standard of having "id" and knowing to always use it as "tableNameID", but that requires both knowing that the practice is in place and depending on the original developers to follow through with a less intuitive standard practice.

While some people have pointed out that it does require some extra key strokes to write out the longer column names, I would posit that writing the code is only a small fraction of the active life of the program.  If saving developer keystrokes was the goal, comments should never be written.

As someone who has spent many years maintaining large projects with hundreds of tables, I would strongly prefer consistent names for a key across tables.