答:
There are quite a few languages (e.g., Java, Go, D, Objective-C) that are either roughly parallel to C++, or attempts at fixing problems that the authors saw with C++.

At least IMO, however, all of them work out substantially inferior to C++ for most practical purposes.

Unfortunately, based on your apparent taste for knowing what assembly code will be produced, we can probably rule out Objective C and Java immediately.

Theoretically, I'd consider Go the most interesting of these -- it has some truly original ideas and interesting approaches to solving problems that make some kinds of code much easier. Unfortunately, current compilers don't produce very good code, and there hasn't be a lot of improvement in that regard over the last few years.

That pretty much leaves D as the only one that stands a chance. It's probably the most similar to C++ (of these), but also the least likely (IMO) to fix what you seem to see as problems.

That leaves one obvious approach: use C++, but use only the parts you want, and avoid the parts you don't like.

Title: Is there a language between C and C++?

Body:
I really like the simple and transparent nature of C: when I write C code I feel unencumbered by "leaky abstractions" and can almost always make a shrewd guess as to the assembly I'm producing. I also like the simple, familiar syntax for C.

However, C doesn't have these simple, helpful doodads that C++ offers like classes, simplified non-cstring handling, etc. I know that it's all possible to implement in C using jump tables and the like, but that's a bit wordy at times, and not very type-safe for various reasons.

I'm not a fan of the over-emphasis on objects in C++, though, and I'm gun shy of the 'new' operator and the like. C++ seems to have just a few too many hiccups to, for instance, be used as a system programming language.

Does there exist a language that sits between C and C++ on the scale of widgets and doodads?

Disclaimer: I mean this as purely a factual question. I do not intend to anger you because I don't share your view that C{,++} is good enough to do whatever I'm planning.


问:
Is there a language between C and C++?
I really like the simple and transparent nature of C: when I write C code I feel unencumbered by "leaky abstractions" and can almost always make a shrewd guess as to the assembly I'm producing. I also like the simple, familiar syntax for C.

However, C doesn't have these simple, helpful doodads that C++ offers like classes, simplified non-cstring handling, etc. I know that it's all possible to implement in C using jump tables and the like, but that's a bit wordy at times, and not very type-safe for various reasons.

I'm not a fan of the over-emphasis on objects in C++, though, and I'm gun shy of the 'new' operator and the like. C++ seems to have just a few too many hiccups to, for instance, be used as a system programming language.

Does there exist a language that sits between C and C++ on the scale of widgets and doodads?

Disclaimer: I mean this as purely a factual question. I do not intend to anger you because I don't share your view that C{,++} is good enough to do whatever I'm planning.

答: You haven't said what C++ features are annoying for you. anyway you could try Objective-C. It emphasizes on Object Oriented instead of Standard Library on C++.</p>

ContentLicense: CC BY-SA 3.0

Title: Is there a language between C and C++?


答: The embedded world specified Embedded C++, which may be what youy are looking for. They removed things like multiple inheritance and such like. As far as I am aware, it's pretty much died out though.</p>

Title: Is there a language between C and C++?


答:
However, C doesn't have these simple, helpful doodads that C++ offers
  like classes, simplified non-cstring handling, etc. I know that it's
  all possible to implement in C using jump tables and the like, but
  that's a bit wordy at times, and not very type-safe for various
  reasons.

I'm not a fan of the over-emphasis on objects in C++, though, and I'm
  gun shy of the 'new' operator and the like.

Sorry, buddy, contradiction alarm. Non-cstring handling requires new. It's a fundamental necessity. You cannot have std::string without new. And furthermore, new/delete is exactly equivalent to malloc/free but safer, because it guarantees correct construction and destruction of heap objects (totally necessary!) and uses exception handling instead of a NULL return, and is therefore superior in every fashion imaginable. In C++11 it is very possible to write your own new-style function, because perfect forwarding allows you to deal with any constructor of any type. If you are gun shy about new, then I suggest that you simply don't really know what you're dealing with.

Oh, yeah, and smart pointers make it so that you never, ever, have to actually deal with any of this yourself.

Furthermore, in C++ there is no over-emphasis. You don't have to use any object you don't want to. You can program functionally with lambdas and such any time you want to. Nobody is forcing you to use inheritance and virtual functions- in fact, many good C++ programs rarely exhibit inheritance. Templates are the more powerful and more useful abstraction technique. This is not Java.

Title: Is there a language between C and C++?


问:
I'm going to quit my job because of our platform: how can I leave a productive explanation of this?
I'm planning on leaving my current job because we're locked into using Blub, with an enterprise Blub framework and a Blub-level web server, on mediocre shared hosting. My coworkers are friendly and my boss is an average small business owner - I want to leave entirely because of the technical reasons. I feel like being soaked in Blub is bad for my brain and making me a worse programmer.

When I leave, how can I explain this to my boss and coworkers? How can I phrase my complaints about Blub productively? What kind of warning can I and should I leave for my successor in documentation?

(trying to make sure I meet the standards)

答:
You can be pretty frank. Just because you don't like it doesn't mean it's the wrong choice for them, so don't expect them to change or slap their heads and go "Of course you are right, how could we have been so stupid!"

Just say. It isn't where I want to be technically, I've enjoyed working for you and with the team and wish you all the best. Then move on.


问:
Why could citing bug IDs in patch notes be considered a bad practice?
Based on a comment and subsequent upvotes from Bug reopen vs. new:

Citing bug IDs in patch notes is just.. very unfriendly. – Krelp

It appears at least some people feel that referencing bug IDs in patch notes is not a good idea. I'm a fairly inexperienced developer, so I'm wondering why that's the case.

答:
A bug ID is mandatory for a point of reference. The reasons:

Prevent ambiguity: Two or more bugs might have similar descriptions. So one would need some anchor to distinguish between them.

Convenience: When discussing a bug, either with a customer or internally, the bug ID is often used for as a short form. If the ID will be omitted from the patch notes, it will be difficult to discuss about them:

3052 was already fixed, still working on 3077

is more convenient than:

The "application crash on apply button" was fixed, still working on
  the "NullReferenceException on clicking change user"


问:
What are the recommended resources for learning about the Actor model of concurrent systems?
The Actor concurrency model is clearly gaining favor. Is there a good book that presents the patterns and pitfalls of the model? I am thinking about something that would discuss, for instance, the problems of consistency and correctness in the context of hundreds or thousands of independent Actors.

It would be okay if it were associated with a specific language (Erlang, I would imagine, since that seems universally regarded as the proven implementation of Actors), but I am hoping for something more than an introductory chapter or two. I'm actually most interested in Actors as they are implemented in Scala, if there are any such resources available.

