问:
At which point do you "know" a technology enough to list it on a resume
I recently had a programmer in for an interview, who listed Python, PHP, Rails and ASP as a few of their skills. In the interview however, they interviewee didn't enough know what control structures and basic logic were, they had only followed a few demo tutorials.

So my question is this: At which point can you add a technology to your resume accurately. Is it when you can demonstrate all basic concepts, write a useful program in it, or are just comfortable using it without having to refer to the documentation every 30 seconds.

I don't believe this is overly subjective, a baseline should easily be established based on feedback.

答:
I list only the things I know well, and for me that means used in anger for about a year or more.

That's just me. That's how long I think I take to really know, appreciate, and understand a language / system / IDE / environment / whatever.

When tinkering, you don't really learn so well. Most languages / frameworks / etc really require you to get into the mind of the designer before you "get it", and to really know what you are about takes about 12 months.

As a bit of an aside:

In my position interviewing and reading CV's, I find it interesting that people list all kinds of stuff, with no supporting information in their experience to back up their assertion. For example, they might list PHP, MYSQL, Ada, C++, C#. And then their experience might say they did a project using C++.

When there is nothing to back up the languages claimed in the experience listed, I usually smell a rat and that person won't even make it to an interview.

Listing languages by rating, or how long used, or proficiency, all helps the interviewer - which is not always whats intended by the person submitting the CV!

HINTS:

IF WRITING A CV:

Be clear, straightforward, and scrupulously honest.

Make life as simple for the person reading your CV as possible. Present clearly, with no hyperbole.

If you have a position description that you don't completely meet, attach a statement showing HOW you meet the position description (don't make the person who gets your CV figure this out). AND WHERE YOU DON'T MEET SOMETHING required - say so. And if willing to learn, SAY SO.  This also shows that you have actually read the position description, and understood it, and you are not just cranking out form CV's for every position around.

IF READING A CV:

Cross check - does the experience listed match the skill set listed? If not, something is fishy.

How long was something used? A few days, or a tutorial, is not experience no matter how you dress it up.

Has the person constantly chopped and changed? Did they stick around long enough to actually see something through? (Have they lived with their own mistakes? No = another warning)

Sometimes these things are hard to assess, and you end up going on "smell". It a CV has a bit of a whiff of the sea (ie it seems a bit fishy) then move on.

From Joel On Software: Any doubts at all = No Hire.
And from my own experience: A vacant position is far better than one filled with somebody you had doubts about, who turns out to be a bad choice. (No progress is better than going backwards.)


问:
How would you create a mobile (android) offline wiki site?
My apologies in advance if this is not a good forum for this question; pointers to others happily accepted.

On the off chance it matters, I'm not going to commercialize this idea or anything; if anything in here is interesting to you, use it as you see fit.

My basic problem is this: My favorite place to do non-code writing (essays, fiction, etc) is on my Android phone when I'm traveling.  Said traveling often causes the phone to lose all signal/web connection.  I would like a system that auto-syncs with the phone in some fashion, can be written in a fairly wiki-ish style (i.e. links are supported but I don't have to actually type out also be edited easily at a regular computer when needed.  I'd prefer the editing on the phone be as close to plain text as possible, because fine manipulation like that required to set something to bold or whatever is a pain; I'd rather just be able to type things out.

Nice-to-have is the ability for other people to collaborate on documents.  Very-nice-to-have is authentication so that some documents can be private, without having to get into the auth quagmire myself.

There really doesn't seem to be any such thing out there.

The two options I've thought of for implementing this:

Now that there exists a proper 2-way sync dropbox app ( https://play.google.com/store/apps/details?id=com.ttxapps.dropsync ), I could just use a plain-text editor on the phone and have a simple web app that presents the text via a wiki markup library of some kind out of the relevant dropbox folder.  Advantages: Dead simple.  Disadvantages: No easy auth or collaboration.

I could use Google Docs, and have a not-so-simple Web app that pulls documents from there, treats them as wiki text, maybe does some cashing, and presents them as a coherent-ish web site(s).  Advantages: If I can get the auth to pass through properly, auth and collaboration are free.  Disadvantages: Much more complex, and this is just a one-off personal project.

I'm curious as to whether I've missed anything, any other easier ways to solve this problem.  I'm actually a little surprised that no-one seems to have thought of backing a wiki on Google Docs; there's the Google app wiki stuff, but that pretty much requires a browser AFAICT, whereas there are several Google Doc apps on pretty much everything with offline sync options.

答:
I had the similar needs on Note PC (in my case) to record my text on offline situation so that I created the tool (Please visit http://sourceforge.net/projects/jjjuli/ If you are interestd in).  I don't have mobile-gear so that I am not sure how the Juli fits your needs, however, there looks like 'git'(one of major revision control system) on android.  So, if the following configuration is OK for you, 'Juli' may work for your needs:

text input on android

file sync with server by 'git'

Juli is installed at server to generate HTML.

Juli requires Ruby platform.

you can browse the genrated static HTML files remotely.

If the generated HTML can be pushed back to mobile or mobile can run Ruby
so juli is installed on mobile,
you can browse HTML at your mobile directly.

There looks like 'git' on android as:

https://play.google.com/store/apps/details?id=com.madgag.agit&hl=en

ContentLicense: CC BY-SA 3.0


问:
How do the algorithms to solve problems encountered in interviews translate into real world solutions?
I have recently finished an undergraduate course in computer science and I am looking for a job. During the search I encountered several interesting (and tough) problems that needed clever algorithms to solve. I also use google code jam as a practice set.

I cannot understand how those solutions translate in solving real world problems. Many problems appear (to me) not only contrived and fantastical but also highly specific to be a general purpose solution (although it isn't impossible to extend them using ingenuity).

Are these problems there only to test the problem solving skills or are these some aspect of real world problem camouflaged?

答:
Sometimes it's just useful to test, how employees will react to unusual problems. I'm sure, if you're applying for a position of a web developer, you can set up a wordpress blog or write your own. But you can't fully evaluate someones skills by giving them routine problems.

To do that, you need to push the boundaries a bit further and throw the candidate off balance. Give him a tough problem and see, how he reacts. Will he be able to quickly solve it by himself? Or will he just say "Hey, I would just google it, I'm sure there's a ready to use solution for this". Both approaches have it's ups and downs, and both answers are acceptable. Most of the time it doesn't even matter, weather the candidate will be able to solve the problem, but it's important, how he addresses it.


问:
What is the point of having every service class have an interface?
At the company I work at, every service class has a corresponding interface.

Is this necessary?

Notes:

Most of these interfaces are only used by a single class

We are not creating any sort of public API

With modern mocking libraries able to mock concrete classes and IDEs able to extract an interface from a class with two or so clicks, is this just a holdover from earlier times?

答:
It seems like overhead to use Interface initially.. but later on when we need to extend some functionality these Interfaces help a lot.

If you do only concrete implementation you have to change code implementation a lot.. But  by using interface you just need to add one new class which implement the contract of Interface (and you can call new class object from the reference variable of Old interface).

ContentLicense: CC BY-SA 4.0


问:
Scala or Clojure Functional Programming best practices
I did a lot of self-study coding, got some experience with Parallel Programming Models: Actors, Software Transactional Memory, Data Flow.

When I am trying to apply these architectures to real life - into high load web application - any model doesn't support durability and persistence for data. Real life tasks requires to save data at the end. This means that still I have to use DB and trapping DB syncs, possible scalability bottle necks etc.

Does anybody knows good example of architecture (src or text or diagram or blueprints) that uses Akka Actors or Software Transaction Memory and implement persistence at the end?

Any good example/idea for Transactional Memory, Actors, Dataflow, Tuple spaces in real life applications is welcome.

答:
Actor / STM models and database persistence are somewhat orthogonal - you can easily have one without the other, and I think there is a danger of confusing the two.

Achieving Durability (the D in ACID) is extremely complex in a transactional setting, and particularly in a distributed setting where you have actors / processes being co-ordinated by message passing. You get into thorny issues like the Byzantine Generals Problem.

As a result, I think there is always going to be some degree of tailoring the solution to meet your specififc persistence requirements. There are no "one size fits all" solutions.

Worth looking at (Clojure perspective):

https://stackoverflow.com/questions/4522796/how-should-i-make-a-clojure-stm-program-persistent

Korma - SQL DSL

Thread on adding persistence to Clojure's STM

OwnerDisplayName: Stas

OwnerDisplayName: mikera


答:
The actor model works pretty with with Command/Query Responsibility Segregation (CQRS), as messages to actors that perform data manipulation can be used as "Command" equivalents.

So, what does that have to do with your persistence problem? Well, you work on memory, and write all commands to a log, which is a cheaper operation because it's append-only, and dump snapshots from time to time to reduce the time required to reload the database if necessary (plus making it possible to recover space used by the log).

This is a pretty common technique. Look at VoltDB and Redis for further inspiration.

Title: Scala or Clojure Functional Programming best practices

Body:
I did a lot of self-study coding, got some experience with Parallel Programming Models: Actors, Software Transactional Memory, Data Flow.

When I am trying to apply these architectures to real life - into high load web application - any model doesn't support durability and persistence for data. Real life tasks requires to save data at the end. This means that still I have to use DB and trapping DB syncs, possible scalability bottle necks etc.

Does anybody knows good example of architecture (src or text or diagram or blueprints) that uses Akka Actors or Software Transaction Memory and implement persistence at the end?

Any good example/idea for Transactional Memory, Actors, Dataflow, Tuple spaces in real life applications is welcome.

OwnerDisplayName: Daniel C. Sobral


问:
Why C++ to write a compiler?
I was wondering why C++ is a good choice to write a compiler. Of course C is good for this purpose too, because many compilers are written either in C or C++ but I am more interested in C++ this time. Any good reasons ? I was looking for that in the Internet, but I cannot find any good reasons.</p>

答:
My experience does not agree with your premise here. In fact, for high-level general-purpose languages, it is a very common practice to write the compiler in the same language as the source language (the language being compiled). For example:

Sun's Java compiler is written in Java

The Scala compiler is written in Scala

Mono's C# compiler is written in C#

Squick's Smalltalk compiler is written in Smalltalk

... and many more

An exception is compiler front-ends written for existing compiler frameworks, such as GCC, LLVM or Polyglot, which are then written in the framework's language, or compilers that rely on existing parser generators such as Yacc. Since GCC, LLVM and Yacc are common, established tools written in C and C++, it gives an incentive to compiler writers to use them, which might lead to C and C++ getting a large share in the compiler implementation language distribution.

Title: Why C++ to write a compiler?


问:
What do you do with a heisenbug?
I've gotten a bug report from one of my users in a section of the software. The scenario is basically a databinding scenario where the user enters info, and that info is printed to pdf.

The problem is, that the functionality:

Is used frequently (about 40 times a week)

Hasn't been updated/modified in months

The area of code is relatively simple to walk through

The validation appears fine (ie, if the information wasn't filled out in the app, validation fires indicating it with a msgbox before the pdf is generated)

But this one user claims that in the past 2 weeks it's happened about 3 times out of 50 and I just can't reproduce it.

So what do you do in the case of a heisenbug?

答:
I've seen things like this on an embedded system take 6 months to find. Really frustrating.

However in desktop land, it's amazing what happens if you go an actually watch what the user does. They may be doing things in some order / manner that had not been expected and this in turn causes the trouble.

ContentLicense: CC BY-SA 2.5

Title: What do you do with a heisenbug?


问:
Choosing a restrictive license to be in compliance, but not enforcing it
I'm very curious about this: Lets say that you have to use the GPL in your library because some dependency uses it or (if your library is fork) the upstream library uses GPL. Now GPL doesn't play well with a couple of important open source licenses which means that some users simply can't use your librar because of licensing issues, which doesn't help anybody

An option that I've been toying with is still using GPL to maintain dependency compatibility but telling users that I will not enforce it against open source software or (if that's way too broad) software that uses open source but not completable licenses like Apache, MPL, CC, etc.

Would there be any legal ramifications of doing this? Would this put my users at legal risk?

答:
Problem is that if your library uses a GPL library, then the author of that library may confront the users of your library too for not conforming to the library license.

It is not enough just to say that you will not do this.


问:
Where could Distributed Version Control Systems currently be in Gartner's hype cycle?
Edit: Given the recent downvoting (+8/-6 at this point) it was made clear to me that Gartner's lifecycle is a biased metric from a programmer's perspective. This is something that is part of a paper I'm going to present to management, and management types are part of Gartner's audience.

Giving DVCS exposure & enthusiasm (that "could" be deemed as hype, or at least attacked as such), think about the following question when reading this one: "how could I use Gartner's hype cycle to convince management that DVCSs are ready (or ready-enough) for us, and that it is not just hype"

Just asking if DVCSs is hype wouldn't be constructive, Gartner's hype cycle is a more objective instrument than just asking that (even if this instrument is regarded as biased). If you know any other instrument please, by all means, mention it.

Edit #2: I agree that Gartner's Life Cycle is not for every technology, but I consider it may have generated enough buzz to be considered hype by some, so it maybe deserves to be at least evaluated/pondered as such by using this instrument in order to prove/disprove it to whatever degree. I'm an advocate of DVCS, BTW.

Edit #3: Thanks for your answers. Bounty goes to Caleb for answering my question with detail and practical advise. Accepted answer goes to philosodad for providing another useful instrument and answering beyond my question.

I'm doing research for a whitepaper I'm writing in favor of DVCS adoption at company and I stumbled upon the concept of social proof. I want to prove that the social proof of DVCS adoption is not necessarily cargo cult and doing further research I now stumbled upon Gartner's hype cycle which describes technology maturity in 5 phases.

My question is: what could be an indicator of the current location of Distributed Version Control Systems (I mean git, mercurial, bazaar, etc. in general) at a particular phase in the hype cycle?... in other (less convoluted) words, would you say that currently expectations of DVCSs are a) starting, b)inflated, c)decreasing (disillusionment), d)increasing (enlightenment) or e)stabilizing (mature) and (more importantly) why?

