答:
When working in a team, what happens when several people are working on one project and change the same files in different ways in one day?

I must to re-phrase and slightly fix previous answers.
Second commit will be not allowed automagically, committer has to update his modified WC (working copy) and merge (automatically or by hand - it depends) incoming changes with own. After merge he'll can commit.

when these changes are commit, they will overwrite each other?

If they intersect at the row level, then win only one variation (handmade merge result), if they touch different strings - repo will store 2 (or more) revisions with all changes

How should one go about testing their changes before commiting back to the master repo?

Same way as it was before SCM. QA and unit-test not related to version-control in common. And yes, developer can commit broken unfinished code of repo - it's a question of usage policy, not used SCM

Using PHP for my example, should the 'working' directory be in my xampp folder so I can test before commiting.

You have (at least) 2 choices:

Yes, site root can be root of (additional) working copy, which (WC)
have to be updated after each commit (read "post-commit hooks in
SVN") - this way you have to test always latest fresh full code.  But
don't forget to protect .svn folders inside site-tree from spy and
spiders

Another solution is to use svn export to extract code from repo and place it on site. Less security, but more headache - if wc update can handle all changes in source-tree (move-delete), export only place current snapshot, thus - all deletes|renames|moves will be performed only partially, without cleaning old data - you'll have delete *.*; (x)copy *.* and this means additional time and resources

Or should there be two "master repo's" on a webserver

You can't use repo content directly anyway, even with  FSFS you'll not see inside repo your stored objects

Title: Version Control Workflow (Subversion)


问:
Does teaching programming make you a better programmer
I consider myself an intermediate Python programmer and have been offered an opportunity to be a trainer for a beginner Python programming class.

I was wondering if this would really widen my programming repertoire. Has somebody had an enlightening experience after they successfully trained a group of people?

Does it also depend on those people -- whether they're programmers or noob students? (In my case they are intermediate .NET and Java programmers)

What should I expect from them?

One of my fears is -- what if I choked when one of them asked a tangled question. Is this normal?

答:
I haven't systematically taught programming myself, only tried to explain some concept or issue to more or less outsiders. It was always an interesting experience, and I learnt something every time.

Indeed, Jan Comenius noted already a couple hundred years ago that the best way to really deeply understand something is to explain it to others.

So go for it - it will be a valuable, enriching experience for you. You will surely get hard or surprising questions - that's OK. Don't try to pretend you know everything - just be honest and tell them something like "I don't know, but I will get back to you with an answer". They will only respect you better for being honest.

ContentLicense: CC BY-SA 3.0


答:
When you can successfully teach others something, whether programming or not, then you truly understand it.  Being able to teach others something most definitely makes you better at the skill as well.  Students will ask you questions that will surprise you and make you think of the subject differently.  You will become skilled in presenting the material in more than one way which will also lead you to a better understanding of the subject.

Being able to teach others has always been my litmus test as to whether I truly understand something.

Title: Does teaching programming make you a better programmer

Body:
I consider myself an intermediate Python programmer and have been offered an opportunity to be a trainer for a beginner Python programming class.

I was wondering if this would really widen my programming repertoire. Has somebody had an enlightening experience after they successfully trained a group of people?

Does it also depend on those people -- whether they're programmers or noob students? (In my case they are intermediate .NET and Java programmers)

What should I expect from them?

One of my fears is -- what if I choked when one of them asked a tangled question. Is this normal?


问:
Would using AJAX extensively improve server performance?
Clearly AJAX improves the user interface but does this also decrease server load?  You would think it does because the entire page will not have to be served up each time, but maybe there are other variables I'm not considering.  </p>

答:
There are other factors you are not considering -- in most cases, AJAX will increase server load. In a typical, non-ajax scenario, a user loads one big page every few seconds or few minutes. Yes, that single page is a bit more work for the server, but it has plenty of time between requests to recover and serve other requests. In an AJAXified scenario, that single page load is now dozens of small hits, constantly hammering the server and waiting for responses.

It is a bit like death from 1000 cuts -- none of the requests are that big in and of themselves, but the total weight is a killer. Especially when you start considering that these small requests are just about as expensive to serve as a full-page request. In both cases, you are probably running through an entire web application pipeline, hitting a database and waiting for an answer while sitting on a precious HTTP connection.

Here is an example of how ajax can get ugly on the server real fast. Let's take a typical "executive dashboard" that features 4 slots for widgets. Let's say the CEO likes a full sales report in the right side, a top 10 list of earners in the middle and a company share price report on the right. And let's say we are going to do this via simple ajax remote requests. Without taking into account stylesheets, images and other assets, your page now requires 4 HTTP round trips (main page, each of the dashboard reports) against the server. Each of these requires a full web stack to execute -- you are going to be hitting databases and rendering HTML using your web framework, right? Now multiply the single CEO by 2000 remote users some of whom have spotty connections.

Conversely, you could have a single server-side page that executues and returns a HTML skeleton as well as the data (included in in-page JSON) to render the reports. Single, bigger connection but less beating on the web server in total because you are not handling 4 requests and spinning up 4 pipelines, etc.


问:
Have objects delivered in terms of code reuse?
I have often heard it said that objects have not delivered in terms of code reuse. Do you agree? If you believe that they haven't, why not?</p>

答:
Honestly I'm not sure if "code reuse" is really what anyone is after (or at least, should be after). My philosophy is "software components", which means better maintainability through good interfaces and avoiding unnecessary coupling. "Code reuse" is one of the things that falls out of that sometimes -- unnecessarily duplicated code is a sign that you've organized things the wrong way and of course it's a pain to maintain.

To answer the question a little more directly, there's a collection of pretty good tools for avoiding repeating yourself: inheritance, traits, delegation, higher-order functions, etc. Of those, people tend to confuse inheritance with OO as a whole -- and they also tend to overuse it a bit, if you ask me. Maybe that's where some of the "OO sucks" vibe comes from: finding inheritance stuck where it has no natural right to be :)

ContentLicense: CC BY-SA 2.5


答:
An old University of Texas study made the following findings.

People retain:

10 percent of what they read

20 percent of what they hear

30 percent of what they see

50 percent of what they see and hear

70 percent of what they do

90 percent of what they teach

Following this logic the best way to LEARN something and retain what you have learned is to make your best effort at teaching it to somebody else.

Even though I coasted through Comp Sci 101 in school I took a tutoring job for C++ and didn't actually LEARN C++ until I was forced to teach it to struggling students.  It was like an orgy of lightbulbs going off in my head as I helped non CS grads with their assignments.


答:
On top of what everyone else has listed ("You have to know the material well" etc) if you're writing material for the course, it's good practice for writing documentation, because documents - be they course notes or technical documents - are written to transfer knowledge, even in industry.

But when you're in industry, often the documentation is for someone you haven't met and won't meet, so it's easy to fall into the trap of documenting what you did and not what the stakeholder/reader needs to know.

When you're writing for students in your class it's easier to practice and develop that mindset of useful documenting, since you're in close proximity to your stakeholder/reader. Hell, if you're really lucky a student will put their hand in the air and tell you your notes suck, and then you've learned something you can improve on.


答:
Yes.  I have often found that I didn't really understand something that well until I tried to explain it to someone else, especially someone without all the assumptions and buzzwords that a practitioner builds up over the years, either in first person (as a teacher or mentor), or even answering questions online (such as here on Stack Overflow!).

In addition, students may bring a different insight or (weird?) methodology to the problem, broadening the solution space.

A teacher, to be useful, may not have the answer on the tip of their tongue, but can say "I don't know", research it or look it up, and help the students find the answer faster and with a higher probability than can the students on their own.


问:
Do You Have To Know CIL To Make A Compiler for .NET?
Assume one wants to create a simple .NET language, or slightly more difficult, a compiler for an existing .NET language. Do you absolutely need to be familiar with the CIL (Common Intermediate Language) to implement a compiler? And do you have to translate the syntax of your language to CIL by hand? Or is there another (more preferable) way? If not, what is the best way to learn CIL and especially to learn how to translate High-Level code to CIL?

答:
Do you have to know CIL?  No, but it can help.

Do you have to translate your language to CIL?  It's not at all necessary.  (more in a moment)

What's the best way to learn CIL?  Well, I've found that the best way to do it is to:

1. Read up on the CIL instruction set, the PE file format, and always have these documents nearby as a handy reference.

2. Write a small program in a .net language you're already familiar with, this small program should only try to do one thing that you don't know how to do with CIL.  Compile it.

3. Use ILDASM to look at the program you've compiled as pure CIL.  Now you understand how to do that with CIL!

4. Return to 2. until you grok the CIL.

Is there another way?  Oh yes.  First, look into The CodeDOM.  This is a generic .net framework for 1) translating raw code into an object model, 2) translating an object model into code, or 3) Creating an executable.  If you implement a CodeDOM parser to generate an object model, you could then use the generic MSIL CodeProvider to write the CIL for you!  I haven't used this specific method, but I have created a compiler that generated CIL and used ILASM to create an executable.  I've also done code compilation using CodeDOM.  I would always choose to use as much CodeDOM as possible.

