问:
Should I teach my students alloca?
How widely used is alloca in the real world? Should I teach my students to use alloca when it makes sense? Or should I teach them never to use it? Coming from a C++ RAII background, the idea of not having to call free manually sounds promising, especially in functions with multiple exit points.

答:
If you are holding a course in general C programming, you shouldn't teach them a thing that is not in the standard. Beginner programmers needlessly writing non-standard and/or non-portable code because they were taught that way, has been a huge problem for the software industry during the past 20-30 years or so. The cost for not teaching them the standard and nothing but the standard is likely astronomic.

If you are holding a more advanced course in algorithms or application programming, it might be good to mention it. On the other hand, I have programmed everything from hard realtime embedded apps to Windows application fluff for 15 years without ever using that function.

OwnerDisplayName: FredOverflow

Title: Should I teach my students alloca?


问:
How can I start testing in a testing anticulture?
I have a confession to make: Formalized automated testing was never a part of my programming background. I now work in a very large company with many developers (most of them web developers of one sort or another), and it's apparent that most of them don't test* either. (*I'm not going to keep saying formally; please infer it.)

If I wait to have the support of my organization to begin testing it will never happen. If I try to "change things from the inside" by pushing testing at management I will run out of steam before change happens. I need to start testing now.

But with TDD and its ilk I'm going to end up with lots of testing code right along with the production code. Our version control systems (all centralized) aren't organized for storing testing code. I'll have to find a place for all that on my workstation.

Is it possible to begin a personal practice of software testing in a culture that doesn't value or provide the tools for it? What techniques and tools do you use to enable you to test when the official tools and organization don't have a place for tests, frameworks and automations?

答:
In my experience if the culture is anti-testing, you can't reasonably introduce it.  Either the tests will be seen as a waste of time and you'll be reprimanded for "wasting time" or "taking too long", or the code has festered from years of not being written in a testable way (e.g. no interfaces, everything tightly coupled) and you'll have to spend a lot of time refactoring and/or rewriting code (thus running the risk of "taking too long" and "wasting time") to make it testable so you can write tests in the first place.

You might have a chance if you're doing greenfield stuff that only has to interact with existing things (create a nice wrapper around the bad areas) or if you can do it in small quantities where it won't cause issues or require you to "work on tasks not assigned to you" which can put you in the doghouse.

ContentLicense: CC BY-SA 3.0


答:
The answer to this question should be based on what your objectives are in the first place.

Do you want to teach someone who already knows how to program how to write C and work with existing C code in the wild? If so, tell about alloca and anything else you want.

On the other hand, if you are teaching an introductory course that only is using C by coincidence (and because C is a very small language and so on) you should focus on the important parts (writing modular programs, subroutines, collections, ...).
From a student's perspective, alloca is a bir redundant since malloc is enough in most cases and from a good-code perspective you are better off explicitely mentioning how manual memory management is annoying and how other languages deal with this problem After all, there are more things to memory management then alloca or RAII so you really shouldn't restrict yourself to these and as you mentioned already, its much easier  to understand the purpose of alloca if you compare it to other "more standard" ways to do things in other languages (or C99...)

Title: Should I teach my students alloca?

Body: How widely used is alloca in the real world? Should I teach my students to use alloca when it makes sense? Or should I teach them never to use it? Coming from a C++ RAII background, the idea of not having to call free manually sounds promising, especially in functions with multiple exit points.


答:
I can see two things happening:

The students understand the impact of alloca, read about the differences between stack and heap, and use alloca carefully. (unlikely)

The students think "wow, this is like malloc without worrying about the free," use it excessively, get stack overflow, and have no idea what's up.

I think it's much better if you describe alloca, then run this code:

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

int OverflowMyStack(int start) {
    if (start == 0)
        return 0;

    char * p = (char *)_alloca(4096);
    *p = '0';
    return OverflowMyStack(start - 1);
}

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

Source: http://www.strchr.com/alloca

show them the dangers, and then tell them not to use it. They'll still learn about stack vs. heap, see the perils in action, and can move on with standard stuff.

Title: Should I teach my students alloca?

Body:
I can see two things happening:

The students understand the impact of alloca, read about the differences between stack and heap, and use alloca carefully. (unlikely)

The students think "wow, this is like malloc without worrying about the free," use it excessively, get stack overflow, and have no idea what's up.

I think it's much better if you describe alloca, then run this code:

#include <malloc.h>

int OverflowMyStack(int start) {
    if (start == 0)
        return 0;

    char * p = (char *)_alloca(4096);
    *p = '0';
    return OverflowMyStack(start - 1);
}

int main () {
    return OverflowMyStack(512);
}

Source: http://www.strchr.com/alloca

show them the dangers, and then tell them not to use it. They'll still learn about stack vs. heap, see the perils in action, and can move on with standard stuff.


答:
Without management support you are dead in the water.  Management will claim that you are not doing worthwhile work, you will get penalised in your reviews, and finally you will get fired.  There are ways to bring management to see that early testing costs them less and all that.  It is possible to change the culture but you are putting your neck on the chopping block.

I would suggest reading Machiavelli The Prince chapter on how to introduce change before doing anything.

Title: How can I start testing in a testing anticulture?

Body:
I have a confession to make: Formalized automated testing was never a part of my programming background. I now work in a very large company with many developers (most of them web developers of one sort or another), and it's apparent that most of them don't test* either. (*I'm not going to keep saying formally; please infer it.)

If I wait to have the support of my organization to begin testing it will never happen. If I try to "change things from the inside" by pushing testing at management I will run out of steam before change happens. I need to start testing now.

But with TDD and its ilk I'm going to end up with lots of testing code right along with the production code. Our version control systems (all centralized) aren't organized for storing testing code. I'll have to find a place for all that on my workstation.

Is it possible to begin a personal practice of software testing in a culture that doesn't value or provide the tools for it? What techniques and tools do you use to enable you to test when the official tools and organization don't have a place for tests, frameworks and automations?


问:
Does Node.js actually increase scalability?
I've been reading about the C10K Problem, and of particular note is the part that refers to asynchronous server I/O. http://www.kegel.com/c10k.html#aio

I believe this pretty much summarises what Node.js does on the server, by allowing threads to process user requests whilst relying on I/O interrupts (events) to notify threads of jobs that are completed, rather than have the thread be responsible for the full CPU job. The thread can get on with other things (non-blocking), and be notified of when a job is done (e.g. a file is found or a video is compressed).

This subsequently means that a thread is more 'available' to sockets and therefore to users on the server.

Then I found this: http://teddziuba.com/2011/10/straight-talk-on-event-loops.html

The writer here claims that although the event driven framework (interrupted threading), may free up threads, it doesn't actually reduce the amount of work a CPU has to do! The rationale here is that if, say, a user requests to compress a video they uploaded, the CPU still has to actually do this job, and will be blocking while it does it (for simplicity's sake, lets forget about parallelism here - unless you know better!).

I'm a straightforward coder, not a server admin or anything like that. I'm just interested to know: is Node.js a gift from the gods of 'cloud computing' or is it all hot air, and won't actually save companies time and/or money by improving scalability?

Many thanks.

答:
Of course any CPU bound work is going to utilize the CPU. It's going to block the CPU in whatever language or framework you write it in.

Node.js is great for when you have I/O bound work, not CPU bound. I wouldn't do heavy lifting in Node, though it can be done. Node.js solves real problems, not fictional or imagined ones like fibonacci number servers. It's not “hot air”.


问:
The usual metadata objects or: How to move a typical ExtJS App to jQuery, and: What's missing in the middle?
I have entered into an existing project that is all about maintaining nested data structures. You have companies which are assigend to accounts, and contacts and notes and... basically the usual bunch of 1:1, 1..n, n:m Database relations, stored in mysql or postgres, wrapped by Doctrine.

Of course, every node comes with the usual set of metadata, that needs validation in terms of type (number, text, ...) and semantically (email, url, 'enums' like status, type, currency).

More specifically what I stepped into I would describe (also from previous experience) as typical ExtJS hell. Does this sound familiar to anyone?

a typical single URL-Application: No history, no meaningful specific bookmarks, oh and dare you pressing the back button...

tabbed browsing is impossible (the not so rare use case of looking at Customer A, while entering something meaningful into Account or Customer B side-by-side)

you have that typical navigation tree on the left, the stuff on the right is called in by Ajax. Data, but also a lot of executable java code.

a strong "MS Office feel": CSS sprites are far, far way, simple pullDowns and multiple-Choice buttons need effort to be 'dressed down' to be usable.

Not to mention all the clobbered div-s as opossed to few clean, semantically meaningful tags

a hell of javascript (some of it quite akwardly created in PHP) to suit hard-to-debug controllers and stores and plenty of redundant code, to ensure the same thing over and over again for the various data fields.Sure, there is OOP class hierarchy for those Ext.[ux.]grids and windows, but of limited help.

From previous experience I would LOVE to switch this to a straight REST-ful API, stuff is actually done between page request, the URl gives it to you just as it should look:

```<code>foo.com/accounts/16324/contact/create
foo.com/customer/search/state=California
</code>```

And make the whole think jQuery-based, where I gain more control.
That brings me to my general question: Do I miss a middle layer?

Trouble: I wonder, how to fill certain gaps (that other 'Converts' are likely to encounter, too, hence I dare to ask such broad question):

what plugins would be good for (editable) tables? Including resizable, sortable comments? I know about jQueryUI and jQueryTools but I don't think that alone fits the bill. I need a really good table/grid think, probably with backend routines that fit.

*Generally speaking, I feel, that I miss a middle layer between ORM and UI if I tinker with data structures, can I bring some automatism like "Here's my data structure, including types and validation rules, (oh, and the exisiting/default data) now build the form from it" Since this might vary from customer to customer, is another reason to not complete hardcode this to much.

Also the Ext-JS-ish store functionaliy of only sending back fields that truly changed would be worthwhile. As is recognizing dirty-ness (aka the need to confirm 'save/cancel' on dialog closing).*

Very valuable would be generic mechanisms of "tentativene sub-Dialogs", e.g. Windows Screensaver do: So going into a Menu, from there to a submenu, saying ok on sub-dialog, then cancel on main ==> cancels the whole thing, nothing stored. In other words: Storing a few hierarchical data sets flexibly in the Session would be good. And pushing them into the DB (by repetive, generic means) when I got the actual "OK".

Any good pointers for me the table-editing part in the frontend and/or the data-structure middle part?

Thank you, Danke, Merci, Mille grazie, Xie xie!

Fronker

答:
... as typical ExtJS hell. Does this sound familiar to anyone?

a typical single URL-Application: No history, no meaningful specific bookmarks, oh and dare you pressing the back button...

It sounds like a nostalgic rant for simpler times.

tabbed browsing is impossible (the not so rare use case of looking at Customer A, while entering something meaningful into Account or Customer B side-by-side)

This is definitely possible; you can use ExtJS to create tabs or modify your links to do a full page refresh.

a hell of javascript (some of it quite akwardly created in PHP) to suit hard-to-debug controllers and stores and plenty of redundant code, to ensure the same thing over and over again for the various data fields.Sure, there is OOP class hierarchy for those Ext.[ux.]grids and windows, but of limited help.

This is just poor practice, independent of ExtJS.  You should move all the JavaScript to the client side, clean it up, and then decide your next move.  Switching to jQuery won't solve this problem.  Sure, jQuery is simpler, but it sounds like you are relying on features of ExtJS that will be difficult to build with jQuery.

It sounds like you are new to ExtJS and reacting to the unfortunately steep learning curve.  You should try righting the ship before abandoning it.


问:
How to account for a bug fixing iteration?
We have implemented Scrum quite successfully for the past 5 months. Though, we are 3 weeks away from PROD without ever doing any end-to-end integration test. OUCH! I need help. Without tackling the causes of this (at THIS point), we need now to plan the current iteration, which consists of minor improvements and MANY still unknown bug fixes. How do you account for this scenario? How do you plan your iteration to fix bugs yet to be found?

答:
We don't plan 'bug fix iterations', but we do plan system test iterations before each release. System test is integration, regression and realese tests on all parts of the product. Testers test the product (a fairly large legacy system) and developers fix any bugs that are found. If no bugs are found we either start investigating features schedules for next project or work on internal improvements. </p>

<p>Currently, we plan for six weeks of system tests after code freeze (for a five month project, system test included), to make sure everything works. This is on top of all the testing that is done during the implementation iterations. </p>

Body:
We don't plan 'bug fix iterations', but we do plan system test iterations before each release. System test is integration, regression and realese tests on all parts of the product. Testers test the product (a fairly large legacy system) and developers fix any bugs that are found. If no bugs are found we either start investigating features schedules for next project or work on internal improvements.

Currently, we plan for six weeks of system tests after code freeze (for a five month project, system test included), to make sure everything works. This is on top of all the testing that is done during the implementation iterations.


问:
How should I go about learning PHP given a background in C#.NET?
I have developed a few websites and applications using C#, and lately I've been developing a website in ASP.NET MVC. To be honest, this has pissed me off somewhat as it has me feeling like I have zero knowledge. So many things work under the hood in .NET that I'm just not able to focus and understand what is left to the developer and how these things are done.

Now, the question that prompted me to make this post is: How should I proceed for learning PHP from a very basic standpoint? Mind you, I have no idea about this language at all, just seen some code and heard people talking.

答:
Start by learning basics of PHP. There are a lot of books for PHP and it's syntax is not so complicated so you will probably pick up basic stuff pretty quickly. You can then start learning about some framework e.g. Symfony or Zend framework.

I would suggest you to find a good IDE to work in because it's pretty frustrating when you need to do everything manually (Zend Studio is great IDE if you're using Zend framework).


