答:
I suppose you are right, the author wants to gain extra flexibility.

This is somewhat a matter of taste. If you are used to bit arithmetic, the & form is readable, too. The usage of 0x1 indicates this. The author could have used 0b1 or 01 or 1. But if you frequently mingle your bits, you eventually start using hex as it is based on 2. BTW, don't think that this is an optimization. Operations with constants are very easy to optimize and compilers will do so. E.g. (n * 32) will be translated to (n << 5).

You only have to check all numbers that are less or equal to the root of the candidate number. But the algorithm checks only numbers of the form 6k - 1 and 6k + 1. At least that is what the author says in the comment. But the k from the comment is not the long k from the code. Instead long k takes values of the form 6 * i. Based on this the possible prime factors are computed. Now if 6i - 1 is a prime factor, you have to make sure, that k runs up to (including) 6i. E.g suppose your (long) Math.sqrt(n) can be written as 6*i - 1. But it is computed as k-1, so k has to run up to 6i, which is (long) Math.sqrt(n) + 1.

An alternative without +1 is thus:

```<code>public static boolean isP2(long n) {
    if (n==2 || n==3 || n==5) return true;
    if ((n&0x1)==0 || n%3==0 || n<2 || n%5==0) return false;
    long root=(long)Math.sqrt(n);
    // we check just numbers of the form 6*i+1 and 6*i-1
    for (long k=6;k<=root;k+=6) {
        if (n%(k+5)==0) return false;
        if (n%(k+1)==0) return false;
    }
    return true;
}
</code>```

The complexity is O(sqrt(n)), which is actually the same as O(sqrt(n) / 6). But as 6 is a constant, we can ignore it in Big-O-Notation. Same goes for O(sqrt(n/6)), it's just harder to see. The reason is

sqrt(n/6) = (n/6)^0.5 = n^0.5 / 6^0.5

And 6 ^ 0.5 is just another constant. However O(n) is definitely wrong.

Title: questions on a particular algorithm

Body:
Upon searching for a fast primr algorithm, I stumbled upon this:

```<code>public static boolean isP(long n) {
    if (n==2 || n==3) return true;
    if ((n&0x1)==0 || n%3==0 || n<2) return false;
    long root=(long)Math.sqrt(n)+1L;
    // we check just numbers of the form 6*k+1 and 6*k-1
    for (long k=6;k<=root;k+=6) {
        if (n%(k-1)==0) return false;
        if (n%(k+1)==0) return false;
    }
    return true;
}
</code>```

My questions are:

Why is long being used everywhere instead of int? Because with a long type the argument could be much larger than Integer.MAX thus making the method more flexible?

In the second 'if', is n&0x1 the same as n%2? If so why didn't the author just use n%2? To me it's more readable.

The line that sets the 'root' variable, why add the 1L?

What is the run-time complexity? Is it O(sqrt(n/6)) or O(sqrt(n)/6)? Or would we just say O(n)?

Body:
I suppose you are right, the author wants to gain extra flexibility.

This is somewhat a matter of taste. If you are used to bit arithmetic, the & form is readable, too. The usage of 0x1 indicates this. The author could have used 0b1 or 01 or 1. But if you frequently mingle your bits, you eventually start using hex as it is based on 2. BTW, don't think that this is an optimization. Operations with constants are very easy to optimize and compilers will do so. E.g. (n * 32) will be translated to (n << 5).

You only have to check all numbers that are less or equal to the root of the candidate number. But the algorithm checks only numbers of the form 6k - 1 and 6k + 1. At least that is what the author says in the comment. But the k from the comment is not the long k from the code. Instead long k takes values of the form 6 * i. Based on this the possible prime factors are computed. Now if 6i - 1 is a prime factor, you have to make sure, that k runs up to (including) 6i. E.g suppose your (long) Math.sqrt(n) can be written as 6*i - 1. But it is computed as k-1, so k has to run up to 6i, which is (long) Math.sqrt(n) + 1.

An alternative without +1 is thus:

public static boolean isP2(long n) {
    if (n==2 || n==3 || n==5) return true;
    if ((n&0x1)==0 || n%3==0 || n<2 || n%5==0) return false;
    long root=(long)Math.sqrt(n);
    // we check just numbers of the form 6*i+1 and 6*i-1
    for (long k=6;k<=root;k+=6) {
        if (n%(k+5)==0) return false;
        if (n%(k+1)==0) return false;
    }
    return true;
}

The complexity is O(sqrt(n)), which is actually the same as O(sqrt(n) / 6). But as 6 is a constant, we can ignore it in Big-O-Notation. Same goes for O(sqrt(n/6)), it's just harder to see. The reason is

sqrt(n/6) = (n/6)^0.5 = n^0.5 / 6^0.5

And 6 ^ 0.5 is just another constant. However O(n) is definitely wrong.


问:
Open source projects and MDD?
Model-driven development seems to have a lot of buzz in certain software engineering circles, but I've never encountered an open source MDD projects "in the wild".

Are any open source projects using model-driven development? (I don't just mean that there's some UML documentation, but that the primary artifacts that the developers manipulate are the models, rather than the code).

答:
I think that live synchronization at model level is a solution. I mean that if you work on a native model explorer which will immediately updated all modified or new information in the complete model then you can manipulate the model at developer level. You can change your model with a simple text editor or using the tree viewer.
Have a look at the EclipseUML2 plugin which is a kind of tree viewer using the EclipseUML2 model.</p>

ContentLicense: CC BY-SA 3.0

Title: Open source projects and MDD?


问:
Advice for learning Javascript with prior knowledge of C++?
Recently I have become interested in learning Javascript for web development. I currently know HTML, CSS, and beginner/intermediate C++. I understand polymorphism, inheritance, and all of that fun stuff. Would any of these skills carry over to Javascript? In what key ways does Javascript differ from C++? </p>

答:
I'm in a similar situation, I'm coming to javascript from the C# world. I'm still a noob with javascript, but I can share some of my personal experience with you.

First of all here is a link from someone with more knowledge than me, that targets your question specifically:
"JavaScript Jump Start For C++ Programmers" https://web.archive.org/web/20140206141018/http://localjs.org/docs/en/tutorial_js4cpp.php

Your knowledge will help you understand Javascript faster, but be careful, they are very different languages, and some of the things you have gotten used to might become caveats.

Here are some things that have brought me pain so far:

Javascript is dynamically typed, not statically typed.
Because of this, typos in property names have become a problem for me...
And sometimes you have to use the debugger to see if you are using the right properties from parameters.

It's Interpreted, not compiled.
That means that you will find many of the errors only at runtime.
And it might happen that your code to executes only partially when you have an error.

Be very careful when you use the 'this' keyword, it's not behaving like you are used to. Here's an article describing this in detail: http://javascriptweblog.wordpress.com/2010/08/30/understanding-javascripts-this/

