问:
Apache 2 License and copyrighted Libraries
I am working on my first big(ger than before) project at my university which is coded under the Apache 2 License.

So here is the question:
Can I use copyrighted material/libraries (no restrictions and free to use) inside that project?
I want to be specific: The library is flot (flotcharts.org)

My guess is yes, but guesses do not count.

答:
The Apache 2 license clearly indicates:

[Section] 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.

*emphasis is mine

As someone with a law degree as well as extensive development experience and intellectual property knowledge, I can tell you that this clearly indicates you are welcome to make anything you want from anything licensed under this agreement and derivatives of any kind. The only caveat is that you MUST include the boilerplate license for Apache 2 in your code/releases/or whatever. You can get that from the link provided.


问:
Is it possible to compile a higher level language to readable C++?
C++ is a great language in many ways, but some things in particular are cumbersome to write without an IDE. As a VIM user, it would be very interesting if I had access to a higher level language which enabled me to write C++ with S-Expressions and possibly with Lisp-like macros, allowing for the generation of clean code while avoiding rewriting the same patters over and over again.

I've asked on freenode and tested several ideas, such as compiling Lisp->C with compilers such as ECL and Bigloo, but none of those generated particularly clean C code.

Are there any works on this issue?

答:
ViM is a great IDE for C++. It has the best completion I've ever seen so far too, though it gets a little slow if you pull in a lot of headers, the clang complete. And for compilation I found all IDEs lacking anyway; you end up writing build system in CMake or something anyway. And I have not seen anything to provide any help for lisp, period.

True, C++ does not have lisp-style macros, but templates can do everything scheme's hygienic macros can and some more, because you can implement them differently based on types and based on their capabilities. True, it's lack of garbage collector makes closures a bit more tedious, but the RAII idiom used for resource management instead has it's own advantages and interesting properties.

If you are a student, do you really know all the advanced C++? From algorithms library over writing templates with alternate implementations based on properties of argument types, compile time calculations using template meta-programming (using Boost.MPL) to understanding how Boost works under the hood? If not, I recommend taking this as opportunity to learn some advanced C++. School assignment won't need to be maintained, so you can play with the language to see what the features are worth where in production code you'd have to be careful about readability.

And to answer the final direct question: C++ has so many more idioms under it's belt that there is no way to generate idiomatic C++ from anything. Simply because there will be no way to express most of those idioms in anything else. Starting from the fact that anything will garbage collection will allocate everything on heap while in C++ it is idiomatic to take advantage of the stack.

ContentLicense: CC BY-SA 3.0


问:
Which layer does async code belong?
I am developing an application that consumes data from an external service.  The application is being implemented following a typical layered architecture with UI, Presentation, Domain and Data layers.  The service client resides within the Data layer.

As is typically the case, I do not want the UI to 'lock-up' while waiting for calls from the external service to complete.  However, implementing the service agents with asynchronous methods results in a complicate model chaining async methods up the layers so the UI can stay responsive.

For example:

In the ViewModel:

```<code>TheRepository.LoadDataAsync().ContinueWith(t => { _data = t.Result; });
</code>```

In TheRepository:

```<code>public Task<TheData> LoadDataAsync()
{
    return ServiceClient.GetDataFromServiceAsync();
}
</code>```

(Note, this is a significant over-simplification meant to convey what I mean by task chaining.)

Because the requirement is a UI requirement (prevent the UI from 'locking'), doesn't it make sense to keep the Domain and Data layers synchronous and leave it up to the Presentation layer to decide when it needs to perform some operation asynchronously?

On the other hand, it is so easy and natural to implement the service client/proxy with async methods (VS will auto-generate them if needed) because this is what we think of when we think about the need for async.

If the application was pulling data out of a database instead of making a service call, the layers wouldn't be any different and it shouldn't really change how the UI, Presentation or Domain layers have been implemented, right?  In this case, we wouldn't think twice about having the data access be synchronous.

Would it be a better design to model the Domain synchronously and leave it to the Presentation layer to address performance issues in the UI?  Or, in the emerging async world, should we just accept async as the norm and make everything fit this model?

答:
Whether a component does work synchronously or asynchronously is an implementation detail. Your design choice for each layer should be independent.

You stated a use case for the UI layer being asynchronous, it needs to not lock up so it should be asynchronous. For each other layer if they have a use case for being asynchronous then make them asynchronous otherwise make them synchronous. As you describe it currently I don't see any advantage in having your repository asynchronous.

Title: Which layer does async code belong?


问:
How to evaluate moving to Team Foundation Server
My development team presently uses the following software in our workflow:

JIRA

Bamboo (Atlassian continuous integration)

Greenhopper (Atlassian agile project management)

Confluence

Git, hosted on BitBucket

Visual Studio 2012

As you can see we are quite heavily invested in the Atlassian ecosystem. We are considering a move to TFS so we can get the niceties of advanced Visual Studio integrations such as code reviews and more importantly the Microsoft Test Manager.

