问:
Looking for best practice for version numbering of dependent software components
We are trying to decide on a good way to do version numbering for software components, which are depending on each other.

Let's be more specific:

Software component A is a firmware running on an embedded device and component B is its respective driver for a normal PC (Linux/Windows machine). They are communicating with each other using a custom protocol. Since, our product is also targeted at developers, we will offer stable and unstable (experimental) versions of both components (the firmware is closed-source, while the driver is open-source). Our biggest difficulty is how to handle API changes in the communication protocol.

While we were implementing a compatibility check in the driver - it checks if the firmware version is compatible to the driver's version - we started to discuss multiple ways of version numbering.

We came up with one solution, but we also felt like reinventing the wheel. That is why I'd like to get some feedback from the programmer/software developer community, since we think this is a common problem.

So here is our solution:

We plan to follow the widely used major.minor.patch version numbering and to use even/odd minor numbers for the stable/unstable versions. If we introduce changes in the API, we will increase the minor number.

This convention will lead to the following example situation:

Current stable branch is 1.2.1 and unstable is 1.3.7. Now, a new patch for unstable changes the API, what will cause the new unstable version number to become 1.5.0. Once, the unstable branch is considered stable, let's say in 1.5.3, we will release it as 1.4.0.

I would be happy about an answer to any of the related questions below:

Can you suggest a best practice for handling the issues described above?

Do you think our "custom" convention is good?

What changes would you apply to the described convention?

答:
I would suggest to use the major.minor.patch format, using an extension "tag" for stable/unstable versions, and a definite meaning of the major and minor numbers:

```<code>major.minor.patch-stable|unstable
</code>```

where

```<code>major  only changes if there are incompatible changes in the API
minor  changes if there are changes in the API but backward compatibility is given
patch  any other changes, could be the build number or any other increasing number
-stable indicates the stable version
-unstable indicates the unstable version
</code>```

This way dependencies are easily managed and will tell each component client/user when they have to pay more attention to new versions. E.g. if component A (1.1.0-stable) depends on B (5.4.534-stable) and a new version of B is due (6.1.0-unstable) one is immediately aware that A will have to be changed, possibly substantially.

Body:
I would suggest to use the major.minor.patch format, using an extension "tag" for stable/unstable versions, and a definite meaning of the major and minor numbers:

major.minor.patch-stable|unstable

where

major  only changes if there are incompatible changes in the API
minor  changes if there are changes in the API but backward compatibility is given
patch  any other changes, could be the build number or any other increasing number
-stable indicates the stable version
-unstable indicates the unstable version

This way dependencies are easily managed and will tell each component client/user when they have to pay more attention to new versions. E.g. if component A (1.1.0-stable) depends on B (5.4.534-stable) and a new version of B is due (6.1.0-unstable) one is immediately aware that A will have to be changed, possibly substantially.


问:
What's a nice explanation for pointers?
In your own studies (on your own, or for a class) did you have an "ah ha" moment when you finally, really understood pointers? Do you have an explanation you use for beginner programmers that seems particularly effective?

For example, when beginners first encounter pointers in C, they might just add &s and *s until it compiles (as I myself once did). Maybe it was a picture, or a really well motivated example, that made pointers "click" for you or your student. What was it, and what did you try before that didn't seem to work? Were any topics prerequisites (e.g. structs, or arrays)?

In other words, what was necessary to understand the meaning of &s and *, when you could use them with confidence? Learning the syntax and terminology or the use cases isn't enough, at some point the idea needs to be internalized.

Update: I really like the answers so far; please keep them coming. There are a lot of great perspectives here, but I think many are good explanations/slogans for ourselves after we've internalized the concept. I'm looking for the detailed contexts and circumstances when it dawned on you.

For example:

I only somewhat understood pointers
  syntactically in C. I heard two of my
  friends explaining pointers to another
  friend, who asked why a struct was
  passed with a pointer. The first
  friend talked about how it needed to
  be referenced and modified, but it was
  just a short comment from the other
  friend where it hit me: "It's also
  more efficient." Passing 4 bytes
  instead of 16 bytes was the final
  conceptual shift I needed.

答:
Pointer are a bit like the application shortcuts on your desktop. Delete the shortcut and the target still exists. Start up the shortcut and the target gets started.

I always explain the working of this by simple creating a txt file on my desktop and two shortcuts to the file. After copying and deleting the shortcuts you can see people understand the idea behind 'references'.

Once the group understands the basic behind the shortcuts you can start explaining pointers anyway you want. They'll probably understand it pretty easily.

ContentLicense: CC BY-SA 2.5

Title: What's a nice explanation for pointers?


问:
How to properly deal with ER and UML diagram management
When learning about these tools, I (naively) thought that mapping about the business space could be front loaded by doing it only once and refering to those diagrams for each project within a single business unit.  However, I am finding that each situation is calling for it's own set of diagrams to properly communicate what's going on.  I find that I am dealing with the same objects, but the relationships change.

My first thought to these different situations was that these were sort of disposable* diagrams as they only pertain to a very narrow scope within the business, but I quickly retracted that thought once I found myself scrambling to find the same ER diagram I disposed 3 months ago in a completely different situation.  So now I am getting a sence that they are not disposable and should be kept, but I want to avoid just a stack of seemingly contradicting UML and ER diagrams so that someone behind me can make sense of it all.  Any suggestions?

答:
An approach that works well is to seperate model content (the objects), and the different views (diagrams). This has worked for me:

Create a package for each group of objects or problem domain (e.g. Customers, Products, Finance ...)

Create a package for each purpose where you will draw a diagram (e.g. ProductManagementView)

Add the objects to the diagram, including all relationships.

If there are view-specific attributes and relationships that you want to capture seperately, create subpackages and use UML's hierarchy/association/dependency constructs to create specific-objects.

E.g. your model may look like this:

```<code> Model
   +- Customer <<package>>
        +- Customer <<entity>>
        +- Address <<entity>>
        +- CustomerService <<package>>
           +- CustomerService <<entity>> -is a-> Customer (+ supportContract attribute)
           +- SupportContract <<entity>>
   +- Product <<package>>
        +- Product <<entity>>
        +- ProductGroup <<entity>>
   +- ProductManagementView
        +- ProductManagementDiagram <<diagram>>
   +- CustomerServiceView
        +- CustomerServiceDiagram <<diagram>>
</code>```

ContentLicense: CC BY-SA 3.0

Body:
An approach that works well is to seperate model content (the objects), and the different views (diagrams). This has worked for me:

Create a package for each group of objects or problem domain (e.g. Customers, Products, Finance ...)

Create a package for each purpose where you will draw a diagram (e.g. ProductManagementView)

Add the objects to the diagram, including all relationships.

If there are view-specific attributes and relationships that you want to capture seperately, create subpackages and use UML's hierarchy/association/dependency constructs to create specific-objects.

E.g. your model may look like this:

 Model
   +- Customer <<package>>
        +- Customer <<entity>>
        +- Address <<entity>>
        +- CustomerService <<package>>
           +- CustomerService <<entity>> -is a-> Customer (+ supportContract attribute)
           +- SupportContract <<entity>>
   +- Product <<package>>
        +- Product <<entity>>
        +- ProductGroup <<entity>>
   +- ProductManagementView
        +- ProductManagementDiagram <<diagram>>
   +- CustomerServiceView
        +- CustomerServiceDiagram <<diagram>>


问:
Desktop framework with rich HTML/CSS interface and strange 'desktop native language support'
I'm not sure if what I'm after even exists or if it doe's im looking for the wrong thing.

I'm after a framework/application/SDK that allows me to build a desktop application with a HTML/CSS/JavaScript based interface yet still allow for more complex OS interaction with a programming language such as Python (im also familiar with Ruby but as this is a hobby project I don't mind looking into other languages if needed). By complex OS interaction I mean more than simply saving files to the HDD, being able to use pythons libraries would be a big bonus.

The closet thing I can find so far is tideSDK http://www.tidesdk.org but it doesn't seem to offer much past its own API for OS interaction.

答:
All you need to do is install and run a local web-server.

Than all your server side code is also local!


答:
Windows 8 (Metro-style) apps would be an option, as you can build your UI in HTML and CSS, and still use Javascript to access all native APIs. You would be limited to the WinRT APIs though. You could also use "real" programming languges in the same project, (C++, C#).

In short, you can build sorta desktop apps for Windows 8 using only the web technologies that you know, without having to dive into a so-called "real" language.

Title: Desktop framework with rich HTML/CSS interface and strange 'desktop native language support'

Body:
I'm not sure if what I'm after even exists or if it doe's im looking for the wrong thing.

I'm after a framework/application/SDK that allows me to build a desktop application with a HTML/CSS/JavaScript based interface yet still allow for more complex OS interaction with a programming language such as Python (im also familiar with Ruby but as this is a hobby project I don't mind looking into other languages if needed). By complex OS interaction I mean more than simply saving files to the HDD, being able to use pythons libraries would be a big bonus.

The closet thing I can find so far is tideSDK http://www.tidesdk.org but it doesn't seem to offer much past its own API for OS interaction.


答:
One of the solutions would be to implement your own web server installed on client machine (that will allow you for more complex OS interaction) and have entire communication via web browser (that will allow you to build a desktop application with a HTML/CSS/JavaScript based interfaces)

There are several things you need to consider e.g.

If you are trying to write that application for multiple operation systems (Linux, Windows) then user interface (based on HTML/CSS/JavaScript) can be the same; server part will change.

If you write server in one technology (Python, Jave etc.) you will also have to install appropriate language/SDK on a client machine. Some client may have different version of the language/SDK already installed on their machine so you would have to deal with that too (that would make instillation procedure a bit more complex).