HTH!


答:
Of course it does serve to decrease the server load.
Look at this presentation @ jsconf'09 -- for how Facebook used ajax to do that.

Ajax is async. server communication -- and you can use that in myriad of ways. People use it for loading simple JSON to real-time Web, and everything in between.

Remember -- the real challenge is the balance between client and server. Strive to make each party do it's work such that the system is optimized and you get obvious benefits of Perceived Responsiveness and real Speed.

Title: Would using AJAX extensively improve server performance?

Body: Clearly AJAX improves the user interface but does this also decrease server load?  You would think it does because the entire page will not have to be served up each time, but maybe there are other variables I'm not considering.  </p>


答: When you are forced to explain something from first principles, it will definitely force you to understand it better. I often use this idea when searching for bugs in code, I drag someone in and try to explain to them how the code works. I usually find the bug within a few minutes. Same idea.</p>


问:
Why is Java considered more portable than other languages like C++?
What differs between "writing a specific JRE for each platform" for Java developers and "writing a C++ compiler for each platform" for C++ ones?</p>

答:
All the answers starting with "The difference is...", or anything very similar, are basically wrong (sorry, but such is life). There are really two separate differences between the two.

One (that's been mentioned a lot) is that a compiled Java program can (or least should) run on any conforming implementation of Java, so even after being compiled, you can still move a Java program from one platform to another without re-compiling. C++ (at least normally) requires re-compilation for each target platform.

The other is that Java (at least attempts to) assure that all correctly written Java will be portable. At least in theory, you shouldn't be able to write any code that isn't portable.

C++ allows you to do quite a few things that aren't portable. The C++ standard contains "warnings" about a lot of things that aren't portable (e.g., telling you that you'll get implementation defined behavior or undefined behavior), but it doesn't necessarily try to stop you from doing them at all. Just for example, if you want to write an operating system for hardware that uses a PCI bus, you're probably going to need to read/write the PCI configuration memory. This obviously won't be portable to systems without a PCI bus, but if you're writing an operating system for hardware with a PCI bus, it's pretty much necessary.  C++ allows it even though it obviously won't be portable.


问:
Are Bools/Bits Faster Than Integers
As the title suggests I'm wondering whether bools or bits are faster than using integers (1 and 0)?  Specifically I thinking about their speed in CASE statements, even more specifically in T-SQL (although it would be interesting to hear about experiences from other languages).

For some context, I have a pretty big SELECT statement over a large table which has to transform a lot of data based on integer being either 1 or 0, and was considering converting the integers to bits for a performance boost.

EDIT:

Thank you all for your responses.  It kind of seemed like you were all giving me pretty much the same advice worded slightly differently or with different levels of detail.

答:
The simple answer: it depends.

The more complex answer: it depends on how your language, compiler, and runtime deal with bools or bits, and the word length of your CPU registers (64, 32, even 16 or 8 still have some use in simpler computing devices).

There are a couple of major ways to set up a boolean:

Enumerated data type: public enum Bool {false, true};. This is probably the least space-efficient, as depending on the language/compiler an enum is usually turned into a bunch of byte constants, with compiler-checking to ensure that an invalid value is never used. However, most computers deal with byte values very efficiently; there's very little binary math required with them.

Bitmasks: When used, it's almost always behind the scenes, though .NET has "Flag Enums" that allow you to specifically set multiple bits on one composite value. The idea for bools is the same; your compiler will take each bool that has the same scope and pack them into bytes. The second boolean to be declared would be the second bit from the left or right, and can be tested with some simple binary math: a&0x02 >> 1 will return a 1 or 0 representing that particular boolean out of the byte.

Everything I know says that each boolean gets a byte in all but the most memory-critical applications, similar to the first option, because the extra computation for bit-packing slows the application considerably to save a paltry 8 bytes of storage space, and only when the booleans are not actively needed.

Title: Are Bools/Bits Faster Than Integers


答:
If you are using AJAX to replace work that the server would otherwise be doing then yes that will improve server performace. However, you may have designed things so that the server is still doing just as much and now whatever is happening with AJAX is on top of what the server was already doing.

Mostly this is about UI stuff, since you shouldn't be doing anything else on the client-side. Basically, anything the server was doing to support UI (eg. reload the page with a different layout in response to user input) do with JavaScript instead.


答:
If HTML rendering is a huge part of your application server's performance profile, then moving HTML rendering to the client can be a performance win on the application server.

However, if HTML rendering is a small part of your application server's performance profile, then more requests will typically mean more trips through the stack, more queries, more of everything on the application server, a performance loss.

Of course, the only way to know in your particular case is to try it out.


答:
I would say it definitely makes a difference. From my personal experience, I defend this because of following reasons :-

While reading, sometimes the mind become lazy enough to ignore the details or begin assuming things instead of giving a thorough read to understand the concerned top. That's the particular reason for having incomplete knowledge gains while reading yourself.

In case of teaching, it's all together a different story. Here one cannot provide assumptions but facts, so a thorough reading is done for teaching. Also, the teachers feels that it's his responsibility to provide the complete and correct knowledge, which again prompts for further proof-reading.


问:
Should I tell someone that their commit caused a regression?
When you track down and fix a regression—i.e. a bug that caused previously working code to stop working—version control makes it entirely possible to look up who committed the change that broke it.

Is it worth doing this? Is it constructive to point this out to the person that made the commit? Does the nature of the mistake (on the scale of simple inattentiveness to fundamental misunderstanding of the code they changed) change whether or not it's a good idea?

If it is a good idea to tell them, what are good ways to do it without causing offense or causing them to get defensive?

Assume, for the sake of argument, that the bug is sufficiently subtle that the CI server's automated tests can't pick it up.

答:
There are a lot of factors at play.

How severe is the bug?

What's the seniority relationship between you and the breaker?

How busy/stressed out is the team?

Was the breaker working in their part of the codebase or yours?

How certain are you that it was real a bug, and how certain are you that your fix is correct?

If the problem was minor - a typo/thinko/cut & paste bug - and the breaker is a busy peer, and you're confident in your assessment of the problem, you probably don't need to bring it to their attention. (e.g. foo.x = bar.x; foo.y = bar.y, foo.z = bar.y).

In most other cases, it's a good idea to mention the problem. In non-serious cases, you don't need to interrupt what they're doing; wait and do it over lunch or when running into them in the break room.

If the nature of the error indicates a serious misunderstanding (of the implementation platform, the local policies, or the project spec), though, bring it up ASAP.

If you aren't certain of your assessment, ask for them to review your fix, especially if it's not in code that you're very familiar with. (I strongly recommend your dev team adopt a 'code buddy' policy where all changes are reviewed by one other person prior to checkin, anyway.)


问:
How is Delphi XE2 going to work across platforms?
So I've been reading a little about Delphi XE2 and I probably will go to the world tour thing in Chicago coming up later this month and ask this question if no one can answer it here.

What I wonder is how is my Delphi code going to be executed on a Mac? Is something else going to have to run (i.e. virtual machine) in order for the program to run?

答: It's so good but RTL support in this release has bugs. Embarcadero promised to fix it in update packs.</p>


问:
How would you go about creating a class diagram for a JPA/JSF application
I was creating a class diagram for an application I was working on today and I didnt include the JPA entities since I had all the information I thought was important in my DAOs, for example, I just care about how to register a user regardless of what information does a User object contain, so I only included the UserDao in my class diagram and added an operation called register which has a parameter of type User without having a User class in my diagram.

My question is if its necessary to include every single class I have in my diagram or can I omit the classes that I will be forced to add because I am using a certain framework such as JSF or JPA?

答: I certainly wouldn't include the classes generated from HTML page templates in a class diagram.  But it's your diagram.  Include whatever you want.  Who is your audience?</p>


答:
Absolutely yes. Teaching gives you a platform to polish your knowledge of the material as well as enhance your presentation layer.

Additionally it helps you build bonds with other developers which can later translate into effective development team relationships.


问:
How to cope with the problem of (compiling) a large code base?
Although I can code, I don't yet have any experience with working on large projects. What I did so far was either coding small programs that get compiled in matter of seconds (various c/c++ exercises like algorithms, programming principles, ideas, paradigms, or just trying out api's...) or working on some smaller projects that were made in a scripting language(s) (python, php, js) where no compiling is needed.

The thing is, when coding in a scripting language, whenever I want to try if something works - I just run the script and see what happens. If things don't work, I can simply change the code and try it out again by running the script again and keep on doing that until I get the result that I wanted.. My point is that you don't have to wait for anything to compile and because of that it is quite easy to take a big code base, modify it, add something to it, or simply play with it - you can see the changes instantly.

As an example I will take Wordpress. It is quite easy to try and figure it out how to create a plugin for it. First you start by creating a simple "Hello World" plugin, then you make a simple interface for admin panel to familiarize yourself with API, then you build it up and make something more complex, in the mean time changing how it looks a couple of times.. The idea of having to recompile something as big as WP over and over again, after each minor change to try "if it works" and "how it work/feels" just seems inefficient, slow and wrong.

Now, how could I do that with a project that is written in a compiled language? I would like to contribute to some open-source projects and this question keeps bugging me. The situation probably differs from project to project where some of them that were pre thought wisely will be "modular" in some way while others will just be one big blob that needs to be recompiled again and again.

I would like to know more about how this is done properly. What are some common practices, approaches and project designs (patterns?) to cope with this? How is this "modularity" called in programmers world and what should I google for to learn more about this? Is it often that projects grow out of their first thought proportions which becomes troublesome after a while? Is there any way to avoid long compiling of not-so-well designed projects? A way to somehow modularize them (maybe excluding non-vital parts of program while developing (any other ideas?))?

Thanks.

答:
You don't recompile the whole project every time. For example, if it's a C/C++ application, there are chances it will be separated into libraries (DLLs in Windows), every library being compiled separately.

The project itself is generally compiled daily on a dedicated server: those are nightly builds. This process can take a large amount of time, because it included not only the compile time, but also the time spent running unit tests, other tests and other processes.


答:
In addition to what the other answers mention, don't forget that while teaching you can also learn from your students if you're open minded about it.

You mentioned in a comment that your "knowledge of Java/.NET is near zero".  That's a perfect opportunity to learn from your students.  Teaching isn't a one way process.

If you don't know the answer to a question, don't try to hide that fact.  The biggest disservice that a teacher can do to a student is to pretend they know something that they don't.  At best you lose their trust when they figure out you don't know what you're talking about, at worse you mislead them and pass on false information which is worse than no information.


答: In addition to what others have said, make sure it's ACTUALLY their commit that caused a bug.  Certainly don't blame someone else for your own mistake.  No matter how tactfully you approach them, you're still going to piss them off if you've blamed them for something they didn't do.  (Speaking as someone who has been blamed for other peoples' bugs constantly; one time someone came up to me and said I did something utterly stupid and I brought up the commit log and found that the last person to touch that line of code was the person who was blaming me.  Somehow he still seemed to think it was my fault because I'd written the line originally.)</p>

Title: Should I tell someone that their commit caused a regression?

Body:
When you track down and fix a regression—i.e. a bug that caused previously working code to stop working—version control makes it entirely possible to look up who committed the change that broke it.

Is it worth doing this? Is it constructive to point this out to the person that made the commit? Does the nature of the mistake (on the scale of simple inattentiveness to fundamental misunderstanding of the code they changed) change whether or not it's a good idea?

If it is a good idea to tell them, what are good ways to do it without causing offense or causing them to get defensive?

Assume, for the sake of argument, that the bug is sufficiently subtle that the CI server's automated tests can't pick it up.


答:
It depends on what you're doing and how you're doing it.

If you're replacing full page loads with AJAX requests (i.e. only
doing AJAX calls when a user clicks on what would have been a full
page load) then AJAX will decrease server load because you're
(presumably) doing less processing and returning less data.