My previous experience with TFS was with 2005 or 2008 (I can't remember) and I have bad memories of it, although not quite as bad as my time with ClearCase.

What criteria should we be looking at in order to properly evaluate our move to TFS?

答:
Peoples should know, TFS is not just VCS, it is ALM.

Seem many peoples just want a VCS but go for TFS is wrong way.

For CVCS, I still prefer SVN.

For solo or open source, sure go for GIT.

But TFS2012 is not bad, it is easy understand on merge/fork then SVN.

And team foundation service is free for 5 user / unlimited,private repo.

Client is free too, TFS explorer build on top of VS2010 and it is free.

For Eclipse, it has Eclipse plugin - TFS everywhere.

I don't see any cost problem on that.

TFS express (free) can be work with SQL Server Express (free too).


问:
Can Scrum use technical specifications in the Product Backlog rather than user stories?
At the company I am currently working for we started to do Scrum projects. It was not so hard to convince the managers to move from waterfall to Scrum. We're doing a project where we rebuild our platform from scratch. So (most) functionality is known and most improvements are rather technical.

In this it could be justified to have technical tasks rather than user stories. Our backlog has got all kinds of technical tasks like:

Rewrite DB class from MySQL to PostgreSQL.

Implement system logging.

Rewrite object cache.

Things that come up during the stand-ups include that long "research tasks" are wanted, but they are never done. Also, the team members claim in the middle of the sprint that unplanned tasks need to be added.

How should a Scrum Master deal with this? Could it be that for this kind of project, Scrum is NOT the way to go?

答:
I don't think the problem here is Scrum as such, I think the problem is that there isn't a clearly defined project deliverable and (I've experienced this many times) no clear direction.

I think your technical tasks are fine, possibly on the large side but measurable and definable so absolutely fine for a story.

Research tasks are a huge red flag for me in Scrum because they provide little visible benefit and can create enormous scope creep. I advocate limiting these upfront in a sprint, they should not be added in and they certainly shouldn't be added in at the expense of committed goals. If they're needed to complete an agreed sprint task then that dependency should have been clear at planning (otherwise, what were they estimating?).

In my experience, projects with lots of "investigation spikes" are a cover for developers not actually doing a great deal and wanting to spend time finding out about the new shiny cool thing rather than creating business value. I'm not suggesting your team is doing this, but a project needs clear goals and if developers are given freedom to "research" then they'll do it, and keep doing it, for as long as you'll allow it.


问:
Woes of a Junior Developer - is it possible to not be cut out for programming?
(Let me start off by asking - please be gentle, I know this is subjective, but it's meant to incite discussion and provide information for others. If needed it can be converted to community wiki.)

I recently was hired as a junior developer at a company I really like. I started out in the field doing QA and transitioned into more and more development work, which is what I really want to end up doing. I enjoy it, but more and more I am questioning whether I am really any good at it or not. Part of this is still growing into the junior developer role, I know, but how much? What are junior developers to expect, what should they be doing and not doing? What can I do to improve and show my company I am serious about this opportunity? I hate that I am costing them time by getting up to speed. I've been told by others that companies make investments in Junior devs and don't expect them to pay off for a while, but how much of this is true? There's got to be a point when it's apparent whether the investment will pay off or not.

So far I've been trying to ask as many questions I can, but I've you've been obsessing over a simple problem for some time and the others know that, there comes a time when it's pretty embarrassing to have to get help after struggling so long. I've also tried to be as open to suggestion as possible and work with others to try to refactor my code, but sometimes this can be hard clashing with various team members' personal opinions (being told by someone to write it one way, and then having someone else make you rewrite it).

I often get over-stressed and judge myself too harshly, but I just don't want to have to struggle the rest of my life trying to get things work if I just don't have the talent. In your experience, is programming something that almost everyone can learn, or something that some people just don't get? Do others feel this way, or did you feel that way when starting out? It scares me that I have no other job skills should I be unsuited for having the skills necessary to code well.

答:
This is an old thread, but I wanted to add my 2 cents in case someone stumbles upon this in a Google search.

The developers I work with are pretty helpful and are open to lending a hand.  We all have strengths in difference places, so we're all pretty much open to helping each other.  If you can learn something that the other people on your team don't know but could be of use to them, it might loosen them up and make them more willing to give and take.  If you're in an entry-level position, I would suck it up and not let it phase you.  When you leave this position, the next one will be with a clean slate.  So, I would hang around and learn as much as you can and get as much experience under your belt as possible so that in your next gig, you'll be more experienced and have better footing.

I don't really believe in filing complaints with management over your repertoire with coworkers.  Management is going to look at you like a tattle-tale who can't get along with the others.  Your supervisors aren't baby-sitters, so if there's that big of a cultural problem with your environment, you don't want to be a part of it.  You can't expect management to come in with a magic bullet answer to force your coworkers to respect you.  I've been in a few positions where I didn't really feel I felt in with the team.  I just pack up and move on.  Whatever their cultural limitations are that won't allow me to be treated like I'm equal... that's their problem.  Who am I to come in and try to change them to fit me?  Your situation sounds like an exception to the norm, so I wouldn't assume that it'll be like that everywhere.

My experience is that most programmers are EXTREMELY pretentious.  Even if you absolutely know what you're doing, if you don't do it their way they'll get all in your face and act like you're a stupid idiot who doesn't know what you're doing.  Most of the answers you see on message boards are indicative of that.  For every helpful answer you see to a development problem on a message board, you'll see 10 pretentious answers by snotty individuals who want to poke fun and say whatever they can to boost their own floundering ego.  In fact, I'm convinced that 3/4 of every reply to a question on a message board either criticizes the formation of the question, whines that the question isn't posted in the right place, complains that the question was already asked a long time ago and therefore should never be asked again, or it's a link to another message board where the question is answered with some kind of comment like "Learn how  to use Google, STUPID!!!"  I don't ask questions on forums unless it is absolutely necessary.  Forums are a great place to find answers, but it's a horrible place to ask questions (if that makes sense).  Forums have these ridiculous rules and guidelines they want you to follow if you ask questions... they basically expect you to be the caliber of user who trolls that message board ALL the time and is used to their formatting and content restrictions.  I've had perfectly normal questions straight DELETED... even from Stack Exchange... all because it "wasn't formatted correctly."

Bad programming is the result of 1 of 2 things:  Either you don't understand the concepts or your don't know the syntax.  I'm not convinced that anybody can't learn both of these principles.  Programming isn't a natural talent that you have to be born with.  It's a learned practice.  I'm not even sure it really takes that much intelligence.  You just have to be patient and committed to learning.  If people understand WHY a certain programming practice is a problem, I think they'll take the necessary steps to correct themselves.  They don't need a freaking review board of snotty assholes berating them.

I learn the most through reading and studying on my own rather than asking others for help.  W3Schools is a great place to learn some new things.  Even if you're mainly developing in VB, running through some tutorials on JavaScript or PHP or Entity or MVC can really help your basic understanding of object oriented programming concepts.  In most cases, your first couple development gigs they'll just throw you into some code and you kind of hack at it until you get it to work.  That may be good enough, but if you don't know the concepts behind what you're doing, you can't really expect yourself to do it the "right" way.

IMO, you can't really learn how to be a top-notch developer before you ever get to develop. As with anything, practice makes perfect... and most seasoned developers seem to forget that.

ContentLicense: CC BY-SA 2.5


问:
If I used GPL code in server side app, what if any of my code do I need to release?
Consider a service such as Netflix... if on the server side netflix used code with a GPL license attached, do they have to make their server side code available under the terms of the GPL?

Obviously netflix being only an example, the company I worked for mostly provides 'services', we don't sell software that anyone can download to their computers, more like, computers over a network talk to our computers and stuff gets done.

Can I consider using GPL code in this environment without making all my code 'open source'?

答:
No, you don't have to release any GPL-derived code as long as it is executed only on your own servers.

The GPL only applies when a program is given to another party.

There is the Affero GPL which requires to license the program to anyone who uses it remotely over a computer network, but this is still a rather exotic license.


问:
What is the size of a reference variable in java. Can it be calculated?
As pointers in C require 2 bytes of memory size irrespective of the size of the data type they are pointing. So does the same thing applies to java references also ?</p>

答:
Because of -XX:+UseCompressedOops JVM HotSpot option, object references are 8 bytes.

Enables the use of compressed pointers (object references represented as 32 bit offsets instead of 64-bit pointers) for optimized 64-bit performance with Java heap sizes less than 32gb.

We can test this by adding a reference to an empty class and measuring its memory usage. This shows 24 bytes used on the heap. Add one more "byte" primitive, measure again and you'll see 32 bytes of heap usage.


答:
As the Scrum Master, you may want to consider longer sprints because of the nature of the work. This will give you a little more of a buffer for the "research" tasks. However, I think you need to make sure the tasks produce some sort of work product/proof of concept in code. Whatelse do you expect a programmer to do? Ask them to get something to work and use this information to determine if A: it does what we want B: it performs better C: How long will it take to get more up-to-speed and start getting any idea how long it will take to make something.

If you discover you don't know as much as you thought about the current rewrite, you can go to shorter sprint cycles. Don't be afraid to adjust them as you go along; this is what is meant by being agile. After your research you may also decide to go with the new technology. This could be another reason to shorten the sprints before getting too far out of control. You may discover in the middle of a sprint the new stuff isn't going to work. Stop the sprint and adjust it with the old technology. Afterall, your developers should have been able to compare and contrast the old and new methods.

You're juggling the needs of your developers and in this case getting the application rewritten. I'm guessing there are Product Owners who want this project completed sooner rather than later and won't accept the need for "research" as a long term excuse.

Title: Can Scrum use technical specifications in the Product Backlog rather than user stories?

Body:
At the company I am currently working for we started to do Scrum projects. It was not so hard to convince the managers to move from waterfall to Scrum. We're doing a project where we rebuild our platform from scratch. So (most) functionality is known and most improvements are rather technical.

In this it could be justified to have technical tasks rather than user stories. Our backlog has got all kinds of technical tasks like:

Rewrite DB class from MySQL to PostgreSQL.

Implement system logging.

Rewrite object cache.

Things that come up during the stand-ups include that long "research tasks" are wanted, but they are never done. Also, the team members claim in the middle of the sprint that unplanned tasks need to be added.

How should a Scrum Master deal with this? Could it be that for this kind of project, Scrum is NOT the way to go?


问:
things to think of when moving into C-land
Hello

Over the years have I made a programming journey from C in 1990 to Pascal, C++ with I programmed commercially, java VHDL, C# and now I'm taking a look on F#.

In the spring I will go back to study embedded programming in C in a university course so before I do that I will refresh my knowledge in C.

I don't remember much of the C that I learnt and I think I am thankful for that for probably learned some bad habits back then.

I have some questions to get me on the way.

--edit--

To clarify: I am thankful for tips that have been given regarding embedded programming but now I am more interested in relearning C in general. Sorry if my question was unclear,

Compiler, Debugger, IDE? As a microslave I was thinking about 2010 C++ Express, any alternatives?

Where do you find good libraries with code for C. I'm thinking something similar to Boost, POCO in C++

Source for procedural programming patterns and best practices. Where can you find good code learn from?

Thanks in advance

Gorgen

答:
I use Komodo and compile and debug using Xcode.  Xcode uses the GDB debugger, but IMHO it is WAY easier to use.  </p>

<p>If you use cmake, you can output xcode project files and compile under bsd and linux.  </p>

Body:
I use Komodo and compile and debug using Xcode.  Xcode uses the GDB debugger, but IMHO it is WAY easier to use.

If you use cmake, you can output xcode project files and compile under bsd and linux.


问:
Problem in Understanding Algorithm from TAOCP "Multiply Permutations in Cycle Form"
I am not able to understand one algorithm discussed in TAOCP Volume 1; Section 1.3.3 named as "Algorithm A" stated as "Multiply permutations in cycle form" while compared with the stated example in next page.

The step that is not clear is mentioned in 8th and 9th rows;i.e. how can be the "CURRENT" value becomes "g" after the previous iteration where the CURRENT value was "d"?

Please refer to "The Art of Computer Programming Volume 1" by Knuth for more details (section 1.3.3). It contains the detailed description of this algorithm.

Detailed Algorithm:

Algorithm A (Multiply permutations in cycle form).

This algorithm takes a product of cycles, such as (6), and computes the resulting permutation in the
form of a product of disjoint cycles. For simplicity, the removal of singleton cycles
is not described here; that would be a fairly simple extension of the algorithm.
As this algorithm is performed, we successively "tag" the elements of the input
formula; that is, we mark somehow those symbols of the input formula that have
been processed.

A1. [First pass.] Tag all left parentheses, and replace each right parenthesis by
a tagged copy of the element that follows its matching left parenthesis. (See
the example in Table 1.)

A2. [Open.] Searching from left to right, find the first untagged element of the
input. (If all elements are tagged, the algorithm terminates.) Set START
equal to it; output a left parenthesis; output the element; and tag it.

A3. [See CURRENT.] Set CURRENT equal to the next element of the formula.

A4. [Scan formula.] Proceed to the right until either reaching the end of the
formula, or finding an element equal to CURRENT; in the latter case, tag it
and go back to step A3.

A5. [CURRENT = START?] If CURRENT i- START, output CURRENT and go back to
step A4 starting again at the left of the formula (thereby continuing the
development of a cycle in the output).

A6. [Close.] (A complete cycle in the output has been found.) Output a right
parenthesis, and go back to step A2.

答:
In my copy of the book, Row #7 has CURRENT value d, Row #8 has CURRENT value g, and Row #9 has CURRENT value a.  I'll therefore assume you are confused about the transition between Rows #7 and #8, which are as follows:

```<code>Row #  After step no.  START  CURRENT  ( a c f g a ( b c d b ( a e d a ( f a d e f ( b g f a e b  Output
  #7        A5           a       d     x x       x x   x   x x     x x x   x     x x           x    d
  #8        A5           a       g     x x       x x   x x x x     x x x   x     x x x         x    g
</code>```

Row #8 starts with the state described in Row #7 and performs Step A5, which moves the cursor back to the beginning of the list and goes back to Step A4.  Here, Step A4 is performed three times:

Keeps going until it hits a d; tags the d because it is equal to CURRENT; sets CURRENT equal to b, because b comes after this particular d.

Keeps going until it hits another b; tags the b because it is equal to CURRENT; sets CURRENT equal to g, because g comes after this particular b.

Keeps going until it hits the end of the elements, because it doesn't find another g.

You can see the newly tagged d and b if you compare rows 7 and 8.  In particular, the second iteration of Step A4 within Row #8's Step A5 is what causes CURRENT to be set to g.

Body:
In my copy of the book, Row #7 has CURRENT value d, Row #8 has CURRENT value g, and Row #9 has CURRENT value a.  I'll therefore assume you are confused about the transition between Rows #7 and #8, which are as follows:

Row #  After step no.  START  CURRENT  ( a c f g a ( b c d b ( a e d a ( f a d e f ( b g f a e b  Output
  #7        A5           a       d     x x       x x   x   x x     x x x   x     x x           x    d
  #8        A5           a       g     x x       x x   x x x x     x x x   x     x x x         x    g

Row #8 starts with the state described in Row #7 and performs Step A5, which moves the cursor back to the beginning of the list and goes back to Step A4.  Here, Step A4 is performed three times:

Keeps going until it hits a d; tags the d because it is equal to CURRENT; sets CURRENT equal to b, because b comes after this particular d.

Keeps going until it hits another b; tags the b because it is equal to CURRENT; sets CURRENT equal to g, because g comes after this particular b.

Keeps going until it hits the end of the elements, because it doesn't find another g.

You can see the newly tagged d and b if you compare rows 7 and 8.  In particular, the second iteration of Step A4 within Row #8's Step A5 is what causes CURRENT to be set to g.


答:
TL;DR

Scrum does not mandate the use of user stories; they are simply a useful agile practice. While the Product Owner could certainly use technical specifications instead of user stories to build the Product Backlog, most of your other process problems stem from a failure to embrace effective Scrum and agile practices.

Various Problems with Your Process

Your Scrum appears to be broken in a wide variety of ways, including:

Your specifications lack an explicit point of view or value proposition.

Your backlog items aren't being tied to Sprint Goals.

Your Backlog Grooming process is either missing altogether or failing to create story spikes for the Product Backlog.

Your Sprint Planning process is not adequately decomposing Product Backlog items into Sprint Backlog items.

Your team is not properly including uncertainty about backlog items in its Sprint Planning estimates.

Your team is not respecting the fundamentals of time-boxing or the integrity of the Sprint.

While Scrum is not always the right fit for every project, in this case it would be more accurate to say that Scrum isn't working because the team isn't really doing Scrum. Your question about user stories is only a small part of the larger process issues facing your team.

Why Agile Programmers Embrace User Stories

Technical specifications are a fundamentally broken way to communicate requirements. Requirements that are unmoored from a point of view don't provide any useful guidance for developers. Using your posted examples:

Rewrite object cache. Why? What's the objective? Who receives the benefit? Who can provide clarification about the task? If this is tied to a non-functional requirement, what project goal does this address?

Implement system logging. Why? Who's going to read the logs? What information do the logs need to contain? How will you know if the log format or log data are useful?

From a developer's perspective, not being able to answer these sorts of questions leads to exactly the sort of process problems you describe. That's what user stories do: they provide much-needed context and act as placeholders for additional conversations with stakeholders or end users about specific features.

You shouldn't use user stories because you think it's a framework requirement, or because it's a widely-accepted agile practice. Instead, you should work on creating and using them effectively because it makes programming tasks easier and the programming profession more fun. Your mileage may vary, of course.


问:
Entity Framework designer not effective anymore
At my current workplace, Entity Framework 5 is used for all data access/manipulation.

It is a database-first approach using the model designer to add/edit/delete/update entities.

Problem

We now have tons of tables and this is becoming a nightmare to update.  The model is very convoluted and it can sometimes crash the IDE. I'm not super clued up on the Entity Framework side of things, but surely this isn't the recommended approach.  I have never liked the designer from the beginning. WYSIWYG-like designers spell trouble in my eyes.

Solution?

Structural changes to the database are essentially done by DBAdmins so we can't do code-first (anyway, I prefer not to have database tables generated).

Is there a better approach to this? Shouldn't we be using an XML-based mapper instead of using the designer.  What about code-first to the existing database?

答: You should consider a few things. Most importantly, don't use one big huge model for your whole app. Create different models focused on your sub-domains. (This is my advice whether you are using code first or using the designer) If you can't give up this big model and don't want to flip to code first, take a look at the EF designers by LLBLGen and DevArt. </p>


答:
We had the same situation and we turned into the code-first approach. Because essentially what EF Designer does, is to:

Generate some classes for you

Map those classes to equivalent database entities

Which is the essence of every ORM. EF designer is only a utility or facility out there, to save you time from writing hundreds of codes of entities. Thus in code-first, the major difference is that you should write the code yourself.

However, since you say that DBA changes the DB, I recommend two things:

First, talk to him to follow OCP in database level too. Once a table is used in many places in code, it's better no to modify it, but to extend it.

Create a powerful mapping test for your data access layer and your models. We have this. Each time we encounter a bug, we first run mapping tests to make sure that our classes are mapped correctly to our database, then we search other places.

Title: Entity Framework designer not effective anymore

Body:
At my current workplace, Entity Framework 5 is used for all data access/manipulation.

It is a database-first approach using the model designer to add/edit/delete/update entities.

Problem

We now have tons of tables and this is becoming a nightmare to update.  The model is very convoluted and it can sometimes crash the IDE. I'm not super clued up on the Entity Framework side of things, but surely this isn't the recommended approach.  I have never liked the designer from the beginning. WYSIWYG-like designers spell trouble in my eyes.

Solution?

Structural changes to the database are essentially done by DBAdmins so we can't do code-first (anyway, I prefer not to have database tables generated).

Is there a better approach to this? Shouldn't we be using an XML-based mapper instead of using the designer.  What about code-first to the existing database?


答:
Scrum says that you'd better have a deliverable product to your customer. However, the point here is that, it doesn't specify the deliverable product and the customer.

In other words, in your specific case, you might define your deliverable product as code improvements, platform changes, rewrites and redesigns, etc., and consider your technical manager to be your customer.

That makes 100% sense to me. You create a backlog that tells the stories of the user of your products, and who is the user? Technical manager. Thus items like:

As the technical manager, I want my database to change from MySQL to X, so that I can increase the scalability

As the developer, I want a comprehensive logging system, so that I can diagnose more efficiently

And what you deliver to your customer (technical manager) is a logging system.

However, regarding the R&D tasks you talked about, I recommend that you read about spikes in Scrum. They are essentially time-boxed mini-tasks that help you determine the time required to perform bigger unfamiliar tasks.


答:
The important stuff is not so much the license you are using, but rather the license that the third-party library is using.

Assuming you have obtained the third-party library through legal means, then the license of that library determines what you can do with it and what conditions you must abide with if you want to distribute your combined program + library.

As the flot library uses the MIT license, you can freely use the library in your project. You only have to make sure that the license text is kept with the files from the flot library.

A different case arises if the third-party library uses a strong copyleft license, like the GPL.

Those licenses stipulate that they must apply to the entire product of program + libraries. This means that if you use a GPL library, then, for all practical purposes, you must also use the GPL for your own code. Technically, you can use a different, more permissive, license, but the GPL terms would still apply to the code, so there is not much point in doing so.

Title: Apache 2 License and copyrighted Libraries

Body:
I am working on my first big(ger than before) project at my university which is coded under the Apache 2 License.

So here is the question:
Can I use copyrighted material/libraries (no restrictions and free to use) inside that project?
I want to be specific: The library is flot (flotcharts.org)

My guess is yes, but guesses do not count.


问:
design practice for business layer when supporting API versioning
Is there any design pattern or practice recommended for business layer when dealing with multiple API version.

For example, I have something like this.

http://site.com/blogs/v1/?count=10

   which calls business object method GetAllBlogs(int count) to get information

http://site.com/blogs/v2/?blog_count=20

which calls business object method GetAllBlogs_v2(int blogCounts)

Since parameter name is changed, I created another business method for version 2.  This is just one example but it could have other breaking changes for which it requires me to create another method to support both version.  Is there any design pattern or best practice for business/data access layer I should follow when supporting API Versioning?

答:
I recommend that you read about versioning first, because I think that you have misunderstood the aim of versioning.

Versioning is not about changing a number each time you change your code, it's about keeping a semantic pattern of numbers related to your code, so that you can track and trace better, manage dependencies, plan releases, etc.

And the best versioning scheme I've ever seen till now is the Semantic Versioning, or SemVer


问:
Should a persisted and 'finished' by state transaction be editable to any user
I came from a background where I taught that when a transaction reached some state (FINISHED, PRINTED, etc) it should no longer be opened for modification even to admin users.

But here I am, fixing their human-input error barbarically by deleting a row in database and/or changing the current item's state to it's previous one.
At some point they even make a mistake in inputting a transaction date, and just realized it somewhere later.

And it's really annoying.

Should a software, especially an enterprise one, gives a user all the freedom they requested?

If so, what good does a transaction state for?

Update :

Here, by transaction I mean a Transaction object which usually consisted a reference to Master object and it's own attributes, not database transaction.

答:
By transaction state, I don't know what you mean clearly. Maybe you should expand a little bit. But I think a kind of misunderstanding has happened here.

A transaction is by definition an ACID operation. In brief, a transaction should:

Either be performed completely, or not at all. Never anything in-between.

Not violate the consistency rules (like constraints) of data

Be performed in an isolated space from other transactions (according to transaction isolation level specified)

Be durable, that is, continue to exist and not be temporary

Now, after a transaction has happened, still anybody with enough privileges can access the database, and change it just like any other normal data.

In other words, what exist before and after a transaction, is pure data. You can manipulate it just like any other data. Transactionally-inserted data is nothing special. It's not that you can't or you shouldn't change it manually.


问:
What do you do to estimates for agile stories where developers are pair programming?
If it was a 2-point story for one person, would you double it if people are pairing?

Pairing isn't always necessarily done 100% of a dev task, so it seems that doubling the story points seems wrong.  And it might not be obvious how much of the task will require pairing until the end, so you wouldn't know what the points the story should be until you've finished - and it seems strange to change an estimate midway through a sprint.

However, if velocity is going to be an accurate representation of how much work we can get through during a sprint, it seems right to change the estimates if more than one person is working on a task.  But also, this seems like it adds a lot of admin overhead.

Thoughts?

答:
TL;DR

Story points are estimates of the effort for the team as a whole to move a story from "started" to the "definition of done." If stories don't involve multiple skill sets or involve multiple people, you probably have a task rather than a story.

Story Points Aren't Man-Hour Estimates

Story points are a measure of relative effort:

```<code>  If FOO is a baseline 2-point story
 And BAR is roughly twice as much work
Then BAR is a 3-point or 5-point story.
</code>```

In Scrum, one typically sees the Product Backlog estimated in story points, although opinion is often divided about whether individual tasks should be estimated on the Sprint Backlog. When estimating Sprint Backlog tasks, one can certainly use ideal hours rather than story points, but even so the estimates are generally for wall-clock time rather than man-hours.

Scrum Teams Use Self-Organized Time-Boxes

Man-hour estimates are usually a "project smell" that a team is not fully self-organizing. An effective Scrum team is agile precisely because it enables teams to shift resources from task to task as needed within each sprint.

If the team embraces pair programming, or if a story requires multiple team members to swarm over specific tasks, then the team should be factoring those things into both their story-point estimates and into their Sprint Planning. During Sprint Planning, the Scrum team peels each story off the Product Backlog, estimates it, and then tries to determine if the story will fit into the current sprint.

Team effort required to reach the "definition of done" tends to be a more accurate tool for this type of assessment than measuring man-hours. However, the team should use whatever metrics lead to the most success for the project.

Generally speaking, the key is to let the task performers (e.g. the development team) do the estimation. Man-hour estimates tend to be a budgeting tool imposed on the team's estimation process from outside, rather than providing an effective estimation technique for a time-boxed process. Scrum is based on time-boxing, not the 100% utilization fallacy, so it's probably best to avoid techniques designed to measure utilization right from the start.

Each team and each project are different, so your mileage may certainly vary.

Body:
TL;DR

Story points are estimates of the effort for the team as a whole to move a story from "started" to the "definition of done." If stories don't involve multiple skill sets or involve multiple people, you probably have a task rather than a story.

Story Points Aren't Man-Hour Estimates

Story points are a measure of relative effort:

  If FOO is a baseline 2-point story
 And BAR is roughly twice as much work
Then BAR is a 3-point or 5-point story.

In Scrum, one typically sees the Product Backlog estimated in story points, although opinion is often divided about whether individual tasks should be estimated on the Sprint Backlog. When estimating Sprint Backlog tasks, one can certainly use ideal hours rather than story points, but even so the estimates are generally for wall-clock time rather than man-hours.

Scrum Teams Use Self-Organized Time-Boxes

Man-hour estimates are usually a "project smell" that a team is not fully self-organizing. An effective Scrum team is agile precisely because it enables teams to shift resources from task to task as needed within each sprint.

If the team embraces pair programming, or if a story requires multiple team members to swarm over specific tasks, then the team should be factoring those things into both their story-point estimates and into their Sprint Planning. During Sprint Planning, the Scrum team peels each story off the Product Backlog, estimates it, and then tries to determine if the story will fit into the current sprint.

Team effort required to reach the "definition of done" tends to be a more accurate tool for this type of assessment than measuring man-hours. However, the team should use whatever metrics lead to the most success for the project.

Generally speaking, the key is to let the task performers (e.g. the development team) do the estimation. Man-hour estimates tend to be a budgeting tool imposed on the team's estimation process from outside, rather than providing an effective estimation technique for a time-boxed process. Scrum is based on time-boxing, not the 100% utilization fallacy, so it's probably best to avoid techniques designed to measure utilization right from the start.

Each team and each project are different, so your mileage may certainly vary.


答:
Your users obviously need a feature (changing or removing of an item after it has reached a certain transaction state) which your application doesn't provide. It seems like when designing the application you thought that there would never be a reason to do so, but the task you are currently performing proves that there is. Otherwise you wouldn't have to do it.

Nobody is perfect. Input errors are human, as is not noticing them until it is too late. Every business process and the software system which represents it must keep that in mind.

When revision requirements dictate that a document must not be invisibly changed after a certain point in the business process was reached, there should be a way to make the correction transparently. This can happen by using a visible change history of an item or by setting its status to "VOID" or "CANCELED" and creating a new item. The latter also allows to define a proper process for these situations.

Example: When the status of an invoice changes from "PRINTED" to "CANCELED", automatically print an apology letter telling the customer to ignore the previous invoice.

Title: Should a persisted and 'finished' by state transaction be editable to any user

Body:
I came from a background where I taught that when a transaction reached some state (FINISHED, PRINTED, etc) it should no longer be opened for modification even to admin users.

But here I am, fixing their human-input error barbarically by deleting a row in database and/or changing the current item's state to it's previous one.
At some point they even make a mistake in inputting a transaction date, and just realized it somewhere later.

And it's really annoying.

Should a software, especially an enterprise one, gives a user all the freedom they requested?

If so, what good does a transaction state for?

Update :

Here, by transaction I mean a Transaction object which usually consisted a reference to Master object and it's own attributes, not database transaction.


问:
What is your favorite whiteboard interview problem?
Just as the title says, what is your favorite whiteboard interview problem, and why has it proven effective for you?

Junior, senior, Java, C, Javascript, PHP, SQL, pseudo-code, etc.

答:
I've found this one extremely illuminating when interviewing candidates and filtering out those with no business being there. It is similar in complexity to Fizz Buzz, but focuses on database skills.

```<code>Assuming the following basic  table structure
Documents (DocID, DocDate)
Keywords (KeyWordID, KeyWord)
DocumentKeywords (DocID,KeywordID)

Write a query to return the following:
Part 1: Documents with a DocDate after 4/1/1995
Part 2: Documents that contain the keyword "Blue"
Part 3: Documents that contain the either the keyword "Blue" or "Yellow"
Part 4: Documents that contain the both the keywords "Blue" and "Yellow"
</code>```

I let them write it in any SQL variant they want, and am not too picky on minor syntax problems. I mainly want to know that they understand basic relational DB concepts.

Most candidates can get through part 3 with no issues at all. You'd be amazed how many think that the answer to part 4 is just to change the operator from OR to AND in the where clause.

Body:
I've found this one extremely illuminating when interviewing candidates and filtering out those with no business being there. It is similar in complexity to Fizz Buzz, but focuses on database skills.

Assuming the following basic  table structure
Documents (DocID, DocDate)
Keywords (KeyWordID, KeyWord)
DocumentKeywords (DocID,KeywordID)

Write a query to return the following:
Part 1: Documents with a DocDate after 4/1/1995
Part 2: Documents that contain the keyword "Blue"
Part 3: Documents that contain the either the keyword "Blue" or "Yellow"
Part 4: Documents that contain the both the keywords "Blue" and "Yellow"

I let them write it in any SQL variant they want, and am not too picky on minor syntax problems. I mainly want to know that they understand basic relational DB concepts.

Most candidates can get through part 3 with no issues at all. You'd be amazed how many think that the answer to part 4 is just to change the operator from OR to AND in the where clause.


问:
Is it safe to just use MySQLi?
I have developed an open source PHP application and currently it uses both the MySQLi or MySQL extension for backwards compatibility. I'm wondering about switching it over to only be compatible with MySQLi since PHP now no longer supports the MySQL. Another reason I'd like to get away from supporting both MySQL and MySQLi is that I'm basically using MySQLi the same way I do as with the old MySQL extension. Can anyone explain to me if this is a good or bad idea?</p>

答: The preferred method is to use only mysqli. As you said, the older MySQL extension is no longer supported. Both can connect to most versions of MySQL server, so there's no reason at all to use the old extension. </p>

Title: Is it safe to just use MySQLi?


问:
Coding style for chained function calls
A common thing you need to do is to take a value, do something with it by passing it to a function, and then do some more with the return value, in a chain. Whenever I run into this type of scenario, I get unsure about how best to write the code.

As an example, let's say I have a number, num, and need to take the floored square root of it and turn it into a string. Here are a few possibilities (in JavaScript).

I might simply pass num to one function at a time, and replace num with the return value:

```<code>function floorSqrt(num) {
    num = Math.sqrt(num);
    num = Math.floor(num);
    num = String(num);
    return num;
}
</code>```

This is nice since I don't need the original num any more, but in practice it might be confusing to start with one thing (a number) and end up with something completely different (a string).

I can save each step in a new variable:

```<code>function floorSqrt(num) {
    var sqrtNum = Math.sqrt(num);
    var floorSqrt = Math.floor(sqrtNum);
    var stringNum = String(floorSqrt);
    return stringNum;
}
</code>```

Although it seems wasteful to declare all those variables and come up with good names for them.

Or I can just do it all as a one-liner:

```<code>function floorSqrt(num) {
    return String(Math.floor(Math.sqrt(num)));
}
</code>```

But for more than two functions that approach gets incredibly unreadable, almost like code golf.

It seems to me like the most beautiful way to do this would be with some stack-based language, which might look something like this (pseudo code):

```<code>[sqrt floor toString]
</code>```

Is there a way to do something similar with JavaScript? List some functions, run one at a time, and use the return value of each one as the argument for the next? The closest is how some libraries like jQuery or Underscore.js allow you to chain methods, something like this:

```<code>function floorSqrt(num) {
    return _.chain(num).sqrt().floor().toString().value();
}
</code>```

I'm sure many wise people have thought wise things about this. What are some thoughts on pros and cons of the different styles?

答: I would not nest too many methods when using the standard math and string methods, for example, in Javascript. But there are libraries which have a so-called fluent interface, these kind of API's are especially made for making readable code by method chaining. You will find tons of articles when you google for those keywords.</p>

Title: Coding style for chained function calls


答:
If you are going to switch anyway, you should really consider going with PDO instead of MySQLi.

The main benefit, would be that your application would be able to work with any of the 11 other database backends supported by PDO, with minimal fuss.
This might not be a priority for you, but since this is an open source application there's little reason to not try and make it as flexible as possible. Also, you'd be able to use named parameters in your prepared statements (MySQLi supports prepared statements, but not named parameters).

In any case, moving away from the mysql_* functions is a very good idea. These days, it's just a relic of the (dark) past, and unless backwards compatibility is an inescapable requirement there's absolutely no reason to use it.

Title: Is it safe to just use MySQLi?

Body: I have developed an open source PHP application and currently it uses both the MySQLi or MySQL extension for backwards compatibility. I'm wondering about switching it over to only be compatible with MySQLi since PHP now no longer supports the MySQL. Another reason I'd like to get away from supporting both MySQL and MySQLi is that I'm basically using MySQLi the same way I do as with the old MySQL extension. Can anyone explain to me if this is a good or bad idea?</p>


答:
Languages such as you describe exist, the most popular (popular being a relative term) is FORTH

Your example would look something like this in FORTH:

```<code>: floorSQRT  ( NUM -- NUM )
    Sqrt
    Floor
    ToString ;
</code>```

(Though FORTH is extremely low level, and so doesn't really have a string type the way we think of it now.)

If you really wanted to do something like this in JavaScript, you could, by creating your own versions of these methods that took an array as the first parameter, something like:

```<code>function Sqrt(stack) { stack.push(Math.sqrt(stack.pop())) };
function Floor(stack) { stack.push(Math.floor(stack.pop())) };
function MakeString(stack) { stack.push(String(stack.pop())) };

function floorSqrt(stack) {
    Sqrt(stack);
    Math.floor(stack);
    MakeString(stack);
}

stack.push(num);
floorSqrt(stack);
num = stack.pop();
</code>```

This would work, but it would be massively confusing to most JavaScript programmers, so don't ever do it.

Having worked with FORTH back in the day, the idea of a stack based language is very appealing, but in practice, for any reasonable sized piece of code, it quickly becomes confusing.  Because everything is implicit, it's hard to remember what each method is going to actually operate on.  Much more confusing than your original code, actually.  Honestly, if I were writing this code, and wanted it to be clear, it'd look like this:

```<code>function floorSqrt(num) {
    num = Math.sqrt(num);
    num = Math.floor(num);

    return String(num);
}
</code>```

I don't really find that confusing at all.  It's very clear.

If you really want to do chaining, you could try to make it clearer like this:

```<code>function floorSqrt(num) {
    return String(
               Math.floor(
                   Math.sqrt(num)
           ));
}
</code>```

But again, I don't think that's really necessary.  I think the original is perfectly fine and straightforward.

Title: Coding style for chained function calls

Body:
A common thing you need to do is to take a value, do something with it by passing it to a function, and then do some more with the return value, in a chain. Whenever I run into this type of scenario, I get unsure about how best to write the code.

As an example, let's say I have a number, num, and need to take the floored square root of it and turn it into a string. Here are a few possibilities (in JavaScript).

I might simply pass num to one function at a time, and replace num with the return value:

```<code>function floorSqrt(num) {
    num = Math.sqrt(num);
    num = Math.floor(num);
    num = String(num);
    return num;
}
</code>```

This is nice since I don't need the original num any more, but in practice it might be confusing to start with one thing (a number) and end up with something completely different (a string).

I can save each step in a new variable:

```<code>function floorSqrt(num) {
    var sqrtNum = Math.sqrt(num);
    var floorSqrt = Math.floor(sqrtNum);
    var stringNum = String(floorSqrt);
    return stringNum;
}
</code>```

Although it seems wasteful to declare all those variables and come up with good names for them.

Or I can just do it all as a one-liner:

```<code>function floorSqrt(num) {
    return String(Math.floor(Math.sqrt(num)));
}
</code>```

But for more than two functions that approach gets incredibly unreadable, almost like code golf.

It seems to me like the most beautiful way to do this would be with some stack-based language, which might look something like this (pseudo code):

```<code>[sqrt floor toString]
</code>```

Is there a way to do something similar with JavaScript? List some functions, run one at a time, and use the return value of each one as the argument for the next? The closest is how some libraries like jQuery or Underscore.js allow you to chain methods, something like this:

```<code>function floorSqrt(num) {
    return _.chain(num).sqrt().floor().toString().value();
}
</code>```

I'm sure many wise people have thought wise things about this. What are some thoughts on pros and cons of the different styles?

Body:
Languages such as you describe exist, the most popular (popular being a relative term) is FORTH

Your example would look something like this in FORTH:

: floorSQRT  ( NUM -- NUM )
    Sqrt
    Floor
    ToString ;

(Though FORTH is extremely low level, and so doesn't really have a string type the way we think of it now.)

If you really wanted to do something like this in JavaScript, you could, by creating your own versions of these methods that took an array as the first parameter, something like:

function Sqrt(stack) { stack.push(Math.sqrt(stack.pop())) };
function Floor(stack) { stack.push(Math.floor(stack.pop())) };
function MakeString(stack) { stack.push(String(stack.pop())) };

function floorSqrt(stack) {
    Sqrt(stack);
    Math.floor(stack);
    MakeString(stack);
}

stack.push(num);
floorSqrt(stack);
num = stack.pop();

This would work, but it would be massively confusing to most JavaScript programmers, so don't ever do it.

Having worked with FORTH back in the day, the idea of a stack based language is very appealing, but in practice, for any reasonable sized piece of code, it quickly becomes confusing.  Because everything is implicit, it's hard to remember what each method is going to actually operate on.  Much more confusing than your original code, actually.  Honestly, if I were writing this code, and wanted it to be clear, it'd look like this:

function floorSqrt(num) {
    num = Math.sqrt(num);
    num = Math.floor(num);

    return String(num);
}

I don't really find that confusing at all.  It's very clear.

If you really want to do chaining, you could try to make it clearer like this:

function floorSqrt(num) {
    return String(
               Math.floor(
                   Math.sqrt(num)
           ));
}

But again, I don't think that's really necessary.  I think the original is perfectly fine and straightforward.


答:
Our goal as software engineers, should be writing code that is clear and understandable for other humans, and I'm glad you've already realized that writing too many nested function calls you end up with code that is hard to read.

So assuming your language doesn't support jQuery-like syntax you mentioned at the end, seems the only good alternative you have left is to break up complex chain of function calls into simpler statements where each assigns a temporary value to an intermediary variable. So now you are left with only two choices: 1) reuse same variable name for each step and 2) define a new local variable for each step.

And assuming you've arrived at the same conclusion as me, I'll help you make the final choice: Use new variable names for each step

The argument "it is wasteful to declare 5 variables when I can use one" is a bit of premature optimization. I've had embedded guys join my team and this was one of their habit that I would always have to break.  Each variable should have a) meaningful name and b) always the same meaning.  Then when one reads through the code he never has to guess what "num" means especially since code tends to not stay as simple as your example.  Imagine someone else comes long, adds a few loops and if-statements and keeps reusing your "num" variable.  Now to understand what's in it, you would have to trace back and perform mental gymnastics in trying to determine just which statement was hit and how many times was "num" reassigned.

Assuming you are not doing embedded programming on a some board with 8 KB of RAM, there's no reason to reuse the same variable multiple times for multiple purposes.  Come up with good, clear names and use them.  When the stack unrolls, it costs exactly same amount to remove 1 int from stack as it takes to remove 6 ints.

Title: Coding style for chained function calls


问:
How many days is it normal for a new hire programmer to take to get up to speed?
I have just landed a role as a C#/Asp.Net developer at a large software house. I have previously worked at a much smaller software house for about two years but it was a varied/mixed role there, and here the asp.net applications we have are a factor of 10 or so larger.

As seems to be the norm, I have been given the task of fixing bugs. At the moment I am just trying to understand the system. How long , in your experience , does it "roughly" take ( and is generally acceptable) for a new developer to get up to speed? It of course varies from company to company but as a general rule, when you have hired someone/have worked with someone new, how many days/weeks would it have been normal for them to get to grips with the system?

答:
Depends. At my first job, all I got was two weeks and then I was thrown into the pool. I swam. I am not proud of my code back then, and I sure wish that someone would either give me more time or took some time to actually help me swim. But, as years went by, I apparently only got better and better.

Just to be clear, I do not condone dropping in the pool policy.


答:
It depends. But IMHO, it should take about a month to know your way around, and up to six months to be normally productive.

An interesting exercise, if you have time, etc: Take a part of the application, and reprogram it in another language, if you know any. Or, try reading all of the source code that you can, and write down what it does. That should help you get up to speed!

Title: How many days is it normal for a new hire programmer to take to get up to speed?

Body:
I have just landed a role as a C#/Asp.Net developer at a large software house. I have previously worked at a much smaller software house for about two years but it was a varied/mixed role there, and here the asp.net applications we have are a factor of 10 or so larger.

As seems to be the norm, I have been given the task of fixing bugs. At the moment I am just trying to understand the system. How long , in your experience , does it "roughly" take ( and is generally acceptable) for a new developer to get up to speed? It of course varies from company to company but as a general rule, when you have hired someone/have worked with someone new, how many days/weeks would it have been normal for them to get to grips with the system?


答:
The answer to this question is completely subjective.  The length of time it takes a developer to come up to speed can depend on:

the developer's level of knowledge and professional experience

the level of complexity of the application(s) or the level of documentation for the same

the ability of current application "experts" to onboard new developers.  By "experts" I mean application experts or those that have domain knowledge that would help a new developer become more familiar with the application.

your software methodology (yes I said it).  My take is that new developers in an Agile environment will get up to speed faster or fail faster.

I don't choose to give a time because I hope that I have given enough proof that this is too subjective to offer an exact answer on how long it will take someone to come up to speed.


问:
What is the job of a language virtual machine, and creating one
Recently I have become incredibly interested in language development. The past few weeks I have written many language front ends (lexer, parser) including a calculator language/expression parser and much more.  After creating so many things I have realized there MUST be more abstraction between parsing and code execution than what I currently have, which leads to my main question(s).

My first question is, this.  What exactly is the job of a language virtual machine, like for example the JVM (of course my envisioned system would be much, much much more smaller scale).  What does it do?  Does it actually sort of emulate hardware and execute low level instructions on the emulated hardware?  Or does it simply provide an abstraction and execute lower level managed instructions on the system?
(I have read this question but it hasn't really helped me understand)

Second question.  What exactly is byte code? Is it some sort of machine code for the virtual machine? Or is it the human readable possibly assembly like instructions, and are these instructions directly executed or somehow compiled to native code?

Third question.  How would I go about implementing this?  I consider myself a competent programmer and don't need step by step instructions by no means, just an overview of what exactly I need to be doing, and how low level this is exactly.

Thanks so much for any help/suggestions/explanations. Please ask questions if something I stated was confusing or you need more detail on it. Thanks again!

答:
After creating so many things I have realized there MUST be more abstraction between parsing and code execution than what I currently have, which leads to my main question(s).

Not really. In a typical industrial-strength production-quality high-performance language implementation, there usually are many more stages, but that is by no means a necessity. Simple tree-walking interpreters such as MRI Ruby, for example, really just lex, parse, then walk the abstract syntax tree and execute a snippet of code for every node visited. That's it. Even simpler line-based interpreters don't even build an AST.

My first question is, this.  What exactly is the job of a language virtual machine, like for example the JVM […].

The most important thing to realize is that a VM is nothing special. A virtual machine is anything which completely abstracts one API from a different API. That's it. For example, in object-oriented programming (at least in the form envisioned by Alan Kay), every object is a virtual machine.

More specifically in the context of languages: every language is a VM and every VM defines a language.

Really the only difference between a programming language and a VM instruction set is intent: the syntax of a programming language is designed to be easily read by humans, the semantics are designed for elegantly expressing complex problems. The syntax (format) of a VM instruction set is designed to be easily parsed by machines, and its semantics are designed to be easily interpreted (or compiled) and also easy to be compiled to.

But again: a VM instruction set is just a programming language like any other, and it is executed exactly the same way as any other programming language: by either interpreting it, or by compiling it to a different language that you already can interpret.

What does it do?  Does it actually sort of emulate hardware and execute low level instructions on the emulated hardware?  Or does it simply provide an abstraction and execute lower level managed instructions on the system?

That depends on what you want the VM to do. The LLVM instruction set, for example, is designed to be a machine-independent machine code, if you will. Its goal is to be easily compiled into efficient machine code. So, it tries to be as low-level and close to current mainstream CPU instruction sets (x86, AMD64, IA-64, SPARC, MIPS, ARM, etc.) as possible without tying it to a specific CPU instruction set.

The JVML instruction set OTOH was designed to be easily interpreted, and as such is much higher-level than the LLVM instruction set. The CIL instruction set is equally high-level as the JVML, but it was designed to be compiled, and so makes some different choices.

Second question.  What exactly is byte code? Is it some sort of machine code for the virtual machine? Or is it the human readable possibly assembly like instructions,

Byte code is simply the name for a language where instructions are encoded as bytes, instead of as text. That's it.

Note that many languages which are erroneously referred to as "byte code" actually aren't. For example, on the CLI, instructions are encoded as ints, not bytes, so CIL is an int code, not a byte code.

and are these instructions directly executed or somehow compiled to native code?

Either. Both. You decide. The first one is called "interpretation", the second is called "compilation". By the way: you don't need to compile to native code, you can compile to anything for which you have an interpreter or compiler. For example, the Fantom VM compiles its instruction set to either JVML or CIL, depending on whether it is run on the Java Platform or the CLI.

Every language can be implemented by a compiler and every language can be implemented by an interpreter. VM instruction sets are no different. For example, there are JVMs which interpret JVML byte code, there are JVMs which compile JVML byte code to native code while the program is running, there are JVMs which compile JVML byte code to native code before the program is running, there are JVMs which compile JVML byte code to JavaScript source code, and many many more. There are even CPUs which execute JVML byte code directly (which is really just a special case of the first option, where the interpreter is implemented in silicon instead of software).

Third question.  How would I go about implementing this?  I consider myself a competent programmer and don't need step by step instructions by no means, just an overview of what exactly I need to be doing, and how low level this is exactly.

A VM instruction set is a language just like any other language. You implement it just like any other language:

parsing

semantic analysis

type inference

type checking

optimization

code generation (for a compiler) or code execution (for an interpreter)

The parsing stage is usually trivial, because VM instruction sets are designed to be easy to parse. Type inference and type checking of course only make sense if the VM instruction set is typed. Optimization is optional, if you don't want to build a high-performance VM. OTOH, if you do want to build a high-performance VM, then optimization is where you are going to spend 99.999% of your development effort.


答:
What exactly is the job of a language virtual machine, like for example the JVM? What does it do?

A virtual machine is a program that can execute machine code that's not intended for the platform your computer uses. So, for example an x86 Windows computer can execute x86 Windows machine code directly, but it can't execute Java bytecode. That's what the JVM is for: to bridge the gap, so that your x86 Windows computer can execute Java bytecode.

This can be useful if you have multiple frontends (Java, Scala, Clojure, Jython, …) and you want to use the same code to execute them (which for example means that you can write many optimizations just once in the VM and use them from any of the supported languages).

Another good reason is if you have multiple backends (Windows, Linux, Android; x86, ARM, …) and you want to execute the same (or almost the same) code on all of them.

Does it actually sort of emulate hardware and execute low level instructions on the emulated hardware?

Kind of. It doesn't emulate specific hardware, but it does emulate some hardware that can execute the bytecode.

What exactly is byte code? Is it some sort of machine code for the virtual machine?

That's exactly what it is.

Or is it the human readable possibly assembly like instructions

That's the human-readable representation of the bytecode. The relation is exactly the same as with for example x86 assembly and x86 machine code.

When people need to read or write at the byte code, they almost always work with the human-readable form. But the virtual machine works directly with the bytecode. The important point is that the translation between the two is 1-to-1: each statement in the human-readable for corresponds exactly to a single instruction in the bytecode.

and are these instructions directly executed or somehow compiled to native code?

That depends on the implementation of the virtual machine. The simplest (and slowest) virtual machines just interpret the bytecode. More advanced VMs (like the desktop JVM or CLR) compile the bytecode into native machine code for the current platform and then execute that. But the only difference between the two options (or any other implementation) is performance.

How would I go about implementing this?

Like I said, the simplest VM is just an interpreter: it reads the bytecode instructions one at a time and immediately executes them. I think that doing this for something like the Java bytecode (or at least a decent subset of it) wouldn't be hard, though I think it would be tedious.

Since JVM is stack based, you could have a something like Stack<Object> to represent that. And instructions like incost_2 would just directly manipulate that stack. (Obviously, the performance of this VM would be abysmal, but that's not the point.)

Title: What is the job of a language virtual machine, and creating one

Body:
Recently I have become incredibly interested in language development. The past few weeks I have written many language front ends (lexer, parser) including a calculator language/expression parser and much more.  After creating so many things I have realized there MUST be more abstraction between parsing and code execution than what I currently have, which leads to my main question(s).

My first question is, this.  What exactly is the job of a language virtual machine, like for example the JVM (of course my envisioned system would be much, much much more smaller scale).  What does it do?  Does it actually sort of emulate hardware and execute low level instructions on the emulated hardware?  Or does it simply provide an abstraction and execute lower level managed instructions on the system?
(I have read this question but it hasn't really helped me understand)

Second question.  What exactly is byte code? Is it some sort of machine code for the virtual machine? Or is it the human readable possibly assembly like instructions, and are these instructions directly executed or somehow compiled to native code?

Third question.  How would I go about implementing this?  I consider myself a competent programmer and don't need step by step instructions by no means, just an overview of what exactly I need to be doing, and how low level this is exactly.

Thanks so much for any help/suggestions/explanations. Please ask questions if something I stated was confusing or you need more detail on it. Thanks again!


问:
What are the cases where keeping source code secret is justified?
When I worked as a freelancer, I encountered lots of cases where customers were protecting their ideas and source code of their projects (such as web applications) as much as possible, no matter how unimportant, uninteresting and unoriginal were the projects and the concepts behind.

I've already posted a question about keeping the ideas secret, and received many great answers. Now, my concern is more about source code secrecy.

According to my observations of:

The codebases I had to work on during my career,

My own willingness to keep some of my own source code secret, and:

A few articles like, for example, Open response to Simon Stuart by the popular Programmers.SE contributor Mason Wheeler,

I conclude that source code is kept secret mostly for those reasons:

Because the author is ashamed of the code of such a bad quality, or the company fears losing reputation if somebody sees such bad codebase, or that given the low quality of the codebase, it will not bring anything useful to anybody to open source it: even if somebody would be interested, he would hardly be able to run the solution (or, often, even compile).

Because parts of the code are stolen (mostly from open source projects covered by a license which restricts its usage in a given situation),

Because the code relies on security by obscurity and the author doesn't care about Kerckhoffs's principle.

Because the product is so breakable that showing the code would cause too much harm: if a closed-source app with all those security leaks would withstand a newbie hacker, the same open sourced app would have far smaller chances, because even the beginner hacker would just have to study the code to discover all the holes.

If it's not clear what I'm talking about, here's an example:

```<code>if (credentials.password === 'masterPassword12345')
{
    isLoggedIn = true
    currentUser = credentials.userName
}
else
{
    authenticate(credentials)
}
</code>```

Because the author over-estimated the source code (and his own skills and expertise). Example: believing that a home-made cryptography-related algorithm (which was never reviewed by anybody) is better than any well-known one.

Because the author believes that the idea behind the code is great, and that it would be stolen.

Because of the "It's not perfect enough" syndrome. In other words, the developer is willing to release the source code to public when the code is "good enough", but day after day, there are still things to improve, so the code would never be released.

All of those reasons give a rather negative image of people who are against publishing the source code.

Are there valid cases to not release to the public the high-quality code which follows Kerckhoffs's principle?

答: The most obvious answer of all, I think, is that the software is, for many companies, a substantial part of the value that the corporate entity brings to customers. So, if anyone could simply modify and re-compile the code, or re-use valuable parts of it, then they could offer the same service or value. This would hurt the corporate entity's competitive interests, and possibly cause them to lose money.</p>


答:
At my current job I am the sole developer and when I started nobody had any knowledge of the code.  I was given a codebase with 200k lines of code and told to implement new functionality against this codebase from day 1.  It probably took a week before I was writing useful code and three months before I understood the codebase well enough to track down most bugs on the spot and give confident technical answers when questions were asked.

That being said, I came to the job with 8+ years experience in coding .NET applications, so I know the basics of C# really well (so I am fairly fast at brain compiling code).  The time that it should take to hit peak coding efficiency in a new job is mostly a function of language experience, the size of the codebase, the available knowledge within the company, how well coded the product is and time.


答:
Some people and most companies have a strange perception about the value of code.

"We spent $100,000 on this project therefore the code must be worth that" and feel a need to protect it.

In reality most code is more like paint. You spend $100 on paint and $200 dollars to apply it to your walls. But now the paint is worth nothing, you cannot sell it, nobody wants it, and even if they did you cannot take it of your wall and put it on somebody else's wall.

It may enhance the value of the building but you cannot realize this without selling the building.

You could "steal" Amazons code base (most of it is freely available from various open source projects) and set up an Ammassons web site but you would not take over much of Amazons business.

Code is a necessary part of any modern businesses infrastructure, but, it only has value as part of a process and culture, on its own its worth nothing.

I would add there are some situations where the code is vital to the business and would be valuable enough to any competitor that it should be kept secret:

To prevent malicious manipulation of your facilities -- a good example would be Google's "page rank" system which is constantly being "gamed" to give web sites an unjustifiably high rank.

Automated Trading Algorithms -- an unscrupulous competitor could study the algorithm and fool your system into selling too low and buying too high.

A "faster/better" algorithim -- if your software' s unique selling point is a faster better algorithm for sorting/compressing/whatever then it probably pays to keep this a trade secret for as long as possible.

Title: What are the cases where keeping source code secret is justified?

Body:
When I worked as a freelancer, I encountered lots of cases where customers were protecting their ideas and source code of their projects (such as web applications) as much as possible, no matter how unimportant, uninteresting and unoriginal were the projects and the concepts behind.

I've already posted a question about keeping the ideas secret, and received many great answers. Now, my concern is more about source code secrecy.

According to my observations of:

The codebases I had to work on during my career,

My own willingness to keep some of my own source code secret, and:

A few articles like, for example, Open response to Simon Stuart by the popular Programmers.SE contributor Mason Wheeler,

I conclude that source code is kept secret mostly for those reasons:

Because the author is ashamed of the code of such a bad quality, or the company fears losing reputation if somebody sees such bad codebase, or that given the low quality of the codebase, it will not bring anything useful to anybody to open source it: even if somebody would be interested, he would hardly be able to run the solution (or, often, even compile).

Because parts of the code are stolen (mostly from open source projects covered by a license which restricts its usage in a given situation),

Because the code relies on security by obscurity and the author doesn't care about Kerckhoffs's principle.

Because the product is so breakable that showing the code would cause too much harm: if a closed-source app with all those security leaks would withstand a newbie hacker, the same open sourced app would have far smaller chances, because even the beginner hacker would just have to study the code to discover all the holes.

If it's not clear what I'm talking about, here's an example:

```<code>if (credentials.password === 'masterPassword12345')
{
    isLoggedIn = true
    currentUser = credentials.userName
}
else
{
    authenticate(credentials)
}
</code>```

Because the author over-estimated the source code (and his own skills and expertise). Example: believing that a home-made cryptography-related algorithm (which was never reviewed by anybody) is better than any well-known one.

Because the author believes that the idea behind the code is great, and that it would be stolen.

Because of the "It's not perfect enough" syndrome. In other words, the developer is willing to release the source code to public when the code is "good enough", but day after day, there are still things to improve, so the code would never be released.

All of those reasons give a rather negative image of people who are against publishing the source code.

Are there valid cases to not release to the public the high-quality code which follows Kerckhoffs's principle?


问:
What are CPU registers?
This question has been bothering me for some time now and today I figured I would Google it. I've read some stuff about it and it seemed very similar to what I've always known as processor cache.

Is there a difference between the two or am I right when I think they are the same?
Is a register actually required to be inside a CPU for it to work?

According to Wikipedia a register is a place in the CPU where memory can be quickly accessed and modified before being sent back to the RAM. Did I understand this wrong or are the cache and register actually the same?

答:
Actually A Register in CPU terminology is small Named chunk of memory  Available inside  a microprocessor(CPU), Registers have specific names, sizes and functions varies from processor to processor, for example, if take 8085 microprocessor is an 8-bit processor which has 8-bit
Registers(A:Accumulator, B,C,D,E, H, and L Registers and one flag register all are 8-bit).  Two 16-bit registers PC and SP all are having special function and functions comes into the picture during assembly programming. Few registers control is beyond the programmer.

If you take another processor Registers will vary let say 8086 is 16-bit processor and it has
AX,BX,CX and DX all are 16-bit, PC, SP and Flag registers.

as you quoted in the question they are to speed up the program execution and acts as processor cache but now a days processor architecture changed and they(Intel) add lot of memory calling processor cache

but there is slight difference between processor(CPU) cache and Processor(CPU)Registers, registers actually needed for some special activities like memory pointer, program status etc.. Ex:PC:Program Counter which acts a memory pointer in the program memory, SP:Stack pointer which acts a memory pointer in the stack memory. and Accumulator is buffer and main register to access ALU for Arithmetic Ops...

You can see Mason Wheeler explanation for exaples

Title: What are CPU registers?


问:
Is allowing voting without sign-in always a bad idea?
I have a mobile app from which I'd like to allow voting on Things. I don't want to force all the users to have to sign up using email/Facebook/etc. just so that I can properly limit voting.

Is it really a bad idea to leave voting to be an "open" process where anyone can vote? I know theoretically that this allows improper voting techniques, etc. but on the other hand getting more votes really don't offer any kind of financial motivation.

--Edit--

Perhaps there are some ways to limit vote-faking? I know theoretically nothing is unbreakable, but maybe I can limit the amount of votes something can get in a minute/hour/day?

--Edit 2 --

Think of it as "views" on a video. It is a simple measure of popularity that requires no login. What are ways to limit view tampering, and when is it necessary?

答: If this is implemented only for a native mobile app, you could restrict retreive some sort of unique device ID, dependent on what's available in the platform API. If no such thing is available, you could genereate a GUID on first run after installed, and store it on the device.</p>


答:
Regarding the third question:

A virtual machine is a program that executes a program. This can range from interpreters to Just In Time-compiling VMs.

To learn how to write a simple VM, you don't need much. The SECD machine is a simple model you can adapt. This is actually a mathematical model which can be used to reason about programs written in the lambda calculus. It is very easy to write your own version, and you can implement closures quite easily. However, you should start with a garbage-collected (and preferably dynamically typed) language for your own sanity (e.g. Python, Perl, Ruby, Go, or something from the ML family). The SECD has the following stacks:

Stack – where you keep intermediate values

Environment – where you keep ID-value mappings for variables

Command – where you keep instructions

Dump, sometimes spelt Kontinuation, which you need as a second stack for control flow.

How you implement instructions is up to you – I have both used Vtables and the Command pattern with great success for toy VMs.

There is another important datatype: the closure, which is just a pair of an environment, and an instruction list.

We can now define a few instructions. You can implement the theoretical instruction set or one of your own design. Important instructions I usually implement are:

Const – puts a constant argument onto the stack.

Stack manipulations like Dup, Drop and Swap.

Basic arithmetic that takes arguments from the stack.

Variable lookups (and if you are pragmatic, a set operation as well). Each map corresponds to one scope level. For string-based lookups: If you don't find the ID in the first map on the Env stack, look into the next. But often two integers are used to identify each variable. The first indicates the scope where the var was defined, the second the number of the variable defined in that scope. E.g. in { var x; HERE }, the x has coordinates 0, 0 – first variable in the outermost scope. But in { var x; { var y; var z; HERE } }, the y has coordinates 1, 0 – first variable in the 2nd scope.

Closure creation – usually has a constant argument, and combines it with a pointer to the current Env. The resulting closure is placed on the Stack.

Call – which takes a closure and a (single) argument from the stack. If you use stack marks, you can implement multiple arguments. But if you know lambda calculus, you know you don't need to.

To call the function, you save the current Environment, the Command and the current Stack on the Dump. Then you install the env from the closure as the new Env, and push a new empty environment on top of that (the current scope). Install the argument(s) in the environment. Next you install a copy of the commands from the closure as the new Command. Finally, you create a new Stack.

Return – pop a return value of the Stack. Then, restore Command, Env and Stack from the Dump. Push the return value onto the Stack.

Conditionals can be implemented by popping a boolean and two closures of the stack, then conditionally placing one closure back again. You can then Call that closure.

Many of these can be implemented as sequences of smaller ops, but the above operations should be sufficient for running Turing-complete programs. A simple program like

```<code>fun myadd(x, y) { x + y }
var a = 40
var result = myadd(a, 2)
</code>```

could be translated to the ops

```<code>Closure(2, [Var(1, 0), Var(1, 1), Add, Return]), Set(0, 0),
Const(40), Set(0, 1),
Var(0, 1), Const(2), Var(0, 0), Call, Set(0, 2)
</code>```

where Closure takes an argument specifying the number of arguments for that function to pop of the stack.

It is very easy to compile to these Ops from an AST representation.

The actual VM is now just a loop that pops Ops from the Command, invokes the correct implementation, and stops once the Command is empty:

```<code># Perl, using an array for Op implementation lookup
method run {
    while (@$command) {
        $self->display_state if $debug;
        $OPCODES[pop @$command]->($self);
    }
}

// Go, using the Command Pattern, and immutability:
func (secd *Secd) Step() *Secd {
        // spew internal info if verbose
        if secd.Verbose() {
                secd.Report()
        }
        // termination and returns are handled by opcodes
        // pop and evaluate
        return secd.c.Pop().(Command).evaluate(secd)
}

for !secd.Finished() {
    secd = secd.Step()
</code>```

Once you leave the toys, and want actual performance, you should look probably into the LLVM. Whereas an SECD is close to functional programming, the LLVM is very close to the metal, and makes it easier to express C-like programs. After you get behind a bit of theory (single assignment form, phi nodes), you can follow the nice tutorial to implement the Kaleidoscope toy language, which showcases the most basic features. An interesting young language that relies on the LLVM to ensure performance is Julia – you can look at the implementation on GitHub for inspiration.

Body:
Regarding the third question:

A virtual machine is a program that executes a program. This can range from interpreters to Just In Time-compiling VMs.

To learn how to write a simple VM, you don't need much. The SECD machine is a simple model you can adapt. This is actually a mathematical model which can be used to reason about programs written in the lambda calculus. It is very easy to write your own version, and you can implement closures quite easily. However, you should start with a garbage-collected (and preferably dynamically typed) language for your own sanity (e.g. Python, Perl, Ruby, Go, or something from the ML family). The SECD has the following stacks:

Stack – where you keep intermediate values

Environment – where you keep ID-value mappings for variables

Command – where you keep instructions

Dump, sometimes spelt Kontinuation, which you need as a second stack for control flow.

How you implement instructions is up to you – I have both used Vtables and the Command pattern with great success for toy VMs.

There is another important datatype: the closure, which is just a pair of an environment, and an instruction list.

We can now define a few instructions. You can implement the theoretical instruction set or one of your own design. Important instructions I usually implement are:

Const – puts a constant argument onto the stack.

Stack manipulations like Dup, Drop and Swap.

Basic arithmetic that takes arguments from the stack.

Variable lookups (and if you are pragmatic, a set operation as well). Each map corresponds to one scope level. For string-based lookups: If you don't find the ID in the first map on the Env stack, look into the next. But often two integers are used to identify each variable. The first indicates the scope where the var was defined, the second the number of the variable defined in that scope. E.g. in { var x; HERE }, the x has coordinates 0, 0 – first variable in the outermost scope. But in { var x; { var y; var z; HERE } }, the y has coordinates 1, 0 – first variable in the 2nd scope.

Closure creation – usually has a constant argument, and combines it with a pointer to the current Env. The resulting closure is placed on the Stack.

Call – which takes a closure and a (single) argument from the stack. If you use stack marks, you can implement multiple arguments. But if you know lambda calculus, you know you don't need to.

To call the function, you save the current Environment, the Command and the current Stack on the Dump. Then you install the env from the closure as the new Env, and push a new empty environment on top of that (the current scope). Install the argument(s) in the environment. Next you install a copy of the commands from the closure as the new Command. Finally, you create a new Stack.

Return – pop a return value of the Stack. Then, restore Command, Env and Stack from the Dump. Push the return value onto the Stack.

Conditionals can be implemented by popping a boolean and two closures of the stack, then conditionally placing one closure back again. You can then Call that closure.

Many of these can be implemented as sequences of smaller ops, but the above operations should be sufficient for running Turing-complete programs. A simple program like

fun myadd(x, y) { x + y }
var a = 40
var result = myadd(a, 2)

could be translated to the ops

Closure(2, [Var(1, 0), Var(1, 1), Add, Return]), Set(0, 0),
Const(40), Set(0, 1),
Var(0, 1), Const(2), Var(0, 0), Call, Set(0, 2)

where Closure takes an argument specifying the number of arguments for that function to pop of the stack.

It is very easy to compile to these Ops from an AST representation.

The actual VM is now just a loop that pops Ops from the Command, invokes the correct implementation, and stops once the Command is empty:

# Perl, using an array for Op implementation lookup
method run {
    while (@$command) {
        $self->display_state if $debug;
        $OPCODES[pop @$command]->($self);
    }
}

// Go, using the Command Pattern, and immutability:
func (secd *Secd) Step() *Secd {
        // spew internal info if verbose
        if secd.Verbose() {
                secd.Report()
        }
        // termination and returns are handled by opcodes
        // pop and evaluate
        return secd.c.Pop().(Command).evaluate(secd)
}

for !secd.Finished() {
    secd = secd.Step()

Once you leave the toys, and want actual performance, you should look probably into the LLVM. Whereas an SECD is close to functional programming, the LLVM is very close to the metal, and makes it easier to express C-like programs. After you get behind a bit of theory (single assignment form, phi nodes), you can follow the nice tutorial to implement the Kaleidoscope toy language, which showcases the most basic features. An interesting young language that relies on the LLVM to ensure performance is Julia – you can look at the implementation on GitHub for inspiration.


问:
In reality, a developer also administers DBMS and system?
I really don't know where else to ask. So here it goes.

I'm working at a very tiny company that makes ERP software and websites.

1 developer with + 10 years experience.

2 developers with + 3years experience.

3 developers with + 1 year experience.

That's it.

No team, no DBA, no system admin.

There is no one around here who has expertise in web development, so I happened to be in charge of web development. But I've only got 3 years experience ! as a developer !.

I know in a small company, you are asked to do lots of different things but is it too much,
if I have to do sysadmin, database architecture, software design and development ?
Oh plus I'm asked to do all that across different platforms.

I am currently working with JSP, ASP, MSSQL, MySQL, Oracle, Windows Server, and Linux.

In database, I do from writing queries to backup & recovery.

Server setup, system crash recovery, DB &  Server migration also.

Plush HTML, Javascript and CSS :)

Number of projects that I'm in charge of : 5

I'm not an expert at all of them !

I have to search the Internet, read tutorials and ask questions in StackOverflow to get all that done !

So I ask you, is this normal ?

Is this a normal practice ?

Will I face the same situation whichever small company I go ?

I'm working in South Korea.
 How is it in your country ?

P.S
Thank you all for your opinion. I was going to upvote all of you because all of you helped me see it in a different way, but apparently you need 15 reputation to upvote :(

答:
From experience I can tell that live as a software developer varies widely based on the size of the company you're working in.

Smaller shops tend to require more multi-tasking and taking on multiple roles, while large companies usually have very strictly described role for each person.

One extreme being a one-man-show, where you (obviously) have to do all the work, whether it fits into your strong areas or not.

The other is the big, multi-national company with several locations in your city alone: here you tend to have a precise position description which tells you exactly what you're working on.

Similarly, I assume, it also varies based on your exact area of business and geographical/cultural location.


答:
I think it helps to think that Registers are not memory and should not be thought of as such.

Think more like OO - Register is a class, not derived from Memory and Memory is a class not derived from register, but the Register class has  methods (Machine Op Codes) to convert its data to and from Memory. Memory on the other hand knows nothing about Registers and cannot invoke actions on them. As a result, all CPU operations are performed by registers, which often access memory.

It is not uncommon to see write only registers - hardly an attribute of memory. Its also possible for a register value to change without writing to it - again, not the behavior you expect of memory.

Title: What are CPU registers?

Body:
This question has been bothering me for some time now and today I figured I would Google it. I've read some stuff about it and it seemed very similar to what I've always known as processor cache.

Is there a difference between the two or am I right when I think they are the same?
Is a register actually required to be inside a CPU for it to work?

According to Wikipedia a register is a place in the CPU where memory can be quickly accessed and modified before being sent back to the RAM. Did I understand this wrong or are the cache and register actually the same?