I know it is a hard question and there is subjectivity involved, but I'll grant the answer (and the traditional cookie) to the clearest argument/evidence for a particular phase.

答:
The hype cycle measures the amount of news/buzz that a particular thing generates, not the actual use of the thing or it's actual productivity value. So... I would say that from that perspective, DVCS is reaching a spike in its news cycle. Enough people are actually using it and encouraging other people to use it that it is getting a lot of buzz in the tech world. Once adoption is more widespread, I expect that news/buzz to fade a bit when something new and shiny comes along, and then rise again as people start to understand the systems more completely.

One way to look at the hype cycle is to look at the number of new adopters. The number of new adopters of a technology tends to follow the same exact curve shape as the hype cycle. It makes sense that the buzz around a given new technology is going to grow rapidly as the technology gains a large number of new adopters. The early adopters spread the innovation, and the middle adopters generate the buzz.

The buzz during rapid adoption of an innovation is neccessarily poorly informed. If there are a lot of people who know of something but don't know about it, they are going to have different and possibly greater expectations than experienced users. So that's where the hype comes from.

The buzz after the rate of adoption has peaked is going to fall off... partly because earlier, unrealistic expectations have not paid off (DVCS will make you more productive, perhaps, but it won't fix all your problems) and partly because something else is going through a rapid adoption period and is taking up all the mindshare. Hype is fickle.

But at some point, you start getting a fairly constant rate of new adopters, the innovation has become the norm, and the new adopters want to know how to use this thing that they've already decided they need to use. Then the buzz around the innovation is all about what people actually are doing with it now that they are using it, rather than what they could do with it if they were using it.

So if you took the hype curve and put it next to the S-Curve of adoption rates (See Everett Rogers "Diffusion of Innovations") you would expect the hype to peak where the S-curve is steepest, trough as the S curve changes direction, and rise again as the innovation reaches its full market saturation.

DVCS is in a period of rapid adoption, so we're probably somewhere around the peak of the hype cycle.


问:
random generator not good enough?
During an interview I was asked to implement a random generator in java without using any existing random number libraries that takes as an argument int n, and returns a random number between 0 and n. This was the implementation I provided:

```<code>public static int random(int n) {
    int r = 0;
    for (int i =0; i <n;i++) {
        r+=helper();
    }
    return r;
}

// helper that returns 0 or 1
private static int helper() {
    long t = System.nanoTime();
    if (t%2 == 0) {
        return 1;
    } else {
        return 0;
    }
}
</code>```

He said it's not right but he wouldn't tell me what he was expecting. Why did he say it's wrong? How would you have done it differently?

答:
As others have said, the problem is that you're summing your bits. When choosing a number between 0 and 4 your algorithm would pick a two most of the time because there are many more ways to get a two by summation of the bits:

```<code>0: 0+0+0+0
1: 1+0+0+0, 0+1+0+0, 0+0+1+0, 0+0+0+1
2: 1+1+0+0, 1+0+1+0, 1+0+0+1, 0+1+1+0, 0+1+0+1, 0+0+1+1
2: 0+1+1+1, 1+0+1+1, 1+1+0+1, 1+1+1+0
4: 1+1+1+1
</code>```

Using bit shifts would have given you a lot better distribution, but you'd still be getting bad values from a timer in a tight loop.

I don't know for sure but I'd imagine there are well-tested normally distributed hash functions in Java's standard libraries. Starting with a seed of, say the timer, you could do something like this:

```<code>randomBits = hashFunction(seed)
seed = randomBits
return seed % n
</code>```

I'm no mathematician and I'm a bit worried that the modulo at the end might skew the distribution, but it would be a lot more random than summing bits and could be written quickly in an interview.

Title: random generator not good enough?

Body:
As others have said, the problem is that you're summing your bits. When choosing a number between 0 and 4 your algorithm would pick a two most of the time because there are many more ways to get a two by summation of the bits:

0: 0+0+0+0
1: 1+0+0+0, 0+1+0+0, 0+0+1+0, 0+0+0+1
2: 1+1+0+0, 1+0+1+0, 1+0+0+1, 0+1+1+0, 0+1+0+1, 0+0+1+1
2: 0+1+1+1, 1+0+1+1, 1+1+0+1, 1+1+1+0
4: 1+1+1+1

Using bit shifts would have given you a lot better distribution, but you'd still be getting bad values from a timer in a tight loop.

I don't know for sure but I'd imagine there are well-tested normally distributed hash functions in Java's standard libraries. Starting with a seed of, say the timer, you could do something like this:

randomBits = hashFunction(seed)
seed = randomBits
return seed % n

I'm no mathematician and I'm a bit worried that the modulo at the end might skew the distribution, but it would be a lot more random than summing bits and could be written quickly in an interview.


问:
Why Use Scala over Java
I am totally into Scala as a language ... and still I struggle with why any company should switch from Java to Scala. Is Scala just syntatic sugar on top of the JVM or are there fundamental improvements in Scala over Java that would improve real world applications? </p>

答: On top of Martijn's answer I would like to add that Scala is more expressive than Java and the benefits are that (1) it makes you more productive (2) writing less code for solving the same problem means that you can reduce the bugs in your code (IMHO bug-free code is a myth).</p>

Title: Why Use Scala over Java


答:
One possible reason for every service class to have an interface is that it makes interactions with sophisticated frameworks (e.g., Spring, JEE) much simpler. This is because Java can simply generate interceptor objects against interfaces (see java.lang.reflect.Proxy); doing so against concrete classes is far more tricky and filled with some non-obvious caveats when working with multiple different classloaders.
This holds doubly true if you work with OSGi, where those service interfaces will end up being loaded from a different classloader from the implementations of those services. That (together with the service discovery fabric) in turn enforces very strong separation between each service and its clients; the clients literally can't break the abstraction.

Be aware that even if an IDE can extract an interface from a class with a single click, it doesn't mean that it's necessarily going to extract the correct interface. Intelligence is still needed.

Title: What is the point of having every service class have an interface?

Body:
At the company I work at, every service class has a corresponding interface.

Is this necessary?

Notes:

Most of these interfaces are only used by a single class

We are not creating any sort of public API

With modern mocking libraries able to mock concrete classes and IDEs able to extract an interface from a class with two or so clicks, is this just a holdover from earlier times?


问:
Quantum computers and Turing Machine
As far as I know, a Turing Machine is the widely used model in computational theory to know whether something could be computed and if computed can they can be computed in finite time (P, NP, NPSpace). But I have the following doubts:

Is a Turing Machine essentially a black-box model where a set of inputs give a set of outputs such that there could be no interaction during computation? By no interaction, I mean that during computation the variables wouldn't be altered by an external factor.

As an extension to the above question, are non-deterministic functions Turing complete?

Is Turing Machine an efficient model for Quantum Computing?

Going by what I have learned so far, my answers are:

Turing Machines cannot handle interaction and random behavior and it's not guaranteed even by Turing in his original paper.

Non-deterministic functions may bring Turing machines to a halt.

No since Turing machines cannot efficiently support the superposition of bits.

Note

I am not well-versed in either Computational Theory or Quantum Computing. So a lot of links and some beginner's stuff would be a lot helpful and reading this article inspired this question.

答:
Quantum computers are still within the limits of Turing-complete. You can exactly simulate one with a regular machine, it would simply take exponential time. Of course, the complexity classes are not necessarily the same- for example, discrete factorization is an NP-hard problem on a classical computer but a quantum algorithm can do it in linear time.

Quantum computers do not fundamentally break the rules of computation. No quantum computer can solve the Halting Problem, or anything like that. They can simply perform some kinds of computation much, much faster than a classical computer. It's exactly the same as having an exponentially faster classical machine.

Title: Quantum computers and Turing Machine


问:
What are the drawbacks when designing a class?
When I read the book Effective Java chapter 4,  I met some sentences but I can't think them out :

What is the implementation when designing a class , why subclass will rely on the implementation detail of superclass?

Why will inheritance break encapsulation?

答: A subclass relies in the implementation of its super class because it inherits from it. Anything from the super class that is visible from the subclass becomes a dependency and a potential source for error. If the super class implementation changes, then the subclass  may no longer be correct, or even compile. This doesn't mean inheritance is a bad thing, it just means you have to be careful when designing your classes. Explicitly documenting your intentions helps.


问:
Using "off-paradigm" coding practices in an existing codebase
Let's assume, for a second, that you're "the boss", or architect, or whatever position would permit you the authority to decide on the following question:

You work on a product that's existed for a number of years and it's developed entirely in an imperative style/language. Let's also say that there is a feature or subsystem to be implemented that would benefit from a functional language/approach.

A hypothetical example might be that the product is implemented in C# and the subsystem/feature could be implemented in F#.

So your dev, who's a proficient F# developer, comes to you and says "I want to write this subsystem/feature in F#".

Do you say yes, or no? Why or why not?

答: Its just risk evaluation. Are there other engineers on staff that know f#? Is it easy to find f# programmers relative to c#? Do they require higher pay? What is the benefit of writing in f# vs. c#? Faster time to market? Easier to maintain or understand? More reliable? Personally unless I knew f# AND there are at least 2-3 f# engineers on staff I think it's a bit risky.</p>


答:
My question would be, who is going to support this application when Ms. F# leaves for greener pastures.  It's hard enough to hire good C# programmers in this town; where am I going to find F# programmers?  What happens if F# falls out of fashion (is it in fashion?) and I have to hire some kid who knows Erlang and is doing his best to figure out F#?

It's not that the language is functional, it's the risks involved in later maintenance that is the major consideration. If there's no readily available local support system for the proposed language, I would have to say no.  Otherwise, I'd ask for a POC and see where it goes.

Title: Using "off-paradigm" coding practices in an existing codebase

Body:
Let's assume, for a second, that you're "the boss", or architect, or whatever position would permit you the authority to decide on the following question:

You work on a product that's existed for a number of years and it's developed entirely in an imperative style/language. Let's also say that there is a feature or subsystem to be implemented that would benefit from a functional language/approach.

A hypothetical example might be that the product is implemented in C# and the subsystem/feature could be implemented in F#.

So your dev, who's a proficient F# developer, comes to you and says "I want to write this subsystem/feature in F#".

Do you say yes, or no? Why or why not?


答:
The main reasons not to are a break in consistency and maintainability. If it's simply a feature, I would be disinclined to let the programmer break from the current standard (unless everything is moving to that standard) since then you would then have essentially two codebases to switch between. If it's a standalone module that occasionally interacts with the existing codebase, then I'd be inclined to go with the best tool for the job (taking maintainability into account).

But it also depends on political/social aspects. You don't want to isolate the programmer politically by making it seem as though he can do whatever he likes; but also you want to let him be creative and have input into the engineering process. You're the boss, so you'll need to determine how big a deal that is for your situation.


问:
Why does adding more people to a late project make it later?
It's a fairly common adage that adding more programmers to a late project will make matters worse. Why is this?</p>

答:
I'd also suggest "Peopleware" by DeMarco and Lister.

And "The Deadline" by DeMarco presents this, and a number of other software project management diseases and fallacies in a lighthearted and very readable fashion.

It also delves into the dynamics of people doing project / team work, and goes into some detail about just HOW things like communication and introduction deplete the available working time of a team.

These books are quite cheap, I'd suggest you get them (Amazon or The Book Depository have them) and have a read. The short answers here can't really do justice to the question asked.


答:
This depends on what the team is like and what the project is like.  If we are talking about a large system that is being developed and maintained by a team of developers, then the answer is "probably not".  In such a case, regardless of who wrote the original feature, the team as a whole has to maintain it.  This means that as much as possible, each feature should be developed in a way that any other member of the team can jump into the code at any time.  If your the only guy who knows F#, that's not going to work.

A manager also has to be concerned about hiring new developers.  Can they find new F# guys off the street?  I know this attitude make it hard for newer (and possibly better) languages from taking hold, but at the end of the day, our job is to deliver working software, not to promote good languages.

On the other hand, if the entire team knows F#, or wants to learn F#, then maybe it's ok.  Regardless, it needs to be a team decision, as does everything else that goes into the project.

On the other hand, if this something completely separate from the main task, then maybe it's ok.  A few years ago, we had a task to write a program to do some back-end database manipulation to create data for our client application.  The dev wanted to use Perl, and since it was entirely decoupled from our client (which used C++) and since it isn't hard to find Perl people in the group, this was no problem.

Ask yourself what would happen if your dev got hit by a bus half way through development?  Will it be a problem that his code is all F#?  That should answer your question for you.


答:
1) As you pointed out a lot of the theory about "what can be computed" is based on it. For that to work out it is essential to know how it operates internally. A Turing machine is not a black box. A favorable property of Turing machines is their locality of change. Every step changes just very little, that is, the internal state (think of it as number), the letter on the tape and the position on the tape. The latter can only be changed by 1 step to the left or to the right. In this model all input is in form of what is written on the tape. The tape content is only changed by the machine. So - no interaction.