There is also a lot of strangeness regarding 'falsy' and 'truthy' values (see this: http://11heavens.com/falsy-and-truthy-in-javascript).

This is a big topic, and I'm sure the answer is not complete, so I invite others to edit it.


答:
The main difference which makes JavaScript really different compared to other languages with C like syntax is the function scope, compared to block scope. This leads to a dynamic this reference. Inheritance is also different and the dynamic, non-static type system might lead to confusion, but that's basically how you add new functionality. Of course, this has also some implications on projekct structure and so on.

I recommend JavaScript the good parts (O'Reilly), JavaScript patterns (O'Reilly) and Secrets of the JavaScript ninja (Manning).

But other than that, JavaScript can really be fun and once you get the idea, you might want to take a peek into CoffeeScript.

Title: Advice for learning Javascript with prior knowledge of C++?

Body: Recently I have become interested in learning Javascript for web development. I currently know HTML, CSS, and beginner/intermediate C++. I understand polymorphism, inheritance, and all of that fun stuff. Would any of these skills carry over to Javascript? In what key ways does Javascript differ from C++? </p>


问:
On mobile is there a reason why processes are often short lived and must persist their state explicitly?
Most mobile platforms (such as Android, iOS, Windows phone 7 and I believe the new WinRT) can kill inactive application processes under memory pressure. To prevent this from affecting the user experience applications are expected to save and restore their state as their process is killed and restarted.

Having application processes killed in this way makes the developers job harder.

On various occasions I've seen a mobile app that would:

Return to the welcome screen each time I switch back to it.

Crash when I switch back to it (possibly accessing some state that no longer exists after the process was killed)

Misbehave when I switch back to it (sometimes requiring a restart or tasks killer to fix)

Otherwise misbehave in some hard to reproduce way (e.g. android service killed and restarted at the wrong time)

I don't really understand why these mobile operating systems are designed to kill tasks in this way especially since it makes application development more difficult and error prone.

Desktop operating systems don't kill processes like that. They swap out unused pages of memory to mass storage. Is there a reason why the same approach isn't used on mobile? Mobile hardware is only a few years behind PC hardware in term of performance.

I'm sure there are very good reasons why mobile operating systems are designed this way. If you can point me to a paper or blog post that explain these reasons or can give me some insight I'd very much appreciate it.

答:
It's not an easy task to completely hibernate and awaken a process even on desktop OS. Apart from memory pages, processes need other resources to operate correctly -- network connections, local files, locks, semaphores etc. -- all kinds of kernel/user space objects that you need to consider. And the list is growing. I thinks this answers why the apps are required to handle the dump&restore issue themselves.

Hibernate a process in Linux question from StackOverflow


问:
When will java change to 64bit addressing and how can we get there faster?
Having to work with large files now, I would like to know when the java libraries will start switching to long for indexing in their methods.

From Inputstreams read(byte[] b, int off, int len) - funnily there is long skip(long) also - to MappedByteBuffer to the basic indexing of arrays and lists, everything is adressed as int.

Is there an official plan for enhancment of the libraries?

Do initiatives exist to pressure oracle into enhancing the libraries, if there is no official plan yet?

答:
p42 of slides at Simon Ritter's PDF To Java SE 8, and Beyond! - QCon London indicates that it is scheduled for Java 9.

Incidentally, the keyword you were lacking to find this yourself with Google in 10 seconds is JSR.


答:
files can already be addressed by longs and having a byte buffer of over 2 GigaByte is a waste and will lead to a OutOfMemoryException very fast on 32 bit machines (use multiple byte buffers if you need to have that big of a range)

also the FileChannel.map takes longs to specifiy the offset and size allowing you to map passed the 2GB mark

also RandomAccessFile uses a long for the seek index

Title: When will java change to 64bit addressing and how can we get there faster?

Body:
Having to work with large files now, I would like to know when the java libraries will start switching to long for indexing in their methods.

From Inputstreams read(byte[] b, int off, int len) - funnily there is long skip(long) also - to MappedByteBuffer to the basic indexing of arrays and lists, everything is adressed as int.

Is there an official plan for enhancment of the libraries?

Do initiatives exist to pressure oracle into enhancing the libraries, if there is no official plan yet?


问:
questions on a particular algorithm
Upon searching for a fast primr algorithm, I stumbled upon this:

```<code>public static boolean isP(long n) {
    if (n==2 || n==3) return true;
    if ((n&0x1)==0 || n%3==0 || n<2) return false;
    long root=(long)Math.sqrt(n)+1L;
    // we check just numbers of the form 6*k+1 and 6*k-1
    for (long k=6;k<=root;k+=6) {
        if (n%(k-1)==0) return false;
        if (n%(k+1)==0) return false;
    }
    return true;
}
</code>```

My questions are:

Why is long being used everywhere instead of int? Because with a long type the argument could be much larger than Integer.MAX thus making the method more flexible?

In the second 'if', is n&0x1 the same as n%2? If so why didn't the author just use n%2? To me it's more readable.

The line that sets the 'root' variable, why add the 1L?

What is the run-time complexity? Is it O(sqrt(n/6)) or O(sqrt(n)/6)? Or would we just say O(n)?

答:
Could just be that the set of primes you can fit in an integer is much smaller than the set of primes you can fit into a long.

There is not much value in optimizing the set of primes which fit into an integer, whereas it worth doing so for the set that will fit into a long.

Title: questions on a particular algorithm


问:
What syntax element do you hate most in a programming language you use frequently?
No matter how much you love a programming language, there are always a few details in it that aren’t quite as nice as they could be.

In this question, I would like to specifically focus on syntax elements. In a programming language that you use frequently (perhaps your favourite programming language, or perhaps the one you are forced to use at work), which syntax element do you find most unreadable, unclear, inconvenient or unpleasant?

答:
Python

self parameter in instance method definitions

ContentLicense: CC BY-SA 2.5


问:
Assignments in mock return values
(I will show examples using php and phpunit but this may be applied to any programming language)

The case: let's say we have a method A::foo that delegates some work to class M and returns the value as-is.

Which of these solutions would you choose:

```<code>$mock = $this->getMock('M');
$mock->expects($this->once())
     ->method('bar')
     ->will($this->returnValue('baz'));

$obj = new A($mock);

$this->assertEquals('baz', $obj->foo());
</code>```

or

```<code>$mock = $this->getMock('M');
$mock->expects($this->once())
     ->method('bar')
     ->will($this->returnValue($result = 'baz'));

$obj = new A($mock);

$this->assertEquals($result, $obj->foo());
</code>```

or

```<code>$result = 'baz';
$mock = $this->getMock('M');
$mock->expects($this->once())
     ->method('bar')
     ->will($this->returnValue($result));

$obj = new A($mock);

$this->assertEquals($result, $obj->foo());
</code>```

Personally I always follow the 2nd solution, but just 10 minutes ago I had a conversation with couple of developers who said that it is "too tricky" and chose 3rd or 1st.

So what would you usually do? And do you have any conventions to follow in such cases?

答:
I would choose 3rd solution for two reasons:

Having it defined as
$result = ...
makes it possible to assign a different value to $result later.

Precisely because second method is too tricky. I think its important for code to be readable and understandable by others as much as possible without comments.

Title: Assignments in mock return values


答:
So, you want an infinite amount of swap space to persistently store app states in? You can't guarantee that the user will even have a memory card installed, so where do you propose that the state of an app that was loaded 23 hours ago, run for 30 seconds, and generated 2Mb of data is stored?

Also, how much battery power will it take to, constantly move this information around?

Comparing mobile operating system design to desktop operating system design seems a little silly. I mean, with a desktop operating system you can (pretty much) guarantee that you have unlimited power, and (compared to smart phones) infinitely more memory and storage capacity.

I suppose the main problem with implementing traditional (desktop) multitasking on a smart phone is that we might end up with thrashing - when the storage/ram/swap runs low, which could lead to a kernel panic. this would be disastrous on a smart phone.

Title: On mobile is there a reason why processes are often short lived and must persist their state explicitly?

Body:
Most mobile platforms (such as Android, iOS, Windows phone 7 and I believe the new WinRT) can kill inactive application processes under memory pressure. To prevent this from affecting the user experience applications are expected to save and restore their state as their process is killed and restarted.

Having application processes killed in this way makes the developers job harder.

On various occasions I've seen a mobile app that would:

Return to the welcome screen each time I switch back to it.

Crash when I switch back to it (possibly accessing some state that no longer exists after the process was killed)

Misbehave when I switch back to it (sometimes requiring a restart or tasks killer to fix)

Otherwise misbehave in some hard to reproduce way (e.g. android service killed and restarted at the wrong time)

I don't really understand why these mobile operating systems are designed to kill tasks in this way especially since it makes application development more difficult and error prone.

Desktop operating systems don't kill processes like that. They swap out unused pages of memory to mass storage. Is there a reason why the same approach isn't used on mobile? Mobile hardware is only a few years behind PC hardware in term of performance.

I'm sure there are very good reasons why mobile operating systems are designed this way. If you can point me to a paper or blog post that explain these reasons or can give me some insight I'd very much appreciate it.


问:
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.

答:
Your Own Site

Build your OWN site to distribute your software. It needs to have a home.
This can be the code hosting repository where you host it and its development, but you could have a more customer facing site, and have them link to each other.

Your own site comes with additional elements:

your own chatroom(s),

your own newsgroup(s),

your own mailing list(s),

your own social network business page(s),

feeds (RSS/Atom) for your update channels (and some of previous points).

Notice that you can have several ones for different purposes: to talk to developers, make announcement, take care of customer support...

One point though: it's better to have one active point of communication than to get dispersed and have no content and no activity at all. It's the chicken and egg thing, but people are less enclined to ask questions on an empty forum. It's understandable to want to reach out to as many users as you'd like (we all prefer one medium to another), but wait a bit before you set up that Gopher site and an IRC channel.

Search Engines

Search Engines are the key element here: that's what everybody uses to find you. In the good ol' days (actually, the dark ages, really :)), you used to have search engines that were actually mostly keyword-based directories, and you had to submit your site to them individually/manually, or using so-called "search-engine auto-submitters". Some were relatively good, some would get you blacklisted easily.

Nowadays, I'd recommend you do 3 things:

Create a decent site with good, sensible, readable and easily-indexible markup

you may want to read these Google Webmaster Guidelines

Create one (or more) sitemaps for your site(s) and define robots.txt rules (if needed);

Submit your site to at least:

Google (via Google Webmaster Tools),

Bing (via Bing Webmaster Toolbox),

