答:
Your examples are all third-party code, but you should not write wrappers for them. They are large, mature projects with stable and well-planned APIs.

The need for wrappers is to provide a layer of abstraction between your code and the library. You only need this abstraction when you discover that a library doesn't provide good APIs for the specific thing you're doing. Then you might create the wrapper to simplify your own code, and hide the fact that the API calls are awkward.

Your code will be testable if you use dependency injection. In your unit tests you can swap out the library dependency with a mock object, allowing you to isolate your code under test.

Title: What is considered third party code?

Body:
Inspired by this question Using third-party libraries - always use a wrapper?
I wanted to know what people actually consider as third-party libraries.

Example from PHP:

If I'm building an application using Zend framework, should I treat Zend framework libraries as third party code?

Example from C#:

If I'm building a desktop application, should I treat all .Net classes as third party code?

Example from Java:

Should I treat all libraries in the JDK as third party libraries?

Some people say that if a library is stable and won't change often then one doesn't need to wrap it. However I fail to see how one would test a class that depends on a third party code without wrapping it.


问:
What is considered third party code?
Inspired by this question Using third-party libraries - always use a wrapper?
I wanted to know what people actually consider as third-party libraries.

Example from PHP:

If I'm building an application using Zend framework, should I treat Zend framework libraries as third party code?

Example from C#:

If I'm building a desktop application, should I treat all .Net classes as third party code?

Example from Java:

Should I treat all libraries in the JDK as third party libraries?

Some people say that if a library is stable and won't change often then one doesn't need to wrap it. However I fail to see how one would test a class that depends on a third party code without wrapping it.

答:
I would consider libraries provided by a specific programming language as just part of the language.

Than, I would consider third party, all the libraries provided by any other entity as an extension or a separate tool from the programming language itself.

Taking your example, I would consider Zend a third party. I would also construct my application in a way that my core business logic would not depend on Zend.

Wikipedia defines third party component as:

In computer programming, a third-party software component is a
  reusable software component developed to be either freely distributed
  or sold by an entity other than the original vendor of the development
  platform.

ContentLicense: CC BY-SA 3.0

Title: What is considered third party code?


问:
AJAX Requests & Client-Side JavaScript
I am new to AJAX and trying to understand a question I've been given:

A HTTP request is generated by a form which contains some drop-down list. When the form is submitted, a new web page is displayed with some relevant text information (which is dependent on the list item selected).
Now, the same parameters are sent to the server via an AJAX request, and the same text information is returned.

Q. What tasks would the client-side JavaScript have to do to ensure a valid request was constructed and sent?

Any useful links or quick explanations greatly appreciated.

答:
I would look at the following terms in the following order:

Web Page

Http Request

Ajax

Ajax is just a special case of a communicating Web Content. So once you feel you understand what a web page is, understand Http Request, and then go to Ajax. The Http Request part might be very technical, but it'll help you understand what javascript does when it implements ajax functionality.

Title: AJAX Requests & Client-Side JavaScript


答: It would be best to check that a valid drop-down value has been selected before sending an AJAX request to the server.  For example, drop-downs containing an option such as "Select One" will need to be validated, and the user should be notified of an invalid selection before the ajax request occurs.</p>

Title: AJAX Requests & Client-Side JavaScript

Body:
I am new to AJAX and trying to understand a question I've been given:

A HTTP request is generated by a form which contains some drop-down list. When the form is submitted, a new web page is displayed with some relevant text information (which is dependent on the list item selected).
Now, the same parameters are sent to the server via an AJAX request, and the same text information is returned.

Q. What tasks would the client-side JavaScript have to do to ensure a valid request was constructed and sent?

Any useful links or quick explanations greatly appreciated.


问:
Is it bad style to redundantly check a condition?
I often get to positions in my code where I find myself checking a specific condition over and over again.

I want to give you a small example: suppose there is a text file which contains lines starting with "a", lines starting with "b" and other lines and I actually only want to work with the first two sort of lines. My code would look something like this (using python, but read it as pseudocode):

```<code># ...
clear_lines() # removes every other line than those starting with "a" or "b"
for line in lines:
    if (line.startsWith("a")):
        # do stuff
    elif (line.startsWith("b")):
        # magic
    else:
        # this else is redundant, I already made sure there is no else-case
        # by using clear_lines()
# ...
</code>```

You can imagine I won't only check this condition here, but maybe also in other functions and so on.

Do you think of it as noise or does it add some value to my code?

答:
If you actually want to do anything if you find an invalid string (output debug text for example) then I'd say that's absolutely fine.  A couple of extra lines and a few months down the line when it stops working for some unknown reason you can look at the output to find out why.

If, however, it's safe to just ignore it, or you know for certain you will never get an invalid string then there's no need for the extra branch.

Personally I'm always for putting in at least a trace output for any unexpected condition - it  makes life much easier when you have a bug with output attached telling you exactly what went wrong.


答:
In the strictest sense, every example you gave is third party code. However, not all third party code should be wrapped. All third party libraries should be wrapped. Frameworks, by definition, cannot be wrapped because they become part and parcel of your code. That is why you would wrap your logging library, but not the .NET framework or the Zend framework. You cannot really separate your code from .NET--they are intertwined. Of course, good frameworks will have interfaces to program against, allowing you to bypass the problem to some degree.

See also: https://stackoverflow.com/questions/148747/what-is-the-difference-between-a-framework-and-a-library

Title: What is considered third party code?


问:
Pure Java web browser, is it practical?
I know that a Java web browser is possible, but is it practical? I've seen the Lobo project and must admit I am impressed, but from what I've gathered it seems that development stopped in 2009. Would a browser coded in pure Java (no WebKit java bindings of any type) be able to compete with those among the ranks of Chrome or Firefox, or would it be inherently slower, hindering the user?</p>

答:
I honestly believe that a dedicated, knowledgeable team could create a performant web browser in Java. The real question is, why? Having the browser written in a specific language is not really a feature. People will use Chrome because it is fast or Firefox because it is extensible, but they will not use JBrowser just because it happens to be written in Java. So the real question becomes, what problem are you trying to solve?

The next question, assuming you have a reason to write JBrowser is, "does using Java make the task easier or harder?" Google, when making Chrome, wrote it primarily in C/C++ despite the fact that they are a very pro-Java shop. It seems quite likely that they believed that the benefits of Java were not going to bring in a net gain on time.

Title: Pure Java web browser, is it practical?


问:
Does studying other people's programs help in self growth?
Should I be studying big softwares written by other people in our company? My work may be a small sub module on the top of that software, and I may not be required to know what goes beneath the hood,

but

Does understanding other people's code grow my knowledge about programming methods or anything else?

答:
Nice question, Each programmer/developer can write code in their own ways and learned ways. Learning/analyzing other's code is one of the reason to become a better developer. In others code

somebody follows coding standard

somebody follows junk code

somebody follows short codes like in framework

somebody follows all of the above

Learners types:

Listening learners

Seeing learners

Touch / experience learners


答:
The goal of wrapping up a library is to break your own code's dependency on that library in order to enable:

Unit testing - You must be able to test your code. If a library does not allow you to mock the classes or force responses that you need for your test, then you'll need to wrap that library. This is an obvious problem, and probably not the case you are wondering about.

Changing implementations - As the code author you need to understand changes that are likely coming your way, and how much those changes will cost to prepare for compared to how likely they are. Can you switch from .NET to JVM? That's difficult and unlikely; however, you are very likely to change UI technologies in the future, or XML engines.

Isolating third party libraries and frameworks is just a subset of isolating change.

Title: What is considered third party code?


问:
Forbidding or controlling "Hidden IT..." Who should write and maintain ad-hoc software applications?
Bigger companies usually have the problem, that it is not possible to write all programs employees want (to save time and to optimize processes) due to a lack of staff and money.

Then hidden programs will be created by some people having (at least some) coding experience (or by cheap students/interns...). Under some circumstances these applications will raise in importance and spread from one user to a whole department.

Then there is the critical point: Who will maintain the application, add new features, ...? And this app is critical. It IS needed. But the intern has left the company. No one knows how it works. You only have a bunch of sources and some sort of documentation.

Does it make sense to try and control or forbid application development done ad-hoc outside of the IT department (with the exception of minor stuff like Excel macros)?

答:
You cannot fully control it...

I'd say you can never FULLY control it, as employees will always have means to produce rogue code and spread it by alternative means. So there's not much use obsessing too much over it, once you've drafted and enforced a few basic rules and processes, and set up a few tools.

The idea is for you to make it as attractive as possible for people to respect these rules and use these tools, rather than to make it so impossible to do new things that they don't produce anything.

But you can create a code-friendly environment

Many companies, often very large, do this. A good example being Google, for which representatives have said they use a single SCM for the whole company, for everyone to be able to monitor and look at others code.

I'd recommend you do the following:

give public access to some areas of your SCM,

make it easy to request access to continuous integration and continuous inspection servers,

encourage people to create build jobs for their tools.

The problem is then the proliferation of technologies. Obviously, some will prefer to use X over Y and that's when it gets harder to have them fit within your architecture. However, it's not impossible, and if they want their code to get maintained they'll probably got the extra mile if, well, it's just one mile.