On the otherhand, if you're adding auto-update type AJAX that polls
the server every few seconds then that could increase load
depending on the user (it might not increase the server load if the
user keeps hitting F5 to refresh manually anyway, but most people
generally don't do that for hours)

Another AJAX optimization is to only load more data as you scroll.
In that case if the user doesn't scroll all the way down, that's
wasted processing.

Of course actually implementation can skew results either way, these are typical results assuming reasonably good implementations.


答:
I would say No. Being a teacher doesn't make you better - learning makes you better. If you have to learn to be a teacher, then you'll become better. Teaching only helps you retain what you know, but in the world of IT everything changes daily. Because of this, you cannot just rely on teaching, you have to get your ... bum... off the couch and learn.

I have met may IT professors who were ignorant when it came to their actual field.They had certificates, courses, papers on the wall, lots of "show". Sure they could talk the talk, but if you EVER got off of the prescribed course schedule they would flutter, stutter and fail. They couldn't handle the pressure of things changing. They didn't change with the times, they taught what they knew, which was obsolete.

So let's turn this around again, I've had a few professors that were amazing. They were developers, senior developers, lead developers, directors of application development, then they became programmers. They knew real world scenarios, they knew that 99% of the stuff in text books didn't prepare people for real life work, so they changed it up, kept it current.

12 years ago my grade 11/12 IT teacher gave me an offer. If throughout each school year I was able to break his security / firewalls etc. at school, he'd give me an A+ (100%) in the course, regardless of my work. Heck, I helped him plan the course as I working as a jr. developer back then. That offer he gave me made him (at the time) an expert at windows NT security. I did get 100%, I had to steal his UN/PW and then lock him out... it was the only way in the end... But needless to say he got better as a teacher and in IT because of teaching - he worked WITH his class - not on his own agenda.

So where do you draw the line? Draw it on the attitude of the teacher. If that teacher is willing to learn, they will get better. If that teacher is just riding the wave, getting paid, and could care less - they're going to get worse.


答:
In addition to MainMa's answer, we've also just upgraded the machines we work on. One of the best purchases we've made was an SSD for when you can't help but to recompile the entire project.

Another suggestion would be to try a different compiler. Back in the day, we switch from Java's compiler to Jikes and now we've moved on to using the compiler bundled with Eclipse (don't know if it has a name) which takes better advantage of multicore processors.

Our 37,000 file project took around 15 minutes to compile from scratch before we made these changes. After changes it was cut down to 2-3 minutes.

Of course, its worth mentioning MainMa's point again. Don't recompile the entire project every time you want to see a change.

Title: How to cope with the problem of (compiling) a large code base?

Body:
Although I can code, I don't yet have any experience with working on large projects. What I did so far was either coding small programs that get compiled in matter of seconds (various c/c++ exercises like algorithms, programming principles, ideas, paradigms, or just trying out api's...) or working on some smaller projects that were made in a scripting language(s) (python, php, js) where no compiling is needed.

The thing is, when coding in a scripting language, whenever I want to try if something works - I just run the script and see what happens. If things don't work, I can simply change the code and try it out again by running the script again and keep on doing that until I get the result that I wanted.. My point is that you don't have to wait for anything to compile and because of that it is quite easy to take a big code base, modify it, add something to it, or simply play with it - you can see the changes instantly.

As an example I will take Wordpress. It is quite easy to try and figure it out how to create a plugin for it. First you start by creating a simple "Hello World" plugin, then you make a simple interface for admin panel to familiarize yourself with API, then you build it up and make something more complex, in the mean time changing how it looks a couple of times.. The idea of having to recompile something as big as WP over and over again, after each minor change to try "if it works" and "how it work/feels" just seems inefficient, slow and wrong.

Now, how could I do that with a project that is written in a compiled language? I would like to contribute to some open-source projects and this question keeps bugging me. The situation probably differs from project to project where some of them that were pre thought wisely will be "modular" in some way while others will just be one big blob that needs to be recompiled again and again.

I would like to know more about how this is done properly. What are some common practices, approaches and project designs (patterns?) to cope with this? How is this "modularity" called in programmers world and what should I google for to learn more about this? Is it often that projects grow out of their first thought proportions which becomes troublesome after a while? Is there any way to avoid long compiling of not-so-well designed projects? A way to somehow modularize them (maybe excluding non-vital parts of program while developing (any other ideas?))?

Thanks.


答:
The idea of having to recompile something as big as WP over and over
  again, after each minor change to try "if it works" and "how it
  work/feels" just seems inefficient, slow and wrong.

Executing something interpreted is also very inefficient and slow, and (arguably) wrong. You're complaining about the time requirements on the dev's PC, but not compiling causes time requirements on the user's PC, which is arguably a lot worse.

More importantly, modern systems can do quite advanced incremental rebuilds and it's not common to recompile the whole thing for minor changes- compiled systems can include script components, especially common for things like UI.


答:
Just like it has been said, you never recompile the whole project each time you make a small change. Instead you only recompile the part of the code that has changed, as well as all code depending on it.

In C/C++, compiling is pretty straightforward. You compile translate each source file into machine code (we call them object files *.o) and then you link all your object files into one big executable.

Just like MainMa mentioned, some libraries are built into separate files, that will be linked dynamically at run-time with the executable. These libraries are called Shared Objects (*.so) in Unix and Dynamically Linked Libraries (DLL) in Windows. Dynamic libraries have many advantages, one of which being that you don't need to compile/link them, unless their source code effectively change.

There are build automation tools that help you:

Specify dependencies between different parts of your source tree.

Launch punctual, discreet compilations only in the part that was modified.

The most famous ones (make, ant, maven,...) can detect automatically which parts of the code has been changed since last compile, and exactly what object/binary needs to be updated.

However, this comes a the (relatively small) cost of having to write a "build script". It is a file containing all the information about your build, like defining the targets and their dependencies, defining which compiler you want and which options to use, defining your build environment, your library paths, ... You maybe heard about Makefiles (very common in the Unix world), or build.xml (very popular in the Java world). This is what they do.

ContentLicense: CC BY-SA 4.0


答:
Here's my list of stuff you can try to speed up C/C++ builds:

Are you setup to only rebuild what has changed? Most environments do this by default. There's no need to recompile a file if it or none of the headers has changed. Similarly, there's no reason to rebuild a dll/exe if all the linked in objs/lib haven't changed.

Put 3rd party stuff that never changes and the associated headers in some read only code library area. You only need the headers and the associated binaries. You should never need to rebuild this from source other than maybe once.

When rebuilding everything, the two limiting factors in my experience have been number of cores and disk speed. Get a beefy quad core, hyperthreaded machine with a really good hdd and your performance will improve. Consider a solid state drive -- keep in mind the cheap ones may be worse than a good hdd. Consider using raid to increase your hdd

Use a distributed build system such as Incredibuild which will split up compilation across other work stations on your network. (Make sure you have a solid network).

Setup a unity build to save you from constantly reloading header files.


答: Not only teaching increase your programming knowledge or skills, it is also useful to write programming articles and tutorials. If you can explaint a topic to others in an understandable way, it means you also know and understand that topic.</p>


答:
Yes, you will get a deeper understanding. I made similar experiences like the other answers you get here.

I made an additional experience: I got quicker in error analyses. You teach people, so they make errors, you never thought about. When you help them, you get an eye for problematic code (at least, I did).

One of my fears is -- what if I choked when one of them asked a tangled question. Is this normal?

I think, it is normal. And my scholars had no problem, when I was honest (and I provided the answer later). In the opposite - they saw that nobody must know everything. The most important thing is to know, how to get informations. One of my best lessons was, when I didn't know the answer and we looked together to the manual to get the answer. After that, they knew how to read manuals.


问:
How should someone used to FP thinking read imperative code?
I graduated from university about five months ago, and have been working in a local startup for past four months. While at university, I studied Haskell, F# etc on my own. We were taught Java at the university, but I was exposed to functional programming very soon, and have spent far more time with it than I did with imperative programming. As a result, my brain is wired for a functional thinking. The company I have joined uses Python, and the code is heavily imperative. I am having a very hard time reading imperative code. I cannot keep a track of mutations. When an for-if-else-for-... nesting goes more than four levels deep, I completely lose the track of what's happening in the code. To add to it, Python is a dynamic language, so there are no types in the code. It's been weeks since I have been trying to understand a part of our codebase (which is supposedly 'moderately complex'), but I haven't made any appreciable progress so far in understanding it. Please offer me some practical techniques on how I should go about understanding that code. Thanks in advance!

Edit:

Maybe I should also mention that there aren't really many comments in the code, and the names are also not very intuitive.

答:
You might try translating some fragments from Python into pseudo-Haskell or whatever you like.  That can give you a sense for what imperative constructions loosely map into what functional constructions.  As you get more experience the imperative constructions will start to feel more native.

I went from programming OCaml and Haskell to programming Java and Python, and my experience is that imperative programming is not as big a leap as dynamic typing, which to this day feels alien.


答:
Simple answer: Yes.

Longer answer: My last job was at an Agile company that used TDD with CI tools to ensure that what was in our SVN repo was good, working code at all times. When something was committed, our TeamCity server got a copy, compiled, and ran unit tests. It also ran integration tests hourly. If something was committed that caused the CI to fail, everyone got an e-mail stating the build had broken based on a commit by a particular person.

That didn't always catch everything; woe to us, we didn't enforce code coverage, and even if something was covered by unit or integration tests, they might not exercise that code sufficiently. When that happened, whoever got the task of fixing the known issue (if QA caught it) or defect (if, dun-dun-dun, the clients did), would run a "blame" (shows who last modified each line of a code file) and determine the culprit.

Calling someone out for checking in broken code is not necessarily a bad thing. They have failed to do their job properly, and either they or someone else had to go back and fix the mistake. This happens all the time; how big a deal it should be depends on how easy the fix was, whether the mistake indicates the person didn't even compile or run the code in question, and the overall corporate culture. What's important in the whole thing is that something is learned by the person who made the mistake; if the build breaks due to the same guy over and over again, there's a deeper issue with that person which must be addressed. Builds breaking all the time indicate an issue with the team's communication or knowledge of the process.


答:
You have to consider the best way to implement your solution.  A simple non dynamic form does not need ajax and adding it may actually harm perfomance.  If your problem is bad queries all the ajax optimization in the world is not going to get you a performance increase that will be acceptable.

If your server is overworked you need to figure out why.

If you are getting alot of hits then ajax is not going to fix that problem you need more capacity.  Adding ajax will just increase the number of requests that your server has to handle.

If you have a complicated page you should see if there is anything you can do client side to reduce the load on your server. If your page is dynamic but really has a limited data package caching that for client side adjustment may pay off better.

And some times Ajax will help.  When you have complex forms with dynamic data ajax wins the day.  But if you queries are complicated and take a long time to run then ajax still will not solve your problem.


答:
You're getting excellent answers here.

I could only add a technique I learned from a manager once when I would make a mistake.

I was the middle-aged consultant with the Ph.D. and she was the young manager without, so there could have been a perceived prestige gradient.
At any rate, she had clearly had experience with this situation and knew how to handle it.

She mentioned to me in an almost apologetic tone that there seemed to be a problem, and would I have time to look into it?

Often enough, the error was mine, and she knew it.
That is skill.


问:
What traits do the best testers you've worked with have in common?
Tester and blogger Lanette Creamer recently posted this question on Twitter:

If you are a professional software developer who works with testers, think of the best testers you know. What traits do they have in common?

I thought it would make an excellent question for here.

My thoughts are:

They want to remove ambiguity from requirements even if it means asking awkward questions.

They create new features by seeing the way software "should" work, rather than just how it's documented.

They demonstrate honesty and integrity and encourage but not demand it from those around them. In other words, they model behavior.

What are the traits of the best testers you've worked with?

答:
Here are a few that I'd add:

Smart - These people come across as rather bright or deep thinkers.  Boundary cases come quickly to these people it seems.  They may ask the, "What about. ." questions a lot.

Attention to detail - Listing reproduction steps, stating the difference between expected and actual results, etc.  Thorough in their work.

Self-motivated - The better testers I know seem to drive themselves to be thorough and go, go, go! Get things done would be another way to state this to my mind.

Analytical - Arguing over priority or severity with calm, rational arguments.  Understanding what bugs are going to get fixed ASAP and which are too cosmetic, e.g. a bad color choice.

Tenacity - They stuck to their interpretation unless a project manager, business analyst, or someone with the power changed the requirements to overrule them.  Not a push-over for another way to put this.


答:
I've taught technical college level classes (but not on software development). Here's my take:

Will it make you a better programmer?

Not 1:1. You won't gain the same experience as you would writing programs - but that is not a bad thing by any means (read on).

Would it widen your programming repertoire?

Absolutely. You'll have new challenges, and will need to (re)learn some things that you never knew or had forgotten over the years. Some of that will be useful in the future. It presents you with many new challenges and concepts. You will need to approach technical issues from new perspectives, and you can learn a lot by taking that perspective and by solving those problems. If you can effectively teach somebody what they need to understand technical problems, it will often improve your knowledge of the subjects and extend your knowledge domains. As well, you mention they already know another language, some say one of the best ways to improve is by learning new languages.

Does it also depend on those people?

Working with professionals in a nearby domain changes the structure dramatically. They already know how to communicate with computers, to write programs. Syntax and logic will be quick for them to learn. They will ask challenging questions in the first week.

What should I expect from them?

I would expect they will benefit most if you have the ability to relate the course's content to the languages they are already familiar with: "Yes, subject is similar to Java in these ways, but different for these reasons". I would expect the pace they learn to be quite quick, such that you should expect to invest a good amount of time outside class in preparation (again, a lot to learn, but the topics would interest most developers.)

What if I choke when I'm asked a tangled question. Is this normal?

Well, they are as experienced as you are, but in another area (although related). explanations can be tough, and you can't be expected to know everything or to have the same area of expertise as all of them (combined). The ability to say "I don't know" is a good quality in a teacher. If they are experienced as well, you can often come to answer via a short discussion ("Oh, we solve that problem using this technique"). If that fails, you should find the answer by the next session (for you and for them).


问:
What does artifact mean?
The dictionary defines artifact as:

artefact, artifact [ˈɑːtɪˌfækt]
  n

something made or given shape by man, such as a tool or a work of art, esp an object of archaeological interest

anything man-made, such as a spurious experimental result

(Life Sciences & Allied Applications / Biology) Cytology a structure seen in tissue after death, fixation, staining, etc., that is not normally present in the living tissue

The word artifact often appears in software development, software development cycles, effort estimation, etc. But the above definition doesn't make sense to me in that context.

Could someone please explain this word by giving some specific examples from software industry?

答: An artifact is something that is created directly or indirectly as a consequence of something else created.  Software artifacts may consist of your project source or resources, or they could be represented as unforeseen manifestations of the interactions between your sources or resources.</p>

Title: What does artifact mean?


问:
Seperating business logic and layout in a highly interlocked project
My company is developing software that has a lot of technical debt that has existed for more than 20 years. It's a mix of C++ and C and consists of about 2M LOC. I would like to make some suggestions how we can advance our project and get rid of technical debt while using modern design principles.

This application is heavily modularized and consists of more than 250 modules that can be viewed by the user. Those modules are designed with our own framework, an xml-file with all the layout, some business logic that is interpreted by the application and a c++ class with other logic.

For example to create a mask with single grid that displays some data, we need to create the generic class-files that register our new module to the application, open our application in designer-Mode, place a grid in our module and attach a sql-statement that fetches the data for it. If we would like to add some logic that is not possible with our designer, we need to add some callbacks to our class and add those to our grid in the designer. Now the xml-file is filled with all the information our application needs to generate that module (i.e. where exactly the grid is, the ID, the attached callbacks and the sql to fill it).

As you can see there is absolute no cut between design, business logic and the dependencies.

There are of course two main advantages:

many things can be done without recompiling the application

small errors can be fixed by non-developers (like wrong SQL statements, name of labels, placement of the elements

But I hope you agree with me, that this system could benefit a lot, but I'm not experienced to propose my own solutions. What steps can I take to solve that problem in a realistic way thats acceptable for both us developers and management?

答:
Every now and then comes a point in the life of a programmer where he/she needs to jettison the 'anything goes' and 'newer is better' paradigms and conduct an exercise in decency.

This project looks like a splendid opportunity for that. It is most likely that there is no benefit in a redesign or recreation from scratch, at least not measurable by the management, no matter how olden and tiresome it may look to you: The domain knowledge (seemingly) has long ago become an essential part of the interlock and no feasible amount of all the kings mythical man-months can separate it again.


答: Having to solve dozens of "why won't my code work?" problems while teaching exercise sessions in an introductory programming course made me a whole lot better at comprehending code on the fly and simulating it in my head.</p>


问:
Why don't we use browser detection and platform-specific CSS?
Nowadays, the common phenomena is to develop a website for a browser and then corresponding apps for Android phones, iPhone, tablets and so on. </p>

<p>Since all the platforms come with a browser, why aren't companies using CSS to accommodate them? Surely we can detect from the request which browser was used and from which platform the request came. Reading those values, why don't we just implement the corresponding CSS for different platforms. Like we do for IE, Chrome and Safari. This way we can use the platforms' browser capabilities and don't need to develop subsequent apps for a platform.  </p>

答:
some do already. its a matter of what you taking it upon yourself to doing it. you can use polyfills (aka modernizers) to fix other browsers and you can serve up specific css per browser/platform.
developing natively will always have its perks, but html5 is gaining ground in the arena and imo will nearly be equal to native soon enough.
you can serve up tons of different styles via media queries. all the tools are out there, it's really a matter of making it your prerogative. </p>


答:
The word artifact is often used in relation to quality management certifications  like CMMI and ISO 9001, and methodologies like Six Sigma. In this context artifact refers to the products and byproducts of the software development process.

Artifacts are gathered and archived throughout the process to be used as evidence that the documented process is being followed. Such artifacts are mainly useful during a certification audit, but collecting and archiving them also makes it easier to figure out how or why the process failed if problems arise.

Artifacts might also be measured and analyzed to find ways to improve the process, measured some more to show evidence of improvement, and then measured continuously after that to show that the process remains in control (i.e. the metrics in question stay within some specified bounds).

Title: What does artifact mean?

Body:
The dictionary defines artifact as:

artefact, artifact [ˈɑːtɪˌfækt]
  n

something made or given shape by man, such as a tool or a work of art, esp an object of archaeological interest

anything man-made, such as a spurious experimental result

(Life Sciences & Allied Applications / Biology) Cytology a structure seen in tissue after death, fixation, staining, etc., that is not normally present in the living tissue

The word artifact often appears in software development, software development cycles, effort estimation, etc. But the above definition doesn't make sense to me in that context.

Could someone please explain this word by giving some specific examples from software industry?


答:
I didn't quite understand it myself before I got my Android phone, but the user experience really is quite different between a mobile app and a mobile site.

As a user I almost always prefer using a native app to a mobile site (unless the mobile app is poorly done).

A site is fine for simple display of information, but if it's a web-app, it's much more natural to use a native app that takes advantage of the touch interface than a mobile web-app.

Title: Why don't we use browser detection and platform-specific CSS?

Body:
Nowadays, the common phenomena is to develop a website for a browser and then corresponding apps for Android phones, iPhone, tablets and so on. </p>

<p>Since all the platforms come with a browser, why aren't companies using CSS to accommodate them? Surely we can detect from the request which browser was used and from which platform the request came. Reading those values, why don't we just implement the corresponding CSS for different platforms. Like we do for IE, Chrome and Safari. This way we can use the platforms' browser capabilities and don't need to develop subsequent apps for a platform.  </p>


答:
Answering the title "Is portability a myth ?", instead of "Which is better at portability, Java or C++", I'll say that partial portability is possible, but full portability it's does a myth.

Something that I insist to write, and it applies to this question, is that developers are not longer working with just programming languages, but, with full programming frameworks.

And those frameworks, include libraries, databases, graphical interfaces.

Which programming language, or which programming framework is more portable ?

Well, it depends, on what your app. is trying to achieve.

Title: Why is Java considered more portable than other languages like C++?

Body: What differs between "writing a specific JRE for each platform" for Java developers and "writing a C++ compiler for each platform" for C++ ones?</p>


答:
I think it depends on how well you personally decide to prepare. I don't like being made to look like a fool, so when I teach, I over prepare, go into much more detail in my notes than what I tend to bring up in class. That way I feel secure I can handle most questions. Anytime I've prepped for a class, I found some fine detail that I had either forgotten or overlooked until then. Designing exercises can be particulalrly challenging.

Prepping for people who are already exisitng programmers is a whole level of extra effort. You can expect to have some people in the class who hate that they are being asked to learn Python vice thier beloved C# (or whatever). They will challenge everything you say. You may have others who already have some knowledge and will ask advanced questions on the first day. In the first case, make sure you keep on topic and DO NOT get into discussing the differences between the languages unless the class is not behaving hostilely. Simply return to the material you are going to cover.  In the second case almost all advanced question can be refered to later in the class (giving you time to look up the answer if you don't know it.) So that should give you confidence.  I always prep some harder exercises for the people who are taking the class because they have to but they are already familiar with the subject matter. Sort of independent study for the easily bored. (And are they surprised when I pull out those advanced topic exercises for them to do while everyone else is struggling with an exercise they did in five minutes!)

Most programmers though, like to learn and will be eager to get started doing something useful. You can probably keep basics down to a minumum, this kind of class is bored by doing Hello World type exercises. Make things more practical and business useful. You can plan to cover more material with experience than non-experienced programmers, so more to prep. If you can make the exercises specific to the kind of work they will be doing, that is even better.

Students have a remarkable ability to interpret things you say in a unique way. Their mistakes may be things it would never occur to you to do. Helping them fix their mistakes and explaining why they are mistakes will help you in code reviews!


答:
I think there's a deeper issue underlying this question. Yes, the submitter should certainly be made aware of the consequences of their change, so that they can understand what happened and not do the same thing again. However, the context of your question indicates that you prepared and submitted a fix without the original submitter's knowledge that they even caused a problem. Therein lies the deeper issue: why doesn't the submitter already know about the regression and why didn't they fix it themselves? The situation you described may indicate a lack of accountability or vigilance on the part of the original submitter, which is a potential concern with respect to their overall performance and motivation.

My software engineering experience has taught me to own all of my code changes, not just projects I'm responsible for, all the way to production, which includes being aware of their impact, including on your build system and (obviously) product behavior.

If someone's change has caused a problem, it doesn't mean the person is a bad engineer, but usually they should be responsible for and involved in fixing whatever has gone wrong. Even if they are not "at fault," e.g. their code exposed an underlying bug that has existed in the codebase for years, they should be one of the first people to be aware of a problem with their change. Even if the original submitter isn't the right person to fix the bug, they should be closely connected to the life cycle of their change.


问:
When does switching to a framework mid-project make sense?
Some of my friends and I started a PHP project some weeks ago. In the beginning, I suggested we use a PHP framework such as CodeIgniter or Zend. But my friends wanted to start clean and without the overhead or extra complexity.

But as time has passed, the project has become more and more complex. At first, we wrote all the code in the view files, in code blocks before the HTML output. Eventually, we changed direction and started to use controllers that did most of the work. But as you can see there is a coding difference here.

At this point, we're trying to determine how to proceed before the project becomes more complex. When does it make sense to start over and use a framework? Or is it possible to formulate a simple way to introduce an MVC pattern to our existing code without having to start from scratch?

答:
Ugh. That's a complicated question that I've always struggled with. My first projects started like yours did. We ended up doing complete rewrites about 2 years into each project whether or not we wanted to. I'd advise either doing the painful thing now, or planning on doing it at a set time.

The awesome thing about switching to a framework is that they usually came with unit testing, which allowed us to move existing code over by mapping existing inputs and outputs into the unit testing framework. Unit testing personally bores me as a programmer, but it's an awesome tool for going from "version 0.1" to "version 1.0" of a project.

Most of the bigger frameworks I've used (Zend and Symfony) have easy ways to include custom javascript into their views -- either in library form or inline in the views. I don't think that should be a concern.

The bigger question is if you pause development to roll your features into a framework, or if you should try to integrate pieces of the framework as you go. I've never seen the former work well; it gets boring (to me). The latter does not work well with Symfony but works great with Zend.


答:
Most of the time the perception of an extra "burden" or overhead to using a web framework deals with the added time needed to learn the framework. But we cannot tell what your friend really means by "starting clean". Is he simply against black-box solutions?

So many PHP frameworks use the MVC pattern, which leaves you with a lot of options. The time needed to research and experiment with the most popular to see which fits your needs better often would preobably be less of a cost than the time needed to roll your own. At least then you can have a better idea of whether your proposed features would really need a custom framework or not.

Title: When does switching to a framework mid-project make sense?

Body:
Some of my friends and I started a PHP project some weeks ago. In the beginning, I suggested we use a PHP framework such as CodeIgniter or Zend. But my friends wanted to start clean and without the overhead or extra complexity.

But as time has passed, the project has become more and more complex. At first, we wrote all the code in the view files, in code blocks before the HTML output. Eventually, we changed direction and started to use controllers that did most of the work. But as you can see there is a coding difference here.

At this point, we're trying to determine how to proceed before the project becomes more complex. When does it make sense to start over and use a framework? Or is it possible to formulate a simple way to introduce an MVC pattern to our existing code without having to start from scratch?


答:
What happens if you don't tell them?

The cons

They may make the same mistake in other places because they don't understand that it is causing a problem. Not only that but there will be extra unnecessary time to repeatedly fix the same mistake. You can't learn from mistakes you are unaware you nade.

Second, they think they are doing a better job than they are. When people are not made aware of their problems they can hardly be blamed for thinking they are doing well when they aren't. Even when the problem is a careless mistake, people make fewer of them when they are aware that the mistakes are noticed.

Next if someone doesn't look up who did it, how will you know if you have a particular problem employee who is either always careless or has basic misunderstandings of the product? Would a responsible person want that to continue in a team he or she is associated on?

If you fix and move on without discussing it are you sure, you fixed it correctly? Sometimes it is tests that need to change when a requirement changes. If it is something other than a fairly minor typo, can you really be sure either one of you has the correct solution? You might be breaking his code in return without consulting.

The pros

People don't get embarrassed or annoyed with you for pointing out their mistakes.

I guess I come down strongly on the side of telling them but doing it nicely and privately. There is no need for public humiliation. If the person repeatedly makes the same mistakes or is making critical mistakes that show a lack of understanding, then the supervisor needs to be made aware as well.


问:
Prefer class members or passing arguments between internal methods?
Suppose within the private portion of a class there is a value which is utilized by multiple private methods.  Do people prefer having this defined as a member variable for the class or passing it as an argument to each of the methods - and why?

On one hand I could see an argument to be made that reducing state (ie member variables) in a class is generally a good thing, although if the same value is being repeatedly used throughout a class' methods it seems like that would be an ideal candidate for representation as state for the class to make the code visibly cleaner if nothing else.

Edit:

To clarify some of the comments/questions that were raised, I'm not talking about constants and this isn't relating to any particular case rather just a hypothetical that I was talking to some other people about.

Ignoring the OOP angle for a moment, the particular use case that I had in mind was the following (assume pass by reference just to make the pseudocode cleaner)

```<code>int x
doSomething(x)
doAnotherThing(x)
doYetAnotherThing(x)
doSomethingElse(x)
</code>```

So what I mean is that there's some variable that is common between multiple functions - in the case I had in mind it was due to chaining of smaller functions.  In an OOP system, if these were all methods of a class (say due to refactoring via extracting methods from a large method), that variable could be passed around them all or it could be a class member.

答:
If the value is a property of the class, keep it in the class. Otherwise, keep it outside. You don't design your class methods first. You design its properties first. If you did not think of putting that property inside the class in the first place, there is probably a reason for that.

The worst thing you can do, in terms of scalability, is changing your code for convenience. Sooner, rather than later, you'll find your code is bloated and duplicated. However, I must admit. Sometimes, I break this rule. Convenience is just so damn appealing.


问:
What did Linus Torvalds mean by his quotation about portability?
In a debate with Andrew Tanenbaum over microkernel vs. monolithic operating system architecture, Linus Torvalds said,

Portability is for people who cannot write new programs.

What did he mean by that?

答:
Tanenbaum makes the point that much of Linux is written in a non-modular way to leverage the 386 CPU, state of the art at the time, instead of making the CPU interaction be a component, and thus very easily swappable. Tanenbaum essentially believes that the fact that the Kernel is so monolithic and tied to 386 CPU makes it very difficult to,

Port Linux itself to another CPU platform (Obviously incorrect, AMD64, PowerPC, etc)

Port Programs written for linux x86 to another CPU architecture (also incorrect)

The linux camp makes several points, among which:

Linux offers multithreaded filesystem as part of the design

Microkernel, while interesting and intuitive are not very performant

The portable API adherence makes the portability issue more or a niggle as opposed to a blocker.


问:
For user defined data, is it better to use a table of tables or dynamically created tables?
In an application that allows users to define their own tables and columns (details of that are not the focus of this question, but imagine a tool that lets users create their own forms and automatically handles storage, just to get the idea) is it better to store each table and column they create in a "table" table and a "column" table, or to dynamically create tables and columns?

This "one table to rule them all" question is somewhat related, but in that case the "table" table is more clearly a bad idea.  In this case, if you don't go that route then all your queries will have to be dynamically generated.

Even though the argument "don't write yet another application designer tool for non-programmers, so you can keep adding features until you are basically having users develop in a crummy version of, say, Visual Studio, using your custom crummy language" is pretty reasonable, I've had a lot of projects with some version of the user defined tables requirement and this question is about how to implement it.  Whether to implement it is another question, but probably too specific to particular applications to be a good question here.

答:
Pros of "table" table- Simpler to write queries, quicker development time, you probably shouldn't be dealing with complicated functionality anyway, since that would be added by programmers, not users.

Cons of "table" table- The database can't see your "real" tables so it can't validate, optimize, or index very well.

Cons of dynamic tables - Ugh, writing dynamic queries is a giant pain.


答:
if the value does not change, it is by definition a constant and should be encapsulated inside the class. In such case, it is not considered to affect the state of an object.
I don't know your case but I think of something such as PI in trigonometry.
If you try to pass an argument of such a constant, you could be exposing the result to error if the client passes the wrong value or a value not with the same accuracy as the method(s) expect.

Title: Prefer class members or passing arguments between internal methods?

Body:
Suppose within the private portion of a class there is a value which is utilized by multiple private methods.  Do people prefer having this defined as a member variable for the class or passing it as an argument to each of the methods - and why?

On one hand I could see an argument to be made that reducing state (ie member variables) in a class is generally a good thing, although if the same value is being repeatedly used throughout a class' methods it seems like that would be an ideal candidate for representation as state for the class to make the code visibly cleaner if nothing else.

Edit:

To clarify some of the comments/questions that were raised, I'm not talking about constants and this isn't relating to any particular case rather just a hypothetical that I was talking to some other people about.

Ignoring the OOP angle for a moment, the particular use case that I had in mind was the following (assume pass by reference just to make the pseudocode cleaner)

```<code>int x
doSomething(x)
doAnotherThing(x)
doYetAnotherThing(x)
doSomethingElse(x)
</code>```

So what I mean is that there's some variable that is common between multiple functions - in the case I had in mind it was due to chaining of smaller functions.  In an OOP system, if these were all methods of a class (say due to refactoring via extracting methods from a large method), that variable could be passed around them all or it could be a class member.


问:
Does teaching programming make you a better programmer
I consider myself an intermediate Python programmer and have been offered an opportunity to be a trainer for a beginner Python programming class.

I was wondering if this would really widen my programming repertoire. Has somebody had an enlightening experience after they successfully trained a group of people?

Does it also depend on those people -- whether they're programmers or noob students? (In my case they are intermediate .NET and Java programmers)

What should I expect from them?

One of my fears is -- what if I choked when one of them asked a tangled question. Is this normal?

答:
Based on my own experience as a teacher. I would say NO.

Because, while you do get better understanding of basics, by teaching kids and / or newbs, you are not making any improvements that relate to your actual profession.

Why does this happen ? - because programming is developing faster than people can study. New languages and frameworks appear, new tools, new concepts, new hardware. And professional programmer MUST know his domain. Or else - nobody would need him.

You might want to say - 'but you can study fundamental algorithms', - and i say to you - 'but you should have studied them in university'.

Other topic is work rhythm. "Teachers" are slow, they are not used to solve actual real world problems fast.

And last but not least - teaching is giving. When you want to teach - you cannot stop yourself ;) its just a call from inside, an unyielding urge to share your knowledge, to reduce stupidity around you, and, eventually, make the world a better place ;)