Personally I think it might be a bit more challenging project than creating standard desktop application.


问:
What is the lifecycle for loading a Linux Desktop Environment?
I'm looking into delving into a bit of custom OS work (and yes I understand that doing any development at the DE level or lower on an OS is extremely complex and not a light thing to undertake, curiosity is driving this though), I'm in the research phase right now, digging around and learning by example from the source code for projects like GNOME, KDE and XFCE.

I can't seem to find a really good resource, or resources that describes how a "desktop environment" is initialized, instantiated and drawn to the screen of the user (i.e. it's lifecycle). I know that Xorg/X11 sits in there somewhere, acting as server and the users screen is the client, and your desktop sits on top of this client. A lot of resources just start talking about rearranging combinations of already developed window managers, apps and such in order to customize your desktop experience, but what I'm thinking is what If I wanted a stripped down OS that only consisted of a screen with three buttons that performed some actions and that was it? I don't need window management, applications, or other GUI items, just the ability to draw a desktop and three buttons... (hypothetical)

My problem is at the distro level, how does a DE get registered as an available desktop environment, how is it strapped into the distros boot up, what happens after the login, what's run, what is the topography of a DE? By example, in Ubuntu you can have KDE, XFCE and GNOME installed on one distro and switch between them by logging out, changing the active DE and logging back in so how does the DE make the OS aware of its existence in the first place?

I only really need high level here really, I want to do something fairly simple in that I want to make a DE available in a distro like Ubuntu Desktop (not openly, I mean just for myself) and initialize to an empty desktop (no taskbar, apps, window manager, etc...; just the most base state possible) in order to understand what's required to get a DE running.

I don't need code specific answers (where's the challenge in that right?) but pointers to good resources on how this process works. I'll take a well formed textual answer over a chunk of code as I'm looking to understand how it all works, the path taken to get to a DE and not implementation specifics.

The outcome of this will not technically be published (code-wise) but I'm looking at doing some blog posts that describe the process of learning all of this and writing the DE layer in order to get a "Raw" desktop up and running in a pre-existing/established OS like Ubuntu, Mint, Gentoo or another distro.

答:
Well, I never actually did what you want to do, but I have some ideas you may consider.

If I were to try what you are doing I would look for a very basic, ultra-minimalistic DE, so that there is little noise and maybe I can build on it.

See an extensive list here: http://xwinman.org/others.php

About how things are starting up. Well, you explained it in big. I would add the following details, general stuff - not Ubuntu specific.

On my Linux, I use Sabayon, but probably on other distros too, there should be a service responsible to initializing X.org and maybe offering the graphical login screen. Look for things like /etc/init.d/xdm , or kdm, gdm, etc. Where "dm" is usually stands for "Display Manager".

After login, "/etc/X11/xinit/xinitrc" is involved in the action. I'm not sure why. In this, or in the user's "~/.xinitrc" a line will specify the DE you want to use. Here are some examples from my .xinitrc file:

```<code>#exec /usr/bin/enlightenment_start
exec /usr/bin/startkde
</code>```

The first line would start E17 DE, de second one, currently active, starts KDE.

Additionally, as @sepp2k pointed out, "X has the concept of a root window that you can draw to like to any other X11 window. This window exists automatically and doesn't have to be created (the X11 API (as well as higher-level APIs like GDK) has a method to get a reference to the root window). That's how you can draw stuff on the desktop."

Finally, X.org provides a "handle to the DisplayContext" and you can add a  "window on top of the display and draws some lines to it." as @jduren discovered later.

Body:
Well, I never actually did what you want to do, but I have some ideas you may consider.

If I were to try what you are doing I would look for a very basic, ultra-minimalistic DE, so that there is little noise and maybe I can build on it.

See an extensive list here: http://xwinman.org/others.php

About how things are starting up. Well, you explained it in big. I would add the following details, general stuff - not Ubuntu specific.

On my Linux, I use Sabayon, but probably on other distros too, there should be a service responsible to initializing X.org and maybe offering the graphical login screen. Look for things like /etc/init.d/xdm , or kdm, gdm, etc. Where "dm" is usually stands for "Display Manager".

After login, "/etc/X11/xinit/xinitrc" is involved in the action. I'm not sure why. In this, or in the user's "~/.xinitrc" a line will specify the DE you want to use. Here are some examples from my .xinitrc file:

#exec /usr/bin/enlightenment_start
exec /usr/bin/startkde

The first line would start E17 DE, de second one, currently active, starts KDE.

Additionally, as @sepp2k pointed out, "X has the concept of a root window that you can draw to like to any other X11 window. This window exists automatically and doesn't have to be created (the X11 API (as well as higher-level APIs like GDK) has a method to get a reference to the root window). That's how you can draw stuff on the desktop."

Finally, X.org provides a "handle to the DisplayContext" and you can add a  "window on top of the display and draws some lines to it." as @jduren discovered later.


问:
Mary Poppendieck's Books on Lean Software Development: Which One Can You Recommend?
Has anyone read all three of Mary Poppendieck's books on Lean Software Development?  She and her husband Tom wrote:

in 2003: Lean Software Development

in 2006: Implementing Lean Software Development

in 2009: Leading Lean Software Development

Mary and Tom Poppendieck are highly regarded lean experts, so I should have probably read one of their books, but I haven't read any of them.

Which one should I start with?

答:
I've read the first two, and thought the second was better than the first, mostly just because the authors expanded on their ideas quite a bit. I thought the first book was interesting, but I actually really enjoyed reading the second and found it quite inspiring.

Unfortunately, it's been a while since I read them, so I don't remember anything much more specific than that as to whether there's anything covered in the first that's not in the second. But I do remember my general impression being that the second expanded on the first without relying on it. (I read the second one before the first.)

Also unfortunately, I haven't yet made time to read the third, so I can't say anything about it.


问:
How to refer to specific areas of code in documentation?
I'm about to leave a project, and before I go my boss has asked for me to document code (I've not documented very well).  It's not a big deal, the project is not terribly complex.  But I'm finding places in my documentation where I would like to say, "Notice on line XYZ that such-and-such happens."

In this case, it doesn't make sense to refer to a specific line number, since adding or deleting a single line of code would immediately outdate the documentation.  Is there some best-practice for referring to a specific line of code without referring to it by line number?

I've considered littering the code with comments like:

```<code>/* linetag 38FECD4F */
</code>```

Where "38FECD4F" is some unique tag for that specific line.  Then I can put in the documentation, "On the line tagged '38FECD4F', notice that such-and-such happens."

Any other ideas?  I feel like it's generally better to document code units as a whole, rather than specific portions of them, but in the case of this particular project there are LONG swaths of procedural code, which have never been refactored into smaller units.

答:
It depend a lot of how the code was written, and I understand that it may induce a bunch of refactoring that you are not here to do.

But... if you need to refer to a specific line of code as a whole unit, wouldn't it mean that its some code that represent an abstract operation, and thus could be refactored in its own method/function? Once its in a method, its pretty easy, just refer to namespace.class.method Of course that mean having methods that are very small, about 5-10 lines long or even less. With Doxygen, you can put the documentation on top of the method, and it would always stay in sync with the name of the method/class/namespace.


问:
What is the reason behind methods with return values and methods with void?
I want to uderstand why there is a method in C# that could reurn a value, for example:

```<code>public int Accelerate()
{
   Speed++;
   return Speed;
}
</code>```

and a method that does not reurn a value (void)?

What is the difference in the following example of the above one:

```<code>public void Accelerate()
{
  Speed++;
  Console.WriteLine(Speed);
}
</code>```

I see that last one will save us a time rather than defining a variable to hold this field in when creating a new object! I'm beginner, so could anyone explain?

答:
From a real basic programming perspective, in C# if you need a method to get, derive, produce, instantiate, or otherwise communicate something back to the caller you use a function with the appropriate return type.

If you need a method to just do something and you don't need anything from it, use a void.

Too Long; Did Not Read Info:

Functions return control to the caller upon completion along with a value or reference to some kind of product; a void is a special case function that has no corresponding product...it is kind of the type equivalent of null.

Some languages specifically differentiate between functions (methods that return a value) and subroutines (methods that do not return a value). C based languages instead use "void" to differentiate between them.

In C# specifically, void is internally mapped to a struct with some strange compiler enforced behavior; you can't really use this type for anything useful but if you are doing reflection you might notice it and think "hrm?":

http://msdn.microsoft.com/en-us/library/system.void.aspx

Eric Lippert, until recently a principal developer on the C# compiler team, had some interesting things to say about void a few years ago; it might provide some insight for you:

Link

Note that you could simulate functions using voids, via out or ref parameter(s) but this would be needlessly verbose and I daresay inelegant; functions are much cleaner and easier to read and write.

Personally, when I use a void it is usually for a private or protected method or to follow a design pattern. I tend to favor functions for public methods; even if only to return true / false to allow a feedback loop for the caller(s) or to assist in unit testing.

ContentLicense: CC BY-SA 4.0


问:
I've been told HTML is a markup language, C++ is a programming language, what could make that difference?
My programming friends are always telling me that HTML is a markup language and C++ is a programming language. When I ask them what's the difference, they never give me a reasonable answer.

What could make one call C++ a programming language, and HTML not?

答:
The phrase "I know it when I see it" is a colloquial expression by
  which a speaker attempts to categorize an observable fact or event,
  although the category is subjective or lacks clearly defined
  parameters. The phrase was famously used by United States Supreme
  Court Justice Potter Stewart to describe his threshold test for
  obscenity in Jacobellis v. Ohio (1964).

-- "I know it when I see it" Wikipedia article