2) A machine or programming language is called Turing complete, if it can simulate all Turing machines. Thus, non-deterministic Turing machines are Turing complete, because they can simulate a Turing machine by simply not using non-determinism. Interestingly enough, a deterministic Turing can simulate a non-deterministic one, simply by trying all possible outcomes of non-deterministic results sequentially. This is a brute force approach and not very efficient. It is unclear if there is an efficient way to do it. BTW, most computer scientist do not think that it can be done.

As for your own answer to this - Turing machines are supposed to halt. In this context it means that the computation is finished and has a result. You might think it means that the machine gets frozen. But it is the other way round. A frozen machine (e.g. your desktop computer) did not halt, when it was supposed to and know you are waiting forever and cannot do anything (but reboot). Non-determinism has no effect on a machine halting or not.

3) The only known way to simulate a quantum computing device uses non-determinism. As said under 2), we can simulate non-determinism, but not efficiently. And we probably never will.

Title: Quantum computers and Turing Machine

Body:
As far as I know, a Turing Machine is the widely used model in computational theory to know whether something could be computed and if computed can they can be computed in finite time (P, NP, NPSpace). But I have the following doubts:

Is a Turing Machine essentially a black-box model where a set of inputs give a set of outputs such that there could be no interaction during computation? By no interaction, I mean that during computation the variables wouldn't be altered by an external factor.

As an extension to the above question, are non-deterministic functions Turing complete?

Is Turing Machine an efficient model for Quantum Computing?

Going by what I have learned so far, my answers are:

