问:
Standards of unit testing output
Simple question, what's more common /  standard / won't make future developers look at me cross-eyed for unit testing:

Displaying just the errors, or reporting every passed test?

答:
I would say that showing every test and its pass/fail/skipped status is the best, because it gives positive feedback that each test was successfully run or purposefully skipped.

However, if you are building your own tools, I recommend giving the user an option to choose what they want to see.

Title: Standards of unit testing output


问:
Can display issues affect SEO?
Can website display issues on certain platforms affect a website's search rankings and potentially hinder any SEO efforts?</p>

答:
It's possible that display techniques might cause problems with SEO. I'll go over a few but without more specifics it's hard to say if what you're doing will cause problems or be unimportant.

URL - Your URL should include page specific keywords (yoursite.com/brandname-mens-loafers.php). The directory depth shouldn't be excessive, no more than about 3-4 levels at most. Querystring parameters should be avoided as much as possible since this can cause duplicate on-site content and other crawling problems. URL's should be easy for people to copy to share via social media, email, blogs and so forth.

Content Layout - Insure meaningful, keyword relevant, content displays above the fold. Avoid using AJAX or other client side script techniques to show primary information although additional info can be shown using this technique. If possible, try to load as much textual content as possible at page load.

Mobile - Use a responsive CSS layout rather than a separate subdomain for mobile. This prevents crawling errors, unintended content duplication and so forth. Include address, phone number and other contact info.

Page elements - Avoid links to outside sites, especially sitewide footer/sidebar links. Use a clear title and description metatags. These aren't important for ranking but may be used to display info about your page on search engine results, thus improving click-thru. Include widgets for sharing your link via social media and email.

ContentLicense: CC BY-SA 3.0

Title: Can display issues affect SEO?


问:
When to use C over C++, and C++ over C?
I've been introduced to Computer Science for a little over a year now, and from my experience it seems that C and C++ are both considered to be "ultrafast" languages, whereas others such as Python and such scripting languages are usually deemed somewhat slower.

But I've also seen many cases where a software project or even a small one would interleave files where a certain number n of those files would be written in C, and a certain number m of those files would be written in C++.

(I also noticed that C++ files almost always have corresponding headers, while C files not so much). But my main point of inquiry is to get a general sense of intuition on when it is appropriate to use C over C++, and when it is better to use C++ over C. Other than the facts that (1) C++ is object-oriented whereas C is not, and (2) the syntaxes are very similar, and C++ was intentionally created to resemble C in many ways, I am not sure what their differences are. It seems to me that they are (almost) perfectly interchangeable in many domains.

So it would be appreciated if someone could clear up the situation! Thanks

答:
Things about C++ that make C programmers nervous

There's a lot of magic happening under the hood; constructors, destructors, virtual methods, templates, etc., can make C++ code a lot easier and faster to write than the equivalent C code, but harder to understand and reason through (depending on how well you know C++ and its associated conventions).  Something as simple as Foo newFoo; may invoke a lot of code, depending on how the constructor for class Foo (and any classes it depends on) has been defined.  This is also why the convention is to write ++it instead of it++ when iterating through a container, since postfix ++ often involves an expensive copy operation.

Depending on what you're doing, there can be some non-trivial overhead, especially for simple tasks.  Take the following two programs, the first in C, the second in C++:

```<code>/* C version */
#include <stdio.h>
int main(void)
{
  char greeting[] = "Hello, world";
  printf("%s\n", greeting);
  return 0;
}
/* end C version */

/* C++ version */
#include <iostream>
#include <string>
int main(void)
{
  std::string greeting("Hello, world");
  std::cout << greeting << std::endl;
  return 0;
}
/* end C++ version */
</code>```

Identical behavior, not a whole lot of difference in terms of source, but on the SLES 10 box I work on with gcc 4.1.2, the former generates an executable of ~9kb in size, whereas the second takes over 12.5kb (no optimization), almost 28% larger. The C++ string type is a lot easier to work with IMO than the C string library, and C++ streams are a lot more flexible and customizable than C streams, but for really brain-dead code like this, they may not be worth the overhead.

C++ is a huge language compared to C, with some extremely complex semantics.  It takes a lot longer to get proficient with C++ than C, meaning a lot of people who claim to know C++ don't know it as well as they think they do.

Things about C that make C++ programmers nervous

