问:
How would you design a programming language?
If you were to design a programming language, how would you do it? What features would you put in? What would you leave out? Statically or dynamically typed? Strongly or weakly typed? Compiled or interpreted? Justify your answers.</p>

答:
First of all, I would buy a few books on compilers, a few standards, and take a course or two in languages and compilers.  I'd contribute PEPs and visit C++ standards committee meetings.  I'd contribute patches to the compilers I use, hopefully both for features and bugs.

Then I'd go back and look in horror at this list that I've come up now, which is of what directions I'd go in with a language if I started right now:

Functional, because I currently am not well-versed in any functional languages and making one would be a great way to learn one.  In case it doesn't follow directly:  everything is constant.

I'd fill it with as much Type Inference as I could fit in it, but with the option to specify interfaces explicitly.  Not sure about other types.  This doubles up as all functions being generic by default.

As you may have guessed, with Interfaces; that is, with types that only provide promises on available operations.

Saying whether the language is strongly or weakly typed isn't very meaningful in this case, as far as I can tell.  I would call it strongly typed, as things never change what interfaces they implement.

It would have a lot of Design by Contract support.  Again, as much as I can fit: preconditions and postconditions are a must; I don't know how much invariants matter when it comes to functional programming.

While I'm at it, I'd take a look at languages where you can formally prove correctness and see if I can pick up anything from there.

I would go out and write an awesome testing library.  Even in case I fail to make it awesome, I'll at least spend a considerable amount of time working on it as I think it's something every language should have.

As for the syntax, the language would either have significant whitespace and look a lot like Python, or it would be based on Lojban and sharing a lot of the grammar and vocabulary.  In the first case, I would do my absolute best to make the grammar as close to a CFG as possible.

I would not care whether people who implemented the language would compile it beforehand, JIT it, interpret it, chant it at campfires, or pay college kids to execute it for them.  My own implementation would probably start out as an interpreter or a C compiler, and eventually move towards a JITter.

Seeing as even these fairly broad points would probably quickly change if I started implementing the language, so I think that going into further detail is unnecessary.


问:
Why are cons lists associated with functional programming?
I have noticed that most functional languages employ a singly-linked list (a "cons" list) as their most fundamental list types. Examples include Common Lisp, Haskell and F#. This is different to mainstream languages, where the native list types are arrays.

Why is that?

For Common Lisp (being dynamically typed) I get the idea that the cons is general enough to also be the base of lists, trees, etc. This might be a tiny reason.

For statically typed languages, though, I can't find a good reasoning, I can even find counter-arguments:

Functional style encourages immutability, so the linked list's ease of insertion is less of an advantage,

Functional style encourages immutability, so also data sharing; an array is easier to share "partially" than a linked list,

You could do pattern matching on a regular array just as well, and even better (you could easily fold from right to left for example),

On top of that you get random access for free,

And (a practical advantage) if the language is statically typed, you can employ a regular memory layout and get a speed boost from the cache.

So why prefer linked lists?

答:
I think it comes down to lists being rather easily implemented in functional code.

Scheme:

```<code>(define (cons x y)(lambda (m) (m x y)))
</code>```

Haskell:

```<code>data  [a]  =  [] | a : [a]
</code>```

Arrays are harder and not nearly as pretty to implement. If you want them to be extremely fast then they'll have to be written low-level.

Additionally, recursion works much better on lists than arrays. Consider the number of times you've recursively consumed/generated a list vs indexed an array.

ContentLicense: CC BY-SA 3.0

Body:
I think it comes down to lists being rather easily implemented in functional code.

Scheme:

(define (cons x y)(lambda (m) (m x y)))

Haskell:

data  [a]  =  [] | a : [a]

Arrays are harder and not nearly as pretty to implement. If you want them to be extremely fast then they'll have to be written low-level.

Additionally, recursion works much better on lists than arrays. Consider the number of times you've recursively consumed/generated a list vs indexed an array.


问:
How to manage github issues for (priority, etc)?
I'm new to github, and am looking for advice on how to manage issues.  I'm used to having priority and other ordering options but see that none exist.

How do others manages issues during the lifecycle of a bug/feature?

Thanks in advance.

答:
You could define different groups of labels like issue types, issue priorities, issue statuses, version tags, and maybe more. In order to be able to see instantly to which group a label belongs to you could use a naming convention like :.

Using such a naming convention should make managing Github issues much easier and helps others to "understand" issues much faster. Note that you can also assign colors to labels which can add even more to readability (I would use a specific color for each label group). But because you still have to assign/unassign those labels to/from issues manually you might want to keep the overall list of groups/labels small.

According to the scheme suggested above you might define groups and corresponding labels as follows.

'issue type' group

type:bug

type:feature

type:idea

type:invalid

type:support

type:task

'issue priority' group

prio:low

prio:normal

prio:high

'issue status' group