You could also take a more arbitrary stance and decide that only language L and Stack S are allowed, but then you'll get some rogue stuff here and there, so I'd recommend to broaden it up a bit. Some CI systems will do wonders with a few plugins, if your employees are willing to write a bit of glue-code or some config scripts to get them to fit in.

Give teams some liberty

It's important to give teams some liberty to go on a whim and start some small new projects with experimental things. It keeps them on their toes, and you as well as it forces you to consider these technologies rather to remain stuck in a stack forever until it causes problems for you.

So make sure they have the ability to install their own systems for testing their pet projects. But, make sure to have them get into the habit of talking to IT about it.

Talk to IT, get them involved

It's much better if your employees develop the reflex of shooting an email request to IT and ask them if they can set up something for them and accommodate. They'll get turn down most of the time, but at least there's some notion of control and of who should be in charge and gives IT some visibility on the demands from different teams.

Once projects pick up a more critical mass, you can request again and they'll reconsider. Communication is key, and you need to have your teams of developers, consultants, IT support staff or anyone dealing with code to work together. None of them want stray programs, so it's in everybody's best interest. It's much easier to enforce rules if they're backing them up themselves.


答:
I think people are missing the general point here:

If you don't like all the custom development that's going on,
  forbidding it is solving the wrong problem - you should instead be
  asking why they're going around IT, not just telling them it's not
  allowed. Remember that you (IT) exist to help them do their job
  better, and that people don't use software because it's cool or neat
  or new, they use it because it solves a problem they have.

Why are these apps being created in the first place?

In all the cases I've seen, there's a common reason:

Business groups prioritize their own needs higher than those same needs are prioritized in the context of the whole company

Marketing is only responsible for marketing, so initiatives that benefit their goals seem critical to them, while being considered fluff to other groups, and tend to be prioritized lower when it comes to limited resources like IT. Prioritization only comes into play when they want to use a shared resource - if they keep the project entirely inside their own department, then only the department head has to care about the budget and timeline.

There's no reason I'd forbid this sort of development, within reason - it eases up constraints on shared resources (mainly IT), and allows each group to empower themselves to solve their own problems (as people versed in advanced Excel are pretty common, since this is a common problem, most departments have at least one).

However, you can't be expected to solve any problems that arise from these applications, or support them after the original developer leaves the company. As another posted mentions, this doesn't stop the big boss from demanding that you support it, but if you keep a feel out for the kinds of custom applications or processes out there, you can get a feel for when something becomes critical and you might need to get involved to bring it "in-house." Also, if something is connecting to and modifying systems that are under IT control, then IT should be involved, if only to ensure the security and integrity of their central systems - however, if it's something confined to a user's desktop, why feel the need to forbid it?

