答:
The code in the question (a linear search), as you rightly point out, is going to get slow for large float arrays. Technically it's O(n) where n is the number of float values in your array.

In general, the best that you can do to find a value in an ordered array is a recursive tree search  of some kind (e.g. binary search), in which case you can achieve an O(log n) lookup time in the number of elements in your array. O(log n) is much better than O(n) for large values of n.

My suggested approach would therefore be a simple binary search of the array, i.e.:

Set min/max integer indexes to cover your whole float array

test the value in the middle of the range at index mid=(min+max/2) against the search value x

if x is lower than this value, set max to mid, else set min to mid

repeat (2-4) until you have found the correct value

This is an O(log n) algorithm which should be fast enough for nearly all situations. Intuitively, it works by halving the range to be searched at each step until you find the correct value.

It's really hard to beast the simple binary search, so if you have already implemented this correctly then you may be pretty close to optimal already. However, if you know the distributions of the data and/or have a limited range of lookup values (x), there are still some other more advanced tricks you can try:

Bucketing - create buckets (e.g. for each interval between two integers), each of which contains a smaller sorted list of the float values between the two bounding integers plus two values immediately below and immediately above each range. You can then start your search at (trunc(x)+0.5). This should give you a good speedup if you choose appropriately sized buckets (it's effectively increasing the branching factor of the tree.....). If integers don't work for you, then you can try buckets of some other fixed-point precision (e.g. multiples of 1/16).

Bit-mapping - if the range of possible lookup values is small enough, you could try creating a big lookup table indexed by the bitwise value of x. This will be O(1) but you may need a lot of memory which will be very unfriendly on your cache... so use with caution. This is especially nasty because you are looking up float values, so you may well need several GBs to account for all of the less significant bits......

Rounding and hashing - hash tables are probably not the best data structure for this problem, but if you can survive losing a bit of accuracy they could work - simply round off the lowest bits of your lookup values and use a hashmap to directly look up the correct value. You will have to experiment on the right trade-off between hashmap size and precision, and also ensure that all possible hash values are populated so this can be a bit tricky......

Tree-balancing - your ideal tree should have a 50% chance of going left or right. So if you create a tree based on the distribution of lookup values (x), then you can optimise the tree to produce answers with the minimal amount of tests. This is likely to be a good solution if a lot of values in your float array are very close together, since it will enable you to avoid searching these branches too often.

Crit-bit trees - these are still trees (so still O(log n)...) but some cases: you would however need to convert your floats into some fixed-point format in order to make the comparisons work

However, unless you are in a very special situation I'd probably recommend sticking with the simple binary search. Reasons:

it's much easier to implement

it's very fast for most common cases

the extra overhead of the more complex approaches (e.g. higher memory usage / cache pressure) often outweighs the minor theoretical gains

it will be more robust to future changes in the data distributions....

Title: Fast algorithm to search a sorted array of floats to find the pair of floats bracketing an input value

Body:
I have an array of floats, sorted from smallest to largest, and need to be able to pick out the nearest float greater than or less than a passed input value.  This input value is not necessarily present as a value in the array.

A naive approach would be to do a simple linear search through the array.  That might look like this:

```<code>void FindClosestFloatsInArray( float input, std::vector<float> array,
                               float *min_out, float *max_out )
{
    assert( input >= array[0] && input < array[ array.size()-1 ] );
    for( int i = 1; i < array.size(); i++ )
    {
        if ( array[i] >= input )
        {
            *min = array[i-1];
            *max = array[i];
        }
    }
}
</code>```

But obviously as the array gets larger, this will become slower and slower.

Does anyone have an idea about an algorithm that would let me find this data more optimally?  I've already switched to a binary search, which has improved matters somewhat, but it's still a lot slower than I'd like, and since I'm not actually looking for a specific value that exists in the array, it can never terminate early.

More information:  The floating point values in the array are not necessarily distributed evenly (that is, the array could consist of the values "1.f, 2.f, 3.f, 4.f, 100.f, 1200.f, 1203.f, 1400.f".

I'm doing this operation hundreds of thousands of times, but I can do any amount of pre-processing on the array of floats, if it'll improve the lookup time.  I absolutely can change to use something other than a vector to store them, if that'll help.


问:
Difference between networking programming and socket programming
Are there any major differences when we talk about "socket programming" compared to "network programming"?

Are there some topics that cover "network programming" but not "socket programming"?

答: "network programming" will require some networking technology - for example, RPC. Sockets (most likely you mean BSD sockets) are an example of such technology. So "socket programming" is a subset of "network programming".</p>

ContentLicense: CC BY-SA 3.0


问:
Is microoptimization worth it in mobile devices?
Usually microoptimization is considered not worth it with the following explanation: it might speed up the program by less that one percent, but noone cares of that minor boost - that's just too little of a change to be noticed.

Furthermore, there might be some event handler that fires one thousand times per second and exits very fast - before it is fired again. Noone cares how fast it is - making it faster can't be noted, because it already "as fast as can be observed".

However in mobile devices energy consumption is an important factor. The same event handler optimized to run ten percent faster will lead to less energy consumed and that's longer battery life and a longer operating device.

How accurate is the latter judgement about mobile devices? Are there any real life examples that confirm or disprove it?

答:
It's worth it if measurements say it's worth it. For mobile device as well as supercomputers.

EDIT: Little off topic, but about your example. If the event is triggered too many times, then you have a conception problem, and solving that conception problem is the real deal. Not make it less visible by microoptimizing.

You can perform a test in the callback for example, to discard too frequents calls, or rework the way callback is called.

In general, it is bad practice to attach callback to « continuous events ». By that, I mean events that don't trigger once and then done, but that trigger on action that last over time.

Scrolling a page or a slider, for example, are continuous events.

You never know how many times those events will be triggered. If they are triggered fast enough, your application become laggy, and if they are triggered too many times, you'll end up with huge CPU load for nothing, potentially making your application laggy too.

ContentLicense: CC BY-SA 4.0


问:
Why do programmers use one-based indexing for line numbers in source code?

Possible Duplicate:

  Why isn't the line count in Visual Studio zero-based?

Why isn't the top line in a source code file labelled line number 0?

i.e. in a source file which was 10 lines long, I would expect line numbers would be 0-9, but they're not!  Now grep, awk, sed etc all seem to number from 1, so I'm assuming it's an established convention for a good reason.

It occurred to me recently that, for almost every other structure a programmer has to deal with in their day to day work, the convention is to count from 0 - and a source file is as much like a list of lines as a line is like a list of chars (afaik list of chars is invariably 0-indexed). I had to actually open up my text editor and sanity check that the top line of a file was labelled line number 1!

I was just wondering if there is a good reason for this or if it's just an unfortunate historical convention.

答:
The "natural" thing to do is 1-based counting, like we do with line numbers. Most real-life entities that we number serially start at 1 - bus lines, pop chart positions, highways, flights, - none of these ever have number 0.

0-based is the exception, not the rule, but there are a few very good technical reasons why we use them, the most important being that it makes pointer arithmetic work naturally, especially in low-level languages like C (a[3] means 'take the address a and step 3 cells forward', i.e., *(a + 3)).


问:
When is a version control commit too large?
I've heard in several places "Don't make large commits" but I've never actually understood whats a "large" commit. Is it large if you work on a bunch of files even if there related? How many parts of a project should you be working on at once?

To me, I have trouble trying to make "small commits" since I forget or create something that creates something else that creates something else. You then end up with stuff like this:

```
Made custom outgoing queue

Bot
-New field msgQueue which is nothing more than a SingleThreadExecutor
-sendMsg blocks until message is sent, and adds wait between when messages get
sent
-adminExist calls updated (see controller)
-Removed calles to sendMessage

Controller
-New field msgWait denotes time to wait between messages
-Starting of service plugins moved to reloadPlugins
-adminExists moved from Server because of Global admins. Checks at the channel,
server, and global level

Admin
-New methods getServer and getChannel that get the appropiate object Admin
belongs to

BotEvent
-toString() also show's extra and extra1

Channel
-channel field renamed to name
-Fixed typo in channel(int)

Server
-Moved adminExists to Controller

PluginExecutor
-Minor testing added, will be removed later

JS Plugins
-Updated to framework changes
-Replaced InstanceTracker.getController() with Controller.instance
-VLC talk now in own file

Various NB project updates and changes

---

Affected files
Modify  /trunk/Quackbot-Core/dist/Quackbot-Core.jar
Modify  /trunk/Quackbot-Core/dist/README.TXT
Modify  /trunk/Quackbot-Core/nbproject/private/private.properties
Modify  /trunk/Quackbot-Core/nbproject/private/private.xml
Modify  /trunk/Quackbot-Core/src/Quackbot/Bot.java
Modify  /trunk/Quackbot-Core/src/Quackbot/Controller.java
Modify  /trunk/Quackbot-Core/src/Quackbot/PluginExecutor.java
Modify  /trunk/Quackbot-Core/src/Quackbot/info/Admin.java
Modify  /trunk/Quackbot-Core/src/Quackbot/info/BotEvent.java
Modify  /trunk/Quackbot-Core/src/Quackbot/info/Channel.java
Modify  /trunk/Quackbot-Core/src/Quackbot/info/Server.java
Modify  /trunk/Quackbot-GUI/dist/Quackbot-GUI.jar
Modify  /trunk/Quackbot-GUI/dist/README.TXT
Modify  /trunk/Quackbot-GUI/dist/lib/Quackbot-Core.jar
Modify  /trunk/Quackbot-GUI/nbproject/private/private.properties
Modify  /trunk/Quackbot-GUI/nbproject/private/private.xml
Modify  /trunk/Quackbot-GUI/src/Quackbot/GUI.java
Modify  /trunk/Quackbot-GUI/src/Quackbot/log/ControlAppender.java
Delete  /trunk/Quackbot-GUI/src/Quackbot/log/WriteOutput.java
Modify  /trunk/Quackbot-Impl/dist/Quackbot-Impl.jar
Modify  /trunk/Quackbot-Impl/dist/README.TXT
Modify  /trunk/Quackbot-Impl/dist/lib/Quackbot-Core.jar
Modify  /trunk/Quackbot-Impl/dist/lib/Quackbot-GUI.jar
Modify  /trunk/Quackbot-Impl/dist/lib/Quackbot-Plugins.jar
Modify  /trunk/Quackbot-Impl/lib/javarebel.stats
Add /trunk/Quackbot-Impl/lib/jrebel.info
Modify  /trunk/Quackbot-Impl/nbproject/private/private.properties
Modify  /trunk/Quackbot-Impl/nbproject/private/private.xml
Modify  /trunk/Quackbot-Impl/nbproject/project.properties
Modify  /trunk/Quackbot-Impl/plugins/CMDs/Admin/reload.js
Add /trunk/Quackbot-Impl/plugins/CMDs/Operator/hostBan
Modify  /trunk/Quackbot-Impl/plugins/CMDs/Operator/mute.js
Modify  /trunk/Quackbot-Impl/plugins/CMDs/lyokofreak/curPlaying.js
Modify  /trunk/Quackbot-Impl/plugins/CMDs/lyokofreak/lfautomode.js
Modify  /trunk/Quackbot-Impl/plugins/listeners/onJoin.js
Modify  /trunk/Quackbot-Impl/plugins/listeners/onQuit.js
Modify  /trunk/Quackbot-Impl/plugins/testCase.js
Add /trunk/Quackbot-Impl/plugins/utils/whatsPlaying.js
Modify  /trunk/Quackbot-Impl/src/Quackbot/impl/SandBox.java
Add /trunk/Quackbot-Impl/vlc_http
Add /trunk/Quackbot-Impl/vlc_http/current.html
Modify  /trunk/Quackbot-Plugins/dist/Quackbot-Plugins.jar
Modify  /trunk/Quackbot-Plugins/dist/README.TXT
Modify  /trunk/Quackbot-Plugins/dist/lib/Quackbot-Core.jar
Modify  /trunk/Quackbot-Plugins/nbproject/private/private.properties
Modify  /trunk/Quackbot-Plugins/nbproject/private/private.xml
Modify  /trunk/Quackbot-Plugins/src/Quackbot/plugins/JSPlugin.java
Add /trunk/Quackbot-Plugins/vlc_http
Add /trunk/global-lib/jrebel.jar
```

Yea....

So for questions:

What are some factors for when a commit becomes too large (non-obvious stuff)?

How can you prevent such commits? Please give specifics

What about when your in semi-early stages of development when things are moving quickly? Are huge commits still okay?

答:
Sometimes you've been working all day on several different logically distinct chagnes, and you forgot to commit your code in between. Using git citool can be very helpful for breaking up your work into nice bite-sized chunks at the end of the day, even if you weren't so careful during the day while you were working.

git citool can let you select which specific hunks of a file (or which specific lines) to commit in a particular commit, so you can break up (non-overlapping) changes made to the same file into several commits.

(It seems that you use Subversion. I don't know of a tool that does this for Subversion, but you could look into using git-svn, the Subversion adapter for git, which will change your life.)

ContentLicense: CC BY-SA 2.5


问:
Fast algorithm to search a sorted array of floats to find the pair of floats bracketing an input value
I have an array of floats, sorted from smallest to largest, and need to be able to pick out the nearest float greater than or less than a passed input value.  This input value is not necessarily present as a value in the array.

A naive approach would be to do a simple linear search through the array.  That might look like this:

```<code>void FindClosestFloatsInArray( float input, std::vector<float> array,
                               float *min_out, float *max_out )
{
    assert( input >= array[0] && input < array[ array.size()-1 ] );
    for( int i = 1; i < array.size(); i++ )
    {
        if ( array[i] >= input )
        {
            *min = array[i-1];
            *max = array[i];
        }
    }
}
</code>```

But obviously as the array gets larger, this will become slower and slower.

Does anyone have an idea about an algorithm that would let me find this data more optimally?  I've already switched to a binary search, which has improved matters somewhat, but it's still a lot slower than I'd like, and since I'm not actually looking for a specific value that exists in the array, it can never terminate early.

More information:  The floating point values in the array are not necessarily distributed evenly (that is, the array could consist of the values "1.f, 2.f, 3.f, 4.f, 100.f, 1200.f, 1203.f, 1400.f".

I'm doing this operation hundreds of thousands of times, but I can do any amount of pre-processing on the array of floats, if it'll improve the lookup time.  I absolutely can change to use something other than a vector to store them, if that'll help.

答:
This seems simple enough:

Do a binary search for the float that you want to bound - O (log n) time.

Then the element to the left of it is the lower bound, and the element to the right of it is the upper bound.


问:
Should I include a selfdestruct-method to my applications?
I recently had a negative experience, where client bailed from the bill, but my middle-man already uploaded our software and design to the clients server. Client turned out be a known criminal, and of course he changed all possible passwords of the server.

However, I can still access the admin-panel of the CMS. Sadly it turns out, that my software is very secure.. Tried to SQL-injection, fake the image-upload etc etc. However, I cannot hack my own software.. Anyways, I preparing to sue this person, so that is not the problem.. I'm just thinking now, that maybe there should be some backend selfdestruct-method. So, if similar case occur, I have the option to kill the software.

My own idea is to hide some function in the core files. Encode it with base64, so it wouldn't be obvious. So something like this:

```<code>eval(base64_decode('ZWNobyAnSGVsbG8gd29ybGQhJzs=')); // echo 'Hello world!';
</code>```

And basically make a small script, that takes all the software's files, chmod's them to be sure and then deletes them.

My newer versions of the CMS, all have filemanagers that I could use for easier hacking. But what if the access to the admin-panel is limited.

To be very clear, this is meant only for the development-stage software's, in my personal server or the clients server (last part being the ethically questionable.) So if my client should steal my software.. This wont be included inside a commercial-software.

And to be even more clear, we are talking about those rare freelance jobs. I think its fairly logical, that contract-work doesn't need such methods. So we are talking about those jumprisk-clients, only in development mode -- when the project is ready, then obviously this would be a very very unethical backdoor to have inside your software.

Ethically is this a good idea? (Keeping in mind, that obviously I will remove it, when project has been 100% and everything is paid for)

Have you guys ever had to hack your own software, because of similar issues with the client(s)?

Any recommendations on this idea, code and method wise?

What may be the possible drawbacks or repercussions of selfdestruct-scripts?

My conclusion on this

Is a little bit sad, that all answers were targeted on the contracted cases. It was my fault really, that I didn't make it more clear in my question.. just thought, that it is fairly clear, that there is no point in the kill-switch.. when you are protected by the contract.

However, if you are doing a contract work.. then this should be stated in the contract -- this makes it legal, even inside the clients own server. However, having kill-switches inside my own personal server is really nobodies business (this is what I really wanted to know.)

I decided to make the kill-switch script for my CMS. Mainly, because it seems an interesting challenge. But also, that I could use this for my non-contracted works where the client is a friend of a friend of a friend.. I probably wont use this on the clients server, but..for the cases, where the client or some middlemen have access to my server .. And my software gets stolen, or "moved without my knowledge", then I don't get paid and they cut the access to the software.

I have read trough alot of topics here, where they recommend to send a warning and then take down the page. Well, I saw a problem in it, as when Im dealing with a person.. who will just copy it to somewhere else (maybe re-brand it and sell it) and tells me, that it has been taken down. And also, I wouldn't "turn the site off", but delete it. Though, I guess its still illegal to access my clients server and to delete it. Or at-least, access it trough backend and not from the FTP. For this I thank all of you, who answered.

答:
Just implement a licensing module with time limited licenses that will disable the software on expiry. This is a well known practice in software industry and your clients should not object to it, as you will remove the limitation afterwards.

This might also come in handy, when you want to limit features and offer different versions of your product.

Kill switches just have way too many risks and are not worth it.


问:
What is the standard /an acceptable period of time to support a particular version of software?
Let's say version 2.4.x of Software Package X was released 2 years ago, and was sold up until about 6 months ago. Version 3.1.0 is now out (which fixes a lot of the issues with version 2.4.x), and is the only version actively being sold.

In this case, the software is being sold to large businesses, not individuals, so the maintenance effort required is substantial.

For how long should the company offer support for version 2.4.x?

答:
Depends on the software.
Best if you maintain full backwards compatibility and all support involves mandatory upgrade. Unless your business model depends on selling new versions every few years.

It requires a precarious balance: make the support period too short and people will leave in favor of better supported competition. Make it very long and the costs will gobble you up.

The usual approach of "keep the previous version supported until new one is released (plus some)" is okay if the release cycle isn't too fast - like, one new version a year, or longer. So, if you release 4.x, you keep support of 2.x for another couple of months to encourage migration, and keep supporting 3.x until a few months past release of 5.x. But if you release a new version every 6 months, you should keep the support longer.

Still, specifics of the job may require much longer support period. Say, it's industrial embedded - software running machinery worth many millions of dollars. So something breaks, and you just can't say "this is not supported any longer" three years after deploying. OTOH, maintaining free warranty support, while nice, is not mandatory. Additional option against disgruntled customers who don't want, or can't upgrade, is paid support - valued at the cost of keeping it up plus a profit.


答:
Usually large businesses pay for maintenance contracts.

You then support old versions as long as customer pays. It is up to you to balance maintenance cost vs. new version costs so that customers switch. You can also offer a support for upgrading.

Title: What is the standard /an acceptable period of time to support a particular version of software?

Body:
Let's say version 2.4.x of Software Package X was released 2 years ago, and was sold up until about 6 months ago. Version 3.1.0 is now out (which fixes a lot of the issues with version 2.4.x), and is the only version actively being sold.

In this case, the software is being sold to large businesses, not individuals, so the maintenance effort required is substantial.

For how long should the company offer support for version 2.4.x?


问:
Would scala be a good choice instead of Java?
We will be starting a new project which will involve training all the .net developers in Java (frameworks/ECO system etc). We have a lot of code written in C# and it seems that all of this will be wasted as we have to re-write it all in Java. The problem I see is that the first year or so (probably 2 years) we will have nothing to deliver as we will spend most of the time reproducing what we had before but now in Java.

Since our team is distributed in different offices around the world and we have a large number of java developers (20 to 30) and 10 developers using .net, we want to get all the developers using the same language/platform so we can start to reuse components/modules. So I can understand managements point of view.

Yesterday I came across Scala and was wondering if it would be better to use this with the current product (which is written in C#) and then at least we will have a working product in a year. Also in a year we have modules that can be used in the Java world whilst we migrate other parts of the product.

Would Scala be a better choice than Java considering what we are trying to achieve?

答: I think the easier option would be to get the java developers to learn C#. Both the languages are very similar in many ways and it doesn't take a long time for a java developer to pick up C#. I have worked with many java developers who learnt C# and it's usually a smooth transition. The one area where they might get stuck for a while is the WebForms programming model. Java developers adjust better to the MVC paradigm. This way, you need not wait for an year before you begin to develop new features. As regards Scala, I'm afraid that will introduce a whole new problem with all 30 developers trying to learn a new language.</p>


答:
Rewriting C# to Scala will be just as hard as rewriting to Java. As for which language is "better", that point is moot, each language has its own plus and minus points.

I dont know how big your codebase is but 2 years for 30 developers seems huge for a simple rewrite. Picking up Java when you know C# is easy. It took me a day or two to get comfortable with it.

My advice would be to let managment get their way and enjoy the fact your getting paid to expand your skillset.

Title: Would scala be a good choice instead of Java?

Body:
We will be starting a new project which will involve training all the .net developers in Java (frameworks/ECO system etc). We have a lot of code written in C# and it seems that all of this will be wasted as we have to re-write it all in Java. The problem I see is that the first year or so (probably 2 years) we will have nothing to deliver as we will spend most of the time reproducing what we had before but now in Java.

Since our team is distributed in different offices around the world and we have a large number of java developers (20 to 30) and 10 developers using .net, we want to get all the developers using the same language/platform so we can start to reuse components/modules. So I can understand managements point of view.

Yesterday I came across Scala and was wondering if it would be better to use this with the current product (which is written in C#) and then at least we will have a working product in a year. Also in a year we have modules that can be used in the Java world whilst we migrate other parts of the product.

Would Scala be a better choice than Java considering what we are trying to achieve?


答:
if you are developing a web app, none : )
anyways, as long as some users still use that version, you have to support the software, that is because of software engineering ethics. If you dont want to support the old release anymore, you have to help them migrate to new release and voila!! problem solved..</p>


答: At the very least, train yourself to commit whenever you think to yourself "I like my progress so far, and I don't want to lose it if the changes I'm about to make are a disaster." Then you have the option to take advantage of the VCS to blow away any dead ends that you tried or special debugging code you added to track down a problem. (e.g. with git reset --hard or rm -rf *; svn update)

Title: When is a version control commit too large?

Body:
I've heard in several places "Don't make large commits" but I've never actually understood whats a "large" commit. Is it large if you work on a bunch of files even if there related? How many parts of a project should you be working on at once?

To me, I have trouble trying to make "small commits" since I forget or create something that creates something else that creates something else. You then end up with stuff like this:

```
Made custom outgoing queue

Bot
-New field msgQueue which is nothing more than a SingleThreadExecutor
-sendMsg blocks until message is sent, and adds wait between when messages get
sent
-adminExist calls updated (see controller)
-Removed calles to sendMessage

Controller
-New field msgWait denotes time to wait between messages
-Starting of service plugins moved to reloadPlugins
-adminExists moved from Server because of Global admins. Checks at the channel,
server, and global level

Admin
-New methods getServer and getChannel that get the appropiate object Admin
belongs to

BotEvent
-toString() also show's extra and extra1

Channel
-channel field renamed to name
-Fixed typo in channel(int)

Server
-Moved adminExists to Controller

PluginExecutor
-Minor testing added, will be removed later

JS Plugins
-Updated to framework changes
-Replaced InstanceTracker.getController() with Controller.instance
-VLC talk now in own file

Various NB project updates and changes

---

Affected files
Modify  /trunk/Quackbot-Core/dist/Quackbot-Core.jar
Modify  /trunk/Quackbot-Core/dist/README.TXT
Modify  /trunk/Quackbot-Core/nbproject/private/private.properties
Modify  /trunk/Quackbot-Core/nbproject/private/private.xml
Modify  /trunk/Quackbot-Core/src/Quackbot/Bot.java
Modify  /trunk/Quackbot-Core/src/Quackbot/Controller.java
Modify  /trunk/Quackbot-Core/src/Quackbot/PluginExecutor.java
Modify  /trunk/Quackbot-Core/src/Quackbot/info/Admin.java
Modify  /trunk/Quackbot-Core/src/Quackbot/info/BotEvent.java
Modify  /trunk/Quackbot-Core/src/Quackbot/info/Channel.java
Modify  /trunk/Quackbot-Core/src/Quackbot/info/Server.java
Modify  /trunk/Quackbot-GUI/dist/Quackbot-GUI.jar
Modify  /trunk/Quackbot-GUI/dist/README.TXT
Modify  /trunk/Quackbot-GUI/dist/lib/Quackbot-Core.jar
Modify  /trunk/Quackbot-GUI/nbproject/private/private.properties
Modify  /trunk/Quackbot-GUI/nbproject/private/private.xml
Modify  /trunk/Quackbot-GUI/src/Quackbot/GUI.java
Modify  /trunk/Quackbot-GUI/src/Quackbot/log/ControlAppender.java
Delete  /trunk/Quackbot-GUI/src/Quackbot/log/WriteOutput.java
Modify  /trunk/Quackbot-Impl/dist/Quackbot-Impl.jar
Modify  /trunk/Quackbot-Impl/dist/README.TXT
Modify  /trunk/Quackbot-Impl/dist/lib/Quackbot-Core.jar
Modify  /trunk/Quackbot-Impl/dist/lib/Quackbot-GUI.jar
Modify  /trunk/Quackbot-Impl/dist/lib/Quackbot-Plugins.jar
Modify  /trunk/Quackbot-Impl/lib/javarebel.stats
Add /trunk/Quackbot-Impl/lib/jrebel.info
Modify  /trunk/Quackbot-Impl/nbproject/private/private.properties
Modify  /trunk/Quackbot-Impl/nbproject/private/private.xml
Modify  /trunk/Quackbot-Impl/nbproject/project.properties
Modify  /trunk/Quackbot-Impl/plugins/CMDs/Admin/reload.js
Add /trunk/Quackbot-Impl/plugins/CMDs/Operator/hostBan
Modify  /trunk/Quackbot-Impl/plugins/CMDs/Operator/mute.js
Modify  /trunk/Quackbot-Impl/plugins/CMDs/lyokofreak/curPlaying.js
Modify  /trunk/Quackbot-Impl/plugins/CMDs/lyokofreak/lfautomode.js
Modify  /trunk/Quackbot-Impl/plugins/listeners/onJoin.js
Modify  /trunk/Quackbot-Impl/plugins/listeners/onQuit.js
Modify  /trunk/Quackbot-Impl/plugins/testCase.js
Add /trunk/Quackbot-Impl/plugins/utils/whatsPlaying.js
Modify  /trunk/Quackbot-Impl/src/Quackbot/impl/SandBox.java
Add /trunk/Quackbot-Impl/vlc_http
Add /trunk/Quackbot-Impl/vlc_http/current.html
Modify  /trunk/Quackbot-Plugins/dist/Quackbot-Plugins.jar
Modify  /trunk/Quackbot-Plugins/dist/README.TXT
Modify  /trunk/Quackbot-Plugins/dist/lib/Quackbot-Core.jar
Modify  /trunk/Quackbot-Plugins/nbproject/private/private.properties
Modify  /trunk/Quackbot-Plugins/nbproject/private/private.xml
Modify  /trunk/Quackbot-Plugins/src/Quackbot/plugins/JSPlugin.java
Add /trunk/Quackbot-Plugins/vlc_http
Add /trunk/global-lib/jrebel.jar
```

Yea....

So for questions:

What are some factors for when a commit becomes too large (non-obvious stuff)?

How can you prevent such commits? Please give specifics

What about when your in semi-early stages of development when things are moving quickly? Are huge commits still okay?


问:
Is this the right strategy to convert an in-level order binary tree to a doubly linked list?
So I recently came across this question - Make a function that converts a in-level-order binary tree into a doubly linked list. Apparently, it's a common interview question.

This is the strategy I had - Simply do a pre-order traversal of the tree, and instead of returning a node, return a list of nodes, in the order in which you traverse them. i.e return a list, and append the current node to the list at each point. For the base case, return the node itself when you are at a leaf.

so you would say

```<code>left = recursive_function(node.left)
right = recursive_function(node.right)
return(left.append(node.data)).append(right);`
</code>```

Is this the right approach?

答:
Turns out it is:

EDIT: Simplified base case

I implemented the code in Java, it looks like this:

```<code>public DLLNode treeToList(TreeNode node, DLLNode list)
{
    if (node.isLeaf())
      return new DLLNode(node.data);

    DLLNode left = treeToList(node.left, list);
    DLLNode right = treeToList(node.right, list);

    DLLNode ret = new DLLNode();

    ret.prev = left;
    ret.next = right;
    ret.data = node.data;

    return ret;
}
</code>```

DLLNode is simply defined with public attributes DLLNode prev, DLLNode next, int data, and TreeNode is defined with public attributes TreeNode left, TreeNode right, int data. The constructors that I defined, and the isLeaf() function are obvious.

Notes: The code does a postorder traversal, not preorder as I thought.

Body:
Turns out it is:

EDIT: Simplified base case

I implemented the code in Java, it looks like this:

public DLLNode treeToList(TreeNode node, DLLNode list)
{
    if (node.isLeaf())
      return new DLLNode(node.data);

    DLLNode left = treeToList(node.left, list);
    DLLNode right = treeToList(node.right, list);

    DLLNode ret = new DLLNode();

    ret.prev = left;
    ret.next = right;
    ret.data = node.data;

    return ret;
}

DLLNode is simply defined with public attributes DLLNode prev, DLLNode next, int data, and TreeNode is defined with public attributes TreeNode left, TreeNode right, int data. The constructors that I defined, and the isLeaf() function are obvious.

Notes: The code does a postorder traversal, not preorder as I thought.


问:
Where could SPMD parallel programming be used in a Compiler?
I have little knowledge about the subjects of compiler construction and parallel programming, so please bear with me. This is a course about compiler construction, and we are asked to learn CUDA while taking the course because the professor would like us to write a compiler for a simplified language. That compiler is supposed to be doing the work in parallel at some specific stages. My understanding was that the scanner, parser, semantic analyzer, code generator and the optimizer are inherently sequential. I have written some parsers for very simple tasks before, so my understanding is based on little bit of theory and little bit of experience. I would understand how to incorporate shared state at some point in the construction of the compiler to do multiprocessing, but not SPMD.

What components of a compiler can be parallelized(e.g. using CUDA as in my case, SPMD model in general)?

SPMD: Single Program Multiple Data

答:
...compiler is supposed to be doing the work in parallel at some specific stages.

Your professor seems to have it the other way around I am afraid. Or maybe you misunderstood him.

I would rather expect a compiler that would produce SPMD (CUDA) optimized target code generated from your simplified language. So that, say, simple addition of vectors, no matter how it is expressed in source language, gets translated into correct and high-performant set of CUDA API calls.

In that sense I would say compiler is supposed to be producing target code doing the work in parallel at some specific stages. It doesn't matter if it does that sequentially - as long as its output code exploits SPMD.


答:
Some points to consider:

Scala is a great language - but it is worth noting that is it also
quite a challenging language to learn and use correctly. Not just my opinion - even experienced Scala
experts say so. Depending on the level of skills in your team, it is probably best suited as a tool for your most experienced / expert developers

Java and C# are pretty similar in many ways - it won't take long for
developers trained in one to move across (the syntax is similar, it's
mostly just a case of learning the quirks of each and getting an
understanding of the different libraries, which often have similar
functionality but are packaged differently and/or have different
names). I've personally switched from Java to C# and back to Java
again without any difficulty.

It's also worth noting that all the JVM languages (Java and Scala,
but also JRuby and Clojure etc.) are very compatible - they share
the same fundamental JVM platform and can share code / libraries very
easily.

Given all this, you might want to hedge your bets and go for a mixed Java/Scala strategy - i.e. migrate to the JVM platform, and focus initially on Java, but keep open the option to use Scala when your developers are comfortable and/or it fits the problem at hand.

From a management perspective this has lots of advantages:

You can still share all the libraries so your investments will be safe

Your less experienced devs will be able to transfer C# -> Java pretty quicky

Your more experienced devs can take full advantage of the advanced features in Scala

All the tools are are compatible / can be shared (build systems, IDEs, deployment tools etc.)

You get free access to the very broad open source ecosystem of libraries on the JVM (alongside cross-platform portability, this is arguably the best reason to be on the JVM platform)

Your developers get to use the language that makes them most productive given their skills / the task at hand (Java in some cases, Scala in others, maybe other languages like Clojure in the future)

The downside is that you still have two primary languages to support. But you probably actually have many more than just two already (shell scripts? domain-specific XML formats? config files? rules engines? HTML? Javascript?) so you could argue that it isn't actually that much of a big deal.


答:
Socket programming (at least as the term is normally used) is programming to one specific network API. Sockets support IP-based protocols (primarily TCP and UDP)1.

Network programming can be done using various other APIs. Windows has a number of protocol-independent APIs such as the WNet* and Net* functions. Older versions of Windows also used NetBIOS/NetBEUI (NetBIOS End User Interface), and most supported (and probably still do) IPX/SPX (an old Netware protocol).

Most current network programming, however, is done either using sockets directly, or using various other layers on top of sockets (e.g., quite a lot is done over HTTP, which is normally implemented with TCP over sockets). TCP/IP and UDP/IP (as well as a number of other IP-based protocols) are done primarily via the sockets interface. In theory, other programming interfaces could be used, but in practice sockets seem to be sufficient, so there's not a lot of interest in replacing it. I should, however, mention that Windows sockets (WinSock) have quite a few extensions that are more or less unique to Windows. I suppose it's open to some argument whether code that uses these extensions really qualifies as "sockets" code or not -- they are extensions based on the same concepts, but code that uses them isn't normally portable to other systems. I guess whether it qualifies as "sockets" or no depends primarily on whether you think of sockets more as a concept, or a very specific set of functions, parameters, etc.

Edit (in reply to comment):

It's a bit hard to say whether "knowing sockets" implies knowing "everything" about TCP and UDP. Let's consider just one small piece of things: one typical demo program for sockets is creating a client/server chat program. The client connects to the server, and when the user on one client types something, it gets forwarded to the other clients that are connected to the same server. Each client displays what comes in from the server, and lets the user type in messages to be sent to the other clients.

At the same time, consider what a "real" chat program like AIM, Windows Messenger, iChat, etc. involves. To handle not only text, but voice, video, file transfers, groups, lists, etc., a typical program probably involves a dozen different standards, including such things as SIP, STUN, TURN, RTCP, RTP, XAMPP, mDNS, etc.

IMO, somebody who "knows sockets" should be able to code up the first (demo-level, text-only) chat program in a few hours without spending much time in help files (and such) doing research. Unless they claimed at least some prior experience working on a "real" chat program, I wouldn't expect them to even know which RFCs/standards applied to such things though.

The same applies in general: given the number of RFCs (and various other standards) that get applied to all the different things people do over networks, it's unreasonable to expect anybody to have memorized all of them. Nonetheless, if you have a set of requirements for something that you'd expect people to be able to handle in a "local" program easily, just adding "over the network" as a requirement shouldn't normally add a tremendous amount of difficulty (though dealing with issues like network latency might).

1 Sockets on Unix also support Unix-family sockets, but these are (at least normally) used for intra-machine IPC, not networking. There are also literally dozens of other protocols for such things as router management that sockets don't really support (beyond raw sockets allowing you to build and send arbitrary packets).

Title: Difference between networking programming and socket programming

Body:
Are there any major differences when we talk about "socket programming" compared to "network programming"?

Are there some topics that cover "network programming" but not "socket programming"?


答:
I'll add a 3rd option.  Has anyone in your organisation looked at interop between your C# and Java modules?  How are you exposing the C# functionality?  Is SOAP or RESTFul web services an option?

A 2 year re-write can be a death knell for an organisation (just ask Netscape).  However a gradual migration whilst existing code plays nicely with each other has potentially less business impact.


问:
Do I need to license my code as GPLv2 if I only read/write to a database and pipe?
I'm writing an API for an open source network monitoring system which is licensed under the GPLv2. I also intend to open source this API but would like to license it under the BSD License.

I don't re-use or link to any of the code in this system and I don't use any header files.

I will not be re-distributing any part of the network monitoring code.

Part of my application will install into the network monitoring installation folders, but not replace, remove or modify any of its files

My hook into the system is via:

existing MySQL databases belonging to the service, my API reads and writes to these databases directly. My concern here would be that whilst I am not copying their SQL statements, there are some complex operations. I've found that in a couple of cases I've arrived at SQL statements or sequences of work that aren't too dissimilar to theirs, it's hard not to.

I talk to a pipe to issue various commands and submit data directly into the checking engine. This pipe is documented by the author as an official mechanism to communicate with the checking engine. The command pipe uses single line strings to issue commands, the pipe does not return any data, it's "fire and forget".

There are a number of HTTP CGI scripts in the system from which I can scrape status information. I may use these in a future release.

Is this considered "arms length" enough for me to license my code under a different license? i.e.

http://www.gnu.org/licenses/gpl-faq.html#MereAggregation

However, in many cases you can distribute the GPL-covered software
  alongside your proprietary system. To do this validly, you must make
  sure that the free and non-free programs communicate at arms length,
  that they are not combined in a way that would make them effectively a
  single program.

Would reading and writing rows to a database be considered "exchanging complex internal data structures"?

http://www.gnu.org/licenses/gpl-faq.html#MereAggregation

By contrast, pipes, sockets and command-line arguments are
  communication mechanisms normally used between two separate programs.
  So when they are used for communication, the modules normally are
  separate programs. But if the semantics of the communication are
  intimate enough, exchanging complex internal data structures, that too
  could be a basis to consider the two parts as combined into a larger
  program.

答:
You shouldn't be checking the GPL FAQ for this information. These are questions about the scope of the license, and the license cannot set its own scope. (And the FSF is not a party to the license, so they can't even waive rights the author might have.)

What matters is whether your work is a derivative work under copyright law. That is determined based on whether or not your work contains sufficient protectable expression taken from the work covered by the GPL.

First, the easy case, the database. You are not exchanging internal structures with the database. You are issuing commands to the database, and it is returning your data to you. In any event, the structure comes from the SQL standard, so I don't see how it could be protected expression from MySQL.

The pipe case is more complex. But if it's basically external structures (commands, responses), you should be okay. This is especially true if it's a documented interface. Functional elements cannot be protected by copyright, and as a general rule, if you take only what you need to interoperate, you are only taking functional elements. (But be careful with things like header files, because these contain parameter names and macros which one can argue you don't need to interoperate.)

Obviously, you should ideally consult a lawyer.


问:
Do speakers get paid for tech talks?
I'm curious if speakers (bloggers, google employees like Matt Cutts) get paid for speaking at conferences. If they do, how much? If they don't, or they get paid so little that it's as though they don't, why do it? What are the attractions beyond money that lead a developer into public speaking?</p>

答: In the world of academic conferences (like the ACM SIG* conferences), if you submit a paper in response to a call for papers, you have to pay your own way to go to the conference. (Though sometimes travel subsidies are available for students.)</p>

OwnerDisplayName: FluffyCoder

Title: Do speakers get paid for tech talks?


问:
Do LAMP/Java-based software development teams have SOE's?
As a developer on the Windows/.NET stack, it's pretty normal for the company-supplied machine to come with Windows (usually an ancient, archaic version like Windows XP) and a stack of software pre-installed as part of a Standard Operating Environment.

In companies building software on the Java/Ruby/PHP/C stack using Linux/Unix/BSD as a primary OS, in your experience:

Does everyone tend to use the same OS/version?

How do you ensure everyone is using the same version of libraries/dependencies/tools (do you?)

How do you create an SOE to pre-configure a machine (do you?)

答:
It depends on the organisation - more enlightened organisations allow developers to work in an environment that's comfortable for them (even if it means providing a VM so the developer doesn't pollute the 'base SOE').

In the Java space we worry more about managing the dependencies of the Java software itself.  That is typically standardised and various build tools and CI servers ensure that it stays that way.

I personally write my code on Windows XP SP 3, Mac OS Lion and a host of *nix systems (whatever I'm ssh'd onto at the time).


答:
The details of your question make it clear that this would be an absolutely horrible idea. The first client to discover such a kill switch (possibly after you use it and they recover from a backup) would publish the kill switch and the fact that you had included it in code you delivered to them. Your reputation would then be completely destroyed.

And before you say "well, they'd be a deadbeat, how will they destroy my reputation?" Consider a scenario like this: The customer is in good standing, but one of their employees takes a copy of the code. They fire that employee, he looks at the code, figures out the kill switch, and uses it. Guess who gets the blame? (Hint: It's you.)

Title: Should I include a selfdestruct-method to my applications?

Body:
I recently had a negative experience, where client bailed from the bill, but my middle-man already uploaded our software and design to the clients server. Client turned out be a known criminal, and of course he changed all possible passwords of the server.

However, I can still access the admin-panel of the CMS. Sadly it turns out, that my software is very secure.. Tried to SQL-injection, fake the image-upload etc etc. However, I cannot hack my own software.. Anyways, I preparing to sue this person, so that is not the problem.. I'm just thinking now, that maybe there should be some backend selfdestruct-method. So, if similar case occur, I have the option to kill the software.

My own idea is to hide some function in the core files. Encode it with base64, so it wouldn't be obvious. So something like this:

```<code>eval(base64_decode('ZWNobyAnSGVsbG8gd29ybGQhJzs=')); // echo 'Hello world!';
</code>```

And basically make a small script, that takes all the software's files, chmod's them to be sure and then deletes them.

My newer versions of the CMS, all have filemanagers that I could use for easier hacking. But what if the access to the admin-panel is limited.

To be very clear, this is meant only for the development-stage software's, in my personal server or the clients server (last part being the ethically questionable.) So if my client should steal my software.. This wont be included inside a commercial-software.

And to be even more clear, we are talking about those rare freelance jobs. I think its fairly logical, that contract-work doesn't need such methods. So we are talking about those jumprisk-clients, only in development mode -- when the project is ready, then obviously this would be a very very unethical backdoor to have inside your software.

Ethically is this a good idea? (Keeping in mind, that obviously I will remove it, when project has been 100% and everything is paid for)

Have you guys ever had to hack your own software, because of similar issues with the client(s)?

Any recommendations on this idea, code and method wise?

What may be the possible drawbacks or repercussions of selfdestruct-scripts?

My conclusion on this

Is a little bit sad, that all answers were targeted on the contracted cases. It was my fault really, that I didn't make it more clear in my question.. just thought, that it is fairly clear, that there is no point in the kill-switch.. when you are protected by the contract.

However, if you are doing a contract work.. then this should be stated in the contract -- this makes it legal, even inside the clients own server. However, having kill-switches inside my own personal server is really nobodies business (this is what I really wanted to know.)

I decided to make the kill-switch script for my CMS. Mainly, because it seems an interesting challenge. But also, that I could use this for my non-contracted works where the client is a friend of a friend of a friend.. I probably wont use this on the clients server, but..for the cases, where the client or some middlemen have access to my server .. And my software gets stolen, or "moved without my knowledge", then I don't get paid and they cut the access to the software.

I have read trough alot of topics here, where they recommend to send a warning and then take down the page. Well, I saw a problem in it, as when Im dealing with a person.. who will just copy it to somewhere else (maybe re-brand it and sell it) and tells me, that it has been taken down. And also, I wouldn't "turn the site off", but delete it. Though, I guess its still illegal to access my clients server and to delete it. Or at-least, access it trough backend and not from the FTP. For this I thank all of you, who answered.


答: This paper ("sublogarithmic searching without multiplications") might be of interest; it even contains some source code.  For the purposes of comparison, you can treat a float number as an integer with the same bit-pattern; this was one of the design goals of the IEEE floating point standard.</p>


问:
How to Properly Google for C
The problem with trying to use Google to find tutorials or answers for the C programming language is that C is not an expressive enough name to narrow down the searches. Even coupled with keywords like "Programming" and/or "Language" yields results mostly for C++, C#, and Objective-C.

Is there a way to more effectively search for specific C resources using Google?

答:
For man pages, simply type on Google form: man printf

If you want to narrow to C libraries: man 3C printf

If you are interested in system calls: man 2 select

Title: How to Properly Google for C


答:
How accurate is the latter judgement about mobile devices?

It's only as accurate as the actual measurements on the actual device that actually indicate that actual optimization will actually help.

Assumptions and judgements are worthless.

Measurements have value.

All optimization (including "microoptimization", whatever that is) is a waste of time until there is an actual measurement that indicates an actual problem where the code actually fails to meet some requirement (for speed, memory, power, or network latency or whatever).

Title: Is microoptimization worth it in mobile devices?

Body:
Usually microoptimization is considered not worth it with the following explanation: it might speed up the program by less that one percent, but noone cares of that minor boost - that's just too little of a change to be noticed.

Furthermore, there might be some event handler that fires one thousand times per second and exits very fast - before it is fired again. Noone cares how fast it is - making it faster can't be noted, because it already "as fast as can be observed".

However in mobile devices energy consumption is an important factor. The same event handler optimized to run ten percent faster will lead to less energy consumed and that's longer battery life and a longer operating device.

How accurate is the latter judgement about mobile devices? Are there any real life examples that confirm or disprove it?


问:
ASP.NET MVC: Getting User input in your Controller?
I wanted to get your opinion on best practices for getting user input while doing something in a controller.  I am inside a Action method in my controller and I am processing some data.  The data may force me to ask the user for further input, based on that input I will then do something with that data.

What is the best practice to go about this?

1) How do I issue an alert or confirm box to get user input from the Controller?  This Action is initiated by an update button on a Telerik MVC grid.

2) How do I persist my data from initially processing it, to asking the user for input, and then continue processing the data?  It's a fair amount of data.

If the initial request was started from a ajax call in a javascript function, I think I would know how to do this.  I would probably have the Action method pass back a JSON object back to the javascript method that would in turn ask the user and then decide which controller action to call and then pass this json object to it.

Am I on the right track here?  If so, my problem would be with the Telerik MVC grid.  I would need the update event of my grid to be bound client side.

Any help or thoughts on this is appreciated.

Steve

答: Why not intercept the OnSave event on the grid, client-side, and do your interaction there before allowing the client/server transaction to go forward?  I'm not deeply familiar with the Telerik stuff, but it looks as if you can expand the data model to encompass whatever additional information you might need to send to the back end (beyond what's displayed in the grid), and you can modify this information in the event handler.</p>

OwnerDisplayName: SteveB

OwnerDisplayName: Jollymorphic


问:
Are there advantages to using a DVCS for a solo developer?
Right now, I use visual svn on my server, and have ankhsvn/tortoise on my personal machine. It works fine enough, and I don't have to change, but if I can see some benefits of using a DVCS, then I might give it a go.

However, if there's no point or difference using it without other people, then I won't bother.

So again, I ask, are there any benefits to using a DVCS when you're the only developer?

答:
I use a DVCS a lot for my own personal stuff. (I'm one of those guys that at $HOME in git.) There are several advantages:

It makes replication between my laptop and desktop and lab computers really easy. Though this was true of SVN also...

I can commit on the laptop even when I don't have internet access.

Backups are as simple as a git pull.

I can use git citool to break up lots of changes into logically-sized commits, even if I've made lots of unrelated changes before deciding to commit. I'm not aware of a tool to do this in Subversion.

When I have to patch an open source project, it's easier to keep things organized by making a new git repository in the project directory than it is to make a second copy of whatever source tree I'm patching. (You can’t do this easily with Subversion because you need a separate repository somewhere else on your hard disk entirely.)

I use the easy branching features to check in revisions I get from other people. For example, when I edit a conference paper with my advisor, even though he doesn't have access to the repository, I can send him a copy of the paper, and check in his revisions in a branch based off the version that I sent him, and then use git merge to merge his revisions with anything I've done in the mean time.

Git got me used to thinking about all of my changes in logical chunks, a lot more than Subversion ever did.


答:
You can't. HTTP is stateless; once you send a request from client browser to server, there is no "hey you didn't give me enough information! ALERTBOX!". Every interaction between your Controller and the client is done via Request/Response.

In other words, what you're saying in the latter half of your post is correct. You will need to design a server/client protocol that you can interface with in Javascript. Maybe you will just return an error code, with a message that your javascript can display in a box.

If you are trying to model a multi-step process, then you will probably need several Actions in your controller.

For example, you could model your process as a Controller.

```<code>public class CreateNewAccountProcessController:Controller{
   public JsonResult Step1(Step1Data data){
      // Persist Data Here (perhaps in session, or in data store)
   }
   public JsonResult Step2(Step2Data data){
      // Persist Data Here
   }
   public JsonResult Step3(Step3Data data){
      // Persist Data Here
   }
   public JsonResult Complete(CompleteData data){
   }
   public JsonResult Cancel(CancelData data){
      // Destroy/Nullify persisted data
   }
}
</code>```

Then in your JS you could call

```<code>ajax('/createNewAccount/step1',formData);
ajax('/createNewAccount/step2',formData);
ajax('/createNewAccount/step3',formData);
ajax('/createNewAccount/complete',id);
</code>```

What you could also do is track a process with a unique identifier so you can track a process.

Title: ASP.NET MVC: Getting User input in your Controller?

Body:
I wanted to get your opinion on best practices for getting user input while doing something in a controller.  I am inside a Action method in my controller and I am processing some data.  The data may force me to ask the user for further input, based on that input I will then do something with that data.

What is the best practice to go about this?

1) How do I issue an alert or confirm box to get user input from the Controller?  This Action is initiated by an update button on a Telerik MVC grid.

2) How do I persist my data from initially processing it, to asking the user for input, and then continue processing the data?  It's a fair amount of data.

If the initial request was started from a ajax call in a javascript function, I think I would know how to do this.  I would probably have the Action method pass back a JSON object back to the javascript method that would in turn ask the user and then decide which controller action to call and then pass this json object to it.

Am I on the right track here?  If so, my problem would be with the Telerik MVC grid.  I would need the update event of my grid to be bound client side.

Any help or thoughts on this is appreciated.

Steve

Body:
You can't. HTTP is stateless; once you send a request from client browser to server, there is no "hey you didn't give me enough information! ALERTBOX!". Every interaction between your Controller and the client is done via Request/Response.

In other words, what you're saying in the latter half of your post is correct. You will need to design a server/client protocol that you can interface with in Javascript. Maybe you will just return an error code, with a message that your javascript can display in a box.

If you are trying to model a multi-step process, then you will probably need several Actions in your controller.

For example, you could model your process as a Controller.

public class CreateNewAccountProcessController:Controller{
   public JsonResult Step1(Step1Data data){
      // Persist Data Here (perhaps in session, or in data store)
   }
   public JsonResult Step2(Step2Data data){
      // Persist Data Here
   }
   public JsonResult Step3(Step3Data data){
      // Persist Data Here
   }
   public JsonResult Complete(CompleteData data){
   }
   public JsonResult Cancel(CancelData data){
      // Destroy/Nullify persisted data
   }
}

Then in your JS you could call

ajax('/createNewAccount/step1',formData);
ajax('/createNewAccount/step2',formData);
ajax('/createNewAccount/step3',formData);
ajax('/createNewAccount/complete',id);

What you could also do is track a process with a unique identifier so you can track a process.

OwnerDisplayName: Daryl Teo


问:
What does Douglas Crockford mean when he says jQuery doesn't scale?
In the Q&A section of this talk, Douglas Crockford says that jQuery doesn't scale as well as some other popular libraries. What does he mean by that, and what is it about the other libraries that makes them more scalable? </p>

答:
jQuery doesn't allow you a lot of reuse like MooTools for instance.

It's a philosophy/design decision: jQuery is not a lot of code for fire-and-forget scenarios.

When you are building unobtrusive JavaScript experiences (usually only page enhancements) this works very well and requires very little code. When you build Google Docs... not so much. You will want more OOP concepts that other projects expose like inheritance, interface-like mechanisms, etc...


问:
How would you feel if your code editor formatted your code for you as you typed, without tabs/spaces?
As with most things, I'm sure this concept has been tried before - I just haven't come across editors that use what I've termed 'Virtual Formatting'. The principle is that there's a floating left-margin that simulates the effect of the padding space/tab characters that are conventionally inserted by the developer or the editor itself to format the code. The editor continously parses code (even when commented-out) as you type and calculates the required indent based on the context where each line-feed is found

I'm developing this idea working specifically with an XML editor as XML has some peculiar problems with formatting characters and it tends to be heavily nested, however I believe many of the principles still hold for conventional code.

Have you experience coding with such a tool or do you have a view on whether it would help or hinder? Would it cause problems with version-control systems? (it detects and strips out all existing padding characters)

Unless you've tried it, the behavior of such a tool is hard to describe, it looks conventional until you actually start editing. I've put up  a screencast video showing a prototype in action which demonstrates editing XML, changing it's hierarchy and doing drag/drop and copy and paste operations, and then how formatting is broken/fixed when invalid characters are typed.

Edit
All answers/comments have so far been negative - so to attempt to redress balance, some benefits of virtual-formatting to think about:

No more debates on formatting standards, just place line-feeds where that conforms to your chosen/mandated convention

Where space is at a premium (in a book/blog/documentation) you can word-wrap but still getting perfect indentation

Each code-block can have a 'mouse-handle' immediately adjacent to where it starts, not squeezed into the screen edge - click this to select the whole block or inner-block

Drag, drop and forget - becomes viable for the first time

No time spent reformatting other peoples code

No incorrectly formatted code (in the sense that there is none - just the rendering)

Using Backspace instead of Ctrl+Backspace keeps your fingers on the keyboard guide-keys

Flexible rendering - adapt rendered formatting to your environment, anyone tried reading code on a mobile phone/small-screen tablet?

Consider that there are roughly 25% fewer editable characters (in a sample XSLT), doesn't that have efficiency benefits?

Edit - Conclusions so far

Developers have established tools and working methods that efficiently overcome most of the disadvantages inherent in the use of padding characters used for indentation.

There is concern that removal of formatting characters will detrimentally affect some differencing tools.

Developers want the flexibility to 'fine-tune' formatting in such a way that automated rendering could not handle.

The removal of leading spaces/tabs means that a 'code-aware' tool capable of code-formatting is needed to review such code efficiently - a plain-text editor would show no formatting.

Those that feel there may be some hypothetical benefits (to virtual-indentation), have a view that the disadvantages outweigh those potential benefits - conclusively.

Edit - Verdict

The perception of the obstacles and few (if any) benefits is such that it would be unwise for me, as a sole-developer, to pursue this space-free editing concept for general languages. For XML/XSLT, however (because of its special treatment of whitespace), there seems to be some agreement of potential at least.

Edit - Product Shipped

In spite of the generally negative sentiment found here, I went ahead and shipped the editor. I made a free version in the hope it would bring criticism in the form of more concrete issues, based on real experience. Somewhat frustratingly, there have been no complaints so far (in fact barely any feedback considering download volume). I'd like to think this was because users adjusted to the idea so well that they see this as a 'so what?' kind of feature - but there's no way of telling...

答:
Now that I've published the XML editor described in my question, I'm in a better (but not ideal) position to attempt to answer this myself - so I will:

After well over 500 downloads in less than 2 weeks, the reaction to this ground-breaking new concept in dynamic code formatting has been...

NIL

No complaints, no praise. My (hopeful) interpretation of this is that people just want and expect an editor that feels normal and doesn't mess up their code. Users will barely notice that their formatting is entirely virtual and evidence suggests they care even less.

It would be a mistake though to read too much into this non-reaction, this tool is free, and unfortunately this means at least some users will be less inclined to criticise. If they didn't like it, they may just have discarded it and used something else.


问:
Command handlers and DDD
I have an ASP.NET MVC application, that uses a query service to get data and a command service to send commands. My question is about the command part.

If a request comes in, the command service uses a command dispatcher that will route the command to its designated command handler. This command handler validates the comand first and if everything is acceptable, it executes the command.

Concrete example: the AddCommentToArticleCommandHandler receives an AddCommentToArticleCommand, which has an ArticleId, CommentText and EmailAddress.

First; validation has to occur, like:
- check if article exists
- check if article is not closed
- check if comment text is filled in and between 20 and 500 characters
- check if email address is filled in and has a valid format.

I'm wondering where to put this validation?

1/ in the command handler itself. But then, it cannot be reused in other command handlers.

2/ in the domain entity. But as a domain entity doesn't know about repositories or services, it cannot do the needed validation (cannot check whether an article exists). But on the other hand, if the entity doesn't contain logic, than it becomes a simple data container, which is not following DDD principles.

3/ the command handler uses validators, so that validation can be reused in other command handlers.

4/ Other mechanisms?

I'm looking for the chain of responsibilities for this particular example and what objects (entities, repositories, ...) play a role in it.

Do you have ideas on how you would implement this, starting from the command handler up to the repositories?

答:
EDIT: WaybackMachine link: http://devlicio.us/blogs/billy_mccafferty/archive/2009/02/17/a-response-to-validation-in-a-ddd-world.aspx

There's no pat answer.

There are two clear project scenarios which come to mind when I try to
answer where validation should live.  The first is wherein a DTO layer
is used to transfer information between the view and domain layers.
For example, you may have a Customer object in your domain layer and
an associated Customer DTO in another layer to which you map the
Customer information, to then give to the view for presenting Customer
information to the user.

The second scenario is a project wherein the
entities within the domain layer are shared directly with the view to
present the data to the user.  For example, instead of maintaining a
separate DTO layer and mapping domain object to the DTOs to be given
to the view, the view could be given the Customer object directly.  So
instead of talking via a separately maintained DTO to show a
Customer's name, the view would simply ask the Customer object itself
for the information.

Title: Command handlers and DDD


答:
I don't re-use or link to any of the code in this system and I don't use any header files.

If that is the case, then the GPL would consider your program to operate with the network monitoring system via "pure aggregation", which does not require your code to be placed under the GPL.

David Schwarz's answer also has a very good point in that your code would likely not be considered a derivative work under copyright law, making the network monitor's licensing terms irrelevant in any case, unless they included an (enforceable) EULA specifically stating that you may not access or use its stored data in the way that your program does.

Standard disclaimer: IANAL, just a programmer who's read way too much about this stuff for his own good. Consult a lawyer licensed to practice in your jurisdiction if you need a definitive answer.

Title: Do I need to license my code as GPLv2 if I only read/write to a database and pipe?

Body:
I'm writing an API for an open source network monitoring system which is licensed under the GPLv2. I also intend to open source this API but would like to license it under the BSD License.

I don't re-use or link to any of the code in this system and I don't use any header files.

I will not be re-distributing any part of the network monitoring code.

Part of my application will install into the network monitoring installation folders, but not replace, remove or modify any of its files

My hook into the system is via:

existing MySQL databases belonging to the service, my API reads and writes to these databases directly. My concern here would be that whilst I am not copying their SQL statements, there are some complex operations. I've found that in a couple of cases I've arrived at SQL statements or sequences of work that aren't too dissimilar to theirs, it's hard not to.

I talk to a pipe to issue various commands and submit data directly into the checking engine. This pipe is documented by the author as an official mechanism to communicate with the checking engine. The command pipe uses single line strings to issue commands, the pipe does not return any data, it's "fire and forget".

There are a number of HTTP CGI scripts in the system from which I can scrape status information. I may use these in a future release.

Is this considered "arms length" enough for me to license my code under a different license? i.e.

http://www.gnu.org/licenses/gpl-faq.html#MereAggregation

However, in many cases you can distribute the GPL-covered software
  alongside your proprietary system. To do this validly, you must make
  sure that the free and non-free programs communicate at arms length,
  that they are not combined in a way that would make them effectively a
  single program.

Would reading and writing rows to a database be considered "exchanging complex internal data structures"?

http://www.gnu.org/licenses/gpl-faq.html#MereAggregation

By contrast, pipes, sockets and command-line arguments are
  communication mechanisms normally used between two separate programs.
  So when they are used for communication, the modules normally are
  separate programs. But if the semantics of the communication are
  intimate enough, exchanging complex internal data structures, that too
  could be a basis to consider the two parts as combined into a larger
  program.


答: A possible use for SPMD acceleration can be something like more aggressive register allocation and instruction scheduling. See this article for inspiration.</p>

Title: Where could SPMD parallel programming be used in a Compiler?

Body:
I have little knowledge about the subjects of compiler construction and parallel programming, so please bear with me. This is a course about compiler construction, and we are asked to learn CUDA while taking the course because the professor would like us to write a compiler for a simplified language. That compiler is supposed to be doing the work in parallel at some specific stages. My understanding was that the scanner, parser, semantic analyzer, code generator and the optimizer are inherently sequential. I have written some parsers for very simple tasks before, so my understanding is based on little bit of theory and little bit of experience. I would understand how to incorporate shared state at some point in the construction of the compiler to do multiprocessing, but not SPMD.

What components of a compiler can be parallelized(e.g. using CUDA as in my case, SPMD model in general)?

SPMD: Single Program Multiple Data


答:
Is there a way to more effectively search for specific C resources using Google?

When looking for C stuff, I avoid a general Google search and try specific resources first:

Stack Overflow with the C tag

The comp.lang.c newsgroup (as Clement J also suggested)

C programming.com - although it's a mixed resource for C and C++, I tend to get better results nonetheless

I do this simultaneously in separate browser tabs. If I don't find anything that way, then I start trawling through Google results.

Anyone else should feel free to add to this, I don't care if it becomes community wiki :)

Title: How to Properly Google for C

Body:
The problem with trying to use Google to find tutorials or answers for the C programming language is that C is not an expressive enough name to narrow down the searches. Even coupled with keywords like "Programming" and/or "Language" yields results mostly for C++, C#, and Objective-C.

Is there a way to more effectively search for specific C resources using Google?


问:
What are the most popular IDEs per language?
This has nothing to do with having a favourite editor or anything like that. I was just wondering, per language, what are the most popular Integrated Development Environments? Maybe a top 2-3 if there is some contention. (Perceived popularity is enough)

Thus Far:

C# - Visual Studio, SharpDevelop

Java - Eclipse, NetBeans, IDEA

Objective-C - Xcode

Delphi - RAD Studio

Object Pascal - Delphi, Lazarus

C, C++ - Visual Studio, Vim

PL/SQL - RapidSQL, Oracle SQLDeveloper

PHP - Eclipse, NetBeans, Nusphere PHPed

Actionscript (AS2, AS3) - FlashDevelop

Flex - Flash Builder 4

Python - Eclipse, IDLE

Perl - Padre

Common Lisp - Lispworks, Emacs

Ruby - TextMate

Haskell - Vim

Fortran - Vim

Visual Basic - Visual Studio

答: XSLT - XmlSpy, Visual Studio

Body: XSLT - XmlSpy, Visual Studio


答: The interesting part would be the linker phase. Regular compilation is embarrasingly parallel anyway; just use one thread per Translation Unit. Merging the results isn't. This is essentially graph theory; you're resolving external references (arcs), and eliminating unused functions (disjoint subgraphs).</p>


问:
Why do programmers use one-based indexing for line numbers in source code?

Possible Duplicate:

  Why isn't the line count in Visual Studio zero-based?

Why isn't the top line in a source code file labelled line number 0?

i.e. in a source file which was 10 lines long, I would expect line numbers would be 0-9, but they're not!  Now grep, awk, sed etc all seem to number from 1, so I'm assuming it's an established convention for a good reason.

It occurred to me recently that, for almost every other structure a programmer has to deal with in their day to day work, the convention is to count from 0 - and a source file is as much like a list of lines as a line is like a list of chars (afaik list of chars is invariably 0-indexed). I had to actually open up my text editor and sanity check that the top line of a file was labelled line number 1!

I was just wondering if there is a good reason for this or if it's just an unfortunate historical convention.

答:
Punch cards started at line 1:

The tradition stuck even when we stopped using punch cards. And of course, early languages like FORTRAN, COBOL and ALGOL all used 1-based indexing.


问:
Contract Billing - How would you handle 'learning time'?
So you take a contract where you have solid experience with 75% of the technology necessary.  How do you handle your time to learn the other 25%?

Work it into the billing time?  Expose the 25% in the contract as 'research'?  Do the learning on my own time (not billed)?  Not take the contract (too large of an unknown for me and the customer)?

On the extreme end of this, I keep hearing a story about Mark Cuban (Dallas billionaire who started broadcast.com and sold it to Yahoo!) when he was at Indiana University.  Someone asked him if he could build a business app for them and he immediately said "Yes"... he had no idea how.  So he bought a book, stayed up nights, studied and coded... He finished it (I'm sure it was ugly), it worked and he kept going.

I'm not suggesting doing contracts this way (the stress!), but there's a middle ground.  What is it, and how would you (or would you?) bill for the unknown?

答:
Regarding the Mark Cuban story, I refer you to the Cult of Done Manifesto, point 4: Pretending you know what you're doing is almost the same as knowing what you are doing, so just accept that you know what you're doing even if you don't and do it.

On the main question, when I was freelancing, I took the position that anything I do for one client is taking up time I could otherwise be using to do work for other clients, so everything was billable.  Time spent learning new technologies or experimenting with new techniques was billed as "research", because that's what I was doing, and it was normally billed at the same rate as everything else (although I did make rare exceptions for small clients who wouldn't otherwise be able to afford it or for tech that I wanted a specific excuse to play with).


答:
My understanding was that the scanner, parser, semantic analyzer, code
  generator and the optimizer are inherently sequential

That's not entirely true. I've had some ideas about running parsers concurrently. Whether or not a parser is concurrent or not depends on whether the language's structure is atomic.

For a really simple example:

```<code>namespace_scope_definition := x | y | z | a | b | c;
namespace := `namespace` `{` namespace_scope_definition+ '}';
program := namespace+;
</code>```

Each namespace in this case, and each definition inside it, has it's own independent parse tree. If you were to separate them out into "atoms", you could parse each "atom" independently.

Arguably, a semantic analyzer could have the same basic idea, and possibly even an optimizer- different sections of source can be analyzed/optimized concurrently. In addition, you can lex each file of source code independently.

Body:
My understanding was that the scanner, parser, semantic analyzer, code
  generator and the optimizer are inherently sequential

That's not entirely true. I've had some ideas about running parsers concurrently. Whether or not a parser is concurrent or not depends on whether the language's structure is atomic.

For a really simple example:

namespace_scope_definition := x | y | z | a | b | c;
namespace := `namespace` `{` namespace_scope_definition+ '}';
program := namespace+;

Each namespace in this case, and each definition inside it, has it's own independent parse tree. If you were to separate them out into "atoms", you could parse each "atom" independently.

Arguably, a semantic analyzer could have the same basic idea, and possibly even an optimizer- different sections of source can be analyzed/optimized concurrently. In addition, you can lex each file of source code independently.


问:
FromXYZ vs Overloaded Method
I'm trying to think of the cleanest way to implement a couple of methods that open a file.

Consider the following method signatures:

```<code>public static DomainObject Load(Uri urlToFile)
{
    /* downloads file and calls Load(savedToFilename) */
}

public static DomainObject Load(string filename)
{
    /* creates filestream and calls Load(stream) */
}

public static DomainObject Load(Stream stream)
{
    /* does actual loading */
}
</code>```

I'm trying to implement some concepts from Clean Code, specifically:

When constructors are overloaded, use static factory methods with names that describe the arguments. For example,

Complex fulcrumPoint = Complex.FromRealNumber(23.0);

is generally better than

Complex fulcrumPoint = new Complex(23.0);

Now, I know I do not have overloaded constructors, per se (I refactored away from that), but I think the principle is the same. So that implies that my Load methods be refactored to something like:

```<code>public static DomainObject FromURI(Uri urlToFile);
public static DomainObject FromFile(string filename);
public static DomainObject FromStream(Stream stream);
</code>```

But, tbh, I think it's more intuitive to use what I've already got. From a consumer's perspective it feels like Open will take whatever source I happen to have whereas the other method requires me to think first about what my source is and then wonder if there is a specific method for that.

So I ask, from your more experienced viewpoint, which is better and why?

答:
I think "Load" is the way to go for a few reasons:

The parameter type is already in the parameter list- why specify it again in the method name?

If you happen to have multiple methods that produce something a stream in a class, "FromStream" becomes a problem.

In the age of intellisense, it's much more logical to type "Load" and get a list of possible parameter options, rather than look at three different methods (especially if more methods than just those in this set happen to start with "From").

Another decent rule of thumb is "name methods after verbs when you can," which votes in favor of something akin to "Load," or at least "LoadFrom..."

Title: FromXYZ vs Overloaded Method


问:
How do we know to favour composition over generalisation is always the right choice?
Whether an object physically exists or not, we can choose to model it in different ways. We could arbitarily use generalisation or composition in many cases. However, the GoF principle of "favour composition over generalisation [sic]" guides us to use composition. So, when we model, for example, a line then we create a class that contains two members PointA and PointB of the type Point (composition) instead of extending Point (generalisation). This is just a simplified example of how we can arbitarily choose composition or inheritance to model, despite that objects are usually much more complex.

How do we know that this is the right choice? It matters at least because there could be a ton of refactoring to do if it is wrong?

答:
Favour happens when both candidate qualifies. The problem stated in the question fails on this account, because it only has a composition option.

"Composition could use generalization as well". Does this statement make sense to us? If not then we are not yet ready to grasp the 'favour' rule.

Why we are favouring Composition is that Composition offers more extension/flexiblity possiblities than generalization. This extension/flexiblity refers mostly to runtime/dynamic flexibility(which is achieved with the combination of interfaces and composition).

The benefit is not immediately visible. To see the benefit you need to wait for the next unexpected change request. So in most cases those sticked to generalization fails when compared to those who embraced composition(except one obvious case mentioned later). Hence the rule. From a learning point of view if you can implement a dependency injection successfully then you should know which one to favour and when. The rule helps you in making a decision when you are not sure which one to choose. Again you should be able to see both options in the first place to favour one.

Summary: Composition :The coupling is reduced by just having some smaller things you plug into something bigger, and the bigger object just calls the smaller object back. Generlization: From a 3rd party API point of view defining that a method can be overridden is a stronger commitment than defining that a method can be called (sure win for Generalization). And never forget that with composition you are using generalization too, from a interface instead of a big class. But the whole credit goes to composition unfortunately.


问:
Unit testing newbie team needs to unit test
I'm working with a new team that has historically not done ANY unit testing.  My goal is for the team to eventually employ TDD (Test Driven Development) as their natural process.  But since TDD is such a radical mind shift for a non-unit testing team I thought I would just start off with writing unit tests after coding.

Has anyone been in a similar situation?  What's an effective way to get a team to be comfortable with TDD when they've not done any unit testing?  Does it make sense to do this in a couple of steps?  Or should we dive right in and face all the growing pains at once??

EDIT

Just for clarification, there is no one on the team (other than myself) who has ANY unit testing exposure/experience.  And we are planning on using the unit testing functionality built into Visual Studio.

答:
TDD is very difficult to implement and isn't always the best option for every development team. In my previous job, the team was heavily focused on TDD. Our development model was entirely TDD using the agile development approach.Testing was done through Visual Studio unit tests.

If a developer didn't write any unit tests for his/her feature they'd be in trouble with the technical lead. Furthermore if anyone check-in a broken build or any unit tests, the developer would need to fix all issues and add a $1 to the team money jar.


问:
Should I include a selfdestruct-method to my applications?
I recently had a negative experience, where client bailed from the bill, but my middle-man already uploaded our software and design to the clients server. Client turned out be a known criminal, and of course he changed all possible passwords of the server.

However, I can still access the admin-panel of the CMS. Sadly it turns out, that my software is very secure.. Tried to SQL-injection, fake the image-upload etc etc. However, I cannot hack my own software.. Anyways, I preparing to sue this person, so that is not the problem.. I'm just thinking now, that maybe there should be some backend selfdestruct-method. So, if similar case occur, I have the option to kill the software.

My own idea is to hide some function in the core files. Encode it with base64, so it wouldn't be obvious. So something like this:

```<code>eval(base64_decode('ZWNobyAnSGVsbG8gd29ybGQhJzs=')); // echo 'Hello world!';
</code>```

And basically make a small script, that takes all the software's files, chmod's them to be sure and then deletes them.

My newer versions of the CMS, all have filemanagers that I could use for easier hacking. But what if the access to the admin-panel is limited.

To be very clear, this is meant only for the development-stage software's, in my personal server or the clients server (last part being the ethically questionable.) So if my client should steal my software.. This wont be included inside a commercial-software.

And to be even more clear, we are talking about those rare freelance jobs. I think its fairly logical, that contract-work doesn't need such methods. So we are talking about those jumprisk-clients, only in development mode -- when the project is ready, then obviously this would be a very very unethical backdoor to have inside your software.

Ethically is this a good idea? (Keeping in mind, that obviously I will remove it, when project has been 100% and everything is paid for)

Have you guys ever had to hack your own software, because of similar issues with the client(s)?

Any recommendations on this idea, code and method wise?

What may be the possible drawbacks or repercussions of selfdestruct-scripts?

My conclusion on this

Is a little bit sad, that all answers were targeted on the contracted cases. It was my fault really, that I didn't make it more clear in my question.. just thought, that it is fairly clear, that there is no point in the kill-switch.. when you are protected by the contract.

However, if you are doing a contract work.. then this should be stated in the contract -- this makes it legal, even inside the clients own server. However, having kill-switches inside my own personal server is really nobodies business (this is what I really wanted to know.)

I decided to make the kill-switch script for my CMS. Mainly, because it seems an interesting challenge. But also, that I could use this for my non-contracted works where the client is a friend of a friend of a friend.. I probably wont use this on the clients server, but..for the cases, where the client or some middlemen have access to my server .. And my software gets stolen, or "moved without my knowledge", then I don't get paid and they cut the access to the software.

I have read trough alot of topics here, where they recommend to send a warning and then take down the page. Well, I saw a problem in it, as when Im dealing with a person.. who will just copy it to somewhere else (maybe re-brand it and sell it) and tells me, that it has been taken down. And also, I wouldn't "turn the site off", but delete it. Though, I guess its still illegal to access my clients server and to delete it. Or at-least, access it trough backend and not from the FTP. For this I thank all of you, who answered.

答:
I think I would devise some kind of licensing mechanism. This could be based on any number of commercial or home brewed ideas and could cause the software to stop working after the license has expired. At the point the system is accepted by the client and they have paid you can provide a full license that does not expire.

This approach also needs approval from a lawyer in your territory but has the advantage that you do not need to remote disable the software and you can stipulate that this is part of the system before hand. However it seems very sad to me that you are dealing with people who refuse to pay in the first place.


答:
Isn’t this called DRM? As long as you remove the “bomb” upon receiving payment I see no legal problem with it. Just make sure you have a patch readily available to cover your ass and show that you didn’t have malicious intent.

It reminds me of the ‘poison pill’ provision in some companies’ articles of incorporation which are activated in the event of a hostile takeover.

To wit, the mentality expressed by some of the other posters here reminds me of why some programmers get stepped on all the time. If more people put such bombs in their code I think programmers might get paid more promptly... I would have absolutely no problem if this were the norm. People love to steal other people’s hard work. Period. And if Apple, et al. can DRM the hell out of their stuff, then I think freelance programmers can too...


问:
Are ASP.NET MVC automated code good enough to be used in real live applications
I have been trying to get my hands dirty with ASP.NET MVC which looks pretty good (I am not certain, but some users say that even StackOverflow and other StackExchange websites made use of it). The tutorial I am following is from asp.net, named MVC Music Store. It's a pretty fast paced tutorial and a good one too. The question that bother's me while going through the various tutorials available on this site including the MVC Music Store is the automated code used for developing them.

Like, this tutorial makes use of Entity Framework 4, which supports a development paradigm called code-first. You add an Entity class inheriting from Entity Framework database context , add two lines of code and it will handle our create, read, update, and delete operations for us.

```<code>public class MusicStoreEntities : DbContext
{
    public DbSet<Album> Albums { get; set; }
    public DbSet<Genre> Genres { get; set; }
}
</code>```

Similarly, when I used the Scaffolding feature while adding a controller, like following :

It does a hell amount of work on its own :

It creates the new StoreManagerController with a local Entity Framework variable

It adds a StoreManager folder to the project’s Views folder

It adds Create.cshtml, Delete.cshtml, Details.cshtml, Edit.cshtml, and Index.cshtml view, strongly typed to the Album class.

As you can see, the developer's life made a hell lot easier with this automation but the question remains is whether or not this automatic code is good enough for production development ? Does anybody use(Does SO) use them. Is there any downside associated with these codes or one should be encouraged to use them ?

答:
The generated code is a starting point - it is designed to get you up and running as quickly as possible.

However, since it is generated it cannot take all possible considerations into account. It is just scaffolding.

The idea is to use this and build up on it to suit your particular needs, adding security, scalability, logging and whatever else you need.

SO does not use EF - their performance needs were not met by it. They have written (and open sourced) a light orm - Dapper, but many organizations do use EF.


问:
Is microoptimization worth it in mobile devices?
Usually microoptimization is considered not worth it with the following explanation: it might speed up the program by less that one percent, but noone cares of that minor boost - that's just too little of a change to be noticed.

Furthermore, there might be some event handler that fires one thousand times per second and exits very fast - before it is fired again. Noone cares how fast it is - making it faster can't be noted, because it already "as fast as can be observed".

However in mobile devices energy consumption is an important factor. The same event handler optimized to run ten percent faster will lead to less energy consumed and that's longer battery life and a longer operating device.

How accurate is the latter judgement about mobile devices? Are there any real life examples that confirm or disprove it?

答:
(Assuming speed is your main issue.) Everyone is right.

Except - measurement won't tell you what to optimize.

Measurement will tell you that you need to optimize.

Measurement will tell you how much you saved when you did optimize.

Measurement will not tell you what to optimize.

This technique will tell you what to optimize.


问:
How do I convince my fellow devs to WANT to add comments to source code commits?
I know that Subversion (what we're using at work) can be configured to require comments on commits, however I'm not in a position of power to simply turn this on.  I know that my reason for commenting my commits is because it is useful, if only as a memory-jogger, to quickly understand the reason behind the commit.  However, this doesn't seem to be enough to combat the two responses I always get:

It takes too long and I just want to get my changes into the repo.

It's easy enough to just look at the diffs.

I even show them the value of simply putting in a JIRA issue ID and how it automatically gets tied to the issue, but still no dice with them.

Worst of all, the person who can make the call is in the same camp: doesn't want to bother and is fine with looking at diffs.

I know it's the right thing to do, but how can I make them see the light?  Even if I can't convince my fellow devs, how can I convince management that it's the right thing to do for the business?

答:
Focus on "Why". Its all very well looking at the diffs and seeing that someone changed the logical flow of a section of code or something like that, but why did they change it? The why is usually in the associated ticket (JIRA for you).

They may wonder why the "Why" is important but in 2 years time when you have caught some bug that is a knock on effect of that change, knowing why it was done is incredibly important for not only fixing your new bug, but making sure you don't cause the old bug to re-emerge.

There is also the auditing reason. Binding commits and ticket id's make it really easy to say ok, we're pushing out Version 2, this fixes defect 23, 25, 26 and 27 but there are no commits against defect 24 so it is still outstanding.