(These labels describe an issue's state in a defined workflow.)

status:confirmed

status:deferred

status:fix-committed

status:in-progress

status:incomplete

status:rejected

status:resolved

'issue information' group

info:feedback-needed

info:help-needed

info:progress-25

info:progress-50

info:progress-75

'version tag' group

ver:1.x

ver:1.1

OwnerDisplayName: djf

Body:
You could define different groups of labels like issue types, issue priorities, issue statuses, version tags, and maybe more. In order to be able to see instantly to which group a label belongs to you could use a naming convention like <label-group>:<label-name>.

Using such a naming convention should make managing Github issues much easier and helps others to "understand" issues much faster. Note that you can also assign colors to labels which can add even more to readability (I would use a specific color for each label group). But because you still have to assign/unassign those labels to/from issues manually you might want to keep the overall list of groups/labels small.

According to the scheme suggested above you might define groups and corresponding labels as follows.

'issue type' group

type:bug

type:feature

type:idea

type:invalid

type:support

type:task

'issue priority' group

prio:low

prio:normal

prio:high

'issue status' group

(These labels describe an issue's state in a defined workflow.)

status:confirmed

status:deferred

status:fix-committed

status:in-progress

status:incomplete

status:rejected

status:resolved

'issue information' group

info:feedback-needed

info:help-needed

info:progress-25

info:progress-50

info:progress-75

'version tag' group

ver:1.x

ver:1.1


问:
How can I prevent programmers from capturing data entered by users?
I'm developing a web application with a strong focus on security. What measures can be taken to prevent those who work on the application (programmers, DBAs, quality assurance staff) from capturing user entered values that should be well-protected, such as passwords, social security numbers, and so forth?</p>

答:
The programmers don't have access to the production servers. But someone has to have access. There's no way around it. And there's always a chance that someone may go insane and abuse their access.

Data that is hashed/salted is theoretically secure even from the people who have full access to view it. But most data is not appropriate for hashing.


问:
What to do (or not do) when a developer doesn't deliver the goods?
I've recently had the misfortune of hiring a developer who failed to deliver a working product by the arranged date.
I have the software, but it produces errors on installation. The developer said the product works.

I had wanted to give the developer the benefit of the doubt, but they have ignored all requests to show me a working demo. I set up a website specifically so that they could install the software, but they have done nothing (it should be a matter of uploading the zip and changing a few things in the configuration). They have also ignored all requests for information on their configuration. Actually it is really difficult to get any reply from them at all.
It is almost 1.5 months after the deadline.

Possible ideas

Have a third party check the software.

Put in a claim with Paypal    (although I think it is too late and
isn't covered anyway).

Make it public (I'm assuming it isn't defamation because it is
true).

QUESTION: What should I do (or not do) about this?

EXTRA

I've noticed that even if the software was to work there are a number
of features that I requested (prior to their acceptance of the job)
that they have ignored.

I've found comments on the web about the company saying that this situation is
normal for them. They seem to use errors in their software as an
excuse to extort more money from their clients. Actually this was a relief as it backed up my belief that I'd been scammed.

They don't have a phone number on their website.

The developer is based in the US.

EDIT:

The arrangement was that I paid 25% of the cost of the development. The developer would keep all rights for the product. The product was integrating an already existing open source component with a CMS. I produced icons and did the styling for part of the component (completed). The developer would have the component done with the features I requested by mid December.

EDIT2:
The developer said that they would be able to provide all the features I requested.

EDIT3:
There is no documentation with the software.

答: You have the right to sue, if you paid for work that didn't actually function. That is a significant threat, but be prepared to compensate for a refund.</p>

OwnerDisplayName: moomoochoo


答:
From the attitude you have described, I don't think you can comfortably rely on the code you have even if some of the functions work.

The guys don't look professional and I would not use such a software for anything serious. As a result hiring a consultant to look at it won't really work well if the software is large. It is not easy to evaluate the correctness of a software you don't know about without serious work.

I guess it all depends on how much the 25% you paid represent to you...?

If the amount is not that large, then taking them to court may cost you more money and effort than what you have paid. Also, publishing the information may again cost you.

If the amount you paid is not significant, I suggest you leave it at that. This is of course not a happy decision but I think it may be the least expensive in terms of effort and money. You could also ask a lawyer about the expected fee the lawyer would ask for and take that into account. But when it comes to law, consider that you may not win. It is always possible.

Title: What to do (or not do) when a developer doesn't deliver the goods?

Body:
I've recently had the misfortune of hiring a developer who failed to deliver a working product by the arranged date.
I have the software, but it produces errors on installation. The developer said the product works.

I had wanted to give the developer the benefit of the doubt, but they have ignored all requests to show me a working demo. I set up a website specifically so that they could install the software, but they have done nothing (it should be a matter of uploading the zip and changing a few things in the configuration). They have also ignored all requests for information on their configuration. Actually it is really difficult to get any reply from them at all.
It is almost 1.5 months after the deadline.

Possible ideas

Have a third party check the software.

Put in a claim with Paypal    (although I think it is too late and
isn't covered anyway).

Make it public (I'm assuming it isn't defamation because it is
true).

QUESTION: What should I do (or not do) about this?

EXTRA

I've noticed that even if the software was to work there are a number
of features that I requested (prior to their acceptance of the job)
that they have ignored.

I've found comments on the web about the company saying that this situation is
normal for them. They seem to use errors in their software as an
excuse to extort more money from their clients. Actually this was a relief as it backed up my belief that I'd been scammed.

They don't have a phone number on their website.

The developer is based in the US.

EDIT:

The arrangement was that I paid 25% of the cost of the development. The developer would keep all rights for the product. The product was integrating an already existing open source component with a CMS. I produced icons and did the styling for part of the component (completed). The developer would have the component done with the features I requested by mid December.

EDIT2:
The developer said that they would be able to provide all the features I requested.

EDIT3:
There is no documentation with the software.


问:
What is O(...) and how do I calculate it?
Help! I have a question where I need to analyze the Big-O of an algorithm or some code.

I am unsure exactly what Big-O is or how it relates to Big-Theta or other means of analyzing an algorithm's complexity.

I am unsure whether Big-O refers to the time to run the code, or the amount of memory it takes (space/time tradeoffs).

I have Computer Science homework where I need to take some loops, perhaps a recursive algorithm, and come up with the Big-O for it.

I am working on a program where I have a choice between two data structures or algorithms with a known Big-O, and am unsure which one to choose.

How do I understand how to calculate and apply Big-O to my program, homework, or general knowledge of Computer Science?

Note: this question is a canonical dupe target for other Big-O
  questions as determined by the community. It is intentionally
  broad to be able to contain a large amount of useful information for
  many Big-O questions. Please do not use the fact that it is this broad
  as an indication that similar questions are acceptable.

答:
The O(...) refers to Big-O notation, which is a simple way of describing how many operations an algorithm takes to do something.  This is known as time complexity.

In Big-O notation, the cost of an algorithm is represented by its most costly operation at large numbers. If an algorithm took n3 + n2 + n steps, it would be represented O(n3). An algorithm that counted each item in a list would operate in O(n) time, called linear time.

For a list of the names and classic examples on Wikipedia: Orders of common functions

Related material:

Plain English explanation of Big O (SO)

Understanding of big-O massively improved when I began thinking of orders as sets. How to apply the same approach to big-Theta?

Is there a system behind the magic of algorithm analysis? (CS.SE)

A beginner's guide to Big O notation

Algorithms: Design and Analysis

ContentLicense: CC BY-SA 4.0


答:
I think this falls under the category of "Stupid-Tax" I suspect that your best bet is to consider it an expensive lesson and move on. Any attempts to recover the money you already spent will probably be more expensive than its worth. For example Spending $5,000 to get back $6,000 seems kind of pointless.

In future I would demand weekly updates with demos. Don't expect a final product after 4 months, but know that every Monday they will show you what they have done in the past week. Or even do a daily stand up via video conference

Stupid Tax is a term I borrowed from Dave Ramsey it refers to the times when you do something dumb that costs you money.


问:
What's the best practice for rendering a different GSP template based on the type of object in a collection?
Let's say I have a collection that is setup in my controller, named "things."  In this collection is a heterogeneous assortment of objects.  Let's say some are of type "Thing" and some others are of type "OtherThing".  In the GSP
page that renders this list, I want to render each different object type
differently.

I know that the following code works, but I can't escape the feeling that there should be a more elegant way to do this.  Does anybody have a better way?

```<code>        <div id="eventStream">

        <ul>
            <g:each in="${things}" var="thing">

                <g:if test="${thing.type.equals( 'Thing' )}">
                    <g:render template="/renderThing" bean="thing" />
                </g:if>

                <g:if test="${thing.type.equals( 'OtherThing')}">
                    <g:render template="/renderOtherThing" bean="thing" />
                </g:if>

            </g:each>
        </ul>

    </div>
</code>```

(Note: there is a "type" field defined on 'Thing' and 'OtherThing' that contains those string literals.  That's just a shortcut).

EDIT:  Just realized that there's another way to do this, that depends on the notion of "convention over configuration."  I could just go with a convention that the templates are always named something like:

_renderXXXXTemplate.gsp where XXX is "Thing" or "OtherThing" or whatever.  Then I just render with something like:

```<code><g:render template="/render${thing.class.name}Template" bean="thing" />
</code>```

Anybody care to share their thoughts on the merit of that approach?

答:
I hate explicit type-checks.  I would probably start by creating a private tag to render this part of the page.

```<code><myApp:renderThing object="${thing}" />
</code>```

Then I would probably add an abstract method to the base class to return the template name.  Sure, it mixes presentation logic into the business classes but it will simplify maintenance considerably.

```<code>abstract class Thing {
    public abstract String getTemplateName();
    ...
}

public class ThingOne extends Thing {
    public String getTemplateName() { return "templateForThingOne" }
    ...
}
</code>```

Another idea would be to derive the template name from the class name, and add a note in the base class to remind developers to create the appropriate template for any subclass.

Body:
I hate explicit type-checks.  I would probably start by creating a private tag to render this part of the page.

<myApp:renderThing object="${thing}" />

Then I would probably add an abstract method to the base class to return the template name.  Sure, it mixes presentation logic into the business classes but it will simplify maintenance considerably.

abstract class Thing {
    public abstract String getTemplateName();
    ...
}

public class ThingOne extends Thing {
    public String getTemplateName() { return "templateForThingOne" }
    ...
}

Another idea would be to derive the template name from the class name, and add a note in the base class to remind developers to create the appropriate template for any subclass.


问:
Which is better SICP or HTDP
I have read that SICP (Structure and Interpretation of Computer Programs)  is hard and HTDP (How To Design Programs) is better as an introductory course.
I would say I am fairly good in maths but not a genius.So how hard is SICP, is it harder than knuth or cormen. </p>

答:
Difficulty varies from person to person. I've read SICP, Art of Computer Programming, and Intro to Algorithms and I found them easy - however, I had a great teacher in all my classes, a lot of support from other students and teaching fellows as well as help online. Furthermore, I've always loved both math and computer programming, and I excel in those subjects.

As far as compartively, I'd say SICP, Art of Computer Programming, and Intro to Algorithms are all around the same level of difficulty, perhaps SICP being slightly easier in some ways.

HTDP is probably easier. As far as which is better, is really anyone's guess. I'd bet that a lot of people on here prefer SICP simply because it's what they learned with.

Title: Which is better SICP or HTDP


问:
What benefits are there to native JavaScript development?
Given how much simpler jQuery development is, when compared to native JavaScript, what makes people forgo libraries like jQuery altogether?

Is this because jQuery has limitations or it is slow? I mean, if jQuery is so easy compared to native javascript, what reasons do people have to still use pure javascript?

答:
Let's talk about cars.

Oh wait, we already did - remember that time we met, some time ago? We talked about cars. In fact, you seemed to be quite the expert on cars. You were able to explain, in detail, all of what's right, wrong, and exciting about the latest Formula 1 race. You knew by heart all of Lamborghini's models, including their price and availability. You even had thoughts of purchasing your own Ferrari 599 GTB Fiorano and were saving up for it (I bet the steak dinner didn't help much).

While explaining the faults of Toyota in a great, excited voice, you suddenly jumped from your chair and screamed into the air, waving your fists about: "Damn it all, I'm a magnificent expert on all things related to cars! I'm going to be a car mechanic!"

And so you went. You had an interview, the Boss Man was just as impressed as I with your knowledge, and you were hired. The first client came in. His clutch was broken. You inspected it and didn't know what to do. As a matter of fact, you had absolutely no idea how to follow the advice the Boss Man gave you. You were fired.

But how could that be!? You know everything about cars! Except for ... everything about cars. You can very well know your dream car has a V12 engine, but you don't know what that actually means.

So you're not a car mechanic, really - you're a car enthusiast. And until you learn how cars work, you will remain an enthusiast.

Now let me ask you. How does $.fn.text work? And what about $.fn? What do they really mean? How does $(something) return a gigantic thingy containing things, and what is that thingy exactly? Can you replicate their functionality, at least a bit, in theory even? Can you cope without jQuery?

Saying that "native JavaScript is hard" is just ... false. First and foremost, because JavaScript as a language has nothing to do with the DOM, which is mainly what jQuery abstracts. Second because once you learn a bit about the DOM, you can already cruise through the most common cross-browser bugs. But just a little secret - everything is hard at first. Long division was a bitch in 5th grade.

As a second analogy for this answer: jQuery is to JavaScript-DOM (not JavaScript the language, just the DOM) like Array.prototype.forEach is to for. It works, for 99% of the cases. And it works well. But for that 1% which isn't covered, you need to know how to use the for loop, if only to be practical. This entire answer is based on the "purer" side of the question, and not even the technical side (the library's size, for example, and several other things as explained in Michael Dorrant's answer). Because I love JavaScript and when people seem to just throw it aside casually saying "pah, those silly javascriptians" and waving fancy white gloves, it gets down to morality.

If you can accept the fact that you'll always be a JavaScript enthusiast, then who am I to stop you? But if you want to be a JavaScript programmer, you first have to have the knowledge to at least choose between using jQuery (or any other library) and not using a library. Learn the DOM. Learn how to use it. Write your own small library or just some collection of helper functions. And once you are knowledgeable of the DOM, and you choose to use jQuery - godspeed. Laziness is awarded for those who worked hard.

OwnerDisplayName: Mike


答:
If you don't need DOM abstraction, cross-browser and legacy browser support - you can easily go without jQuery.

This is the case when you are developing browser extensions, greasemonkey scripts (sometimes), number-crunching stuff, developing for Node.js or other non-browser environments.

Title: What benefits are there to native JavaScript development?

Body:
Given how much simpler jQuery development is, when compared to native JavaScript, what makes people forgo libraries like jQuery altogether?

Is this because jQuery has limitations or it is slow? I mean, if jQuery is so easy compared to native javascript, what reasons do people have to still use pure javascript?


问:
Why are developer commit statistics harmful?
I have long believed (and heard from others) that keeping track of commit statistics, such as how many commits each developer makes per day, is harmful to the development process. The reason seems obvious - developers will commit in smaller increments, maximising their commit-per-day number, but making it harder to bisect (perhaps all their intermediate patches won't leave the repo well formed) and harder to work with the commit history (a change will suddenly be in multiple commits, instead of just one, reverting a patch is harder etc).

Are there any studies that show commit statistics are harmful? Any elegant and well-argued article on the topic? Equally applicable would be anything about why measuring the wrong thing leads to people optimising the wrong thing, which this problem is just a special case of.

答:
http://www.mit.edu/~hauser/Papers/Hauser-Katz%20Measure%2004-98.pdf

Is this the kind of thing you're looking for?  There are thousands of "you only get what you measure" articles found by Google.


答:
It is a fun statistic to measure, but no more useful than recording the number of hours a developer worked during the week.

For one, it doesn't take into account code quality. One developer might be committing continually as he keeps on fixing bugs in his code. This would show large number of commits, compared to a developer who commits one chunk of finished, polished code. You wouldn't think that the guy with the bigger commit count was the better developer.

Similarly, someone who slacks off and surf SO all day long only to commit once a day would have the same commit count as the dedicated developer who spent all day coding only to do a final commit at day-end to keep his code safe.

If you have a system where lines of code committed is counted, the guy who goes through the source files 'refactoring' every curly bracket to his preferred style will have a huge value. The guy who did the 1-line sup-important bugfix will barely show up.

So it doesn't make any meaningful statistic even if developers don't game the system. It should provide you with nothing except a pretty graph. However everyone likes stats so I'd say keep them, but don't use them for anything other than fun.

Title: Why are developer commit statistics harmful?

Body:
I have long believed (and heard from others) that keeping track of commit statistics, such as how many commits each developer makes per day, is harmful to the development process. The reason seems obvious - developers will commit in smaller increments, maximising their commit-per-day number, but making it harder to bisect (perhaps all their intermediate patches won't leave the repo well formed) and harder to work with the commit history (a change will suddenly be in multiple commits, instead of just one, reverting a patch is harder etc).

Are there any studies that show commit statistics are harmful? Any elegant and well-argued article on the topic? Equally applicable would be anything about why measuring the wrong thing leads to people optimising the wrong thing, which this problem is just a special case of.


问:
Are C and/or C++ viable/practical options for web development?
I am proficient in C, and I am learning C++ right now. I always played with websites (HTML/CSS), and I was wondering if it would be viable/practical to create some simple web apps using C and/or C++.

For C it would be via CGI scripts, as explained in this tutorial for example -> http://www.cs.tut.fi/~jkorpela/forms/cgic.html

For C++ it could be via a web toolkit like Wt -> http://www.webtoolkit.eu/wt

Notice that I know it's possible (as explained in this previous question -> Can C++ be used as a server-side web development language? ).

What I am asking is if it's viable/practical (i.e., not a nightmare). I am not keen on picking up another language yet as I just started with C++, but if it would make web dev incredibly easier I will consider it (or I'll postpone my web dev projects until I am ready to pick up a new language).

Also, in case you think it's viable/practical, recommendations on the route to follow would be highly appreciated (i.e., forget C and go with C++, what framework to use and so on).

答:
I can recommend the mongoose library as a web interface for C based programs, I have used it multiple times and it's very easy to use.

Though maybe PHP is a better option for web development than C or C++. It's easy to learn once you know C and C++ (the syntax is very similar). You can save more effort with learning PHP than struggling with C and C++ for web development . . .


问:
Should we rename overloaded methods?
Assume an interface containing these methods :

```<code>Car find(long id);

List<Car> find(String model);
</code>```

Is it better to rename them like this?

```<code>Car findById(long id);

List findByModel(String model);
</code>```

Indeed, any developer who use this API won't need to look at the interface for knowing possible arguments of initial find() methods.

So my question is more general :
What is the benefit of using overloaded methods in code since it reduce readability?

答:
This is a relatively minor issue compared to many other bad readability practices you could be susceptible to, so I'd say it's mostly a matter of taste how you name your methods.

With that said, if you are going to do something about it, I would follow this practice:

Overload if...

The methods obey nearly the same contract but simply operate on different input (imagine a phone operator who can look up your account by your personal tax ID number, your account number, or your name and birthday).  This includes returning the same type of output.

Use a different name if...

The methods do substantially different things or return different output (like your case). You might consider using a different name if one accesses the database and one does not.

In addition, if the type returned is different, I would also change the verb to indicate that:

```<code>Car findById(long id);

List findAllByModel(String model);
</code>```

Title: Should we rename overloaded methods?

Body:
This is a relatively minor issue compared to many other bad readability practices you could be susceptible to, so I'd say it's mostly a matter of taste how you name your methods.

With that said, if you are going to do something about it, I would follow this practice:

Overload if...

The methods obey nearly the same contract but simply operate on different input (imagine a phone operator who can look up your account by your personal tax ID number, your account number, or your name and birthday).  This includes returning the same type of output.

Use a different name if...

The methods do substantially different things or return different output (like your case). You might consider using a different name if one accesses the database and one does not.

In addition, if the type returned is different, I would also change the verb to indicate that:

Car findById(long id);

List findAllByModel(String model);


答:
For server-side applications, then the answer is absolutely yes. Many large sites use C++ simply to provide the performance and resource usage that scripting languages don't. Many years ago a lot of web server code was written in C++ anyway (see things like Microsoft's ISAPI or ATLServer frameworks) or just as CGI applications. This changed when the web became more popular and needed faster development turnround. A script language is always going to be faster to develop, especially when you're just 'knocking something together', and was always very popular with junior developers getting in to programming.

As proof look to the most popular language for web development, PHP. Its a fine environment in which to work but no-one will say its the best language in the world.

Today, I'd hope that things have matured to a point where the server-side backend should be written with as much professional care as any other application. That means C++ can make a comeback in web development (and I think MS is going that way, as Herb Sutter reported that C++ will reduce the energy requirements in the data centre, which with huge datacentres we have today means a significant cost saving. Hence the C++ renaissance at MS, though I'm not convinced that'll turn into anything beyond system software for them)

One thing to note though: it is trivial to write C++ backend software that sit as services that are called from simple scripts on the web server. I did this with my old place of work - the web server was there solely to provide a pass-through to the application services. This allowed us to provide much better security (anyone hacking the exposed webserver got very little to work on), much better performance (as the business logic was distributed on servers that didn't web-serve), and they were very easy to test - the back-end services were stand-alone and provided explicit and well-defined interfaces so they could be tested without the web part of the total infrastructure.

There are some interesting developments in C++ as web server client code too. I saw Wt recently. This allows you to write Qt code but have the GUI display in the browser - the gadgets displayed on the browser are just thin javascript/html/etc that transparently call into the Qt/C++ code running on the server. Have a go with their Hangman example (though they get 0/10 for the graphics, typical developers :) )

I think this is a natural evolution of RPC mechanisms, where once we could run an object  locally or remotely without (as a developer) caring where the object was located, now we can disconnect GUI from objects in a web browser rather than a desktop app.

Title: Are C and/or C++ viable/practical options for web development?

Body:
I am proficient in C, and I am learning C++ right now. I always played with websites (HTML/CSS), and I was wondering if it would be viable/practical to create some simple web apps using C and/or C++.

For C it would be via CGI scripts, as explained in this tutorial for example -> http://www.cs.tut.fi/~jkorpela/forms/cgic.html

For C++ it could be via a web toolkit like Wt -> http://www.webtoolkit.eu/wt

Notice that I know it's possible (as explained in this previous question -> Can C++ be used as a server-side web development language? ).

What I am asking is if it's viable/practical (i.e., not a nightmare). I am not keen on picking up another language yet as I just started with C++, but if it would make web dev incredibly easier I will consider it (or I'll postpone my web dev projects until I am ready to pick up a new language).

Also, in case you think it's viable/practical, recommendations on the route to follow would be highly appreciated (i.e., forget C and go with C++, what framework to use and so on).


问:
How to stop the development spec from changing in mid development?
Problem: It seems with almost every development effort I'm involved in, no matter how much time is spent planning prior to starting development, there is always a large amount of changes required either midway or towards the end of the project. These are sometimes big changes which require alot of re-development.

I don't work for clients who pay money, this is an in-house development team on in-house development websites. So, it's not like I can charge for it or anything. And at the end of the day, we have to try to hit deadlines.

Questions: What are some of the best ways you guys have found to minimize and prevent spec changes from cropping up midway or after development?

答: I've found that, directly or indirectly, customers are the cause of most changes (and also most critical bugs, BTW).  So the obvious solution is to eliminate customers.  (What good are they anyway?)</p>


问:
As a Junior Software Engineer should I say that something has been done wrong if I feel so?
I recently joined a company and it is my first job. When reading the code base, I felt that the code was not well written. It seemed to me that the code had most of the problems mentioned here and also seemed to have an Anemic Domain Model. There are no unit tests and they don't employ any code quality checking tools like findbugs or pmd. The problem I have is that the code is very difficult to understand. Maybe my conclusions are wrong because I am not that experienced. I need advice on whether to communicate the above facts to a superior or not. If I am to communicate, to whom(Tech Lead, Architect, Product Manager) and how? And if I do communicate will they take it badly since I'm a Junior and has no experience?</p>

答: Ask any senior developer on your team. Don't tell them you think it's wrong. Instead, Tell them you don't understand the code and are curious why it is developed the way that it is. Ask them to explain the code to you.</p>


答:
Asking for an explanation of the code in a non-confrontational manner from a senior developer or someone who knows enough about the structure and details of the code is a good idea.

Make sure to ask about the details (why the code is the way it is) you are questioning and make note of what the answer is. If after the explanation is given and you are not satisfied, dig into the problem a bit more and create a case and be prepared to back it up. Present it to whomever helped you first and ask them what they think of your findings and work from there.

Depending on your culture of your workplace, you may wind up waiting for an opportunity to have someone go over the code with you. Take this time to look into the issue more if at all possible. A junior developer is generally not expected to be very experienced and situations like this will arise.

Title: As a Junior Software Engineer should I say that something has been done wrong if I feel so?

Body: I recently joined a company and it is my first job. When reading the code base, I felt that the code was not well written. It seemed to me that the code had most of the problems mentioned here and also seemed to have an Anemic Domain Model. There are no unit tests and they don't employ any code quality checking tools like findbugs or pmd. The problem I have is that the code is very difficult to understand. Maybe my conclusions are wrong because I am not that experienced. I need advice on whether to communicate the above facts to a superior or not. If I am to communicate, to whom(Tech Lead, Architect, Product Manager) and how? And if I do communicate will they take it badly since I'm a Junior and has no experience?</p>


答:
In reality, the answer is "no". Words like "good" or "bad" are only used by management. To define what is "good" you must become management. Whether or not this is what you want is your preference.

I am not myself a programmer (well, not by job secription anyhow), but I work with/know many programmers. I know a woman, for instance, who is low-level management for [insert majeor telecom company] and man who is a senior design engineer for [insert major audiovisual co]. The woman is always going on about how it's "insulting" and "unreasonable" for a person of her carreer level and experience to be expected to learn new languages. The man started doing ARM development but doesn't want to use "unfinished" software like eclipse so he's always bugging me to pirate paid tools. Moral of the story - bad code exists for all kinds of reasons. Pointing it out won't make you any friends.

That said, if you really do want to do this the other advice presented here is really the way to go.


答:
In addition to what @Bryan Oakley says, I suspect the only explanation for the lack of unit tests is that the team never feels they have the time to write them,  This is a common dilemma, and it also makes refactoring extremely difficult.

So, I'd suggest that the most constructive course you could take is to volunteer to write unit tests for the code--perhaps as a way to "get a better understanding" of it.  This could solve one of the major smells you've encountered while opening the door to fix others.


答:
http://teddziuba.com/2010/05/why-engineers-hop-jobs.html

I spent too many after-work evenings stressed and unhappy because yet another chap does not understand or care how software business works. I have no problem confronting anyone higher up, but I do not have the backing of my fellow nerds. Having kids is a bitch, eh? I will likely quit soon.

Frankly, I wish programmers in general had more balls. Let's look at this:

"""I don't work for clients who pay money, this is an in-house development team on in-house development websites. So, it's not like I can charge for it or anything. And at the end of the day, we have to try to hit deadlines."""

If you were dealing with a $-paying client and if you covered your ass by having a contract (http://vimeo.com/22053820?utm_source=swissmiss), then changes in spec would cost this client more time AND more money (or potentially same or less time but exponentially more money). Your company is trying to get away with changing the spec without incurring the cost of more time and more money.

In the mean time, trying to hit deadlines causes you and your co-workers UNNECESSARY stress; you cannot spend a quality weekend with friends/family. It really is unnecessary, because whoever is throwing work at you probably do not even know it, which is sad.

My proposed solution: collectively have the balls to confront them and explain that there is no free lunch and everything has cost, that an auto-mechanic would take longer and charge more if specs were changed mid-work, that a contracting agency would take longer and charge more if specs were changed mid-work, and there is a good reason for it. If they are not willing to work with you in a reasonable manner, then you as a group will get up and leave, and they will have to hire developers who can pick up the project where it was left off and deliver on time.

Then there is also a promise of agile development, which implies no hard deadlines.

I am yet to see programmers go on strike, but this would have been something. Incompetent managers are too abundant in software companies. Way too many people want to get something for nothing, on Craigslist or within an actual company. http://teddziuba.com/2011/07/the-craigslist-reverse-programmer-troll.html

Programmers need to have more balls.

Title: How to stop the development spec from changing in mid development?

Body:
Problem: It seems with almost every development effort I'm involved in, no matter how much time is spent planning prior to starting development, there is always a large amount of changes required either midway or towards the end of the project. These are sometimes big changes which require alot of re-development.

I don't work for clients who pay money, this is an in-house development team on in-house development websites. So, it's not like I can charge for it or anything. And at the end of the day, we have to try to hit deadlines.

Questions: What are some of the best ways you guys have found to minimize and prevent spec changes from cropping up midway or after development?


答:
About the Anemic Domain Model. I too was confused about objects that are used like structs with getter/setters. I don't particuarly like how it is used for EVERYTHING especially in Java projects. There is a case for this design though.

A system may have multiple computers using multiple languages. The objects could be used by javascript in a browser, a C++ app serverside, a Java app serverside, some webservices implemented in Python on a different network, etc.

Some behaviors are different if you are on the server or the client. Consider a "save" method.  If the object is in javascript it cannot use the exact same technique to get that data into the database that server-side code would. You could hide a service call in the javascripts "save" method. But its not bad for code to be "aware" of the tier it's on and call the service explicitly.

Some behaviors should not even exist depending on which tier you're on. Consider a "draw" method. This would only be relevant in the client-side javascript. Packaging behavior with data can violate the principals of separation. Drawing should only be done on the front end computers. Although you could give the object different methods on each tier, it doesn't feel right.

Instead you go with the old fashioned C-style approach. You have a struct-like object that you pass around between the computers. (multi-language, different networks, serverside, client side). The C-style methods are "services" and may be a web-service. You may be using some neat OOP polymorphism within each tier, but the apps communicate in the old C-style technique. (which is not always a bad thing).


问:
What makes a language Turing-complete?
What is the minimal set of language features/structures that make it Turing-complete?</p>

答:
From a more practical standpoint: if you can translate all programs in a Turing-complete language into your language, then (as far as I know), your language must be Turing-complete.  Therefore, if you want to check whether a language you designed is Turing-complete, you could simply write a Brainf*** to YourLanguage compiler and prove/demonstrate that it can compile all legal BF programs.

To clarify, I mean that in addition to an interpreter for YourLanguage, you write a compiler (in any language) that can compile any BF program to YourLanguage (keeping the same semantics, of course).

Title: What makes a language Turing-complete?


问:
Naming convention for associative entity
When designing Many-to-Many relationship on a database, we need to put another table in the middle so it become 3 tables with 1-to-many relationship. Wikipedia told me that it's called associative entity

I always have problem naming these kind of tables. Is there any convention for them? or how do you name these tables?

答: I've seen "link".  E.g., if you have Document and Checklist, and one document can be in many checklists, name the table  DocumentChecklistLink. Of course it doesn't tell you whether it should be ChecklistDocumentLink or DocumentChecklistLink, I suppose you could adopt a convention of alphabetically first comes first.</p>


问:
What should the main content area be called?
I'm working on a CMS that will be used by others and I'm trying to figure out what the main body of the site page should be called.

Originally, I was going to call it "content" - but perhaps "body" or "page" would be better.

```<code><html>
<body>
    ....
    print $content;
    ....
</body>
</html>
</code>```

This isn't just a question about markup class/id names. It's also about what the name means to people when they first hear it. I want people to know that ____ is the main area of the page.

答:
At the end of the day anything along the lines of 'content' or 'body' should be fine, as long as you are consistent about using that term throughout your system (both in the front and back end ideally).

For what it's a worth, a quick survey of what some popular CMSs are using for their main text areas (thanks http://www.opensourcecms.com). Yes, these are field names, but 80% of the time this is what will end up in the template, e.g. WordPress "content" -> "the_content()":

Drupal = body

Joomla = articletext

Wordpress = content

Typo3 = content

MODx = content

I guess content is probably the safe option if you want to go with what is popular anyway.

OwnerDisplayName: Xeoncross

OwnerDisplayName: incarnate


答:
Your snippet suggests you're after what to call the templating variable/function. Use whatever you want; it's your app. Most tend toward generic terms, since you aren't necessarily dealing with "pages":

WordPress: the_content()

Movable Type: <$mt:entrybody$>

Drupal: $content (though this dumps out all the content, not just the single field)

ExpressionEngine: {body}

MODx: [[content]]

But you say it's maybe also something to do with id or class names. That's determined by what theme is applied and you have no control over it(other than forcing people to use themes you provide, I suppose).

Then @incarnate's answer provides the names/labels of the content fields within some applications' admin areas, which is again something else entirely.

Whichever it is you're after, no real standard exists or particularly needs to. It's not like you're able to take a WordPress template, dump it into a Drupal installation and have it work. And nobody reasonably expects their ExpressionEngine knowledge to directly translate to Movable Type.

Whatever you decide to use, what's more important is that it ideally be consistent with the rest of your terminology(asking what to name a single arbitrary-to-us variable is a waste of time) and that you provide documentation for it.

Title: What should the main content area be called?

Body:
I'm working on a CMS that will be used by others and I'm trying to figure out what the main body of the site page should be called.

Originally, I was going to call it "content" - but perhaps "body" or "page" would be better.

```<code><html>
<body>
    ....
    print $content;
    ....
</body>
</html>
</code>```

This isn't just a question about markup class/id names. It's also about what the name means to people when they first hear it. I want people to know that ____ is the main area of the page.

OwnerDisplayName: Su'


答:
A Turing tarpit is a kind of esoteric programming language which strives to be Turing-complete while using as few elements as possible. Brainfuck is perhaps the best-known tarpit, but there are many.

Iota and Jot are functional languages with two and three symbols, respectively, based on the SK(I) combinator calculus.

OISC (One Instruction Set Computer) denotes a type of imperative computation that requires only one instruction of one or more arguments, usually “subtract and branch if less than or equal to zero”, or “reverse subtract and skip if borrow”. The x86 MMU implements the former instruction and is thus Turing-complete.

In general, for an imperative language to be Turing-complete, it needs:

A form of conditional repetition or conditional jump (e.g., while, if+goto)

A way to read and write some form of storage (e.g., variables, tape)

For a lambda-calculus–based functional language to be TC, it needs:

The ability to abstract functions over arguments (e.g., lambda abstraction, quotation)

The ability to apply functions to arguments (e.g., reduction)

There are of course other ways of looking at computation, but these are common models for Turing tarpits. Note that real computers are not universal Turing machines because they do not have unbounded storage. Strictly speaking, they are “bounded storage machines”. If you were to keep adding memory to them, they would asymptotically approach Turing machines in power. However, even bounded storage machines and finite state machines are useful for computation; they are simply not universal.

Strictly speaking, I/O is not required for Turing-completeness; TC only asserts that a language can compute the function you want, not that it can show you the result. In practice, every useful language has a way of interacting with the world somehow.

Title: What makes a language Turing-complete?

Body: What is the minimal set of language features/structures that make it Turing-complete?</p>


问:
Windows GUIs: How Long Will 'Deprecated' APIs Last?
Note I said 'deprecated' and not 'abstracted'. Back in the days of the MFC, the WinAPI wasn't deprecated because, from what I've read, the MFC merely abstracted the WinAPI. There's a difference, for a deprecated API is one who's functionality has a newer slide-in replacement as opposed to a layer on top.

I ask in light of the direction Windows has taken. First, GDI objects were bypassed with WPF by using DirectX. Unless I've read misinformation, this means the Windows GUI could have been reimplemented in an API that doesn't need GDI underneath.

Then came Windows 8, announcing the move to HTML/JavaScript interfaces, which means DirectX isn't needed too. Ha. Of course it is, the IE engine running such interfaces probably uses hardware acceleration provided by DirectX these days. But GDI isn't needed right?

In fact, because GDI isn't needed anymore, doesn't that deprecate GDI, GDI+, MFC, and the various other templating libraries built on the GDI?

Now, contrary to common thought, it's known that Windows traditionally took backwards compatibility very seriously. But how long will they go before dropping GDI? How long until .NET's core libraries are rewritten to call the kernel and private low-level Windows routines directly for services without going through the WinAPI itself? After all, C# supports unsafe code, so the public WinAPI layer being bypassed isn't inconcievable even for the lower-level stuff.

I'm not talking about the C code being eliminated or anything like that. Just wondering if some of the public interfaces presented by Windows might not be available if MS deems them unneccessary in the future.

答:
Microsoft (almost) never deprecate core API functionality.

And new major libraries almost never get rewritten. There is too much risk of breaking something for no obvious benefit at great expense


问:
How did you get good practices for your OOP designs?
I realized I have a difficulty creating OOP designs. I spent many time deciding if this property is correctly set it to X class.

For example, this is a post which has a few days: https://codereview.stackexchange.com/questions/8041/how-to-improve-my-factory-design

I'm not convinced of my code. So I want to improve my designs, take less time creating it.

How did you learn creating good designs? Some books that you can recommend me?

答:
Designing systems is one of the things that you can only get better at by doing. Of course, it does help a little to read about good design - the recommend general object-oriented design book is the Gang of Four's Design Patterns: Elements of Reusable Object-Oriented Software. There are also other books on design patterns and principles for different types of systems and within different domains.

It's also best to get other people involved. After you create a design, present the problem(s) you are solving and the design to other people for a critical review. Listen to their feedback and have a dialog with them, focusing on why you made the decisions you did. As you are implementing the solution, you'll realize other problems with your design. Make note of these and learn from them. It might also be a good idea to work with other people to review the implementation against the design and requirements as well, and have a critical discussion of the reasons why you have done the things you did.

Although I typically find it best to sit down with other people face-to-face, specific design questions can be asked about here on Programmers. There are also Stack Exchange sites for code reviews and implementation questions.


答:
From the looks of the codereview question you asked, you're at the stage of overdoing it. I think it is a rather common problem among people who discover the importance of good design.

It is actually a natural and probably even necessary step with any skill you pickup. As you start to learn something, the more you advance in the knowledge of a skill and the more you apply it, the better your results and it seems as though you were headed straight for mastery. The problem is, that your new target becomes not the quality of your results, but how much knowledge you have accumulated on your skill.

True mastery of a skill involves the understanding of when to use it and when not to. Overusing that skill is probably the only way to develop such understanding. Sure, you can read about this, but reading is no substitute for experience.

For one thing, reading about design patterns is a bad start IMHO. Reading about OO design principles, such as SOLID and GRASP is better. After getting acquainted to them, study of common design patterns is a good idea, because you will see how those principles can be applied to form concrete idioms.

It is claimed, that when patterns emerge in the use of a language, then the language actually lacks a feature. While this statement is very radical, there is a lot of truth in it. Therefore I would suggest, you look at and play around with other languages to gain a better understanding of the concepts you are seeking to employ, and also to learn about new concepts. A shortlist would be Squeak, Ruby and Lisp.

As for List, my personal recommendation is Structure and Interpretation of Computer Programms, which taught me a great deal about design, by showing me how effortlessly one can create robust solutions to complex problems, with little more than clear abstraction and (de)composition in a top-down manner.

So here's what I suggest:

write code (and try to understand what makes it bad)

read code (and try to understand what makes it good)

exchange knowledge with other people. put your ideas to the test.

Title: How did you get good practices for your OOP designs?

Body:
I realized I have a difficulty creating OOP designs. I spent many time deciding if this property is correctly set it to X class.

For example, this is a post which has a few days: https://codereview.stackexchange.com/questions/8041/how-to-improve-my-factory-design

I'm not convinced of my code. So I want to improve my designs, take less time creating it.

How did you learn creating good designs? Some books that you can recommend me?


问:
I have only two languages on my resume - how bad is this?
I have a question that can be best answered here, given the vast experience some of you guys have!

I am going to finish my bachelor's degree in CS and let's face it, I am just comfortable with C++ and Python. C++ - I have no experience to show for and I can't quote the C++ standard like some of the guys on SO do but yet I am comfortable with the language basics and the stuff that mostly matters. With Python, I have demonstrated work experience with a good company, so I can safely put that.

I have never touched C, though I have been meaning to do it now. So I cannot write C on my resume because I have not done it ever. Sure I can finish K & R and get a sense of the language in a month, but I don't feel like writing it cause that would be being unfaithful to myself.

So the big question is, are two languages on a a resume considered OK or that is usually a bad sign? Most resumes I have seen mention lots of languages and hence my question. Under the language section of my resume, I just mention: C++ and Python and that kinda looks empty!

What are your views on this and what do you feel about such a situation?

PS: I really don't want to write every single library or API I am familiar with. Or should I?

答:
For a first position out of school, intangibles matter more than experience.  Even later in life, you can get a job as a specialist in just a few technologies.  (That's not to say don't learn other languages, just that it won't make you unemployable)

Be prepared to discuss algorithms, write in the languages you know on a white board, and show enthusiasm for solving problems.  If you can do that, you'll find someone who can use your skills.

Remember that hiring is relative to position.  Juniors are expected to be smart and eager.  Seniors are expected to have more specific experience - that's why they get paid more.

ContentLicense: CC BY-SA 2.5


问:
What are the three main technologies for a redesign of a COBOL legacy system
There exists an application that reports financial data of a bank to a national bank (all located in Europe). It is a legacy system that is written mainly in COBOL. Only the user interface is written in Java.

The business logic is stored as complex data base tables and entries. Without knowing all internals, the system can hardly be changed according to new financial regulations. Thus, the current system is very hard to debug and unmaintainable.

My aim is now to identify state-of-the art technologies/methods for a redesign and rewrite of the whole system.

What would you consider as the three most important technologies to use for a rewrite of a  COBOL System in finance?

Current considerations include:

Using  a DSL approach (domain specific language)

Using a modern programming language like Scala

MS OLAP cube (suggested by a colleague, not by me)

答:
The business logic is stored as complex data base tables and entries. Without knowing all internals, the system can hardly be changed according to new financial regulations. Thus, the current system is very hard to debug and unmaintainable.

This could mean 3 things:
1-You can't understand the original business requirements
2-You don't understand the current logic in the code
3-Both 1 and 2

If (1) applies, then you can't re-write the system without getting around the problem. Technology would not be your primary issue.

if (2) is the problem, but you understand the business requirements, then you need to consider the following in the new selected technology:

You should try to make your team all take the same language if possible, this makes Java a good component of the technical architecture

You should make sure you can access the mainframe data. I presume that it could be stored on DB2, IMS, VSAM, SAM files and such. Since IBM has a Java compiler, this would make java play a role in the back end solution.

If the application does nothing but reporting (aggregation and summarization) for reporting purposes with some data consolidation, then you are looking for an Edit, Transform, and Load solution. A tool like  IBM InfoSphere (DataStage) is ideal if you can afford the price. Other tools also exist. In my humble opinion, I would choose a leading ETL tool over MS OLAP cubes specially that a new release of MS OLAP technology is comming soon. Also, if you use MS, you will definitely need to migrate the data.

You need to consider not to migrate the data if possible. If you can, then again, don't use MS Cubes.

You need to consider a strategy for the GUI OLAP part.

I hope the above helps.


答:
Whatever you do, if its a commonly used word or phrase, then namespace it with a prefix.

This will help avoid conflicts during development, when integrating with other software, and beyond.

```<code>e.g. mjw-mainContent mjw-main-content
</code>```

I usually use the initials of the website, but anything will do really.

Body:
Whatever you do, if its a commonly used word or phrase, then namespace it with a prefix.

This will help avoid conflicts during development, when integrating with other software, and beyond.

e.g. mjw-mainContent mjw-main-content

I usually use the initials of the website, but anything will do really.


问:
Should I use friend classes in C++ to allow access to hidden members?
Here is my situation (a simple example).

Say I have a class called HiddenData

Then I have another class called StoreHiddenData

And finaly a class called OperateHiddenData

Here's the thing, my class called HiddenData has private members that I don't want to be visible to the  rest of the world, but I still need classes to be able to operate on private members of this HiddenData class (StoreHiddenData and OperateHiddenData for example).  I would like to be able to pass this object around to different classes that do different things on it.

Another thing I was thinking of is to create a form of handle to these HiddenData objects, but I can't think of a way to use handles without using friend classes again (as to give the other classes access to a table that contains what the handles point to, without exposing it to the rest of the world as well).

I was reading this question on this site just a while ago as I was researching the use of friend classes, and it has me thinking if using friends is the best way to go.

If anyone has any suggestions for how to accomplish this task without the use of friend classes in C++, or if the use of friend classes is an OK OOP practice, please provide me with any suggestions.  Thanks.

EDIT:
I figure I should add a little bit more information about my problem.  For one thing, I am trying to create an API that consists of several classes that hide their functionality from the outside and only allow public functions to be accessed.  On the inside I have data structures (or classes, doesn't really matter), that need to be passed around to these different classes with public functions.  I don't want the outside to have access to anything inside these data structures other than being able to pass them around to functions of the API.  I kind of think of it like the Windows API, where you pass around Handles to API functions, but you can't actually dissect the handles in your own code.  Well I would like to do something very similar, but while remaining object oriented, and NOT passing these private data structures around by value because they will be BIG.  Thanks again.

答:
C++ friends exist just for that. Every other surrogate will simply mimic the same concept.

There are thing that are for everyone,

Things for you only, (eventually inherited from your children)

Things shared by you with a well define and limited set of people.

Those "people" are called "friend".
Eliminating that concept will require those things to become public, or to become private, but with public accessors to be managed. You must also expect anyone to be capable of doing things with them out of your control.


答:
Test-Driven Reverse Engineering.

There are two parts.

A modern language.  C#, Java, Python, Scala.  Do not use a DSL.  Any DSL you choose simply becomes another COBOL.

A suite of test cases that the original programs appear to pass successfully.

Note that most COBOL systems have a huge number of individual application programs.  Almost incomprehensible.

However, the number of programs which do database Create-Update-Delete is considerably smaller.

Step 1 is to partition the space of COBOL programs into two:

Create-Update-Delete.  Somewhere near 20%.

Retrieve-only.  Somewhere near 80%.

For the 80%, you can use whatever reporting tools appear relevant.  Hypercubes or whatever.  It doesn't matter, since this is only reporting, and any commodity reporting tool will work.  Invest as little time in reporting as humanly possible.  Create extract-transform-load (ETL) that populates a simple data warehouse; create metadata for that warehouse that fits a reporting tool.  Done.

For the 20%, you have serious, difficult work ahead of you to gather a suite of test cases, confirm that the original COBOL actually processes them as expected, and then writing new code in C#, Java, Python or Scala to implement that programming logic.

You will find that 20% of the Create-Update-Delete programs involve simple business rules that can be easily articulated, fit the regulatory environment, and are easy to implement in Stored Procedures or Java (C# or Python) code.  Avoid stored procedures.  (Haterz will tell you stored procedures are essential, but can't provide a reason.)

You will find that 80% of the Create-Update-Delete programs involve exceptions, special cases, overrides and incompetent programming too horrifying to examine closely.  (It's like being a character in a story by HP Lovecraft; you begin to doubt the very existence of logic or rationality.)

Make the best guess you can at this code and trust your test cases.  Time spent creating test cases and samples is more valuable than time spent reverse engineering old COBOL.

Title: What are the three main technologies for a redesign of a COBOL legacy system

Body:
There exists an application that reports financial data of a bank to a national bank (all located in Europe). It is a legacy system that is written mainly in COBOL. Only the user interface is written in Java.

The business logic is stored as complex data base tables and entries. Without knowing all internals, the system can hardly be changed according to new financial regulations. Thus, the current system is very hard to debug and unmaintainable.

My aim is now to identify state-of-the art technologies/methods for a redesign and rewrite of the whole system.

What would you consider as the three most important technologies to use for a rewrite of a  COBOL System in finance?

Current considerations include:

Using  a DSL approach (domain specific language)

Using a modern programming language like Scala

MS OLAP cube (suggested by a colleague, not by me)


答: I would recommend using a different name, in every case.  It's possible that at some time in the future, you'll want to add another method, say List<Car> findByMake(String make), in contrast to List<Car> findByModel(String model).  So suddenly, calling everything find stops making sense.  Your methods also less likely to inadvertently be used incorrectly, if their names give more information as to how they should be used.

Title: Should we rename overloaded methods?

Body:
Assume an interface containing these methods :

```<code>Car find(long id);

List<Car> find(String model);
</code>```

Is it better to rename them like this?

```<code>Car findById(long id);

List findByModel(String model);
</code>```

Indeed, any developer who use this API won't need to look at the interface for knowing possible arguments of initial find() methods.

So my question is more general :
What is the benefit of using overloaded methods in code since it reduce readability?


问:
Is it considered "conveying" if I share modified LGPL v3 code on GitHub?
It is critical to know what constitutes "conveying" under LGPL v3. I am considering creating some software based on LGPL v3. The software will be used to run a web application. Now I wonder whether the "conveying" clauses would get activated if I published the modified code on GitHub to the public.

I understand that none of you are lawyers so IANAL is implied. I also understand that I could contact the developers of the LGPL software and ask for a different license.

答:
The general, FAQ level answer is that the GPL was designed so that if you gave somebody your software to use you also had to give them the source code to use.

As the versions of the GPL have rolled out they are to combat, essentially, things that work around that definition and stop people being able to change the program they got a copy of.

In the specific case you can be reasonably confident that the intention was to allow you to take an LGPL library, modify it, and give it to other people under the same license (or a more strongly free license, the GPL) - and to require that you do that if you give them anything derived from the modified version.

So, the answer is yes, if you follow the spirit of the license.


答:
GitHub has private repositories as well as publich repositories.

If you publish it on the public repositories, since GitHub allows people to download, publishing on Github constitutes conveying.

If you publish it in the private repositories, where there is not access to outsiders, it is equivalent to having it inside your own computer. This is not conveying.

Title: Is it considered "conveying" if I share modified LGPL v3 code on GitHub?

Body:
It is critical to know what constitutes "conveying" under LGPL v3. I am considering creating some software based on LGPL v3. The software will be used to run a web application. Now I wonder whether the "conveying" clauses would get activated if I published the modified code on GitHub to the public.

I understand that none of you are lawyers so IANAL is implied. I also understand that I could contact the developers of the LGPL software and ask for a different license.


问:
How do I determine how many numbers are in a floating point number system?
I'm trying to make floating point number systems a bit more intuitive for myself. There are a few things I am confused about, and I think the best way to clear up my confusions would be for someone could guide me through one question: How many numbers are there in a floating point number system (Given the base, precision, max exponent, and min exponent)?

This is what I am thinking:

I figure that the maximum possible number (realmax) divided by the smallest possible number (realmin) would give all of the possible positive numbers. Part of me also believes I could divide realmax by the smallest increment, machine epsilon (eps), to figure out how many numbers there are. Just looking at the differences in magnitude between eps (10^-16 for IEEE double precision) and realmin (10^-308), however, tells me this isn't true at all. I can't think of an intuition for why!

So the problem I am facing is determining the correct formula for realmax and realmin. The answer I get using my textbook's formulas differ radically from the one I got with wikipedia's formula.

Help!

答:
The reason why your intuition about smallest increments doesn't work out is that the increments increase as the numbers get bigger.  This is so that very small numbers can be expressed with a higher precision than very big numbers (for which several decimal places probably don't matter).  Every time you cross a power of 2, the size of the increment doubles.  So the number of floating point numbers between 8 and 16 is the same as the number of floating point numbers between 4 and 8 - they're just spaced twice as far apart.  And this, in turn, is the same as the number of floating point numbers between 2 and 4; and also between 1 and 2.  Of course, exactly how many this is depends on whether you're using single or double precision.

This pattern keeps going until you get down to the smallest possible exponent.  For numbers smaller than this, the increments are all the same.


答:
The following is based on my own deduction and I have no proof of its accuracy.

Ultimately, how many bytes does a floating point number consume?  A computer can't possibly represent more unique numbers than it can unique bit patterns.  For a 64-bit floating point (C# double) there are 2^64 unique values.  Note that some combinations give equivilent values.  Quoting Wikipedia:

While the exponent (11-bits for C# double) can be positive or negative, in binary formats it is stored as an unsigned number that has a fixed "bias" added to it. Values of all 0s in this field are reserved for the zeros and subnormal numbers, values of all 1s are reserved for the infinities and NaNs.

So this means there's 2^53 combinations that represent infinate or invalid numbers, and 2^53 combinations that represent zero and subnormal numbers.  I can't say one way or the other whether there are other bit-combinations that will produce the same number.

2^64 - 2^53 + 3 = 18,437,736,874,454,810,627 unique values
(Represents all bit combinations with positive infinity, negative infinity, and not-a-number combinations being condensed to three unique values.)

Read Floating point, Internal representation.

Title: How do I determine how many numbers are in a floating point number system?

Body:
I'm trying to make floating point number systems a bit more intuitive for myself. There are a few things I am confused about, and I think the best way to clear up my confusions would be for someone could guide me through one question: How many numbers are there in a floating point number system (Given the base, precision, max exponent, and min exponent)?

This is what I am thinking:

I figure that the maximum possible number (realmax) divided by the smallest possible number (realmin) would give all of the possible positive numbers. Part of me also believes I could divide realmax by the smallest increment, machine epsilon (eps), to figure out how many numbers there are. Just looking at the differences in magnitude between eps (10^-16 for IEEE double precision) and realmin (10^-308), however, tells me this isn't true at all. I can't think of an intuition for why!

So the problem I am facing is determining the correct formula for realmax and realmin. The answer I get using my textbook's formulas differ radically from the one I got with wikipedia's formula.

Help!


答:
You're trying to find the granularity of a floating point representation. This is formally called a "Machine Epsilon"

You can compute it with this formula

You then take that and plug it into this formula 1.0(XOR)(epsilon)=1.0. If that holds the Epsilon is correct.

Note that this Epsilon is a measure of the granularity for numbers with an absolute value of 1.0. Epsilon decreases (i.e. more precision) for numbers whose absolute value is less than 1, and increases (less precision) for numbers whose absolute value is greater than 1.

Formulas and such from here.


答:
As others have mentioned, you will only get good with practice and experience. There isn't really that much of a shortcut you can take.

The fact that you look back at your stuff and you don't like what you've written, already puts you ahead of the curve compared many other people in our profession. While you are trying to improve yourself, the rest of us work with people who would write a 500-line function with 20 parameters, all passed in by reference and 15 of them being [in/out] and those people think they are the bomb because they got that mess to work.

When it comes to software design, it's not black and white, either design is good or bad. No matter how much experience you have, you will go back to some of your old code and think, "what was I smoking when I wrote this?"  The key is constant evaluation of things and frequently going through the thought exercises to evaluate what makes good code good and bad code bad.

Finally, although nothing replaces practice, it's always a good idea to always keep reading blogs/books/this site because other other people will point out different perspectives that you may not have considered.

To start I would recommend these books:

Agile Principles, Patterns and Practices in C# - I'm 3/4th through this book myself. One of the main points the author makes, and I agree 100% with that, don't start off solving a problem by looking for a design pattern to apply.  Keep things as simple as possible and evolve the code into a pattern, if the alternative starts to becomes more complicated than that.

Head First Design Patterns - I haven't read this book and in IMO many Head First series are targeted specifically for newcomers to the field. So they tend to be on the simpler side, but I've heard/read many good responses from others about that book


答:
I would be extremely cautious about the use of friends.  Although friends, have their time and place, most of the time when people use them, it's only as a convenient way of breaking encapsulation, which makes the code easy to write and deliver v1.0 but as the number of classes that operates on your HiddenData increases and as the average size of those classes increases, it will become a nightmare to read and modify.

I've used friends a few times, but only when alternatives would've been even uglier/harder to maintain. Iterators which are associated with a specific collection is definitely a good example of using friends.

Another example is implementations of finite state machines(FSM), where each state is represented by a separate class. Here your FSM is your real class, the states are just a way of splitting up logic into manageable units, but generally the data still belongs to FSM.

Bottom line, I would lean towards friends if second class is extremely small and won't be extended with more and more functionality with each release. Also the placement of the two classes should be as close as possible to one another. In case of STL's iterators, those classes are defined right inside their own container classes. Don't get any closer than that.

There are several ways of implementing your scenario while not having to break encapsulation by using friends. Here's only few of many alternatives:

Have HiddenData be truly hidden. Don't freely give out reference to it. Instead have another adapter/view/decorator (whatever you want to call it) class between the data and the public. This other class would ensure that only public operations are allowed.  Then your special manipulator classes would access normal public interface of HiddenData directly.

Take a look at Visitor Pattern. It might be exactly what you need. It give you the ability to add functionality to a class without actually touching the class itself. So to implement another special manipulator which has access to internal data, you would create a new visitor class and give a reference to a single Accept() method of the HiddenData.

Title: Should I use friend classes in C++ to allow access to hidden members?

Body:
Here is my situation (a simple example).

Say I have a class called HiddenData

Then I have another class called StoreHiddenData

And finaly a class called OperateHiddenData

Here's the thing, my class called HiddenData has private members that I don't want to be visible to the  rest of the world, but I still need classes to be able to operate on private members of this HiddenData class (StoreHiddenData and OperateHiddenData for example).  I would like to be able to pass this object around to different classes that do different things on it.

Another thing I was thinking of is to create a form of handle to these HiddenData objects, but I can't think of a way to use handles without using friend classes again (as to give the other classes access to a table that contains what the handles point to, without exposing it to the rest of the world as well).

I was reading this question on this site just a while ago as I was researching the use of friend classes, and it has me thinking if using friends is the best way to go.

If anyone has any suggestions for how to accomplish this task without the use of friend classes in C++, or if the use of friend classes is an OK OOP practice, please provide me with any suggestions.  Thanks.

EDIT:
I figure I should add a little bit more information about my problem.  For one thing, I am trying to create an API that consists of several classes that hide their functionality from the outside and only allow public functions to be accessed.  On the inside I have data structures (or classes, doesn't really matter), that need to be passed around to these different classes with public functions.  I don't want the outside to have access to anything inside these data structures other than being able to pass them around to functions of the API.  I kind of think of it like the Windows API, where you pass around Handles to API functions, but you can't actually dissect the handles in your own code.  Well I would like to do something very similar, but while remaining object oriented, and NOT passing these private data structures around by value because they will be BIG.  Thanks again.


问:
Options for a lead programmer who prefers programming to leading?
At the beginning of this year I was promoted to a lead developer role after our team's lead developer moved to a different department.  I have about 5 years of job experience and due to availability and past performance I was management's primary choice for leading the project.  I was a little apprehensive but decided it was a good opportunity for career advancement and experience, so I accepted.

But my conclusion so far is that I don't enjoy it nearly as much as my previous developer position.  Though I have successfully led a team of 5 developers through several releases, I almost never touch any code.  Instead I perform planning and design and team management, along with code reviews.  The need to keep track of many more things, and have tasks planned so they can be assigned to the team, literally gives me headaches most every day.  Even though I rarely work overtime, I feel burnt out most every day when I leave work, and don't think I have even enjoyed off-work time as much as a result.

So my question: how would you handle, or how have you handled, such a situation?  For people in similar situations, did you find ways to better manage your team, tasks and time that made you enjoy the work?  Or did you find a way to transition back into a more development-oriented position?  I know that lead developer positions almost always pay a higher salary, but I can see myself getting to a point where I care less about money and promotions than I do about my enjoyment of my current job.

I have not discussed this with anyone in management as I thought I should try to adjust for at least a year.

答:
2 questions that aren't obvious from your post:

Are you in a firm that directly makes money from the software you write (like Google, Microsoft, or Fog Creek) or are you in a subsidiary function (like at a bank or a food company)?

Is the CEO a technologist, or someone who rose up via business roles?

If you're a software firm with a technologist CEO, don't worry.  The corporate leadership will know who the valuable developers are, and will do whatever it takes to keep them.  If the execs are all folks who got their stripes "managing people" or "managing budgets", be concerned.  Be doubly concerned if you're in an internal IT department.  If this is the case, then you have to accept that a good work-life balance is the reward for staying a developer.

One last point - do what will make you happy.  Everyone else's advice on career choices like this is about what would make them happy - and this is about you.


答: I've been in exactly your situation. the answer comes down to the relationship you have with your manager. In my case it was a very good one, so I took him aside one day and said that I was not enjoying the work, was feeling too stressed and wanted to move back to coding. He was much happier to hear that than to have me walk in and quit. So we worked out a plan for someone else to take over as Team Lead and me to go back to coding.</p>

Title: Options for a lead programmer who prefers programming to leading?

Body:
At the beginning of this year I was promoted to a lead developer role after our team's lead developer moved to a different department.  I have about 5 years of job experience and due to availability and past performance I was management's primary choice for leading the project.  I was a little apprehensive but decided it was a good opportunity for career advancement and experience, so I accepted.

But my conclusion so far is that I don't enjoy it nearly as much as my previous developer position.  Though I have successfully led a team of 5 developers through several releases, I almost never touch any code.  Instead I perform planning and design and team management, along with code reviews.  The need to keep track of many more things, and have tasks planned so they can be assigned to the team, literally gives me headaches most every day.  Even though I rarely work overtime, I feel burnt out most every day when I leave work, and don't think I have even enjoyed off-work time as much as a result.

So my question: how would you handle, or how have you handled, such a situation?  For people in similar situations, did you find ways to better manage your team, tasks and time that made you enjoy the work?  Or did you find a way to transition back into a more development-oriented position?  I know that lead developer positions almost always pay a higher salary, but I can see myself getting to a point where I care less about money and promotions than I do about my enjoyment of my current job.

I have not discussed this with anyone in management as I thought I should try to adjust for at least a year.


答:
If you rename a method, it is no longer going to be overloaded.  In and of itself, overloading doesn't necessarily make code less readable, however it can make the implementation more difficult to follow if the syntax isn't clear.

Many languages use method overloading as a means to present an interface to functionality where the parameters may be optional and defaults for the optional parameters are implied. This is particularly true for languages that do not support a default parameter syntax in the method declaration.

So doing this:

```<code>void MyMethod(int param1, int param2 = 10)
{
    ...
}
</code>```

saves you from doing this:

```<code>void MyMethod(int param1)
{
    MyMethod(param1, Param2Default);
}

void MyMethod(int param1, int param2)
{
    ....
}
</code>```

As to which is more readable, that really comes down to you. Personally I prefer the second option, particularly when the parameter list is getting a little long, but I suppose it doesn't really matter so long as you are consistent throughout your API.

The difficulty with overloading comes when you want functions that do essentially the same thing, and where you want the parameter lists to be the same, but the return types to be different. Most languages don't know how to differentiate between two methods named the same, but with different return types.  At this point, you need to think about either using generics, changing the parameter interface, or renaming one of your methods to indicate the difference in return type.  This is where readability can become a big issue, if you don't settle on a simple and clear naming scheme to deal with situations like this.

Naming your overloaded methods GetSomething() and GetSomethingEx() isn't going to say a lot about what the differences are between your methods, particularly if it is the return types that are the only differences between them. On the other hand, GetSomethingAsInt() and GetSomethingAsString() tell you a little more about what the methods are doing, and while not strictly an overload, do indicate that the two methods do similar things, yet return different value types.  I know that there are other ways you could name methods, however for the purposes of illustrating the point, these crude examples should do.

In the OPs example, the rename isn't strictly necessary because the method parameters are different, however it does make things a little clearer to name a method more specifically.  In the end, it really comes down to the type of interface you wish to present to your users. A decision on whether on not to overload should not be made solely based on your own perception of readability.  Overloading methods can for example simplify an API interface and reduce the number of methods that a developer might need to remember, on the other hand, it can obfuscate the interface to a degree which then requires a developer to read the method documentation to understand which form of method to use, whereas having a number of similarly yet descriptively named methods can make it more apparent just be reading a method name as to its purpose.

Title: Should we rename overloaded methods?

Body:
If you rename a method, it is no longer going to be overloaded.  In and of itself, overloading doesn't necessarily make code less readable, however it can make the implementation more difficult to follow if the syntax isn't clear.

Many languages use method overloading as a means to present an interface to functionality where the parameters may be optional and defaults for the optional parameters are implied. This is particularly true for languages that do not support a default parameter syntax in the method declaration.

So doing this:

void MyMethod(int param1, int param2 = 10)
{
    ...
}

saves you from doing this:

void MyMethod(int param1)
{
    MyMethod(param1, Param2Default);
}

void MyMethod(int param1, int param2)
{
    ....
}

As to which is more readable, that really comes down to you. Personally I prefer the second option, particularly when the parameter list is getting a little long, but I suppose it doesn't really matter so long as you are consistent throughout your API.

The difficulty with overloading comes when you want functions that do essentially the same thing, and where you want the parameter lists to be the same, but the return types to be different. Most languages don't know how to differentiate between two methods named the same, but with different return types.  At this point, you need to think about either using generics, changing the parameter interface, or renaming one of your methods to indicate the difference in return type.  This is where readability can become a big issue, if you don't settle on a simple and clear naming scheme to deal with situations like this.

Naming your overloaded methods GetSomething() and GetSomethingEx() isn't going to say a lot about what the differences are between your methods, particularly if it is the return types that are the only differences between them. On the other hand, GetSomethingAsInt() and GetSomethingAsString() tell you a little more about what the methods are doing, and while not strictly an overload, do indicate that the two methods do similar things, yet return different value types.  I know that there are other ways you could name methods, however for the purposes of illustrating the point, these crude examples should do.

In the OPs example, the rename isn't strictly necessary because the method parameters are different, however it does make things a little clearer to name a method more specifically.  In the end, it really comes down to the type of interface you wish to present to your users. A decision on whether on not to overload should not be made solely based on your own perception of readability.  Overloading methods can for example simplify an API interface and reduce the number of methods that a developer might need to remember, on the other hand, it can obfuscate the interface to a degree which then requires a developer to read the method documentation to understand which form of method to use, whereas having a number of similarly yet descriptively named methods can make it more apparent just be reading a method name as to its purpose.


答: Up-front design is never as good as out-back design.  Just test, code, and refactor.  When things are ugly, and you're not sure how to clean it up, then see if some design pattern will help.  Practice this for a while and soon other developers will be asking how you come up with such clean designs.</p>


问:
Advice for an ambitious student on building your own kernel
I'm a very ambitious university student who wishes to learn pretty much everything there is to know about computers (bash me if you want, I love learning). Recently I thought it would be a fun project (albeit a lengthy one) to design and build my own kernel.

I got some basic info and I've gathered that I need to master Assembly and C/C++ to really make this work. While I'm working on those, I'd like to learn HOW a kernel actually works from a programming perspective. I've spent hours browsing the linux kernel's code but that can only take you so far.

What are the basic steps in building a kernel? Things you need to address? Order or doing things? I know I'm biting off a lot but I'm determined enough to handle it.

答:
I've been learning it as well. You can check out these resources. They're very good!

http://www.osdever.net/tutorials/index

http://kernelnewbies.org/

Have fun along the way!


问:
What's the benefit of having a private repository for personal projects?
So I just created my first GitHub repository and started to wonder if there would be any reason why somebody shouldn't post their code. I don't mean the obvious, such as code that is IP of somebody else or any other possible legal situation; I'm talking about a newbie posting their own, albeit terrible, code.

I've heard several times on this site that one of the things that a some of the hiring managers do is check out the person on Github (or similar site), so what if the code is lacking? Would the position desired—for example, if I'm going after a junior developer position instead of a senior developer position—matter?

答:
YES

Take a look at this post: Is it worth listing testing or self-learning repositories on my résumé? -- I would extend it to also having it online with your name on it.

I strongly agree with the accepted answer there. The sum of all things visible about you online is your personal balance sheet.  You want to make sure to display as many assets while minimizing liabilities.

If I come across your name and find some of the code you wrote, I can't tell if it's some toy program you didn't care about or if this is your best work.

I just posted my first project on GitHub myself, and I spent good amount of time making sure it is readable by someone other than myself.

If you are just looking for storage, I would take other people's advice and use one of other repositories (online or offline). Personally, I also use Perforce at home (I have no affiliation with the company) for my toy projects.  It is a very mature and good product and it comes with 2 free users, so if its just for you, you get full, professional, non-crippled in any way version control system for free.


问:
Vim key mappings / plugin XCode?
I'm a developer who mostly does web stuff in ruby and C#.

I'd like to start tinkering with iOS and Mac development.

Over the last few month i've been trying to get fluent in one set of key bindings (vi / vim because it just feels right).

I have the awesome ViEmu installed for visual studio on windows which gives me a ton of the vim awesomeness side by side with visual studio power toys.

Is there anything like this for xcode?

I know I could set up MacVim as the default editor, but I'm not too interested in this as it means losing all of xcode's cocoa awareness.

The other option of course would be to go for the lowest common denominator and switch to emacs (as the mac keybindings are based massively on emacs) but let's not think about that for too long. :P

答:
I have just made one. Here is a link to it.

This is currently developed for personal (my) use. So you may feel bad with some lack of implementation. Give me a feedback (or feature requests) then. I'll add some keybinds or commands if I have enough time.

Title: Vim key mappings / plugin XCode?