答:
When you can answer YES to any of this questions:

It will take a greater effort for you to stay on your path, than to go back and change frameworks.

You realize your current implementation does not support a required feature you can't do without.

It is more cost effective to go back and change than to keep on the current path. (Similar to the first.)

You do not have a delivery date and you just want to try out something different.

When should you NOT do it:

When you'll miss a delivery date because of the change. What to do: Deliver it how you planned, then change it. It might be more costly to go back and miss a delivery date, than just to change it later and make it version 2.


答:
Perhaps you should extract a new class containing all the methods sharing that value.  Of course the highest-level method will be public in the new class.  It may be helpful to expose that method for testing.

If you have two or more temporaries that are always passed together, then you should almost certainly extract a new class.


答:
If you don't actually need to hold the state between invocations (and apparently you don't, or you wouldn't ask the question) then I would prefer the value be an argument, rather than a member variable, because a quick glance at the method's signature tells you that it uses the argument, while it's a little harder to tell right away what member variables are used by the method.  It is also not always quick to determine what private member variables are for.

So normally I wouldn't agree that code using member variables is visibly cleaner, but if the method signatures are getting out of hand I might make an exception.  It's a worthwhile question, but not something the project will hinge on in any case.


问:
What should I do when my project manager does not care about implementation details?
My project manager, when providing requirements for specific tasks, does not care about the implementation details. Although he has a programming background and has some knowledge of the MVC framework, he does not consider the perspective of the developer.