Turing Machines cannot handle interaction and random behavior and it's not guaranteed even by Turing in his original paper.

Non-deterministic functions may bring Turing machines to a halt.

No since Turing machines cannot efficiently support the superposition of bits.

Note

I am not well-versed in either Computational Theory or Quantum Computing. So a lot of links and some beginner's stuff would be a lot helpful and reading this article inspired this question.


答:
This question is easy to answer. It's a big no-no. The reason is the following:

Answering YES will allow programmers to use new nice features with end result of one happy programmer. All the other programmers will need to learn some strange environment. But causes large amount of wrapping between languages and tools, which is just waste of time. Two environments will have difficulty communicating. It's like your codebase is split to two separate parts.

Answering NO will keep the status quo. One programmer will be unhappy, but the system you're building is going to have less limitations and restrictions.


问:
Design patterns: moving object references around an application
I'm new to Programmers and I am looking to increase my knowledge of programming. Recently, a user on Stack Overflow told me using singletons is a bad idea, that they encourage tight coupling and that they make testing harder.

What prompted this discussion was that every class I've ever written accessed any kind of data through a singleton. For example, a class that handles state data for a game. If any other class wanted to access this data, all they would have to do is get the singletons instance and there it would be. Specifically, instantiating a class on the AppDelegate, then accessing it via: [[[[UIApplication sharedApplication] delegate] gameObject] getScore].

The SO user told me that I should instantiate the 'gameObject' wherever I first need it, then pass that object to every other class that needs it via either a method as an argument, or via a property.

I was discussing these points when someone else pointed out that this information is completely wrong, that singletons are unrelated to coupling and that they do not affect testing at all.

I'm now completely confused as to which person is correct. Could someone please clarify which technique is best for an object to persist for the lifetime of the app, and be accessible to other classes, and also maintain loose coupling. To me, the object passing by method or property to each class seems the most logical, but I do not know!

Thanks in advance for any help!

答:
Decoupling has value if you plan on reusing your code (maybe making a multi-game server, for instance) or on creating unit tests for continued development or team development.

However, the time and effort to decouple your code might be completely wasted if you never reuse or need to further test your code (e.g. the game works, but doesn't sell well, so you move on to some other project).  Furthermore, too much decoupling in the innermost loops of a compute engine (physics simulation, etc.) can actually waste a users battery life (e.g. not be "green").

The added value of decoupling might come into play if your game is a sleeper, starts to sell well next year, and your have to come back and read your code to update the app.  Then decoupling to add readability, potential code reuse and testability will end up having value after all.

It's a trade-off and a gamble.  Many large mission critical projects have to gamble that decoupling adds value (and almost always win that bet).  For many small apps that go to die in an app store, the gamble may be a complete loss.


答:
Were I a manager, I would say yes. Here’s why.

Developing a solution in a language well suited to the problem is to my mind a no-brainer. Provided of course that it’s quantifiably better suited than (and integrates well with) the prevailing toolset, a developer can be an order of magnitude more productive when using the right tool than when striving for uniformity. The price you pay for that productivity is increased maintenance cost in the event of the original developer’s departure or bus-related demise.

The technical edge tends to be worth the cost.

To riff on your example: F# is not a wildly popular language, but it is well-supported. As a .NET language, it is eminently compatible with the C# predominant at your (hypothetical) workplace. Microsoft intends to maintain it for some time, and there are resources out there for learning it and maintaining systems written in it. As such, you will always be able to find F# developers. Moreover, the (current) programming language status quo ensures that F# developers are not only well equipped to handle F#, but also probably good developers in general. The same goes for Haskell, or Lisp—languages that people know when they really know what they’re doing.


问:
What are some ways to maintain codebases written in two languages that implement the same logic?
I have a logic intensive algorithm that I need to code in two languages (actually I finished it in one language satisfactorily and am about to start coding in the other language).  By logic intensive I mean the algorithm is non trivial, needs careful understanding and, importantly, could be having bugs (due to complexity and carelessness, you know) that would have to be patched in the future.

Also, I want to make sure that when this code changes hands, eventually, it must not overwhelm the new programmers.

Given this scenario, what are some ways that would help maintain the codebases and keep they in sync? By ways I mean software tools, best practices etc.

FYI the two languages are C++ and Java. C++ for Windows/Linux and Java for "everything else" including Android.

答: Build a single external test suite that can ensure both code bases behave the same way. I put extra emphasis on the word "single" because otherwise you will have to maintain two test suites which can differ in their assertions. I don't have any suggestions on how to do this, but it seems like one way to maintain your (and future developers') sanity when working on this kind of code base.


答:
Short answer: don't do this unless absolutely forced.

If you have to use C++, then you might consider using the NDK to build your algorithm for Android in C++ and then add on a thin Java wrapper for the UI.  Note that using the NDK means that your code is a lot less portable to different sorts of hardware.  This is definitely not preferable to using Java everywhere, but better than having two code bases.

If you absolutely can't do this, and have to have two code bases, here are three suggestions:

1) Look for a tool like Unity geared towards portable software.

2) Try to pull the complex bits of the code into data, or some scripting language.  If you can write fairly generic code to deal with the scripting language, it is easier to test and get right twice.  (Especially if it is a standard language created by someone else.)  Then you can have one codebase for the complex bits.  (You might try Lua, which is geared towards embeddability.)

3) As the other answer states, create a test suite to validate both code sets.  Note that this is really hard to get right.  Having done exactly this, I can tell you that it leeds to lots of debates about which version is "right", especially in error cases.

(2) and (3) can be used together.

Title: What are some ways to maintain codebases written in two languages that implement the same logic?

Body:
I have a logic intensive algorithm that I need to code in two languages (actually I finished it in one language satisfactorily and am about to start coding in the other language).  By logic intensive I mean the algorithm is non trivial, needs careful understanding and, importantly, could be having bugs (due to complexity and carelessness, you know) that would have to be patched in the future.

Also, I want to make sure that when this code changes hands, eventually, it must not overwhelm the new programmers.

Given this scenario, what are some ways that would help maintain the codebases and keep they in sync? By ways I mean software tools, best practices etc.

FYI the two languages are C++ and Java. C++ for Windows/Linux and Java for "everything else" including Android.


答:
you could use a language that can compile into machine code and java byte code either by first transforming into java and C++ or directly. Last I checked LLVM  has back-ends for both

edit: a bit of wiki surfing got me to GCJ which can compile java to machine code


问:
Quantifying the price for source code and software product
I'm about to undertake a project. This requires me to write code, and tons of it. The client's requirement is to hand in all source code at the end of the project.

My question is: How do I quantify the price for source code and the software product? Is there any metric that one follows to determine pricing? How would I quantify the software product?

Extra info: The application must run anywhere, in any OS, including tablets (iPad, Galaxy tabs, etc.), Smartphones (iPhone, Android phones, etc.) and also on the web.
(Now, imagine how much code this will be).

答: Do not accept a fixed price for an open ended commitment.  You'll be screwed every time if you do.</p>


问:
Ways to version user generated documents
I have an online document which essentially gets stored to the database as XML string.

I'm thinking about a way to implement versioning of the document for the user.  So that user can go back to previous versions of the document.

update In my case it's a web application with hundreds of thousands of users.  A user can store unlimited amount of documents. The XML for document is stored in MySQL blob field so it's not small.  Eventually I need to cap the limits somehow but that is a different topic all together.

Is there a standard way to approach this? Should I store only the differences between versions? What are other things that I need to consider?

答:
Why not mimic a database log?

Basically, changes are marked chronologically as transactions. For a document DB a transaction would consist of a diffs blob + timestamp instead of an table row entry but the concept works the same. Pretty much the same way version control systems work.

To keep things snappy keep a cached copy of the current version. If somebody needs to go back in time, they can rollback (ie reverse) the transactions until they reach the historical requested they need. The idea being that the cached copy doesn't change until a save operation is performed.

To maintain consistency, you also need to take into account rollbacks. Following what I described already, lets say the user goes back 5 versions. 5 transactions would be reverse-applied in reverse-chronological order to the current version but when that state gets saved, the transaction is stored as a diff from that state compared to the current version.

Basically, history never gets re-written, just re-used to create new versions.


问:
I've released a software product - how do I maximize exposure given no budget and limited time?
I'd like to reach out to the community on this one. As a software developer, I'm not an expert salesperson or marketing guru - I think in code and not much else.  Most developers I come across are like this and also tend to be serious penny-pinchers.  Let's say, as a developer, I recently released a new software product that I'm pretty sure will be a hit IF people only knew about it.  Assume a budget of $0.00 and limited time each day (i.e. 30 to 60 minutes).  What can I do, within those limitations, to maximize exposure?

If possible, please back up your reply with at least two working examples.

答:
Note: I assumed your "software product" was an open source project. If not, ignore my answer.

Other than using it yourself and promoting what you build with it, I suggest you announce the project on mailing lists and other communities that might find it useful or interesting. If you haven't already, put your code on a site like GitHub or Google Code so people can easily find it. Take advantage of the social features of these sites like easy forking and sharing. The other advantage of that is then you'll have a location for people interested in the project to gather and collaborate. Do everything you can that will make it easy for others to promote it for you.


问:
Need a file location in Business logic layer from UI layer
Here's what I'm doing:

I am reading a file in BLL, which is sitting in the UI layer. Currently the application is using HttpContext.Current.Request.PhysicalApplicationPath to find the absolute path written in BLL. I feel this is not a good design and I am thinking that I should pass this information in some kind of structure to BLL or I could use a helper method to get that.