and Yahoo! (via Yahoo! Site Explorer this seems to have merged with Bing's Webmaster Toolbox, actually).

Surprisingly, even Google still has pages to let your "submit" a site for inclusion, but usually that won't be needed. Feel free to also look for other directories and less known search engines to check for your inclusion in their databases. It's a good thing to regularly check where you are.

Software Distribution Sites

Software distribution sites: Softpedia, CNet (and their acquisition Download.com), Softonic...

OSS distribution sites: Freshmeat / Freecode, etc...

Direct-install app stores (generally specific to a target platform and type of apps): Apple App Store, Google Play, Google Apps Marketplace, Amazon App Store, Google Chrome WebStore, Ubuntu Software Center and many more...

As mentioned by stmax in comments, the easiest way to start promoting an app that targets known mobile devices would usually be to use their dedicated app stores. It's rather quick and easy.

Depending on your platform of choice, and whether you want to sell your app or not (and if it supports in-app payments or not), you may want to to look at package management systems. This somewhat similar to software distribution sites (in that they aggregate software distribution in one place and) and app stores (in that they allow one-click install), but usually you only use them directly from you system (and not from the web). A famous example is the debian packaging format, and its mainy repositories and front-ends (which includes the Ubuntu Software Center, for instance).

Social Networks

End-User Social Networks: Facebook, Twitter, Google+, etc... to:

generate buzz,

re-route users to your site,

Professional Social Networks: LinkedIn, Xing|OpenBC

Programmer-Oriented Social Networks: Ohloh, CIA, ...

You can use social aggregators to make things easier to deal with, or at least to make it easier for your users to then enhance your popularity on several networks, for instance with ShareThis or AddThis.

Communicate Actively

This can take some time, but not this much if you're efficient and have things well prepared.

communicate on forums, chat rooms, newsgroups...

DO NOT be spammy,

DO answers that relate to your software, give full disclosure in a proper way, and kindly point people to your software when they request alternatives or solutions.

broadcast updates and news to your different communication streams above, tweet about them, tell your friends on FB, publish an announcement on appropriate mailing-lists:

when you publish a minor revision,

when you have a potential project or feature in mind and need feedback,

when you reach a milestone (# of downloads, # of users...),

anything, really.

Of course, broadcast these to your communication channels described above.

Write Support Material

Write user and developgment guides accordingly.

Publish video tutorials or demonstrations (create a Youtube and/or Vimeo channel).

Write tutorials on how to use your software.

Publish a (tentative) roadmap for future features.

Get Reviewed

Friends can review you on their blogs and social network pages.

Users can review you and you can facilitate that by adding "talk about MY_PROJECT on SOCIAL_NETWORK" link.

Professionals (bloggers, writers, developers...) can review your app, for free or for a compensation (this is a possibly spammy route, beware to contact the right people).

Contact newspapers and technical magazines, online and offline (print is NOT dead). Some might want to write an article on you, some will just write a small column, some won't but will remember your name and product later, and some might just talk about your product to some friends at the bar.

Engage your Users

Request feedback, and permission to publish it, via:

User feedback websites: GetSatisfaction, UserVoice...

Survey systems: SurveyMonkey, built-in services in your blogging / CMS platform...

Hallway testing!!

Listen to feature requests.

Request your users' help in promoting your software.

Request your users' help in identifying flaws and troubleshooting in your software.

Personally, I'm not a fan of the user feedback sites like GetSatisfaction and UserVoice. They tend to slow down your site or web-app, you need to rely on them and if they break they may break parts of your site, and are generally more prone to downtimes than a good old mailing system. So I prefer a mailing-list/newsgroup, maybe with a web-interface as well (like a Google Group), and a simple contact form for the basic user. An issue- and/or bug-tracker is good to have for more advanced users (use one hosted on Google Code Project Hosting, BitBucket, GitHub, Sourceforge, Assembla... depending on your licensing terms, of course) and to let them know about the progress of a feature request and vote for the most requested features or bugfixes).

Advertize

All of the above is advertisement, really, but obviously some more professional advertising can help. And even a 75USD AdWords voucher can go a long way, if you play it right.

You can go further and contact some services that manufacture and sell promotional items for you (mugs, t-shirts, caps, ...). This seems a bit nutty, but some users are happy to have some, and this does sometimes help to reach out to new users. Just make sure to pick the right services, where you won't need to pay much, or anything (some just take a commission on sales of articles).

Stay Up to Date

Publish updates often and communicate about them. Before you know it people will follow suit. Publuish beta-testing versions of upcoming releases, for advanced users only.

Also keep up with competitors and eventually review and compare them. DO NOT be derogatory or pejorative, be fair, do not twist numbers, and point our where you fare better. We don't expect you to to point ou your flaws, but to state what's the small "plus" you have over them.

Zero Budget, 30 minutes

All of this looks like a lot of time and even like it involves some money. But you can do most of it for no cost at all, or very low cost.

If you register for AdWords / AdSense / Google Webmaster Tools, you might eventually get a free voucher, or some friends might have one to spare. Technically this is money, but you didn't actually pay it, you're not down anything.

You can find free hosting services (even Blogger would do) for simple sites with (originally) low to medium traffic, and domain names can be found for very cheap value per year.

And all the communication, while it can be expensive in terms of time, gets better over time:

Write out templates for your release and update announcements for your mailing-list, your tweets, etc..

Make sure to program said updates to be broadcasted automatically to your different commication channels. Automate this as much as possible. It will be worth the time saved over the longer run.

Giving a little of your time every day or every week amounts to a lot in the end, and it's generating constant noise that matters to keep conversations going. And your friends and die-hard fans can help with this as well.

It's important to remember that every single new visitor and new recommendation counts. Whether it's someone publishing a full-page article about you, or just a friend sending a link to your app to another friend or talking about your product over a drink in a bar.

Learn

Put these 30 minutes a day to good use by learning the tools of the trade and the techniques of SEO experts, marketers and advertisers. They are, in the end, valuable skills and knowledge to have.

I remember omeone saying on another StackExchange site you should set apart 5 years of your life to learn them. Though I'd say it really doesn't take this long, there's obviously a lot to learn and various levels of expertise to obtain, but you can learn a great deal.

I'm sure as a developer you'll be happy to learn the more technical bits (like how to create pages that are SEO-friendly), relatively less happy to learn less technical bits (how to produce user-friendly page layouts, based on actual and tested HCI concepts and marketing research, not just programmer's instincts), and a lot less happy to learn the "annoying" bits that relate to marketing and advertising (picking keyword lists, writing good announcements, etc...). The motivator, for me, is to always view it as something technical, in the end: what you want is optimize the visibility, and all this because purely a game of numbers. Learning to write and design decently is just a mean to get these numbers up. Plus I find it interesting to learn UI and UX concepts, for which "lambda" users often have very different expectations than the programmers of an application (hence the need to request a lot of user feedback, and to listen to it).

Stand on the Shoulders of Giants... Be a Copy-Cat

You're not the first person to try to promote a product. Pick a famous product, and look how they did it. How do you get access to this product when you start from 0? Ideally, you want to be able to allow users to do the same with yours. That's what you aim for. Maybe look at some influential commercial or free software project, and look how they created a community, how they communicate around their product. You can try to find innovative ways of promoting yourself (and it's usually good to innovate, to stand out of the crowd), but the good old and tested ways work well, obviously.

Measure, Measure, Measure

I said two things I need to repeat here:

Listen to your users;

It's all about data, not about what you think you know as a programmer.

You can't improve things if you don't know what doesn't work or what is a better alternative. Learn (see above ;)) to use analytics systems (like Google Analytics) to track basic stats about your visitors (population demographics, origins, platforms ...) and more advanced reports (conversion rates, funnels...). Use such tools to measure the impact of changes you make to your site, and get real hard data to be able to know whether a change is beneficial or not.

I've done personal mistakes like this at first, believing my vision was better, and I've had (and still have...) to deal with startup founders who always start 83% of their sentences with "I think that...". No you don't. If you really "thought", you wouldn't say that. You assumed, and that's a bad habit. Usually, when someone says "I think", I now follow up with "prove it", or if I can't and don't believe their claim, I will go do my own hallway testing to prove or disprove their assumption.

A/B testing just works.

Of course, all this also takes time. I'm giving you the tools here, but just do with what you can with your own constraints. You don't need to A/B test every single scenario, and you don't need to re-evaluate every week every single little thing you do. But the more you do it, the better.

All of this meant to consolidate the prevalence of your software's own distribution site.

Your goal is to promote it, and to then allow users to find all the necesasry and relevant information on your site, and to minimize the path to a download.


问:
SQL language drawbacks, The Third Manifesto
Sometime ago I read about SQL language drawbacks
(the basic language specification, not vendor specific),

and one of the drawbacks was that the language does not allow to create a set of tuples that don't come  from a table.

For instance,

```<code>SELECT firstName, lastName from people;
</code>```

this creates a set of tuples coming from the table people.

Now, if I don't have this table people, and I want to return a constant, I'd need something like this to return a set of two tuples (this would not require to have a table):

```<code>SELECT VALUES('james', 'dean'), ('tom', 'cruisse');
</code>```

Why I would need that?

Because of the same reasons that we can define constants (not only basic types, but objects and arrays also) in any advanced programming language.

Workarounds,

Yes, I could create a temporal table, fill the data, and SELECT from that table.
This is a hack, to overcome the drawbacks of the poor SQL language.

I think that I read about this somewhere in "The Third Manifesto",

but I don't find the paragraph/example talking about this concrete drawback anymore.

Do you know a reference about it?

答:
"that the language does not allow to create a set of tuples that don't come from a table.
"

This is not entirely correct.  The standard SQL language has both ROW constructors - ROW('james','dean') - and table constructors - VALUES ( (col1v1, col2v1) (col1v2, col2v2) ).  I'm not entirely certain of the VALUES syntax, so take with a grain of salt here.

Thus, standard SQL indeed has things that resemble

SELECT * FROM VALUES((...),(...));

Standard SQL also has the extremely verbose

SELECT col1v1 AS c1, col2v1 as c2
UNION
SELECT col1v2 AS c1, col2v2 as c2
UNION
...

I cannot point you to a reference yet (other than the SQL standard itself), but reliable sources tell me that a new book is in preparation that will discuss exactly this whole issue of SQL's deficiencies against Third Manifesto norms.

OwnerDisplayName: David Portabella


问:
What is your strategy for converting RC builds into retail?
We're trying to implement a strategy for how we transition our builds from RC to released retail code.

When we label a build as a release candidate, we send it to QA for regression. If they approve it, that RC then becomes our released retail code.

I liked the idea of "obvious" labeling of versions so that a user knows whether they have a beta or an RC or retail code... where you would have some obvious watermark in non-retail code (think Windows 7 where the RC or non-genuine builds watermark in the bottom right).

... but it seemed strange to us to manipulate the project (to remove the watermark) once it passed regression. If QA certified version a.b.c.d then our retail code should be that same version, not a.b.c.d+1

what strategies have you employed to clearly label non-release software versions without incrementing your build to disable the watermarks in your retail code? One idea I've considered is writing your build to look for a signed file in the installer archive... non-release code wouldn't include this file and so the app would know to display a watermark.

But even this seems like QA is then working with non-release code.

Ideas?

EDIT: What about a process that QA themselves can run to remove the "RC" indicator? That might be an interesting way to handle it.

答:
Let us look at this the object oriented way. A project just has a version --in the sense that a code change makes it is different from its previous version. Therefore, version must be a property of the project.

On the other hand, a project (in most cases) does not test itself or certify it. That decision is made by the testing/QA teams. And hence, while you/they can label the project "Alpha", "Beta", "RC", "Gold", "Platinum", "Retail" etc. this labelling is not a property of the build but rather of your perception of that build.

It is tempting to store this information in the project itself (perhaps even in the AssemblyInfo.cs) but as your question and Caleb's answer shows it requires re-building the project after each stage (to edit/remove the watermark).

So here is the solution --generate the watermark at run time by using another system (can be as simple as a web object queryable by your project, a simple file, database entry --you decide). The key is to keep this system outside the project scope and only have the testing authorities update the build "watermarks".

Here is how this system looks like (with the timeline):

```<code>  Version  |   Status |    Comment
------------------------------------------------------------------------------------------------------------
    1.0    |   Alpha  |  First dev. build released
    1.0    |   Beta   |  Dev. team tests and decides to release it as beta without any code change/rebuild
    1.0.1  |   Beta   |  QA team identifies a bug, dev. fixes, rebuilds, updates the version, sends it for more testing.
    1.0.2  |   Beta   |  QA team identifies a bug, dev. fixes, rebuilds, updates the version, sends it for more testing.
    1.1    |   Beta   |  QA team identifies a bug, dev. fixes, rebuilds, updates the version, sends it for more testing.
    1.1    |   RC     |  QA team promotes it to RC build. You send the exact same build for user testing/preview.
    1.1    |   Retail |  Users do not report bugs, QA team also does not. You decide this build (without any change) can be shipped to retail.
</code>```

An added advantage of this system is that you control the build tag and can easily create a newer tag (e.g., expired, recalled) and push it out without application reinstalls or rollouts. As a fail safe, the watermark should show a default value or last queried value in case it cannot establish a connection to the system.

Edit: If you are not fan of external systems, then just keep a simple file within the project itself but not embedded into the main assembly/jar/etc. This file can track the build watermark. The key is to not embed the watermark into a unit that has to be compiled in order to be changed.

Body:
Let us look at this the object oriented way. A project just has a version --in the sense that a code change makes it is different from its previous version. Therefore, version must be a property of the project.

On the other hand, a project (in most cases) does not test itself or certify it. That decision is made by the testing/QA teams. And hence, while you/they can label the project "Alpha", "Beta", "RC", "Gold", "Platinum", "Retail" etc. this labelling is not a property of the build but rather of your perception of that build.

It is tempting to store this information in the project itself (perhaps even in the AssemblyInfo.cs) but as your question and Caleb's answer shows it requires re-building the project after each stage (to edit/remove the watermark).

So here is the solution --generate the watermark at run time by using another system (can be as simple as a web object queryable by your project, a simple file, database entry --you decide). The key is to keep this system outside the project scope and only have the testing authorities update the build "watermarks".

Here is how this system looks like (with the timeline):

  Version  |   Status |    Comment
------------------------------------------------------------------------------------------------------------
    1.0    |   Alpha  |  First dev. build released
    1.0    |   Beta   |  Dev. team tests and decides to release it as beta without any code change/rebuild
    1.0.1  |   Beta   |  QA team identifies a bug, dev. fixes, rebuilds, updates the version, sends it for more testing.
    1.0.2  |   Beta   |  QA team identifies a bug, dev. fixes, rebuilds, updates the version, sends it for more testing.
    1.1    |   Beta   |  QA team identifies a bug, dev. fixes, rebuilds, updates the version, sends it for more testing.
    1.1    |   RC     |  QA team promotes it to RC build. You send the exact same build for user testing/preview.
    1.1    |   Retail |  Users do not report bugs, QA team also does not. You decide this build (without any change) can be shipped to retail.

An added advantage of this system is that you control the build tag and can easily create a newer tag (e.g., expired, recalled) and push it out without application reinstalls or rollouts. As a fail safe, the watermark should show a default value or last queried value in case it cannot establish a connection to the system.

Edit: If you are not fan of external systems, then just keep a simple file within the project itself but not embedded into the main assembly/jar/etc. This file can track the build watermark. The key is to not embed the watermark into a unit that has to be compiled in order to be changed.


问:
Can I use a child class variables in its parent class?
I am programming in Objective C, iOS. I create a Class A which is a parent class, and Class B inherits to Class A.

Now I have Class B variables which I also need to use in Class A. And also one another Class C, Class A add in Class C (not inherits), and I want to use Class B variables in Class C.

How can I access? I have created object also but not working, is that possible to access?

答:
Is it possible to move ClassB's variables to ClassA?

If not then maybe you could add whatever the Obj-C equivalent of pure virtual functions/interface is to ClassA, that ClassB must implement, so that ClassA can use the variables. Then ClassC could also access them through this interface.


答:
IMHO all the 3 approaches are fine

considering all three cases

1. You return a value ('baz') and then apply the assertion using the same value.

2. You are returning a variable which you are assigning while returning the same.

3. You have a previously assigned variable ($result ='baz') which you return and then use the same variable for the assertion.

Your 2nd strategy is a bit tricky because you assign the variable value during return time.

Considering in general case if my function fails to execute.Then trying to use $result variable anywhere else besides the assertion makes no sense since it is unassigned.

Whereas in the other 2 cases I can use the value('baz') directly or use the varable $result.

Title: Assignments in mock return values

Body:
(I will show examples using php and phpunit but this may be applied to any programming language)

The case: let's say we have a method A::foo that delegates some work to class M and returns the value as-is.

Which of these solutions would you choose:

```<code>$mock = $this->getMock('M');
$mock->expects($this->once())
     ->method('bar')
     ->will($this->returnValue('baz'));

$obj = new A($mock);

$this->assertEquals('baz', $obj->foo());
</code>```

or

```<code>$mock = $this->getMock('M');
$mock->expects($this->once())
     ->method('bar')
     ->will($this->returnValue($result = 'baz'));

$obj = new A($mock);

$this->assertEquals($result, $obj->foo());
</code>```

or

```<code>$result = 'baz';
$mock = $this->getMock('M');
$mock->expects($this->once())
     ->method('bar')
     ->will($this->returnValue($result));

$obj = new A($mock);

$this->assertEquals($result, $obj->foo());
</code>```

Personally I always follow the 2nd solution, but just 10 minutes ago I had a conversation with couple of developers who said that it is "too tricky" and chose 3rd or 1st.

So what would you usually do? And do you have any conventions to follow in such cases?


答:
Now I have Class B variables which I also need to use in Class A. And
  also one another Class C, Class A add in Class C (not inherits), and I
  want to use Class B variables in Class C.

How can I access?

Short answer: No, you can't do what you propose.

Longer, more detailed explanation:
Classes don't have variables -- objects do. They're called instance variables (or ivars for short) because they're variables that are associated with an instance of a class, which is to say an object. You declare the variables in the class declaration, of course, but they aren't actually created until the class is instantiated, that is, until an instance (an object) of the class is created.

So, if you have this:

```<code>ClassA *objectA = [[ClassA alloc] init];
ClassB *objectB = [[ClassB alloc] init];
</code>```

then objectA is an instance of ClassA, and objectB is an instance of ClassB. Let's also stipulate (as you have in your question) that ClassB is a subclass of ClassA. That is, it's declared like:

```<code>@interface ClassA : NSObject
{
    int foo;
}

@interface ClassB : ClassA
{
    int bar;
}
</code>```

So to get to your question... objectA has an instance variable called foo, plus any that it inherits from NSObject. objectB has an instance variable called bar, and it also inherits foo from ClassA and whatever ClassA gets from NSObject. objectA does not have an ivar called bar, and trying to access it would cause an error:

```<code>objectA->foo = 1;    // OK
objectB->foo = 2;    // OK
objectA->bar = 3;    // Error!
objectB->bar = 4;    // OK
</code>```

This is because any instance of ClassB is also an instance of ClassA (that's the effect of inheritance) but an instance of ClassA is not necessarily an instance of ClassB. It's okay for code in ClassA to refer to variables or properties in ClassB, but only if it knows that it's dealing with an instance of ClassB. So you could have a method like:

```<code>- (void)addBar:(ClassB*)someB
{
    foo += someB->bar;
}
</code>```

That's okay because you know that someB is supposed to be an instance of ClassB. What you can't do in ClassA is:

```<code>- (void)addBar:(ClassB*)someB
{
    bar += someB->bar;    // Error! ClassA doesn't have a 'bar' ivar!
}
</code>```

because, again, ClassA doesn't have an ivar named bar.

By the way, even the first example isn't great form -- unless there's a good reason, it's better to avoid the situation where a class (like ClassA) is dependent on its own subclass (like ClassB).

Title: Can I use a child class variables in its parent class?

Body:
I am programming in Objective C, iOS. I create a Class A which is a parent class, and Class B inherits to Class A.

Now I have Class B variables which I also need to use in Class A. And also one another Class C, Class A add in Class C (not inherits), and I want to use Class B variables in Class C.

How can I access? I have created object also but not working, is that possible to access?

Body:
Now I have Class B variables which I also need to use in Class A. And
  also one another Class C, Class A add in Class C (not inherits), and I
  want to use Class B variables in Class C.

How can I access?

Short answer: No, you can't do what you propose.

Longer, more detailed explanation:
Classes don't have variables -- objects do. They're called instance variables (or ivars for short) because they're variables that are associated with an instance of a class, which is to say an object. You declare the variables in the class declaration, of course, but they aren't actually created until the class is instantiated, that is, until an instance (an object) of the class is created.

So, if you have this:

ClassA *objectA = [[ClassA alloc] init];
ClassB *objectB = [[ClassB alloc] init];

then objectA is an instance of ClassA, and objectB is an instance of ClassB. Let's also stipulate (as you have in your question) that ClassB is a subclass of ClassA. That is, it's declared like:

@interface ClassA : NSObject
{
    int foo;
}

@interface ClassB : ClassA
{
    int bar;
}

So to get to your question... objectA has an instance variable called foo, plus any that it inherits from NSObject. objectB has an instance variable called bar, and it also inherits foo from ClassA and whatever ClassA gets from NSObject. objectA does not have an ivar called bar, and trying to access it would cause an error:

objectA->foo = 1;    // OK
objectB->foo = 2;    // OK
objectA->bar = 3;    // Error!
objectB->bar = 4;    // OK

This is because any instance of ClassB is also an instance of ClassA (that's the effect of inheritance) but an instance of ClassA is not necessarily an instance of ClassB. It's okay for code in ClassA to refer to variables or properties in ClassB, but only if it knows that it's dealing with an instance of ClassB. So you could have a method like:

- (void)addBar:(ClassB*)someB
{
    foo += someB->bar;
}

That's okay because you know that someB is supposed to be an instance of ClassB. What you can't do in ClassA is:

- (void)addBar:(ClassB*)someB
{
    bar += someB->bar;    // Error! ClassA doesn't have a 'bar' ivar!
}

because, again, ClassA doesn't have an ivar named bar.

By the way, even the first example isn't great form -- unless there's a good reason, it's better to avoid the situation where a class (like ClassA) is dependent on its own subclass (like ClassB).


问:
How does the Java Virtual Machine execute code written in other languages?
Since Java 1.6 the JVM can run a myriad of programming languages on top of instead of just Java. I conceptually understand how Java is run on the Java VM, but not how other languages can run on it as well. To me, it all looks like black magic. Do you have any articles to point me to so I can better understand how this all fits together?</p>

答:
The key is the native language of the JVM: the Java bytecode. Any language can be compiled into bytecode which the JVM understands - all you need for this is a compiler emitting bytecode. From then on, there is no difference from the JVM's point of view. So much so that you can take a compiled Scala, Clojure, Jython etc. class file and decompile it (using e.g. JAD) into normal looking Java source code.

You can find more details about this in the following articles / threads:

Java virtual machine (Wikipedia)

Why do we need other JVM languages (Stack Overflow)

I am not aware of any fundamental changes in the Java 5 or 6 JVMs which would have made it possible or easier for (code compiled from) other languages to run on it. In my understanding, the JVM 1.4 was more or less as capable in that respect as JVM 6 (there may be differences though; I am not a JVM expert). It was just that people started to develop other languages and/or bytecode compilers in the first half of the decade, and the results started to appear (and become wider known) around 2006 when Java 6 was published.

However, all these JVM versions share some limitations: the JVM is statically typed by nature, and up to release 7, did not support dynamic languages. This has changed with the introduction of invokedynamic, a new bytecode instruction which enables method invocation relying on dynamic type checking.

ContentLicense: CC BY-SA 4.0


问:
What licence should I use for internal projects?
I need to package an internal project as a debian package. That project will never ever be downloaded by anyone outside of our company, but the debian packaging system insists on there being a copyright file.

What should I choose for this file? There's a remote possibility that a sysadmin could stumble upon that package and would like to read its licence. What should it then read?

答: for internal code I would make the copyright file simply be a one line copyright 'your company here' licenses are for distribution of code and you aren't distributing. I would hope your sysadmin knows the name of your company.


问:
Plan variable and call dependencies
I'd like to write down the design of my program to understand the dependencies and calls better. I know there are class diagrams which show inheritance and attribute variables.

However I'd also like to document the input parameters to method functions and in particular which calls the methods function executes inside (e.g. on the input parameters).

Also sometimes it might be useful to show how actual objects are connected (if there is a standard structure).

This way I can have a better understanding of the modules and design before starting to program. Can you suggest a method to do this software design? It should be one-to-one to programming code structure so that I really notice all quirks beforehand (instead of high-level design where thing are hard to implement without further work).
Maybe some special diagram or tool or a combination?

It is static dependency and call design rather than time dependent execution monitoring.

(I use Python if you have any specialized recommendations).

答:
I don't think there is any one diagram standard to represent everything.

Typically, I think for going from requirements to design, I would follow these steps:

Use case diagrams

Sequence diagrams

Class Diagrams

You might also want to have a look at Collaboration diagrams.

The use cases give a higher level approach which you can skip in your case.

I have found the sequence diagrams most helpful in drawing out my mind. It helps put on paper the first logical objects and the interactions between them. I have also found these to be most helpful in understanding the behavior of an already built system.

Once those are clear and if you need then you can start making a class diagram with as much detail as you want. Class diagrams are static. If you are using a good IDE, you will hardly miss class diagrams.

Title: Plan variable and call dependencies


答: Although it's likely that Ryathal's answer is suitable in most instances, you might also want to consult your manager or legal department. There might be a standard template for projects. Although it's currently an internal product, it would be wise to have your company's standard copyright/license notice (if one exists) should it ever be released or sold in the future, or perhaps in a worse case gets leaked.</p>

Title: What licence should I use for internal projects?

Body:
I need to package an internal project as a debian package. That project will never ever be downloaded by anyone outside of our company, but the debian packaging system insists on there being a copyright file.

What should I choose for this file? There's a remote possibility that a sysadmin could stumble upon that package and would like to read its licence. What should it then read?


答:
A virtual machine, like the JVM, is a program that accepts as input, usually files, a set of simple instructions (that are usually easy to convert to real CPU instructions), and actually  compiles and runs them as native CPU instructions (usually using an on-demand compiler such as HotSpot or JIT).

It's essentially a layer of abstraction. It's usually much easier to port VM instruction set implementations to different processor architectures, because of several similarities (such as being stack based). It's also much easier to port different programming languages to VM instructions, since it's more oriented toward modern programming languages than the primitive CPU instructions. Many Virtual Machines such as the JVM and the CLR (.NET) contain instructions for calling virtual methods, and creating object instances.

So let's take a language for example. Call it MyLanguage. Since it is a programming language, it ultimately compiles down to a set of some CPU architecture instructions.
So that means that, given a compatible, flexible Virtual Machine instruction set, it's also possible to compile MyLanguage down to a set of that VM's instructions.

There are always question of efficiency, since you might need to hack some workarounds in VM instruction sets that you wouldn't have to do natively, but it's still possible.

Title: How does the Java Virtual Machine execute code written in other languages?

Body: Since Java 1.6 the JVM can run a myriad of programming languages on top of instead of just Java. I conceptually understand how Java is run on the Java VM, but not how other languages can run on it as well. To me, it all looks like black magic. Do you have any articles to point me to so I can better understand how this all fits together?</p>


问:
Planning milestones and time
I was hired by a marketing company a year ago initially for link building / SEO stuff, but I'm actually a Web developer and took the job just in desperation to have one (I'm still quite young and just finished 2nd year of University). From the 3rd day my boss realised that I'm not into that stuff at all and since he had an idea of a web based app we started to plan it.

I estimated that it shouldn't take me longer than two months to do it, but as I was making it we soon realised that we want to add more and more stuff to make it even better.

So the development on my own lasted for about 4 months, but then it became an enterprise size app and we hired another programmer to work along me. The guy was awesome at what he did, but because I was assigned to be programmer/project manager I had to set up milestones with deadlines and we missed most of them, because most of the time it was too much work, and my lack of experience kept me setting really optimistic deadlines. We still kept adding features and had changed the architecture of the application twice.

My boss is a great guy and he gets that when we add features it expands the time frame in which things should be done so he wasn't angry at me nor the other guy. But I was feeling bad (I still am) that I suck at planning.

I gained loads of experience from the programming side, but I still lack the management/planning skills which make me go nuts. So over the last year I have dedicated probably about 8 months of work to this app (obviously my studies affected it) and we're launching as a closed beta this month. So my question is how do I get better at planning/managing a project, how do you estimate the times? What do you take into consideration when setting goals.

I'm working alone again because the other guy moved from the city. But I'm sure we'll be hiring to help me maintain it so I need to get better at it.

Any hints, points or anything on the topic are appreciated.

答:
Here is an excellent article by Joel Spolsky: http://www.joelonsoftware.com/items/2007/10/26.html

It's a very simple process that basically advocates estimating how wrong your estimates are going to be by keeping track of how wrong they have been in the past.  Over time you'll end up with much better guesses at the time it takes to do things.  It's not an instant fix but, then again, accurate scheduling of software projects is very hard.

He also advocates breaking projects down into very small (and theoretically easier to estimate) parts.

Title: Planning milestones and time


答:
Part of knowing how to plan out timelines, dependencies, etc., will come from experience.  However, that being said, it's a very different skill set than web development and programming.  Part of that experience you're gaining is that project management probably isn't your thing, and there's nothing to be ashamed in that.  To be honest, I'm surprised they expected a full project manager out of you, knowing that you are still in the middle of your studies.  I've known people that have been doing project management professionally for many years who still don't quite get it!

Unless you are really in need of the money, I'd encourage you to place an increased emphasis on your studies over this work.  If you really enjoy doing web development, and you want to succeed in it, then you should focus on improving your knowledge and skill set of that type of work and step away from this project management role.  There's no shame in telling your boss that you've come to realize that you bit off more than you can chew and that you've run into personal limitations that might hurt your organization.  Tell him that you'd like to keep working with him but strictly in a development role.  If he's a great boss, he'll recognize how that will benefit both of you, and you can push your career farther than you could otherwise.

Title: Planning milestones and time

Body:
I was hired by a marketing company a year ago initially for link building / SEO stuff, but I'm actually a Web developer and took the job just in desperation to have one (I'm still quite young and just finished 2nd year of University). From the 3rd day my boss realised that I'm not into that stuff at all and since he had an idea of a web based app we started to plan it.

I estimated that it shouldn't take me longer than two months to do it, but as I was making it we soon realised that we want to add more and more stuff to make it even better.

So the development on my own lasted for about 4 months, but then it became an enterprise size app and we hired another programmer to work along me. The guy was awesome at what he did, but because I was assigned to be programmer/project manager I had to set up milestones with deadlines and we missed most of them, because most of the time it was too much work, and my lack of experience kept me setting really optimistic deadlines. We still kept adding features and had changed the architecture of the application twice.

My boss is a great guy and he gets that when we add features it expands the time frame in which things should be done so he wasn't angry at me nor the other guy. But I was feeling bad (I still am) that I suck at planning.

I gained loads of experience from the programming side, but I still lack the management/planning skills which make me go nuts. So over the last year I have dedicated probably about 8 months of work to this app (obviously my studies affected it) and we're launching as a closed beta this month. So my question is how do I get better at planning/managing a project, how do you estimate the times? What do you take into consideration when setting goals.

I'm working alone again because the other guy moved from the city. But I'm sure we'll be hiring to help me maintain it so I need to get better at it.

Any hints, points or anything on the topic are appreciated.


答:
The only way to get better at estimating is to do it more, less experienced developers are generally overly optimistic. From what you wrote it doesn't look like estimation was your issue, it was scope creep.

You will probably have a class eventually about project management, but as a quick overview the PM is responsible for a lot more than setting the schedule and keeping it on track. They are also responsible for ensuring that the project that was defined at the start in the project charter/other documents is the project that gets worked on. In your case t seems you ended up doing a poor job of this because you went from a small app to an enterprise wide app. This is a hard thing to manage though, especially when you are also a developer on the project. Developers tend to always want to add to and improve everything they work on indefinitely and never really get to the release part. As a PM sometimes you need to tell developers their plans are out of scope or X feature is good enough already start working on Y.

Title: Planning milestones and time


答: A JVM is a Turing-complete compute machine (except for limited memory), and any Turing-complete machine (physical or virtual) can execute any programming language (except for memory, performance and physical IO limitations).</p>


问:
Is Microsoft Prism alive and active?
I've been doing a lot of reading these last two days on Microsoft Prism, but the thing I'm still not very sure of is what does the future look like for it? I know that version 4.1 was just released a few months ago, but besides Microsoft's own documentation, I haven't found many blog posts written in the last year on the subject, most of what I find is 2009-2010.

It definitely looks interesting but the learning curve seems to be a bit steep and I wouldn't want to embark if it's going to become obsolete in the near future. Anyone has any insight on this?

答:
Yes it is still active, I mean is not the most popular MS project that does not mean that is inactive, in general when a considerable big company Google, MS, Apple or organization like Apache will stop development of certain project they will make it clear month if not a year before. That being said in the official Doc there is no sign of being abandon or dropped either. Although I am not a MS fan or ever heard of Prism seems like a solid unknown project.

If you go to this Codeplex site:

```<code>future releases

Prism 4.1 targetting Silverlight 5. Go here to learn about future releases.
Prism 4.5 targetting .NET 4.5.
</code>```

Title: Is Microsoft Prism alive and active?

Body:
Yes it is still active, I mean is not the most popular MS project that does not mean that is inactive, in general when a considerable big company Google, MS, Apple or organization like Apache will stop development of certain project they will make it clear month if not a year before. That being said in the official Doc there is no sign of being abandon or dropped either. Although I am not a MS fan or ever heard of Prism seems like a solid unknown project.

If you go to this Codeplex site:

future releases

Prism 4.1 targetting Silverlight 5. Go here to learn about future releases.
Prism 4.5 targetting .NET 4.5.


问:
What does it mean to do a "null check" in C or C++?
I have been learning C++ and I am having a hard time understanding null. In particular, the tutorials I have read mention doing a "null check", but I am not sure what that means or why it's necessary.

What exactly is null?

What does it mean to "check for null"?

Do I always need to check for null?

Any code examples would be much appreciated.

答:
There are a couple of methods, all essentially do the same thing.

```
int *foo = NULL;  //sometimes set to 0x00 or 0 or 0L instead of NULL
```

null check (check if the pointer is null), version A

```
if( foo == NULL)
```

null check, version B

```
if( !foo )  //since NULL is defined as 0, !foo will return a value from a null pointer
```

null check, version C

```
if( foo == 0 )
```

Of the three, I prefer to use the first check as it explicitly tells future developers what you were trying to check for AND it makes it clear that you expected foo to be a pointer.

Body:
There are a couple of methods, all essentially do the same thing.

int *foo = NULL;  //sometimes set to 0x00 or 0 or 0L instead of NULL

null check (check if the pointer is null), version A

if( foo == NULL)

null check, version B

if( !foo )  //since NULL is defined as 0, !foo will return a value from a null pointer

null check, version C

if( foo == 0 )

Of the three, I prefer to use the first check as it explicitly tells future developers what you were trying to check for AND it makes it clear that you expected foo to be a pointer.


答:
The other answers pretty much covered your exact question. A null check is made to be sure that the pointer you received actually points to a valid instance of a type (objects, primitives, etc).

I'm going to add my own piece of advice here, though. Avoid null checks. :) Null checks (and other forms of Defensive Programming) clutter code up, and actually make it more error prone than other error-handling techniques.

My favorite technique when it comes to object pointers is to use the Null Object pattern. That means returning a (pointer - or even better, reference to an) empty array or list instead of null, or returning an empty string ("") instead of null, or even the string "0" (or something equivalent to "nothing" in the context) where you expect it to be parsed to an integer.

As a bonus, here's a little something you might not have known about the null pointer, which was (first formally) implemented by C.A.R. Hoare for the Algol W language in 1965.

I call it my billion-dollar mistake. It was the invention of the null reference in 1965. At that time, I was designing the first comprehensive type system for references in an object oriented language (ALGOL W). My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn't resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years.

Title: What does it mean to do a "null check" in C or C++?

Body:
I have been learning C++ and I am having a hard time understanding null. In particular, the tutorials I have read mention doing a "null check", but I am not sure what that means or why it's necessary.

What exactly is null?

What does it mean to "check for null"?

Do I always need to check for null?

Any code examples would be much appreciated.


答: You don't. The only reason to use a pointer in C++ is because you explicitly want the presence of null pointers; else, you can take a reference, which is both semantically easier to use and guarantees non-null.</p>


问:
Is it possible to know what programming language a web-site uses?
For example, stackexchange.com, without asking the site owner or Google their information about developing the website, is this possible to know what language is used in the back end?

Seems, the website don't have .extension bar, for example .php that can indicated which is developed in PHP, but without the extension, how can I know that?

答: Well, there is the humans.txt file that a developer can put up on the domain that gives some information about the site development, maybe who worked on it and what standards or tools were used. If they want you to know about those kinds of information, they could/should put it there. However, just like anything else this is optional so it can't guarantee to inform you either. Check out humans.text</p>


答: You should explore Visual Studio's Configuration Manager.  It can do what you want it to do.  We implemented each configuration with a different Installer Project so that for each build all that was needed was to run compile on the installer project that the desire was to build.  We incorperated Dev/Test/prod watermarking scheme into that.</p>

Title: What is your strategy for converting RC builds into retail?

Body:
We're trying to implement a strategy for how we transition our builds from RC to released retail code.

When we label a build as a release candidate, we send it to QA for regression. If they approve it, that RC then becomes our released retail code.

I liked the idea of "obvious" labeling of versions so that a user knows whether they have a beta or an RC or retail code... where you would have some obvious watermark in non-retail code (think Windows 7 where the RC or non-genuine builds watermark in the bottom right).

... but it seemed strange to us to manipulate the project (to remove the watermark) once it passed regression. If QA certified version a.b.c.d then our retail code should be that same version, not a.b.c.d+1

what strategies have you employed to clearly label non-release software versions without incrementing your build to disable the watermarks in your retail code? One idea I've considered is writing your build to look for a signed file in the installer archive... non-release code wouldn't include this file and so the app would know to display a watermark.

But even this seems like QA is then working with non-release code.

Ideas?

EDIT: What about a process that QA themselves can run to remove the "RC" indicator? That might be an interesting way to handle it.


问:
displaying multi-section html documents - best practices
I work at a research organization and we publish a lot of large-ish documents, usually organized in sections. What I want to know is how best to present these multi-section documents on our website.

Presently, what I do is load the entire document as a single page, with each section as its own div. Then I show and hide divs as needed via a table of contents and "next" and "prev" buttons.

The advantages to this are mainly: 1) that you can move between sections very quickly, 2) it produces consistent analytics (when a page is loaded, I know a report is being read).

The disadvantages, however, are real:

Readers can't take advantage of browser back/forward buttons to move between sections.

It's complicated to create direct links to individual sections (I can do it with javascript but it's not easy for other people to grab and share).

For long reports, you have to wait for the full report to load before you can move around (and that can include hordes of images and charts).

Do other people have thoughts on better ways to organize this? Here's an example of the current system: http://massbudget.org/825

答: Only load the abstract of a report on the page, if a user wants to read more provide a download of a PDF that contains the full report and has sections. An abstract should have everything you need from an SEO perspective.</p>


问:
dvcs - is "clone to branch" a common workflow?
I was recently discussing dvcs with a coworker, because our office is beginning to consider switching from TFS (we're a MS shop). In the process, I got very confused because he said that although he uses Mercurial, he hadn't heard of a "branch" or "checkout" command, and these terms were unfamiliar to him. After wondering how it was possible that he didn't know about them and explaining how dvcs branches work "in place" on your local files, he was quite confused.

He explained that, similar to how TFS works, when he wants to create a "branch" he does it by cloning, so he has an entire copy of his repo. This seemed really strange to me, but the benefit, which I have to concede, is that you can look at or work on two branches simultaneously because the files are separate.

In searching this site to see if this has been asked before I saw a comment that many online resources promote this "clone to branch" methodology, to the poster's dismay. Is this actually common in the dvcs community? And what are some of the pros and cons of going this way? I would never do it since I have no need to see multiple branches at once, switching is fast, and I don't need all the clones filling up my disk.

答:
I wouldn't personally worry about code filling up my disk... first, it's just code, and second, you're not going to keep all of your clones around forever. </p>

<p>This methodology is promoted in a lot of online resources, especially for Hg. I've never seen it used in production, in CI environments it's much more common to have short lived feature branches than additional repository clones. I don't see the advantage of doing this, if anything it's going to make your history more confusing, not less, and it also doesn't gain you anything. If you want to look at your new code side by side with the old code you can use a diff/merge tool to look at the two commits next to each other, with the added advantage that you will see your changes highlighted. </p>

Body:
I wouldn't personally worry about code filling up my disk... first, it's just code, and second, you're not going to keep all of your clones around forever.

This methodology is promoted in a lot of online resources, especially for Hg. I've never seen it used in production, in CI environments it's much more common to have short lived feature branches than additional repository clones. I don't see the advantage of doing this, if anything it's going to make your history more confusing, not less, and it also doesn't gain you anything. If you want to look at your new code side by side with the old code you can use a diff/merge tool to look at the two commits next to each other, with the added advantage that you will see your changes highlighted.


问:
Is event sourcing ready for prime time?
Event Sourcing was popularized by LMAX as a means to provide speed, performance scalability, transparent persistence and transparent live mirroring. Before being rebranded as Event Sourcing, this type of architectural pattern was known as System Prevalence but yet I was never familiar with this pattern before the LMAX team went public. </p>

<p>Has this pattern proved itself in numerous production systems and therefore even conservative individuals should feel empowered to embrace this pattern or is event sourcing / system prevalence an exotic pattern that is best left for the fearless? </p>

答:
The concepts behind Event Sourcing have been around a long time, and often with other names.  Tandem computers were built on this idea as was IBMs IMS TM.  IMS TM was developed for the Apollo space program in the 60s and Tandem appeared in the 70s.

Many modern high-performance systems for the financial domain are built on such patterns.  Almost all are custom builds.  Unfortunately no one to my knowledge has offered a product that supports Event Sourcing and CQRS to a suitable standard for production systems.  It is something I've often considered doing having built many such systems over the years.  Just never had the right opportunity.

Title: Is event sourcing ready for prime time?


答:
Your setup doesn't sound that bad at all. To improve the user experience you can integrate the "page changes" into the browser's history. This will allow the back and forward buttons to work as expected.

Also, you can change the URL in the browser's address bar whenever a "page change" occurs. You don't need to reload the page in order to do this. (I imagine this is also part of browsers' history API.) Then people can easily grab a link to the "page" they are reading and share it. When one of those links is requested, you wont need much (if any) JavaScript to "navigate"  to it. You can just deliver the page as it needs to be.

For an example of these features, take a look at any GitHub code repository and browse the code.

Title: displaying multi-section html documents - best practices

Body:
I work at a research organization and we publish a lot of large-ish documents, usually organized in sections. What I want to know is how best to present these multi-section documents on our website.

Presently, what I do is load the entire document as a single page, with each section as its own div. Then I show and hide divs as needed via a table of contents and "next" and "prev" buttons.

The advantages to this are mainly: 1) that you can move between sections very quickly, 2) it produces consistent analytics (when a page is loaded, I know a report is being read).

The disadvantages, however, are real:

Readers can't take advantage of browser back/forward buttons to move between sections.

It's complicated to create direct links to individual sections (I can do it with javascript but it's not easy for other people to grab and share).