For example, I was given a task to create a simple form in ASP.NET MVC. This form should be pluggable - that is, the customer should choose which fields do or do not exist and which fields are required. If this were a simple form with validation, I would easily be able to implement it using ASP.NET validations. However, the problem is not simple and requires design and architecture first. The time that I have to implement the solution, which is not well understood, is very restricted. Not having sufficient time will not let me come upwith a solution that meets the requirements, but also benefits myself and any future developers.

What should I do in this situation? Do you feel that given requirements in the example can be expected from a single developer?

答:
What should I do when my project manager does not care about implementation details?

The project manager (PM) should not care about implementation details. That's not their job, but rather the job of the software developers. Ultimately, the responsibilities of a project manager are to control the cost, schedule, scope, and quality of a project. Depending on the process methodology used, the PM might also be the primary point of contact with the customer. On a regular basis, the PM is responsible for coordinating requirements, design, implementation, testing, and maintenance activities. The job might also entail business perspectives - obtaining funding, contractual obligations, and so on.

The PM considers the project as a whole, not as the individual components. Those are up to the people in the functional roles as well as the people leading those function roles. In short, there's nothing wrong (and, I might even argue that there's everything right) with a project manager who isn't concerned with implementation details.

Will telling him that this is not easy make him see me as being lazy and a slacker?