Please let me know which one is better and if there are any better solutions / suggestions. Please ask if you need more details.

答:
Just the mere fact that the business logic needs to load a file from the physical application path sounds a little dodgy to me.

But if that is really what you need, I would extract knowledge about file paths to a separate component.

```<code>public interface IFileLocations
{
    string FilePathWhereCriticalFilesAreFound { get; }
}

public class FileLocations
{
    public string FilePathWhereCriticalFilesAreFound
    {
         return HttpContext.Current.Request.PhysicalApplicationPath;
    }
}
</code>```

Now your business logic only needs a reference to an IFileLocations instance, which could be configured in a DI container (if you use one).

An even better design could be that instead of the class returning a file path, it could open a file for you.

```<code>public interface IFileOperations
{
    Stream OpenCriticalSystemFile(string fileName);
}
</code>```

This makes the business logic that depends on this file even more testable, as the code that depends on the file doesn't actually open the file. This allows you to create an in-memory file and serve that component during unit testing.

Body:
Just the mere fact that the business logic needs to load a file from the physical application path sounds a little dodgy to me.

But if that is really what you need, I would extract knowledge about file paths to a separate component.

public interface IFileLocations
{
    string FilePathWhereCriticalFilesAreFound { get; }
}

public class FileLocations
{
    public string FilePathWhereCriticalFilesAreFound
    {
         return HttpContext.Current.Request.PhysicalApplicationPath;
    }
}

Now your business logic only needs a reference to an IFileLocations instance, which could be configured in a DI container (if you use one).

An even better design could be that instead of the class returning a file path, it could open a file for you.

public interface IFileOperations
{
    Stream OpenCriticalSystemFile(string fileName);
}

This makes the business logic that depends on this file even more testable, as the code that depends on the file doesn't actually open the file. This allows you to create an in-memory file and serve that component during unit testing.


答:
In my opinion, the most important rule for a programmer is, "Don't Repeat Yourself". What you suggest is a clear violation of this rule.

I would seriously suggest that you find a way to only implement the algorithm once. I can currently think of two different approaches.

Use a domain specific language. Maybe the algorithm can be better expressed in a different language, e.g. a script language, for which a parser could exist on all the platforms you expect to run the application on, or you could generate C++/Java code based on the DSL code.

Write everything in C++. C++ can be compiled to virtually any platform. If on some platforms you require the main application to be written in Java, I would guess that it is possible to call a native library (I am not very knowledgeable in Java, but I assume that it can be done).

Maintaining the same algorithm on two different platforms can only lead to pain and bugs.


答:
A simple class of random number generators are the linear congruential generators, which generate numbers through state = (state * a + b) % c.

Java's Random class works exactly like that, using the system time as initial state. The state in java.util.Random has a size of 48 bits, while it only ever returns at most 32 bits of that, so it looks "quite random". LGCs aren't great random number generators, but they do their job if only few values are needed.

Title: random generator not good enough?

Body:
During an interview I was asked to implement a random generator in java without using any existing random number libraries that takes as an argument int n, and returns a random number between 0 and n. This was the implementation I provided:

```<code>public static int random(int n) {
    int r = 0;
    for (int i =0; i <n;i++) {
        r+=helper();
    }
    return r;
}

// helper that returns 0 or 1
private static int helper() {
    long t = System.nanoTime();
    if (t%2 == 0) {
        return 1;
    } else {
        return 0;
    }
}
</code>```

He said it's not right but he wouldn't tell me what he was expecting. Why did he say it's wrong? How would you have done it differently?


问:
Should I refactor single letter variables for constructs like pointer/structure names?
And No, i am not referring to single variables in loops or exceptions. Lets say pointer/struct names in large c ,c++ programs . Are there any languages where this type of naming is acceptable or is the norm. Or any constructs in c/c++ ( not iterators,loops) where it is implicit.

what is the general practice in handling such naming conventions ?  would you change it? if so how would you change it?

If you are a team-project lead and some one raises an issue with regards to the naming convention how would you view it?

答:
Programming style guidelines can be useful for the individual programmer, team and wider audience of your code.

There are lots out there, have a look and maybe adopt one or amend to suit your needs?

e.g.

http://geosoft.no/development/cppstyle.html

http://www.erlang.se/doc/programming_rules.shtml


答:
Depends on what your product is and what your market is.

If its commercial grade, shrink-wrap quality and for download, then like all the other "micro-isvs" out there your need to get in front of your potential customers eyeballs.

Step 1: You need a web site, very carefully put together, which sets out what your product does and the features, benefits, and its cost.

Step 2: You need to drum up viewers. You will need to spend money. Pay for some Google ads - set a sensible budget. You can also find potential customers, or classes of customers. Find the web sites or user forums where they already go, and see what you can do to post in there about your product or purchase advertising. Watch out for policies that forbid plugging products in these places, though, you might get banned.

Step 3: Give away some copies, to try and get interest / conversation.

Example: Suppose you had some new photo processing software... then that tells you where you should be directing your initial sales efforts. There are lots of photography forums and web sites.

If you have trouble developing a web site, then there are plenty of people out there who will do it for a fee.

You said in the OP that you have a budget of $0.  If you are not prepared to spend anything at all, you will almost certainly fail. You need to spend money to make money.

Title: I've released a software product - how do I maximize exposure given no budget and limited time?

Body:
I'd like to reach out to the community on this one. As a software developer, I'm not an expert salesperson or marketing guru - I think in code and not much else.  Most developers I come across are like this and also tend to be serious penny-pinchers.  Let's say, as a developer, I recently released a new software product that I'm pretty sure will be a hit IF people only knew about it.  Assume a budget of $0.00 and limited time each day (i.e. 30 to 60 minutes).  What can I do, within those limitations, to maximize exposure?

If possible, please back up your reply with at least two working examples.


问:
Programming Language most relevant to the Financial sector?
I am a freshman in college and doing a software engineering/ finance double major. I've been learning programming on my own and have a good bit of familiarity with php by now. I was wondering what you guys think the most relevant programming language is for financial/investment banking use?

I have read this thread: https://softwareengineering.stackexchange.com/questions/13109/books-on-developing-software-for-financial-markets-investment-banks

I want to start learning/reading up on a language (the basics not financial/quant stuff) to set a foundation for the future financial/quant stuff.

答:
It's a VERY broad field, but some things to consider...

Building custom Front Office Interfaces - Java

Building package systems - Not language specific.  Murex, Calypso and Sophis are some of the technologies.

Maintaining legacy code - Java, C++, and (yes) even COBOL.

Front office trading analytics - VBA (Yes) and other scripting languages to a much lesser degree.

Low latency trading - C++

Quantitative analytics - C++

Integration - Java, XML, FPML (Financial Products Markup Language)

General - You need to know UNIX and SQL


问:
Building a dropbox clone
I want to create my own Dropbox clone (for learning purposes - only the Windows app) and am looking for some tips.

Currently, I use the FileSystemWatcher to check if there's a change, then use rsync to sync all the data. Now, how does this work with multiple computers? If computer A changes a file, it should be pushed to computer B (and vice versa).

My questions are:

Do I need to create a push notification system or are there (better) alternatives so I know if data has to be pulled (as in a file has changed on the server)?

Dropbox has the green tick and a blue sync icon. How can this be done? How do I know which files are being uploaded/downloaded (if rsync-ing the whole directory)?

答:
Do I need to create a push notification system?

This is one solution.  I am sure there are many that would do what you want.

Are there (better) alternatives so I know if data has to be pulled (as
  in a file has changed on the server)?

Define "better" you should keep track of which files have been updated.  This requires you keep multiple versions and your system will always grab the most recent version unless another version is requested.

Dropbox has the green tick and a blue sync icon. How can this be done?
  How do I know which files are being uploaded/downloaded (if rsync-ing
  the whole directory)?

How can you implement what exactly?  When your system detects a new version of a file on the local system create a new versions on the server before you upload the file.

It sounds like you need to think about how this system is going to work before you proceed.

OwnerDisplayName: Devator

Title: Building a dropbox clone

OwnerDisplayName: Ramhound


答:
You can do a push notification about file update OR you can set some timer on client to periodically check for file updates, and pull it if necessary. If you are dependent on timers, you may have to wait a while before the update happens.
You have to do something like download-if-newer followed by file-id and its last-update-time.

You have to keep time stamps/or hash values of last updates for each file. Client will also have last update time stamp/hash value. If the time stamp is newer/hash different on server, you will know that the file on server is newer. If you are using time stamps, make sure its some global time value of server side.

Title: Building a dropbox clone

Body:
I want to create my own Dropbox clone (for learning purposes - only the Windows app) and am looking for some tips.

Currently, I use the FileSystemWatcher to check if there's a change, then use rsync to sync all the data. Now, how does this work with multiple computers? If computer A changes a file, it should be pushed to computer B (and vice versa).

My questions are:

Do I need to create a push notification system or are there (better) alternatives so I know if data has to be pulled (as in a file has changed on the server)?

Dropbox has the green tick and a blue sync icon. How can this be done? How do I know which files are being uploaded/downloaded (if rsync-ing the whole directory)?


问:
What are the chances of Google's Go becoming a mainstream language?
Who here is learning Go? Are other companies looking at using it? Is it likely to become widely used?</p>

答:
It might be a little late for this, but Go is becoming a popular language now and will likely enter the mainstream with Google pushing it forward.  It's being pushed as being a language used for systems and products within Google and is being pushed as a language to use with Google App Engine.  There are some very sharp folks on the backend of Go building and enhancing it.  There are some very clever and imaginative people working on third-party libraries for Go.