Like obscenity, I think we all know a programming language when we see one. Clearly the OP does, since you've already judged C++ to be a programming language, and HTML not to be one.

So what exactly is the goal of pursuing a formal definition? Yannis has already given a great rundown of why the most popular definition, Turing completeness, is flawed: it leads to categorization which defy the "I know it when I see it" test.

I put it to you that any definition you can come up with will lead to some languages which we all feel are not "programming" languages will be categorized as being so; or to some languages which we all feel are "programming" languages will be categorized as not being so.

Why not just go with your gut? I use a simple heuristic: a programming language is a language whose primary purpose, in my opinion and according to my observations, is to write programs. Not to mark up content. Not to transform XML. To write general purpose programs. I'd rather just know it when I see it than try to nail down a formal definition, and I don't see any genuine value that can come from attempting such a definition.


问:
How do you explain refactoring to a non-technical person?
How do you go about explaining refactoring (and technical debt) to a non-technical person (typically a PHB or customer)? ("What, it's going to cost me a month of your work with no visible difference?!")

UPDATE Thanks for all the answers so far, I think this list will provide several useful analogies to which we can point the appropriate people (though editing out references to PHBs may be wise!)

答:
Re-factoring is the same as cleaning up something and giving stuff a new place to 'stay'

Easy simple and something that can take a lot of times. Sometimes I even add that person X left a huge mess of things and I have to clean it up.


答:
I've lately been experimenting with Node-Webkit and plan on using it in a particular upcoming project where I'm porting a PhoneGap app to the desktop.  Node-webkit is still a little rough around the edges, but it has tons of potential and seems to be progressing fast.

Node-webkit is essentially an application that offers an embedded build of chromium that uses Node as its scripting engine.  This allows a combination of using HTML/JS to create a desktop app, while having access to node modules.  One nice touch is you can build standalone (if large) apps by simply concatinating a zip file of your html/JS content to the end of the nw executable.  Another nice perk is its available for Windows/Mac/Linux.


问:
GPLv3 Project with BSD Library
I am working in a Python project that I want to release under the GPL3 license. This project has one file that uses the BSD lxml library .

I really need to put reference of the BSD license in the file where I use the library? Or just the GPLv3 of my project covers the licenses restrictions.

Library:
http://lxml.de
Licenses:
https://github.com/lxml/lxml/blob/master/doc/licenses/BSD.txt
http://www.gnu.org/licenses/gpl.txt

[Edit]

I think we're misunderstanding

I will not put the source code of the lxml library on my project. I will put the reference for functions of the library. If someone wants use my project, he needs to download separately the lxml library.

```<code>import lxml

# do stuff with lxml...
# do stuff
# my code
</code>```

Only is necessary put the library license if I distribute the lxml source code with my project. Am I right?

答:
No, you probably don't need to put the BSD reference into the library, but you should.

When you re-release the BSD component within your GPLv3 package you are re-licensing the BSD component as well.  At that point, the only license text that's required is the GPLv3 one.

The GPLv3 license contains the same or similar clauses as the BSD license.  In particular, section 4 requires maintaining the copyright notices.  Sections 15, 16, and 17 handle the disclaimer of warranty.  And the section "How to apply these terms" goes into the details on propagating the conditions of the license.

However, as a courtesy to the original authors on the BSD licensed component, you should provide full attribution and a copy of the BSD license.  Effectively you're saying "If you want to use this component from my distribution, then it's under GPLv3.  However, you can access this component from its source under a BSD license."

Some supplementing points.

FSF's definition of a compatible license

```
It means that the other license and the GNU GPL are compatible; you can combine code
released under the other license with code released under the GNU GPL in one larger
program.

All GNU GPL versions permit such combinations privately; they also permit distribution
of such combinations provided the combination is released under the same GNU GPL
version. The other license is compatible with the GPL if it permits this too.
```

The very last sentence (The other license is compatible...) in that quoted section along with the preceding combination clause (they also permit distribution...) is your permission (and requirement) to distribute the combination of your project + lxml as GPLv3.

The BSD license (without the advertising clause) is on FSF's list of compatible licenses.  Specifically here.  This is the same license the lxml team is using.

Whether you provide a copy of lxml source is kind of a moot point.

Your program won't work without their program, so you can't really get around dragging their program into yours from a licensing point of view as far as the GPL is concerned.  It's a "known" circumvention trick that isn't allowed.  Fortunately, the licenses are compatible.  Because you are choosing to release under the GPLv3 then you're re-licensing the lxml project as expressed / instantiated in your project.  Essentially, you've forked the license on lxml but only for within your project.

The lxml team can continue to update and release their code under modified BSD, but the instantiation you use and any modifications you make to it within your project are considered as GPLv3.  Note that you could still contribute directly to lxml and then they can release your contribution as BSD.  But you can't do that through your GPL project.

Title: GPLv3 Project with BSD Library

Body:
No, you probably don't need to put the BSD reference into the library, but you should.

When you re-release the BSD component within your GPLv3 package you are re-licensing the BSD component as well.  At that point, the only license text that's required is the GPLv3 one.

The GPLv3 license contains the same or similar clauses as the BSD license.  In particular, section 4 requires maintaining the copyright notices.  Sections 15, 16, and 17 handle the disclaimer of warranty.  And the section "How to apply these terms" goes into the details on propagating the conditions of the license.

However, as a courtesy to the original authors on the BSD licensed component, you should provide full attribution and a copy of the BSD license.  Effectively you're saying "If you want to use this component from my distribution, then it's under GPLv3.  However, you can access this component from its source under a BSD license."

Some supplementing points.

FSF's definition of a compatible license

It means that the other license and the GNU GPL are compatible; you can combine code
released under the other license with code released under the GNU GPL in one larger
program.

All GNU GPL versions permit such combinations privately; they also permit distribution
of such combinations provided the combination is released under the same GNU GPL
version. The other license is compatible with the GPL if it permits this too.

The very last sentence (The other license is compatible...) in that quoted section along with the preceding combination clause (they also permit distribution...) is your permission (and requirement) to distribute the combination of your project + lxml as GPLv3.

The BSD license (without the advertising clause) is on FSF's list of compatible licenses.  Specifically here.  This is the same license the lxml team is using.

Whether you provide a copy of lxml source is kind of a moot point.

Your program won't work without their program, so you can't really get around dragging their program into yours from a licensing point of view as far as the GPL is concerned.  It's a "known" circumvention trick that isn't allowed.  Fortunately, the licenses are compatible.  Because you are choosing to release under the GPLv3 then you're re-licensing the lxml project as expressed / instantiated in your project.  Essentially, you've forked the license on lxml but only for within your project.

The lxml team can continue to update and release their code under modified BSD, but the instantiation you use and any modifications you make to it within your project are considered as GPLv3.  Note that you could still contribute directly to lxml and then they can release your contribution as BSD.  But you can't do that through your GPL project.


问:
How much Code Coverage is "enough"?
We are starting a push for code coverage here at my work, and it has got me to thinking.... How much code coverage is enough?