Absolutely not. Although your PM has a software development background, he probably doesn't do that much software development anymore, if any. It's the responsibility of the engineer to estimate task length and difficulty.

In some cases, you might be given a deadline to complete the task in. If this deadline is inappropriate for the task, it's the responsibility of the engineer to inform the project manager and/or appropriate supervisors of the problem, associated risks, and reach a resolution. It might not be the best resolution, but it's important for everyone to be on the same page when it comes to decisions.

Do you feel that given requirements in the example can be expected from a single developer?

Just about any requirement can be completed by a single developer, given that they have enough experience and knowledge. However, the length of time needed and the quality of the output will change. A developer with experience in the particular domain and technologies can design, implement, and test a solution much quicker than a developer with limited experience. It's not possible to say if you can finish this assignment in the given length of time or not.


答:
Part of requirements gathering is requirements validation. Validation is for correctness and for feasibility. Feasibility deals with constraints of time, complexities, expertise, etc.
The project manager should ensure that approved requirements are feasible before passing them to designer/developer.

Apparently this approach is not followed in your project (as is the case in many others...).

I assume that you are given a time frame for this task. Either you can solve the problem in the given time frame or you can't. If you can't you have to clarify to your PM the problems you are having and suggest a time frame or ask him to review the requirement with the user.
This is a positive attitude and should not be looked at as a negative one. If you don't the time will slip and there will be no value added by keeping quite.