问:
How do I unit test a web forms site?
How do I unit test a web forms site? It seems to me that as so much of it depends on state and user input it wouldn't be feasible. </p>

<p>If it's not feasible is there a valid automated alternative? </p>

答:
ASP.NET

When developing an ASP.NET site we were able to run unit tests on:

The domain

BL controllers/presenters

the codebehind of Web Forms pages

It is possible to TDD all of this, depending on your architecture. The only thing you cannot unit test is the layout of the markup file.

Title: How do I unit test a web forms site?


问:
What are the pros and cons of the MVVM architecture?
In class today we were introduced to the MVVM architecture for Silverlight/WinPhone/WPF; it looks nice for big projects, but what are your thoughts on MVVM?

What are the pros and cons?

I want to get more into the architecture so that I know when I should use it.

答:
In my experience small projects that are successful become big projects.  So always assume your project will be a success and plan for the future.  Design it is such a way that you can add on functionality with out forcing it in. </p>

<p>So MVVM is a great tool for just that.  Once you set up a few projects and get the hang of it you will find there really is not that much overhead it is just shifting the work from as you go to up front. And once you are ready to go you can take off and create your application.  As for when to use it anytime you need a robust dynamic user interface.  </p>

Body:
In my experience small projects that are successful become big projects.  So always assume your project will be a success and plan for the future.  Design it is such a way that you can add on functionality with out forcing it in.

So MVVM is a great tool for just that.  Once you set up a few projects and get the hang of it you will find there really is not that much overhead it is just shifting the work from as you go to up front. And once you are ready to go you can take off and create your application.  As for when to use it anytime you need a robust dynamic user interface.


答:
No.

The only reason a C programmer should even be aware of alloca's existence is to understand and fix legacy code that's using it.

Any use of alloca is either

Useless, i.e. it could trivially be replaced by fixed-size variables of automatic storage duration, OR

A dangerous stack overflow waiting to happen.

Aside from a few thought experiments for which I have never found any real-world examples, there is no usage case for alloca (or VLA's) that's not either useless or vulnerable (one of the above 2 cases).

Title: Should I teach my students alloca?


问:
Why was Python's popularity so sudden?
Python first appeared in 1991, but it was somewhat unknown until 2004, if the TIOBE rankings quantify anything meaningful.

What happened?  What caused the interest in this 13 year old language to go through the roof? Is there a reason that Python wasn't considered a real competitor to Perl in its first decade of existence? Is there a reason that Python didn't continue in relative obscurity for another ten years?

I personally think that Python is a very nice language, and I'm glad that I'm not the only one. But it doesn't have corporate backing or a killer feature that would explain a sudden rise to relevance.

Does anyone know the story?

答: The community around it reached critical mass. It's very hard to overcome the barrier of popularity, and it's not really unexpected that it happens very suddenly.</p>

Title: Why was Python's popularity so sudden?


答: While the C10K paper is somewhat out of date with regards to implementation details, event-based concurrency (the reactor model) is still in some ways superior to preemptive scheduling. For example, a preemptive scheduling model may schedule threads while they are IO blocked. This allows node (and other tools like Ruby's Event Machine and Python's Twisted) to better use available cycles by spending more time doing real work and less time blocking.</p>

Title: Does Node.js actually increase scalability?

Body:
I've been reading about the C10K Problem, and of particular note is the part that refers to asynchronous server I/O. http://www.kegel.com/c10k.html#aio

I believe this pretty much summarises what Node.js does on the server, by allowing threads to process user requests whilst relying on I/O interrupts (events) to notify threads of jobs that are completed, rather than have the thread be responsible for the full CPU job. The thread can get on with other things (non-blocking), and be notified of when a job is done (e.g. a file is found or a video is compressed).

This subsequently means that a thread is more 'available' to sockets and therefore to users on the server.

Then I found this: http://teddziuba.com/2011/10/straight-talk-on-event-loops.html

The writer here claims that although the event driven framework (interrupted threading), may free up threads, it doesn't actually reduce the amount of work a CPU has to do! The rationale here is that if, say, a user requests to compress a video they uploaded, the CPU still has to actually do this job, and will be blocking while it does it (for simplicity's sake, lets forget about parallelism here - unless you know better!).

I'm a straightforward coder, not a server admin or anything like that. I'm just interested to know: is Node.js a gift from the gods of 'cloud computing' or is it all hot air, and won't actually save companies time and/or money by improving scalability?

Many thanks.


问:
Why use phpunit when traditional manual testing can be used
When I make a web app I test my work on the browser to see if I receive any errors and fix them. I have made complex applications and testing this way has been easy and fast. I have watched many videos on youtube regarding phpunit and cannot find a purpose for it. Why is this library useful? Is phpunit more for php framworks like cakephp or zend? I dont use any framework just core php. Would or can phpunit be useful for me? If yes, how?

There is also xdebug but I'm not sure if it relates.

答:
Let's say that you wanted to manually test your application every time that you deployed it. How would you go about doing that?