When do you get to the point of diminishing returns on code coverage?  What is the sweet spot between good coverage and not enough?  Does it vary by the type of project your are making (ie WPF, WCF, Mobile, ASP.NET)  (These are C# classes we are writing.)

答:
"Enough" is when you can make changes to your code with confidence that you're not breaking anything.  On some projects, that might be 10%, on others, it might be 95%.  </p>

<p>It's almost never as high as 100%.  However, sometimes trying to get 100% code coverage can be a great way to remove cruft from the code base.  Don't forget that there's two ways to increase code coverage - write more tests or take out code.  If code isn't covered because it's hard to test, there's a good chance you can simplify or refactor to make it easier to test.  If it's too obscure to bother to test, there's usually a good chance that nothing else in the code is using it. </p>

Title: How much Code Coverage is "enough"?

Body:
"Enough" is when you can make changes to your code with confidence that you're not breaking anything.  On some projects, that might be 10%, on others, it might be 95%.

It's almost never as high as 100%.  However, sometimes trying to get 100% code coverage can be a great way to remove cruft from the code base.  Don't forget that there's two ways to increase code coverage - write more tests or take out code.  If code isn't covered because it's hard to test, there's a good chance you can simplify or refactor to make it easier to test.  If it's too obscure to bother to test, there's usually a good chance that nothing else in the code is using it.


问:
Defining Rank names for employees
I want to create a list of ranks for the employees in my company. We are an open source integrator that works usually with existing solutions and also building custom solutions.

We don't want to name our employees as normal senior consultant, trainee and we would like give them ranks as forums do to the users.

Does anyone have any suggestion for this?

答:
Biggest problem I see with this, is while it may be fun internally, it really creates problems when employees try to use these clever names on a resume or job profile.

It is best to use industry standard names with HR, Business Cards, Performance reviews etc.

Nothing says immature on a resume as a job title like "Code Fairy".

Something that people may not be fully aware of is that when applying for another job or getting a security clearance etc., the job titles on the application must match what HR tells the recruiter, or security consultant that is verifying this information.

Title: Defining Rank names for employees


问:
Are header files actually good?
I find header files to be useful when browsing C++ source files, because they give a "summary" of all the functions and data members in a class.  Why do so many other languages (like Ruby, Python, Java, etc.) not have a feature like this?  Is this an area where C++'s verbosity comes in handy?</p>

答:
It is not clear on, what you mean by browsing file for functions and data members. However, most IDE's do provide Tools to browse the class and see class data members.

For example: Visual Studio has Class View and Object browser that nicely provides your requested functionality. Like in the following screen-shots.

Title: Are header files actually good?


答:
I would actually say that headers files are not great because they muddy the interface and implementation.  The intent with programming in general, and especially OOP is to have a defined interface and hide the implementation details, but a C++ header file shows you both the methods, inheritance, and the public members (interface) as well as private methods and private members (some part of the implementation).  Not to mention that in some cases you end up inlining code or constructors in the header file, and some libraries include template code in the headers, which really mixes implementation with interface.

The original intent, I believe, was to make it possible for code to use other libraries, objects, etc without having to import the entire contents of the script.  All you need is the header to compile and link.  It saves time and cycles that way.  In that instance, it's a decent idea, but it's just one way of solving these issues.

As for browsing the structure of the program, most IDEs provide that ability, and there are a lot of tools that will kick out the interfaces, do code analysis, decompilation, etc so you can see what's happening under the covers.

As for why other languages don't implement the same feature?  Well, because other languages come from other people, and those designers/creators have a different vision of how things should work.

The best answer is to stick with what does the job you need to do, and makes you happy.

Title: Are header files actually good?

Body: I find header files to be useful when browsing C++ source files, because they give a "summary" of all the functions and data members in a class.  Why do so many other languages (like Ruby, Python, Java, etc.) not have a feature like this?  Is this an area where C++'s verbosity comes in handy?</p>


问:
Why would you use MVC over Web Forms?
Recently an architect described our company as offering a Rolls-Royce solution (MVC) when all he needed was a Toyota (Web Forms).

I'm curious to find out what you think about web forms vs MVC as an architectural choice.

答:
Old question but it deserves a more detailed answer just in case anybody else out there is still actually having a dilemma over it.

Ultimately, webforms is a thin-client solution by which it's meant that you press a bunch of pretty buttons and the front end (client) stuff is built for you. If you have people who know how to crank it out in webforms and there are absolutely no maintainability/modifiability concerns and the site is completely short term and disposable, there is nothing at all wrong with this approach. It is possible to learn how to do your own stuff but in this case it would require knowing both the web stuff webforms tries to protect .NET app developers from and all the webforms stuff that makes most client-side web devs want to murder the Microsoft engineers responsible.

In the 99.5% of all other use-case scenarios, we've stopped trying to hide the web from app developers because really, if you want to write web apps you're much better off actually learning how the web works. The irony of thick vs thin client solutions is that inevitably the thin-client approach inevitably bloats the crap out of your front end and is anything but performant. More importantly, these solutions have always made things inflexible as all Hell for people who actually know what they're doing and don't want to be constrained by the framework in effect.

There is nothing quite so pointless as taking somebody who knows everything about CSS, JavaScript, HTML, XHR and making them completely useless by roadblocking them every step of the way with a framework that...

Clears out all 'unneeded' script tags in the head tags to keep you from screwing up on script dependencies. (better to let a 'script manager' handle that for you) Granted, nobody puts 'em up there nowadays if they know what they're doing but that's just messed up.

Insists you wrap all of the HTML in one ginormous form tag. HTML doesn't allow forms inside forms so you do forms the webforms way or no way at all.

Creates like an 18-step "life-cycle" for what really should boil down to reacting to UI events by interacting with the browser to send messages to the server and then react when the server responds. Abstracting that process with a big giant pile of garbage never needed to happen (and to be fair, MS isn't the only jackass who's tried to do this).

Actually does everything it possibly can to get in the way of using non-webforms solutions to problems. Example: When I was a more junior client side dev I spent an entire day finding a way to make a submit button at the top of the page trigger a submit button at the bottom of a page (I assume due to that one-big-giant-form thing). Normally this would take 5 minutes but after quite a few hours reverse engineering the webforms JavaScript responsible, I discovered that they were among other things setting a property I didn't even know about at the time that tells you what the last form element to have focus was so that when a submit button was clicked, only the official Microsoft Submit(tm) button would work in regards to the activation of an official Microsoft Submit(tm) handler.

So no, Rolls-Royce vs Toyota, is completely unreasonable. I would say more, a perfectly reasonable Hyundai that you pay way too much for vs. a Microsoft engineered Pinto with an onboard system that automatically makes sharp 90 degree turns when it discovers you bought gas or oil from somebody other than Microsoft and it's detected a convenient wall to slam into. An ideal car for the suicidally-brand-loyal driver who knows nothing about the web and wants to swear life-long loyalty to Microsoft.

All .NET MVC really is, is simple and reasonable, and it doesn't reinvent its own layer to slap on top of the web. It just works with what's there to help knock out some boilerplate for you. There's better/cheaper/free-er frameworks available but if you've already locked yourself into the .NET thing, you could do much worse.

But seriously, stay the !@#$ away from webforms. It's almost dead now. Let it go. Tell your clients you'll do it for three times the money if they also promise you an exclusive and lucrative by-the-hour support contract for when they actually want to do something new or different or when crap starts breaking because not even MS could be bothered to continue adding to that behemoth of a 10,000 line ajax.js file they pull out of their DLL ass where you can't touch it.

Title: Why would you use MVC over Web Forms?


答:
Original purpose of header files was to allow single-pass compilation and modularity in C. By declaring the methods before they are used, it allowed for only single compilation pass. This age is long time gone thanks to our powerfull computers being able to do multi-pass compilation without any problems, and sometimes even faster than C++ compilers.

C++ being backwards compatible with C needed to keep the header files, but added lot of on top of them, which resulted in quite problematic design. More in FQA.

For modularity, header files were needed as metadata about code in modules. Eg. what methods (and in C++ classes) are available in what library. It was obvious to have developer write this, because compile time was expensive. Nowadays, it is no problem to have compiler generate this metadata from code itself. Java and .NET languages do this normally.

So no. Header files are not good. They were when we still had to have compiler and linker on separate floppies and compilation took 30 minutes. Nowadays, they only get in the way and are sign of bad design.

Title: Are header files actually good?


答:
While they may be useful for you as a form of documentation, the system surrounding header files is extraordinarily inefficient.

C was designed so that each compilation pass builds a single module; each source file is compiled in a separate run of the compiler. Header files, on the other hand, are injected into that compilation step for each of the source files that reference them.

This means that if your header file is included in 300 source files, then it gets parsed and compiled over and over, 300 separate times while your program is built.   The exact same thing with the exact same result, over and over. This is a huge waste of time, and is one of the primary reasons why C and C++ programs take so long to build.

All modern languages intentionally avoid this absurd little inefficiency. Instead, typically in compiled languages the necessary metadata is stored within the build output, allowing the compiled file to act as a sort of quick-lookup reference describing what the compiled file contains. All the benefits of a header file, automatically created with no additional work on your part.

Alternately in interpreted languages, every module that gets loaded stays in memory. Referencing or including or requiring some library will read and compile the associated source code, which stays resident until the program ends. If you also require it elsewhere, no additional work as it's already been loaded.

In either case, you can "browse" the data created by this step using the language's tools. Typically the IDE will have a class browser of some sort. And if the language has a REPL, it can also often be used to generate a documentation summary of any loaded objects.

Title: Are header files actually good?


答:
Assigning creative professionals into an official hierarchy is a great way to increase animosity and lower productivity and satisfaction.

Instead, use ranks that recognize the strengths of a given individual while at the same time intentionally preventing any sort of ordering or comparison.

For example, someone with a reputation for being able to make programs run faster might be "Chief Code Accelerator", while someone who is your go-to-guy for getting difficult operations to work together might be your "Coordinator in Chief".

Make everyone feel like the king of their own little mountain, and they'll do what they can to live up to the reputation.

Title: Defining Rank names for employees

Body:
I want to create a list of ranks for the employees in my company. We are an open source integrator that works usually with existing solutions and also building custom solutions.

We don't want to name our employees as normal senior consultant, trainee and we would like give them ranks as forums do to the users.

Does anyone have any suggestion for this?


答:
You have a problem. To license your project as a GPLv3 license, requires the license to apply to all parts of 'the work'. (see section 5.c in the GPLv3 license for the exact wording.), and you are not entitled to relicense the lxml library under the GPLv3 terms.

To solve this, you can either write a "from first principles" implementation of xml parsing in python that you are then entitled to license as GPLv3, or approach the authors of lxml and ask if they are prepared to license you a version of lxml under the GPLv3.

Title: GPLv3 Project with BSD Library

Body:
I am working in a Python project that I want to release under the GPL3 license. This project has one file that uses the BSD lxml library .

I really need to put reference of the BSD license in the file where I use the library? Or just the GPLv3 of my project covers the licenses restrictions.

Library:
http://lxml.de
Licenses:
https://github.com/lxml/lxml/blob/master/doc/licenses/BSD.txt
http://www.gnu.org/licenses/gpl.txt

[Edit]

I think we're misunderstanding

I will not put the source code of the lxml library on my project. I will put the reference for functions of the library. If someone wants use my project, he needs to download separately the lxml library.

```<code>import lxml

# do stuff with lxml...
# do stuff
# my code
</code>```

Only is necessary put the library license if I distribute the lxml source code with my project. Am I right?


问:
Software licensing: free [as in gratis] and copyleft
I've been reading about software licensing as I feel that I'm at a stage now, where I should probably have some sort of a license associated with my code.

What I am looking for is a copyleft (weak or strong) license that basically is very liberal. So I'd like the license to allow anybody to do anything with the code/program with the exception that nobody can ever make money from the code. I don't want anybody to be able to get my code and sell it, or to get my code and sell it or get my code, modify it in any way and sell it. I don't want anybody to be able to make money from any code I write. Aside from that, I don't care how it is used as long as the original author of the code (in this case, me) is associated with the code that I wrote.

I've looked at the GPL license, the MIT license and a few others and I can't find what I want. Does anybody have any suggestions?

If it matters, the license will be associated with C/C++, assembler and Ruby programs.

答:
The GPL is probably the closest to your requirements of the standard licenses.  Whilst it does allow someone to sell copies of your work, the commercial basis of such a business is rather limited as their customers can get the same code for free on the internet. It also severly restricts the ability of someone to use your code in a commercial product - and even if they did, it would be part of a much larger product, and your work would be a minor part of the commercial deal.

If this is unacceptable to you, then you would need to create your own license.

I do wonder what you are trying to achieve though?


答:
Basically @Gary Rowe introduced the right model. Memory as a set of boxes with addresses (numbers) on them. Each box stores a value (number).

The idea of a pointer is to interpret the value in one box as the address of another box. This value is used to refer to a specific box, which is why it is called a reference. Thus dereferencing is the process of opening the box that is refered to.

if v is a variable (box), then the statement

v means value of v, i.e. give me what is in the box

*v means dereference the value of v, i.e. give me what is in the box refered to by the value of v

&v means reference v, i.e. give me the address on box

I think it doesn't server the purpose of introducing pointers as something completely different. It was a concept hard to grasp for me when I was a kid. It always seemed like some dark magic I never truly understood, that needed a lot of special characters. The first time I did understand was when I wrote a small game using double indirection in a language that doesn't have pointer arithmetics. That enlightened me.

Pointers are a matter of interpretation. I think explaining that makes things a lot easier. And pointer arithmetics are extremely simple and intuitive operations if shown a simple example with a memory of 10 variables.

Title: What's a nice explanation for pointers?

Body:
In your own studies (on your own, or for a class) did you have an "ah ha" moment when you finally, really understood pointers? Do you have an explanation you use for beginner programmers that seems particularly effective?

For example, when beginners first encounter pointers in C, they might just add &s and *s until it compiles (as I myself once did). Maybe it was a picture, or a really well motivated example, that made pointers "click" for you or your student. What was it, and what did you try before that didn't seem to work? Were any topics prerequisites (e.g. structs, or arrays)?

In other words, what was necessary to understand the meaning of &s and *, when you could use them with confidence? Learning the syntax and terminology or the use cases isn't enough, at some point the idea needs to be internalized.

Update: I really like the answers so far; please keep them coming. There are a lot of great perspectives here, but I think many are good explanations/slogans for ourselves after we've internalized the concept. I'm looking for the detailed contexts and circumstances when it dawned on you.

For example:

I only somewhat understood pointers
  syntactically in C. I heard two of my
  friends explaining pointers to another
  friend, who asked why a struct was
  passed with a pointer. The first
  friend talked about how it needed to
  be referenced and modified, but it was
  just a short comment from the other
  friend where it hit me: "It's also
  more efficient." Passing 4 bytes
  instead of 16 bytes was the final
  conceptual shift I needed.


问:
Is a day really 24 hours long?
I asked this question on Stack Overflow and it was closed as off-topic. I'll ask it here hoping it will do better.

This might sound silly, but bear with me. I've been working a lot with intervals and dates lately. One question that bothers me: is a day really 24 hours long? I'm interested by the answer both from a theoretical and from a practical point of view.

Let's take today for example, the day started on 13 Dec 2012 00:00:00 and according to (all) date-time implementations it will end on 14 Dec 2012 00:00:00. This is correct and the difference between the two dates is a complete 24 hours.

The problem with this is that the end date is perceived as "tomorrow". Most people thinking that a day starts on 00:00:00 and ends on 23:59:59.

So the question is: is today a closed interval at the start, and opened at the end, like [start..end), with the end being very very close to 14 Dec 2012 00:00:00 (so not really a complete 24 hours)? Or is it actually closed at both ends with a full 24 hours between them?

答:
Let's take today for example, the day started on 13 Dec 2012 00:00:00 and according to (all) date-time implementations it will end on 14 Dec 2012 00:00:00

No. By convention the day starts at 00:00:00 and end at 23:59:59 (well 23:59:59.999 if you go down to milliseconds). Time is continuous, but we have to represent it by discrete values (no matter how "accurate" those values might be) and as no one time (00:00:00, for example) can exist in more than one 24 hour period we come to an agreement as to where that boundary lies.

It is therefore 24 hours long as there are 24 * 60 * 60 seconds in this interval.

There are three occasions when this isn't true:

When the clocks go forward for the start of daylight saving in which case that day is 23 hours long (one hour is lost).

When the clocks go back for the end of daylight saving in which case that day is 25 hours long (one hour is repeated).

When a leap second is added to a day to bring the time back into sync with the solar day in which case that day is 24 hours 0 minutes and 1 second long.

If it makes it easier think of the day starting at 00:00:01 and ending at 24:00:00. This is more obviously 24 hours.

Title: Is a day really 24 hours long?


答:
It is obviously open/closed interval. How else do you want to create continuous interval of all days and still be able to account for mili/microseconds?

And it is obviously 24 hour long. That single second between 23:59:59 and 00:00:00 still counts.

Title: Is a day really 24 hours long?

Body:
I asked this question on Stack Overflow and it was closed as off-topic. I'll ask it here hoping it will do better.

This might sound silly, but bear with me. I've been working a lot with intervals and dates lately. One question that bothers me: is a day really 24 hours long? I'm interested by the answer both from a theoretical and from a practical point of view.

Let's take today for example, the day started on 13 Dec 2012 00:00:00 and according to (all) date-time implementations it will end on 14 Dec 2012 00:00:00. This is correct and the difference between the two dates is a complete 24 hours.

The problem with this is that the end date is perceived as "tomorrow". Most people thinking that a day starts on 00:00:00 and ends on 23:59:59.

So the question is: is today a closed interval at the start, and opened at the end, like [start..end), with the end being very very close to 14 Dec 2012 00:00:00 (so not really a complete 24 hours)? Or is it actually closed at both ends with a full 24 hours between them?


答:
X Window overview:

a display is one or several screens, a keyboard, a pointer device (often a mouse) (1)

the display server is the program which act a mediator between the display and the program who want to use it (the clients). The server do very little as a matter of ui policy (but it handles the access right one).

clients are drawing on windows, rectangular area on the screens.

there are special windows which cover each a whole screen, the root windows of those screens.

X is a network protocol, so the clients may run on another machine than the server. Part of the protocol allows some communication between clients.

drawing window borders, changing the focus, minimizing, ... and such kind of ui policy is handled by a client called the window manager. There is very little special about the window manager excepted that it answer to events which are ignored by other clients and for which there can be only one recipient. In some situations, you may end up without a window manager active.

there are more or less standardized conventions for communicating between clients and the window manager.

desktop environment isn't a well defined term. What it usually covers is a window manager and a set of applications designed to provide a coherent use model and some more conventions so applications can interact with them and between them. Part of those conventions are also more or less standardized.

when you start an X server after having logged in in text mode, or when you use a graphical display manager to log in, there is a session script which is executed. That session script may launch just an xterm on the display, launch several programs and a window manager or starts the initialization of a whole desktop environment.  Display managers tend to allow to choose one of several session scripts.

Linux distributions do their packaging in such a way that when you install a desktop environment, it registers a session scripts for each of the display manager installed.

(1) well there may be several keyboards and mouses, but you are unable to make a difference between them

Title: What is the lifecycle for loading a Linux Desktop Environment?

Body:
I'm looking into delving into a bit of custom OS work (and yes I understand that doing any development at the DE level or lower on an OS is extremely complex and not a light thing to undertake, curiosity is driving this though), I'm in the research phase right now, digging around and learning by example from the source code for projects like GNOME, KDE and XFCE.

I can't seem to find a really good resource, or resources that describes how a "desktop environment" is initialized, instantiated and drawn to the screen of the user (i.e. it's lifecycle). I know that Xorg/X11 sits in there somewhere, acting as server and the users screen is the client, and your desktop sits on top of this client. A lot of resources just start talking about rearranging combinations of already developed window managers, apps and such in order to customize your desktop experience, but what I'm thinking is what If I wanted a stripped down OS that only consisted of a screen with three buttons that performed some actions and that was it? I don't need window management, applications, or other GUI items, just the ability to draw a desktop and three buttons... (hypothetical)