答:
Apart from Actors in scala, there are some chapters that discuss Actors in Scala in these books: Programming in Scala (Artima) and Programming Scala (O'Reilly).

Furthermore, you could take a look at Akka documentation: Akka


答:
The Blub framework may still meet the business needs of the business owner.

I don't understand why you would expect the business owner to discard their investment in the existing (functioning) code base just because the language/framework does not mesh well with your brain.

It is far cheaper to replace you with someone who thinks that Blub is awesome.

I am not saying you shouldn't move on if Blub does not work for you, just don't confuse your feelings with the business' needs.

Update: "think" != data. I make a point of documenting productivity barriers and their time cost every day. The things that slip through the cracks now don't.

Example:

VPN not working (10:15am-10:35am : 20min);

build tool misconfigured (12:30pm-1:20pm = 50min);

etc.

Unless you have data about the productivity question, you just have an uninformed opinion.

Lastly, how are you defining "productivity". After all it may be more "productive" to not have to write the tests for the new code or to fix broken tests. (Yes, I had an engineering manager who believed this).

Unless you can make a data-driven case for a change, why should the business change?

Title: I'm going to quit my job because of our platform: how can I leave a productive explanation of this?

Body:
I'm planning on leaving my current job because we're locked into using Blub, with an enterprise Blub framework and a Blub-level web server, on mediocre shared hosting. My coworkers are friendly and my boss is an average small business owner - I want to leave entirely because of the technical reasons. I feel like being soaked in Blub is bad for my brain and making me a worse programmer.

When I leave, how can I explain this to my boss and coworkers? How can I phrase my complaints about Blub productively? What kind of warning can I and should I leave for my successor in documentation?

(trying to make sure I meet the standards)


答:
First you don't have to justify yourself when you quit a job, but it's generally what you should do to keep good professionnal relationships with your employer. Don't forget that he will probably be called by your new employer (most serious ones do it).

Telling that you leave because you think they are locked into a Blub may not be appropriate for two reasons, even if honesty is usually the best option in most situations:

First it may hurt them, in their feelings, and adopt a defensive position against you. It may makes things more difficult and you should always avoid to hurt other feelings as much as you can (I like to make the association here with Emotional Intelligence).

Secondly you may be wrong. Yes, they may have their own reasons for keeping those technologies. Very often, we don't understand management's choices because we don't have all the needed information to build our opinion.

The only way I found appropriate to leave a company is to tell them you want to do something that is more close with what you like to do. You can tell them you don't like the technology, instead of telling them they are wrong.


问:
Usage of repository between EF model and code consumer
I have binary data in my database that I'll have to convert to bitmap at some point. I was thinking whether or not it's appropriate to use a repository and do it there. My consumer, which is a presentation layer, will use this repository. For example:

// This is a class I created for modeling the item as is.
public class RealItem
{
    public string Name { get; set; }
    public Bitmap Image { get; set; }
}

public abstract class BaseRepository
{
    //using Unity (http://unity.codeplex.com) to inject the dependancy of entity context.
    [Dependency]
    public Context { get; set; }
}

public calss ItemRepository : BaseRepository
{
    public List<Items> Select()
    {
        IEnumerable<Items> items = from item in Context.Items select item;
        List<RealItem> lst = new List<RealItem>();
        foreach(itm in items)
        {
            MemoryStream stream = new MemoryStream(itm.Image);
            Bitmap image = (Bitmap)Image.FromStream(stream);
            RealItem ritem = new RealItem{ Name=item.Name, Image=image };
            lst.Add(ritem);
        }

        return lst;
    }
}
```

<p>Is this a correct way to use the repository pattern? I'm learning this pattern and I've seen a lot of examples online that are using a repository but when I looked at their source code... for example:</p>

<pre class="lang-cs prettyprint-override"><code>public IQueryable<object> Select
{
    return from q in base.Context select q;
}
</code>```

as you can see no behavior is added to the system by their approach, so I was confused that maybe repository is something else and I got it all wrong. At the end there should be extra benifits of using them right?

答:
I would leave the Image field in your entity as byte[] and add a new property called ImageObject which returns the Image byte[] into an appropriate Image object.

```<code>public class RealItem
{
    public string Name { get; set; }
    public byte[] Image { get; set; }
    public Bitmap ImageObject
    {
        get
        {
            using(MemoryStream stream = new MemoryStream(this.Image))
            {
                 Bitmap image = (Bitmap)Image.FromStream(stream);
                 return image;
            }
        }
    }
}
</code>```

Feel free to improve this by adding some sort of caching functionality to convert the image bytes once instead of each call (and renew the image object only if bytes changed).

Body:
I would leave the Image field in your entity as byte[] and add a new property called ImageObject which returns the Image byte[] into an appropriate Image object.

public class RealItem
{
    public string Name { get; set; }
    public byte[] Image { get; set; }
    public Bitmap ImageObject
    {
        get
        {
            using(MemoryStream stream = new MemoryStream(this.Image))
            {
                 Bitmap image = (Bitmap)Image.FromStream(stream);
                 return image;
            }
        }
    }
}

Feel free to improve this by adding some sort of caching functionality to convert the image bytes once instead of each call (and renew the image object only if bytes changed).


问:
Why Aren't There New Versions of C?
While many other languages have rapid development, such as Python, which has come out with a whole new version in the past few years, or to use a framework, Rails, which evolves super-fast (A book that was published in early 2011 is now obsolete), it seems that there are no updates for C. Why is this?</p>

答: C was developed with systems programming in mind, a more useable assembler. For this application C is widely usee in e.g. embedded programming. A lot of new application areas for programming have emerged, e.g. the web. New programming languages emerged more suitable for these new application areas, limiting the need for C to extend into these areas. In regard to books, new books tend to emerge more early in the life cycle of a language as tge developments and expansion of the language are strongest at that time. C is very mature, explaining why C books are not coming out every week, only to be outdated very soon.</p>

Title: Why Aren't There New Versions of C?


答:
There was a new revision of the C standard just a few months ago (C11, ratified 8th December 2011). I wouldn't be surprised if all of the latest releases of the GNU C compiler slightly modifies the lanuage it accepts (add and remove language extensions, possibly add more C11 features, possibly remove support for ancient cruft). True, that's slow, incremental changes rather than a revolution, but the language still evoles.

But apart from that, C is quite old - it had more than enough time to be refined. C as it is now is pretty close to what the language is intended to be: A super-simple, ultra-portable, low-overhead, extremely stable [in a backwards combability sense] system programming language. There have been some attempts to re-invent sytem programming (such as D, Go, and the much more obscure BitC) but they all drop some of C's goals - most importantly backwards combability - and are sufficently different to stop light-hearted adoption.

Title: Why Aren't There New Versions of C?

Body: While many other languages have rapid development, such as Python, which has come out with a whole new version in the past few years, or to use a framework, Rails, which evolves super-fast (A book that was published in early 2011 is now obsolete), it seems that there are no updates for C. Why is this?</p>


答:
C is almost a subset of C++, so you could just use those parts of C++ that you like and disregard the rest. It is even possible to write valid C that is also valid C++.

You won't be writing idiomatic C++, but that's about as "in-between" as it gets.

Alternatively, you could check out other languages that try to extend C towards something more powerful, most notably D and Objective-C.

And finally, depending on the nature of the project, you can go for a polyglot approach: divide your project into modules, and pick the most suitable language for each part. The downside of this is that you need to get the languages to work together, which may be too much work to be worth the effort.

Title: Is there a language between C and C++?


答: I quit my first job, because the company decided to move from Java to .NET. I simply told them that I invested a lot of effort into learning and mastering Java and there's no way that I would start learning .NET while there was a need for Java developers on the Job market. I did a mistake though. I told them this before I had a new job, so I had to spent some time home. There's nothing new in my story, you got great answers, but I wanted to emphasis two things: honesty, and having a new job already.


问:
How can I find a good open source project to join?
I just started working a year ago, and I want to join an open source project for the same reasons as anyone else: help create something useful and develop my skills further.

My problem is, I don't know how to find a project where I'll fit in.

How can I find a beginner-friendly project?  What attributes should I be searching for?  What are warning signs that a project might not be the right fit?  Are there any tools out there to help match people with open source projects?

There's a similar question here, but that question has to do with employment and is limited to PHP/Drupal.

答:
I recommend reading : http://open-advice.org/.

It aims at helping those who create and maintain communities, and those who are not confident about which one they want to join or how to do so.

Failing that, find a project which has a mission that resonates with you, or fork and contribute to one that is already useful to you.

Good luck.


问:
Storing data for use on Android and Windows Applications
I posted this last night on StackOverflow and was advised to move it over to StackExchange, thank you for taking a moment to look at my question.

I'm developing a project proposal for my final year project at University and as I aim to use programming languages I am currently not too familiar with I'm looking for some guidance - I can't include details of my project but hopefully you will understand what I'm after.

I'm going to be creating an Android application (in Java) and a Windows Application (in C#) that will ideally access, query and update a remotely hosted Database or set of XML files (this would most likely be over the Internet).

I've done some looking around the internet and SQLite seems like a safe-bet for cross-platform manipulation of the database; however I would like to keep the system as lightweight as possible and I'm wondering whether XML files may provide a better alternative? Anyone out there that has experience using SQLite and/or remotely hosted XML for the purposes of Android and/or C# development that could point me in the right direction?

If there is an alternative solution other than those I have mentioned I would be interested to hear about them too.

Thank you for taking the time to read my question.

Edit: The purpose of this application is for a small scale business, the data source would not need to be updated by more than one source but may be view from multiple sources (i.e. through multiple phones and a desktop PC). The database wouldn't be updating masses of data at a time (most likely single rows of a few tables at the most).

答:
If you are planning to develop an application in Android SQLite is the only way to go. In my case I have to include a database which is already populated with information to fill the dropdownlists (can't remember their Android name but I hope you got the meaning). Thus I have to insert data prior to deploy and have to include it. Also using SQLite means you can query database with SQL syntax which is very handy.

Windows Phone, on the other hand, provides Azure platform in addition to SQLite, but the drawback is it is not free and needs an always online device.

A caveat regarding Android is the assets folder, the place where you put additional files to include with the application, has a filesize limit of 1,5 megabytes concerning files other than MP3 or PNGs. You have to rename your db file to PNG or MP3 if you exceed filesize limit and copy it to application (which you have to do if you include it with its db extension) with correct filetype.


问:
Does your programming knowledge decrease if you don't practice?
I'm a novice programmer. I study languages such as C, C++, Python and Java (mainly focusing on C++). I'm what you'd call "young and inexperienced" and I admit that because I can't claim otherwise.

As a student, I have many other problems besides programming. I practice programming as often as I can, and especially because my teacher gives me a lot more exercises than the rest of the class (it's a very low level), so oftentimes I spend weeks doing something else such as school projects or sports, or traveling, anything besides programming.

Don't get me wrong though, I love programming. I love to build functional code, to watch as a program comes alive at the push of a button, and to learn as much as I can. The thing is, I simply don't have much time for it.

Straight to the question, now: does your programming knowledge decrease as time passes and you don't practice? You may ask "how much time do you mean?". I don't mean a specific amount of time, but for reference you could take a month-two or even a year as an example.

By knowledge I mean anything from syntax to language functionality.

答: Anything not used will eventually atrophy. </p>


答:
Obviously, programming is something you learn to do, not a set of facts or information.  That said, it's more like riding a bike or speaking a language. There are theories too, but it's more about putting them to practice.

Even so, like anything, if you don't use it your brain will start to drop the information. Your brain is like a muscle that way. After a period of time you'll most likely remember broad concepts but not specifics about syntax and lesser-used functions. For example, you may want to do a for loop or iterate over a list and know that it's something like while List.hasNext() or for item in list or for index, item of list but not writing it very confidently.

The good thing is, you'll know what you want to do. You just need to look it up. So I wouldn't be too worried about it. It'll come back to you. The important thing is to learn how to solve problems with programs. All programming languages are usually capable of doing the same things, but most of the time in different ways. You might forget that Ruby or Python have comprehensions and write too many for loops instead, but you'll get the job done.

As for how much you'll forget or remember, I think that kind of depends on how active your mind is and how old you are. I don't think I developed a fully functional brain until I was 19. At that point memorizing anything for me was a snap. Everyone is different.

In sum: details always fade, the rate they fade depends on you, all languages are trying to make it easy to solve the same problems, so maybe it's more important to learn how to solve problems. :)

Title: Does your programming knowledge decrease if you don't practice?

Body:
I'm a novice programmer. I study languages such as C, C++, Python and Java (mainly focusing on C++). I'm what you'd call "young and inexperienced" and I admit that because I can't claim otherwise.

As a student, I have many other problems besides programming. I practice programming as often as I can, and especially because my teacher gives me a lot more exercises than the rest of the class (it's a very low level), so oftentimes I spend weeks doing something else such as school projects or sports, or traveling, anything besides programming.

Don't get me wrong though, I love programming. I love to build functional code, to watch as a program comes alive at the push of a button, and to learn as much as I can. The thing is, I simply don't have much time for it.

Straight to the question, now: does your programming knowledge decrease as time passes and you don't practice? You may ask "how much time do you mean?". I don't mean a specific amount of time, but for reference you could take a month-two or even a year as an example.

By knowledge I mean anything from syntax to language functionality.


问:
Any Practical Alternative to the Signals + Slots model for GUI Programming?
The majority of GUI Toolkits nowadays use the Signals + Slots model. It was Qt and GTK+, if  I am not wrong, who pioneered it.

You know, the widgets or graphical objects (sometimes even ones that aren't displayed) send signals to the main-loop handler.  The main-loop handler then calls the events, callbacks or slots assigned for that widget / graphical object. There are usually default (and in most cases virtual) event-handlers already provided by the toolkit for handling all pre-defined signals, therefore, unlike previous designs where the developer had to write the entire main-loop and handler for each and every message himself (think WINAPI), the developer only has to worry about the signals he needs to implement new functionality on.

Now this design is being used in most modern toolkits as far as I know. There are Qt, GTK+, FLTK etc. There is Java Swing. C# even has a language feature for it ( events and delegates ), and Windows Forms has been developed on this design. In fact, over the last decade, this design for GUI programming has become a kind of an unwritten standard. Since it increases productivity and provides greater abstraction.

However, my question is:

Is there any alternative design, that is parallel or  practical for modern GUI programming?

i.e Is the Signals + Slots design, the only practical one in town? Is it feasible to do GUI Programming with any other design? Are any modern (preferably successful and popular) GUI toolkits built on an alternative design?

答: A few control type systems use a database approach - each gui control is linked to a filed in the database so that the Gui always reflects the database state. DB hooks are used to trigger functions when a value changes.</p>


答:
Just to offer a wild, out of the box answer: if the language you want doesn't exist, why not make one yourself?  There are a variety of powerful language development tools out there, right down the old stand-bys of (F)Lex and Yacc/Bison.  Since you already know C, you just need your "compiler" to output C code, which you then use your existing tool chain for.

This can be both simpler and more powerful than you think.  Start with a parser/lexer for C, then add in the extra features that you think are important.  If jump tables are annoying to write by hand, figure out a construct to express the abstract, and let your interpreter write them for you.  Essentially this is just a higher-level of pre-processor metaprogramming, using outside tools to do the metaprogramming.  You'll always know exactly what the final assembly is going to be like since you know the C, and you know what C your language extensions will expand into.

Obviously there are some limitations to how effective this can be without a lot of extra work.  Adding a full static type system might be a tad more complex than you want to get into, but it's an option you could explore if you find you have a taste for it.  Your DSL extensions are as powerful and complex as you have time and energy to make them, and who knows, maybe someday your extension language will become "the next C++".

Title: Is there a language between C and C++?


答: Although I wouldn't call it all that popular, there is always reactive programming for GUIs, especially functional reactive programming, as implemented, for example, by the .NET Rx Framework, as well as by several toolkits in somewhat more esoteric languages/platforms, like reactive-banana or FrTime, for Haskell and Racket respectively.

Title: Any Practical Alternative to the Signals + Slots model for GUI Programming?

Body:
The majority of GUI Toolkits nowadays use the Signals + Slots model. It was Qt and GTK+, if  I am not wrong, who pioneered it.

You know, the widgets or graphical objects (sometimes even ones that aren't displayed) send signals to the main-loop handler.  The main-loop handler then calls the events, callbacks or slots assigned for that widget / graphical object. There are usually default (and in most cases virtual) event-handlers already provided by the toolkit for handling all pre-defined signals, therefore, unlike previous designs where the developer had to write the entire main-loop and handler for each and every message himself (think WINAPI), the developer only has to worry about the signals he needs to implement new functionality on.

Now this design is being used in most modern toolkits as far as I know. There are Qt, GTK+, FLTK etc. There is Java Swing. C# even has a language feature for it ( events and delegates ), and Windows Forms has been developed on this design. In fact, over the last decade, this design for GUI programming has become a kind of an unwritten standard. Since it increases productivity and provides greater abstraction.

However, my question is:

Is there any alternative design, that is parallel or  practical for modern GUI programming?

i.e Is the Signals + Slots design, the only practical one in town? Is it feasible to do GUI Programming with any other design? Are any modern (preferably successful and popular) GUI toolkits built on an alternative design?


答:
As long as you are going to another job right away you can say "better opportunity etc."  Now if you are leaving and don't have another job, the gap might be tough, but you should be able to explain it when asked that you wanted to re-train into something different and you needed the time to do that.

Try and enroll in something so you can put down the college or program as what you were doing during the gap.

You could also try and land some simple freelance stuff (or not) and then you can list as self-employed.  Just be sure to have something to show for that.

Don't be afraid of the gap.  My wife didn't work (outside the home) for 7 years and had two offers at the same time, while not as high paying as she would have liked, they were competitive technology offers.


问:
How does const storage work? (Item 2, Scott Myers Effective C++)
In Item2 on page 16, (Prefer consts, enums, and inlines to #defines), Scott says:

Also, though good compilers won't set aside storage for const objects of integer types...

I don't understand this.  If I define a const object, eg

```<code>const int myval = 5;
</code>```

then surely the compiler must set aside some memory (of int size) to store the value 5?

Or is const data stored in some special way?

This is more a question of computer storage I suppose.  Basically, how does the computer store const objects so that no storage is set aside?

答:
Not necessarily. It can also decide to just use the raw value 5 instead of myval in the compiled code.

The difference between #define MYVAL 5 and const int myval = 5 is that in the former case, the compiler has no choice whatsoever, as the preprocessor already replaced all mentions of MYVAL in the source code with 5 by the time the compiler gets to see the source code. In the latter case though, there is a choice. For a non-optimized debug build, the compiler may explicitly allocate a const int, so in the debugger you will be able to see the constant myval, instead of just the raw value 5.


答: The compiler will substitute the number five wherever the variable 'myval' is used. </p>

Title: How does const storage work? (Item 2, Scott Myers Effective C++)

Body:
In Item2 on page 16, (Prefer consts, enums, and inlines to #defines), Scott says:

Also, though good compilers won't set aside storage for const objects of integer types...

I don't understand this.  If I define a const object, eg

```<code>const int myval = 5;
</code>```

then surely the compiler must set aside some memory (of int size) to store the value 5?

Or is const data stored in some special way?

This is more a question of computer storage I suppose.  Basically, how does the computer store const objects so that no storage is set aside?


答:
That's a favorite subject of mine, and for about a decade ('70s to '86) I thought that having a GUI consisting of objects that respond to events was just the right way to do it.

Then I stumbled on another way to do it described here and with a sourceforge project here.

In a nutshell, the problem with objects is that they persist, and if you write code to create them, you also have to write code to modify them incrementally if changes are needed, and somehow get messages to and from them.
Wouldn't it be nice if you could just paint what you wanted, and then repaint it if you want something different, and not have to worry about the persistence of prior objects?
Wouldn't it also be nice if you never had to write code for message handling, because it is all done under the hood?

That's what that package does. For simple dialogs, it saves an order of magnitude in code. For complex dynamically changing dialogs, it makes them possible.

P.S. I've only done this for desktop UIs and remote terminal UIs, not web browser UIs.
I'm sure it's possible, but I haven't had the chance to try it.


答:
I'll steal the first sentence from Péter Török's answer but elaborate differently:  Not necessarily. It can also decide to just use the raw value 5 instead of myval in the compiled code.

Treating myval like a regular variable by allocating space for it in memory can have performance implications that range from miniscule to severe depending on the architecture and how it handles memory.

Working that way, a compiler would emit an instruction that says something along the lines  of "load register R with whatever is at the memory location for myval".  The location of myval as an operand of the instruction, so it comes right out of the same block of data as the instruction itself.  On modern CPUs, this value will be readily available on-chip because of instruction prefetch.  With the address in hand, the CPU still has to get the value out of memory.  That might go quickly if the location is nearby in cache or not so quickly if it isn't.  Not only does the CPU have to go off-chip to get the value, doing so might force it to bump other, more useful data out of the cache that will have to be brought back in later.  When the program is running under an OS that virtualizes memory, access to that location might cause a page fault, resulting in the program being put to sleep until the required page is brought into RAM via peripheral (e.g., disk) I/O, the program restarted via a context switch and the cache mechanism does whatever it's going to do with it.

By hard-wiring the constant value into the object code, the compiler would emit an instruction like "load register R with the value 5."  Like the memory address described above, the 5 would be an operand to the instruction and available in the same way (i.e., prefetched).  That's where the similarity ends, because the CPU now has everything it needs to put the 5 into register R and get on with its business.  Since addresses and registers are usually the same size, there's no difference in the number of bytes the instruction occupies and the actual execution takes place with zero chance of the cache misses and page faults that can occur when you go fish something out of memory.

The compiler could, as Péter pointed out, allocate space and a symbol for myval in debug builds.  There wouldn't be any harm in doing this and still hard-wiring its value, since the value remains the same no matter what and the symbol is really just there for us humans to use in debugging.

Note that this only applies to values that can be held in registers, because registers are integers by nature.  Other constants will end up in memory.


答:
Short form: you tell them you are leaving in order to expand your experience and skills.  As for your successor, you don't need to leave anything beyond whatever documentation/reports/memo you have produced.

Long form: Programming, unlike most professions, is in part defined by the tools one uses. Both managers and HR understand this (even those asking for 5-7 years of Go experience), neither will blink at hearing you want to expand your experience.  That you want to work with a specific tool or simply to vary your experience will be taken as neither rejection or signs of unreliability. Everything else being equal, experience with more languages, frameworks, editors, IDEs is a plus - it gives you a yardstick for comparison, making your judgement more worthwhile.

You don't say whether you have tried to convince your current employer to switch tools or whether you even think it would be a good idea for them to do so.  If you do and have, then your boss should already have everything your replacement needs if the decision is revisited, it's not your place to try to convince them to take up the cause in your place.

What you should be leaving for your replacement is as much documentation about how to do your job as you have available.  If you feel that there is something you know about how to do the job with the current tools, that your replacement should not be expected to know or easily discover, then document it.

As for your complaints.  You should not be mentioning them at all, they aren't relevant.


答:
Also, though good compilers won't set aside storage for const objects of integer types...

A slightly more correct statement would be that compilers wouldn't set aside data memory for const objects of integer type: they would trade it for program memory. There is no difference between the two under Von Neumann architecture, but in other architectures, such as Harvard, the distinction is rather important.

To fully understand what's going on, you need to recall how assembly language loads data for processing. There are two fundamental ways to load the data - read a memory from a specific location (so called direct addressing mode), or set a constant specified as part of the instruction itself (so called immediate addressing mode). When compiler sees a const int x = 5 declaration followed by int a = x+x, it has two options:

Put 5 in a data memory, as if it were a variable, and generate direct load instructions; treat writes to x as errors

Each time the x is referenced, generate an immediate load instruction of the value 5

In the first case you will see a read from x into the accumulator register, an addition of the value at the location of x to accumulator, and a store into the location of a. In the second case you will see a load immediate of five, an add immediate of five, followed by a store into the location of a. Some compilers may figure out that you are adding a constant to itself, optimize a = x+x into a = 10, and generate a single instruction that stores ten at the location of a.


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

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

答:
It should be noted that no ethically-trained software engineer would ever consent to write a DestroyBaghdad procedure. Basic professional ethics would instead require him to write a DestroyCity procedure, to which Baghdad could be given as a parameter.

Nathaniel Borenstein

LastEditorDisplayName: Roger Pate

ContentLicense: CC BY-SA 2.5


答:
A new standard for the C programming language (C 2011) was ratified just a few months ago, and has some significant additions over the previous version (such as a built-in threading library).

Previous standards were released in 1999 and 1989.

It takes WG14 a while to agree on a new standard for the following reasons:

There's over 40 years' worth of legacy code running out there, and the standards committee is understandably reluctant to break any of it;

There's a very large and varied community of C implementors and users, and keeping everybody happy isn't easy;

There's a desire to avoid creeping featuritis -- C's major virtue is its relative ease of implementation, and tacking on too many doo-dads may make implementation difficult (indeed, the addition of variable-length arrays in C99 caused some consternation, and IINM are now optional under the 2011 standard);

Say what you will about the virtues of Java and C#, but at least C reference manuals don't require a forklift to carry.

Title: Why Aren't There New Versions of C?


问:
How easy is it to alter a browser fingerprint?
I am researching this question for a possible paper. Given the exploitation of user identities for risk management and market tracking, how easy is it to alter a browser enough to throw off  fingerprinting techniques?

My current sources are:

EFF Panopticlick project

Peter Eckersly's follow-up presentation at Def Con 18.

答:
Your question comes down to how well you can change the individual components that make up a digital "fingerprint". There are some that you can't control (at least not without going to a whole lot of effort), but remember you only have to change some of them to alter the fingerprint, and some are rather easy to change depending on what sort of lengths you're prepared to go to in order to throw off anyone trying to fingerprint you. Here are some examples:

Cookies - set your browser to delete cookies on exit, or at least to not accept third-party cookies

Browser's user agent string - some browsers (e.g. Opera) let you "identify as" or "mask as" another browser, or use third-party software to change it (though some JavaScript tests can still tell which browser it actually is)

Browser and browser version - Keep updating your browser and that information will keep changing, or have multiple installations of the same browser where possible, or multiple browsers

IP address - use a proxy server

There are several other things you can change if you have multiple machines (be it physical or virtual), such as your OS and your screen resolution, etc.

The reason most people can be fingerprinted is because they're either not aware of these simple options, or it's too much effort for them, so they browse with the same browser using the same settings and don't delete their cookies. Personally, I haven't had any problems with fingerprinting (at least that I'm aware of!), and don't mind having ads targeted at me (I block most of them anyway), so I don't bother with most of these, but I can see how people would have something against it...


问:
Career advice: stay with PHP or start a new career in something else ( .Net?)
I'm planning on moving to NY in 6-12 months tops, so I'm forced to find a new job. When I'm planing to start my life in another city it's also probably a good time to think about career changes.

I've found a lot of different opinions about PHP vs .Net vs Java and this is not the topic here. I don't want to start a new fight about which language is better. Knowing a programming language is not the most important thing for being a software developer. To be a really good developer you need to know OOP, design patterns, testing... and a language is just a tool to make things happen.

So back to my question. I have mixed experience in IT - 1 year as an IT support guy (Windows administration and support), around 2 years of experience in embedded programming (VB.Net 2005) and for the last 2 years I'm working with PHP/MySQL. I have worked with Magento web shop, assisted in some projects in Symfony, modified few Drupal sites.

My main concerns are the following:

Do I continue to improve my skills in PHP e.g. to start learning some major PHP framework like Zend, Symfony maybe get some PHP certification.

Or do I start learning .NET or Java. I'm more familiar to .NET so I'll probably choose it if choice falls between .NET and Java ( or you could convince me to choose Java :).

Career-wise, I don't know what is the best choice. Learning a new framework and language is more time consuming then improving my existing skills in PHP. But with .NET you have a lot of possibilities (Windows 7 Phone development, Silverlight, WPF) and possibly bigger chances to find better jobs.

PHP jobs are less well payed then .NET, at least, according to my research (correct me if I'm wrong). But if I start now with .NET I'm just a beginner and my salary will be low. I need at least 2+ years of experience in some language to even try to find some job that is paying higher than $50-60k in NY. My main goal in the next 2-3 years is to try to find a job in the $60-80k category. Don't get me wrong, I'm not just chasing money, but money is an important factor when you're trying to start a family.

I'm 27 years old and I feel that there isn't a lot of room for wrong decisions regarding my career, so any advice will be very welcome.

Update

Thank you all for spending time to help me with my problem. All of the answers and comments have been very helpful. I have decided to stick with PHP but also to learn C# and Silverlight 4. We'll see where the life will take me.

答:
I disagree with most comments listed on this board.

Apart from learning software engineering principles and theory, the language you choose to master is a career choice. That's why there's Java programmers and PHP programmers. PHP programmers are probably not going to be working for NASA and Java programmers are probably not going to be working for a web shop.

If you want a job in corporate America, you're better off going the Java/.Net. Good income in you can get in but be prepared to donate your life to them (time wise).

If you want to be an independent freelancer, and live in the fast lane with web technology you're better off with PHP. A lot of work here but the pay varies greatly and being independent is work itself with every Tom, Dick and Harry with an idea trying to hire you for pennies.

There's some overlap with PHP and Java but only seen in Corporate jobs (Java REST Services with PHP front-end) however you will not find web shops or independent freelance work anywhere near Java.

Both require a lot of time and dedication if you want be useful in any given situation.

To be a competent and sought after PHP developer you need a bag full of skill sets. Chances are you'll be expected to know CSS, HTML4/5, and most definitely Javascript DOM/Ajax/Jquery plus at least a viable framework such as Zend (corporate America's taster's choice), Codeignitor, cakePHP, etc.. and then you'll need to know the "big three" CMS's: Drupal, Wordpress and Magento. Get these skill sets under your belt and you'll be a PHP specialist with the ability to land work anywhere you go. As you can tell, taking all this in is a devotion to a language and it's tools 'cause learning Perl isn't going to help you be an expert Drupal or Zend developer.

The same goes for Java: OOP, J2EE, REST/SOAP, Spring/Struts, etc.. and it's fleet of other tools that take years to masters.

Has anyone here tried coding Java for a year and then gone back to PHP (or any scripting language). It's difficult. It feels awkward.

I work for a fortune 500 company and Java developers would not be able to do what PHP developers do and PHP developers would not be able to do what Java developers do. But they both do well financially 'cause they're specialists in their field, their language of choice and the spew of tools that come with it.


答:
I'm the owner of a small business, meaning I'm The Guy. So when the website needs updating, I have to be Zend/MVC guru. When I need to hacksaw data or tweak webpages, I find I'm needing to use php. When I'm wrestling with Quickbooks, I can find myself using faux-QB queries, Visual Basic, php, mysql, linux, and windows in a miasma of technology soup. Oh right, and I do CAD work when a vendor needs drawings, which means I have to be a mechanical engineer / designer and figure out file formats and what it takes to get people the knowledge that is inside my head clearly. We just ran out of catalogs again, so I bought Adobe CS5 and took the InDesign file for the old catalog and tweaked it for new catalog. I'm also the electrician and networking guy that builds cables when needed.

Given all that experience over the last 10 years, I've found that I do forget things within about a month. BUT when immersed into it again, the brain will spark memories that send me to php.net or digging through old/legacy/ancient code I've written. Same for the CAD work; there's a huge project I've been in and out of for over a year. When I turn that computer on, it takes a day for all the updates to complete and licenses to sort out and then two to five more days to get to where I was when I left off.

I'm finding the hardest to pick up again each time is the Quickbooks qodbc programming. :P I've done MySql and PostgreSQL off and on over the years and with my cheats text files where I save particularly useful queries, I can pick that stuff up real quickly.

Summary: keep all of your work forever, play with it every 6-12 months, when you need to revisit that code, you probably will not have regressed too much, and expect to be full speed again within a week.


问:
What advantages do continuous integration tools offer on a solo project?
If you're doing a solo project - would you use CI tools to build from a repository? I've used Hudson and Cruise Control in a team environment, where it's essential to build as soon as anyone checks anything in.

I think the value of version control is still obvious, but do I need to build after every commit, seeing as I would just have built on my local machine, and no-one else is committing?

答:
It is important if you want to reduce your wait time to see if everything is still going well.  Although you can get your IDE to compile stuff for you as soon as you save, it does not automatically run unit tests, so I have my CI server run the unit tests and test case coverage reports and other quality analysis of my code as soon as I push it.

The only trigger I have to do is push my current changes to version control and I can go back to coding.  And while I am thinking about coding, the CI system is busy churning along doing the long winded quality reports which I will look at once in a while when my brain goes in a lull.

I have a separate VMWare machine on the same laptop that does the builds for code that I push in.  To do this I just get a Turnkey Linux VMWare image and install the jenkins using apt-get and do a few minor configuration changes.


问:
Does making source code available affect your ability to generate revenue?
We’re working on a .Net framework which ultimately amounts to a single DLL.  We intend to charge for commercial use of the framework, but make it free for open source/non-commercial use.  The rough plan at the moment is to administer this through some form of fairly simple licence which will be issued whether you’re using it for free or paying.

We’re debating whether to make the source code available.  It’s our perception (and our own preference) that it’s far more appealing to use something where you have access to the source code.

I’m interested in whether people think making the source code available will damage our ability to make money from the framework, or whether it will encourage more usage and enough “good” people will arrange to pay for the correct licence if using it commercially.

My feeling is that, generally, commercial operations don’t mess about on the licencing front and so making the source code available will only encourage usage and therefore ultimately generate more revenue, but I’d be interested in others views/experience.

答:
I think that having source can come at two levels.

Source for the classes you have but not in a state where it is easy to rebuild the distributed binary.  In other words, you can see but not touch.

Full source in a form that can be easily rebuilt.

I as a developer strongly prefer the latter, as it allows you to hot fix a problem.  It might be the decisive factor when given a choice between two libraries!

The thing to protect your source must be the license.  Let the Open Source version be GPL and allow business to purchase a non-GPL version to be included in their commercial non-GPL products.


答: You might find this in-depth side-by-side comparison of C++, Objective-C, Java and C# useful. Personally I think C# is a lot cleaner to work with than C++. I have ported several (numerical/calculations) C functions to C# before without too many changes being necessary due to the similarity of the syntax and numeric data types.</p>

Title: Is there a language between C and C++?


问:
I created a program based on an LGPL project, and I'm not allowed to publish the source code
I thought LGPL was a permissive license, just like MIT, BSD or Apache. But today I read, that only linking to LGPL (libraries etc) is allowed from closed-source code - other than that, it's copyleft - so I have to publish code that is based on an LGPL program.

I created a program for my employer that is based on an LGPL program, but has considerable modifications to it. Of course, I am not allowed to put that modified source code out there. At the same time, I have to, if I distribute it (right?).

So I wonder whether there is a workaround to this, so I can keep this closed-source (I wish I could publish the source) - any suggestions?

My idea: can I put most functions of the original LGPL app into an external library, write the core executable from scratch, but refer back to the library for all functions that I haven't modified?

Currently, everything is in a .jar file (it's Java/Swing). if you think my idea is legally/technically feasible - how much effort would it be to seperate what I wrote and what the original is? I'm not the most java savvy.

答:
you may use adapter pattern and don't touch the original code.
Also LGPL allows you to inherit classes and override functionality of it's classes in your own project. </p>

OwnerDisplayName: Dave


答:
Methodologies and the likes doesn't decrease if you don't practice, but remembering the correct syntax and libraries surely does.

I mainly use Java, C++ and C#. But for the last two years, I've been using Java only occasionally (if a bug needs to be fixed in a legacy system). So I often struggle a bit to remember what the correct syntax is or which library I need now.


问:
Trial/Free & Full Version VS. Free App + In-app billing?
I'm just wondering what would be the best strategy to publish an application on the Android Market.

If you have a free and paid version you have two codes to update (I know it will be 99% the same but still) and besides all the popular paid apps are quite easy to find for "free" in "alternative" markets. Also if you have any stored data in the trial/free version you lose it when you buy the full version..

On the other hand if you put a free application but inside you allow the user to unlock options (remove ads/more settings/etc...) you only have to worry about one code. I don't know the drawbacks of that strategy and how easy/hard is to hack that to get all the options for "free".

答:
I haven't actually tried this, but one approach to upgrading on Android Market would be to have a separate paid license app that does not duplicate any of the code of the free app, but which enables features in the free app once it is purchased and installed.

It seems possible that the well known app ROM Manager takes that approach, since I ended up having two apps installed when I purchased the premium version, and I continued to use the original version after installing the premium one, and was able to access the enhanced (premium) capabilities.

I don't know how ROM Manager implements this, but it seems possible that it supplies a ContentProvider that can be accessed by the free app once the license app has been installed.  This could allow the free app to know that the user had installed the license, which in turn could trigger the enablement of the app's premium features.

This approach would allow the user to upgrade without losing any of the content created by the user in the free app.

Just an idea; not sure if it is a technically good or secure approach.  If anyone has experience or thoughts regarding this approach, I'd be interested to hear them.


答:
There is a point which is missing in the current answers:

Stability is a virtue for any production programming language. C is standardized not only in its syntax, but also in its ABI, which allows other system to easily call dlls compiled from c code. Try to do the same with c++: you will see that you will have to implement one interface for each existing compiler. This is only possible because the language is very stable.

This is why python 3 new features developpement was frozen at some point: in order to gain serious adoption you need to have stability, because shops will want to keep existing source code while upgrading their toolchains.

At this point c is probably one of the more stable language out there, and this is a good thing.

EDIT

More details about my opinion on stable languages: When a given language is stable AND used by some known projects AND actively maintained, you are pretty sure that the implementation is solid. If new features are continously added, you are not sure that they have received enough testing simply because time has not allowed QA to happen. Most of the time the last cornercases and bugs will be found by users pushing an implementation to its limits by using it on several platforms and in different contexts. Time allows the maintainers to fix the bugs they want to fix and document the other ones.

Title: Why Aren't There New Versions of C?


答:
Well, there's two distinct ways to go about this:

Have every widget expose a granular subscribing mechanism (Signal/Slot, Observer/Observable, Event/Delegate) and have client code subscribe and take action accordingly.

Built a widget against an abstraction of the data it presents and have client code implement that abstraction.

Here's an example for the second approach:

```<code>interface Action {
     void execute();
     Bool isEnabled();
     Null<String> description();//used for tooltip
}
interface LabledAction extends Action {
     String getName();
}
</code>```

And now you can build a LabelButton against a LabledAction and client code can just implement it or use some generic default implementation, if available and suitable.

In a way the second approach is less flexible, but more rigid. You don't just somehow wire together the view with the model through relatively atomic means. You design a suitable GUI based on your requirements and then you implement the adapters between that GUI and your domain/application logic.

Body:
Well, there's two distinct ways to go about this:

Have every widget expose a granular subscribing mechanism (Signal/Slot, Observer/Observable, Event/Delegate) and have client code subscribe and take action accordingly.

Built a widget against an abstraction of the data it presents and have client code implement that abstraction.

Here's an example for the second approach:

interface Action {
     void execute();
     Bool isEnabled();
     Null<String> description();//used for tooltip
}
interface LabledAction extends Action {
     String getName();
}

And now you can build a LabelButton against a LabledAction and client code can just implement it or use some generic default implementation, if available and suitable.

In a way the second approach is less flexible, but more rigid. You don't just somehow wire together the view with the model through relatively atomic means. You design a suitable GUI based on your requirements and then you implement the adapters between that GUI and your domain/application logic.


问:
I'm going to quit my job because of our platform: how can I leave a productive explanation of this?
I'm planning on leaving my current job because we're locked into using Blub, with an enterprise Blub framework and a Blub-level web server, on mediocre shared hosting. My coworkers are friendly and my boss is an average small business owner - I want to leave entirely because of the technical reasons. I feel like being soaked in Blub is bad for my brain and making me a worse programmer.

When I leave, how can I explain this to my boss and coworkers? How can I phrase my complaints about Blub productively? What kind of warning can I and should I leave for my successor in documentation?

(trying to make sure I meet the standards)

答:
Lots of great answers here already, but I have experienced something similar trying to introduce better project management practices that eventually lead to me butting heads with everyone important.  I decided to leave and had to consider what to say.

I decided to bite my tongue and leave on the most positive note possible, especially since a lot of the people I was clashing with were my friends.  A couple of years later the company asked me to come back and manage the software development my way.

So I say leave on a positive note because it is not necessarily the end of the story.


问:
Why not write all tests at once when doing TDD?
The Red - Green - Refactor cycle for TDD is well established and accepted. We write one failing unit test and make it pass as simply as possible. What are the benefits to this approach over writing many failing unit tests for a class and make them all pass in one go.

The test suite still protects you against writing incorrect code or making mistakes in the refactoring stage, so what's the harm? Sometimes it's easier to write all the tests for a class (or module) first as a form of 'brain dump' to quickly write down all the expected behavior in one go.

答: I think by doing this, you miss out on the process of TDD. By just writing all your tests at the start you are not really going through the process of developing using TDD. You are simply guessing up front which tests you will need. This will be a very different set of tests from the ones you end up writing if you do them one at a time as you develop your code. (Unless your program is going to be trivial in nature.)


答:
When you write one test, you concentrate on one thing.

With many tests you spread your attention on many tasks, so it's not a good idea.

Title: Why not write all tests at once when doing TDD?

Body:
The Red - Green - Refactor cycle for TDD is well established and accepted. We write one failing unit test and make it pass as simply as possible. What are the benefits to this approach over writing many failing unit tests for a class and make them all pass in one go.

The test suite still protects you against writing incorrect code or making mistakes in the refactoring stage, so what's the harm? Sometimes it's easier to write all the tests for a class (or module) first as a form of 'brain dump' to quickly write down all the expected behavior in one go.


答:
One of the difficulties when writing unit tests is that you are writing code, and that in itself can potentially be prone to error. There is also the possibility that you might end up needing to change your tests later on as a result of a refactoring effort as you write your implementation code. With TDD, this means you could potentially end up getting a little too carried away with your testing and find your self needing to rewrite a lot of essentially "untested" test code as your implementation matures over the course of the project. One way to avoid this sort of problem is to simply focus on doing one single thing at a time.  This ensures you minimize the impact of any changes on your tests.

Of course, this will largely comes down to how you write your test code.  Are you writing a unit test for every individual method, or are you writing tests which focus on features/requirements/behaviours? Another approach could be to use a Behaviour Driven approach with a suitable framework, and focus on writing tests as if they are specifications. This would mean either adopting the BDD method, or adapting BDD testing if you wish to stick with TDD more formally.  Alternatively you might stick entirely with the TDD paradigm, yet alter the way you write tests so that instead of focusing entirely on testing methods individually, you test behaviours more generally as a means to satisfy the specifics of the requirements features you are implementing.

Regardless of the specific approach you take, in all the cases that I've described above you are using a test-first approach, so while it may be tempting to simply download your brain into a lovely test suite, you also want to fight the temptation to do more than is absolutely necessary. Whenever I am about to start a new test suite I start repeating YAGNI to myself, and sometimes even throw it into a comment in my code to remind me to stay focused on what is immediately important, and to only do the minimum required to satisfy the requirements of the feature I am about to implement.  Sticking to Red-Green-Refactor helps to ensure that you will do this.


答:
What the quote says is not quite correct.

A good compiler won't set aside storage for static  const variables.  If the const variable isn't static and is in file-scope, it must set aside storage because the variable could be referenced from another compilation unit.  With link-time optimizations, the linker might  be able to eliminate the storage and rewrite instructions that reference the variable if it can prove that the program doesn't generate a pointer to that variable.

A much better reason for using const int instead of #define is that debuggers don't "see" macros, so you can't inspect a #defined'd value in the debugger.


答:
The idea behind TDD is rapid iterations.

If you have large swaths of tests that have to be written before you have to write your code it's hard to iteratively refactor your code.

Without easy code refactoring you lose a lot of the benefits of TDD.


答:
I've worked on a project where developers who wrote the (failing) tests were different from the developers implementing the necessary code to make them pass and I found it really effective.

In that case, only the tests related to the current iteration were written once. So what you suggest is perfectly possible in that kind of scenario.


答: General programming knowledge or programmatic problem solving skills do not age really, but language-specific or framework-specific knowledge gets outdated after a while.</p>


答:
I do “write” all the tests I can think of up front while “brain storming”, however I write each test as a single one comment describing the test.

I then convert one test to code and do the work so it will compile and pass.  Often I decide I don’t need all the tests I thought I did, or I need different tests, this information only comes from writing the code to make the tests pass.

The problem is you can’t write a test in code until you have created the method and classes it tests as otherwise you will just get lots of compiler errors that get the way of you working on a single test at a time.

Now if you are using a system like spec flow when the tests are written in “English”  you may wish to get the customers to agree to a set of tests while you have their time, rather than only creating a single test.


答:
One test at time: main advantage is focus on one thing. Think of depth-first design: you can go deep and stay focused with fast feedback loop. You may miss the scope of the whole problem though! That's the moment (large) refactoring comes into play. Without it TDD doesn't work.

All tests: analysis and designing may reveal you more of the scope of the problem. Think of breadth-first design. You analyze problem from more angles and add input from experience. It's inherently harder, but may yield interesting benefit - less refactoring - if you do 'just enough of it'. Beware it's easy to over-analyze and yet completely miss the mark!

I find it hard to generally recommend to prefer one or the other, because factors are many: experience (especially with the same problem), domain knowledge and skills, friendliness of the code for refactoring, complexity of the problem...

I'd guess if we focus more narrowly to typical business applications then TDD with its fast -almost- trial&error approach would usually win in terms of effectiveness.


答:
Test driven design is about getting your API right, not the code.

The benefit of writing the simplest failing tests first is that you get your API (which it essentially is you are designing on the fly) as simple as possible.  Up front.

Any future uses (which the next tests you write are) will go from the initial simple design, instead of a suboptimal design coping with more complex cases.


问:
Time Tracking - Best method?
I'm looking to track the time it takes users to traverse through a few forms I have on a website.

My old thought was to use something like jQuery to poll the server updating the time spent on a page, but it appears this would be incredibly resource intensive.

Recently I've been reading about sockets.io and node.js. It seems like the connection and disconnection methods might be a perfect way to track time.

Before I dive into learning all about sockets etc, is there a better way for doing this? I know I could do this server side, but it'll fall over if someone abandon's the site entirely midway through the process, and with sockets I could even track down to the length of time spent on each form field if I wanted.

答:
Any Decent web analytic package will go this for you. If that doesn't work for you I would analyze the web logs.

I don't think this is something you want code into your front end.

Title: Time Tracking - Best method?


问:
Is mentioning my blog on my resume helpful or hurtful to a job search?
I have a blog that I use mostly to record solutions to problems I have had, that I had some trouble finding an answer to. Mostly problems where the online doc I googled provided too much info, and I found the answer to my question on the fifth page of my third google hit.

(Or if I asked the question here, I either didn't get an answer or I got slammed for asking a question that "the answer could be easily googled.")

I frequently look up stuff on this blog to remind myself of how I solved a problem, and it gets a decent amount of hits from others as well.

Anyway, I was wondering if mentioning this blog on my resume would help or hurt me in a job search? The topics are all over the map.

What I would hope it shows is that

I am a person who finds solutions to problems

I have used many different technologies in my work

I am not afraid to tackle a challenge

What I am concerned it shows is that

This person had trouble with something that simple?

Why is this person bothering to blog this stuff?

答:
I'd say that mentioning your blog would be helpful. It gives a history of your progression and shows a potential employer that you're able to solve problems and diligent enough to record that information for future use.

Also, it differentiates you from most other candidates that probably don't have their own blog.


问:
How to "translate" interdependent object states in code?
I have the following problem. My UI interace contains several buttons, labels, and other visual information. I am able to describe every possible workflow scenario that should be  be allowed on that UI. That means I can describe it like this - when button A is pressed, the following should follow ->

In the case of that A button, there are three independent factors that influence the possible result when pushing the A button. The state of the session (blank, single, multi, multi special), the actual work that is being done by the system at the moment of pressing the A button (nothing was happening, work was being done, work was paused) and a separate UI element that has two states (on , off)..This gives me a 3 dimensional cube with 24 possible outcomes.

I could  write code for this using if cycles, switch cycles etc....but the problem is, I have another 7 buttons on that ui, I can enter this UI from different states..some buttons change the state, some change parameters...
To sum up, the combinations are mindbogling and I am not able come up with a methodology that scales and is systematically reliable.
I am able to describe EVERY workflow with words, I am sure my description is complete and without logical errors. But I am not able to translate that into code. I was trying to draw flowcharts but it soon became visually too complicated due to too many if "emafors".
Can you advice how to proceeed?

答:
Sometimes, with complex functionality comes a complex implementation.  Since the reaction of your UI to user input depends on so many variables, you may just have to accept that your code is not going to be short, sweet, and simple.

You may have to have a separate function to handle each UI component and encapsulate it that way.  So, each of these functions acts as an event handler that looks at what is going on in the environment before acting on the user's input.

Another option is to code each UI component as a separate class that perhaps specializes and inherits from a common UI component class.  That way, each UI component has its own properties, methods, and state.  This may be the best solution to mitigate the complexity of your design.


答:
don't try to combine everything in one place

if a button changes a parameter let it change the parameter (and nothing else)

if a button uses a parameter let it request the parameter

this is called limiting responsability

edit: the fact that you are trying to visualize all the possibilities of one action into a cube is an indicator of trying to look too broadly at your program flow. many times there will be similarities between those outcomes (for example blank state means nothing should happen regardless of what the other parameters are)

also try to decentralize the code the OOP approach for this is: each state has it's own code to execute when button A is pressed; have a interface State with the method buttonAPressed() (add parameters as needed) that handles everything specific to the state and implement it differently for blank, single, multi, multi special

Title: How to "translate" interdependent object states in code?

Body:
I have the following problem. My UI interace contains several buttons, labels, and other visual information. I am able to describe every possible workflow scenario that should be  be allowed on that UI. That means I can describe it like this - when button A is pressed, the following should follow ->

In the case of that A button, there are three independent factors that influence the possible result when pushing the A button. The state of the session (blank, single, multi, multi special), the actual work that is being done by the system at the moment of pressing the A button (nothing was happening, work was being done, work was paused) and a separate UI element that has two states (on , off)..This gives me a 3 dimensional cube with 24 possible outcomes.

I could  write code for this using if cycles, switch cycles etc....but the problem is, I have another 7 buttons on that ui, I can enter this UI from different states..some buttons change the state, some change parameters...
To sum up, the combinations are mindbogling and I am not able come up with a methodology that scales and is systematically reliable.
I am able to describe EVERY workflow with words, I am sure my description is complete and without logical errors. But I am not able to translate that into code. I was trying to draw flowcharts but it soon became visually too complicated due to too many if "emafors".
Can you advice how to proceeed?


答:
Beyond just thinking of one thing, one paradigm of TDD is to write the least code possible to pass the test. When you write one test at a time, it is much easier to see the path to writing just enough code to get that test to pass.  With a whole suite of tests to pass, you don't come at the code in small steps but have to make a large leap to make them all pass in one go.

Now if you don't limit yourself to writing the code to make them all pass "in one go," but rather write just enough code to pass one test at a time, it might still work.  You'd have to have more discipline to not just go ahead and write more code than you need, though.  Once you start down that path, you leave yourself open to writing more code than the tests describe, which can be untested, at least in the sense that it isn't driven by a test and perhaps in the sense that it isn't needed (or exercised) by any test.

Getting down what the method should do, as comments, stories, a functional specification, etc., is perfectly acceptable.  I would wait to translate these into tests one at a time though.

The other thing that you can miss by writing the tests all at once is the thinking process by which passing a test can prompt you to think of other test cases.  Without a bank of existing tests, you need to think of the next test case in the context of the last passing test.  As I said, having a good idea of what the method is supposed to do is very good, but many times I've found myself finding new possibilities that I hadn't considered a priori, but which only occurred in the process of writing the tests.  There is a danger that you might miss these unless you specifically get in the habit of thinking what new tests can I write that I don't already have.


答:
If you are looking for a formalism, check some graphical approaches:

finite state machines

statecharts

Petri nets

Many others exist.

I would put the whole state logic in a controller and the UI itself in a view, using a model-view-controller architecture.


答:
the problem is, I have another 7 buttons on that ui, I can enter this UI from different states..some buttons change the state, some change parameters... To sum up, the combinations are mindbogling and I am not able come up with a methodology that scales and is systematically reliable. I am able to describe EVERY workflow with words, I am sure my description is complete and without logical errors. But I am not able to translate that into code.

Seems like you should look into the state pattern or the mediator pattern.  If your program has all of these states already, imagine how many it might have after 2-3 more years of added features.. You will be able to add new transitions and states easily if you follow the state pattern.

Design patterns actually apply really well the more complex the problem is.  Having the foresight to see extendability problems and trying to apply one that fits will payoff in the future.


答:
In my (limited) experience with TDD, I can tell you that every time I've broken the discipline of writing one test at a time, things have gone badly.  It's an easy trap to fall into.  "Oh, that method is trivial," you think to yourself, "so I'll just knock out these two other related tests and keep moving."  Well, guess what?  Nothing is as trivial as it seems.  Every time I've fallen into this trap, I ended up debugging something I thought was easy, but turned out to have weird corner cases.  And since I'd gone on to write several tests at once, it was a lot of work to track down where the bug was.

If you need a brain dump of information, you have lots of options:

Whiteboard

User stories

Comments

Good ol' pen and paper

Notice that nowhere on this list is the compiler. :-)


答:
Any blog, if it covers technical topics rather than the adventures of your cat, can be useful in showing employers what you care about, what you know, and how you approach problems. Consider adjusting your entry style a little bit to eliminate the one negative, that it might show you once didn't know X, where X is some trivial thing that "everyone" should know.

Next time you want to write "I have been having such trouble for weeks now trying to figure out how to get the first 4 characters of a string with .NET, I was so confused but in the end I sorted it out, and along the way I learned a lot about the String functions ..." and then writing a useful post about string functions, but possibly tainting yourself as someone who didn't know that basic thing, start it instead "Some people are confused about all the different String functions. Here's a handy summary..." and then carry on as you would have.

You're not lying, you're sharing the same information you would have otherwise shared, and you're helping others. Plus, it looks better when others investigate you.

Title: Is mentioning my blog on my resume helpful or hurtful to a job search?

Body:
I have a blog that I use mostly to record solutions to problems I have had, that I had some trouble finding an answer to. Mostly problems where the online doc I googled provided too much info, and I found the answer to my question on the fifth page of my third google hit.

(Or if I asked the question here, I either didn't get an answer or I got slammed for asking a question that "the answer could be easily googled.")

I frequently look up stuff on this blog to remind myself of how I solved a problem, and it gets a decent amount of hits from others as well.

Anyway, I was wondering if mentioning this blog on my resume would help or hurt me in a job search? The topics are all over the map.

What I would hope it shows is that

I am a person who finds solutions to problems

I have used many different technologies in my work

I am not afraid to tackle a challenge

What I am concerned it shows is that

This person had trouble with something that simple?

Why is this person bothering to blog this stuff?


答:
You are assuming that you know what your code will look like before you write it. TDD/BDD is as much a design/discovery process as it is a QA process. For a given feature you write the simplest test that would verify that the feature is satisfied (sometimes this may require several because of a feature's complexity). That first test you write is loaded with assumptions of what the working code will look like. If you write the entire test suite before writing the first line of code to support it, you are making a litany of unverified assumptions. Instead, write one assumption and verify it. Then write the next. In the process of verifying the next assumption, you might just break an earlier assumption so you have to go back and either change that first assumption to match reality or change reality so that first assumption still applies.

Think of each unit test you write as a theory in a scientific notebook. As you fill out the notebook you prove your theories and form new ones. Sometimes proving a new theory disproves a previous theory so you have to fix it. It's easier to prove one theory at a time rather than trying to prove say 20 at once.


答:
Then you try to concentrate on too much things at a time.

While implementing to make all the tests pass you have no working version of your application. If you have to implement a lot then you will have no working version over a long time.

OwnerDisplayName: magomi


答:
TDD is a highly iterative approach, which (in my experience) fits better the real world ways of development. Usually my implementation takes shape gradually during this process, and each step may bring further questions, insights and ideas for testing. This is ideal to keep my mind focussed on the actual task, and is very efficient because I only need to keep a limited number of things in short term memory at any point in time. This in turn reduces the possibility of mistakes.

Your idea is basically a Big Test Up Front approach, which IMHO is more difficult to handle, and may become more wasteful. What if you realize midway through your work that your approach is not good, your API is flawed and you need to start all over, or use a 3rd party library instead? Then a lot of the work put into writing your tests up front becomes wasted effort.

That said, if this works for you, fine. I can imagine that if you work from a fixed, detailed technical specification, on a domain you are intimately experienced with, and/or on a fairly small task, you may have most or all the necessary test cases ready and your implementation clear right from the start. Then it might make sense to start by writing all tests at once. If your experience is that this makes you more productive in the long run, you needn't worry too much about rulebooks :-)

OwnerDisplayName: Péter Török


答:
You are describing BDD, where some external stakeholder has an executable specification. This may be beneficial if there is a predetermined up front specification (for example a format spec, industrial standard or where the programmer is not the domain expert).

The normal approach is then to gradually cover more and more acceptance tests, which is the progress visible to the project manager and customer.

You usually have this tests specified and executed in a BDD framework such as Cucumber, Fitnesse or some such.

However, this is not something you mix up with your unit tests, which are much closer to the nitty gritty implementation details with a lot of API related edge cases, initialization issues etc heavily focused on the item under test, which is an implementation artifact.

The red-green-refactor discipline has a lot of benefits, and the only upside you can hope for by typing them up front is to break even.

OwnerDisplayName: Tormod


答:
The Red-Green-Refactor cycle is a checklist intended for developers new to TDD. I'd say it's a good idea to follow this checklist until you know when to follow it and when you can break it (that is, until know don't have to ask this question on stackoverflow :)

Having done TDD for close to a decade I can tell you that I very seldom, if ever, write many failing tests before I write production code.

OwnerDisplayName: Torbjörn Kalin


问:
What standards to use in Business Process Modelling?
There are several approaches on how to model a business process in software applications (BPM software). For instance, a processes can be described in BPMN, EPC, IDEF0, SOMF, etc.

Additionally, different process execution languages such as BPEL, RPC, Wf-XML are available.

If I were to develop software for the BPM-market, which standards should I implement or focus on? Which standards are most suitable if my BPM software was going to be implemented in my client's IT-System?

答:
If you are going for an Enterprise market, taking an approach similar to IBMs might be useful.

See Business process standards, Part 1: An introduction which includes a short section on the relationship between the standards and Business process standards, Part 2: How the standards are used in WebSphere products which describes specifically how IBM incorporates them into their own products.

There is also Modeling Standards Supported by ARIS which includes the standards they support and pointing out that each standard is focused for

different stakeholders.

I believe that the full answer to your question depends on who you want to pitch your software to. A BA likely to model the process at a higher level than an Architect, who will likely want to specify some implementation and possibly shares some interest in code generation with the developer, who probably cares mainly about the execution.


答:
Probably not

This is a fine question @TheMoot.  It's been discussed a couple of times in slightly different wording (e.g. should I put my StackExchange profile on my resume, etc.)  The general consensus seems to be that pointing to websites is a double-edged sword and it's probably best to stick to a traditional resume format that lists your job experience and accomplishments on the job instead.

Besides, if your potential employer is really into a person's web presence, they'll be Googling your name anyways.


问:
Must developers understand the business domain or should the specification be sufficient?
I work for a company for which the domain is really difficult to understand because it is high technology in electronics, but this is applicable to any software development in a complex domain.

The application that I work on displays a lot of information, charts, and metrics which are difficult to understand without experience in the domain. The developer uses a specification to describe what the software must do, such as specifying that a particular chart must display this kind of metrics and this metric is the following arithmetic formula.

This way, the developer doesn't really understand the business and what/why he is doing this task. This can be OK if specification is really detailed but when it isn't or when the author has forgotten a use case, this is quite hard for the developer to find a solution.

At the other hand, training every developer to all the business aspects can be very long and difficult.

Should we give more importance to detailed specification (but as we know, perfect specification does not exist) or should we train all the developers to understand the business domain?

EDIT: keep in mind in your answer that the company could used external developers and that a formation to all the domain can be about 2 weeks

答:
The more involved that a developer becomes and the more senior in the business the more important it becomes to have at least mid-level domain knowledge or the more nuanced areas of that industry which may be critical won't be understood by the developer team.

However a specification should be suffcient for lower level tasks. In short, it's best to train your workforce to a lower level. They may be the best polyglot programmer in the world, but if they can not understand the issue fairly deeply they are always doomed to failure or death march programming.

OwnerDisplayName: Jerome C.

OwnerDisplayName: krystan honour


问:
Best practices for upgrading user data when updating versions of software
In my code I check the current version of the software on launch and compare it to the version stored in the user's data file(s).  If the version is newer, then I call different methods to update the old data to the newer data version, if necessary.

I usually have to make a new method to convert the data with each update that changes user data in some way, and cannot remove the old ones in case there was someone who missed an update.  So the app must be able to go through each method call and update their data until they get their data current.  With larger data sets, this could be a problem.

In addition, I recently had a brief discussion with another StackOverflow user this and he indicated he always appended a date stamp to the filename to manage data versions, although his reasoning as to why this was better than storing the version data in the file itself was unclear.

Since I've rarely seen management of user data versions in books I've read, I'm curious what are the best practices for naming user data files and procedures for updating older data to newer versions.

Edit:
The 'date stamp' stemmed form a discussion here:

https://stackoverflow.com/questions/8104812/does-releasing-a-new-version-of-the-app-delete-files-of-the-older-one/8104906#8104906

Since the question is too open-ended, I should say I'm looking for the recommended procedures for upgrading user data between versions.

If possible, it would be nice to see iOS / objective-c practices, but it's not required.

答:
As you've noted there is no real advantage of a date over the version number.  And you do need to keep old conversions in order to support people who skip updates (my wife is bad at that).

One thing you might think about is some kind of inventory of the number of people on each version so you would know when you could drop old updates.  Apple should be able to provide you with those statistics (but I have no clue if they do).  Or you could possibly add a ping function that would send you the version number and some unique id each time the app is run for the first time after an installation or upgrade.


答: The specification is virtually never sufficient. Developers who do not have domain knowledge cannot point out when the specification is in error (a frequent occurence most places) and make poor design choices.</p>

Title: Must developers understand the business domain or should the specification be sufficient?

Body:
I work for a company for which the domain is really difficult to understand because it is high technology in electronics, but this is applicable to any software development in a complex domain.

The application that I work on displays a lot of information, charts, and metrics which are difficult to understand without experience in the domain. The developer uses a specification to describe what the software must do, such as specifying that a particular chart must display this kind of metrics and this metric is the following arithmetic formula.

This way, the developer doesn't really understand the business and what/why he is doing this task. This can be OK if specification is really detailed but when it isn't or when the author has forgotten a use case, this is quite hard for the developer to find a solution.

At the other hand, training every developer to all the business aspects can be very long and difficult.

Should we give more importance to detailed specification (but as we know, perfect specification does not exist) or should we train all the developers to understand the business domain?

EDIT: keep in mind in your answer that the company could used external developers and that a formation to all the domain can be about 2 weeks


答:
SOMEONE on the project needs to have fairly complete domain knowledge. That person may or may not be the developer.

In Agile projects, the client project owner is that person, and they're working collaboratively and closely with the team. In non-Agile projects, somebody on the team needs to acquire that knowledge, but they usually don't, which is one reason why non-Agile projects are so failure-prone.


答: Yes developers need to know the business to a degree.  They don't have to know every minute detail, but they should have a basic understanding of what report X is used for and how its used in the business process. The more your developers understand about the business the better the solution they can deliver.</p>


答:
There should always be some specification - you can't expect all developers to become domain experts. At the same time, if the developers blindly follow a spec without really understanding what it's for, the result may not really be what the clients want. It often happens that when a developer has even a somewhat decent (but not expert) level of understanding, they can catch errors and omissions in the specs. They can also contribute and give feedback to the process which can make the final product much better.

It might be worth hiring some domain experts whose job it is to liason between the clients and developers to help give the developers a better understanding and also to help write the spec.


答:
I think you should try to get the domain knowledge.  Specs are check list saying what the end product should do and is required for the validation of your product. As developer you should always try to understand what is the real problem you are trying to solve. Getting the domain knowledge will help you understand that.

It will help you design and code easily as you will understand what are changing parts (say rule set) and put them separately. You do not need to be a master at it but would be able to speak to a end user in their language.

You can drive a car with basic knowledge of it; but in case you want to enjoy the ride you need to learn more on how to use it exactly. As with other trades, it is not mandatory to understand the domain, but it is fun when you do it.


答:
I think this hard to give an answer either way.

It's hard to see how, say, a freelance developer can understand the business (or science) behind every single application they develop. In this situation, I think it is more important that the developer knows to ask the right questions about the spec or business model than to really understand the business itself.

An enterprise developer on the otherhand, assuming they have been in the same business for a while, really ought to have learned how the business works after a few months (or years perhaps). In large team you might also have an architect who understands the business more clearly than the developers.

In SMEs with lone developers it is important that the developer has frequent discussions with the owners/managers to avoid going off and implementing the wrong thing.

So there are lots of possible ways of thinking about this, but the key is the same in all cases: communication.


答: Software development is the only profession I know of that requires you to not only be proficient in your own profession but have a basic understanding of the profession that you are working in.  It is important to have enough understanding of the domain to communicate with clients and other developers in the language of the client.  As a developer you cannot always rely on others to train you.  Sometimes you have to ramp up on your own with personal research, often times outside of typical work hours.</p>