Go fills a void that other languages have not quite filled.  For me, I used to try to fill that void with Perl and a bunch of workarounds and tricks.  I don't believe it's the perfect language for all situations and all people, but it certainly is a candidate for quite a large number of situations.  For example, it works great for web apps while also working great for desktop apps or server-based apps.  It does such a fantastic job with HTTP and WebSocket (which means you can skip Apache or nginx altogether) while also running very well on Windows, Linux, and OS X for both daemons and for regular ol' desktop apps.  Right now the only situation that it fails for me is for Android apps, which I hope is remedied soon.  I use it for Windows desktop apps, Linux desktop apps, and Linux-based web apps.  It feels good to get real work done and not have to tinker with workarounds.

I believe it will be several years before it really hits the mainstream, but it will get there.  I think it needs to get more third-party libraries built, much like the sort of number and selection that Perl has with CPAN.  It'll get there.


问:
At which point do you "know" a technology enough to list it on a resume
I recently had a programmer in for an interview, who listed Python, PHP, Rails and ASP as a few of their skills. In the interview however, they interviewee didn't enough know what control structures and basic logic were, they had only followed a few demo tutorials.

So my question is this: At which point can you add a technology to your resume accurately. Is it when you can demonstrate all basic concepts, write a useful program in it, or are just comfortable using it without having to refer to the documentation every 30 seconds.

I don't believe this is overly subjective, a baseline should easily be established based on feedback.

答:
Sometimes just knowing the meaning of the acronym is enough to add it to the resume...

That's true, for example, for frameworks and libraries that you can couple with a given language.


问:
In programming light, what is special about the number 1223?
Just came across this post on reddit, where someone was charged $1,223 for a "FREE STEAK SALAD".

I was trying to figure out 'Why 1223?' thinking that this might be a programming error somewhere. But 1223 seems to be pretty much an ordinary number (= 100110001112).

Any ideas?

答:
The price is not the only thing which is special with the concerned product. You can also notice that the name is a bit strange:

The first word is "free". Do you see a lot of stuff with its name starting with "free" in your market/restaurant?

The name starts with a whitespace. Why?

The name is written in capitals, while the other names are written using Capitalize Each Word style.

At the bottom, you see "Food: $6.95; […]quor: $1,249.90". If the half-hidden word is "Liquor", it means that the steak salad was defined as a beverage instead of food.

Given that, it seems more like an human error, like those test entities you may see on low quality websites when they are just opened¹ and didn't get rid of demo data. You may often find products entitled "Hello Hello", or "TEST" or something similar, with 12345, 1111 etc. for integer-type fields, like prices or quantities. Since this data is entered quickly, sometimes you can see typos like "TTEST" or "Hlelo" or 1223.

So why this data appears in a ticket?

To be short, because nobody cares.

When you release a software product, you have to test it on data close to the real. One way is to:

Define the data how it is meant to be in production,

Set the demo data which is close enough; for example, Adventure Works contains demo data which is still close to real: if you see the table containing customers, there are people with real but fictive names, and you'll not find anybody called Mr. Test Test.

The case is similar for example for Oracle database Express Edition, when you create an application in Application Express.

Test the website with the development database containing demo data.

Push the website to production environment, using production database with no demo data.

The same comes for any bug. Where a bug is reported, you test it in development environment, solve it, test it in staging, and then push the update to the server.

This process is both hard and expensive, so beginner developers or developers working on products with insufficient funding are testing the bug reports directly in production. So when a bug report says that the product management software crashes when creating a product with a specific property, a developer might just go and create a "·free·steak·salad" with a random price of 1223. Then the developer finds that there is actually a bug, solves it, but after four hours of spaghetti code debugging, he forgets to remove the test data, and mixes it up with a real product which ends up in a ticket.

¹ Some contain test data for years, since nobody cares.


问:
Should the database of a web application be considered an actor?
I'm just learning about use-case analysis and use-case diagrams and am a little confused whether or not the MySQL database of a web app should be considered an actor.

Is the databased considered outside of "the system" or my application, because it is its own server, most probably on another physical machine?

On the other hand, the database in a basic web application won't ever initiate a use case.

答: The database is an actor when it takes independent action -- triggers and jobs mainly.  It is not a actor when it it is simply responding to CRUD commands.</p>


答:
Adding indentation is a common in some bills to mark that the item is a subitem or options of the preceeding unindented bill. This means that the FREE STEAK SALAD may be a bonus from purchasing Berry Mojito.

As to how its price becomes $1223.00, it may be a 0xDEADBEEF number; the programmer uses that number to initialize variables which is supposed to be overwritten by the proper price, but somehow a bug in the code when processing subitems/options causes the variable to not be written and instead gets printed into the bill. In this case, the number $1223 is chosen because it's a distinctive huge number and would attract attention if there is a bug in the POS system (and it does save the day in this bill).

It may be that this particular establishment doesn't use subitem/options in the program, but the POS machine still has the button to create them and a staff pressed that button by accident. And it's probably that the POS software has never been tested when pressing the subitem/option button when there is no entries in the subitem/option database; that's why the magic number showed up.

Also, as to how it's in ALL CAPS; it may be because the POS software is hardcoded to capitalize subitems/options, to make it easy to distinguish them while scanning the bill.

All these are speculations though, unless you contacted the establishment and their POS developer.

Title: In programming light, what is special about the number 1223?

Body:
Just came across this post on reddit, where someone was charged $1,223 for a "FREE STEAK SALAD".

I was trying to figure out 'Why 1223?' thinking that this might be a programming error somewhere. But 1223 seems to be pretty much an ordinary number (= 100110001112).

Any ideas?


答:
Implementation question

This is a nuanced way of looking at the base class and derived classes.
The implication is that you should look at what the derived class (aka subclass) inherits as a sort of contract with the base class.  What the base class provides, or doesn't provide, affects how the derived classes can be used and how much work goes into them.

So let's use a base class of "Shape" with the property "Name."

I derive a "Square" and a "Circle" from Shape, and I'm able to use their inherited Name field to set the object's name.

So far, so good.

Now we add an "Area" property and a "GetArea()" method to Shape.

We can code GetArea() within Shape because we simply return the Area property.

But how do we make the shapes calculate their area?  We can't write Shape.CalcArea() as we haven't given it any knowledge of the shape's dimensions.  So we're obligated to write a CalcArea() routine in each of the derived classes so that Shape.GetArea() doesn't fail.  (failure == not producing expected results)

There are ways to solve this through overrides, virtuals, abstracts, etc... based upon the language.  But the point of the sentence is to make you think through those relationships.

We need to think things through because we now want to use Shape to derive a class "Cone."  Cones don't have an area, they have a volume.  And now you're into your class design questions of what should the base class implement, and what should the derived classes implement.

Encapsulation

By definition, the derived class can see and access everything that the base class has to offer.  In the Shape example, this is a "good thing" and we explicitly want to share everything from the base to the derived class.

But let's say that in Shape v2.0, I need to pre-populate things from a database.  So I make Shape derive from a database connection class "DBConn."  Now, all of my circles, squares, and cones are database connections as well.  Each individual shape has access to all of the database connection information and is potentially now tightly bound to how the DBConn actually works.

So instead of calling Square.myDBConn.Connect(), I can just call Square.Connect().  So if I should ever want to change the implementation of Connect() later on, then I'll need to look at all of the derived shape classes to see what may break with that change.

At it's crux, this is the "Is A ..." vs. "Has A ..." encapsulation question that should always be considered when combining objects.

Title: What are the drawbacks when designing a class?

Body:
When I read the book Effective Java chapter 4,  I met some sentences but I can't think them out :

What is the implementation when designing a class , why subclass will rely on the implementation detail of superclass?

Why will inheritance break encapsulation?


问:
Scala or Clojure Functional Programming best practices
I did a lot of self-study coding, got some experience with Parallel Programming Models: Actors, Software Transactional Memory, Data Flow.

When I am trying to apply these architectures to real life - into high load web application - any model doesn't support durability and persistence for data. Real life tasks requires to save data at the end. This means that still I have to use DB and trapping DB syncs, possible scalability bottle necks etc.

Does anybody knows good example of architecture (src or text or diagram or blueprints) that uses Akka Actors or Software Transaction Memory and implement persistence at the end?

Any good example/idea for Transactional Memory, Actors, Dataflow, Tuple spaces in real life applications is welcome.

答:
Rich Hickey has a brand new brainchild called Datomic. It's a new approach to persistence, decoupling storage, transaction management, and querying. It's based on immutable records and uses a query language called Datalog (shares features with Prolog). The key goal was to allow easy distribution and cloud deployment. It relies on storage as a service (so not one concrete implementation, but loosely coupled through an over-the-wire API).

In Clojure we have STM which gives us ACI, the D missing. Datomic adds the D.


问:
Why most job offerings are for a <language here> developer, rather than a developer in general?
In an ideal world:

In an excellent article Don't Call Yourself A Programmer, And Other Career Advice, Patrick McKenzie explains, among other things, that language doesn't matter:

A developer is a person who solves problems, in general. A developer is not a person who writes code in a specific language.

Businesses don't care about the languages you know. If they need to hire a developer for a project written in a specific language, and they have a candidate who is highly experienced but never wrote a line of code in this language, he would still be hired.

According to my experience both as a developer and as a person who had to hire other developers, the observation is very similar:

The N years experience in Java or N years experience in C# doesn't matter. What matters is that the candidate knows how to solve problems, knows the difference between spaghetti code and clean code with well-thought architecture, etc.