Title: What should I do when my project manager does not care about implementation details?

Body:
My project manager, when providing requirements for specific tasks, does not care about the implementation details. Although he has a programming background and has some knowledge of the MVC framework, he does not consider the perspective of the developer.

For example, I was given a task to create a simple form in ASP.NET MVC. This form should be pluggable - that is, the customer should choose which fields do or do not exist and which fields are required. If this were a simple form with validation, I would easily be able to implement it using ASP.NET validations. However, the problem is not simple and requires design and architecture first. The time that I have to implement the solution, which is not well understood, is very restricted. Not having sufficient time will not let me come upwith a solution that meets the requirements, but also benefits myself and any future developers.

What should I do in this situation? Do you feel that given requirements in the example can be expected from a single developer?


问:
Why do so many developers believe performance, readability, and maintainability cannot coexist?
While responding to this question, I began to wonder why so many developers believe a good design should not account for performance because doing so would affect readability and/or maintainability.

I believe that a good design also takes performance into consideration at the time it is written, and that a good developer with a good design can write an efficient program without adversely affecting readability or maintainability.

While I acknowledge that there are extreme cases, Why do many developers insist an efficient program/design will result in poor readability and/or poor maintainability, and consequently that performance should not be a design consideration?

答:
One problem is that finite developer time means that whatever you seek to optimise takes away from spending time on the other issues.

There's a rather good experiment done on this referenced in Meyer's Code Complete. Different groups of developers were asked to optimise for speed, memory usage, readability, robustness and so forth. It was found that their projects scored high in whatever they were asked to optimise in, but lower in all the other qualities.


答:
Do people prefer having this defined as a member variable for the
  class or passing it as an argument to each of the methods - and why?

If I understand what you're asking:  The methods in a class are by definition privy to the implementation details, so I'd have no qualms about using any member directly from any method.

On one hand I could see an argument to be made that reducing state (ie
  member variables) in a class is generally a good thing...

There's nothing wrong with declaring a private static final to define constants.  The compiler will be able to use the value in considering some optimizations, and being constants, they don't really add state to the class.

although if the same
  value is being repeatedly used throughout a class' methods...

Being able to refer to it symbolically (e.g., BLRFL_DURATION) and not having to add extra arguments to your methods will make your code more readable and therefore more maintainable.


问:
Are Bools/Bits Faster Than Integers
As the title suggests I'm wondering whether bools or bits are faster than using integers (1 and 0)?  Specifically I thinking about their speed in CASE statements, even more specifically in T-SQL (although it would be interesting to hear about experiences from other languages).

For some context, I have a pretty big SELECT statement over a large table which has to transform a lot of data based on integer being either 1 or 0, and was considering converting the integers to bits for a performance boost.

EDIT:

Thank you all for your responses.  It kind of seemed like you were all giving me pretty much the same advice worded slightly differently or with different levels of detail.

答:
This answer is not specific to T-SQL, or SQL, but is a more general answer to the title of this question, "Are Bools/Bits Faster Than Integers", this is certainly true for some microcontrollers which actually have a "bit" data type in hardware, such as the 8051 architecture and many PICs processors from Microchip.

In the 8051, the bit addressable memory in RAM runs from byte addresses 0x20 through 0x2f (128 bits total), and any SFR (special function register) whose address ends in 0 or 8 (another potential 128 bits, but not all are implemented).  To support these, the 8051 has several bit-addressable instructions such as set bit, clear bit, complement bit, jump if bit set or clear and several more.  The RAM bits are very useful for use as flags, and the SFR bits allow registers to be set, toggled, and cleared individually.

In most PICs (but not the PIC32), all internal RAM and I/O ports are bit addressable, and supported by instructions such as set bit, clear bit, and skip if a bit is set or reset.  Since the working register WREG and status register are mapped to internal addresses also, one can do bit tests on those also.

On CPUs which do not have bit-addressable instructions, as other posters have noted, it would be necessary to load an entire word from memory and do a bit-wise operation on it, which might take as many as three instructions: load, and/or/xor, and store or branch.

C compilers for the 8051 and PICs typically have a "bit" data type in addition to char, short, int and long to allow C code to take advantage of these operations.

Title: Are Bools/Bits Faster Than Integers