Well, to start with, you might make a list of all the things you want to test so you wouldn't forget to test something later on. Then you would probably write the steps for each test to make sure that you did them the same way each time. If you didn't make sure the testing process you used was consistent, your results wouldn't be consistent.

So, now that you have the list of tests you need to perform, you would open your browser, read the first test's steps, perform them, and make a note of the result. You would repeat this process for each test in your list.

The number of tests you perform would continue to grow as your application grows and as you find new bugs. You would, of course, be limited to performing these tests at human speed, making them rather slow.

The irony here is that in mechanically stepping through a list of operations, you are computing. You're just doing it way more slowly than, say, a computer would.

This, among many other good reasons, is why we write unit tests: they let the computer do the computing so you don't have to.

I can run a comprehensive unit test suite fast enough to use it frequently during development, not just once a week before deploying. This lets me detect errors more quickly, saving me time and money.

I can even write tests that predict the behavior of the system and then write that behavior (which I already know is correct because I just tested it), a process known as Test Driven Development.


问:
What language should be used to teach object-oriented design and development in university?
My understanding is that C++ is usually offered as the 1st OOP language, and as the 2nd programming language (after C) in my country (Bangladesh). I've taught it several times, and the problem I've run into is that students often tend to think C++ as an extension of C, i.e. C with cin and cout!
This has lead me to think about teaching Java as the first OOP language in the upcoming semester.

What is your opinion? I would like some suggestions from professional programmers as well as academics.

答:
I believe the choice of language is less important than the set of librariries. Let me clarify.

I had several C++ classes (1st OO language) at the Univ. This is where I was taught OO mechanisms such as inheritance and polymorphism, but a I was lacking a "working" understanding of OO. I feel I truly started understanding how to write OO programs (everything is an object, objects talk to each other, etc...) only after I started a larger java project, where I had to use the JDK libraries. In C++ it always seemed I could get away with large procedural chunks tucked away in non-objects.

I assume I would get the same effect (ie working with objects) from using the STL on the C++ side.


答:
I don't think you'll get very far until you can make a good enough case that there's a problem (that may not currently be recognised) that automated testing can address.

If there's a culture of manual testing against defined scripts, then there's a cost of executing those scripts coupled with a risk of incomplete or inaccurate results. There may be a history (documented or in "war story" form) of this. Suggest a pilot project to automate some of those manual tests with a view to delivering a long-term cost saving.

If there's not even a manual testing function then I'd suggest that the business doesn't perceive that any kind of formal testing, automated or otherwise, has value. In that case I'd consider the road ahead to be long and steeply uphill, but again it's likely to need a clear demonstration that the business can benefit from adopting a less casual approach to software quality. If you can't do that then it's hard to see how there could be any support for the idea on commercial grounds.


答:
I would say it depends on the degree.

I would teach C# or Java for CIS/MIS because this is what is used when programming real world business applications in today's market.

C++, Scala, or Smalltalk for CS students. There are many educational programming languages designed to both teach and enforce OOP.

Title: What language should be used to teach object-oriented design and development in university?

Body:
My understanding is that C++ is usually offered as the 1st OOP language, and as the 2nd programming language (after C) in my country (Bangladesh). I've taught it several times, and the problem I've run into is that students often tend to think C++ as an extension of C, i.e. C with cin and cout!
This has lead me to think about teaching Java as the first OOP language in the upcoming semester.

What is your opinion? I would like some suggestions from professional programmers as well as academics.


问:
How to include rookie developers into your project?
We're considering teaching some employees who have either zero or general hobbyist level programming experience to take workload off me.

We use Python/Django which has some of the friendliest documentation around and a breeze to learn.

I'm currently a one man IT department for my company and I don't have enough hours to develop everything the company needs. We are not a software company, but it helps to have in house IT to automate tasks, develop customer service features, analyze data, etc.

How do you slowly integrate rookies working on your codebase? Say you have an intern - what do they do? I'm completely reluctant to let them design or develop core code as we'll be dealing with their mistakes / strange design patterns for years. As the primary developer, I'll be the one who has to work around their code.

My thought was to have rookies only modify existing code, never building core features. I can offload work to them with simple tasks after I build the feature itself.

We'd like our employees to learn / find value in the company, and we generally have people 'move up the ranks'.

Is it standard practice to teach people with general/hobbyist level programming? How does the "moving up the ranks" in a software company work for junior level programmers? When do they start working on core code?

I'm trying to decide if it's going to cause more damage than help, and or if there's a way we can use their help without potentially risking core site code (isolated environments?).

答:
I used to work at a software shop, where we were coding a large project (significant ramp-up time).

Rookies were treated like vets. They were assigned a technical leader and started features "on their own". The architecture style was dictated, but they were free to come up with their own clean design. The "strange design patterns" were weeded out during (daily) peer code reviews.

One mistake I have seen in another shop: assume "core" is hard and "ui" is easy. Rookies had an easier time in the core, and messed up the UI front-end code.

Good luck!


答:
If you delegate the rookie to an ineffectual role he/she will never learn anything substantial, and they certainly will not be too terribly useful to you.

Let me give you a word of advice, my first IT job out of school was at a relatively small manufacturing firm where I was going to be working on software to assist sales engineers in writing quotes for various projects.  I was also supposed to assist the IT guy who single handedly managed IT for the whole company.

The guy was a stressed out overworked mess, and the worst micro-managing perfectionist I have ever worked under.  I was supposed to lighten his workload but he spent almost as much time worryingly checking up on me and my work as I was spending working (he almost never left the office, I think he despised his family).  If I made so much as a single mistake he would completely lose his mind and start throwing a tantrum about, "I knew I shouldn't have trusted you with this, it was too important!" and other rants.

The point I am trying to make is to NOT be that way.  Not only will it make the rookies miserable and destroy their morale, you will be burning the candle at both ends worrying about their work.

Give them a chance to prove themselves but have formal technical specifications, design reviews, and code reviews.  Also you can test what they produce to make sure it meets requirements.

I think you will be surprised how capable some of them can be.

Title: How to include rookie developers into your project?

Body:
We're considering teaching some employees who have either zero or general hobbyist level programming experience to take workload off me.

We use Python/Django which has some of the friendliest documentation around and a breeze to learn.

I'm currently a one man IT department for my company and I don't have enough hours to develop everything the company needs. We are not a software company, but it helps to have in house IT to automate tasks, develop customer service features, analyze data, etc.

How do you slowly integrate rookies working on your codebase? Say you have an intern - what do they do? I'm completely reluctant to let them design or develop core code as we'll be dealing with their mistakes / strange design patterns for years. As the primary developer, I'll be the one who has to work around their code.

My thought was to have rookies only modify existing code, never building core features. I can offload work to them with simple tasks after I build the feature itself.

We'd like our employees to learn / find value in the company, and we generally have people 'move up the ranks'.

Is it standard practice to teach people with general/hobbyist level programming? How does the "moving up the ranks" in a software company work for junior level programmers? When do they start working on core code?

I'm trying to decide if it's going to cause more damage than help, and or if there's a way we can use their help without potentially risking core site code (isolated environments?).


答:
It depends on your primary emphasis. If you're primarily interested in teaching programming, with some OO language as the vehicle, then C++ would be preferred. If you're primarily interested in teaching OO, with programming more or less secondary, then Java is probably preferred. Based on your comments, the latter seems to be the case.

Edit: I should add that IMO, teaching OO as a concept in itself is mostly a mistake. I think the real concept is generic programming, with OO as a special/specific case of one limited form of generic programming. From that viewpoint, C++ is clearly preferable.


答:
How can your company afford to take time away from other employees, but not hire someone with programming experience? The amount of your time training, trouble-shooting and hand holding along is costly.

The only thing I've ever done in this area is to teach people how to use a report writer or maybe some VBA/Macro code for Excel. I usually give the data sets to reuse. Having them learn SQL is a stretch, but I've seen it done (Paid for them to get outside training.) Most of these people were financial analysts who have the ability to learn to code, but may not have taken the time. Trying this with some people in operations is a long-shot.

Make sure you get the right person and they really want to learn to code. You won't have time to teach them everything. They'll have to do a lot on their own.


问:
What are the biggest differences between F# and Scala?
F# and Scala are both functional programming langugages that don't force the developer to only use immutable datatypes. They both have support for objects, can use libraries written in other languages and run on a virtual machine. Both languages seem to be based on ML.

What are the biggest differences between F# and Scala despite the fact that F# is designed for .NET and Scala for the Java platform?

答: One small but important points is the license: Scala is BSD (pretty much the most permissive free software license there is), F#  used to be "Microsoft Research Shared Source license agreement" but is a commercial product nowadays (according to @Lorenzo below, although I couldn't find more specific license agreements anywhere).</p>

ContentLicense: CC BY-SA 2.5


问:
How can I display a diff result in a single file or document?
I'm reviewing my peer's code. I use SourceGear DiffMerge as my diff program, on a Windows environment.

While I'm using the diff program, I can clearly see the code changes, etc.

Is it possible to save the diff display somehow, with all its colorful rendering and strike-throughs so that I can send my comments by mail?

In other words, is it possible to export the diff display to a single file (which includes all the relevant data) to be displayed without the actual need to save the two files separately? (Perhaps HTML is fit for this job).

Can you recommend on a diff program that can export the diff as a single file?

Thanks in advance!

答:
WinMerge can diff compare any file(s) or folder(s) and generate a report (Tools > Generate Report) of differences in various formats (including HTML and CSV).