For long reports, you have to wait for the full report to load before you can move around (and that can include hordes of images and charts).

Do other people have thoughts on better ways to organize this? Here's an example of the current system: http://massbudget.org/825


答:
Apart from the general advantage/disadvantage of being able to see both branches, I think there's a Mercurial-specific advantage to doing that.

If you clone to create a branch, you can delete the clone later if you don't want to keep your changes. If you decide to merge them, then the fact that you decided to separate your changes out in this way isn't visible to anybody else.

By contrast, if you use hg branch to create a new named branch, the branch name is recorded in the history when you commit, is visible to everybody else, and has to be fairly unique in order to avoid potential confusion later. This might not be appropriate if your branch is for developing some experimental feature, or for a change that might turn out to be small.

If you use named branches to maintain released versions of your software and also use them for developing short-term features or bugfixes, it's easy to become confused because there is no way (besides naming conventions) to keep these two kinds of branches separate.

http://mercurial.selenic.com/wiki/StandardBranching explains this in more detail. It's also worth mentioning that since Mercurial 1.8, it's possible to create a bookmark (hg bookmark) - a disposable name for a short-lived branch. Bookmarks can be pushed, pulled, moved around and deleted.

Title: dvcs - is "clone to branch" a common workflow?

Body:
I was recently discussing dvcs with a coworker, because our office is beginning to consider switching from TFS (we're a MS shop). In the process, I got very confused because he said that although he uses Mercurial, he hadn't heard of a "branch" or "checkout" command, and these terms were unfamiliar to him. After wondering how it was possible that he didn't know about them and explaining how dvcs branches work "in place" on your local files, he was quite confused.

He explained that, similar to how TFS works, when he wants to create a "branch" he does it by cloning, so he has an entire copy of his repo. This seemed really strange to me, but the benefit, which I have to concede, is that you can look at or work on two branches simultaneously because the files are separate.

In searching this site to see if this has been asked before I saw a comment that many online resources promote this "clone to branch" methodology, to the poster's dismay. Is this actually common in the dvcs community? And what are some of the pros and cons of going this way? I would never do it since I have no need to see multiple branches at once, switching is fast, and I don't need all the clones filling up my disk.


问:
What is the definition of "Big Data"?
Is there one?

All the definitions I can find describe the size, complexity / variety or velocity of the data.

Wikipedia's definition is the only one I've found with an actual number

Big data sizes are a constantly moving target, as of 2012 ranging from a few dozen terabytes to many petabytes of data in a single data set.

However, this seemingly contradicts the MIKE2.0 definition, referenced in the next paragraph, which indicates that "big" data can be small and that 100,000 sensors on an aircraft creating only 3GB of data could be considered big.

IBM despite saying that:

Big data is more simply than a matter of size.

have emphasised size in their definition.

O'Reilly has stressed "volume, velocity and variety" as well. Though explained well, and in more depth, the definition seems to be a re-hash of the others - or vice-versa of course.

I think that a Computer Weekly article title sums up a number of articles fairly well "What is big data and how can it be used to gain competitive advantage".

But ZDNet wins with the following from 2012:

“Big Data” is a catch phrase that has been bubbling up from the high
  performance computing niche of the IT market... If one sits through
  the presentations from ten suppliers of technology, fifteen or so
  different definitions are likely to come forward. Each definition, of
  course, tends to support the need for that supplier’s products and
  services. Imagine that.

Basically "big data" is "big" in some way shape or form.

What is "big"? Is it quantifiable at the current time?

If "big" is unquantifiable is there a definition that does not rely solely on generalities?

答:
There isn't one; it's a buzzword.

The delineator though is that your data is beyond the capabilities of traditional systems. The data is too large to store on the largest disk, the queries take tons too long without special optimization, the network or disk can't support the incoming traffic flow, a plain old dataview isn't going to handle visualization for the shape/size/breadth of data...

Basically, that your data is beyond some ill-defined tipping point where "just add more hardware" isn't going to cut it.

Title: What is the definition of "Big Data"?


答:
Best practice is to do AJAX based development. For browser history you can then use a plugin like ajaxhistory if you are developing over plain javascript.

If you are using a library such as jquery or prototype, then you can use a plugin provided for those. e.g., jquery-history-plugin


问:
Is the agile approach too much of a convenient excuse for cowboys
I believe that an agile approach is best for projects where the requirements are fuzzy and a lot of interaction is required to help shape the end user's ideas.

However... In my professional work, I keep ending up at companies where an "agile" approach is used as an excuse as to why no effort was put into an up front design; when the requirements are well understood.

I can't help but thinking that if the agile approach wasn't around, I'd be sitting here with a nice high-level specification and not having to revisit the same screen and functionality every second day when something else crops up or so and so hadn't thought of that.

Are the benefits of agile methodologies really enough to outweigh the excuse for being lame it gives to cowboy technical leads?

Update: Ironically I'm now a certified Scrum Master. One of the papers presented on the Scrum course observed that the best development process was one where there was a single expert or guru making the design decisions, however that has obvious weaknesses. Scrum shifts the responsibility for producing quality software to the "Team" which means a sub-standard team can get away with churning out spaghetti which I guess is no different to other Agile and non-Agile development processes.

答:
I think its true, in some environments Agile is used as an excuse for no discipline.  The real problem is we've lost sight of why we have any methodology.  Personally, I feel the methodology is an architectural issue in the sense that the architecture of the system is supposed to address the non-functional, quality attributes, the methodology should be addressing some of those same attributes (maintainability, development productivity, knowledge transfer, et al.)

Viewing the methodology as a control for the process attributes implies a couple of things:  1)  without metrics we cannot compare the effectiveness of one methodology over another, 2) an active decision needs to be made about what attributes are important (delivery time vs code quality vs knowledge transfer).