I don't care about the languages you used before. For a C# project, I'll rather hire a professional developer who spent his life writing Java, Python and Ruby on Rails code rather than a beginner who knows only C#, and knows it badly.

The knowledge and the experience you gain using one language is mostly reusable in any other language.

An experienced developer who used Ruby on Rails for web development and spent the rest of his career writing Java desktop applications using Oracle fits perfectly well for an ASP.NET MVC project using Microsoft SQL Server. Because this person already knows everything she need for this job, aside a few specific things and syntax differences.

On the other hand, a person who have done just a few ASP.NET MVC small websites doesn't fit at all, because she may not completely understand the MVC architecture, may know know what is SQL profiling, and may lack some other essential knowledge.

Don't tell me that I'm unable to fix a small problem with a PHP website which uses CodeIgniter just because I never used CodeIgniter before.

In practice:

In practice, when I search for freelance jobs and when I see the job offerings in general, they are very language-specific.

Some would search for a PHP developer with two years experience in Magento. Others will be searching for a person with VB.NET experience of at least three years, and if you send them a resumé mentioning that you've done C# development for six years, but with no mention of VB.NET, they will not bother to answer. If they ask for a person with an experience with Firebird, they will not listen about your ten years experience with Oracle.

Why there is such difference between the theory and what Patrick McKenzie and I describe as being common sense, and the real world of job offerings?

答:
Businesses don't care about the languages you know. If they need to hire a developer for a > project written in a specific language, and they have a candidate who is highly experienced > but never wrote a line of code in this language, he would still be hired.

Say, you are looking for a candidate for a .NET/C# job. If you have two candidates for the job, both seem to be equally highly experienced, but the first one has gotten his experience in the Java ecosystem, the second one in the .NET ecosystem - which one is your favorite?

Others will be searching for a person with VB.NET experience of at least three years, and if
  you send them a resumé mentioning that you've done C# development for six years,
  but with no mention of VB.NET, they will not bother to answer.

Who can say why you don't get an answer? Perhaps there were enough experienced VB.NET devs applying for the job? Perhaps the human resource department uses the programming language experience as a filter to reduce the number of job applications from 100 down to 10. Perhaps you have just talked to the wrong companies (I guess in my company we would send an answer in the example case you described above).


答: Because many companies have HR drones do the recruiting who have no idea about any of it. When HR says "What qualifications does the candidate need?" it's a lot easier to say "Six years C#" than to say "Writes good code". That drone has no idea what "Writes good code" looks like or how to filter a resume by whether or not they can write good code. They can, however, quickly read a resume and see "Five and three quarter years C#" and throw it away.</p>

Title: Why most job offerings are for a <language here> developer, rather than a developer in general?

Body:
In an ideal world:

In an excellent article Don't Call Yourself A Programmer, And Other Career Advice, Patrick McKenzie explains, among other things, that language doesn't matter:

A developer is a person who solves problems, in general. A developer is not a person who writes code in a specific language.

Businesses don't care about the languages you know. If they need to hire a developer for a project written in a specific language, and they have a candidate who is highly experienced but never wrote a line of code in this language, he would still be hired.

According to my experience both as a developer and as a person who had to hire other developers, the observation is very similar:

The N years experience in Java or N years experience in C# doesn't matter. What matters is that the candidate knows how to solve problems, knows the difference between spaghetti code and clean code with well-thought architecture, etc.

I don't care about the languages you used before. For a C# project, I'll rather hire a professional developer who spent his life writing Java, Python and Ruby on Rails code rather than a beginner who knows only C#, and knows it badly.

The knowledge and the experience you gain using one language is mostly reusable in any other language.

An experienced developer who used Ruby on Rails for web development and spent the rest of his career writing Java desktop applications using Oracle fits perfectly well for an ASP.NET MVC project using Microsoft SQL Server. Because this person already knows everything she need for this job, aside a few specific things and syntax differences.

On the other hand, a person who have done just a few ASP.NET MVC small websites doesn't fit at all, because she may not completely understand the MVC architecture, may know know what is SQL profiling, and may lack some other essential knowledge.

Don't tell me that I'm unable to fix a small problem with a PHP website which uses CodeIgniter just because I never used CodeIgniter before.

In practice:

In practice, when I search for freelance jobs and when I see the job offerings in general, they are very language-specific.

Some would search for a PHP developer with two years experience in Magento. Others will be searching for a person with VB.NET experience of at least three years, and if you send them a resumé mentioning that you've done C# development for six years, but with no mention of VB.NET, they will not bother to answer. If they ask for a person with an experience with Firebird, they will not listen about your ten years experience with Oracle.

Why there is such difference between the theory and what Patrick McKenzie and I describe as being common sense, and the real world of job offerings?


答:
I can think of a few reasons:

Employee vs consultant - If I'm hiring a consultant, I want him/her to be up to speed already on the technology stack we are using.  Consultants are expected to be efficient very quickly since they aren't around as long to amortize learning.

Supply/demand - As Doc said, if I'm going to pick the most experienced candidate I can for the job.  And technology stack does matter there for established technologies.  If I'm looking for a person to develop in Go (picking a language few people know), almost nobody has experience with it and I'm back to skillset as a developer in general.


答:
Step back and think about the premise.  You want a person do some some .net work.  You put that in your job description and you look for candidates with that skill!  This is just common sense.

I certainly agree with your more detailed philosophies about why that might not be a good idea, but most people will just advertise, require and look for a candidate with the skills they need now.  It's just that simple so I think this answers the title of your question as to why.

If they can't get any candidates at all , or go through several bad ones, then they might study up a little and be more amenable to the items you detail.  In fact in the area that I'm in (Ruby on Rails) there are a LOT of ads right now saying "no experience required, we'll train you", etc. and in fact some of the top Ruby on Rails organizations are very open to candidates "without bad habits" that they can train up.  So the right approach is out there by some organizations.

Bear in mind too that most ads are by external recruiters or non-technical internal recruiters who just don't have the knowledge to "go sidewards" as you describe.


问:
Can functional programming be used to develop a full enterprise application?
I am just beginning to learn Functional programming (FP). I come from a OOP world, where everything are objects, and most of them are mutable. I have a hard time wrapping around the concept that  functions don't have side effects.

If something is not mutable, how are common things objects like Employee or Person represented in FP.

Can FP be used to create a full fledged enterprise application?

答:
Yes, it can. Google a bit and you'll find real software coded in pure functional languages.

As for your question about business objects, I guess your actual problem is with immutability. In that case, consider that you are returning a new "Person" each time you would mutate it if you were using an imperative language.

Note that this technique can also be implemented using imperative languages!


答:
I think it is time to put to bed this myth that a developer with X years experience in language Y can seamlessly transfer to language Y2. This is not how it works.

If you treat the language as just its syntax and common patterns then knowing, say, Java will give you a huge head start when moving to C#. It will not however prepare you for WCF, WPF, Click Once, the various threading libraries, Linq, and it certainly won't prepare you for the things that the brochure says work, but in practice don't.

You see you are not talking about a language, you are generally talking about a platform. And where the platform, .NET is a good example, supports many languages, people tend to converge on a preferred choice.

So when I ask for a C# developer, I'm actually advertising for a .NET platform developer who's experience lies in C# projects. Those tend to be .net server projects, winforms/wpf projects.


问:
What popular "best practices" are not always best, and why?
"Best practices" are everywhere in our industry.  A Google search on "coding best practices" turns up nearly 1.5 million results.  The idea seems to bring comfort to many; just follow the instructions, and everything will turn out fine.

When I read about a best practice - for example, I just read through several in Clean Code recently - I get nervous.  Does this mean that I should always use this practice?  Are there conditions attached?  Are there situations where it might not be a good practice?  How can I know for sure until I've learned more about the problem?

Several of the practices mentioned in Clean Code did not sit right with me, but I'm honestly not sure if that's because they're potentially bad, or if that's just my personal bias talking.  I do know that many prominent people in the tech industry seem to think that there are no best practices, so at least my nagging doubts place me in good company.

The number of best practices I've read about are simply too numerous to list here or ask individual questions about, so I would like to phrase this as a general question:

Which coding practices that are popularly labeled as "best practices" can be sub-optimal or even harmful under certain circumstances?  What are those circumstances and why do they make the practice a poor one?

I would prefer to hear about specific examples and experiences.

答:
Now that you mentioned Clean Code, while it contains some good ideas, I think its obsession to refactor all methods into submethods and those into subsubmethods etc. is taken way too far. Instead of a couple of ten-line methods you're supposed to prefer twenty (supposedly well named) one-liners. Obviously someone thinks it's clean, but to me it seems way worse than the original version.

Also, replacing simple elementary things such as

```<code>0 == memberArray.length
</code>```

within a class with a call to the class's own method such as

```<code>isEmpty()
</code>```

is a questionable "improvement" IMHO. Addition: The difference is that the first check does exactly what it says: checks whether the array length is 0. Ok, isEmpty() might check array length too. But it could also be implemented like this:

```<code>return null != memberArray ? 0 == memberArray.length : true;
</code>```

That is, it  includes an implicit null check! This may be fine behavior for a public method - if the array is null, then something is certainly empty -  but when when we're talking about class internals, this is not so fine. While encapsulation to outside is a must, class internals must know exactly what's going on within the class. You can't encapsulate the class from itself. Explicit is better than implicit.

This is not to say that breaking down long methods or involved logical comparisons is no good; of course it is, but to which degree to do it -- where the sweet spot is -- is obviously a question of taste. Breaking down a long method results in more methods, and that does not come for free. You have to jump around source code in order to see what's really going on, when you could see it at a glance if all that stuff were in a single method.