You can generate a report add your own comments into the results.  Run the report at the file level to get a colored diff compare.

Ultimately, the best method does depend on your tools (which you did not specify).  TFS has some powerful diff tools.  TFS is also highly extensible, lots of plugins you can download.


答:
You want to start by giving them small, discrete pieces functionality to implement. Define the input you promise and the output you expect, and let them connect the dots. And then use team-lead code review to ensure quality, and peer review to train them to learn from each other and to teach themselves.

This assumes that you have an overall application architecture that allows for atomic units of logic to be built in a decoupled way. If not, you're headed for a world of grief as multiple developers work in it--that would be the case even with old pros.

Inevitably you'll have certain people who take to it, learn quick, and rise up. Make sure you keep feeding them tasks that are just a small step beyond their current capability. Nothing educates somebody like a task that starts out impossible. Inevitably you'll have some people who try and never really catch hold of it. Those people should be thanked for their efforts and gracefully transitioned to something else.


问:
How  'simple' is a real KISS solution?
I confess: I have a problem to "Keep It Simple and Short" most of the time because trying to make it according to the books I have read, design-patterns I have heard etc. gives me such an enthusiasm -an enthusiasm coming from the sense of that I am on the right path to a probable perfection.

On the other hand, yes, it puts an extra stress on me in terms of delivering the deadlines sometimes...

But whenever I say to myself, "Next time keep it simple, you stupid!" I find it quiet hard to make it "simple" when that next-time comes, because it starts to feel weird... and uncomfortable after a point.

Then I start to judge my understanding of 'simple'...

Does SIMPLE mean too short that it works but hard to maintain and extend?

Does SIMPLE mean breaking many of the OOP principles?

Does SIMPLE mean cheating?

Does SIMPLE mean just keeping the deadlines without no dealy? etc.

Actually, what is it?

Question is: Can you write the EXACT definition of SIMPLE in terms of KISS principle? -if there is.

Thanks!

答:
Let's learn a french KISS:

La perfection est atteinte, non pas lorsqu'il n'y a plus rien à
  ajouter, mais lorsqu'il n'y a plus rien à retirer. — Antoine de Saint-Exupéry

Which is translated to:

Perfection is achieved, not when there is nothing more to add, but
  when there is nothing left to take away. — Antoine de Saint-Exupéry

OwnerDisplayName: pencilCake

Title: How  'simple' is a real KISS solution?


答: Whenever I want to save diff results to a file, I use sdiff Unix/Linux/Cygwin utility. No color but still human readable.

Title: How can I display a diff result in a single file or document?

Body:
I'm reviewing my peer's code. I use SourceGear DiffMerge as my diff program, on a Windows environment.

While I'm using the diff program, I can clearly see the code changes, etc.

Is it possible to save the diff display somehow, with all its colorful rendering and strike-throughs so that I can send my comments by mail?

In other words, is it possible to export the diff display to a single file (which includes all the relevant data) to be displayed without the actual need to save the two files separately? (Perhaps HTML is fit for this job).

Can you recommend on a diff program that can export the diff as a single file?

Thanks in advance!


问:
Do ORM POCOs replace domain entities?
This is somewhat similar to this question but more broad.

In general, with ORMs like EF 4.1 supporting POCOs, does it now make sense to have your domain entities be the objects that are persisted to your database?

With older ORMs like EF 4 or Linq-to-SQL, your "database objects" were auto-generated, and tightly coupled to your database, and so, for non-trivial applications, were mapped to more robust, intelligent domain entities before being put to work.

Is the idea with newer ORMs to just build robust domain entities, and then have a data-layer that simply provides a mapping between said domain entities and your DBMS?

In writing that I get the feeling that this has always been the goal, but not readily (easily) possible with the tools available, at least not in the .NET world.

答:
I think the general goal with ORMs is that the database is mapped directly to domain objects, which are ideally POCOs.  So the answer to your question is yes.  Now that EF is capable of mapping to POCOs it is ideal to consider those POCOs as domain entities.  For other ORMs such as NHibernate this has been possible for awhile and I believe people have generally been using them as such.

But this goal of having domain entities directly mapped to the database isn't always achievable.  There are some cases where there is a significant translation needed between the database and the domain model.  The ORM may not be capable of doing the translation.  In this case you might want a layer of intermediate POCOs that are mapped with the ORM to the database and then a translation layer that changes them into domain POCOs and back again.

Title: Do ORM POCOs replace domain entities?


答: @louisgab was right about code review. That would be my first step too. One critical thing that will hel you is to make sure they have to fix thier own mistakes whether you find them in code review or later. They won;t even realize they are making mistakes unless they have to fix them. MAke sure also to explain why the solution they used is a mistake and why what you are proposing is better. The first few wweeks it will feel as if you have more work due to having these other people, but if you do your code reviews and explain things and expect them to learn, in a few weeks they will be much more help than if you just do it all yourself. But there is an intial commitment of your time to get them up-to-speed that your management needs to be aware of. </p>


答: My opinion is do not encourage using it unless you are teaching low level compiler principles used to allocate stack space for local variables.  Teach it in that context.</p>

Title: Should I teach my students alloca?


答:
"Make things as simple as possible, but not simpler" -Einstein

Keeping code as simple as possible, but not simpler depends on the problem being solved.  As long as the problem being solved tends to change, so does KISS.