Without having both metrics and a tangible goal, we simply choose a methodology as our "magic feather" that if we hold on to tight, we'll be able to deliver software.

Now the nay-sayers of Agile, XP, Scrum, etc talk about the fragility of that particular category of methodologies.  The argument being:  why use a methodology that can be sabotaged by one individual lacking the discipline to follow all the rules?  The question is a valid one; however, that is the symptom, not the cause.  If an accurate and meaningful (that's the hard part) set of process metrics are defined, tested, and timely feedback given I think we'll discover the particular methodology has little to do with success. (Anecdotally speaking I've seen successful projects using a myriad of methodologies and twice as many fail using the same methodologies)

So what are the metrics?  They vary from project to project, team to team, and time to time.  Useful for when the delivery schedule is important, one that I've personally used is estimation skill and quality.  Most developers can accurately estimate tasks that are a week long or less.  So one approach is to divide up the project into tasks one developer-week long and track who made the estimation.  As the project goes along, they may change their estimates.  After a task is complete, if its off by more than 10% (1/2 a day) we treat this the same as a bug - we identify why the estimate was off (i.e. a database table wasn't considered), identify the corrective action (i.e. involve the DBA in the estimation), and then move on.  Using this information we can create metrics such as # of estimation bugs per week, # of bugs per developer, # of bugs per KLOC, # of bugs per developer-KLOC, etc.  Posting these numbers on the team wiki provides serious social pressure and from the managerial perspective, after a couple of weeks, you can generate a predictive model of subsequent development weeks.

So what?  That's when the methodologies come in - if you have a predictive model that fails to meet the process qualities, you can choose to add or remove some aspect of the methodology and see how it affects your model.  Granted, no one wants to play with a development process for fear of failure, but we're already failing at a consistently high and predictable rate.  By making individual changes and measuring the result you may find that Agile is the perfect methodology for your team, but you could just as easily find RUP, waterfall, or just a hodge-podge of best practices to be ideal.

So my suggestion is lets stop worrying about what we call the process, put in place checks that are relevant to our development process goals, and experiment with different techniques to improve that process.

OwnerDisplayName: TEC


问:
On mobile is there a reason why processes are often short lived and must persist their state explicitly?
Most mobile platforms (such as Android, iOS, Windows phone 7 and I believe the new WinRT) can kill inactive application processes under memory pressure. To prevent this from affecting the user experience applications are expected to save and restore their state as their process is killed and restarted.

Having application processes killed in this way makes the developers job harder.

On various occasions I've seen a mobile app that would:

Return to the welcome screen each time I switch back to it.

Crash when I switch back to it (possibly accessing some state that no longer exists after the process was killed)

Misbehave when I switch back to it (sometimes requiring a restart or tasks killer to fix)

Otherwise misbehave in some hard to reproduce way (e.g. android service killed and restarted at the wrong time)

I don't really understand why these mobile operating systems are designed to kill tasks in this way especially since it makes application development more difficult and error prone.

Desktop operating systems don't kill processes like that. They swap out unused pages of memory to mass storage. Is there a reason why the same approach isn't used on mobile? Mobile hardware is only a few years behind PC hardware in term of performance.

I'm sure there are very good reasons why mobile operating systems are designed this way. If you can point me to a paper or blog post that explain these reasons or can give me some insight I'd very much appreciate it.

答:
Swapping goes some way towards fixing the problem, but it isn't necessarily a complete solution. Here are some reasons why you might not want to swap:

When swap space gets low, you would have to kill apps anyway, and deal with their potential bugginess. You could partially mitigate this by reserving some space on the flash for swap, but then you're taking that space away from users.

Some memory can't be swapped out. Which memory this is normally depends on the OS. One example might be a gallery application that uses hardware acceleration to scale photos - in that case, a sizeable portion of its memory might not be swappable because it's mapped into the GPU.

Swapping costs power and a bit of time (even if it's not very much), whereas killing apps would normally save power.

Another reason (although this is just speculation) might be that if you run out of swap and apps that normally behave well start misbehaving because you had to kill them, users will perceive that to be a problem with your OS. If some apps always misbehave because you kill them all the time and they can't handle it, users are more likely to see that as a bug in the app.


问:
File Upload Forms: Security
SO I'm building an application for uploading files. We're paying scientists to contribute information on pests, diseases and bugs (for Plants). We need the ability to drag and drop a file to upload it.

The question becomes since the users will be authicentated and setup by us, will it be necessarcy to include a virus scanner to prevent the uploading and insertition of malicious files.

How important is this?

答: Yes. Always. Never consider not scanning the files. The scanner may not be perfect, but at least you have something that can be updated when new "bad file" cases are found, rather than nothing at all. The people uploading the files might be, under good intentions and unknowingly, uploading a file that has a virus or malicious code in it. Even if you never handle the file in a way that can harm you, it could harm the computers of the people who retrieve the files. Think of it this way: you're using authentication to help protect access to the files, whereas  you would use virus scanner to help protect the safety of the computers that will use or handle the files. They are two different things that need to be taken into consideration.</p>

Title: File Upload Forms: Security


问:
Do you start migrating your Swing project to JavaFX
I have a 4 years old project which is written in Swing + SwingX. Currently, it is still alive and still kicking.

However, as more GUI related feature requests coming in (For instance, a sortable tree table), I start to feel the difficulty in fulling the requests. This is true especially since there isn't any active development going around SwingX project.

Also, I can hardly find any good, yet actively maintained/ developed/ evolving GUI Java framework.

I was wondering, do any of the Swing developers feel the same thing? Have you start to migrate your Swing project to a much more active developed GUI framework, like JavaFX?

答:
(For instance, a sortable tree table), I start to feel the difficulty in fulling the requests. This is true especially there isn't active development going around SwingX project.

not true, again is this project alive,

blablabla once time when SwingX lost the grants by Sun (during aquiring by Oracle) peoples from SwingX went to built JavaFX

Also, I hardly can find any good, yet being actively maintained/ developed/ evolving GUI Java framework.

no Swing isn't about Framework but about Look and Feel

Frameworks are for non_technical users (MsAccess is may be the best example for GUI Framework)

but if you want to build an real application you have got strong knowledges about Swing and overriden came from Framework too,

funny example Netbeans has built_in Swing Framework based on JSR296, but there isn't able to change JFrames Icon directly,

Have you start to migrate your Swing project to a much more active developed GUI framework like JavaFX?

no reason why

same with migrating to Java7, maybe when will be there Java7.15 - 17

I'm compare JavaFx to with the Nimbus, development ended/give up somewhere in the first half

sorry I'm not developer I'm only Java & Swing Fan


答:
One thing that helps us a lot is to have a standard estimating template that we use for every project. It forces us to include time for things developers might forget in their estimates like meetings and client communincations, project managment, unit testing, support for qa  and UAT testing, documentation. When you add in all the pieces that 8 hours of development time can easily turn into 22 or 23 hours.

Scope creep which you also suffered from means a new estimate. Every time without exception. When you decide to add a new feature (or are requested to) they need to know how many additional hours and how far that will push the deadline.  It is best to push the product and move scope changes to the next iteration much of the time.

Get a product out and add features rather than continually delaying to add more cool stuff. And make sure the scope creep doesn't come from the developers. Scope changes should come from the clients or stakeholders in the organization not from the devlopers. There really is no excuse for that. If you think of something you want to add, then add it to the next version after vetting the idea with the stakeholders instead of delaying the current version unless something is actually so broken it won't work without the new thing. Shipping the product is a critical skill to have. Every piece of software ever written can have some additional shiny new things added to them before realease. Resist the temptation and plan for your new features in future releases.

Title: Planning milestones and time