But here's something to remember: Every custom application that's been developed outside of IT corresponds to a need that's not being met by IT. There may be a good reason they're not met - not a priority in the company, very specialized problem, not as good as other options, custom language your IT people don't know, etc - and the lack of IT involvement may be legitimate, but these solutions were created because some department had a need that IT couldn't (or wouldn't) satisfy.

Try to help them solve their problems, and if you don't have the time or resources, let them solve them on their own. Mandating some language that has a steep learning curve, with the sole purpose of keeping people out of your business, only serves to enhance the elitist attitude most business users perceive IT to have, and in the end, that kind of elite attitude only leads to more of the same problem, as users are afraid to approach IT and are convinced that IT doesn't understand their needs or wants. Open the relationship - understanding what they need is the only way to keep them from going around you.

Title: Forbidding or controlling "Hidden IT..." Who should write and maintain ad-hoc software applications?

Body:
Bigger companies usually have the problem, that it is not possible to write all programs employees want (to save time and to optimize processes) due to a lack of staff and money.

Then hidden programs will be created by some people having (at least some) coding experience (or by cheap students/interns...). Under some circumstances these applications will raise in importance and spread from one user to a whole department.

Then there is the critical point: Who will maintain the application, add new features, ...? And this app is critical. It IS needed. But the intern has left the company. No one knows how it works. You only have a bunch of sources and some sort of documentation.

Does it make sense to try and control or forbid application development done ad-hoc outside of the IT department (with the exception of minor stuff like Excel macros)?


问:
Is it possible (and practical) to search a string for arbitrary-length repeating patterns?
I've recently developed a huge interest in cryptography, and I'm exploring some of the weaknesses of ECB-mode block ciphers.  A common attack scenario involves encrypted cookies, whose fields can be represented as (relatively) short hex strings.

Up until now, I've relied on my eyes to pick out repeating blocks, but this is rather tedious.  I'm wondering what kind of algorithms (if any) could help me automate my search for repeating patterns within a string.

Can anybody point me in the right direction?

答:
Donald Knuth wrote a lot about string matching pattern theory. A lot of algorithms are very efficient in time and hidden constant.
You can found some good algorithms here:

http://delab.csd.auth.gr/~dimitris/courses/cpp_fall05/books/SIAM_JNL_Comp_77_KMP_string_matching.pdf


问:
Persisting natural language processing parsed data
I've recently started experimenting with natural language processing (NLP) using Stanford's CoreNLP, and I'm wondering what are some of the standard ways to store NLP parsed data for something like a text mining application?

One way I thought might be interesting is to store the children as an adjacency list and make good use of recursive queries (Postgres supports this and I've found it works really well).

But I assume there are probably many standard ways to do this depending on what kind of analysis is being done that have been adopted by people working in the field over the years. So what are the standard persistence strategies for NLP parsed data and how are they used?

答:
A good strategy is to use a good Reduce/Map featured database, also know like NOSQL database, like MongoDB or CouchDB.

Theses database permit to create simple coded rules on which map terms and adjacencies, and simple coded rules to reduce (also "group") informations.

You can starts here:

http://www.mongodb.org/

http://wiki.apache.org/couchdb/


问:
Does comparison operand order affect speed?
I notice that someone in my organization programs comparisons like:

```<code>if (100 == myVariable)
</code>```

rather than:

```<code>if (myVariable == 100)
</code>```

He claims the former is quicker in languages like C++.  I can't find any evidence.  We program in C#.

Is this true for any programming language?

答:
Compare disassembly:

```<code>if (cmdline == NULL)
    cmp         dword ptr [ebp-138h],0
    jne         ........
</code>```

To:

```<code>if (NULL == cmdline)
    cmp         dword ptr [ebp-138h],0
    jne         ........
</code>```

No difference whatsoever.

The sole reason for "if (const == variable)" order is to catch accidental mistypes of "=" for "==", but your compiler, with the appropriate warning level set (you do have the appropriate warning level set?  Good, just checking) will catch those anyway.

Worse, aside from being as unreadable as the Voynich Manuscript, it can lead the programmer into a false sense of safety.  Witness:

```<code>int a = GetMeAnInteger ();
int b = GetMeAnotherInteger ();

if (a = b)
</code>```

Ha!  Gotcha!

So - not any faster, false sense of safety, makes your fellow programmers want to gouge their eyes out.

Or on the other hand you could just ramp up your warning level and catch them all anyway.

Body:
Compare disassembly:

if (cmdline == NULL)
    cmp         dword ptr [ebp-138h],0
    jne         ........

To:

if (NULL == cmdline)
    cmp         dword ptr [ebp-138h],0
    jne         ........

No difference whatsoever.

The sole reason for "if (const == variable)" order is to catch accidental mistypes of "=" for "==", but your compiler, with the appropriate warning level set (you do have the appropriate warning level set?  Good, just checking) will catch those anyway.

Worse, aside from being as unreadable as the Voynich Manuscript, it can lead the programmer into a false sense of safety.  Witness:

int a = GetMeAnInteger ();
int b = GetMeAnotherInteger ();

if (a = b)

Ha!  Gotcha!

So - not any faster, false sense of safety, makes your fellow programmers want to gouge their eyes out.

Or on the other hand you could just ramp up your warning level and catch them all anyway.


答:
... suppose there is a text file which contains lines starting with "a", lines starting with "b" and other lines and I actually only want to work with the first two sort of lines. My code would look something like this (using python, but read it as pseudocode):

```<code># ...
clear_lines() # removes every other line than those starting with "a" or "b"
for line in lines:
    if ...
</code>```

I hate if...then...else constructions.  I would avoid the whole issue:

```<code>process_lines_by_first_character (lines,
                                  'a' => { |line| ... a code ... },
                                  'b' => { |line| ... b code ... } )
</code>```

Title: Is it bad style to redundantly check a condition?

Body:
I often get to positions in my code where I find myself checking a specific condition over and over again.

I want to give you a small example: suppose there is a text file which contains lines starting with "a", lines starting with "b" and other lines and I actually only want to work with the first two sort of lines. My code would look something like this (using python, but read it as pseudocode):

```<code># ...
clear_lines() # removes every other line than those starting with "a" or "b"
for line in lines:
    if (line.startsWith("a")):
        # do stuff
    elif (line.startsWith("b")):
        # magic
    else:
        # this else is redundant, I already made sure there is no else-case
        # by using clear_lines()
# ...
</code>```

You can imagine I won't only check this condition here, but maybe also in other functions and so on.

Do you think of it as noise or does it add some value to my code?

Body:
... suppose there is a text file which contains lines starting with "a", lines starting with "b" and other lines and I actually only want to work with the first two sort of lines. My code would look something like this (using python, but read it as pseudocode):

# ...
clear_lines() # removes every other line than those starting with "a" or "b"
for line in lines:
    if ...

I hate if...then...else constructions.  I would avoid the whole issue:

process_lines_by_first_character (lines,
                                  'a' => { |line| ... a code ... },
                                  'b' => { |line| ... b code ... } )


答:
There is one case where there's a difference in C++, and that's if the variable is of an user-defined type, you've got the possibility of overloaded equality testing operators or an operator with a biased implementation.

```<code>bool operator == (int a, T b);
bool operator == (T a, int b);
</code>```

They could have different implementations, have one forward to the other, or per
For vanilla symmetric comparison, there shouldn't be any differences.

Title: Does comparison operand order affect speed?

Body:
I notice that someone in my organization programs comparisons like:

```<code>if (100 == myVariable)
</code>```

rather than:

```<code>if (myVariable == 100)
</code>```

He claims the former is quicker in languages like C++.  I can't find any evidence.  We program in C#.

Is this true for any programming language?

Body:
There is one case where there's a difference in C++, and that's if the variable is of an user-defined type, you've got the possibility of overloaded equality testing operators or an operator with a biased implementation.

bool operator == (int a, T b);
bool operator == (T a, int b);

They could have different implementations, have one forward to the other, or per
For vanilla symmetric comparison, there shouldn't be any differences.


问:
How does font rendering actually work?
I realize that I know essentially nothing about the way fonts get rendered in my computer.

From what I can observe, font rendering is generally made in a consistent way throughout the system. For instance, the subpixel font hinting settings that I configure in my DE control panel have influence on text which appears on window borders, in my browser, in my text editor and so on. (I should observe that some Java applications show a noticeable difference, so I guess they are using a different font rendering mechanism).

What I get from the above is that probably all applications that need font rendering make use of some OS (or DE)-wide library.

On the other hand, browsers usually manage their own rendering through a rendering engine, that takes care of positioning various items - including text - according to specific flow rules.

I am not sure how these two facts are compatible. I would assume that the browser would have to ask the OS to draw a glyph at a given position, but how can it manage the flow of text without knowing beforehand how much space the glyph will take? Are there separate calls to determine the glyph sizes, so that the browser can manage the flow as if characters were little boxes that are later filled in by the OS? (Although this does not take care of kerning). Or is the OS responsible for drawing a whole text area, including text flow? Does the OS return the rendered glyph as a bitmap and leaves it to the application to draw that on the screen?

答:
You are correct that, in general, applications use libraries provided by the OS or a GUI toolkit to do font rendering.

Typical font engines allow a number of modes of operation. For the simple case, an application can ask for a string of text to be drawn at a certain position, and the engine takes care of everything (measurement, positioning, drawing the pixels to the display, etc).

For applications which require a finer degree of control - browsers or word processors, for example - the engine will expose interfaces where the app can ask for a given piece of text to be measured in advance. The app can then use this knowledge to work out how much text it can fit on a line, where the line-breaks should be, how much room a paragraph will take, etc. The app can still ask the engine to do the actual rendering of the pixels.

(There may be an in-between scenario where the engine can take a maximum-width parameter, and possibly some kerning/padding parameters, and automatically render as much text as it can fit.)

Finally, the font engine might allow the app to take over the final rendering of the text, by returning bitmaps of glyphs pre-rendered at a certain size, allowing the app to position and composite it onto the final display. Or the engine might even offer to return the raw glyph outline data for rendering with some vector toolkit.

Title: How does font rendering actually work?


问:
Mobile Web Framework that will only control rendering and page transitions
I have been using jQueryMobile for a bit now, and there are some things I like about it and others I do not.

First I will give a bit of background.

I have a light weight mobile application that has a few configurations and 6 pages. Ideally I Would like to load all pages into the DOM (they interact with each other quite often and pages will be switched in the same frequency). The application will post for some JSON every n seconds and refresh the values on the page (yes it is primarily a information display app).

with the jQuery Mobile framework the only real thing I like is how easy it is to have a standardized UI a crossed all devices and browsers, I'm really not using too much else out of the framework other than the basic page navigation (if you are familiar with the framework; a bare-bone multi-page design is all i need).

Why I want to step away from jQueryMobile is how weighty it is. Not only do you need to include the mobile library, but also the base jQuery libraries. This I do not like because I'm not using jQuery anywhere else on the site.

Any suggestions on light-weight mobile frameworks that have a similar rendering as jQueryMobile?

答:
Try the customizable download builder for jQuery Mobile. You can get very specific about which pieces you want included, and it generates a package with just the JS and CSS that you need, based on your selections.

There's also a similar thing for jQuery UI.


问:
Grid Game Algorithm
Problem Link - http://www.iarcs.org.in/inoi/2009/zco2009/zco2009-1a.php

You have to find the path with the maximum weight, from the top-left cell to the bottom-right cell. It could've been solved with a simple Dynamic Programming approach, if it were not for the special condition - you are allowed at most one move that can be either to the left or up.
How do I now approach the problem with this special case?

Also, I'm looking for a time-efficient approach.

Thanks!

答:
It is still doable with the special case, but you need to add a third logical dimension to your DP, indexed by a Boolean variable. This new dimension distinguishes between the scores before the special move (when the index is false) and the scores after the special move (when the index is true). The other two dimensions remain the grid's rows and columns.

When you compute the best score for a cell at [r][c], you must compute two values:

A value where the third index is false. This result is computed based only on other values from the dimension where the index is false, looking at the cells to the left and up from [r][c]

A value where the third index is true. This result is computed based on values from both indexes: you consider the items to the left and up where the index is true, and also the items to the left, to the right, up, or down from [r][c].

The second set of values (index == true) must be calculated after the entire set of the first items has been computed. In other words, you solve the problem with no special move, and then use the table for that solution to build an expanded table for the solution that allows special moves.

Title: Grid Game Algorithm


问:
Examples of when we'll use interpreted language over compiled language?
I understand the differences between interpreted and compiled languages, but if someone could provide some examples of situations when one is likely to use interpreted languages over compiled languages, as well as situations when one is likely to use compiled languages over interpreted languages, it'd be really helpful.</p>

答:
There's (to my knowledge) no such thing as an interpretted "language" or a compiled "language".

Languages specify the syntax and meaning of the code's keywords, flow constructs and various other things, but I am aware of no language which specifies whether or not it must be compiled or interpreted in the language spec.

Now if you're question is when you use a language compiler vs a language interpreter, it really comes down to the pro's/con's of the compiler vs. the interpreter and the purpose of project.

For instance, you may use the JRuby compiler for easier integration with java libraries instead of the MRI ruby interpreter. There are likely also reasons to use the MRI ruby interpreter over JRuby, I'm unfamiliar with the language though and can't speak to this.

Touted benefits of interpreters:

No compilation means the time from editing code to testing the app can be diminished

No need to generate binaries for multiple architectures because the interpreter will manage the architecture abstraction (though you may need to still worry about the scripts handling integer sizes correctly, just not the binary distribution)

Touted benefits of compilers:

Compiled native code does not have the overhead of an interpreter and is therefore usually more efficient on time and space

Interoperability is usually better, the only way for in-proc interoperation with scripts is via an interpreter rather than a standard FFI

Ability to support architectures the interpreter hasn't been compiled for (such as embedded systems)

However, I would bet in 90% of cases it goes something more like this: I want to write this software in blub because I know it well and it should do a good job. I'll use the blub interpreter (or compiler) because it is the generally accepted canonical method for writing software in blub.

So TL;DR is basically, on a case by case basis comparison of the interpreters vs the compilers for your particular use case.

Also, FFI: Foreign Function Interface, in other words interface for interoperating with other languages. More reading at wikipedia


问:
Consultant in a firm that doesn't understand the tech!
I got the job as a Consultant in a firm that has 3 other programmers. My job is to rewrite all the old system in Java, Spring etc but the staff programmers only know perl and the manager does not know any programming.

I am trying to get them to understand that I have 6 projects to rewrite here but no one has design docs or spec. the staff programmers never had to write any documents. Plus I cant get the manager to understand the new java tech stuff.. he keeps asking some of the staff for views on things but the staff don't know it or understand it.

Where do I go from here to make the manager understand that the staff programmers or someone has to write a design document so I know what to build. or if I have to write the documents how do I get the information?

答: I would start by talking to you manager and accepting the responsibility for collecting the requirements and defining the specs.  You will need to convince him of the need for these documents and what they will provide.  I would probably find an example online.  Then you take charge of assembling the requirements and the specifications for the system.  Then meet with your manager again to go over the document. Once you have shown them the first document you may be able to get some assistance in creating the other 5.  Other wise if it is effective then you will probably be responsible for gathering those requirements as well but at least someone will be doing it.</p>


答:
Seems kind of odd that the staff don't know the platform you've been asked to re-write their work in. What happens after you leave? Who will support your work?

So you've got a complex system that doesn't have proper documentation, and you must re-create the system in a different platform. What I would do, in your position, is to identify the single person who must "sign off" on the new system. From there, do some reading on User Stories to identify how to break requirements down into bit-sized chunks that can be described in plain English. Their format is something like "As a USERROLE, in SYSTEM X, I want to ACCOMPLISH ACTION so that GOAL IS MET.

To further explain a User Story, you add in 'success criteria' in the format of "Given when CONDITION then OUTCOME" to explain what happens with different actions inside the parent User Story. This is a decent way of breaking out functionality into pieces that can be understood individually, and you can get help writing different Stories from different groups (just make sure the top-level person who signs off on the work stays the same).

So get all the old functionality of the system re-written as User Stories, then ask the project owner if there's any NEW functionality that they want in the Java version. Add stories to satisfy that, if there's any, and then start coding.

Basically, you need to be able to expose the staff programmers' unhelpfulness. Get the project owner to require that they provide you with the Success Criteria for some of the Stories, so that if they give you crappy input, you can just hold that up as your official requirements. Anything they leave out will be their fault, not yours.

Title: Consultant in a firm that doesn't understand the tech!

Body:
I got the job as a Consultant in a firm that has 3 other programmers. My job is to rewrite all the old system in Java, Spring etc but the staff programmers only know perl and the manager does not know any programming.

I am trying to get them to understand that I have 6 projects to rewrite here but no one has design docs or spec. the staff programmers never had to write any documents. Plus I cant get the manager to understand the new java tech stuff.. he keeps asking some of the staff for views on things but the staff don't know it or understand it.

Where do I go from here to make the manager understand that the staff programmers or someone has to write a design document so I know what to build. or if I have to write the documents how do I get the information?


答:
First of all, a programming language can be both inerpreted and compiled. Interpretion and compilation are just methods of generating executable code from the source code. With an interpreter the source code is being read and interpreted by an interpreter which then executes the code as it interprets it. A compiler on the other hand reads the source code and generates an executable binary file from the source code - so that the program can be ran as a separate process independently.

Now before anyone wonders... Yes, C/C++/C#/Java can be interpreted, and yes, JavaScript and Bash scripts can be compiled. Whether there are working interpreters or compilers for these languages is another question though.

Now to actually answer the question when we'll use "interpreted language" over "compiled language". The question itself is somewhat confusing, but I assume it means when to prefer interpretion over compilation. One of th downsides of compilation is that it generates some overhead due to compilation process - the source code has to be compiled to executable machine code so it's not suitable for tasks which require minimal delay when invoking the source code to execute a program. On the other hand compiled source code is almost always faster than equivalent interpreted source code due to the overhead caused by interpreting the code. Interpreters on the other hand can invoke and run the source code with very little invocation overhead, but at the expense of run-time performance.

In the end it's near impossible to mention any definite use cases when to prefer one after another, but for example one (to my undersanding very unrealistic) case would be when the program source code changes dynamically between program invocations and the overhead of compiling is too high for it to be viable choice. In that case interpreting the source code instead of compiling would probably be desirable.

However, there's something which can be regarded a real-world example: hidnig source code upon deployment. With natively compiled code the developer deploys the executable macine code of the program and data. With interpreted code the source code itself has to be deployed which can then be inspected and reverse-engineered wit much less effort than what it is to reverse-engineer native machine code. One exception to this is languages like C# and Java which compile to immediate language/bytecode(MSIL for C# and Java bytecode for Java) which then gets deployed and compiled "just in time" at runtime, kind of like an interpreter does. However, there exist so-called decompilers for MSIL and Java Bytecode which can reconstruct original source code with relatively good accuracy and as such reverse-engineering such products is far more trivial than reverse-engineering products which are deployed in native machine code.

Title: Examples of when we'll use interpreted language over compiled language?

Body: I understand the differences between interpreted and compiled languages, but if someone could provide some examples of situations when one is likely to use interpreted languages over compiled languages, as well as situations when one is likely to use compiled languages over interpreted languages, it'd be really helpful.</p>


答:
I can think of the following scenarios when you'd use an interpreted language:

Where no compiler exists, like Linux/Unix shell scripts.

Quick and dirty scripts that solve a little problem

Languages that make it easy to write dynamic HTML pages and are generaly interpreted like JSP (Tomcat compiles it into a servler previos to run), PHP, ASP etc.

I can think of the following scenarios when you want to compile your code:

You need to distribute binaries because your app is closed-source and you don't want to give out your source code.

Speed, like embedded systems and the like.

You need a level of code type-safety that only a compiler with an strictly typed language can give you. Compilers expose typos in every nook and cranny of your source code, whereas in interpreted programs typos can go undiscovered into production code.

Large, complex systems: can't imagine a OS or an office suit as anything but compiled binaries.

You want to get every tiny bit of overhead out of the way and need good communication with assembler snippets (hard with any kind of runtime, especially with an interpreter) ( this point brought about by a @delnam comment )


答:
I have been involved in a project where the entire system was written in Oracle Forms, but without any documentation. The technology could have easily have been Perl. Here is the plan of attack for migrating the system to Oracle ADF (but could also just as easily be any other platform):

Create a set of code categories for business requirements (functional, bugs, validation, ui, etc.).

Create a set of categories for the screens (group them by similar functionality).

Create a list of all screens for the entire application and enumerate them within a spreadsheet.

Assign each screen a code category and a code type (e.g., business rule, system requirement, technical).

Reverse engineer the code to extract the business requirements, crafting a one-sentence description of each requirement.

At this point you will have documented the business rules for the application. This alone will be gold for anyone who next has to maintain the system. Moreover, it will give you a chance to see what parts of the system have been duplicated. (In my case, we discovered that over 60% of the code base was duplicated.)

From here, you can sort through the business requirements with management. This might entail crafting user stories, for example. This will also reveal high-level duplicate functionality, and present opportunities to both simplify and enhance the system during migration. I have included a screen shot of the spreadsheet to show one way to go about tracking and documenting the requirements.

You might have to brush up on your Perl. ;-)

Once you have reverse-engineered the project, you can employ a suite of tools to help you out with the software development life-cycle. (We're using JIRA, but there are many other software suites that would work.) You might have some fighting to do, but once you have the requirements down, you'll want to move to the following environments:

Create a documentation environment (e.g., a wiki).

Create a development (DEV) environment. Web servers, database servers, source repository, etc.

Create a test (TEST) environment that mirrors development.

Create a pre-production (PREPROD) environment that exactly mirrors production, and can act as a fail-over for the production system.

Create a production (PROD) environment.

Think about using a community-oriented service to tackle the requirement of end-user documentation. An excellent software package similar to the StackExchange suite is OSQA. Let the users build the help system (it's quite a clever strategy).

The SDLC becomes:

Developers make and test application changes in DEV (using a repository).

System tools automatically deploy regular builds into TEST.

Once testers are satisfied with the application, the application is deployed into PREPROD. This allows the deployment process to be tested as well. More testing happens in PREPROD.

Once testers are satisfied with PREPROD, the application is finally rolled into PROD.

I find this to be a highly-organized approach that works well with different development methodologies. The first pass, which I have described here, should be considered a "broad brushstroke" -- you don't want to get too detailed (bogged down) with technical minutia at this point. (User interface requirements, for example, are captured by each screen. As long as you have the screens enumerated, you needn't iterate every single input field -- just link to a screen shot or working URL.)

Lastly, to review the source code, we auto-generated a series of web pages (one web page per functional "screen"). This worked well because the PL/SQL code could be split into separate files, and automatically converted to HTML with syntax highlighting. With Perl, this might not work as well for you. The idea, though, is that you can create anchor links within the spreadsheet that point back to the section of code that enforces the business requirement. (As an aside, this would also allow multiple developers to reverse-engineer the system requirements in parallel because each developer can tackle different screens simultaneously.)

An example source code snippet (the + is an anchor link):

You could recommend hiring a couple of Perl gurus to help with the analysis task.

I don't think it's very productive to point out that other people are doing "crappy work"; rather, you should be looking to improve the product and give people an opportunity to help with this goal (and perhaps learn how to improve their skills in the process). That is, you don't know what the other developers know, nor were you there when they developed the system. This approach makes the entire process open and highly visible whereby everyone can contribute.

Honestly, managers will see for themselves who is genuinely helpful and who wants to improve.


答: In today's multi-core, out-of-order-execution world, you can't count on microefficiencies like this any more.  Even if it did save a cycle or two, there's no guarantee when the instruction will be scheduled, or if the cache line holding your variable will be locked (or flushed).  I'm not even sure how much more efficient short-circuit evaluation is any more (for simple comparisons).</p>


答:
They have no documentation and their code is so poor they've hired someone else to rewrite it in another language. Start gathering requirements from the source. You will find a lot of the features and functionality are no longer used or may not work properly. It's equally important to know what not to build.

Once you've found what the users need, determine what is already in the current application and what has to be built from scratch. The existing pieces is where you can look at the code and talk to the devs.

Anyone who proclaims they need everything has never bother to check. There is an arguement to never rewrite an application, but that assumes everything works the way users want it and that is not always true. They use it because there is no alternative. Give them a better alternative.


问:
What do you call a queue when the word queue is reserved?
I'm working on a rails app, and in rails queue is a reserved word. I need to make a Queue model for my app, and I'm stuck because I don't know what else to call it.

Has anyone else run into this before, and if so what did you call your Queue that can't be called a Queue?

答:
If this is not a priority queue*, you can call it FIFO, for the abbreviated name of the strategy used by the data structure.

* If it is a priority queue, calling it priorityQueue would be a good choice, and it wouldn't conflict with the reserved word


问:
How does a browser determine that a script has run for too long?
How does a browser determine that a script has run for too long ? Is it actually configurable through some advanced settings ?</p>

答:
This is probably not the answer you expected but it might be useful to somebody else. I only know the details for Firefox but I assume that the other browsers do something similar (at least the ones that limit script execution, see the link provided by Yannis Rizos in the comments).

JavaScript in the browser is generally single threaded and event driven. This means that there is an event queue somewhere and the browser is processing the queued events in a loop. The events posted to the event queue can be both "real" events (e.g. keyboard input) or synthesized events (created by JavaScript code, native code or things like timeouts). The processing of these events might involve JavaScript code (e.g. event handlers in a web page) but it doesn't have to - an event could be handled in native code only. It is essential that processing of an event is fast because it delays processing of all other events, including the ones essential to keep the browser UI working - the user perceives lack of event processing as a hang.

So the trick Firefox is using: there is a thread checking regularly how long the processing of the current event takes (how much time has been spent outside the event processing loop so far). If it exceeds a certain threshold (determined by the dom.max_script_run_time preference for web scripts and dom.max_chrome_script_run_time for browser's own scripts) this thread checks the stack of the main thread - and if it finds a JavaScript frame on the stack it suspends it. The "unresponsive script" warning shows up and the browser returns to processing the event queue temporarily. If you decide to stop the script then this JavaScript code is stopped. I'm not certain how exactly it is being stopped but probably by generating a JavaScript exception which cannot be caught - something that doesn't always work correctly if native and JavaScript stack frames are interleaved.

The real implementation is of course more complicated than what I explained above (e.g. when it comes to modal dialogs) but this should be enough to get you started if you want to find out more.


答:
An important point here is that many language implementations actually do some sort of hybrid of both. Many commonly used languages today work by compiling a program into a intermediate format such as bytecode, and then executing that in an interpreter. This is how Java, C#, Python, Ruby, and Lua are typically implemented. In fact, this is arguably how most language in use today are implemented. So, the fact is, language today both interpret and compile their code. Some of these languages have an additional JIT compiler to convert the bytecode to native code for execution.

In my opinion, we should stop talking about interpreted and compiled languages because they are no longer useful categories for distinguishing the complexities of today's language implementations.

When you ask about the merits of interpreted and compiled languages, you probably mean something else. You may be asking about the merit of static/dynamic typing, the merits of distributing native executables, the relative advantages of JIT and AOT compilation. These are all issues which get conflated with interpretation/compilation but are different issues.


问:
Do database tables need to have IDs?
Is an ID field is always needed in database tables?

In my case I have a user with firstName, lastName and email fields. email is unique and not null, so it could be used as an ID, right? So in that case, could/should I try to remove the ID?

Also I want to have another table which extends this one. Let's say its called patient and it has it's own field additionalData and I would like to link the relationship through the email of user I mentioned. So the relationship should be 1 to 1, right? and I wouldn't need the IDs? Somehow MySQL Workbench wants me to use the IDs.

What do you guys think. Any suggestions on this topic?

答:
email is unique and not null, so it could be used as an index, right?

Right. It would be the natural key of the table. You don't need to a surrogate key, but having to join on this field is wasteful and could be slower than using an int surrogate key.

So the relationship should be 1 to 1, right? and I wouldn't need the IDs?

Lets say it is 1 to 1. You still need to link the two tables together.

Using a surrogate key can help with performance. If the natural key is also of a data type that leads to efficient storage and execution, all the better.

Title: Do database tables need to have IDs?


问:
Designing a Content-Based ETL Process with .NET and SFDC
As my firm makes the transition to using SFDC as our main operational system, we've spun together a couple of SFDC portals where we can post customer-specific documents to be viewed at will. As such, we've had the need for pseudo-ETL applications to be implemented that are able to extract metadata from the documents our analysts generate internally (most are industry-standard PDFs, XML, or MS Office formats) and place in networked "queue" folders. From there, our applications scoop of the queued documents and upload them to the appropriate SFDC CRM Content Library along with some select pieces of metadata. I've mostly used DbAmp to broker communication with SFDC (DbAmp is a Linked Server provider that allows you to use SQL conventions to interact with your SFDC Org data).

I've been able to create [console] applications in C# that work pretty well, and they're usually structured something like this:

```<code>static void Main()
{
    // Load parameters from app.config.
    // Get documents from queue.
    var files = someInterface.GetFiles(someFilterOrRegexPattern);

    foreach (var file in files)
    {
        // Extract metadata from the file.
        // Validate some attributes of the file; add any validation errors to an in-memory
        // structure (e.g. List<ValidationErrors>).
        if (isValid)
        {
            var fileData = File.ReadAllBytes(file);
            // Upload using some wrapper for an ORM or DAL
            someInterface.Upload(fileData, meta.Param1, meta.Param2, ...);
        }
        else
        {
            // Bounce the file
        }
    }

    // Report any validation errors (via message bus or SMTP or some such).
}
</code>```

And that's pretty much it. Most of the time I wrap all these operations in a "Worker" class that takes the needed interfaces as constructor parameters.

This approach has worked reasonably well, but I just get this feeling in my gut that there's something awful about it and would love some feedback. Is writing an ETL process as a C# Console app a bad idea?  I'm also wondering if there are some design patterns that would be useful in this scenario that I'm clearly overlooking.

Thanks in advance!

答:
Well...just focusing on the practical aspects of the general ETL problem, without too much additional effort you could separate the backing logic into one or more reference-able assemblies, and create a simple windows service to call into your ETL process in an identical way.

It's trivial to set up a windows service application to also be runnable via console (via a command line argument) so you don't lose the ability to run it as a console if you want to.

In return you gain the ability to run the ETL process as a windows service; using a System.Threading.Timer or scheduling mechanism of your choice within the windows service object gives you an automated / scheduled solution that should rarely require manual intervention.

If your ETL process is working already as a console app, it should only take you somewhere between a few hours to a couple of days (depending on how familiar you are w/ windows services and if you want to embellish the solution w/ extra bells and whistles) to evolve it into a windows service and start testing it.

As the actual ETL logic itself is independently available from this means of running it you can also drive the logic from other applications, such as a workflow or from one or more GUI's.

Console apps are handy for convenient "utility" dev tools, one off batch process, command line style UI's (a rare thing these days), to get something off the ground, or to play around with some logic w/o worrying about wiring up a GUI, and so forth.

But mission critical, repetitive, and or operational processes deserve a more robust mechanism of execution / interaction, in my opinion.

From a "Patterns" perspective, more logic and context would be necessary to make a real recommendation, but from a general ETL perspective the Pipeline aka Pipes and Filters pattern is often a key consideration...you may already have a simple version of it set up even if you didn't deliberately set out to implement it as it's very natural to this kind of problem.

If you are ETL'ing a lot of data, you probably want to consider splitting it up into pieces that you can do parallel processing on...but that leads into a bigger discussion.

Hope something in there helps...


问:
Number Game Algorithm
Problem Link - http://www.iarcs.org.in/inoi/2011/zco2011/zco2011-1b.php

The task is to find the maximum score you can get in the game. Such problems, based on games, where you have to simulate, predict the result, or obtain the maximum possible score always seem to puzzle me.

I can do it with recursion by considering two cases - first number picked or last number picked, each of which again branches into two states similarly, and so on... which finally can yield the max possible result.

But it's a very time-inefficient approach, since time increases exponentially, due to the large test cases.

What is the most pragmatic approach to the problem, and to such problems in general?

答:
The trick is thus:

Consider 2,5,3,3,2,1.

Your move: Pick Left

Opponent move: Pick Right

Current state: 5,3,3,2.

vs.

Your move: Pick Right

Opponent move: Pick Left

Current state: 5,3,3,2.

Using recursion, you will end up calculating how many more points you can get for 5,3,3,2 twice!

So, the solution is to use memoization (dynamic programming)

The first time you call your function on 5,3,3,2, store the score for that (e.g., in a two dimensional array where the first index is how many numbers have been removed from the left and the second index is how many numbers have been removed from the right).  The next time you are about to call it, just load the score from the previous time.

A nice benefit of this strategy is that you can use your existing recursive algorithm with only minimal modification.

Title: Number Game Algorithm


答:
Virtually every table needs a primary key.  I would strongly argue that every table needs a primary key but I'm willing to make the occasional exception.

Whether the primary key of a table should be a "natural" primary key-- some column or columns that are part of the business data that are naturally unique-- or whether a "synthetic" primary key should be used-- some additional data that has no business meaning and is used solely as an identifier, generally either an incrementing integer or a GUID-- is a bit of a religious debate.  Personally, I tend to prefer synthetic keys over natural keys but other data modelers who I have a great deal of respect for prefer natural keys.

In your case, one of the primary issues with using a email address as a natural key is dealing with what happens when someone wants to change their email address.  If email address is the primary key, they you'll have to change the data in the USER table but you'll also have to ripple the change through every child table that has a foreign key relationship to the USER table.  Depending on your database, that can range from annoying to a major undertaking, depending on whether your database happens to support cascading updates.  Oracle, for example, believes that primary keys ought to be immutable so it does not support cascading updates-- you'd have to write that code yourself (or leverage one of the packages floating around to do it).  I believe MySQL does support cascading updates so you merely have to ensure that each and every foreign key constraint in the system is set to cascade on update and test that you haven't broken the ability to change an email address every time you add a new table to the database or modify a constraint.  On the other hand, if you use a nice, simple synthetic key, i.e. a user_id column, you can simply update the email address column like you would update any other piece of business information.

Whatever you define as the primary key of your parent table should be used as the foreign key in your child table.

Title: Do database tables need to have IDs?

Body:
Is an ID field is always needed in database tables?

In my case I have a user with firstName, lastName and email fields. email is unique and not null, so it could be used as an ID, right? So in that case, could/should I try to remove the ID?

Also I want to have another table which extends this one. Let's say its called patient and it has it's own field additionalData and I would like to link the relationship through the email of user I mentioned. So the relationship should be 1 to 1, right? and I wouldn't need the IDs? Somehow MySQL Workbench wants me to use the IDs.

What do you guys think. Any suggestions on this topic?


答: Or add the type of things you plan on storing in it: taskQueue, messageQueue.</p>

Title: What do you call a queue when the word queue is reserved?

Body:
I'm working on a rails app, and in rails queue is a reserved word. I need to make a Queue model for my app, and I'm stuck because I don't know what else to call it.

Has anyone else run into this before, and if so what did you call your Queue that can't be called a Queue?


答:
well as my title says I have a qeustion whether an index is always needed in database tables?

Pretty much nothing is always needed--but you will basically always want an index.

Natural keys are a wonderful thing when they are efficient and exist. In the real world, both rare. In your example, I would be very hesitant to regard email as unique. Email addresses can be reissued. Domain names are bought and sold. This is especially possible if you have soft deletes on your tables (e.g. toggle an IsDeleted flag to 1 instead of issuing a hard DELETE statement).

Moreover, as @Oded pointed out, using a combination of strings is seldom as efficient a key as just allocating one usable integer.

Title: Do database tables need to have IDs?


问:
Not-for-profit universities that offer computer science undergraduate degree online?
There are many masters degree programs in computer science online offered by reputable organizations. However, I've found very few bachelors only degree programs offered by non for-profit institutions.

I am looking for a degree in computer science and also any programs for entrepreneurship/management or algorithmic trading.

I've found only 2 programs so far that fit:

http://www.regis.edu/regis.asp?sctn=cpcis&p1=ap&p2=cs&p3=ol

http://depaul.edu

Requirements:

100% online undergraduate non-profit

Options: Bachelor of Science Bachelor of Arts

Bonuses: accelerated recognized ABET cost effective

Update:
I've answered my question with a list. If anyone knows an online program that combines skills in entrepreneurship (getting capital, starting a business) or algorithmic trading with a computer program that would be ideal.. maybe too much to ask though

答:
Troy University

I am in the midst of my first term at Troy.  I had a list similar to yours, and Troy fit the bill.  In the end, it came down to Troy's program or UMUC.  Troy was half the cost for what appeared to be the same level of education, so I chose it.  It is regionally accredited; however, it is NOT recognized by ABET.  That is to say Troy University as a whole, not just their online program, is not recognized by ABET.  Troy makes no distinction between their online or on-campus programs.  The coursework is the same for both.  It operates on a term system.  They have five terms a year.  Your first term you may only take two classes, but after that, you can appeal to take more classes per term.  So far, the institution's staff has been very knowledgeable, helpful, and prompt to respond to my questions.  I enjoy the experience but YMMV.  I'm not sure what you're situation is, but I'm 30 with a family and have already completed a B.A. and a M.A. the traditional way.  I want to make a career change, and this was the best possible scenario for me to make it happen.  Also, I don't know how much schoolin' you're looking to get, but while there are only a handful of accredited B.S. Comp sci programs available online, there are several M.S. Comp sci programs online from most of the major schools.  That is the route that I am probably going to take.  Hope this helps.

ContentLicense: CC BY-SA 2.5


答:
In every database schema there could be many tables.

In some tables the natural key is a good key.

In some tables no natural key exists or it is not a good key.

In case 1 you should used the natural key.

In case 2 you should use a autogenerated surrogate key

"Every PK must be natural" is a wrong approach and impossible to achieve. This is an extreme position, but nobody proposes it.

"Every PK must be surrogate" is a wrong approach also but sadly possible to achieve. This is also an extreme position.

Use natural when natural fits and use surrogate when it doesn't.

The "every PK must be surrogate" approach leads to many headaches:

Migrating data from a database to another is a nightmare since surrogates are sequences that are not syncroniced between databases.

Data is only meaningful if visualized through "the" application, assuming an "one application -> one database" paradigm.

Queries are more complex because you have to join every table from the top-most table ( only place where the business key exists, down to the last table ).

Business people speaks business, they know that a car plaque is ADFG 237, they don't know the car has 155201 ID in the car table. Meetings with the users/business people get awkward because you continue talking about keys they don't know and they continue talking about business keys they know.

Users will continue to use the natural key for searches, meaning you will have to keep the natural key indexed anyway.

Interoperation with any external system has the overhead of translating the business key, like the ISO/universaly accepted LHR code for London Heatrow Airport, into the surrogate meaningless key.

Those who defend the "every PK must be surrogate" approach usually argue than character keys are inefficient for joins. Well maybe that was a decade ago, and they fail to produce numbers to support that.

They also argue the update issue when the natural key changes. If the natural key changes frequently, then it's not a good key. If it changes every ten years, that's what cascade update is built for into modern RDBMS.

Also, any hipotethical performance problem of using character keys can be solved by throwing money at it.

But the problems of using the "every PK must be surrogate" approach, cannot be solved by throwing money at them.

Please someone produce any canonical text or bibliography that supports the "every FK must be surrogate" point. On the other hand, the "mixed", "surrogates when necessary" approach is well documented. And Codd's normal forms still exist.

My suggestion:

Use natural keys where a good enough one exists.

Use surrogates when a good enough natural key doesn't exist.

EDIT: Some people say that "every PK must be surrogate" is an implementation decision, and thus it doesn't violate 3NF and 3NFBC, but they include them first off from the beginning of the design, in the conceptual phase, violating 3NF and 3NFBC, which is an error that is paid by means of writing much much more code than necessary.

Title: Do database tables need to have IDs?


答:
In the end, the big trade-off is between productivity (how many lines of code do you have to write) and performance (how fast will your program execute).

Because interpreted languages when transformed to CPU information have more information, they can rely on reflection and dynamic typing which greatly increase the productivity. Another advantage of interpreted languages is that they are platform independent so long there is an interpreter for the platform.

Because the CPU mustn't transform the language code in machine code and run the code at the same time, as in the interpreted case, compiled languages yield more faster programs. Also, a system built in a compiled language is more secure since it can detect issues at compile time which basically means you see an error as you type it (with modern IDEs) instead of seeing it only when you actually run the program (of course, this does not fix logical errors).

Knowing this, interpreted languages are suitable for:

Productive development: fast web development (PHP, Javascript) or for prototyping.

Cross-Platform; for example JavaScript is supported in every browser (including mobile browsers).

And compiled languages are suitable when:

Performance is critical (operating systems) or resources are scarce (microcontrollers).

Systems to be built are complex; when building large systems (enterprise systems) compiled languages are essential handling many possible bugs that may appear in interpreted languages; also complex programs require many resources and the balance tends to compiled languages also.


答:
It's good to use IDs because of clustered indexes. IDs are integers (small) and sequential so they are the ideal for clustered indexes.

Also it's good to use IDs because they are surrogates. Surrogates never change. An email address can change causing you headaches to update all the tables that reference the email as a key.

But all tables should not have ID's. The question boils down to 2 things:

can the table benefit from a clustered index?

can the table benefit from a surrogate key?

If the answer to both of those questions is "no" then there is no point of having an ID.

A key/value hash that does not grow at run-time gains no benefit from an ID. The table is a stand alone island so an ID would never be used in a join. All filters will be on the natural key. The ID would just waste space. No benefit from clustering on the ID, no benefit from the surrogate.

Mapping or junction tables should never have their own ID. These are used to implement many-to-many relationships.

There is never a situation where you would join or filter on the ID of a mapping table.  All joins and filters would be on the IDs which the mapping table maps. The PK would be the combo of the 2 mapped IDs. The combo of 2 surrogate ID's is a surrogate in it's own right.

Usually you will want 2 separate covering indexes on a mapping table. So each mapped ID can be the dominate field in a covering index. A dedicated ID would just waste space for junctions.

Title: Do database tables need to have IDs?


答:
You cannot stop these "hidden" applications because people make them to solve real-world business problems. All you can do is help them do it the "right" way. And by "right" I mean making it so that the apps can be maintained after the person starting them has left. I recommend using the language suggested in Up or Out: I need you to document this process in detail so that any yahoo can understand it a year from now after you’ve left.  Help with setting up version control (and showing them how to use it), a wiki (for keeping informal notes on how work actually gets done) and a simple bug tracking system. If you want to make things really slick, set up continuous integration on a spare server (if you have one).

You'll see the huge desire for Excel integration (or at least import/export) because all business schools now teach Excel and it is a major tool used in many business courses.


答:
The decision to write a new application is often based on a cost benefit analysis of the request; as well as the overall value to the business. All while taking in to consideration many other drivers such as available IT resources, scope of the request, business goals and direction just to name a few. Often times a specific departments request is denied because the department manager/director has failed to show a reasonable ROI or simply doesn't follow established process.

Regardless of the reason the 'IT Department' is often the scapegoat, even if the decision was outside of their control. So even though denial of the request may not reflect poorly on the IT department the perception is often entirely different.

Despite this you'll find rogue applications in nearly every business organization in the world. Some well written and others that well, contain code that should have never seen the light of day.

While we should do everything we reasonably can to meet our internal customers needs there are times that we simply can not. When that happens they will look elsewhere to address their problem.

If the IT group is actively involved in the project then we can demand adherence to our standards, help the consultant to follow internal coding guidelines, and understand the applications interactions with and demands upon our systems   (database, network, firewall, …). Without that involvement we'll be caught short and spend a great deal of time trying to figure out why our production systems are not meeting SLA.

Whether the IT department condones and supports them or not they can, and will, have a direct impact in terms of support, OLA and SLA commitments that any IT department is measured by.


问:
How do professional application developers use version control systems, like GIT and Subversion?
I am a beginner developer and I have been wondering from the start, how do professional use tools like GIT and Subversion (I don't have a very good understanding about these tools), to fulfill their project's needs. If they do use it, how would I set up something like that?

My applications are not so large and I am not working in a team yet, would they be of huge help to me?

There are questions on this site about how to use the tools, but I need beginner support.

答:
Source control systems (SVN, Git etc) at a very simplistic level allow you to keep the change history of files. This allows you to see how your code has changed over time and roll back changes which you may not want (e.g. the change doesn't work as expected, you can revert the code to a previously known state). This is something that even developing on your own will become invaluable to you once you start using it.

As soon as you are working with other people in a team, the benefits increase even more as multiple people can change the same file and if the changes don't conflict (e.g. 2 people change different sections of the file) the changes will be merged automatically. If there are any conflicts then you will be able to see your changes next to your colleagues and discuss with them how to merge the changes.

You can also create snapshots of the codebase (usually called a tag) when releasing a version of the code so that you can easily debug issues even though the main source has moved on with new features which may not have been released yet.

Here are a few useful resources:

Getting up and running Subversion and Tortoise SVN
with Visual Studio and .NET

Version Control with Subversion


答:
Source control is ubiquitous--one might even say you can't call yourself a professional developer if you are not using it. Even when developing alone, source control still offers quite a few benefits. In the end it provides both a history and an extensive undo path. It also frees you up to experiment a lot more, secure in the knowledge that if you do not like the new version, you can always switch back to what you had before.

That said, workflows, even within a source control system like Subversion or Git, vary immensely from team to team. The best place to start is probably to pick a source control system and get familiar with its standard workflows (keeping in your head that you will have to switch workflows throughout your professional life).

For getting started, I would recommend Git. I am a Git fan, but more specifically choosing Git gets allows you to begin by working serverless and only set up a server when it makes sense for you. Subversion, on the other hand, requires a server and setting one up, while not extremely difficult, is daunting when you are unfamiliar with that sort of thing.

Here is a good overview of the some good rules of thumb for source control in general: http://scottonwriting.net/sowblog/archive/2008/11/13/163320.aspx

When working by yourself, you do not need a good deal of workflow. Commit early, commit often. If you start rolling out versions, tag your releases. Create branches for experiments or long divergent work (Git makes this cheaper and simpler than Subversion does).

Title: How do professional application developers use version control systems, like GIT and Subversion?

Body:
I am a beginner developer and I have been wondering from the start, how do professional use tools like GIT and Subversion (I don't have a very good understanding about these tools), to fulfill their project's needs. If they do use it, how would I set up something like that?

My applications are not so large and I am not working in a team yet, would they be of huge help to me?

There are questions on this site about how to use the tools, but I need beginner support.


答:
There are two widely-used algorithms for this task: the Index of Coincidence (IC) and Kasinski's method. Googling for either should yield a fair number of hits. Kasiski's method is is older -- at least IMO, the IC is a more effective, especially if you're working with a limited amount of ciphertext. Kasiski's method can work well, but generally requires more ciphertext before it becomes effective.

I should probably add: both of these are really intended for attacking polyalphabetic substitution ciphers. The first step in each is attempting to find the length of the key being used. In your case, working with block ciphers in ECB mode, you probably already know the block size (which is probably the closest equivalent of the key length in a polyalphabetic substitution cipher). What you're left with is largely a matter of just walking through the blocks, and counting how many times a block occurs to see if you can find repetitions. That being the case, it's probably about as easy to skip past most of the algorithm, and just use something like a hash table to count the number of times different block values occur.

Most normal string search algorithms (e.g., Knuth-Morris-Pratt, Boyer-Moore-Horspool) are of little use in this pursuit.

Title: Is it possible (and practical) to search a string for arbitrary-length repeating patterns?

Body:
I've recently developed a huge interest in cryptography, and I'm exploring some of the weaknesses of ECB-mode block ciphers.  A common attack scenario involves encrypted cookies, whose fields can be represented as (relatively) short hex strings.

Up until now, I've relied on my eyes to pick out repeating blocks, but this is rather tedious.  I'm wondering what kind of algorithms (if any) could help me automate my search for repeating patterns within a string.

Can anybody point me in the right direction?


问:
Specify that a spawned process returns to a parent
I am using yED to build an application flow-chart, and I can't figure out a 'nice' looking way of representing that a GUI's call to spawn a process loops back to the GUI process once it terminates, other than drawing another arrow to the GUI process.

Is there a better way of presenting a process looping back to its parent on return/exit other than drawing another arrow back to the parent?

答:
In an ordinary flowchart (not a UML diagram), any box that represents some other process, subroutine or method (returning back to the caller) would be represented by a box having double-vertical lines instead of single, the Predefined Process Symbol.

Return to the calling entity is indicated by flow control passing through the box, and out the other side, just as it would with any other non-terminating shape.


问:
Forbidding or controlling "Hidden IT..." Who should write and maintain ad-hoc software applications?
Bigger companies usually have the problem, that it is not possible to write all programs employees want (to save time and to optimize processes) due to a lack of staff and money.

Then hidden programs will be created by some people having (at least some) coding experience (or by cheap students/interns...). Under some circumstances these applications will raise in importance and spread from one user to a whole department.

Then there is the critical point: Who will maintain the application, add new features, ...? And this app is critical. It IS needed. But the intern has left the company. No one knows how it works. You only have a bunch of sources and some sort of documentation.

Does it make sense to try and control or forbid application development done ad-hoc outside of the IT department (with the exception of minor stuff like Excel macros)?

答:
If there is a problem here it is with the IT department.

There is nothing wrong with allowing people with specialist business/domain knowledge manipulating and processing there own data.

The IT department needs to acknowledge this and support it. By providing re-usable interfaces, delivering data in convenient formats like EXCEL or Access DBs, and providing flexible tooling (COGNOS, Jasper Reports etc.).

The IT department also needs to re-think its priorities -- it is there to serve the business, not to implement the latest methodology, or, install the sexiest hardware.


问:
How to access an encrypted INI file from C on an embedded system with little RAM
I want to encrypt an INI file using a Delphi program on a Windows PC.

Then I need to decrypt & access it in C on an embedded system with little RAM.

I will do that once & fetch all info; I will not be continuously accessing the INI file whenever my program needs data from the file.

Any advice as to which encryption to use? Nothing too heavyweight, just good enough for "Security through obscurity" and FOSS for both Delphi & C.

And how can I decrypt, get all the info from the INI file - using as little RAM as possible, and then free any allocated RAM?

[Update] I am currently using an Atmel UC3, although I am not sure if that will be the final case. It has 512kB flash & 128kB RAM.  For an INI file, I am talking of max 8 sections, with a total of max 256 entries, each max 8 chars.

I chose INI (but am not married to it), because i have had major problems in the past when the format of a data file changes, no matter whether binary, or text.

For text, I prefer the free format of INI (on PC), but suppose I could switch to line_1=data_1, line_2=data_2 and accept that if I add new fields in future software releases they must come at the end, even if it is not pretty when read directly by humans.

I suppose if I choose a fixed format text file then I never need get more than one line into RAM at a time ...

[Verdict] I will go with either TEA or AES (tbd). I will split the functionality into two parts: 1) decrypt into a plain text file, 2) parse that as an INI file and if I hit memory problems then change to a line_1=data_1, line_2=data_2 format.

Thanks for your help.

答:
How about something like RC4/
ARCFOUR?

On the PC  - encrypting should be trivial - pick a good key...

On the device read, decrypt, store in a tree.... assuming they can't easily observe your memory.

ContentLicense: CC BY-SA 4.0


问:
How do you use blank lines in your code?
There has been a few remarks about white space already in discussion about curly braces placements.

I myself tend to sprinkle my code with blank lines in an attempt to segregate things that go together in "logical" groups and hopefully make it easier for the next person to come by to read the code I just produced.

In fact, I would say I structure my code like I write: I make paragraphs, no longer than a few lines (definitely shorter than 10), and try to make each paragraph self-contained.

For example:

in a class, I will group methods that go together, while separating them by a blank line from the next group.

if I need to write a comment I'll usually put a blank line before the comment

in a method, I make one paragraph per step of the process

All in all, I rarely have more than 4/5 lines clustered together, meaning a very sparse code.

I don't consider all this white space a waste because I actually use it to structure the code (as I use the indentation in fact), and therefore I feel it worth the screen estate it takes.

For example:

```<code>for (int i = 0; i < 10; ++i)
{
    if (i % 3 == 0) continue;

    array[i] += 2;
}
</code>```

I consider than the two statements have clear distinct purposes and thus deserve to be separated to make it obvious.

So, how do you actually use (or not) blank lines in code ?

答:
A Professor Emeritus Gave Two Great Pieces of Advice

Whitespace is Free

Don't use the staples that poke back up through the front of the paper, or I'll fail you.


答:
Tutorials for Beginners

There are great tutorials (video and text) that can help you start from a very basic level.  Git seems to have a great approach to introducing the topic in a gentle way for beginners that tells you the why first and uses repetition, definition, and graphics to help you remember the names and functions of key commands.

SVN

SVN intended to be CVS done better.  CVS (concurrent Version System) worked on things a file at a time, SVN typically worked on things a directory or directory tree at a time.  SVN (and CVS or other systems) may be important if you are using it at work, but my opinion is that we significantly improve our understanding of what it takes to do source control every few years, so just as you would prefer a late model computer, you should prefer a late model source control tool.  It is a huge investment to change systems, and code history can be lost, although for many systems there are converters that let you migrate your code as well as history and other artifacts created by the system being retired.

Professional Source Control Meets Professional Needs

Your question "How do professional use tools like GIT and Subversion to fulfill their project's needs?" closely relates to the question "How do teams work together without getting in each others way while still working as quickly as possible?"

The code is changing frequently with some developers making code that other developers will use, and with a variety of stakeholders needing differing levels of stability vs. innovation.  Source control systems help by storing code for use by the team, keeping each change in context with versions that change with time and often also with branches that are controlled copies of the code that serve to isolate groups of changes from other groups of changes.

Bringing things back together, merging the work of many team members is a chore that in SVN and older systems was centralized and difficult.  For teams using Git, merging becomes simpler and more accessible to the influence of the whole team instead of a few experts.  In SVN, branching could be a personal matter, but merging often had painful impacts on the team and the movement of code back into the main line could be painful from the perspective of getting permission, avoiding breakage, and the level of effort needed the task.

From an established source control repository, professionals can fulfill other needs like diagnosing problems to their root cause.  If there were versions of the code that used to work, and newly found problems that occur in the current version, it is possible to step forward and backward across the history to pin-point when the problem occurred.  In SVN, this capability is immature, but in Git the search for the last working / first failing version is supported by a command called git bisect.  The problem will be caused by one of the source changes between the two versions which is potentially a much easier diagnosis than a search of the entire code base.

Sorry to ramble, hope this helps you on your way toward using source control.


答:
My team uses a home-grown team version control system.  (Sadly, Git does not seem to work yet on IBM i "native" source files) But personally, once I have pulled source from that system, I use Git during my development, until the project is done and I check it back into the team VCS.

As they say in voting... commit early, commit often.  As I work on new features, I commit.  I commit between compiles, and at each attempt to correct compiler errors, each time I make changes during testing and debugging.  This enables makes it simpler to try several variations on a theme and so easily back out of it if needed, especially when a change is coordinated across several files.

Git has improved the way I approach development.


答:
Have a look at TEA

( By "little RAM" I have assumed something like 1-10K in something like a PIC )

As for how to read the INI file Text based and especially INI is not the correct format to use for a resource (particularly memory) constrained embedded system. As you are using encryption, it's not like you need to stick to some open, widely used human readable standard for the data storage.

The PC using to encrypt the files has (to all practical purposes) infinite resource and can preform infinitely complex processing in no time all all compared to the embedded system. Therefore you should offload as much work to the PC as possible, and minimize the work the embedded system has to do.

In your case, I would write a binary file in the format required by the embedded system (trivial in Delphi). Once the software was working, the encryption layer can be added and tested. If needed, this could be a separate application that takes an INI file in and outputs a binary representation for the embedded device.

If you must use an INI file, the easiest way is to read the entire file into memory, decrypting and processing the stream as you go.  As you have not defined what kind of data and how much the ini will store - so it's impossible to suggest an optimized  strategy.

Title: How to access an encrypted INI file from C on an embedded system with little RAM

Body:
I want to encrypt an INI file using a Delphi program on a Windows PC.

Then I need to decrypt & access it in C on an embedded system with little RAM.

I will do that once & fetch all info; I will not be continuously accessing the INI file whenever my program needs data from the file.

Any advice as to which encryption to use? Nothing too heavyweight, just good enough for "Security through obscurity" and FOSS for both Delphi & C.

And how can I decrypt, get all the info from the INI file - using as little RAM as possible, and then free any allocated RAM?

[Update] I am currently using an Atmel UC3, although I am not sure if that will be the final case. It has 512kB flash & 128kB RAM.  For an INI file, I am talking of max 8 sections, with a total of max 256 entries, each max 8 chars.

I chose INI (but am not married to it), because i have had major problems in the past when the format of a data file changes, no matter whether binary, or text.

For text, I prefer the free format of INI (on PC), but suppose I could switch to line_1=data_1, line_2=data_2 and accept that if I add new fields in future software releases they must come at the end, even if it is not pretty when read directly by humans.

I suppose if I choose a fixed format text file then I never need get more than one line into RAM at a time ...

[Verdict] I will go with either TEA or AES (tbd). I will split the functionality into two parts: 1) decrypt into a plain text file, 2) parse that as an INI file and if I hit memory problems then change to a line_1=data_1, line_2=data_2 format.

Thanks for your help.


问:
What is the difference between development and R&D?
I was asked by a colleague to explain clearly the difference between ordinary development and research and development (R&D) and was unable to do it. After reading Wikipedia, I still don't have the precise answer.

According to Wikipedia (slightly modified):

There are two primary models:

In one model, the primary function is to develop new products;

in the other model, the primary function is to discover and create new knowledge about scientific and technological topics for the purpose of uncovering and enabling development of valuable new products, processes, and services.

The first model is confusing. Does it mean that development (not R&D) consists exclusively in adding new features to a product, solving bugs and doing maintenance? What if something which was previously developed as a new feature becomes a separate product?

The second model is less confusing, but still, how to qualify whether something is new knowledge or existent knowledge which is just rediscovered?

Later, Wikipedia adds that ordinary development is different from R&D because of its:

nearly immediate profit or immediate improvement.

It's still not clear enough. How to qualify "nearly immediate profit"? What if a task has an immediate profit but requires heavy research? Or if it is basic but has uncertain profit, like the enforcement of a common style over the codebase?

For example, does it belong to development or R&D to:

Develop an engine which abstracts the access to the database, simplifying and shortening enormously the code of other applications (existent or ones which will be written in future) which should access to the database?

Establish a new service-oriented architecture for the entire organization of company resources, in order to move from a bunch of separate and autonomous applications to a set of well-organized, interconnected web services, like what is used by Amazon?

Design a new communication protocol to allow faster replication of data between two data centers of the company?

Conceive a new type of software testing while working on a specific product, knowing that this type of testing will improve/simplify the testing process?

Prove that Functional programming is more appropriate than OOP for a specific application, based on evidence, logic and previous experience?

Enhance the existent application by adding gestures on tactile screens, after doing studies and testing that shows that those gestures improve the productivity of the users by a ratio of at least 1.4 for a precise set of tasks?

Find a way to strongly enhance the Power usage effectiveness (PUE) of a data center?

Create a Domain-Specific Language (DSL)?

In short, how could I determine whether I'm doing R&D while working on something?

答:
Informally, the way I would define it (and how I've generally seen it used in practice) is something like:

The phrase R&D is used to signify that you are unsure about the exact approach to achieve something, and / or if it can even be done, and how well it will work.

(EDIT: rephrased slightly)

Basically, it's a quick, common way of saying that there's a significant unknown ahead.  Attempting to answer your actual question then, it really depends on who is doing the classification; many of those items seem like they include a significant research component, but I guess there are some individuals who would be able to achieve many of them without any research whatsoever.  It depends on both the task, and the individual.

Looking at the actual list, I personally would classify those based on whether I've done something similar enough in the past, and would therefore be highly confident in what I'm about to do (or at least, be able to give good ballpark estimates).