There is a balance between over-engineering (oh man this looks like a great place to show off my Design Pattern skills!) and under-engineering (if only I used a factory I wouldn't have this coupling that caused me to make 20 code changes...).  The goal is maintainability.

Title: How  'simple' is a real KISS solution?

Body:
I confess: I have a problem to "Keep It Simple and Short" most of the time because trying to make it according to the books I have read, design-patterns I have heard etc. gives me such an enthusiasm -an enthusiasm coming from the sense of that I am on the right path to a probable perfection.

On the other hand, yes, it puts an extra stress on me in terms of delivering the deadlines sometimes...

But whenever I say to myself, "Next time keep it simple, you stupid!" I find it quiet hard to make it "simple" when that next-time comes, because it starts to feel weird... and uncomfortable after a point.

Then I start to judge my understanding of 'simple'...

Does SIMPLE mean too short that it works but hard to maintain and extend?

Does SIMPLE mean breaking many of the OOP principles?

Does SIMPLE mean cheating?

Does SIMPLE mean just keeping the deadlines without no dealy? etc.

Actually, what is it?

Question is: Can you write the EXACT definition of SIMPLE in terms of KISS principle? -if there is.

Thanks!


问:
How can programming ability be used to help people in poverty?
As a student studying Computer Science in college, I often hear from friends working on various humanitarian projects, and I want to do something myself. But it seems that programmers don't have as many obvious avenues to help out as, say, doctors or teachers. What are some ways in which programmers can put their talent to use for people in poverty?</p>

答:
It's more of a long-term strategy, but you could teach kids in poverty or in a developing country.  If not as a full-time job, then teach programming for an after-school program at a boys/girls club in a poor neighborhood, or simply mentor at-risk kids.  If you instill a love of learning, knowledge of programming and other scientific/technical fields, and inspire them to pursue an advanced education generally, you greatly increase the chances that they will end up with a life in which poverty (for themselves and their families) is very unlikely.

How many poor kids spend hours a day on the basketball court or football field hoping to strike it rich but in reality have a 1 in 10,000 chance of doing so and a 9,999/10,000 chance of getting nothing in return?  If they spent the same amount of effort learning programming, math, science, etc., they would probably have a 95% chance of being solidly middle class for their whole life.  Given decent smarts and hard work, a lot of them could do it, but it's just not an option in life that they see by example or know anyone to guide them toward.  You could be the one.


答: Common practice in UNIX-land is to just send the plain diff output. The recipient can then use a tool of their choice to read it.</p>


问:
Is there justification for leaving conflict markers in checked-in code?
Consider conflict markers. i.e.:

```<code><<<<<<< branch
blah blah this
=======
blah blah that
>>>>>>> HEAD
</code>```

In the particular case which has motivated me to post this question, the team member responsible had just completed a merge from upstream to our branch, and had in some cases left these in, as comments, as a sort of documentation over what had just been resolved. He left it in a compiled state, tests passing, so it's not as bad as you would think.

Instinctively though, I really took objection to this, however being devils advocate to myself I can see why he might have done it:

because it highlights to other team developers what has changed as a result of the merge.

because those who are more expert with the particular pieces of code can then address the concerns illustrated by the comments so that he doesn't have to guess.

because the upstream merge is a right pain and it can be difficult to justify the time to resolve everything well and completely, so some semi-complete FIXME notice is necessary, so why not use the original conflict as a comment to document this.

My objection was instinctive, but I'd like to be able to justify it rationally, or see my position more wisely. Can anyone give me some examples or even experiences where people have had a bad time with someone else doing this and/or reasons why it's bad practice (or you can play devil's advocate and support it).

My own immediate concern was that it would clearly have been annoying if I had been editing one of the files concerned, pulled the changes, got real conflicts, but also pulled in the commented ones. Then I would have had a very messy file indeed. Fortunately that didn't happen.

答: This is clearly wrong.  It is the job of the version control system to keep track of changes, and it is the job of diff tools to show what has changed as a result of the merge.  There should be a comment in the commit log, and maybe in the code, explaining what was changed and why.  However, IMHO, leaving the conflict markers in as comments is the same as leaving dead code around.</p>


问:
Stuff every programmer needs while working
I've been tasked with creating a fun and relaxing environment, one thing I know that I want is ergonomic mice and keyboards, others have suggested exercise balls and bands.

What is it that every programmer needs while working? What might not be necessary but would be nice to have anyway?

Note: this question was asked previously, but has been recommended to be posted here. See this link for the previous responses: https://stackoverflow.com/questions/3911911/stuff-every-programmer-needs-while-working-closed

答: The Ability to use whatever editor/IDE that you prefer</p>


问:
How can I protect a java app to be deployed in the google chrome app market?
I'm making a java app. Is to solve a problem in engineering. I'm thinking that it would be nice to sell it as an app in the google chrome market, but I'm worried about security. I've been trying to find any info on the subject, but to no avail.

Does anybody have any thoughts on this? how secure is the google chrome market? I mean security in the sense that someone downloads your software and uses it -and distribuites it- without permission.

I would appreciate any kind of info, be it links to books or personal experiences, whatever.

Thanks!

答:
'Security' isn't really going to help you here.

You need to talk to a lawyer - most likely, you can copyright (or will by default receive copyright) the code implementation you have written.  Then, if you discover another person copying your code, you can serve them a Cease/Desist order, or more (depends on circumstances, I would imagine).

Preventing copying ahead-of-time has largely been proven to be ineffective in the long term (where 'long-term' is probably weeks to months).  This is as true for the software industry as it is for the entertainment industry.


答:
Scenario

You need to cut and pinch.

Solution A: Not KISS

Solution B: KISS

As for an exact definition: It's hard to define an absolute scale for measuring simplicity. Mostly because true simplicity precludes true understanding of the problem at hand, and that's rarely attainable. But let's say that solution A and B illustrate the difference between solutions that tend towards overcomplication and simplicity respectively.

Title: How  'simple' is a real KISS solution?


答:
MVVM is (yet another) variation on patterns that separate the concerns of a typical presentation, much like MVC and MVP. Regardless of these variations, the basic concerns are the following triad:

the Model (the underlying data and domain objects).

the View (what the user actually sees and interacts with)

the facade that translates between the Model and View. (the ViewModel in this case)

Doing so leads to benefits on it's own that have nothing to do with the platform technology including the increased testability that comes from taking logic that might be lumped into the View otherwise.

The particular slant in MVVM's ViewModel is that it promotes the use of data binding, which is a strong suit of the technologies that tend to use it (wpf, silverlight).

Theoretically, that's it! In practice, this implies skills and experience with data binding. OOP, and testing - so there may be a learning curve. There is also several ways to execute the pattern, so the first few attempts may seem a bit overwhelming.

But you will have the security of your tests as you gain experience and refactor towards more elegant usages. Testing is essential to any non-trivial project IMO, regardless of its ultimate size. Did I mention that MVVM promotes testability?

Title: What are the pros and cons of the MVVM architecture?

Body:
In class today we were introduced to the MVVM architecture for Silverlight/WinPhone/WPF; it looks nice for big projects, but what are your thoughts on MVVM?

What are the pros and cons?

I want to get more into the architecture so that I know when I should use it.


答:
Simple doesn't mean breaking good programming principles. In fact, it means more of the opposite.

Does SIMPLE mean too short that it works but hard to maintain and
  extend?

No. Being hard to maintain and extend are a big symptom of complexity. In fact, I find that making code extensible leads to simpler code, since you do not deal with every single case to begin with, you can keep the base code simpler.

Does SIMPLE mean breaking many of the OOP principles?

No. Most OOP principles are designed to keep code cleaner and more organized, which in the end, is simpler.

Does SIMPLE mean cheating?

No. writing hard to maintain code & hacks under the guise of keeping deadlines is.

Does SIMPLE mean just keeping the deadlines without no dealy? etc.

No. deadlines and the simplicity of your code are two separate issues. Writing simple code doesn't take any time longer to write (although it is a common misconception).

Title: How  'simple' is a real KISS solution?


答:
Question is: Can you write the EXACT definition of SIMPLE in terms of
  KISS principle? -if there is.

No.

Title: How  'simple' is a real KISS solution?


答: A life outside of work.</p>

Title: Stuff every programmer needs while working

Body:
I've been tasked with creating a fun and relaxing environment, one thing I know that I want is ergonomic mice and keyboards, others have suggested exercise balls and bands.

What is it that every programmer needs while working? What might not be necessary but would be nice to have anyway?

Note: this question was asked previously, but has been recommended to be posted here. See this link for the previous responses: https://stackoverflow.com/questions/3911911/stuff-every-programmer-needs-while-working-closed

Body: A life outside of work.


问:
Newbie seeking advice on programming in general
need some of you to remember back to a time when you might have been bad at programming...

Been at my new job (as a software developer) for a couple of months now, passed probation period. Have very little programming experience (C++ only) and am currently working with asp.net MVC and silverlight. So there's a website the company has been working on and I am joining the effort to make it better, iron out bugs etc.

The problem is - learning about a system/website which has already been made, via visual studio. I ALWAYS feel HUGELY overwhelmed, never knowing which part of this line should I look up, and generally having lots of trouble getting the big picture. Visual studio itself is something I'm finding it difficult to get to grips with, let alone the asp.net framework.

I get the impression that because my coworkers have more experience than me, they are getting all the good jobs, and I am left with crap to do - stuff which is not even vaguely programming. Meaning they are learning/creating more, and I am learning/creating near nothing. I'm getting demoralised, and too scared to say anything.

I'm not stupid, I've read and practiced plenty of the fundamental programming concepts...I'm just bloody scared of this damn framework. I look at it and just feel paralyzed.

The result is that I keep asking the older veteran guy of questions, and he is getting irritated, and would rather give me easy/mindless/non programming jobs to avoid wasting time with helping me out. Then when I don't understand something, I'm hesitating about whether or not I should ask him yet, and trying to decide if it would be a waste of time.

I'm the kind of person who picks things up slowly, but with a lot of attention to detail. The former I think is making me look incompetent though.

Anyone get where I'm coming from please say something helpful....I'm scared of losing my job in a few months or something...

答:
It takes time. A couple of months is a short time. Unless you see no future in your current company I would give it more time.

It's common to work on existing products. As a matter of fact you'll do that more often than brand new systems. It takes a lot of skill to improve existing systems that are already in production. That's not necessarily a bad thing.

Good luck on your new job.


答:
Process that people should be doing on a job as a new hire

Initially look at the code

Small bug fixes

Bigger bug fixes

Feature Requests - Adding something to an existing piece of the puzzle

New things - Creating something from nothing

Rushing a green developer with no domain experience too far too fast will cause way too many problems.  You're going to get the new guy stuff because you need to get the new guy stuff.

Hang in there

Title: Newbie seeking advice on programming in general

Body:
need some of you to remember back to a time when you might have been bad at programming...

Been at my new job (as a software developer) for a couple of months now, passed probation period. Have very little programming experience (C++ only) and am currently working with asp.net MVC and silverlight. So there's a website the company has been working on and I am joining the effort to make it better, iron out bugs etc.

The problem is - learning about a system/website which has already been made, via visual studio. I ALWAYS feel HUGELY overwhelmed, never knowing which part of this line should I look up, and generally having lots of trouble getting the big picture. Visual studio itself is something I'm finding it difficult to get to grips with, let alone the asp.net framework.

I get the impression that because my coworkers have more experience than me, they are getting all the good jobs, and I am left with crap to do - stuff which is not even vaguely programming. Meaning they are learning/creating more, and I am learning/creating near nothing. I'm getting demoralised, and too scared to say anything.

I'm not stupid, I've read and practiced plenty of the fundamental programming concepts...I'm just bloody scared of this damn framework. I look at it and just feel paralyzed.

The result is that I keep asking the older veteran guy of questions, and he is getting irritated, and would rather give me easy/mindless/non programming jobs to avoid wasting time with helping me out. Then when I don't understand something, I'm hesitating about whether or not I should ask him yet, and trying to decide if it would be a waste of time.

I'm the kind of person who picks things up slowly, but with a lot of attention to detail. The former I think is making me look incompetent though.

Anyone get where I'm coming from please say something helpful....I'm scared of losing my job in a few months or something...


答:
Amongst your options: find a job where you won't be expected to hit the ground running. Not every company is a good place for an entry-level job. A major consulting corporation (e.g. Dell or Accenture) might be a soul-draining hellhole to stay at as a regular programmer, but they should have solid training programs and the resources to deal with the overhead of employees with your learning style.

The corollary is that it's entirely possible you're the wrong kind of employee for your current employer and vice versa. While losing your job is a scary proposition, it might be best to cut your losses.

Of course, I'm not saying you should give up. There's a good chance you just need some more time to get over the worst part of the difficulty curve and get to the point where everything "clicks".

Random other observations:

I ALWAYS feel HUGELY overwhelmed, never knowing which part of this line should I look up, and generally having lots of trouble getting the big picture.

The main reason why hitting the ground running with new projects gets easier with experience is because you'll have worked with most of what said systems consist of, so they're not really "new". There is no "general experience", just being familiar with a great many concepts and frameworks and tools and drawing on the problem being related to the things you're familiar with. For an entry-level programmer to be overwhelmed with a nontrivial system is perfectly normal. (As it is for an experienced programmer if he works on a system with enough things that are new to him. Programming is a complex beast, and most programmers have a "comfort zone".)


答:
I get the impression that because my coworkers have more experience
  than me, they are getting all the good jobs, and I am left with crap
  to do - stuff which is not even vaguely programming. Meaning they are
  learning/creating more, and I am learning/creating near nothing.

How certain are you about this?  I ask as someone that generally when you are starting something new there are all kinds of learning being done that you may not realize.  How well have you gotten used to Visual Studio?  I can remember it being rather scary to learn the IDE from scratch when I first started working back in 1998 but it was an interesting time in some ways.  How well do you know the bug tracking software?  How well are you getting an idea of all the different people on the team?  There are probably more than a few things you are learning though you may not see them as big things to learn.

My advice would be to consider talking to some co-workers or your boss about seeing how well or not so well are you doing.  They may say, "Yeah, you're doing fine," or "You are awesome!" which is something you may have to accept though some may just be saying that as they are afraid to say the truth.  At the same time, recognize that this is where you find out where you stand and then do something about it.  In being there for a couple of months, you should know a few things and thus be able to do better than you did on your first week.

Its like, "fix this bug, should only take a line", and then I take
  ages just finding out where I THINK that line should go.

I've heard and said that kind of line dozens of times in my career, really.  There are a couple of different points I'd make about such a line:

It may be an estimate and so the person may have forgotten some quirky case that makes the fix be a handful of lines.  I know I've had times where I thought, "That should be done in one line of code somehow," only to later discover what I missed.

Some lines of code can be ridiculously complicated.  Ever see an if where there are dozens of brackets in it to enforce some logic where it took a handful of times to read the condition correctly?  I know I have.

Consider what kind of picture of the application do you have now and how do you see different pieces fitting together, what conventions does the code generally use, what kinds of development methodology are used and what tools get used for various processes, e.g. is there a continuous integration server, is there a story board, etc.


答: Keep asking questions, but demonstrate initiative, though, too; do as much as you can before you ask. It's kind of like asking questions here on Stack Exchange.


答: It happens to everybody in programming. Even programmers with many years of experience will have a substantial learning curve when faced with a complex system that's been in place many years. It's rare to walk into a job with almost all the knowledge you'll need. You can expect to feel overwhelmed for a while unless you're working on 100% new development in a relatively new company/division or very simple system(s).</p>


问:
Anyone had success with selling source code, at sites like code canyon?
Recently I came across two sites that help programmers sell source code - binpress and codecanyon.  Anyone have experience/success with sites like these?

Would you use them again?  What was good about them?  What was bad about them?

答: The prices that the software is being sold at only makes sense (for the seller) if you live in a third world country OR if you think your component will sell thousands of copies. Just look at the prices...the ones I've seen are between $10 and $100. If your component only sells a handful of copies you're losing money, guaranteed.</p>


答:
This is very tricky to explain because simple does not mean the same thing to everyone.

Example. Some devs think that ?: is simple but others think an if statement is better. When its down to this level, you cannot please everyone.

In general, simple means without complexity. In order to understand simplicity, we need to understand complexity.

There are two types of complexity:

Essential complexity refers to a situation where all reasonable
  solutions to a problem must be complicated (and possibly confusing)
  because the "simple" solutions would not adequately solve the problem.
  -- Wikipedia

Accidental complexity is complexity that arises in computer programs
  or their development process (computer programming) which is
  non-essential to the problem to be solved.
  -- Wikipedia

You can check essential complexity with the following questions:

Is this solution simple? Can I explain it to my peer in a span of a couple of minutes and they get it? Is there a simpler solution to the problem? If yes, are there any trade-offs between the complicated solution versus the simple one? Can we live with those trade-offs? For example, many programmers make a mistake of micro optimizing everything and their solution (and the code as well) becomes overly complicated.

Checking your accidental complexity:

Is the code simple? If I come back to it in three months, how long will it take for me to build the context in my brain so I can make the change I need to make? Is everything in my source code has a clear purpose and it conveys that purpose effectively to me and other developers? How hard is it to test my code? Usually the more complicated your code is, the harder it is to unit test, so I usually use this as a measure of complexity. You usually want small, well named and focused classes and methods. Design patterns usually help you achieve these as well.

If you find yourself wanting to use a design pattern just because you just read about it, it is probably going to introduce accidental complexity. If you find yourself wanting to put something in because you think 'its smart' it will probably introduce accidental complexity.

I hope this helps and do not forget: Simple does not mean EASY.

Title: How  'simple' is a real KISS solution?


问:
What's your favourite quote about programming?
What's your favourite quote about programming?

One quote per answer, and please check for duplicates before posting!

答:
You should go home if you are thinking suicidal thoughts.

  — Robert Read, "How to be a Programmer"

LastEditorDisplayName: Roger Pate

OwnerDisplayName: ginotria


问:
What's the best way to learn code if you are just starting out?
I'm just starting out with some articles and tutorials.

I am looking for some guidance on which languages to start with and what is the best way to go about learning code, books, tutorials, classes.

Which tutorials or books are best?

Is it possible to learn this stuff online? If so how?

Thanks for any help!

答:
The most important thing is to get cracking. Pick a language, find suitable resources online (there are plenty of those for all the mainstream languages), install the programming environment, and start playing with it.

As far as languages go; there is no wrong choice, really, but I'd like to mention a few languages that I think are especially suitable for your first language.

Python. The basics are easy to learn, yet the language is quite powerful. It has a fairly consistent design and few gotchas.

C. It's still the de facto lingua franca, the language that has influenced all current mainstream languages one way or another. It's also so close to the metal that you'll be pushed towards learning how things actually work. The initial learning curve is a bit steeper though, and certain tasks are really hard in C.

Javascript. A language full of little peculiarities, and with quite a few gotchas, but the huge upside is that you already have the development environment (you're looking at it right now). Javascript, being embedded in the browser, gives you a number of things 'for free': text rendering, downloading images from the network, etc. Another big problem with javascript is that even though there is an abundance of tutorials and guides available, most of that is outdated, buggy, or plain out wrong. Finding good resources is fairly hard, especially if you don't know what you're looking for.


答: Grab a good book on asp.net and probably on .net framework too and read them thoroughly off working hours. You will feel pretty confident at work once you have read them. Its also amazing to practically work on what you are learning. The code will make sense to you as you read on and therefore the reading will be more fun too. You should make best of the time you have right now, not a lot of tasks are being thrown at you, so use this time wisely. </p>


答: I've had similar problem with some code either being commented out (which is somehow simillar to your case) or moved to a method not being actually called anywhere. When asked why people do this the response was that they feel a bit safer when they have some code block still around. The most obvious counter argument is that it is VCS job and not theirs. However, there is also another aspect. When somebody else is reading code while learning or making changes, he will probably be side-tracked by such a comment. He will definitely read it and perhaps spend some time to understand why it is here and what possible correlation it has to his current job. As a conflict marker is a sign of a conflict, that already have been resolved, this is for sure a waste of time.</p>

Title: Is there justification for leaving conflict markers in checked-in code?

Body:
Consider conflict markers. i.e.:

```<code><<<<<<< branch
blah blah this
=======
blah blah that
>>>>>>> HEAD
</code>```

In the particular case which has motivated me to post this question, the team member responsible had just completed a merge from upstream to our branch, and had in some cases left these in, as comments, as a sort of documentation over what had just been resolved. He left it in a compiled state, tests passing, so it's not as bad as you would think.

Instinctively though, I really took objection to this, however being devils advocate to myself I can see why he might have done it:

because it highlights to other team developers what has changed as a result of the merge.

because those who are more expert with the particular pieces of code can then address the concerns illustrated by the comments so that he doesn't have to guess.

because the upstream merge is a right pain and it can be difficult to justify the time to resolve everything well and completely, so some semi-complete FIXME notice is necessary, so why not use the original conflict as a comment to document this.

My objection was instinctive, but I'd like to be able to justify it rationally, or see my position more wisely. Can anyone give me some examples or even experiences where people have had a bad time with someone else doing this and/or reasons why it's bad practice (or you can play devil's advocate and support it).

My own immediate concern was that it would clearly have been annoying if I had been editing one of the files concerned, pulled the changes, got real conflicts, but also pulled in the commented ones. Then I would have had a very messy file indeed. Fortunately that didn't happen.


答:
First things first. You're the newbie. You'll get the crap assignments. There is no way around that. You must understand that this is not malicious. Like you yourself have stated, these guys have more experience and are more skilled. They are also probably on a higher pay grade as well. Which means, from the project's point of view, their time is precious and more valuable than yours. So they get to do the more cutting edge (and fun) assignments, leaving you with the more mundane (but still important) work.

Now, the important thing is not to get stuck in the rut forever. Take every moment possible to familiarize yourself with the project and tools at hand. You can play Minesweeper when you're dead. I know that learning a new platform as well as getting up to speed with an existing project is a very overwhelming prospect. The trick is to cut it up to smaller pieces and tackle them one by one. In your shoes I would do something like this:

At work, first figure out the general architecture of the whole application. No need to get into the details yet. Just identify the major blocks of code; i.e. where the user interface is? Which part accesses the data base? Which one does the business decisions? Don't be afraid to ask around. Show them you are eager to learn and people will generally reciprocate. If there is good (and recent) documentation around use it.

Now that you know the major bits, its time to drill down a bit. Try to start at one of the ends. The user interface, or the database layer, then work your way to the other end. Take a general look at the bit you're studying. Get a feel on how it works. What functions and methods it exposes. Details can come later. Take copious notes, draw graphs and flowcharts, do anything that will help you look it all up later.

Only when you feel you understand how logic flows in the application can you start really looking at the code. This is a good time to familiarize yourself with Visual Studio. Right click on any object/function in the code and you'll get a very helpful context menu. "Go to definition" and "Find all references" are particularly useful and powerful. If a command seems cryptic to you, click F1.

At home, or in your free time, read up more on ASP.NET MVC and Silverlight (or whatever platform you end up using). Specifically, read up more on the bits you've seen at work today.

As your understanding of the platform and project grows you will eventually see more and more opportunities to contribute to the code. Seize those moments!

If this looks like a lot of work, that's because it is. But the dividends you will eventually collect are more than ample compensation.


问:
Appropriate uses of fall-through switch statements
When is it appropriate to use a fall-through (classic) switch statement? Is such usage recommended and encouraged or should it be avoided at all costs?</p>

答:
I use them when certain functionality has to be applied for more than one value. For example, say you had an object with a property called operationCode. If the code equals 1, 2, 3 or 4, you want to startOperationX(). If it's 5 or 6, you want to startOperationY() and 7 you startOperationZ(). Why have 7 complete cases with functionality and breaks when you can use fall-throughs?

I think it's completely valid in certain situations, especially if it avoids 100 if-else statements. =)


答:
I've always felt like the principles behind X11 ( http://en.wikipedia.org/wiki/X_Window_System#Principles ) were worth heeding. I do not always succeed in this goal.

Specifically, I keep having to remind myself ...
"Do not add new functionality unless you know of some real application that will require it.", and "If you can get 90 percent of the desired effect for 10 percent of the work, use the simpler solution."

Title: How  'simple' is a real KISS solution?


答: I've used them occasionally, I think its always appropriate usage - but only when included with the appropriate comment.</p>

Title: Appropriate uses of fall-through switch statements

Body: When is it appropriate to use a fall-through (classic) switch statement? Is such usage recommended and encouraged or should it be avoided at all costs?</p>


答:
I think you concern is really valid. But you shouldn't worry too much.

As a new employee, of course you will get the tasks nobody wants to do. Like task left to do, task that are more mechanical and unpleasant.

I really feel your pain, because everyone here, like me, has already been there. What you need is to do things fast and the do the best as you can.

This way: people will see you can do harder and harder stuff, that you are really giving your best and you will really improve which will allow you to perform even better and leave a good impression (in the right way).

And also be patient. It takes some time, but it's worth it.


答:
Programming is a never-ending learning process. I won't get into what will make you better, but I'll tackle that feeling overwhelmed, having been there and occasionally feeling that way still. To jump into a big project while learning the IDE and the technology being used IS a ton to handle. I'm in a job where I'm using VS 2010, C#, WPF, SQL Server and MVVM for the first time. So, nothing has come easy without tons of Googling.

Consider a few things - you passed the probational period, so they like what you do. They believe in you as an employee. They also know that you are new and they aren't expecting you to absorb 10 years of experience by opening up VS a couple of times. They'll allow you to grow. Your'e an investment and an asset - they don't want you to fail and if you show progress and desire, they'll keep you around to do succeed.

As far as the "irritated" senior guy goes - he's 100% in the wrong. If you are showing a penchant for effort and researching before you ask, he has no reason to get irritated. Part of being a leader is leading - someone would say it's a big part. =) If he's leading by that poor of an example, they've chosen the wrong man (or woman). Broach the subject with him and let him know you appreciate the help. Devs can be surly types and often may be a bit full of themselves. If he's a problem, talk to your manager about it. Again, you're an asset and having someone stunt your growth by not helping as he should hurts the team.

Most importantly - don't sweat it. If you put forth effort and you like what you do, it's a guarantee you'll get better and be heading up that team one day or one like it. If they are smart, they'll give you bites you can chew.

Lastly - I'm 6 years in and still learning. Sometimes when I don't "get it" immediately, I get a bit down on myself. I, like you, just have to tell myself: 'Calm down, the world isn't ending. It's .Net for God's sake.'


答:
Here's an example where it would be useful.

```<code>public Collection<LogItems> GetAllLogItems(Level level) {
    Collection<LogItems> result = new Collection<LogItems>();
    switch (level) {
        // Note: fall through here is INTENTIONAL
        case All:
        case Info:
             result.Add(GetItemsForLevel(Info));
        case Warning:
             result.Add(GetItemsForLevel(Warning));
        case Error:
             result.Add(GetItemsForLevel(Error));
        case Critical:
             result.Add(GetItemsForLevel(Critical));
        case None:
    }
    return result;
}
</code>```

This sort of thing (where one case includes the other) is rather rare, I think, which is why some newer languages either don't allow fallover or require special syntax for it.

Body:
Here's an example where it would be useful.

public Collection<LogItems> GetAllLogItems(Level level) {
    Collection<LogItems> result = new Collection<LogItems>();
    switch (level) {
        // Note: fall through here is INTENTIONAL
        case All:
        case Info:
             result.Add(GetItemsForLevel(Info));
        case Warning:
             result.Add(GetItemsForLevel(Warning));
        case Error:
             result.Add(GetItemsForLevel(Error));
        case Critical:
             result.Add(GetItemsForLevel(Critical));
        case None:
    }
    return result;
}

This sort of thing (where one case includes the other) is rather rare, I think, which is why some newer languages either don't allow fallover or require special syntax for it.


问:
Is CodeFirst intended for large scale applications?
I've been reading up on Entity Framework, in particular, EF 4.1 and following this link ( http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx) and it's guide on Code First.

I find it neat but I was wondering, is Code First supposed to be just a solution for rapid development where you can just jump right in without much planning or is it actually intended to be used for large scale applications?

答: Usually for large projects the database has already been created. Either because it's a legacy database or created by a competent dba for performance. The only benefit from CodeFirst is if you don't want to use EF's entities but instead POCOs.</p>


问:
How to name parts of your program as a non native English speaker

Possible Duplicate:

  Do people in non-English-speaking countries code in English?

I am from the Netherlands and we speak Dutch.

I have worked on quite a few projects now in various languages, and I must say what always annoys me is the mixing of Dutch and English words in the naming of urls, variables, classes, files, db tables and db columns. Besides the mixing there is alot of bad use of words and bad grammar going around.

I reckon if you work with an international team the code HAS to be in English, but since I never do I often see people use Dutch words for database columns and variables. This is mostly because the requirements are written in Dutch, most of the data is also Dutch and, of course, the developer thinks in Dutch.

How do other non native English people tackle this? Do you just live with it? Do you develop everything in English and do a translation afterwards for the GUI and urls? Is there a code checking tool/approach to see if a developer actually used a proper word to describe something?

答: From what I've read, non-English natives tend to agree that the best practice is to write all of your code in English (the GUI can remain the same).  This is not only because most programming languages are in English, but because English is a highly-technical language, thus you can be very precise and unambiguous in your naming conventions, comments, etc.</p>

OwnerDisplayName: Benjamin Udink ten Cate


答:
Talking about a good decade of coding...

I always code in English, because thats to me the native-code language. It is so in every serious programming text, and also all the scientific and non-scientific literature is in English.

Everything that is code, data, whatever is English.

Strings and display text etc. is localized (with placeholders in English, too). The first final product is always English. Localizations follow (which usually are just added string files).

Title: How to name parts of your program as a non native English speaker

Body:
Possible Duplicate:

  Do people in non-English-speaking countries code in English?

I am from the Netherlands and we speak Dutch.

I have worked on quite a few projects now in various languages, and I must say what always annoys me is the mixing of Dutch and English words in the naming of urls, variables, classes, files, db tables and db columns. Besides the mixing there is alot of bad use of words and bad grammar going around.

I reckon if you work with an international team the code HAS to be in English, but since I never do I often see people use Dutch words for database columns and variables. This is mostly because the requirements are written in Dutch, most of the data is also Dutch and, of course, the developer thinks in Dutch.

How do other non native English people tackle this? Do you just live with it? Do you develop everything in English and do a translation afterwards for the GUI and urls? Is there a code checking tool/approach to see if a developer actually used a proper word to describe something?


答:
I've seen some code (OCE, Salome) that was written by people who were thinking in a foreign language. They didn't mix languages very much, but when they did it made it very hard to run the comments through translation software!

Bottom line - stick with one language. No abbreviations, no slang, and use common words and proper grammar. Do that, and I can get the gist of your comments and variable names with a translator and/or with an educated guess.

OwnerDisplayName: Mark


答:
I am always naming all identifiers in program in English. I am non-native english speaker. If I don't know the right word for specific variable, I just use online dictionary to find right one.

GUI is either single-language (if it is not meant to be internationally used) or multi-language (with locale text files, or something like that, depending on platform).


答:
The strategy that I have found best is to have the domain specific vocabulary in the native tongue, in my case Norwegian, and everything else, including code comments, db tables, file names, etc in English. If a database table or file has, as part of its name some domain specific word, that word is still not translated. This means that one can encounter names like barnepensjonMainTable (Barnepensjon is an extra pension one gets if one is retired in Norway and has a child under the age of 18 if I recall right), which on the surface looks silly, but is easy to understand for a native speaker, and uses the native domain specific vocabulary. This means that, based on variable names, file names or other info one can ask the domain experts about the term with no (possibly lossy) translation.

The main key here is consistency. Just all all non-domain specific words should NEVER be in the native tongue, domain specific words should NEVER be translated. On large projects this is especially true since different (well meaning) programmers can translate domain specific words into a bewildering array of similar words. This breaks any "search in all files" and adds confusion.

For smaller projects I use all english.

For mixed-language projects that break the above principles, I just try to extend whatever principles that project uses, as consistency is more important than the above principles.

OwnerDisplayName: Thomas N

ContentLicense: CC BY-SA 4.0


答:
I have experience of this being the native english speaker receiving code written by programmers from other countries.

I think it is just good practice to write your variable names / table names etc in English for a few reasons. You never know what is going to happen in the future, the code which you are working on now may be just for an internal project, but it may also be passed off to another office in the future or it may be something you or your company decide to sell as the product grows.

Having your names in english means you can pass off your code to not only native english speaking devs but any developers you may meet, English may not be their native language but they will understand enough generally to get the idea of what your names mean.

Whilst programmers may struggle with some names in english GoogleTranslate and / or a dictionary is generally enough to accuartely translate single words. Since english does not have masculine / feminine words it isnt too hard to get the names correct or close enough.

Having English names also makes it easier to outsource work and / or get support from external parties. Imagine you have to integrate something into your code you have no experience of and decide to outsource this to another programmer. If your names arent in english this programmer either has to bug you to find out what things mean or translate it themselves, both of these options waste time.

From my own history I have recently worked on code which was written by a french company, all the database tables / columns / report names (and text) etc were in french, given that myself and the colleague I was working with had very little knowledge of the language we had to constantly use GoogleTranslate, this slowed the entire task down, eventually we did learn some of the words but it made the task a lot more tedious and long winded than it had to be. Had the initial developer considered this when developing this database our task would have taken half the time.

The GUI is best to write using resource files to contain your text, that way you can easily have your software support multiple languages. Whilst this may seem overkill for some projects it is nice to be future proof and for the little extra effort you can future proof your work in a way.

The only place I would say it would be acceptable to use non english names is maybe in website design where the user will see the complete URL with folders ie  www.yourURL.com/subfolder/filename.htm  in this situation if your website is not for an international audience it is appropriate to use non english file / folder names.

All of the above should ideally be part of a well planned coding standards document which not only includes the language to name things, but also which case to use and the gramatical style.

OwnerDisplayName: Purplegoldfish


答:
Following my personal experience with this:

I've seen a loot of projects that are exactly programmed as you mentioned; two languages, slang's and custom shortcuts and all that mixed up from persistent layer to the presentation layer.

At the time I started in the company I am still working at I declared English as programming language for all new projects. That was hard at the first time and much code need to be revised but it worked after 3 Month at least. Now all projects are written in English from the Database Tables over the exception handling to the Fronted (Some projects still require just one language so that here English get still skipped in some projects).

I have to mention that we are developing with .NET and the resource files are an important pillar for this setup. Nearly six months after I started this all programmers agreed that the code is now better to read then before and the developing process is as fast as before.
For sure you are thinking in your native language but it needs just a little bit of training to write all in English. The Project Documentation outside the Program code get of course still written in our native language.

With the use of the resource files it is easy to translate our projects while all other parts doesn't need any change cause we declared the programming language to English, so no Database table or variable will need a translation. Not to mention that every programmer should follow basic rules to name short and straight.

OwnerDisplayName: sra


答:
Don't mix up programming and GUI/other user interaction.
For a programming language, you have to use the most easier and simple language without any accent or other stuff like that.
For example, you couldn't program in Japanese with romanji writing as you would have serious issues with accents influing on pronounciation.

The best for now is still English (I'm not familiar with other languages), I work in a French programming team and whenever someone use a french noun for a method name it's a mess because accents are really important in French. That's why we use English.
Bottom line is, you can use whatever language as long as you can write it in pure alphanumeric (a-z0-9). Or you could use a programming language/compiler that accept every chars in syntax but I don't know any.

OwnerDisplayName: TecHunter


答:
My experience here in Brazil is that many people I've worked with tend to mix portuguese and english a lot, be it variables, classes, database columns, function names, etc.

Though, to be fair, portuguese is easy to put into coding language, as we can easily read missing accentuation marks such as ~ or a ç. For instance, "promoção" would turn out as 'promocao' for coding purposes, and any programmer could look up at it and guess "it's actually promoção".

Personally, I'd say that, unless your native language uses lots of special characters, and their presence or ausence makes all the difference, use mainly it, sticking to english only for convention things such as "get" and "set" for Java.
Unless you're developing for foreign clients. In that case, full english is your best option.


答:
I am from Israel, my native language is Hebrew, and I always program in English.

It's just much more comfortable (though Hebrew is rtl while English and Latin-based languages are ltr, so it makes it a pain to read if it's in Hebrew, I don't know how it's like in ltr languages like Dutch).

I find it much more efficient.

OwnerDisplayName: Rikudo Sennin


答:
When I started with programming I prefered Czech (my native language). It was more obvious what is some language feature or library function and what is purely my choice of name. I especially liked it for examples that I adopted - it was clear what has to stay and what can be chaged.

Now I prefer English even if it is only my personal project. It seems more fluent with the language keywords and library functions. If I do not expect future need of localization I write the strings directly in GUI language. Sometimes I use inconsistent language for comments - English for documentation and Czech for remarks and todo: notes. I use specific czech characters like ěščřž (valid name in C#) for one purpose debugging variables - it makes them easier to find later since I dont use them anywhere else in the code.

OwnerDisplayName: Lukas


问:
What is a clean Agile (Scrum) Sprint Presentation?
Suppose someone of your development team is presenting a sprint to the customer but he is having web connection problems such that a complete story cannot be presented. For the sake of the cleanness of the presentation, do you help your colleague suggesting possible solutions and try to fix it in the moment? Or is it kind of messy?

May be the customer (who is "part" of the team) will understand? Why?

答:
No, I wouldn't try to fix it in the moment as a general rule.  I'd rather schedule a follow-up meeting and between then and now figure out how to fix what went wrong.  Something to consider is how well do you want your customer seeing what it looks like for a pair of you to struggle here.  Depending on how formal and professional the presentation is, I could see some rare cases where I'd work around it though those are where I'm working with people where 99% of us would agree to try to get to the good part quickly and that we have enough knowledge and control over the issue that it could be resolved in 5 minutes or less.

While the customer may say they understand, I'd wonder what kind of reputation are you creating here.  Do you want to have that kind of reputation where things go wrong and you have to rush and fix it during the presentation time?  What someone says can be quite different from what he or she thinks.

OwnerDisplayName: negarnil


答:
This is the rule I use:

1- Domain specific terms are always in the language of the customer/client.

2- Computer terms are always in english.

My firs language is french. My clients write their requirements in french, they speak in french, the gui is in french, etc.

If you put everything in english, you have some mental mapping where the application display the french word "Avis Juridique" for example, but these are stored in a database table whose name is in english, say "Legal advice" (google's own translation).

What can happen then is that developpers speak to the users with the english terms, and the clients have no idea what the developper is speaking about.

Worst the translation can be misleading. For example in the transalation I mentioned earlier while Avis can mean Advice, that may not necessarly be the correct usage I am looking for.

If I have a factory of "Avis Juridique" I will call it AvisJuridiqueFactory.


答:
Simple - in this particular context is the exact opposite to complex. Simple doesn't necessary mean: Every stupid minded person has to understand it - but you have to make sure, that you could understand it, even if you haven't written it yourself.

Complexity could be achieved by hard tyo understand references - get rid of those! Many files/classes linked to each other - no way! And complicated code (meaning: chained loops, multiple ITE layers, etc.) - nobody wants to read that.

In my opinion: It is very easy to add another function, in classes you can also add private functions, so you don't mess with the interface. So why don't use this advantage and limit you functions/procedures to 50 lines. Maybe even less. Get some meaningful names. In this way you render most comments obsolete. In this way your functions are easy to read, easy to modify/extend.

Of course...the last few sentences would have worked as: In classes there is the availability to define private functions, just use this possibility to split functions into 50 liners so it is be much more readable (don't forget good names, so you don't need to comment that much).

BUT: It is much more simple(!) to read everything if there is a fullstop which shows: I finished a thought, let's go on with the next one.

Thats what I would define as simple.

Title: How  'simple' is a real KISS solution?


答:
It depends on:

your personal preference

your employer's coding standards

the amount of risk involved

The two main problems associated with letting one case fall through to the next are:

It makes your code dependent on the order of the case statements. That's not the case if you never fall through, and it adds a degree of complexity that's often unwelcome.

It's not obvious that the code for one case includes the code for one or more subsequent cases.

Some places explicitly prohibit falling through. If you don't work at such a place, and if you're comfortable with the practice, and if breaking the code in question won't cause any real suffering, then it might not be the worst thing in the world. If you do it, though, be sure to put an attention-grabbing comment nearby to warn those who come later (including the future you).


答:
I started in a German code base, but when my company becomes more international, developers should document everything in English. Some do - other do it not. Those who worked in international teams switch to English.

I write all my programs in English, even programs for German use only (often they start German-only, later they are needed in other countries).

When I have complex code I switch to German. If I have problems to explain something in my mother language I don't try to explain it in a foreign Language. I add a short (or long) English explanation and add the German documentation, just in case I don't understand my own English.