答:
I suggest you put breakpoints and start using the Next command (as if you're debugging), this will help you understand the flow (probably on branches, there are paths which are more likely to be taken, on those you should concentrate to get the general idea of the code).

(I had good results with Eclipse along with PyDev as Eclipse plugin)

Title: How should someone used to FP thinking read imperative code?

Body:
I graduated from university about five months ago, and have been working in a local startup for past four months. While at university, I studied Haskell, F# etc on my own. We were taught Java at the university, but I was exposed to functional programming very soon, and have spent far more time with it than I did with imperative programming. As a result, my brain is wired for a functional thinking. The company I have joined uses Python, and the code is heavily imperative. I am having a very hard time reading imperative code. I cannot keep a track of mutations. When an for-if-else-for-... nesting goes more than four levels deep, I completely lose the track of what's happening in the code. To add to it, Python is a dynamic language, so there are no types in the code. It's been weeks since I have been trying to understand a part of our codebase (which is supposedly 'moderately complex'), but I haven't made any appreciable progress so far in understanding it. Please offer me some practical techniques on how I should go about understanding that code. Thanks in advance!

Edit:

Maybe I should also mention that there aren't really many comments in the code, and the names are also not very intuitive.


问:
Why is Java considered more portable than other languages like C++?
What differs between "writing a specific JRE for each platform" for Java developers and "writing a C++ compiler for each platform" for C++ ones?</p>

答:
You have misunderstood the premises.  Java programs are very portable, because the JVM provides a standard behaviour guaranteed to be the same.  C++ programs have a less standardized environment closer to the actual hardware, so the program needs to be able to handle the various platform specific details - like size of an int, word alignment etc etc etc.

The JVM itself is not very portable.  It is a herculean task to port a high-performant JVM to another platform or CPU architecture.


问:
How do I get over my .NET hump?
I've been teaching myself how to write code with the help of a very talented friend, who unfortunately is talented enough that he has never free time. I've read and worked out of a couple books, but I feel more like I'm going through motions, rather than elegantly solving real world problems. What did you guys do to get out of your larval stage?

Is there a course or educational product out there that isn't quite the $1500 all encompassing lecture, but more than just a dry,"regurgitate this example," type book?

答:
I would try out the c# book from headstart. It takes a fun and humorous approach, that may be just what you are looking for. </p>

<p>Also, I would start working on some projects that are meaningful to you. Even the most dry text will seem interesting when it contains the next puzzle piece to an interestingproblem you are working on. </p>

Title: How do I get over my .NET hump?

Body:
I would try out the c# book from headstart. It takes a fun and humorous approach, that may be just what you are looking for.

Also, I would start working on some projects that are meaningful to you. Even the most dry text will seem interesting when it contains the next puzzle piece to an interestingproblem you are working on.


答: Programming is hard enough that few people elegantly solve real world problems until they spend quite some time learning.  Try solving small real world problems in a painfully ugly way first, then go back and try to make it more elegant.</p>

Title: How do I get over my .NET hump?

Body:
I've been teaching myself how to write code with the help of a very talented friend, who unfortunately is talented enough that he has never free time. I've read and worked out of a couple books, but I feel more like I'm going through motions, rather than elegantly solving real world problems. What did you guys do to get out of your larval stage?

Is there a course or educational product out there that isn't quite the $1500 all encompassing lecture, but more than just a dry,"regurgitate this example," type book?


问:
Tabs versus spaces—what is the proper indentation character for everything, in every situation, ever?
The coding standards for the code hosted in drupal.org suggest to use two spaces to indent the code; other sites suggest to use tabs to indent the code.

What is the proper indentation character for everything, and in every situation? Please explain the answer you give.

答:
Spaces, because when you align comments to the right of code, or function parameter lists, or complex multiline expressions, or things of that nature, you want your beautiful work to appear right for everyone. If you use tabs and allow people to set their tabstops differently, they will break alignment for all but the simplest cases of code indenting.

Besides, it's blatantly obvious that everyone in the world should be using vim, which makes it trivial to indent, unindent, and navigate through "tab stops" even in space-indented files.


答: Look into a refactoring book on your language of choice. Here's one: Professional Refactoring in C# & ASP.NET I recommend. Goes beyond basic coding and shows you how to elevate your existing code. You'll get exposed to a little theory, OOP, design paterns, and a way to develop this skill.</p>

Title: How do I get over my .NET hump?


问:
Are there any studies of cross-functional teams vs. domain-based teams (e.g. project-based vs. software/mechanics/etc)?
I work in an organization which creates many integrated systems products - i.e. it is complete products with mechanical/system/electronics/software being designed and manufactured.  At the moment most teams are organized around projects in a cross functional way.  The advantage of an organization like this is that people who are working closely together for a common goal are close.

The disadvantages come from the isolation of engineers from their peers. Typically a project is assigned only one software engineer.  This means that the projects have a high truck factor, minimal knowledge sharing and best practices, and technical development is limited.

So my question is: are there any studies comparing the cost/benefits of these two approaches?

答:
The best type of team structure to use isn't necessarily one of cost-benefit, but instead on the organizational culture currently in place, the characteristics of the employees, and the type of project being conducted. Because of these variables, there's no way to say that a particular strategy or approach is best, but there are some general indicators as to how you can best structure a team to complete the task at hand.

There are many types of teams and ways to organize teams and organizations. Some of the more common forms are functional, lightweight, heavyweight, and autonomous. Below, I'm summarizing a portion of a book on managing technological innovation - Melissa A. Schilling's Strategic Management of Technological Innovation.

A functional team is entirely non-cross-functional. Every employee remains within their own department. Total isolation between science, engineering, human resources, and so on. An employee will report to a functional manager. Under this structure, people working on a project tend to be more committed to their functional department rather than to the project. This structure is appropriate for what is known as a derivative project - leveraging existing work with only minor modifications or improvements and projects that only (or mostly) require a single type of expertise.

Lightweight teams occur when members reside in their functional departments and report to functional managers. However, a project manager is introduced. The project manager will oversee the people that are needed to carry out the project, but not manage them directly. The role of the project manager is to facilitate communication and ensure that each member on the project is appropriately contributing. This structure is best for derivative projects that don't require a large amount of coordination and communication between members.

Heavyweight teams remove required individuals from their functional departments, however they still report to a functional manager. A project manager oversees the project activities, but doesn't directly supervise or manager the individual team members. Project managers typically outrank the functional managers in this environment and are responsible for evaluating, rewarding, and leading the project members. These teams have a high degree of communication and collaboration among those assigned to the project and the members are also committed to the success of the project. This format is used on platform projects, which are used to improve cost, quality, and performance from a previous generation (but might not have significant new innovation).

Autonomous teams remove members from functional departments entirely, and having them work directly under a project manager. Project managers here are senior staff members and leaders of the organization. Sometimes, these teams are given immense freedom to "get the job done" by developing their own policies and procedures. At the same time, they would be held entirely accountable for the successes or failures of the project. These types of teams are often deployed on breakthrough projects, which introduce new innovation into the organization's products, or to produce new business units.

However, just because a particular team type might be generally good for a particular type of project, it also matters what the culture of the organization is. Some organizations can't (or won't) support autonomous teams for cultural reasons. Others "have always done it" a certain way and simply won't change. It also matters what kind of people are on the team - some people function better if they are colocated and have a high degree of communication and ability to collaborate, while others prefer their space to solve the problem and throw it back out.

The following papers/books/documents are cited by the section of the book I'm reading:

S.C. Wheelwright and K.B. Clark, Revolutionizing Product Development: Quantum Leaps in Speed, Efficiency, and Quality (New York: Free Press, 1992).

F. Damanpour, "Organizational Innovation: A Meta-Analysis of Effects of Determinants and Moderators," Academy of Management Journal 34, no. 3 (1991).

E.F. McDonough, "Investigation of Factors Contributing to the Success of Cross-Functional Teams." Journal of Product Innovation Management 17 (2000).


答:
If you have the basics ironed out, why don't you try building something with what you know. Get serious about a small project and see where you get stuck, then find out how to solve your 'real life problem'. I am sure you will get a handful of those. Without hands on experience, you may read books forever and still not learn how to do things.

Make sure that your objectives are: realistic, simple (but not trivial), clear and short.

After you finish this project, start criticizing it and think how it could be made better, add features and solve more problems. When you have done this few times, you will be able to assess your real show stoppers (database design, coding logic, HTML, etc.). Once you identify those problems, you can find books, courses, etc. that could help you overcome them.

Title: How do I get over my .NET hump?


答:
New developers go through a larval stage where they haven't yet assimilated the skills necessary to solve problems using basic constructs like loops.

Reading a book will not get you over this hump any more than reading a book on karate will make you a yellow belt. It's about repetition. Working the muscles. You have to burn the patterns into your head by doing it over and over and over.

So I hope you like programming! :)

My advice is to play. Find some simple, fun projects to work on and just hack away at them. If you're mathy, you could try Project Euler  or you could go to Rosetta Code and find some  simple, linear problems to work through.

Good luck. The work will pay off, I promise!

Title: How do I get over my .NET hump?


答: The thing is "you" don't write the JRE you write the Java code which runs on any JRE. "You" do write the C++ code which can require changes by you before it will compile on another platform.