My problem is at the distro level, how does a DE get registered as an available desktop environment, how is it strapped into the distros boot up, what happens after the login, what's run, what is the topography of a DE? By example, in Ubuntu you can have KDE, XFCE and GNOME installed on one distro and switch between them by logging out, changing the active DE and logging back in so how does the DE make the OS aware of its existence in the first place?

I only really need high level here really, I want to do something fairly simple in that I want to make a DE available in a distro like Ubuntu Desktop (not openly, I mean just for myself) and initialize to an empty desktop (no taskbar, apps, window manager, etc...; just the most base state possible) in order to understand what's required to get a DE running.

I don't need code specific answers (where's the challenge in that right?) but pointers to good resources on how this process works. I'll take a well formed textual answer over a chunk of code as I'm looking to understand how it all works, the path taken to get to a DE and not implementation specifics.

The outcome of this will not technically be published (code-wise) but I'm looking at doing some blog posts that describe the process of learning all of this and writing the DE layer in order to get a "Raw" desktop up and running in a pre-existing/established OS like Ubuntu, Mint, Gentoo or another distro.


问:
Best way to store revision information for quick access to view or revert changes
What I am looking for is the most optimal solution for storing content revisions in an MSSQL database. We have an application that allows users to make changes to small HTML content blocks similar to a wiki, but we need to have tight audit control over the changes. At any point in time, the manager might want to look at previously submitted contents or revert the entire HTML block back to the previous state.