I would even go as far as to say that in some cases a 1-line method is too short to deserve being a method.

Body:
Now that you mentioned Clean Code, while it contains some good ideas, I think its obsession to refactor all methods into submethods and those into subsubmethods etc. is taken way too far. Instead of a couple of ten-line methods you're supposed to prefer twenty (supposedly well named) one-liners. Obviously someone thinks it's clean, but to me it seems way worse than the original version.

Also, replacing simple elementary things such as

0 == memberArray.length

within a class with a call to the class's own method such as

isEmpty()

is a questionable "improvement" IMHO. Addition: The difference is that the first check does exactly what it says: checks whether the array length is 0. Ok, isEmpty() might check array length too. But it could also be implemented like this:

return null != memberArray ? 0 == memberArray.length : true;

That is, it  includes an implicit null check! This may be fine behavior for a public method - if the array is null, then something is certainly empty -  but when when we're talking about class internals, this is not so fine. While encapsulation to outside is a must, class internals must know exactly what's going on within the class. You can't encapsulate the class from itself. Explicit is better than implicit.

This is not to say that breaking down long methods or involved logical comparisons is no good; of course it is, but to which degree to do it -- where the sweet spot is -- is obviously a question of taste. Breaking down a long method results in more methods, and that does not come for free. You have to jump around source code in order to see what's really going on, when you could see it at a glance if all that stuff were in a single method.

I would even go as far as to say that in some cases a 1-line method is too short to deserve being a method.


问:
How should I pitch moving to an agile/iterative development cycle with mandated 3-week deployments?
I'm part of a small team of four, and I'm the unofficial team lead (I'm lead in all but title, basically).  We've largely been a "cowboy" environment, with no architecture or structure and everyone doing their own thing.  Previously, our production deployments would be every few months without being on a set schedule, as things were added/removed to the task list of each developer.  Recently, our CIO (semi-technical but not really a programmer) decided we will do deployments every three weeks; because of this I instantly thought that adopting an iterative development process (not necessarily full-blown Agile/XP, which would be a huge thing to convince everyone else to do) would go a long way towards helping manage expectations properly so there isn't this far-fetched idea that any new feature will be done in three weeks.

IMO the biggest hurdle is that we don't have ANY kind of development approach in place right now (among other things like no CI or automated tests whatsoever).  We don't even use Waterfall, we use "Tell Developer X to do a task, expect him to do everything and get it done".

Are there any pointers that would help me start to ease us towards an iterative approach and A) Get the other developers on board with it and B) Get management to understand how iterative works?  So far my idea involves trying to set up a CI server and get our build process automated (it takes about 10-20 minutes right now to simply build the application to put it on our development server), since pushing tests and/or TDD will be met with a LOT of resistance at this point, and constantly force us to break larger projects into smaller chunks that could be done iteratively in a three-week cycle; my only concern is that, unless I'm misunderstanding, an agile/iterative process may or may not release the software (depending on the project scope you might have "working" software after three weeks, but there isn't enough of it that works to let users make use of it), while I think the expectation here from management is that there will always be something "ready to go" in three weeks, and that disconnect could cause problems.

On that note, is there any literature or references that explains the agile/iterative approach from a business standpoint?  Everything I've seen only focuses on the developers, how to do it, but nothing seems to describe it from the perspective of actually getting the buy-in from the businesspeople.

答:
Focus on the people and the process and how they interact.

This is a new (well worth it) initiative for the company.  I recommend you:

Talk you your CIO.  I mean really talk.  request a lunch meeting perhaps and then lay out your pitch about things like your excitements about the company, the mission, your work, etc.  Then pivot to your concerns and how troubled you are and how you want to help make things better for the company so that you can sleep better at night.  Also listen carefully to their pitch about exactly what they are trying to achieve (listen first, understand 2nd, ask/suggest 3rd)

Appoint a team lead to do all this.  You may need to be this person, even if it's not your ideal thing.  The company needs to formally fill the position though to give that person the authority to implement these things without a lot of questioning / resentment / double-guessing.  They need to be able to make some mistakes along the way too.

Focus on small items.  It shouldn't be hard to have some things each time, even if it's just changing the placement of the logo or fixing a typo.  If you were busy doing a lot of other stuff for a given sprint, that's ok.  You have your sprint planning meeting and then you say why this has been the case for the past sprint and what the reasons were.  If you're working on bigger stuff that needs infrastructure first then you say that and look at what can be actually delivered in the next sprint.  If this happens a LOT that the either 3 weeks is not a good period, or the results of your efforts are not seen unless there is a front end component.

Good Communication - a critical part of the job of project lead is to explain to the owners and product owners what's going on technically but in non-technical terms.  If there's good communication and trust (those things take time and effort) it will work better.

Focus on the benefits that you'll all get from following these Best Practices.  It doesn't mean magic or that there will be big changes each sprint but in the long-term, adherence to the process will greatly improve the results.

Ask the developers themselves about how to get the various details done, once the big picture is in place from management.  Give everyone a task to do that is part of the change.  Perhaps one person sets up the ci, another defines the qa process, another the automated build process, another the sprint planning leader, etc. to get buy-in and involvement.


答:
Be careful. First, why is your cio asking for a three week cycle? Find out if you have not already asked. This is critical because he may be addressing a perceived problem with the wrong solution. Find out the specific issue he is trying to fix. Are you perceived as being slow but accurate? delivering the wrong stuff? Delivering the wrong stuff late? etc etc.

If you are unofficial team lead, now is a good time to start drawing in the others. First put together a proposal for the boss which details how you will address the specific problems. It's important here to be a can do person.

A CI build will be a good starting place. Get one of the other developers to do this. If the idea of getting another developer to do something doesn't appeal, we need to address what this unofficial team lead means in practice. It could mean you are being used, and I mean that as politely as I can.

Finally talk to the developers. They won't buy into anything until you talk to them. Find out what they dislike about the current system and then sell them a more agile approach based on how it will improve their issues.

It's all about communication, and I'll finish on this. If you don't get the communication going, at all levels, with the best will in the world, agile will not work for you. It is 90% about communication and collaboration and 10% all the other bits.

Title: How should I pitch moving to an agile/iterative development cycle with mandated 3-week deployments?

Body:
I'm part of a small team of four, and I'm the unofficial team lead (I'm lead in all but title, basically).  We've largely been a "cowboy" environment, with no architecture or structure and everyone doing their own thing.  Previously, our production deployments would be every few months without being on a set schedule, as things were added/removed to the task list of each developer.  Recently, our CIO (semi-technical but not really a programmer) decided we will do deployments every three weeks; because of this I instantly thought that adopting an iterative development process (not necessarily full-blown Agile/XP, which would be a huge thing to convince everyone else to do) would go a long way towards helping manage expectations properly so there isn't this far-fetched idea that any new feature will be done in three weeks.

IMO the biggest hurdle is that we don't have ANY kind of development approach in place right now (among other things like no CI or automated tests whatsoever).  We don't even use Waterfall, we use "Tell Developer X to do a task, expect him to do everything and get it done".

Are there any pointers that would help me start to ease us towards an iterative approach and A) Get the other developers on board with it and B) Get management to understand how iterative works?  So far my idea involves trying to set up a CI server and get our build process automated (it takes about 10-20 minutes right now to simply build the application to put it on our development server), since pushing tests and/or TDD will be met with a LOT of resistance at this point, and constantly force us to break larger projects into smaller chunks that could be done iteratively in a three-week cycle; my only concern is that, unless I'm misunderstanding, an agile/iterative process may or may not release the software (depending on the project scope you might have "working" software after three weeks, but there isn't enough of it that works to let users make use of it), while I think the expectation here from management is that there will always be something "ready to go" in three weeks, and that disconnect could cause problems.

On that note, is there any literature or references that explains the agile/iterative approach from a business standpoint?  Everything I've seen only focuses on the developers, how to do it, but nothing seems to describe it from the perspective of actually getting the buy-in from the businesspeople.


答:
It is impossible to say for sure without getting our hands on the software.

My guess from doing Point of Sale programming for many years:

Point of Sale software tends to be very configurable at the store.  I suspect that this particular software doesn't have support for "special deals".  That is, the software itself has no way to support things like "Buy a Mojito, get a free steak salad".  The manager pokes around the software trying to figure out how to get this to work.

The software probably supports items with fixed prices and items with variable prices.  Variable priced items ask for price.  The manager things "aha!  I'll make set up one of these for the steak salad and instruct my people to just enter zero!"  He does so, capitalizing and indenting the "FREE STEAK SALAD" because he wants to highlight the special deal.

This works well enough.  Cashiers sell mojitos, enter the "FREE STEAK SALAD" item number, then zero, then enter.

One day, a cashier isn't paying attention and forgets the price prompt.  They are probably just typing blind from an order.  They enter the "Free Steak Salad" item number than the "Angel Food Cake" item number.  The latter is 1223.  They look up, and the prompt says "FREE STEAK SALAD".  "Huh", they say, at enter it again.  It works, and they figure "must be a computer glitch" and stuff the receipt in the bill without looking at the price.

This may be exacerbated by the fact that older registers don't have CRTs but rather only a 2-line display.  The display may not have the total price on it.

That's my guess.  It's just a theory, though.  There are many possible explanations.  As others have said, it could also be that "FREE STEAK SALAD" is a fake item and the cashier got it by accident by mistyping the item number.  I think that's less likely though.