C is not a secure programming language by any stretch of the imagination; no bounds checking on arrays leads to lots of exploitable behavior (be it through the now-dead gets function, or through scanf with the %s and %[ conversion specifiers).  C++ at least gives you containers that throw exceptions if you try to access outside their currently defined range; all C gives you is (if you're lucky) a segmentation violation.

Memory management in C is very labor-intensive and error prone, compared to the tools C++ provides you.  If you're building your own container, you're responsible for matching up all the malloc and free calls, making sure allocations are successful, backing out any partial allocations in the event of an error, etc.  In C++, you just add items to or remove items from the container.  If there's a problem, an exception will be thrown.

Similarly, error handling in C is a pain in the ass compared to the tools C++ provides (namely, exceptions).  What's really fun is when you've allocated a bunch of memory and then hit a wall in your processing; as you have to back out, you have to release that memory in the right order.  With C++ and RAII principles, this is (relatively) easy to do.

So when do I use one over the other?

If what you're writing is a bog simple, read it / muck with it / get rid of it application, whose behavior can be described cleanly in terms of inputs and outputs, and performance matters, then prefer C over C++.  Otherwise, prefer C++

Title: When to use C over C++, and C++ over C?

Body:
Things about C++ that make C programmers nervous

There's a lot of magic happening under the hood; constructors, destructors, virtual methods, templates, etc., can make C++ code a lot easier and faster to write than the equivalent C code, but harder to understand and reason through (depending on how well you know C++ and its associated conventions).  Something as simple as Foo newFoo; may invoke a lot of code, depending on how the constructor for class Foo (and any classes it depends on) has been defined.  This is also why the convention is to write ++it instead of it++ when iterating through a container, since postfix ++ often involves an expensive copy operation.

Depending on what you're doing, there can be some non-trivial overhead, especially for simple tasks.  Take the following two programs, the first in C, the second in C++:

/* C version */
#include <stdio.h>
int main(void)
{
  char greeting[] = "Hello, world";
  printf("%s\n", greeting);
  return 0;
}
/* end C version */

/* C++ version */
#include <iostream>
#include <string>
int main(void)
{
  std::string greeting("Hello, world");
  std::cout << greeting << std::endl;
  return 0;
}
/* end C++ version */

Identical behavior, not a whole lot of difference in terms of source, but on the SLES 10 box I work on with gcc 4.1.2, the former generates an executable of ~9kb in size, whereas the second takes over 12.5kb (no optimization), almost 28% larger. The C++ string type is a lot easier to work with IMO than the C string library, and C++ streams are a lot more flexible and customizable than C streams, but for really brain-dead code like this, they may not be worth the overhead.

C++ is a huge language compared to C, with some extremely complex semantics.  It takes a lot longer to get proficient with C++ than C, meaning a lot of people who claim to know C++ don't know it as well as they think they do.

Things about C that make C++ programmers nervous

C is not a secure programming language by any stretch of the imagination; no bounds checking on arrays leads to lots of exploitable behavior (be it through the now-dead gets function, or through scanf with the %s and %[ conversion specifiers).  C++ at least gives you containers that throw exceptions if you try to access outside their currently defined range; all C gives you is (if you're lucky) a segmentation violation.

Memory management in C is very labor-intensive and error prone, compared to the tools C++ provides you.  If you're building your own container, you're responsible for matching up all the malloc and free calls, making sure allocations are successful, backing out any partial allocations in the event of an error, etc.  In C++, you just add items to or remove items from the container.  If there's a problem, an exception will be thrown.

Similarly, error handling in C is a pain in the ass compared to the tools C++ provides (namely, exceptions).  What's really fun is when you've allocated a bunch of memory and then hit a wall in your processing; as you have to back out, you have to release that memory in the right order.  With C++ and RAII principles, this is (relatively) easy to do.

So when do I use one over the other?

If what you're writing is a bog simple, read it / muck with it / get rid of it application, whose behavior can be described cleanly in terms of inputs and outputs, and performance matters, then prefer C over C++.  Otherwise, prefer C++


问:
What kind of metrics, if any, can be collected from requirements development?
We elicit requirements from our product stakeholders by creating and refining user stories in monthly sprint planning meetings.  This includes defining use cases, acceptance criteria, and identifying constraints, and the final result is a sprint backlog of user stories.  The high-level customer requirements are refined into lower-level product requirements through design reviews among the development team throughout the sprint.  The design reviews result in UML diagrams, software interfaces, and, in general, a human language description of various software requirements.

We are increasing our metric-awareness as an organization so that we can better identify potential areas of process improvement (and so that we can eventually be appraised at CMMI level 3).

What kind of useful metrics are there to collect in the elicitation and refinement of customer requirements?

答:
How long you spend developing requirements.  This is to see if the overhead is worth the benefit.

Average time to implement a requirement (requirements per hour or day).  Some tasks are unavoidably complex, but in general, better-defined requirements don't take as long to implement.

How often requirements change between requirements development and the end of a feature's implementation.  This measures both how well you understood the requirement and if you're breaking them down into small enough pieces.

Lag time between requirements development and start of implementation.  This measures how well you're focusing on the most urgent needs.


问:
Is it a good idea to install Mercurial on your server and hg pull to deploy?
I've just started at a new job this past month and looks like they have NO source control for their code. They are relying on the backups their hosting provider takes for them.

After talking a bit I convinced my boss that we should definitely be using source control and after I gave a short seminar on it, the entire team is on board; they loved Mercurial.

So right now this is the way we work:

```<code>º----------BitBucket
º---------/
º--------/
</code>```

Myself and the three other developers hg pull from BitBucket, make our changes, then hg push to BitBucket.

Now for deployment, someone would need to FTP the latest files towards the production server.

I was thinking of installing Mercurial on our server, and using hg clone (subsequently hg pull) to keep the versions up to date on production.

```<code>º---push->-----BitBucket----<-pull-----º (production server)
º---push->----/
º---push->---/
</code>```

Is this a good idea? Any potential pitfalls I may not be seeing? Has anybody here done something similar? How do you deploy a large PHP framework application (We're using Moodle)?

答:
We do this, or things similar to this. The nonatomic @johannes mentions angle is one issue, though in realistic terms it happens so fast it should be OK and there are ways around this as he points out.

Probably more important than this non-atomicity would be "how do you manage database schema updates" -- deploying bad code this way makes fixing that easy. The big issue is when you deploy an update that changes the database that you wish to roll back. Or if you are making bad updates and corrupting data.

The other issue we had with DCVS tools (as opposed to using SVN) is that you now have a copy of the entire codebase on the machine someplace an attacker could potentially grab. And also that that DCVS codebase can get pretty heavy size-wise, which could matter if you are paying for storage and/or backup. We are still using SVN for the final deployment for these reasons.


问:
Should I take help of Internet and other programmers or I should do all programming myself?
I am a developer in a good company. I was given a task by my company to accomplish within a week however I finished the same in 4 days, my boss, the client, and other team members all are happy by my work; even I was! However suddenly I got a thought in my mind: "For my work I took some code from internet and mixed it up with my programming and gave the result faster however, my worry is that I should have done the task all of my own so that I would have a better understanding of it (even which was taken from internet)".

Can anyone tell me if I am ruining my programming career this way (I mean by using others code)?

答: Probably not. Getting parts of solutions online is not that uncommon. If you don't understand what you are copying and pasting from the internet, you will eventually run into trouble. If you take a little bit of time and effort to learn about the code you find and how to adapt it better to your own circumstances, that is fine!


答:
There are two sides to this issue that you need to watch out for. On the one hand, don't reinvent the wheel. On the other hand, avoid licensing traps.

The internet is a great resource for getting code to do things quickly. There are all kinds of useful libraries and other utilities that make life easier. The issue of developer knowledge is certainly important and you do not want to be unable to withstand a code review because your code is replete with someone-else's. As Brian Kergihan once said: "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." Using code from people more clever than you are may well (and likely will) result in the inability to debug said code efficiently or effectively.

This leads me into my second point. Almost all code on the internet is licensed. Either explicitly or implicitly by copyright or similar. Certain licenses are very permissive as to what you can do with code, others much less so. The GNU GPL is famous for rendering any code it touches open source by default. Even one function could potentially render you obligated to release your codebase as open source software. Even Stackoverflow and the rest of Stack Exchange is licensed.

So by using other people's code willy nilly, you run the risk of both technical and legal shibolleths, the likes of which you may not understand.

Title: Should I take help of Internet and other programmers or I should do all programming myself?

Body:
I am a developer in a good company. I was given a task by my company to accomplish within a week however I finished the same in 4 days, my boss, the client, and other team members all are happy by my work; even I was! However suddenly I got a thought in my mind: "For my work I took some code from internet and mixed it up with my programming and gave the result faster however, my worry is that I should have done the task all of my own so that I would have a better understanding of it (even which was taken from internet)".

Can anyone tell me if I am ruining my programming career this way (I mean by using others code)?


答:
Licensing issues aside, I don't think there's a real answer to your question.

If you have a lot of time and think that writing some piece of code by yourself will be useful to you in the future, do it. Otherwise, don't. Or maybe you can copy some piece of code but still take the time to understand it. That might be the best thing to do, or it might not be the best thing to do. It depends on the situation, and you can't really tell for sure until it's over.

It all comes down to making judgments. You can't make the right judgments all the time, but you can avoid doing things dogmatically, without looking at the specific situation that you're in... Although, overthinking can be another pitfall.


答:
It is hard to tell what metrics to collect for an unknown project with unknown goals. I would strongly recommend you to take a look at some kind of goal definition approach (such as GQM). Using this methodology you might come with metrics that best suit your needs.

Basically, GQM (goal, question, metric) defines a process where: you first define your measurement goals, those goals lead you to some questions, and those questions require metrics to be answered. So, in the end, you have metrics that really support your goals.

Hope it is helpful.

Title: What kind of metrics, if any, can be collected from requirements development?

Body:
We elicit requirements from our product stakeholders by creating and refining user stories in monthly sprint planning meetings.  This includes defining use cases, acceptance criteria, and identifying constraints, and the final result is a sprint backlog of user stories.  The high-level customer requirements are refined into lower-level product requirements through design reviews among the development team throughout the sprint.  The design reviews result in UML diagrams, software interfaces, and, in general, a human language description of various software requirements.

We are increasing our metric-awareness as an organization so that we can better identify potential areas of process improvement (and so that we can eventually be appraised at CMMI level 3).

What kind of useful metrics are there to collect in the elicitation and refinement of customer requirements?


问:
What is abstraction?
Is there a generally agreed upon definition for what a programming abstraction is, as used by programmers? [Note, programming abstraction is not to be confused with dictionary definitions for the word "abstraction."] Is there an unambiguous, or even mathematical definition? What are some clear examples of abstractions?

答:
Ok, I think I figured out what you're asking: "What is a mathematically rigorous definition of 'An Abstraction.'"

If that's the case, I think you're out of luck- 'abstraction' is a software architecture/design term, and has no mathematical backing to it as far as I'm aware (maybe someone better versed in theoretical CS will correct me here), any more than "coupling" or "information hiding" have mathematical definitions.

Title: What is abstraction?

ContentLicense: CC BY-SA 2.5


答:
Depends what you want to see. It's always nice to have at least the option of seeing all the results (as in, a complete list of all tests that have been run, and their status), and if you run the tests as a developer, you are probably also interested in error details for the failed ones. You do want a way to boil it all down to one single exit status though: either everything passes (which means global pass) or one or more tests do not pass (which means global failure). This is especially important if you want to hook your test suite into a Continuous Integration framework or similar automated checking mechanism.

So, long story short: If you can, make it configurable. Most off-the-shelf solutions have this option, and if you're rolling your own, it's not hard to do either.

Title: Standards of unit testing output

Body:
Simple question, what's more common /  standard / won't make future developers look at me cross-eyed for unit testing:

Displaying just the errors, or reporting every passed test?


问:
Hiding away complexity with sub functions
I am having a discussion on code style, and it's starting to sound like a "matter of taste". I strongly believe otherwise, so I'm writing this to get your opinion and learn from your arguments for and against.

The issue is that of hiding complexity by replacing a bunch of lines of code with a method. This discussion is unrelated to reusable functions, and I'm trying to make the argument for simple code organization, not for factoring out common functionality.

So, take this example in loose java:

```<code>public void purchase(Customer customer, Set<Item> items, Warehouse warehouse){
     int credit = customer.getCredit();
     int orderPrice;

     for(Item item: items){
         orderPrice+=items.getPrice();
     }

     if(orderPrice + customer.getPendingPayments() > customer.getCredit()) {
           warehouse.reserveStock(items);
           transportCenter.allocateTransport();
           customer.bill(items, orderPrice);
     }
}
</code>```

As opposed to this:

```<code>public boolean isCreditOk(Customer customer, Set<Item> items){
     int credit = customer.getCredit();
     int orderPrice;

     for(Item item: items){
         orderPrice+=items.getPrice();
     }
     return  orderPrice + customer.getPendingPayments() > customer.getCredit();
}

public void purchase(Customer customer, Set<Item> items, Warehouse warehouse){
     if(isCreditOk(customer, items)){
           warehouse.reserveStock(items);
           transportCenter.allocateTransport();
           customer.bill(items, orderPrice);
     }
}
</code>```

The whole discussion now is: would you have created the isCreditOk method or would you have left if inline? When do you do one or the other? does it depend, in a general case, on:

The length of the function to extract

How many sub-functions and sub-subfunctions isCreditOk will end up having

Again, this is not done because isCreditOk will be used often, but because it makes the code easier to read (in my opinion).

Can I have your comments? Thanks!

Note: I have found this question to be related: Is there such a thing as having too many private functions/methods?

答:
I'd modify the Customer class to have a getAvailableCredit() method.

Ideally, I'd like to see this as the "Working" line of code:

```<code>if (order.getTotal() <= customer.getAvailableCredit() ) order.Ship();
</code>```

In particular, I'd like to see a PurchaseOrder class that would encapsulate the the set of items, which would total itself, and add an relevant taxes, shipping charges etc.

I would also probably go so far as to separate the Credit functions out of the Customer class, by making a CreditAccount class which would be owned by a Customer.

Body:
I'd modify the Customer class to have a getAvailableCredit() method.

Ideally, I'd like to see this as the "Working" line of code:

if (order.getTotal() <= customer.getAvailableCredit() ) order.Ship();

In particular, I'd like to see a PurchaseOrder class that would encapsulate the the set of items, which would total itself, and add an relevant taxes, shipping charges etc.

I would also probably go so far as to separate the Credit functions out of the Customer class, by making a CreditAccount class which would be owned by a Customer.


问:
How do you avoid working on the wrong branch?
Being careful is usually enough to prevent problems, but sometimes I need to double check the branch I'm working on (e.g. "hmm... I'm in the dev branch, right?") by checking the source control path of a random file.

In looking for an easier way, I thought of naming the solution files accordingly  (e.g. MySolution_Dev.sln) but with different file names in each branch, I can't merge the solution files.

It's not that big of a deal but are there any methods or "small tricks" you use to quickly ensure you're in the correct branch?  I'm using Visual Studio 2010 with TFS 2008.

答: There's a free Visual Studio extension called TFS Solution Info that may help with this. It shows you the current branch and workspace in a little window that you can dock/pin wherever you want.</p>


答:
I always try to avoid copy-pasta from Internet, unless the code is exactly what's needed, is an industry standard/best practice, and is free of any licensing issues.

The copy pasta code usually is:

out of date

bloated

adds additional dependencies

has unknown bugs

It's better to understand the idea. Then write your own solution with code style that matches the project, doesn't add extra dependencies, is simpler, more modern, and better known.

Also, sometimes ideas can be encumbered with patents, so you should be aware of that as well.


答:
An abstraction is just the programming version of a theorem.

You have a formal system, you propose a thought about that system.  You do a proof of it, and if it works out, then you have a theorem.  Knowing that your theorem holds, you can then use it in further proofs about the system.  Primitives provided by the system (like if statements and int value types) would typically be seen as axioms, although that isn't strictly true since anything that isn't CPU instructions written in machine code is a kind of abstraction.

In functional programming, the idea of a program as a mathematical statement is very strong, and often the type system (in a strong, statically typed language like Haskell, F#, or OCAML) can be used for testing theoremhood through proofs.

For example: let us say that we have addition and equality checking as primitive operations, and integers and booleans as primitive data types.  These are our axioms.  So we can say that 1 + 3 == 2 + 2 is a theorem, then use the rules of addition and integers and equality to see if that's a true statement.

Now let us suppose we want multiplication, and our primitives (for brevity's sake) include a looping construct and a means to assign symbolic references.  We could suggest that

```<code>ref x (*) y := loop y times {x +}) 0
</code>```

I'm going to pretend I proved that, demonstrating that multiplication holds.  Now I can use multiplication to do more stuff with my system (the programming language).

I can also check my type system.  (*) has a type of int -> int -> int. It takes 2 ints and outputs an int.  Addition has a type of int -> int -> int so the 0 + (rest) holds as long as (rest) results in an int.  My loop could be doing all kinds of things, but I'm saying it outputs a chain of curried functions such that (x + (x + (x... + 0))) is the result.  The form of that addition chain is just (int -> (int -> (int ... -> int))) so I know my final output will be an int.  So my type system held up the results of my other proof!

Compound this sort of idea over many years, many programmers, and many lines of code, and you have modern programming languages: a hearty set of primitives and huge libraries of "proven" code abstractions.

Title: What is abstraction?

Body: Is there a generally agreed upon definition for what a programming abstraction is, as used by programmers? [Note, programming abstraction is not to be confused with dictionary definitions for the word "abstraction."] Is there an unambiguous, or even mathematical definition? What are some clear examples of abstractions?

Body:
An abstraction is just the programming version of a theorem.

You have a formal system, you propose a thought about that system.  You do a proof of it, and if it works out, then you have a theorem.  Knowing that your theorem holds, you can then use it in further proofs about the system.  Primitives provided by the system (like if statements and int value types) would typically be seen as axioms, although that isn't strictly true since anything that isn't CPU instructions written in machine code is a kind of abstraction.

In functional programming, the idea of a program as a mathematical statement is very strong, and often the type system (in a strong, statically typed language like Haskell, F#, or OCAML) can be used for testing theoremhood through proofs.

For example: let us say that we have addition and equality checking as primitive operations, and integers and booleans as primitive data types.  These are our axioms.  So we can say that 1 + 3 == 2 + 2 is a theorem, then use the rules of addition and integers and equality to see if that's a true statement.

Now let us suppose we want multiplication, and our primitives (for brevity's sake) include a looping construct and a means to assign symbolic references.  We could suggest that

ref x (*) y := loop y times {x +}) 0

I'm going to pretend I proved that, demonstrating that multiplication holds.  Now I can use multiplication to do more stuff with my system (the programming language).

I can also check my type system.  (*) has a type of int -> int -> int. It takes 2 ints and outputs an int.  Addition has a type of int -> int -> int so the 0 + (rest) holds as long as (rest) results in an int.  My loop could be doing all kinds of things, but I'm saying it outputs a chain of curried functions such that (x + (x + (x... + 0))) is the result.  The form of that addition chain is just (int -> (int -> (int ... -> int))) so I know my final output will be an int.  So my type system held up the results of my other proof!

Compound this sort of idea over many years, many programmers, and many lines of code, and you have modern programming languages: a hearty set of primitives and huge libraries of "proven" code abstractions.


答:
If you're using a unit testing framework:

Use defaults. They're usually good, succinct and convey exactly the information you need. Look at nose in Python (find command line examples!) or the Test tools in Visual Studio 2010. In my experience, they're quite good.

Less is more. Don't clutter results with lots of long-winded error messages or needless warnings. Again, see default results for tests in the previous frameworks to get a good idea of what looks good.

If you're building a unit testing framework:

Above all make things intuitive and easy to understand. You can get pretty far just presenting pass/fail/skipped results for each test can be extremely helpful. Again, less is more: gussied-up presentations usually won't help things out too much. Even simple colour text-coding can help immensely, as can basic print-outs to a command window.

Title: Standards of unit testing output


问:
Multiple Same Object Instantiation
What exactly happens in Java when you instantiate the same object multiple times?

For example:

```<code>Test test = new Test();
</code>```

then later on I will call it again, Test test = new Test(); again or inside a loop. Will the previous instantiation be disposed?

答: Short answer: all previously created objects will be disposed of if no one points to them. Only the most recent one will exist because test references it.</p>

Title: Multiple Same Object Instantiation


答:
I've been using VSCommands extension (with Visual Studio 2012, but there is a 2010 version) and it conveniently puts the branch name in the upper left corner of the screen as well as into the solution explorer.

Not affiliated with the product in any way, just a happy user.

Title: How do you avoid working on the wrong branch?

Body:
Being careful is usually enough to prevent problems, but sometimes I need to double check the branch I'm working on (e.g. "hmm... I'm in the dev branch, right?") by checking the source control path of a random file.

In looking for an easier way, I thought of naming the solution files accordingly  (e.g. MySolution_Dev.sln) but with different file names in each branch, I can't merge the solution files.

It's not that big of a deal but are there any methods or "small tricks" you use to quickly ensure you're in the correct branch?  I'm using Visual Studio 2010 with TFS 2008.


答: Lots of answers here already, but none that touches on the simple solution we have where I work: for each branch, create a new VM containing a dev environment, and check out from the proper branch.  You only have to do that and get it right once, and then you just switch VMs to switch branches.</p>


问:
Using UML and Use Cases in Game Design
In the Use case you need to make all the activities the user can do. And then in the Activity diagram I need to explain the Use cases, show the steps that it handles.

But if this is all correct, where do I need to show the enemies? Like: Generate path, walk, etc...
Because it isn't controlled by the player, the player has almost no influence on the enemy.

答:
Just from the couple examples you gave (in particular "generate path"), I think you are trying to define your use cases at too low of a level.  The enemy's actions in a use case might be attack, chase, search, stand but "generate path" is too low of a level.  Also, it is describing "how" and not "what" which is also a bad idea IMO.  If you do use-cases at that low of a level you'll never get done.

Back to the original question....how to show the enemies? You would normally identify the event that triggers the use-cases. It could be a timer, it could be the player comes within x-distance away. It is possible to declare the system or the timer or any other trigger as an actor if it makes sense. It's even valid to declare the enemy as an actor.  ie. The enemy detects the player and does....  You don't necessarily have to specify how the enemy detects the player (just that the event the occurs). You worry about the how in the implementation.

Title: Using UML and Use Cases in Game Design


问:
C++ is easy once you know PHP
I was at work last week and one of our "lead developers" (who said he has programmed C++ before, but I don't believe him) was talking about C++ and how our team of developers who only know PHP would not have a hard time at all learning C++.

My first reaction was pure shock and then I laughed at his comment. He gave me a bad look and i asked if he was serious. Me personally I program a lot of C and C++ for mostly school projects and coding competitions. I don't think it's at all like PHP. I asked him why they were the same and he could not give me an answer (he doesn't know C++ at all I was thinking). Then I said "OK, yeah they both use curly braces and have conditional statements. But C++ you have to worry about memory management and all the easy to use built in functions in PHP, for example the array functions, are non-existent in C++. You actually have to know the algorithms behind them.". There are some great C++ libraries (STL, Boost) that will make your life easier but C++ is like PHP, come on!

If you already know one language it will make it a little easier to learn another because you will already be good at boolean login (if this then that) or looping but there is just so much more to C++ than PHP. Like you have to compile the language and actually have to define what type of variable you are using and returning from functions.

What do you think?

EDIT: Actually what he said was "C++ is not much different than PHP"

答: Why is everyone always griping about memory management in php? Just because the language attempts to do garbage collection for you, doesn't mean that it's adequate, and you can forget about it. The memory you use in PHP does matter. And that's why you use functions like memory_get_usage(). Just because PHP is very forgiving and allows some awful practices to compile, doesn't mean that you should use awful practices in writing code. The biggest difference I see between php and C++ syntactically is that PHP has less brutally ugly syntax. If you compare PHP and C++ in the scenarios you would use PHP, they're very similar. You just need to remember to top load your libraries in C++, which I find annoying. C++ does appeal to my inner need to control every detail of execution, though. </p>

Title: C++ is easy once you know PHP


答:
You may want to check out some of Bob Martin's metrics

http://en.wikipedia.org/wiki/Software_package_metrics

That said, I don't think his "Abstractness" is the same as yours. His is more a measure of "lack of implementation on a class" meaning use of interfaces/abstract classes. Instability and Distance from Main Sequence probably play more into what you're looking for.

Title: What is abstraction?


问:
Application that provides unique keys to multiple threads
Thanks all for your help before.
So, this is what I came up with so far,

the requirements are, application has two or more threads and each thread requires a unique session/transaction ID. is the below considered thread safe?

thread 1 will register itself with get_id by sending it's pid
thread 2 will do the same

then thread 1 & 2 will call the function to get a unique ID

```<code>function get_id(bool choice/*register thread or get id*/, pid_t pid)
{

static int pid[15][1]={0};//not sure if this work, anyway considor any it's been set to 0 by any other way than this
static int total_threads = 0;
static int i = 0;
int x=0,y=0;

    if (choice) // thread registeration part
    {
        for(x=0;x<15;x++)
        {
            if (pid[x][0]==0);
            {
            pid[x][0] = (int) pid;
            pid[x][1] = (x & pidx[x][1]) << 24;//initiate counter for this PID by shifting x to the 25th bit, it could be any other bit, it's just to set a range.
            //so the range will be between 0x0000000 and 0x0ffffff, the second one              will be 0x1000000 and 0x1ffffff,
            break;
            }
        total_threads++;
        }
    }

//search if pid exist or not, if yes return transaction id
        for(x=0;x<15;x++)
        {
            if (pid[x][0]==pid);
            {
            pid[x][1]++;//put some test here to reset the number to 0 if it reaches 0x0ffffff
            return pid[x][1];
            break;
            }

        }

}
</code>```

答:
A few suggestions:

Threads vs. Processes

In your description, you mention threads and have a variable total_threads.  However, in the code you use a pid_t type and name a table pid.  Please be precise in your language.

This code may only run in one process, so I suspect you are mainly dealing with threads.

C Training

You may be unfamiliar with some of the conventions of C programming.

To provide the most help possible, we probably need to see the include files that you use, particularly the one that defines pid_t.  It is also helpful if we see the code that calls your function.

There is a variable pidx that is not defined and is used as pidx[x][1].  I expect this is a typo.

In your code, to access pid[x][0] and pid[x][1], you will need to declare static int pid[15][2].  static int pid[15][1] is an array fifteen arrays of one item each.

Review bitwise logical operators.  You have at least one statement that will probably not give you what you want.

The columns in your array are not homogeneous.  The first column seems to be compared against pid_t values and I suspect the second column might benefit from defining and using sessionID_t variables.  You could make this table an array of structs with two elements of types pid_t and sessionID_t.

pid is not very descriptive naming, and I think you mentioned thread IDs in your description.  Perhaps the table should be named threadID_to_sessionID_table.

You should read the description of the return statement.  You will find that you would never need a break; in the context where it is used above.

In the case where no pid is matched, what is returned?  You must return some value for any path through this function, perhaps zero if it is an invalid data value.

I suggest that you move the table and the variable total_threads outside the function and declare it static at the module level.  This would permit you to extend its use as you identify more functions that need that data.

One of your comments seems to indicate a problem that may be caused by using int rather than unsigned int.

As a point of C style, if you pick an array size of 15 and type 15 everywhere in your program, you are using a manifest constant.  There are two problems with this.  First, if you decide your array needs 16, you need to replace all the 15s associated with the use of the array with 16.  Second, (and this is much worse), if you find another 15 that is actually used for something else and make it 16, you can create a crash.  The solution to this problem is to create a defined constant with a statement like:

#define SESSION_ID_TABLE_MAX 15

Algorithm

This function appears to do two things.  Called get_id(true, my_pid) it allocates a session id and stores it in the table.  Called get_id(false, my_pid) it simply looks up the session id.  Using a flag or variable to steer one function to do the job of two separate functions is considered poor practice.  I suggest you make two functions allocate_session_id(pid) and find_session_id(pid).

I am concerned about the way you create session IDs from the pid.  If the pid is greater than eight bits and the int is 32 bits, you are in trouble.  Use of a signed 32-bit integer makes things even more hazardous.

There is nothing thread safe in about this code.  Each time you use a sequence with a comparison followed by a step that modifies the table, you need a critical region.  Otherwise, another thread in the system can stomp on it at will.

How is total_threads intended to be used?  I would suggest that the loop index in the first for loop could be total_threads.  If you get to the end of the loop without finding a match, then append your thread id and session id, and increment the thread id.

You should use some array range checks.  If the array is full, you need to skip over the attempt to allocate a new session id, and return something to indicate that the allocation failed.  This is one place where having separate functions will help.

If you have a transformation of the PID into the session ID, perhaps this could be encapsulated into its own function to permit ease of analysis, maintenance, and perhaps unit testing.

The method used to create session IDs seems unsound.


问:
How do you deal with the costs of too-rapid change?
Like most modern developers I value Agile principals like customer collaboration and responding to change, but what happens when a product-owner (or whoever determines requirements and priorities) changes requirements and priorities too often? Like several times a day?

I recently inherited a smallish code base that was buggy, incomplete, and couldn't even handle the simplest scenario it was supposed to. I can deal with the technical issues but I get several emails, texts, or phone calls a day saying "OMG you MUST work on this RIGHT NOW! TOP PRIORITY! This is a MUST!!!oneone" (that's only a slight exaggeration) What makes it even worse is that most of the things are minor details that aren't even relevant to what the software is actually supposed to do and would take days to implement anyway. I've tried explaining that there's only so much time and that we should focus on the most important things first, but something seems to get lost in translation because the same thing happens a day or two later.

Is there some sort of Product-Owner-Handler role, in-depth study, metaphor, or quote that can help me reduce the amount of wasted effort or at least explain the costs of this chaotic behavior?

答:
It looks like nobody mentioned it yet, Sprint and its user stories ideally should be locked till the next sprint (typical sprint takes 2-4 weeks). By locking - i mean no additional tasks should be added into already started Sprint.

If user story is big enough not to fit to the sprint then brake it down to smaller, achievable tasks during the sprint. Also, as mentioned even prioritized tasks need to be hold in backlog, and during the next sprint planning high-priority once get the flag up :)

Edit: only minor changes can be introduced during the spring. if they carry emergency state. However, if there is always couple emergencies during the sprint, then something needs to be changes in Sprint planning itself.


答:
Scrum has the Scrum Master role, which would be the person who should address the issues you mentioned.

If there is someone like a team lead, project manager, scrum master, etc. who is responsible, I would talk to that person.

I've tried explaining that there's only so much time and that we
  should focus on the most important things first, but something seems
  to get lost in translation because the same thing happens a day or two
  later.

I think that you will have to keep explaining that again and again and again. It sounds like you may need to accept that certain people you work with have unhelpful habits. If you are fortunate, you will see a change eventually.

Title: How do you deal with the costs of too-rapid change?

Body:
Like most modern developers I value Agile principals like customer collaboration and responding to change, but what happens when a product-owner (or whoever determines requirements and priorities) changes requirements and priorities too often? Like several times a day?

I recently inherited a smallish code base that was buggy, incomplete, and couldn't even handle the simplest scenario it was supposed to. I can deal with the technical issues but I get several emails, texts, or phone calls a day saying "OMG you MUST work on this RIGHT NOW! TOP PRIORITY! This is a MUST!!!oneone" (that's only a slight exaggeration) What makes it even worse is that most of the things are minor details that aren't even relevant to what the software is actually supposed to do and would take days to implement anyway. I've tried explaining that there's only so much time and that we should focus on the most important things first, but something seems to get lost in translation because the same thing happens a day or two later.

Is there some sort of Product-Owner-Handler role, in-depth study, metaphor, or quote that can help me reduce the amount of wasted effort or at least explain the costs of this chaotic behavior?


问:
Order of subject and modifiers in variable names
I'm looking for experiences regarding the ordering of the subject and modifiers in variable names.

A simple object Shape would have just a subject for the variable name, such as Area.

A slightly more complex case Sphere which has a wall will have an inner volume and an outer volume, which is where my question comes into play.

What's preferred between Modifier-Subject or Subject-Modifier?

As an example set:

```
class Containers_Modifier_Subject
{
  AreaAdjustmentFactor
  WallThickness
  Height
  Length
  Width
  AdjustedArea
  SurfaceAreaInner
  SurfaceAreaOuter
  LongWallArea
  ShortWallArea
  TopArea
  InnerVolume
  OuterVolume
}

class Containers_Subject_Modifier
{
  AreaAdjustmentFactor
  WallThickness
  Height
  Length
  Width
  AreaAdjusted
  AreaInnerSurface
  AreaOuterSurface
  AreaLongWall
  AreaShortWall
  AreaTop
  VolumeInner
  VolumeOuter
}
```

The trigger for my question comes from an object that is similar to the examples.  There were enough variables in the object that only a portion displays in the code ahead / lookup window from the IDE.  I want to make sure that any future developer is quickly led to the correct variable that they'll be looking for without having to scroll up and down through the lookup window.

In my case, I was looking for the total area, but the area factor and adjusted area values had popped up first.

Consistency in naming as a code standard is a given.

Which naming approach has been:

most maintainable?

more easily understood?

semantically correct?

i.e. how well does the variable name match the business object and how well does the variable name flow into conversations about the problem being solved?

conducive to being used with code lookup functionality like Intellisense or the various Eclipse based constructs?

答:
I prefer modifier-subject because that is how English is usually written and spoken.

If there is a clear specific benefit in a certain situation to make a name subject-modifier, I will.


问:
Should you use Fields or just Properties in C#?
I've seen some people who make properties for every single member, private or not... does this make any sense?

```<code>private string mWhatever;

private string Whatever
{
    get
    {
        return this.mWhatever;
    }
    set
    {
        this.mWhatever = value;
    }
}
</code>```

I could see it making sense in 1% of the cases at times when you want to control access to the member inside the class containing it.

Because if you don't use properties for every member it would lead to inconsistencies and checking to see if the member has an access or not (since you have access to both in the scope of the class).

答:
Short answer: Yes, when there is a need. Otherwise, use an Auto-Implemented Property getter and setter like private string Whatever { get; set;}

It is very handy When you are using a close domain approach

It is also handy when a specific logic should be checked when you are setting the value

Here is a full description of when you would be using private setters: C# property usage.

ContentLicense: CC BY-SA 4.0


答:
It's not absolutely necessary to do this for private properties, but it does allow for modifying how the property gets/sets the underlying value without changing how it is accessed.

For example, modifying how the underlying value is set:

```<code>private string Whatever
{
    get
    {
        return this.mWhatever;
    }
    set
    {
        this.mWhatever = string.IsNullOrEmpty(value) ? string.Empty : value;
    }
}
</code>```

Title: Should you use Fields or just Properties in C#?

Body:
I've seen some people who make properties for every single member, private or not... does this make any sense?

```<code>private string mWhatever;

private string Whatever
{
    get
    {
        return this.mWhatever;
    }
    set
    {
        this.mWhatever = value;
    }
}
</code>```

I could see it making sense in 1% of the cases at times when you want to control access to the member inside the class containing it.

Because if you don't use properties for every member it would lead to inconsistencies and checking to see if the member has an access or not (since you have access to both in the scope of the class).

Body:
It's not absolutely necessary to do this for private properties, but it does allow for modifying how the property gets/sets the underlying value without changing how it is accessed.

For example, modifying how the underlying value is set:

private string Whatever
{
    get
    {
        return this.mWhatever;
    }
    set
    {
        this.mWhatever = string.IsNullOrEmpty(value) ? string.Empty : value;
    }
}


答: If you don't use a property, your only other option is to use a field to store variable data. Properties and fields have significant differences. Most of these differences are found Fields vs. Properties. I suggest you study the differences then make your choice according to your application needs. However, bear in mind that using fields instead of properties is not the common OO practice because of their nature and shortcoming.</p>


答:
One of the biggest advantages of this approach is that you get control on when your variables change.

Consider the following.

You are debugging a large project. A certain method throws an exception. You set a breakpoint and you reveal that a certain member variable has wrong value. Say your code relies on this variable very extensively, and you find hundreds write usages (Spaghetti scenario). So you can't figure out which of these usages assigned a bad value.

If the code is multithreaded, debugging may become a real nightmare.

With property, you may set a breakpoint in a setter. Combined with a condition, it may be nailed down in a single run.

VC++ has data breakpoints, but it is only available for unmanaged code.


答:
I think variable naming should support thinking above anything else (be it a commonly known convention or a language syntax). This immediately makes one decision: the SubjectModifier version, because in this way the name expresses the organization of data: PlannedStart, PlannedEnd, PlannedCost; ActualStart, ...

I consider supporting IntelliSense not only good, but important! When looking at an unknown code, I don't care how many getters and setters they have made, but I want to understand what components (Subjects) are there in it, and only then what I can do with them (Modifiers). Feeding IntelliSense properly will surely save other programmers (and perhaps even yourself after a few months) some seconds every time you call a function or refer to a member variable. That quickly accumulates to hours.

... and perhaps something even more important: control. I like narrowing the scope by each letter I type. I prefer typing the subject and getting a list of things that I can do with that subject, to typing "access" and still have to browse among the Subjects... or even then realizing that it was not "access" but "get" for that Subject, because my target Subject is missing from the list. Aaargh...

IntelliSense is there to save you (and fellow programmers) time and let you avoid frustration. If you use it.

Container is another issue, and I agree that when you have a question about a container in your naming system, you really have a question about the class hierarchy. My example is just on the line, but right now I started hesitating whether to create a TaskInfo class with Start, End, Cost fields, and use InfoPlanned, InfoActual in the parent.

Creating such small classes result in a more flexible application. TaskInfo would let me create a TaskInfoPanel displaying Start, End, Cost properly - and I could reuse that panel twice to show Planned and Actual costs. It would also allow having even more TaskInfo instances to the project - like having more estimations made by different persons: offers from different service providers. In the end, this new structure would support a project planning system where you can separate task planning (internal) and execution (internal/contractor), let the contractor make their (perhaps multiple, parallel) offers to some tasks, from which you can choose and build the project planned timeline, make the contract, and so on.

A bunch of viable services just because I decided to extract a meaningful group of data into a separate class... I just played with the idea right now, but the consequence is evident, and when I will meet this scenario, I surely would use this approach.

So, I would strongly suggest you to separate your data into the smallest containers with strictly one responsibility. This allows broader reusability, more flexible structure, narrow interface; and I also think that it is much easier to understand. I think we can easier get the picture of a system having a hierarchy with precisely defined small components than some big, feature-oriented blocks.

My 2 cents.

Title: Order of subject and modifiers in variable names

Body:
I'm looking for experiences regarding the ordering of the subject and modifiers in variable names.

A simple object Shape would have just a subject for the variable name, such as Area.

A slightly more complex case Sphere which has a wall will have an inner volume and an outer volume, which is where my question comes into play.

What's preferred between Modifier-Subject or Subject-Modifier?

As an example set:

```
class Containers_Modifier_Subject
{
  AreaAdjustmentFactor
  WallThickness
  Height
  Length
  Width
  AdjustedArea
  SurfaceAreaInner
  SurfaceAreaOuter
  LongWallArea
  ShortWallArea
  TopArea
  InnerVolume
  OuterVolume
}

class Containers_Subject_Modifier
{
  AreaAdjustmentFactor
  WallThickness
  Height
  Length
  Width
  AreaAdjusted
  AreaInnerSurface
  AreaOuterSurface
  AreaLongWall
  AreaShortWall
  AreaTop
  VolumeInner
  VolumeOuter
}
```

The trigger for my question comes from an object that is similar to the examples.  There were enough variables in the object that only a portion displays in the code ahead / lookup window from the IDE.  I want to make sure that any future developer is quickly led to the correct variable that they'll be looking for without having to scroll up and down through the lookup window.

In my case, I was looking for the total area, but the area factor and adjusted area values had popped up first.

Consistency in naming as a code standard is a given.

Which naming approach has been:

most maintainable?

more easily understood?

semantically correct?

i.e. how well does the variable name match the business object and how well does the variable name flow into conversations about the problem being solved?

conducive to being used with code lookup functionality like Intellisense or the various Eclipse based constructs?


问:
What is the relevance of resumes in the age of GitHub, Stack Exchange, Coursera, Udacity, blogs, etc.?
My resume is no longer relevant. It can no longer contain an adequate description of my technical abilities. One can get a much better sense of what I am capable of by looking at my GitHub repositories, my Stack Exchange profiles, and the various courses that I am taking at Udacity and Coursera. The problem is that I have no idea how to tell employers that those are the places to look if they want an accurate description of what I can do.

Every time a recruiter contacts me I gently nudge them towards all the resources I just mentioned and I also provide a link to a publicly visible Google doc that contains my resume along with links to all those resources. Yet, they keep coming back asking for a more descriptive resume.

How can I make it even more blatantly obvious that if somebody wants to hire me then they can save themselves a whole bunch of trouble by just clicking on a few links and browsing around?

答:
Look at a resume as a distilled brochure that advertises highlights from your skills and experience. A combination of your github and SO profiles and a bunch of other online resources may be complete and accurate, but it isn't sorted or otherwise prepared for easy reading in any way. People who hire want you to tell them what you think distinguishes you from the rest, so your resume should be written so that you pass the first three seconds of eyeballing; if it doesn't, three seconds is all you get. Nobody can form any useful opinion about your skills in three seconds of looking at your github account page.

If you have too much to fit on your resume, great - pick the absolute highlights, and refer to online resources for more. Aim for 'impressive', not 'exhaustive'.


答:
I would argue that "in the age of GitHub, Stack Exchange, Coursera, Udacity, blogs, etc." the relevance of a concise and a well written resume is more important than ever.

As an employer, I am not going to start with your github projects and blog posts. I might end up checking them if:

your resume is relevant to my job requirements;

and your resume demonstrates a track record of achievements.

You do not even have to put links to all the aforementioned sites on your resume. I will google your name if I'm interested.

Title: What is the relevance of resumes in the age of GitHub, Stack Exchange, Coursera, Udacity, blogs, etc.?

Body:
My resume is no longer relevant. It can no longer contain an adequate description of my technical abilities. One can get a much better sense of what I am capable of by looking at my GitHub repositories, my Stack Exchange profiles, and the various courses that I am taking at Udacity and Coursera. The problem is that I have no idea how to tell employers that those are the places to look if they want an accurate description of what I can do.

Every time a recruiter contacts me I gently nudge them towards all the resources I just mentioned and I also provide a link to a publicly visible Google doc that contains my resume along with links to all those resources. Yet, they keep coming back asking for a more descriptive resume.

How can I make it even more blatantly obvious that if somebody wants to hire me then they can save themselves a whole bunch of trouble by just clicking on a few links and browsing around?


问:
I want to create a new language

Possible Duplicate:

How do I create my own programming language and a compiler for it

I want to create a new general purpose language that will compile to JavaScript and I'd like to be able to write it in that same JavaScript.

I wouldn't go much into detail about why, but how can I do it? Currently I have professionally coded in JS, Java, Groovy, PL/SQL, PHP among the rest, so I'm covered on the language user side of the story, but I have no theoretical or practical knowledge from the create language side.

I have browsed the web for the past week and noticed a soup of acronyms and/or names like RR, LALR, BNF, AST etc. so I figure I need two things:

Good Book(s) about theory

Working projects or experiments that I can use to jump start my learning (something free like that narcissus)

EDIT:

No, this question does not cover the EXACTLY SAME content and it is not on the same topic even worse, even though there are two good answers, they don't answer how I can practically USE JS TO BUILD THE TOOLS (JS TRANSPILER) I NEED FOR THE NEW LANGUAGE.

Any ideas?

答:
First, forget about LALR and the other intimidating words associated with the dragons. There is a nice and friendly one, behold: PEG. A ready to use implementation for JavaScript is available.

After you've done with the parsing you will have to transform your Abstract Syntax Tree in one or several steps into an AST of JavaScript and serialise it into text. There are many schools of thought in this area, but my personal preference is to use the very simple and obvious term rewriting model. You can draw your inspiration from things like this.

An unmodified pure JavaScript is not quite suitable for implementing compilers straight away, since it does not provide any decent pattern matching facilities, so I'd recommend to implement a eDSL layer as above first before starting to implement your language transforms.

Depending on what kind of type system your source language will have, you may want to implement various kinds of typing algorithms. For some of the practical strict type systems, an embedded Prolog might help a lot. E.g., implementing a Hindley-Milner algorithm in Prolog is trivial. Otherwise, a simple type propagation implemented with trivial term rewriting will be sufficient.

If you want to perform some optimisations, consider employing intermediate representations such as SSA or CPS. You may possibly need a decent graph handling library for it.

Title: I want to create a new language


答: It is told that Jeremy Ashkenas was inspired to create CoffeeScript after reading this very book. Since CoffeeScript is one of the most popular languages for javascript as target language, I guess you also can find some useful information there.</p>

Title: I want to create a new language

Body:
Possible Duplicate:

How do I create my own programming language and a compiler for it

I want to create a new general purpose language that will compile to JavaScript and I'd like to be able to write it in that same JavaScript.

I wouldn't go much into detail about why, but how can I do it? Currently I have professionally coded in JS, Java, Groovy, PL/SQL, PHP among the rest, so I'm covered on the language user side of the story, but I have no theoretical or practical knowledge from the create language side.

I have browsed the web for the past week and noticed a soup of acronyms and/or names like RR, LALR, BNF, AST etc. so I figure I need two things:

Good Book(s) about theory

Working projects or experiments that I can use to jump start my learning (something free like that narcissus)

EDIT:

No, this question does not cover the EXACTLY SAME content and it is not on the same topic even worse, even though there are two good answers, they don't answer how I can practically USE JS TO BUILD THE TOOLS (JS TRANSPILER) I NEED FOR THE NEW LANGUAGE.

Any ideas?


答:
It is a great idea, however keep in mind the following:

Try not to commit on the server (although some rare times it makes sense to do this, e.g. installing a plugin or adding content assets)

Use a staging server or a secondary repository deployment for testing

Be always careful that hg update -C doesn't affect production (i.e. delete important files)

Have a production and a development branch, only deploy the production branch

Treat assets as backup (e.g. images for content,) and ignore user data (e.g. attachments/uploads, cache, etc)

Always have a clean hg status output on the server (this will help you make sure you are ignoring things as cache)

Don't deploy the repository in the web folder. Use symlinks from outside the public space (e.g. ln -s /myrepo/src/web /public_html/myapp)

Be careful not to version configuration files (specially with database passwords or other)

Don't use instead of a production backup, this is a development backup for production code, not production data

Finally, I think the most valuable thing for adding a DVCS to your deployment process is that this will add security to your deployment, sometimes hackers inject malicious code to your stuff and you really have no means of detecting it easily without something like version control (specially distributed, since the distributed aspect to VCS makes it easier to check for integrity of your files).

I've had some sites gotten hacked a few times, having Mercurial helps me litterally undo this hacks by just issuing an hg update -C in the server (of course you might want to do an hg status and get the affected files for later analysis).

Title: Is it a good idea to install Mercurial on your server and hg pull to deploy?

Body:
I've just started at a new job this past month and looks like they have NO source control for their code. They are relying on the backups their hosting provider takes for them.

After talking a bit I convinced my boss that we should definitely be using source control and after I gave a short seminar on it, the entire team is on board; they loved Mercurial.

So right now this is the way we work:

```<code>º----------BitBucket
º---------/
º--------/
</code>```

Myself and the three other developers hg pull from BitBucket, make our changes, then hg push to BitBucket.

Now for deployment, someone would need to FTP the latest files towards the production server.

I was thinking of installing Mercurial on our server, and using hg clone (subsequently hg pull) to keep the versions up to date on production.

```<code>º---push->-----BitBucket----<-pull-----º (production server)
º---push->----/
º---push->---/
</code>```

Is this a good idea? Any potential pitfalls I may not be seeing? Has anybody here done something similar? How do you deploy a large PHP framework application (We're using Moodle)?


答:
Some good answers here already, but I think most of them miss one point of your question:

I've seen some people who make properties for every single member, private or not... does
  this make any sense?

I think this is seldom necessary beforehand, for every single member. Start with

```<code> private string Whatever;
</code>```

When you later come to a point where you need encapsulation or a conditional breakpoint for this specific member, you can still replace it by a property with same name - in most cases without changing the code which uses Whatever. But beware, there are subtle differences, see Brian Rasmussen's answer in this SO post  (link also given by Emmad Kareem, +1).

Body:
Some good answers here already, but I think most of them miss one point of your question:

I've seen some people who make properties for every single member, private or not... does
  this make any sense?

I think this is seldom necessary beforehand, for every single member. Start with

 private string Whatever;

When you later come to a point where you need encapsulation or a conditional breakpoint for this specific member, you can still replace it by a property with same name - in most cases without changing the code which uses Whatever. But beware, there are subtle differences, see Brian Rasmussen's answer in this SO post  (link also given by Emmad Kareem, +1).


问:
Recurring Problem - need instruction to run only once inside code which executes multiple times
I come across this problem usually (especially when dealing with certain frameworks) where I would like once piece of code to execute once and only once however the provided method e.g (something like an onComplete function) that I wish to place this instruction in will in reality execute multiple times.

I am just wondering does anybody know of the best way that would get around this problem, one programmer friend of mine told me to use a flag (boolean) to check whether or not this code has already run but I feel like this is not a suitable solution and I would not like to introduce global variables for the sake of checking a condition once and only once.

Has anybody ever come across a problem like this before, I am wondering is there any good practice out there to keep in mind when dealing with code like this.

答:
A boolean flag indicating the method ran would be the right solution.

Not sure why you think this needs to be a global variable though - it can be declared outside the loop before it starts running.

If you do need to ensure that the method only ever runs once during the lifetime of the program run, there are several different ways to do this, depending on the language, but they do all essentially boil down to a global boolean (though in some languages that can be encapsulated).

For example in C#:

You can have the method live in a static class with a private static boolean - this would only be visible to the class itself and you can set it once the method executes the first time. Next time through, since the flag is set, you don't execute the body of the method. Statics are global state, but as a private member, the flag is not visible to other classes.


问:
A place for putting code samples in projects
Every now and then I get or write some minimal code samples to achieve tasks. What's the usual practice for storing these samples (which could prove useful later on) ? Have a separate source folder or create a separate project ?</p>

答: I always use a separate project called scratchpad and I follow the same principles I do with the rest of my code (they have unit and/or integration tests etc).</p>


问:
Not specifying a return in a function, good or bad?
I have coded like this many times, and I've never encountered an issue, but the compiler always warns when it expects a return and there is none.

For instance, look at this:

```<code>-(NSString *)outputStringForInteger:(NSInteger)int
{
    if (int == 0)
    {
        return @"Number is Zero";
    }
    else
    {
        return @"Number is not Zero";
    }
    //no "failsafe" or other explicit return
}
</code>```

If the function will never get to the last line, ever, is it important to still have a failsafe option, or do you guys just deal with compiler warnings?

答: Get a better compiler.  The ones I use complain that you have code which will never execute if you put the "failsafe" return in there.  That's a much better warning that the false one you're apparently seeing.</p>


问:
How far should 'var' and null coalescing operator '??' be entertained without hampering readability?
I know the title of the question is very subjective, but I was confronted with usage of ?? operator by my peers, where at the same time I was not very happy/comfortable with applying var in new up-coming code.

The argument given for using ?? operator was, it takes away readability in code.

My question is, doesn't the same thing happens when you start using var?

答:
I have a fundamental issue with using var.

In this example everything is side-by-side, but the issue is really with large solutions with shared libraries or projects.

Consider this:

```<code>public MyFirstObject GetMeAnObject() {
    return new MyFirstObject();
}

public void MainProgram() {
    var theObject = GetMeAnObject();
    theObject.PerformOperation();
}
</code>```

What happens if GetMeAnObject is changed, by someone else, to suit their needs?

```<code>public MySecondObject GetMeAnObject() {
    return new MySecondObject();
}
</code>```

The MainProgram method will have a big red error on .PerformOperation(). What happened? PerformOperation worked perfectly well before. We look at the methods on theObject and it's just disappeared without a trace. It was there last time, and we need that method. You could spend a long time chasing your tail and trying to figure out why, if MyFirstObject has a method called PerformOperation, it now can't be seen. Everybody "knows" that GetMeAnObject returns a MyFirstObject, so there's no point checking that.

If you had explicitly typed theObject then you would have an Invalid Cast error on the line that calls GetMeAnObject, and it would be blindingly obvious that GetMeAnObject is returning a type that is not what you expect.

In short, explicit declaration means you know what the errors mean. An invalid cast means you expected one type and another type was returned. An unrecognised member means the member was unrecognised.

Body:
I have a fundamental issue with using var.

In this example everything is side-by-side, but the issue is really with large solutions with shared libraries or projects.

Consider this:

public MyFirstObject GetMeAnObject() {
    return new MyFirstObject();
}

public void MainProgram() {
    var theObject = GetMeAnObject();
    theObject.PerformOperation();
}

What happens if GetMeAnObject is changed, by someone else, to suit their needs?

public MySecondObject GetMeAnObject() {
    return new MySecondObject();
}

The MainProgram method will have a big red error on .PerformOperation(). What happened? PerformOperation worked perfectly well before. We look at the methods on theObject and it's just disappeared without a trace. It was there last time, and we need that method. You could spend a long time chasing your tail and trying to figure out why, if MyFirstObject has a method called PerformOperation, it now can't be seen. Everybody "knows" that GetMeAnObject returns a MyFirstObject, so there's no point checking that.

If you had explicitly typed theObject then you would have an Invalid Cast error on the line that calls GetMeAnObject, and it would be blindingly obvious that GetMeAnObject is returning a type that is not what you expect.

In short, explicit declaration means you know what the errors mean. An invalid cast means you expected one type and another type was returned. An unrecognised member means the member was unrecognised.


问:
Sporadic unittests or TDD?
I've read some basics about unit tests and TDD, but I find it hard to convince myself why TDD can have an advantage over only selected unittests.

I've read common arguments for TDD, but don't see the improvment compared to simple unittests. Maybe you can help to clarify:

TDD allows a loosely coupled, testable design -> I believe I can well imagine if a class is theoretically testable, without having to write tests; Loose coupling is a fundamental requirement that one can judge without refering to TDD?!

TDD gives confidence in refactoring -> Isn't it more efficient to add selected unittests as soon as you start refactoring? While you have to think what to cover by test, you still save writing a lot of tests.

TDD makes you define the interface first -> To me it seems some minor points are easier to decide while coding (which also agrees with agile?). It's even hard to predict a nested return data structure, but after coding I can often validate that I get what I expected. I made up the nested data while coding (a small unit) and see the behaviour. I'd save a lot of time writing the method first and using the validated result a posteriori to plug into a unittest.

from what I've read many (of course not all) sources state that TDD does require more development time even considering the benefit for debugging; merely the code quality improves -> Can it be that some programmers make different kinds of mistakes and for some TDD doesn't cover the type of mistakes they make anyway? So if my typical bugs are not approachable by predictable tests, it's not for me?

TDD aids changing teams, and larger interacting teams -> Is this a large issue? I can imagine it is, however as for the moment I program alone I cannot judge. How does TDD help teams in ways that... and here is the important point: other ways don't? It can force some discipline for less experienced team members, but apart from that any advantages?

答:
I often write unit tests but I think that, as any tool, they are not the solution for all problems and one should evaluate from case to case whether they are appropriate or not. Using them systematically for every piece of code I write does not seem the most effective solution to me.

Here are some situations in which unit tests have proved to be very useful for me:

Validating methods that perform complex data transformations: unit testing with a lot of possible inputs and outputs allowed me to discover even small bugs very early.

Refactoring: unit tests help to ensure that the refactored code has the same functionality as the original code. Newly introduced bugs show up very soon.

On the other hand, I have some doubts regarding TDD and whether this approach is always the best. Here are some points of criticism:

Not all the code can profit from unit tests, e.g. suppose that you want to check that a certain event is dispatched to the correct component in your GUI. The most effective thing to do is to run the program and, say, check that the appropriate button is enabled. The effort needed to unit test the underlying logic would be too high compared to the manual tests that (at least if you have a decent development process) you are going to carry out anyway.

I sometimes develop interrelated classes as clusters and I am not sure which classes and methods I really need until the whole cluster of classes is finished. Such a cycle can last a few days. During such a cycle I can introduce new classes and then, on a second thought, realize that I do not need them and remove them. If I had written unit tests for these classes, I would have had to throw away the unit tests as well. So I find it much more efficient to (1) write unit tests for selected, critical classes and (2) start writing the unit tests towards the end of a development cycle (of a few days) when the class structure has stabilized enough, so that I do not waste my time writing unit tests that I am going to throw away later.

Title: Sporadic unittests or TDD?


答:
these notes might be useful:

You can create an idempotent function, which means that no matter how many times you call that method, you still get the same result.

Using an if statement to check an external condition, and run the code only if that condition is not met. (Maybe another implementation of idempotency)

As you said, inject this dependency into your method. Your method is dependent upon an external state to tell it how many times it's been executed. Thus if another manager (container) manage this for your method, things get easier.

Title: Recurring Problem - need instruction to run only once inside code which executes multiple times

Body:
I come across this problem usually (especially when dealing with certain frameworks) where I would like once piece of code to execute once and only once however the provided method e.g (something like an onComplete function) that I wish to place this instruction in will in reality execute multiple times.

I am just wondering does anybody know of the best way that would get around this problem, one programmer friend of mine told me to use a flag (boolean) to check whether or not this code has already run but I feel like this is not a suitable solution and I would not like to introduce global variables for the sake of checking a condition once and only once.

Has anybody ever come across a problem like this before, I am wondering is there any good practice out there to keep in mind when dealing with code like this.


答:
Yeah

I personally use this as the caching mechanism, and we might call it property-level caching.

```<code>private List<User> users;
private List<User> Users
{
    get
    {
        if(users == null) users = new UserManager().GetUsers();
        return users;
    }
}
</code>```

Now in other places inside my class, I use Users property instead of users field.

Another feasible situation might be when you want to implement some logic on a field, but in a centralized way in a class. Thus you can both create a GetFoo() method, or a Foo property for foo field.

```<code>private string foo;
private string Foo
{
    get
    {
        return "Mr. " + foo;
    }
}
</code>```

Body:
Yeah

I personally use this as the caching mechanism, and we might call it property-level caching.

private List<User> users;
private List<User> Users
{
    get
    {
        if(users == null) users = new UserManager().GetUsers();
        return users;
    }
}

Now in other places inside my class, I use Users property instead of users field.

Another feasible situation might be when you want to implement some logic on a field, but in a centralized way in a class. Thus you can both create a GetFoo() method, or a Foo property for foo field.

private string foo;
private string Foo
{
    get
    {
        return "Mr. " + foo;
    }
}


答:
Something else to consider:

Actual properties are an implementation detail.  One of the goals of OOP is to try and minimize the exposure of implementation details where practical.

The reason for this is if you hide the properties and only expose them through getters and setters, you have far more control.  For example, your getter can validate its input and prevent the property being set to an invalid state.  If the ability to change the value is time critical, then the setter can protect against this too.  The getter, should getting the actual value be expensive for whatever reason, can do lazy initialization and/or caching.

Having getters and setters exposed and the properties hidden means sometimes you don't need a property at all.  Your getter can compute the value on invocation, or delegate the task somewhere else, or anything that lets it meet its specification.  What's important about your class is the information you can access from it, not how that information is represented internally.

Of course, if there's no negative consequences to anything outside the class being able to access a property directly, then you should just make it public.  However in my experience, such cases are relatively few and far between.


答:
Most HR screening these days done by recruiters and corporate HR departments is automated resume reading. A human never sees your resume/application. A computer program that searches out keywords in a plain text, HTML or Word document determines if your resume matches the specified job criteria.

If it's a match, a HR person, who knows nothing about GitHub or StackExchange, looks at your resume and double checks the computer results. They may call you on the phone to make sure that you aren't a total loser or liar. Then, they'll submit your resume to the department or client along with a stack of other qualifying resumes. (Smaller companies who don't use a recruiter usually start at this point.)

Then, the hiring manager will begin to sort through a stack of resumes, scanning them for certain keywords/buzzwords and making some subjective judgments. For example, you may have graduated from the same school so you end up on the callback pile. They then ask the recruiter or HR to setup a face-to-face or phone interview for those selected.

In the interview, that's the time you can bring up things that you do online. They'll probably Google on you and check out what you've given them after that if they like you in person. However, this can work against you in some organizations. They may think you're too dedicated to outside projects, like a blog or open source projects. They may see a Facebook entry where you're out partying or being openly religious and be offended by it. They may not like your code style or be intimidated by it. Then again, some hiring managers won't even bother to do even a Google search and base their decision on the interview alone.

So, a resume still remains as an advertising brochure for you because it's easily automated and quick to read/scan. Online qualifications are generally something that can be a deal winner or breaker after an initial interview with a hiring manager.


问:
What is abstraction?
Is there a generally agreed upon definition for what a programming abstraction is, as used by programmers? [Note, programming abstraction is not to be confused with dictionary definitions for the word "abstraction."] Is there an unambiguous, or even mathematical definition? What are some clear examples of abstractions?

答:
The answer to "Can you define what a programming abstraction is more or less mathematically?" is "no." Abstraction is not a mathematical concept. It would be like asking someone to explain the color of a lemon mathematically.

If you want a good definition though: abstraction is the process of moving from a specific idea to a more general one. For example, take a look at your mouse. Is it wireless? What kind of sensor does it have? How many buttons? Is it ergonomic? How big is it? The answers to all of these questions can precisely describe your mouse, but regardless of what the answers are, it's still a mouse, because it's a pointing device with buttons. That's all it takes to be a mouse. "Silver Logitech MX518" is a concrete, specific item, and "mouse" is an abstraction of that. An important thing to think about is that there's no such concrete object as a "mouse", it's just an idea. The mouse on your desk is always something more specific - it's an Apple Magic Mouse or a Dell Optical Mouse or a Microsoft IntelliMouse - "mouse" is just an abstract concept.

Abstraction can be layered and as fine- or coarse-grained as you like (an MX518 is a mouse, which is a pointing object, which is a computer peripheral, which is an object powered by electricity), can go as far as you want, and in virtually any direction you want (my mouse has a wire, meaning I could categorize it as an objects with a wire. It's also flat on the bottom, so I could categorize it as a kind of objects that won't roll when placed upright on an inclined plane).

Object oriented programming is built on the concept of abstractions and families or groups of them. Good OOP means choosing good abstractions at the appropriate level of detail that make sense in the domain of your program and don't "leak". The former means that classifying a mouse as an object that won't roll on an inclined plane doesn't make sense for an application that inventories computer equipment, but it might make sense for a physics simulator. The latter means that you should try to avoid "boxing yourself in" to a hierarchy that doesn't make sense for some kind of objects. For example, in my hierarchy above, are we sure that all computer peripherals are powered by electricity? What about a stylus? If we want to group a stylus into the "peripheral" category, we'd have a problem, because it doesn't use electricity, and we defined computer peripherals as objects that use electricity. The circle-ellipse problem is the best known example of this conundrum.

Title: What is abstraction?


答:
Agile Manifesto says that one of the most fundamental principals is:

Welcome changing requirements, even late in
  development. Agile processes harness change for
  the customer's competitive advantage.

However, I don't believe that they meant change on a daily basis. You might need to change the base price of a product many times a day, but not changing how that product might be sold many times a day. Rather the workflow of sales of a product might change on a week basis (in  highly responsive and dynamic businesses).

Again, while workflow of sales of a product might change each week, I think the overall product won't be changed each week. I can't imagine a Microsoft which today gives us Office, but tomorrow will give us Offooose, and a week later Offasooooooooooos.

Nope, that's not what agile means by change. I do believe that it comes from poor visions, and a big deep misunderstanding of the concept of change.

Let alone mentioning that change is not welcomed in a sprint, where developers go to their caves and do need to concentrate on what their doing. Rather, changes should be added to Product Backlog, and be analyzed and prioritized before they get delivered to the hands of the scrum team. In other words, a Sprint Backlog is not immutable. More agility should be sought using shorter sprints, not by injecting changed directly into developer rooms, many times a day.


问:
Validating best practices, property vs dto, simple type vs object
Consider an application where adds an email address to his profile and submits it.

We have some dispute in our team over how to validate this email address. Some developers (including me) believe that we should validate this simple string via an extension method:

```<code>bool isValid = newEmail.IsEmail();
</code>```

They argue that any validation mechanism other than a single method call would be overhead, and an anti-pattern (against KISS principal).

While others argue that this email should first be added to a new instance of UserEmail DTO, then that DTO should be passed to a the relevant validator:

```<code>UserEmail userEmail = new UserEmail() { Email = newEmail };
bool isValid = new UserEmailValidator().Validate(userEmail);
</code>```

The second group argues that validating a single property makes no sense, because a property can't exist on its own. Thus we should always validate an object, not a property (I mean, value type properties, like strings and integers, etc.)

What advantages and disadvantages could each approach have?

答:
Assuming that you have at least 2 tiers:

They argue that any validation mechanism other than a single method call would be overhead, and an anti-pattern (against KISS principal).

Not always true. You may need to perform validation on the client as soon as wrong data is entered without logic and data travel to the next tier. In this case, you need to validate email syntax on the client and do that again on the server (may be with further business rule such as uniqueness check).

While others argue that this email should first be added to a new instance of UserEmail DTO, then that DTO should be passed to a the relevant validator:

Say the form has 10 fields that could be in error, the user enters the email as "abc" and tabs to the next field, now do you want to alert the user? If you want to do so you have to pass the entire client object and validate it. the validator will return 10 errors back which may confuse the user since all he/she did is to tab away, no action button was pressed. Add to that the overhead of moving data across tiers and you will see that this is not quite valid.

The second group argues that validating a single property makes no sense, because a property can't exist on its own.

This is sometimes true, however not always true. In the case of email value of "abc" or in the case of skipping a mandatory fields, you can tell that an error exists regardless of the other data entered on the form.

In summary, you must decide on the user experience style and adhere to it in all pages/forms of your application. Take in consideration that validation costs trips between tiers and may cause delay. Also, too much validation + delay in a large form is a bad thing. In all cases never relay on one tier's validation result alone. You must do all necessary checks before committing the data to the database. Because of this, design your validation logic to be re-usable across tiers as much as possible.


答: In C, I used to use function pointers for this.  The first time the function was called, the initialization function was called.  At the end of the initialization function, it changed the function pointer to point at the code that was to be called the rest of the time.  There are various ways to do this in other languages, with various levels of efficiency.</p>


问:
Asking back technical questions during the interview (as the interviewee)
I would like to know if people have already asked back some technical questions to your interviewer. Saying something like "Well, you asked me a bunch of technical questions, and now, do you mind if I ask you some? If I am going to join your company, we will work closely together and I want to make sure my I respect the skills of my coworkers like they respect mine...".

Doesn't it sound arrogant? I am curious to have your opinion or experience (as the interviewee or the interviewer, of course).

P.S: throwaway account as I dont want that people who know me know I am preparing interviews.

答:
Bear in mind that your interviewer may not be a technical person - and if they are a team manager, they may not even touch code on a day-to-day basis.

Assuming you were talking to a technical person however, I wouldn't start questioning them, just question any ambiguity in the technical questions they may direct at you, which both shows that you may have a deeper understanding than they were looking for and their response will give you an indicator as to approximately their skill level.


答: If technical questions translates into "asking questions about specific ways you do things and stuff you use" then I'd be worried if a candidate did not ask that. I want people who care about using the good stuff and software craftsmanship on my team. YMMV.</p>

Title: Asking back technical questions during the interview (as the interviewee)

Body:
I would like to know if people have already asked back some technical questions to your interviewer. Saying something like "Well, you asked me a bunch of technical questions, and now, do you mind if I ask you some? If I am going to join your company, we will work closely together and I want to make sure my I respect the skills of my coworkers like they respect mine...".

Doesn't it sound arrogant? I am curious to have your opinion or experience (as the interviewee or the interviewer, of course).

P.S: throwaway account as I dont want that people who know me know I am preparing interviews.


答: As an interviewee, the questions I was asked, the way they were asked and the reactions to my answer or requests for clarification have been enough for me to get a idea about the technical level of my interlocutors, and what aspects they considered as important. My questions to technical interviewers were more about the working environment and management style.</p>


问:
How to split large, tightly coupled classes?
I have some huge classes of more than 2k lines of code (and growing) that I would like to refactor if possible, to have some more light and clean design.

The reason it is so big is mainly because these classes handle a set of maps that most methods need to access, and methods are very connected to each other.

I will give a very concrete example: I have a class called Server that handles incoming messages.
It has methods like joinChatroom, searchUsers, sendPrivateMessage, etc.
All of these methods manipulate the maps such as users, chatrooms, servers, ...

Maybe it would be nice if I could have a class handling messages concerning Chatrooms, another handling all about Users, etc.
but the main problem here is that I need to use all of the maps in most of the methods.
That's why for now they are all sticked in the Server class as they all rely on these common maps and the methods are very connected to each other.

I would need to create a class Chatrooms, but with a reference to each of the other objects.
A class users again with a reference to all the other objects,
etc.

I feel like I would be doing something wrong.

答: The need to access the maps doesn't justify the mega-class. You have to separate logic in several classes, and each class must have a getMap method so other classes can access the maps.</p>

OwnerDisplayName: Matthew


问:
How to properly design classes for a big project?
If we need to represent classes in a class diagram for a big project that is not completely designed yet, and the classes have to be actual tables in a database, how would we predict and design the classes?

Let's say we have a project that is going to have more than 15 tables, do all these tables need to be classes in the class diagram?

How would classes be designed in this kind of situation? The language that is being used is Java and the class diagram has to prepared in UML. I know how to design them, I just don't know if the tables should represent the classes in this case.

答:
Tables not necessarily drive class design.

For example not all programs connect to a DB. Should tables drive class design, such a program should have no classes at all.


答:
"Well, you asked me a bunch of technical questions, and now, do you mind if I ask you some? If I am going to join your company, we will work closely together and I want to make sure my I respect the skills of my coworkers like they respect mine...".

Doesn't it sound arrogant?

Yes, it does. But there are other ways to get that information.

Ask to look at the codebase. Say something like "I'd like to see the best and the worst part you can think of."

Engage them in conversation, use lots of terms that lesser developers wouldn't understand.

Mention bloggers and authors, see if you get a blank expression.

Ask them about the technology stack and ask for reasons behind various decisions, compare the frameworks they use with the ones you've used.

Sometimes you can impress as much by the type of questions you ask as the type of questions you answer. I once had a junior developer come in with an A4 sheet full of questions. They were the right questions to ask. They showed a deep (for a junior) knowledge of the right and wrong ways to do things. He was offered the job.

I wouldn't ask someone to code up a method to display the Fibonacci sequence. But then I also wouldn't ask that as an interviewer. It's a waste of time and teaches me nothing about the person.