I had it setup in the past where we had a primary table that stored the HTML information (along with various other meta tags) and then an audit table that kept a copy of the entire data row everytime a change was made. What I am wondering is if this is the best way to go, or should I just keep 1 table with all the current records and the changes in it and just have a flag that lets me know which one is the current one?

答:
One table with flags would be preferable IMHO.

The alternative adds in overhead (adding old record to archive table), with little in the way of benefit. Such is the efficiency of most SQL engines, that there is usually negligible overhead in finding the current version of a record compared to searching for the only record in the table.

In certain, high-volume applications, there might possibly be a case for the alternative, but not for a wiki.


答:
What you are looking for is not really open source or free software that main stream copy left licenses are made to support. It's seems more like a rather strict proprietary license.

If you still want to stick with copyleft, I'm thinking of something like AGPL which is pretty much GPL but with the additional requirement that changes to the source needs to made available if it's used in a web based service (typically if you write server based software or similar).

People still can make money out of this. GNU/Linux is sold in enterprise versions by for instance Red Hat, even though the same thing is available for free without support. Is that OK for you?

If you need to make totally sure no one will make any money from it, in any way, please consider to write your own strict license. Probably you need to consult a lawyer to get it 100% right.

Maybe you could start out with something like Ms-RSL and loosen it a bit?

Title: Software licensing: free [as in gratis] and copyleft

Body:
I've been reading about software licensing as I feel that I'm at a stage now, where I should probably have some sort of a license associated with my code.

What I am looking for is a copyleft (weak or strong) license that basically is very liberal. So I'd like the license to allow anybody to do anything with the code/program with the exception that nobody can ever make money from the code. I don't want anybody to be able to get my code and sell it, or to get my code and sell it or get my code, modify it in any way and sell it. I don't want anybody to be able to make money from any code I write. Aside from that, I don't care how it is used as long as the original author of the code (in this case, me) is associated with the code that I wrote.

I've looked at the GPL license, the MIT license and a few others and I can't find what I want. Does anybody have any suggestions?

If it matters, the license will be associated with C/C++, assembler and Ruby programs.


答: Let's ask the License-o-mator!  Hmm, "Allow modifications of your work?", yes.  "Allow commercial uses of your work?", no.  "License Jurisdiction", probably "International".  Answer: you want the Creative CommonsAttribution-NonCommercial 3.0 Unported license (aka "CC BY-NC 3.0").


问:
flat files vs. RDBMS database, few read/writes, few changes
I have to handle data from long term (years, decades) climate monitoring stations. The data flow usually starts with raw data (voltages, etc.) plus quality check information (pressure, temperature, flow rate, etc.) generally recorded @ 1Hz. Then, the data are assigned a quality flag (human and/or program), processed (apply calibration curves) and flagged.

So, we basically end up with 2 datasets : raw and processed data. New data are typically added once a day (~500Ko/day/instrument). Simultaneous queries are not likely to ever happen.

I wanted to go for a RDBMS (we have a MySQL server) and have some experience in database design, but the IT guy keeps telling me that flat files will to the job just as well. I suspect him to try to make his life easier when it comes to backup/upgrade the MySQL.

There are not so many links between data, they don't change much, but the quality flags will change. A RDBMS is easier to compare data from different instruments on a "many days" scale, compared to daily text files.

Well, what would you advise ?

Thanks.

答:
I made an app that might help out in some situations.  It connects to a flat file and lets you run sql queries and updates on it.  It might be a solution for merging the two worlds together.  You can leave the data in the legacy format but still be able to analyze it with queries.  Of course if your legacy data is not designed in a relational manner....  Then I guess you won't be able to do any joins.  But you can pull resultsets with field expressions and order the output and drop records.  And the queries and indexes are all external files from the original flat file.  So they won't affect any legacy software using the flat file.<br>
www.McCoyOnlineStore.com - type "RDBMS" into the search box.
If this doesn't seem to work for you.. please let me know where it fell short for your needs...  BTW be careful with any "Update" statements.. they will change the information in your flat file.  </p>

OwnerDisplayName: Bob Lapique

Body:
I made an app that might help out in some situations.  It connects to a flat file and lets you run sql queries and updates on it.  It might be a solution for merging the two worlds together.  You can leave the data in the legacy format but still be able to analyze it with queries.  Of course if your legacy data is not designed in a relational manner....  Then I guess you won't be able to do any joins.  But you can pull resultsets with field expressions and order the output and drop records.  And the queries and indexes are all external files from the original flat file.  So they won't affect any legacy software using the flat file.

www.McCoyOnlineStore.com - type "RDBMS" into the search box.
If this doesn't seem to work for you.. please let me know where it fell short for your needs...  BTW be careful with any "Update" statements.. they will change the information in your flat file.


问:
What's a nice explanation for pointers?
In your own studies (on your own, or for a class) did you have an "ah ha" moment when you finally, really understood pointers? Do you have an explanation you use for beginner programmers that seems particularly effective?

For example, when beginners first encounter pointers in C, they might just add &s and *s until it compiles (as I myself once did). Maybe it was a picture, or a really well motivated example, that made pointers "click" for you or your student. What was it, and what did you try before that didn't seem to work? Were any topics prerequisites (e.g. structs, or arrays)?

In other words, what was necessary to understand the meaning of &s and *, when you could use them with confidence? Learning the syntax and terminology or the use cases isn't enough, at some point the idea needs to be internalized.

Update: I really like the answers so far; please keep them coming. There are a lot of great perspectives here, but I think many are good explanations/slogans for ourselves after we've internalized the concept. I'm looking for the detailed contexts and circumstances when it dawned on you.

For example:

I only somewhat understood pointers
  syntactically in C. I heard two of my
  friends explaining pointers to another
  friend, who asked why a struct was
  passed with a pointer. The first
  friend talked about how it needed to
  be referenced and modified, but it was
  just a short comment from the other
  friend where it hit me: "It's also
  more efficient." Passing 4 bytes
  instead of 16 bytes was the final
  conceptual shift I needed.

答: I remember a book "C puzzles" or similar, which I read purely because it was one of the few programming/computer related books available in the library, my understanding of C was rudimentary. It threw a C expresison at you, and asked to explion it, getting more and more complicated. </p>

Title: What's a nice explanation for pointers?


问:
Algorithm to find if a set can be recreated
I'm finding it hard to solve the problem and was hoping that someone could help me with the solution or at least give me a search term to use for problems like this one.

The generalized problem: I have a set of numbers (e.g. [1,2,3]) and a an array of sets (e.g. [1,4,5],[4,2,3],[6,7,8],[2],[1,3]). What I need to do is to find if I can create the first set from the others by taking 1 or 0 elements from them (e.g. taking 1 from the first, 2 from the second and 3 from the last). Order of the elements doesn't matter in any of the sets.

答:
Let's say your "big" set is called bigSet and your array of sets is called arrayOfSets.

1. Go through all the elements of all sets in arrayOfSets and remember how many times you found each number from bigSet in those sets. Let's say you'll store this info in count (which should be a dictionary if bigSet is not ordered, which it shouldn't be by definition... or you can make your bigSet ordered by copying it into an array or something).

2. If you found some number zero times (that is, if count(bigSet[i]) is 0 for some i), bigSet can't be generated from arrayOfSets.

3. Go through arrayOfSets again and each time you find some number from bigSet whose count in arrayOfSets is min{count(bigSet[1]), count(bigSet[2]),..., count(bigSet[n])}, eliminate that set from arrayOfSets and decrease the number of times each number from that array appears in arrayOfSets. If some number's count hits 0 after doing this, and if it's not the number you just found, bigSet can't be generated. "Eliminate" (delete or somehow "mark" so you know you shouldn't consider it anymore) the number you just found from bigSet and restart this step. Remember the set from which you took that number (if you want to recreate the solution afterwards)

4. If bigSet is empty (all the numbers from it have been eliminated), you can generate bigSet from arrayOfSets.

5. Repeat 3. - 4.

Example:
(I'm using 1-based indexing)

```<code>bigSet = {10,4,8,1,7}
arrayOfSets = [{10,4}, {10,8,12,7},{1,5},{9,7},{7}]
Go through arrayOfSets and get:
count(10) = 2
count(4) = 1
count(8) = 1
count(1) = 1
count(7) = 3
min(count()) = 1 so go through arrayOfSets searching for numbers from {4,8,1}.
arrayOfSets[1] contains 4, so you delete arrayOfSets[1] from arrayOfSets, delete 4 from bigSet and decrease count for 4 and 10.
After this, you have:
bigSet = {10,8,1,7}
arrayOfSets = [{SKIPME},{10,8,12,7},{1,5},{9,7},{7}]
count(10) = 1
count(8) = 1
count(1) = 1
count(7) = 3
min(count()) = 1 so go through arrayOfSets searchinig for numbers from {10,8,1}.
arrayOfSets[2] contains 8 so, following the same procedure, you get:
bigSet = {10,1,7}
arrayOfSets = [{SKIPME},{SKIPME},{1,5},{9,7},{7}]
count(10) = 0
count(1) = 1
count(7) = 3
bigSet can't be generated from arrayOfSets because count(10) = 0.
</code>```

Body:
Let's say your "big" set is called bigSet and your array of sets is called arrayOfSets.

1. Go through all the elements of all sets in arrayOfSets and remember how many times you found each number from bigSet in those sets. Let's say you'll store this info in count (which should be a dictionary if bigSet is not ordered, which it shouldn't be by definition... or you can make your bigSet ordered by copying it into an array or something).

2. If you found some number zero times (that is, if count(bigSet[i]) is 0 for some i), bigSet can't be generated from arrayOfSets.

3. Go through arrayOfSets again and each time you find some number from bigSet whose count in arrayOfSets is min{count(bigSet[1]), count(bigSet[2]),..., count(bigSet[n])}, eliminate that set from arrayOfSets and decrease the number of times each number from that array appears in arrayOfSets. If some number's count hits 0 after doing this, and if it's not the number you just found, bigSet can't be generated. "Eliminate" (delete or somehow "mark" so you know you shouldn't consider it anymore) the number you just found from bigSet and restart this step. Remember the set from which you took that number (if you want to recreate the solution afterwards)

4. If bigSet is empty (all the numbers from it have been eliminated), you can generate bigSet from arrayOfSets.

5. Repeat 3. - 4.

Example:
(I'm using 1-based indexing)

bigSet = {10,4,8,1,7}
arrayOfSets = [{10,4}, {10,8,12,7},{1,5},{9,7},{7}]
Go through arrayOfSets and get:
count(10) = 2
count(4) = 1
count(8) = 1
count(1) = 1
count(7) = 3
min(count()) = 1 so go through arrayOfSets searching for numbers from {4,8,1}.
arrayOfSets[1] contains 4, so you delete arrayOfSets[1] from arrayOfSets, delete 4 from bigSet and decrease count for 4 and 10.
After this, you have:
bigSet = {10,8,1,7}
arrayOfSets = [{SKIPME},{10,8,12,7},{1,5},{9,7},{7}]
count(10) = 1
count(8) = 1
count(1) = 1
count(7) = 3
min(count()) = 1 so go through arrayOfSets searchinig for numbers from {10,8,1}.
arrayOfSets[2] contains 8 so, following the same procedure, you get:
bigSet = {10,1,7}
arrayOfSets = [{SKIPME},{SKIPME},{1,5},{9,7},{7}]
count(10) = 0
count(1) = 1
count(7) = 3
bigSet can't be generated from arrayOfSets because count(10) = 0.


答:
I always liked header files as they provide a form of interface to the implementation, along with some extra information such as class variables, all in one easy-to-view file.

I see a lot of C# code (that doesn't need 2 files per class) written using 2 files per class - one the actual class implementation, and another with an interface in it. This design is good for mocking (essential in some systems) and helps to define the documentation of the class without having to use the IDE to view the compiled metadata. I'd go so far to say its good practice.

So C/C++ mandating an equivalent (of sorts) of an interface in header files is a good thing.

I know there are proponents of other systems that do not like them for reasons including 'its more difficult to just hack out code if you have to put things in 2 files', but my attitude is that just hacking out code is not good practice anyway, and once you start writing/designing code with a bit more thought, then you'll be defining headers/interfaces as a matter of course.

Title: Are header files actually good?


问:
Will Java still be relevant in 5 years?
Will Java have the same importance it had in the past, or it will be less relevant than nowadays?</p>

答:
Google writes a lot in Java and Google is the biggest company in the web. I think the web is the future - web application , cloud computing - and so I think Java is still relevant in the future.

And there is Android, which is the future of smart phones in my opinion. And some people say smart phones are the future of the computer - whats not my opinion :) - but whould also gave Java a big future. So go Java :D

Title: Will Java still be relevant in 5 years?


问:
Why aren't user-defined operators more common?
One feature I miss in from functional languages is the idea that operators are just functions, so adding a custom operator is often as simple as adding a function. Many procedural languages allow operator overloads, so in some sense operators are still functions (this is very true in D where the operator is passed as a string in a template parameter).

It seems that where operator overloading is allowed, it is often trivial to add additional, custom operators. I found this blog post, which argues that custom operators don't work nicely with infix notation because of precedence rules, but the author gives several solutions to this problem.

I looked around and couldn't find any procedural languages that support custom operators in the language. There are hacks (such as macros in C++), but that's hardly the same as language support.

Since this feature is pretty trivial to implement, why isn't it more common?

I understand that it can lead to some ugly code, but that hasn't stopped language designers in the past from adding useful features that can be easily abused (macros, ternary operator, unsafe pointers).

Actual use cases:

Implement missing operators (e.g. Lua doesn't have bitwise operators)

Mimic D's ~ (array concatenation)

DSLs

Use | as Unix pipe-style syntax sugar (using coroutines/generators)

I'm also interested in languages that do allow custom operators, but I'm more interested in why it has been excluded. I thought about forking a scripting language to add user-defined operators, but stopped myself when I realized that I haven't seen it anywhere, so there's probably a good reason why language designers smarter than me haven't allowed it.

答:
Given a choice between concatenating arrays with ~ or with "myArray.Concat(secondArray)", I would probably prefer the latter. Why? Because ~ is a completely meaningless character that only has its meaning - that of array concatenation - given in the specific project where it was written.

Basically, as you said, operators are no different from methods. But while methods can be given readable, comprehensible names that add to the understanding of the code flow, operators are opaque and situational.

This is why I also don't like PHP's . operator (string concatenation) or most of the operators in Haskell or OCaml, though in this case, some universally accepted standards are emerging for functional languages.


答:
One of the main reasons custom operators are discouraged is because then any operator can mean/can do anything.

For example cstream's much criticized left shift overload.

When a language allows operator overloads, there is generally an encouragement to keep the operator behavior similar to the base behavior to avoid confusion.

Also user defined operators makes the parsing much more difficult, especially when there is also custom preference rules.

Title: Why aren't user-defined operators more common?

Body:
One feature I miss in from functional languages is the idea that operators are just functions, so adding a custom operator is often as simple as adding a function. Many procedural languages allow operator overloads, so in some sense operators are still functions (this is very true in D where the operator is passed as a string in a template parameter).

It seems that where operator overloading is allowed, it is often trivial to add additional, custom operators. I found this blog post, which argues that custom operators don't work nicely with infix notation because of precedence rules, but the author gives several solutions to this problem.

I looked around and couldn't find any procedural languages that support custom operators in the language. There are hacks (such as macros in C++), but that's hardly the same as language support.

Since this feature is pretty trivial to implement, why isn't it more common?

I understand that it can lead to some ugly code, but that hasn't stopped language designers in the past from adding useful features that can be easily abused (macros, ternary operator, unsafe pointers).

Actual use cases:

Implement missing operators (e.g. Lua doesn't have bitwise operators)

Mimic D's ~ (array concatenation)

DSLs

Use | as Unix pipe-style syntax sugar (using coroutines/generators)

I'm also interested in languages that do allow custom operators, but I'm more interested in why it has been excluded. I thought about forking a scripting language to add user-defined operators, but stopped myself when I realized that I haven't seen it anywhere, so there's probably a good reason why language designers smarter than me haven't allowed it.


答:
I think you'd be surprised how often operator overloads are implemented in some form. But they're not commonly used in a lot of communities.

Why use ~ to concatenate to an array? Why not use << like Ruby does? Because the programmers you work with are probably not Ruby programmers. Or D programmers. So what do they do when they come across your code? They have to go and look up what the symbol means.

I used to work with a very good C# developer who also had a taste for functional languages. Out of the blue, he started introducing monads to C# by way of extension methods and using standard monad terminology. No one could dispute that some of his code was terser and even more readable once you knew what it meant, but it did mean that everyone had to learn monad terminology before the code made sense.

Fair enough, you think? It was only a small team. Personally, I disagree. Every new developer was destined to be confused by this terminology. Do we not have enough problems learning a new domain?

On the other hand, I will happily use the ?? operator in C# because I expect other C# developers to know what it is, but I wouldn't overload it into a language that didn't support it by default.


问:
How do I prevent unknowningly duplicating code?
I work on a rather large code base. Hundreds of classes, tons of different files, lots of functionality, takes more than 15 minutes to pull down a fresh copy, etc.

A big problem with such a large code base is that it has quite a few utility methods and such that do the same thing, or has code that doesn't use these utility methods when it could. And also the utility methods aren't just all in one class (because it'd be a huge jumbled mess).

I'm rather new to the code base, but the team lead who's been working on it for years appears to have the same problem. It leads to a lot of code and work duplication, and as such, when something breaks, it's usually broken in 4 copies of basically the same code

How can we curb this pattern? As with most large projects, not all code is documented(though some is) and not all code is... well, clean. But basically, it'd be really nice if we could work on improving the quality in this respect so that in the future we had less code duplication, and things like utility functions were easier to discover.

Also, the utility functions are usually either in some static helper class, in some non-static helper class that works on a single object, or is a static method on the class which it mainly "helps" with.

I had one experiment in adding utility functions as Extension methods(I didn't need any internals of the class, and it definitely was only required in very specific scenarios). This had the effect of preventing cluttering up the primary class and such, but it's not really anymore discoverable unless you already know about it

答:
This is a typical problem of a larger project that has been handled by many programmers, that have been contributing under sometimes a lot of peer pressure. It is very very tempting to make a copy of a class and adapt it to that specific class. However, when a problem was found in the originating class, it should also be solved in it's decedents which is often forgotten.

There is a solution for this and it is called Generics which has been introduced in Java 6. It is the equivalent of C++ called Template. Code of which the exact class is not yet known within a Generic Class. Please check for Java Generics and you will find tons and tons of documentation for it.

A good approach is to rewrite code that seems to be copied/pasted  in many places by rewriting the first one that you need to ie fix because of a certain bug. Rewrite it to use Generics and also write very rigorous testing code.

Make sure that every method of the Generic class is invoked. You can also introduce code coverage tools: generic code should be fully code coverage because it will be used in several places.

Also write testing code ie using JUnit or similar for the first designated class that is going to be used in conjunction with the Generic piece of code.

Start using the Generic code for the second (most of the times) copied version when all the preceding code works and is fully tested. You will see that there are some lines of code that are specific for that designated Class. You can call these lines of coded in a abstract protected method that needs to be implemented by the derived class that uses the Generic base class.

Yes it is a tedious job, but as you go along it will get better and better to rip out similar classes and replace it with something that is very very clean, well written and much easier to maintain.

I have had similar situation where on generic class eventually replaced something like 6 or 7 other almost identical classes that were all almost àlmost identical but have been copied and pasted by various programmers over a period of time.

And yes, I am very very much in favor of automated testing of the code. It will cost more in the beginning but it will definitely saves you a tremendous amount of time overall. And try to achieve a code coverage of overall of at least 80% and 100% for Generic code.

Hope this will helps and good luck.


答:
Let's ignore the whole "operators get abused to harm readability" argument for the moment, and focus on the language design implications.

Infix operators have more issues than simple precedence rules (though to be blunt, the link you reference trivializes the impact of that design decision). One is conflict resolution: what happens when you define a.operator+(b) and b.operator+(a)? Preferring one over the other leads to breaking the expected commutative property of that operator. Throwing an error can lead to modules that would otherwise work become broken once together. What happens when you start throwing derived types into the mix?

The fact of the matter is that operators are not just functions. Functions either stand alone or are owned by their class, which provides a clear preference on which parameter (if any) owns the polymorphic dispatch.

And that ignores the various packaging and resolution problems that arise from operators. The reason languages designers (by and large) limit infix operator definition is because it creates a pile of problems for the language while providing debatable benefit.

And frankly, because they're not trivial to implement.


问:
typical way to share database connection for open-source project, without revealing too much
I have an open source project for mydomain.com which requires connections to a database (...as is tradition). What is the standard practice for allowing others to work on the site, without giving them full access to the database's credentials?

For example: If I have a connect.php page that connects to the database. I don't want someone to be able to read that file, or simply write <?php include("http://mydomain.com/connect.php") because then they will have full access to the database. If I put the file in my .gitignore file, sure the file won't be in the repo, but it'll still be visible in the source code.

Do I just make a read-only user and give them access to that, and then put the full read-write connection file and follow the guidelines of this answer?: Making sure database connection information is secured

What is standard practice here? or what can I research to learn more about this?

答:
Why would other developers want to work on production server? They should be working on either their own machines or shared non-production machine where they can do anything.

Also, all related configuration should be in configuration files. No such configuration should be in source code.


答:
There are two diametrically opposed schools of thought in programming language design.  One is that programmers write better code with fewer restrictions, and the other is that they write better code with more restrictions.  In my opinion, the reality is that good experienced programmers flourish with fewer restrictions, but that restrictions can benefit the code quality of beginners.

User-defined operators can make for very elegant code in experienced hands, and utterly awful code by a beginner.  So whether your language includes them or not depends on your language designer's school of thought.


答:
Best practices suggest the following:

Do not commit database credentials or any other sensitive data to source control. Ever. Put those in a file (say, config.php) that is explicitly excluded from source control (through .gitignore / .hgignore / ...), and provide a placeholder file (say, config.dist.php) instead that contains only dummy credentials; then in your installation guide, tell people to copy this file over to config.php and fill in the correct credentials.

Do not give anyone access to the production server. The database is the least of your concerns: if you allow people to upload arbitrary PHP, you might as well give them shell access, and preventing a skilled hacker from escalating to root from there borders on impossible. Instead, have people run their own private installs of the application. Provide an example apache configuration, php.ini, and some scripts to set up a test database (structure and data). You should have such an install kit anyway, if only for your own peace of mind. (What if your production server crashes beyond repair? Having an install kit that is proven to work means you can reinstall at any time, instead of having to come up with an emergency solution when the room is already on fire.)

Review every single line of code that goes onto the production server, or even into the main line of development. If you are using a distributes source control system, have people work on their own clones of the main repository, and send you pull requests for any feature they want included in the main line. If you're still on centralized source control, give each contributor their own branch, and mandate that only you are to merge into trunk. Review every merge before you make it final.

Test each version before deploying it. This should go without saying, but reality suggests otherwise. Also, make sure to use release tags; it's the easiest way to make sure no extra commits sneak in between testing and deployment (i.e., you want to make sure the version you're deploying is the exact version you have tested).

For a bit of a reference frame, consider yourself wearing two hats - the code maintainer hat, and the primary user hat. As code maintainer, you guard source control and anything that goes into it; as the primary user, you install the product on a server and open it to the public. Structure the whole project in a way that would allow you to pass one of those hats to someone else at any time without impacting your work under the other. At some point, you may want to share the burden of these duties, and when that happens, it will come handy if you have to trust people with either the main repo or the production server, but not both.

Title: typical way to share database connection for open-source project, without revealing too much

Body:
I have an open source project for mydomain.com which requires connections to a database (...as is tradition). What is the standard practice for allowing others to work on the site, without giving them full access to the database's credentials?

For example: If I have a connect.php page that connects to the database. I don't want someone to be able to read that file, or simply write <?php include("http://mydomain.com/connect.php") because then they will have full access to the database. If I put the file in my .gitignore file, sure the file won't be in the repo, but it'll still be visible in the source code.

Do I just make a read-only user and give them access to that, and then put the full read-write connection file and follow the guidelines of this answer?: Making sure database connection information is secured

What is standard practice here? or what can I research to learn more about this?


问:
Describing requirements in SRS - use cases?
I do not have the access to the IEEE standard and information on the net are contradictory. Can I capture user requirements in SRS using use cases? Or I should keep use cases separate as they are more like scenarios than separate requirements?</p>

答:
Brief Summary

The answer is yes, you can use UML Use Cases to describe requirements in your SRS, however, the original SRS needs to be customized for that purpose because the standard is out of date.

IEEE 830-1998

It is important to bear in mind that the latest published version of the SRS standard IEEE 830-1998 is from 1998. The standard does not apply well to modern software engineering. Instead of following it as-is, we can use it as a basis for defining our own SRS.

One of the reasons is that in 1998, requirements were typically written as required functions. The major paradigm was procedural programming. Often, requirements were stated in a natural language. Today, we are using object-oriented programming and different techniques/tools to support it.

The best practice is, and always was, to write unambiguous requirements. For that, UML is a perfectly viable notation. The only suggestion would be to consider also textual use cases before deciding on graphical diagrams. Use cases contain much more information in text which helps to clear out possible misunderstandings.

Accessing the Standard

Without the need to buy a copy of the standard, you can read its outline available for free at wikipedia. Some software engineers have been using IEEE 830-1998 as a basis for their own custom SRS. That is how issues with its age can be addressed.

Examples of Customized SRS With Use Cases

Paper on the topic (A good enough solution to follow)

Sample Ad-hoc customized SRS #1

Sample Ad-hoc customized SRS #2

SRS Template with use cases incorporated in it


问:
Designing entities to be self-manageable
Although this is a gamedev project, the question is about general OOP practices, so I believe it goes here. Here's the problem:
(note: I will call any equivalent of real-world physical objects "entities" from now on; e.g. a rock in the game is an entity)

A specific class:

```<code>class Character
{
public/private CharacterInventory Inventory;
public/private CharacterStats Stats;
public/private CharacterEquipment Equipment;
}
</code>```

Inventory functionality is self-contained in the CharacterInventory class. Same goes for stats. My aim is to make each character in my game a self-manageable entity. What do I mean by this? To put it plainly, I want to design the base Character class so that in the end I get an object that reacts in its entirety even when the smallest change occurs, in any of its components. To make things clearer, here's an example: when an item that changes the strength of the character gets equipped, the CharacterEquipment component of Character gets updated. At the same time, the Character will call the Stats object to change the strength attribute.

I've thought about doing this using events. Character subscribes to Equipment's OnEquip event, and in its handler, tells the Stats component do do its job. I believe this is an elegant enough solution; my issue however lies somewhere else.

I've got two ways in which I can update the character's inventory. First, by making the inventory (and any other component) private and providing a public method inside of Character, that does the work of calling the appropriate update method in the inventory.
Like so:

```<code>Character chara = new Character();
chara.AddItemToInventory(SomeItem);
</code>```

The 2nd way is by making the components public and accessing them like:

```<code>Character chara = new Character();
chara.Inventory.AddItem(SomeItem);
</code>```

To me, both ways seem roughly equivalent in terms of readability. But the 2nd way seems like it's breaking the whole "self-manageable" idea. Basically, I'm invading the "private" space of the character. By going with the 2nd way, I can hook to the inventory events from some other place, but then again, this breaks the main idea even further.
However, going the 1st way, I get the impression of writing duplicated code; even though it's not! I think the impression is given to me by the fact that Character.AddItemToInventory(...) and CharacterInventory.AddItem(...) share enough naming similarities to suggest duplicated code.

To be sincere, I'd go the first way, even though it seems to me like an extra layer of code. Then again, to make the character a self-manageable object, an extra layer of security is essential.
But I'd like to hear from people more experienced than me. Are there any advantages to the 2nd way? Any severe disadvantages? I just can't get over the impression that I'm writing extra, unnecessary code.

答:
Are there any advantages to the 2nd way?

Absolutely, you're not repeating yourself. AddToInventory is just going to call Inventory.Add anyways. Worse, it is going to also know enough of the item to have to dispatch to the different things that care about it.

A better approach is to create your stats class with input as to where it can find modifiers. In the inventory, in skills you might've picked, etc. When someone asks for the character's Strength, it can aggregate the modifiers to provide a result.

Abstracting that well is near-impossible. Program design tends to be thorny with games in that regard since so many things can impact others depending on context. Focus on getting something working good-enough; your goal after all isn't making a great design - it's getting a game done.