问:
How to manage the task of reviewing localized strings by a non-developer?
In .NET Framework, localized strings are located in an XML file (or multiple files). Those files are part of the project and are committed to the source control as any other source code file. Usually, Visual Studio is used to display those files as a table and edit the localized strings.

I work in a small team on a product which should have a multilingual interface.

As a developer, I draft the localized strings in both languages, given that the translation may be inexact,

Another person from the team (a non-developer) reviews the content in both languages and corrects it if needed.

The current issue is that the non-developer person would not use neither source control, nor an IDE, since it would be too cumbersome and difficult (version control is difficult for non-developers) for this person.

An alternative solution would be for me to export the localized strings as an Excel file, wait for this person to review the Excel, then to re-import the modified strings. The caveat here is that I may be creating other strings, renaming existing ones, etc., making it difficult to diff the local version with the reviewed one.

What to do?

How does it happen in other teams?

答:
Editing XML sucks. Visual Studio has a view you can use to edit resources:

I think that check-out-on-edit combined with a minute of demonstrating the "pending changes" window should enable your non-developer to use as much source control as they need to.

OwnerDisplayName: MainMa


问:
Should extension scripts be run in a sandbox?
In particular, this is about game extensions written in lua (luajit-2.0). I was contemplating whether I should restrict what these scripts can do, and arrived at the conclusion that I probably shouldn't:

It's hard to get right. Sounds silly, but chances are my sandbox is gonna end up leaky anyways.

The only benefit I could think of would be giving users some sense of security when running third party scripts.

The disadvantages would be that it's just incredibly annoying for extension writers. That is, for now, myself (game content will be mostly scripted).

The reason I'm asking this now before I actually have anything presentable is that adding a sandbox early on is easy, but would impose said annoying restrictions on myself too. However if I first go on with it and then later decide I do need a sandbox after all, I'm gonna run into problems (I'd either have to rewrite the scripts that are already there, or introduce some form of trust management system which seems to be more trouble than it's worth).

答:
I believe that both the development of a videogame, which in any software development of a medium-large dimensions, the programmer will always try to create a layer exchange or free-set options for future functionality.

Lua is a language that allows these options are easy to implement for the end user, and for the developer, but that does not mean it is easy to plan your workspace, with experience I can tell you today, also a simple multiplication can leak, if the end user is allowed to customize their behavior.

If we focus on what a sandbox game has to offer, we can bequeath to understand that the end use can be a double-blade, allowing the game to become non-linear, interesting and fun, but at the same time not be easy plan their limits in the work area.

From a security standpoint, it sounds fantastic! a good test environment for extensions,  should be implemented in all types of software.

In conclusion, I can say that although it seems that not worth making
  a sandbox for your product, actually the developer or group of
  developers will get more benefits, because as the end user can easily
  configure your environment at the developer may also less time to make
  changes to the functional structure. I am firmly convinced that a
  sandbox game, (as in the software scalability), allows a creative
  evolution of their extensions and a natural evolution of its
  functionalities.

ContentLicense: CC BY-SA 3.0


答:
I would look into finding an XML editor* for the non-developer to use.

You'll then need to provide versioned extracts to the non-developer for review.

Once they're done with the review, you can check the file back in.

When you have made changes, you'll simply need to diff the XML files prior to check-in and send the updated-by-you sections to the non-dev for review.  Your updates are why why you need to keep the the review files versioned.

Trying to use Excel will make things exceedingly difficult since the diff tools for excel leave a lot to be desired.  You also run the risk of additional comments creeping into the extra cells within the spreadsheet.  Those comments would require additional handling upon your part in order to merge them back in.

In a previous life, we used a fairly similar process for a number of translations by external organizations.  Our files were essentially text files with a similar but different form than XML.  And we had tons of changes going on while files were out for review, so I appreciate the fun of your situation.

* I've used xml notepad and it's tolerable, I would suspect there are better ones out there

Title: How to manage the task of reviewing localized strings by a non-developer?

Body:
In .NET Framework, localized strings are located in an XML file (or multiple files). Those files are part of the project and are committed to the source control as any other source code file. Usually, Visual Studio is used to display those files as a table and edit the localized strings.

I work in a small team on a product which should have a multilingual interface.

As a developer, I draft the localized strings in both languages, given that the translation may be inexact,

Another person from the team (a non-developer) reviews the content in both languages and corrects it if needed.

The current issue is that the non-developer person would not use neither source control, nor an IDE, since it would be too cumbersome and difficult (version control is difficult for non-developers) for this person.

An alternative solution would be for me to export the localized strings as an Excel file, wait for this person to review the Excel, then to re-import the modified strings. The caveat here is that I may be creating other strings, renaming existing ones, etc., making it difficult to diff the local version with the reviewed one.

What to do?

How does it happen in other teams?


答:
How do you know you got all the strings and that they're formatted correctly in the app? How do you know that numbers, currency, timezone and other locale info is formatted correctly? That everything is loaded and multibyte serialization works properly?

No. Localization is a feature like any other. Check it in. Make a build. Let the tester get the build and verify the feature is done properly like any other. When you make a new build, you get to do regression testing on the localization - just like any other feature.


问:
(Dis)advantages of datetime vs. long in globally used applications
I am currently designing a web/mobile application the bulk of whose users will be distributed across the different U.S. time zones with a potential of scaling up to other countries and time zones as well

I have worked with several other globally used apps and noticed they all used datetime to record timestamps with the default time zone being that in which the application is typically hosted.  In displaying the times, they would typically do not care about the user preference (locale) and simply display the timestamp with the TZ and leave it up to the user to convert if (s)he wishes.

I am entertaining the idea of shifting away from that paradigm and recording timestamps as one global time (GMT) in long milis regardless of the user location and collecting the user locale by their IP or letting them change their TZ as a preference in their profile, which would later be used for display formatting of all their GMT long milis.  This seems like a simpler solution than confusing the app design with TZs.

I am curious to hear feedback of pros and cons to this approach.  I am also curious to hear some explanations why the, IMO overcomplicated time zoned datetime data type has ever been used across databases and not a uniform single time zone with conversions just for display.

答:
There are a lot of intricacies in converting between time zones, especially when you consider daylight saving time and the fistful that aren't even increments of one hour.  If you're using a database that has robust TIMESTAMP support, switching to integer storage would lose you access to the wealth of available operations.  That may seem like the expedient thing to do, but having to re-implement all of the conversions in your own code is redundant and error-prone.  Why reinvent an already well-proven wheel?

SQL92 defines an AT TIME ZONE clause that lets you recast a time in one time zone to another (PostgreSQL example):

```<code>-- Grab a value in one time zone and convert it to another
SELECT TIMESTAMP WITH TIME ZONE '2013-01-03 12:34:56 EST' AT TIME ZONE 'MST';

-- Store it as the user provided it, in his preferred time zone
INSERT into bar (foo) VALUES ('2013-01-03 12:34:56 EST');

-- Retrieve it in its original form
SELECT foo FROM bar WHERE ... ;

-- Retrieve it in the time zone some other user prefers
SELECT foo AT TIMEZONE 'PST' FROM bar WHERE ... ;
</code>```

Several databases, Oracle and PostgreSQL among them, implement this.

I am also curious to hear some explanations why the, IMO
  overcomplicated time zoned datetime data type has ever been used
  across databases and not a uniform single time zone with conversions
  just for display.

There's nothing complicated about it; the zoned types just store more information.  Sometimes it's important to know the time zone in which an event occurred, and converting to a single time zone irrevocably obliterates that information.  If you're doing a marketing promotion and want to know which customers placed orders around lunchtime, an order that appears to have been placed at noon GMT isn't very helpful when it was actually placed over breakfast in New York.  To get all of that sorted out, you're going to have to reinvent the aforementioned wheels, which your database may have already done for you.

Body:
There are a lot of intricacies in converting between time zones, especially when you consider daylight saving time and the fistful that aren't even increments of one hour.  If you're using a database that has robust TIMESTAMP support, switching to integer storage would lose you access to the wealth of available operations.  That may seem like the expedient thing to do, but having to re-implement all of the conversions in your own code is redundant and error-prone.  Why reinvent an already well-proven wheel?

SQL92 defines an AT TIME ZONE clause that lets you recast a time in one time zone to another (PostgreSQL example):

-- Grab a value in one time zone and convert it to another
SELECT TIMESTAMP WITH TIME ZONE '2013-01-03 12:34:56 EST' AT TIME ZONE 'MST';

-- Store it as the user provided it, in his preferred time zone
INSERT into bar (foo) VALUES ('2013-01-03 12:34:56 EST');

-- Retrieve it in its original form
SELECT foo FROM bar WHERE ... ;

-- Retrieve it in the time zone some other user prefers
SELECT foo AT TIMEZONE 'PST' FROM bar WHERE ... ;

Several databases, Oracle and PostgreSQL among them, implement this.

I am also curious to hear some explanations why the, IMO
  overcomplicated time zoned datetime data type has ever been used
  across databases and not a uniform single time zone with conversions
  just for display.

There's nothing complicated about it; the zoned types just store more information.  Sometimes it's important to know the time zone in which an event occurred, and converting to a single time zone irrevocably obliterates that information.  If you're doing a marketing promotion and want to know which customers placed orders around lunchtime, an order that appears to have been placed at noon GMT isn't very helpful when it was actually placed over breakfast in New York.  To get all of that sorted out, you're going to have to reinvent the aforementioned wheels, which your database may have already done for you.


问:
Many Blocking VS Single Non-Blocking Workers
Assume there is an HTTP server which accepts connections and then it has somehow wait for headers to be fully sent in. I wonder what is the most common way of implementing it and what are the rest pros and cons. I can only think of these:

Many blocking workers are good because:

It is more responsive.

Easier to introduce new connections (workers pick them up them selves rather than outsider waiting till it can add it to a synchronized list).

CPU usage balances automatically (without any additional effort) as number of connections increases and decreases.

Less CPU usage (blocked threads are taken out of the execution loop and do not require any logic for jumping between clients).

Single non-blocking worker is good because:

Uses less memory.

Less vulnerable to lazy clients (which connect to the server and send headers slowly or don't send at all).

As you probably can see, in my opinion multiple worker-threads seem a bit better solution overall. The only problem with it is that it is easier to attack such server.

Edit (more research):
Some resource I found on the web (Thousands of Threads and Blocking I/O
- The old way to write Java Servers is New again (and way better) by Paul Tyma) hints that blocking approach is generally better but I still don't really know how to deal with fake connections.

P.S. Do not suggest using some library or applications for the task. I am more interested in knowing how it actually works or may work rather than have it working.

P.S.S. I have split logic into multiple parts and this one only handles accepting HTTP headers. Does not process them.

答:
There's no silver bullet

In practice it depends...

tl;dr - easy solution, use nginx...

Blocking:

For instance, Apache by default uses a blocking scheme where the process is forked for every connection. That means every connection needs its own memory space and the sheer amount of context-switching overhead increases more as the number of connections increases. But the benefit is, once a connection is closed the context can be disposed and any/all memory can be easily retrieved.

A multi-threaded approach would be similar in that the overhead of context switching increases with the number of connections but may be more memory efficient in a shared context. The problem with such an approach is it's difficult to manage shared memory in a manner that's safe. The approaches to overcome memory synchronization problems often include their own overhead, for instance locking may freeze the main thread on CPU-intensive loads, and using immutable types adds a lot of unnecessary copying of data.

AFAIK, using a multi-process approach on a blocking HTTP server is generally preferred because it's safer/simpler to manage/recovery memory in a manner that's safe. Garbage collection becomes a non-issue when recovering memory is as simple as stopping a process. For long-running processes (ie a daemon) that characteristic is especially important.

While context-switching overhead may seem insignificant with a small number of workers, the disadvantages become more relevant as the load scales up to hundreds-to-thousands of concurrent connections. At best, context switching scales O(n) to the number of workers present but in practice it's most-likely worse.

Where servers that use blocking may not be the ideal choice for IO heavy loads, they are ideal for CPU-intensive work and message passing is kept to a minumum.

Non-Blocking:

Non-blocking would be something like Node.js or nginx. These are especially known for scaling to a much larger number of connections per node under IO-intensive load. Basically, once people hit the upper limit of what thread/process-based servers could handle they started to explore alternative options. This is otherwise known as the C10K problem (ie the ability to handle 10,000 concurrent connections).

Non-blocking async servers generally shares a lot of characteristics with a multi-threaded-with-locking approach in that you have to be careful to avoid CPU-intensive loads because you don't want to overload the main thread. The advantage is that the overhead incurred by context switching is essentially eliminated and with only one context message passing becomes a non-issue.

While it may not work for many networking protocols, HTTPs stateless nature works especially well for non-blocking architectures. By using the combination of a reverse-proxy and multiple non-blocking HTTP servers it's possible to identify and route around the nodes experiencing heavy load.

Even on a server that only has one node, it's very common for the setup to include one server per processor core to maximize throughput.

Both:

The 'ideal' use case would be a combination of both. A reverse proxy at the front dedicated to routing requests at the top, then a mix of blocking and non-blocking servers. Non-blocking for IO tasks like serving static content, cache content, html content. Blocking for CPU-heavy tasks like encoding images/video, streaming content, number crunching, database writes, etc.

In your case:

If you're just checking headers but not actually processing the requests, what you're essentially describing is a reverse proxy. In such a case I'd definitely go with an async approach.

I'd suggest checking out the documentation for the nginx built-in reverse proxy.

Aside:

I read the write-up from the link you provided and it makes sense that async was a poor choice for their particular implementation. The issue can be summed up in one statement.

Found that when switching between clients, the code for saving and restoring values/state was difficult

They were building a state-ful platform. In such a case, an async approach would mean that you'd have to constantly save/load the state every time the context switches (ie when an event fires). In addition, on the SMTP side they're doing a lot of CPU-intensive work.

It sounds like they had a pretty poor grasp of async and, as a result, made a lot of bad assumptions.


问:
How can I profile database queries from PHP?
CodeIgniter has a very nice feature called a Profiler, which displays information at the foot of a page, information such as GET, Memory, POST data. It also shows database queries and how long they took to run which I find very useful.

I have recently taken over a legacy PHP application and it would help a lot to see what tables in the database are being queried by PHP pages. Is there a library for raw PHP applications that could produce something similar to CodeIgniter's Profiler? I am already using xdebug, I am only interested in profiling database queries.

答:
CI's profiler is a nifty little class that assembles data from CI's database class and CI's controller class and gives you a pretty thorough view of what's going on. Unfortunately it's not going to work in isolation, it's tightly coupled with the rest of the framework, and afaik there isn't a simple alternative that you could plug in into a legacy application.

Since you are mainly interested in profiling database queries and assuming you are using MySQL, you should check out the General Query Log:

The general query log is a general record of what mysqld is doing. The server writes information to this log when clients connect or disconnect, and it logs each SQL statement received from clients. The general query log can be very useful when you suspect an error in a client and want to know exactly what the client sent to mysqld.

mysqld writes statements to the query log in the order that it receives them, which might differ from the order in which they are executed. This logging order contrasts to the binary log, for which statements are written after they are executed but before any locks are released. (Also, the query log contains all statements, whereas the binary log does not contain statements that only select data.)

From MySQL 5.1.6 you can store the log in a MySQL table, thus the logs are extremely easy to query and present.

PostgreSQL has a similar mechanism that's also quite easy to setup (PostgreSQL manual > 18.8. Error Reporting and Logging). If you are using PostgreSQL, you should check out pgFouine, a log analyzer written in PHP. I'd imagine every other major RDBMS provides similar logging mechanisms.

The query log will give you all the information you'll need for your database queries, and it's quite easy to hack together a simple script to prettify the reports. If you're interested in profiling HTTP requests as well, then you should look at Apache's logs (or your favourite web server's logs). For log analyzers, you should check out AWStats, apache-scalp and PHPIDS.


问:
Rails - Does using partials slow views rendering?
I'm having performance issues on a Rails 3.1.0 application, now I've done dome changes on my queries with AR and so but views still takes too many time to render, I've divided the views, loops and so, on many partials that are rendered dynamically inside views and inside other partials.

So it's a bad practice to have a large number of partials?

Should I reduce the number of partials to improve the views rendering time?

Thanks

答:
I disagree with both answers.  I have copied and pasted the code from a partial into the position that it is present in the parent view partial and with 500 iterations, this takes a huge 600ms off the time take to render the view.  <%= render xyz %> is in my opinion very broken.

Example, total time to render view:

```<code>Before:
5759.8ms
5804.2ms
5973.6ms

After:
5268.7ms
5201.6ms
5222.4ms

Diff = 5846 - 5231 = 615 ms
</code>```

Edited

I ended up unDRYing all _partials within the _model partial and got it down to ~2000ms, at which point I tried moving the _model partial into the index however this did NOT have any affect on rendering times so I guess it's with calls to nested render that does it.

Body:
I disagree with both answers.  I have copied and pasted the code from a partial into the position that it is present in the parent view partial and with 500 iterations, this takes a huge 600ms off the time take to render the view.  <%= render xyz %> is in my opinion very broken.

Example, total time to render view:

Before:
5759.8ms
5804.2ms
5973.6ms

After:
5268.7ms
5201.6ms
5222.4ms

Diff = 5846 - 5231 = 615 ms

Edited

I ended up unDRYing all _partials within the _model partial and got it down to ~2000ms, at which point I tried moving the _model partial into the index however this did NOT have any affect on rendering times so I guess it's with calls to nested render that does it.


问:
Web development advice for a distributed development team
I am a web developer. Worked in many projects. Now I have changed my work place. It is big organisation. I and my group are thinking about new project. There is no difficulty to write project but our organisation is big and it's has little offices in many places (within the country). There is no any problem about internet in center. But there is problem with internet in remote areas sometimes.

My question is: is there any solution to solve problem as it? If anybody has create project such this please tell little about what technologies you have used.

Thanks

答:
I would decide upon a 'central' site by which major decisions are made regarding the project (although that doesn't mean other offices can't make decisions).  At that site, host a SVN server and have all other offices commit code to that server in order to have a consist progression of development.

It would help to find some sort of medium by which you can talk easily with other programmers such as yahoo or windows live.  Email is okay, but you tend to lack the response times you could get otherwise with chat programs.

I hope that's what you meant by internet troubles.  Otherwise you're going to have to be more clear with your question.

ContentLicense: CC BY-SA 2.5


问:
How to obtain GPS Coordinates for local businesses?
Is anybody aware of a database that consists of businesses, addresses and GPS location information, preferably searchable by city at a minimum?  I have an application in mind that I'd like to develop and would like to know if someone is doing this for free or cheap in possibly a web service or similar open format.  </p>

答:
If you are thinking of building some sort of directory service where you need large amounts of geocoded addresses (like the 15 million or so business in the United States) you are going to have to pay and pay a lot.

If you are looking at something on the fly, like you have the business name already in hand and just need the co-ordinates to go with it, the look at Google geocoding service.

The geocoding service has a limit on the number of requests that you can do for free as well as a rate limit, so you can't batch fill you database very easily, but you can do them on the fly.  I recommend that once you have an address geocoded, you store it to cut down on lag for the request and the limit on the number of requests you can make.

As for buying data, that has traditionally been at least a six figure number and there are a number of vendors around that provide that data, with varying levels of quality.

As for IP address geocoding, that is supported by google and a few others as well, but is not as accurate as private, fee based, services.


答:
One option is to create a helper application where the translator can see the list of strings in one pane and enter the language specific in another.  This way the data is stored back to the XML and then you can have that application export the file.

If you process the keys into a database and store each languages there, it would allow for changes to be integrated and the translator to see what needs updated.  Then you can just export to the language specific XML file which you put back into version control or the translator could.

We use a similar method to this with our Rails code, we never edit or even provide the language specific files, they are all maintained and then exported by the external application our translation team uses.  Sorry I don't know if their software is custom or off the shelf, but it shouldn't be that hard to put something simple together.


问:
What can a company do to restrict offsite contract developers from redistributing GPLv2-licensed code modifications?
My company uses a mix of onsite and increasingly offsite contractors for development of websites and online applications.

Our platform uses a mix of open source software and libraries that we've made a number of modifications to over the years.  Some of the modified software is licensed GPLv2 without the linking exception.  For various reasons, we do not want the source to be made public.

The concern is that if we supply the binaries to our platform for our offsite developers, we are obligated to supply the source code upon request.  Additionally, there will be times when we need to distribute the source of our modified libraries.  From there, nothing would seem to preclude the contractor from redistributing the work.

The GPL FAQ states:

. . . when the organization transfers copies to other organizations or individuals, that is distribution. In particular, providing copies to contractors for use off-site is distribution.

Furthermore, the GPL states:

You may not impose any further restrictions on the recipients' exercise of the rights granted herein.

The question is: what can be done to restrict offsite contractors from redistributing our modified code?

A note, that I think the GPLv3 addresses this concern with the following clause.  So my question is specifically about GPLv2-licensed modified code:

You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright.

答:
I am by no means an expert on licensing, but to the best of my knowledge:

You can't do anything. If you distribute modifications - in any form - source code must be made available, under the same license. That's kind of the thing with the GPL licenses - the source can't become proprietary.

What is allowed under the GPL is making modifications for personal use and keeping them to yourself. The clause you're quoting from GPLv3 means that you can also have someone else make modifications - as long as you are the only one using them. Otherwise you would have to make the source available to the public.

Again: I am not a lawyer. You should talk to one.


问:
UML modeling tool for Linux
I am starting a new project using Eclipse under Linux and I am looking for a UML 2.x modeling tool not just a diagramming tool.

Do anyone has experience with UML plugin for Eclipse? Does it support all UML diagrams?

Do you recommend another modeling tool?

If you have been in a similar situation, what did you end up doing anyway?

答:
I vote for UMLet

Unlike Umbrello, doesn't keep crashing (on Linux/gnome)

Unlike Dia it draws itself so I'm not wasting my time trying to keep objects attached to each other.

It's free.

It's self-documenting so I was able to start using it immediately.

Title: UML modeling tool for Linux


问:
Expensive AOT Optimizations
I've seen it stated several times that AOT can run some more expensive optimizations that take too long to be used by a JIT. But I've never seen it stated what exactly these optimizations are. So I'm wondering, what are these optimizations?  </p>

答:
Register allocation comes to mind.

According to wikipedia:

Graph coloring allocators produce efficient code, but their allocation
  time is high. In cases of static compilation, allocation time is not a
  significant concern. In cases of dynamic compilation, such as
  just-in-time (JIT) compilers, fast register allocation is important.
  An efficient technique proposed by Poletto and Sarkar is linear scan
  allocation. This technique requires only a single pass over the list
  of variable live ranges. Ranges with short lifetimes are assigned to
  registers, whereas those with long lifetimes tend to be spilled, or
  reside in memory. The results are on average only 12% less efficient
  than graph coloring allocators.

Also, I recently came across a stackoverflow question about an optimization that the JIT compiler doesn't do. Not sure if compile times are the reason, but it might still be worth checking.

Title: Expensive AOT Optimizations


答:
In all seriousness, get an attorney experienced in these matters.

It seems to me that your contractors are working on your behalf, accessing your software, and this is not "distribution" (in a common sense standpoint).

I would ensure that the contract with your contractors is a work for hire, causing you to own their work on your behalf (like an employee).  If this is not the case, you don't likely own the copyright to their modifications anyway.

Common sense would dictate that an appropriate work for hire contract whereby they are working on your software on your behalf and not for their own use -- it would not conflict with GPL.

Title: What can a company do to restrict offsite contract developers from redistributing GPLv2-licensed code modifications?

Body:
My company uses a mix of onsite and increasingly offsite contractors for development of websites and online applications.

Our platform uses a mix of open source software and libraries that we've made a number of modifications to over the years.  Some of the modified software is licensed GPLv2 without the linking exception.  For various reasons, we do not want the source to be made public.

The concern is that if we supply the binaries to our platform for our offsite developers, we are obligated to supply the source code upon request.  Additionally, there will be times when we need to distribute the source of our modified libraries.  From there, nothing would seem to preclude the contractor from redistributing the work.

The GPL FAQ states:

. . . when the organization transfers copies to other organizations or individuals, that is distribution. In particular, providing copies to contractors for use off-site is distribution.

Furthermore, the GPL states:

You may not impose any further restrictions on the recipients' exercise of the rights granted herein.

The question is: what can be done to restrict offsite contractors from redistributing our modified code?

A note, that I think the GPLv3 addresses this concern with the following clause.  So my question is specifically about GPLv2-licensed modified code:

You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright.


问:
Is it common to use partial classes to achieve 'modularity'?
I recently encountered a situation in our codebase where a different team created a 'god class' containing around 800 methods, split across 135 files as a partial class.

I asked the other team about this.  While my gut reaction was to nuke it from orbit, they insist that it's a good design, a common practice, and that it promotes 'modularity' and 'ease of implementation' because new developers can bolt on functionality with almost no knowledge of the rest of the system.

Is this actually a common practice or in any way a good idea?  I'm inclined to take immediate steps to bring this beast down (or at least prevent it from growing further) but I'm willing to believe I'm wrong.

答:
So the question was:

Is this actually a common practice or in any way a good idea?

Among the currently available answers is a resounding no. So there is few other things I could chime in about it such as; even procedural code can be made modular and including everything but the kitchen sink is not how you achieve modularity. Which one giant class split into partials does do, it all adds up into one big mess.

However that question is a red herring to the real critical part what has been missed; as the OP also has the following to say about the situation:

(...) While my gut reaction was to nuke it from orbit, they insist...

(...) I'm inclined to take immediate steps to bring this beast down (or at least prevent it from growing further) but I'm willing to believe I'm wrong.

HOLD YOUR HORSES!

This here is something that would make my figuratively speaking monocle drop into my figurative cup of tea.

I've been in similar situations and let me do tell you: DON'T fall for the urges to do so. Sure, you can drop the Nuke Hammer of Justice on the team but before you do so please humour yourself with the following bit of conundrum:

What will happen if you tell the team that their code sucks and to sod off?

(...or something like that but less offensively, it doesn't really matter because they will be offended regardless what you do if you decide to go full force on them)

What is the current situation with the code base? Is it working? Then you'll have big problems explaining to their clients that their code essentially sucks. No matter what reasons they have: as long as it is working, most clients don't care about how the code is organized.

Also put yourself in their shoes, what would they do? Let me amuse you with the following very possible outcome:

Team Member #1: "So there is this guy telling us that we've been doing it wrong for the past years."

Team Member #2 and #3: "What a jerk."

Influential Team Member #4: "Don't worry about it, I'll just go to the management and report it as a harrasment."

See what Influential Team Member #4 did there? He went to the management and reduced your karma in the company. He might be American-Italian, telling everyone to not worry about it, but then I'd be racist about it.

Painting the offending team into a corner with letting them admit that they did it wrong for so long is also a bad idea and lead to the same thing. You'll lose respect and some office politics karma.

Even if you managed to get a bunch of people to sign off on this, in order to "teach the team a lesson", remember that you're doing this to fairly smart people who apparently get some things done. Once the code will be rewritten/refactored/dealt/whatever'd with and problems arise that you will be held accountable as you were the firestarter.

Being adversarial about situations like this is mostly a lose/lose game as it risks to become a vicious circle of blame games. This is a suboptimal outcome for this situation. Even if you win, you're suddenly handed over the mess that someone else did.

There are Other (Much Mature) Ways

I was in a similar situation once, but then I took an arrow in the knee. So after a while with that sudden career altering arrow in my mind I got a book Driving Technical Change by Terrence Ryan. It lists several patterns of skeptics, the kind of people don't act on good ideas. They are all most likely applicable in the OP's case:

The Uninformed - They genuinely did not know there are other ways or simply didn't understand. Junior developers usually fit this category but not necessarily. (To be honest: I've met junior developers that would be more brighter than this.)

The Herd - They knew better techniques than using partial classes but didn't know that they were allowed.

The Cynic - They just like to argue that having partial classes is better than your idea just for the sake of arguing. It's easy to do that in a crowd instead of standing in front of a crowd.

The Burned - For some odd reason they don't like to create new classes, most likely they perceive it as too difficult.

The Time Crunched - They're so busy that they can't bother to fix their code.

The Boss - They think: "Well it works; so why bother?"

The Irrational - Ok, they're just completely crazy.

The book goes on with a list of strategies and so on, but in the OP's case it's a matter of persuasion. Going head strong with facts on the anti-pattern is not enough.

If it is in your interest to increase code quality, at least give the offending team chances to reiterate and rectify their own mess. Personally I would try to sway them by listening and asking leading questions, let them tell their story:

What exactly is their god class doing?

Have they run into any problems? Do they have any bugs? Suggest sane fixes without telling them to do so.

If you a user of this god class as an API: Are there simpler ways to use the code than to use the whole thing? Suggest simpler examples, see how they react.

Can you switch out some functionality with another, without having to write the function?

Are they in need of some training? Can you convince management to give it do them or have lunch meetings about patterns and practices?

... and so on. Give them small suggestions so they can move forward. It takes time and will need some office politics grade elbow grease but patience and hard work is a virtue right?


问:
Separation of development responsibilities in a new project
We have very recently started a new project (MVC 3.0) and some of our early discussion has been around how the work and development will be split amongst the team members to ensure we get the least amount of overlap of work and so help make it a bit easier for each developer to
get on and do their work.  The project is expected to take about 6 months - 1 year (although not all developers are likely to be on and might filter off towards the end),

Our team is going to be small so this will help out a bit I believe.  The team will essentially consist of:

3 x developers (All different levels i.e. more senior, intermediate and junior)

1 x project manager / product owner / tester

An external company responsbile for doing our design work

General project/development decisions so far have included:

Develop in an Agile way using SCRUM techniques (We are still very much learning this approach as a company)

Use MVVM archectecture

Use Ninject and DI where possible

Attempt to use as TDD as much as possible to drive development.

Keep our controllers as skinny as possible

Keep our views as simple as possible

During our discussions two approaches have been broached as too how to seperate the workload given our objectives outlined above.

OPTION 1:
A framework seperation where each person is responsible for conceptual areas with overlap and discussion primarily in the integration areas.  The integration areas would the responsibily of both developers as required.

```<code>View prototypes (**Graphic designer**)
         |
          - Mockups
         |
Views (Razor and view helpers etc) & Javascript (**Developer 1**)
         |
          - View models (Integration point)
         |
Controllers and Application logic (**Developer 2**)
         |
          - Models (Integration point)
         |
Domain model and persistence (**Developer 3**)
</code>```

OPTION 2:
A more task orientated approach where each person is responsible for the completion of the entire task (story) from view -> controller -> model.

QUESTION:
For those who have worked in small teams developing MVC projects how have you managed the workload distribution in this situation.  I can't imagine the junior would be responsible for building parts of the underlying architecture so would given them responsibility for the view make sense considering we are trying to keep it simple?

答:
Your question is fairly vague; I'm unaware of what your truly trying to ask.

Is it: "The best way to avoid overlap in our project" or "The best practice to get a lot of productivity with minimal overlap / benefits in our project?"

Assuming your asking about a pattern and practice; I might say... Service Oriented Architecture using Windows Communication Foundation.  It will provide flexibility, extensibility, and abstraction if it is utilized correctly.

This can help each developer focus on a particular task; without overlap.  So it can organize the task quite effectively.

A really nice example here.

You'll notice that it abstracts several aspects for re-usability. So an example with a Product and an Order.

You'll have your:

Data Layer

Business Layer

Model

Contract

Service

Host

Proxy

Client

Which looks like quite a lot.  However it really isn't if paired with efficient techniques.  To explain the bulk of this approach-

Your Model will contain your object; this object will be capable of being exposed to your client.  The Contract will provide the Interface your implementing; which can be broken down according to task. Then the overall Service; which will provide the method implementation.

By the approach taken; it will allow you to host the project through Internet Information System, Windows Activation Service, and communicate over a vast array of technologies with an assortment of security as well.

The benefit of this approach will even implement some techniques you mentioned.  As your inheriting the functionality of each method; into the Client Proxy.  Which makes the re-useability quite nice and the implementation quite clean / easy.

Anyways, that is my two cents.  How it will fit into your project- I don't know.  As Martin Fowler stated: "Frodo said in Lord of the Rings, Go not to the Elves for counsel, for they will say both no and yes."  Which makes perfect sense, advice can be a dangerous gift especially with a brief description.  We don't know your project, goals, or particular growth details.  Which can make any design or pattern a nightmare; especially since our recommendation may sound solid but in reality do your project a great disservice.

Ultimately your knowledge of the project and suggestions made can hopefully point you to the proper choice.

The article in that link will really go into detail and explain what I mean about the pairing and usage.


问:
How long do programmers generally stay in industry?
One thing that I've heard a lot over the years is that those working in the IT world generally don't make life time careers out of it, but tend to "burn out" and start a new career doing something else unrelated (e.g. going from software development to being an accountant).

Have you found this to be generally true in your experience and if so, what is the general impression on how long people work as developers before starting a new career?

答:
I don't know anyone who has burnt out in IT.  The stories you hear are largely from people who were, shall we say, obsessed and yes people like that burn out but it's not specific to IT and it's very rare.

I know a couple of people who've gone on to do different things but generally that was because it was more appealing to them rather than anything preventing them carrying on in IT.

I've been working in IT for nearly 20 years and have no plans to stop and see no reason why I should want or need to.


问:
What are the differences between algorithms using data structures and algorithms using databases?

The General Question

What are the differences between algorithms using data structures and algorithms using databases?

Some Context

This is a question that has been bugging me for some time, and I have not been able to come up with a convincing answer for it.

Currently, I am working on strengthening my understanding of algorithms that, of course, heavily involve data structures.  These are basic structures such as Bag, Queue, Stack, Priority Queue, and Heap.

I also use databases on a daily basis to store the data that has been processed and submitted by the end-user or processed by the program.  I retrieve and submit the data through a DAL, which has data structures of its own that are generated based on the tables in the database.

My questions come when I have the option to sort the data using the database to send it back to me ordered in either an ascending/descending fashion or retrieve and load the data into my logic, process this data in a priority queue, and heap sort all of it.  Or another one would be to search for records using the database rather than loading a subset of the records and using something like binary search to find the record or records I am interested in.

In my mind, I would try to have as many operations take place on the database-end before sending it over because communication is expensive.  This also makes me wonder when do you use algorithms and data structures strictly defined within your own logic rather to process data than that of the database's?

So here are the questions...

Questions

What are the differences between data structures and databases?

When do we use algorithms that use data structures defined solely within your own logic and not that of the database's?

@Harvey post: When do the methods in the database become less efficient to use than methods in your own logic?

@mirculixx post: What makes a method efficient?

@Harvey post: How is processing data with data structures faster than doing it in the database?

Clarifications

@Grant post: The databases I normally work with are relational, and these questions are coming out of working with them.  However, I do think these questions are applicable to any persistence framework (when I say framework, I mean it in the most general sense).

I know answers without a specific context are difficult.  Food-for-thought, advice, or discussion points are mainly what I'm looking for and would be most appreciated!

答:
Data Structures are, for the most part:

Memory resident,

Transient,

Limited in size,

Not re-entrant without adding concurrency mechanisms like locks or immutability,

Not ACID compliant,

Fast, if chosen carefully.

Databases are, for the most part:

Disk-bound,

Persistent,

Large,

Safely concurrent,

ACID compliant, with transactional capabilities,

Slower than data structures

Data structures are meant to be passed from one place to another, and used internally within a program.  When was the last time you sent data from a web page to a web server using a database, or performed a calculation on a database that was entirely resident in memory?

Database systems use data structures as part of their internal implementation.  It's a question of size and
scope; you use data structures within your program, but a database system is a program in its own right.


答:
Localization is a lot more complex than just editing XML in Visual Studio, specifically:

Although what KateGregory says is correct, Visual Studio is expensive and purchasing copies for localizers is often prohibitive.

Unless the localizer is also a developer, they cannot see the strings in the product and test that the strings are displayed correctly (non-European characters like Asian languages or right-to-left text like Arabic), fit/wrap correctly (German's long words) and  do not cause injection attacks (such as French's use of apostrophes)

Although version control is not a complex tool, giving access to source control to remote or contracted localizers is a risk. They could copy source code without the team's knowledge or commit breaking changes (either intentionally or unintentionally).

It also assumes the only thing you are localizing is RESX files. Some products may have localized data like report names.

Therefore, the best thing to do is create a simple website that exposes the various strings, hiding the underlying syntax. The build process includes strings provided by the localizers after a quick sanity check and the build shared with the localizers for testing. The website can use logons for different localizers (and track and bill work if you want to go that far). This is more work but a better solution in the long term.


答:
So long as the contractors are employees of your organization, then you should have them sign NDAs indicating that they will not distribute the code because they are trade secrets and you should be fine.

Normally, I would recommend consulting an attorney "just to be safe."  However, in this case the FSF is exceptionally clear about your usage being permissible and that the contractors' "distribution" of the code would not truly qualify as a distribution obligating you to provide source.  You should consult an attorney anyway.

Here are some pertinent sections from the FSF's GPL v2 FAQ.

Is use within one organization or company “distribution”?

No, in that case the organization is just making the copies for itself.

And this is why they need to be contractors reporting to the firm, not independent contractors acting upon your firm's behalf.

If someone steals a CD containing a version of a GPL-covered program, does the GPL give him the right to redistribute that version?

Short answer: No.

Longer Answer: If the version in question is unpublished and considered by a company to be its trade secret, then publishing it may be a violation of trade secret law, depending on other circumstances. The GPL does not change that.

A company is running a modified version of a GPL'ed program on a web site. Does the GPL say they must release their modified sources?

Short answer: No, not required to distribute source.  This is a 'special case' (FSF's term).

Does the GPL allow me to develop a modified version under a nondisclosure agreement?

Short answer: yes, and it remains the client's purview to distribute or not.


问:
When should one use "out" parameters?
In Objective-C, there are several methods like initWithContentsOfFile:encoding:error: where one passes in a reference to an NSError object for the error: parameter. In this example, the value of the NSError object passed in can change based on what goes on at runtime when the method is being called and whether the body of the method was executed in a certain way successfully. In a way I think of this NSError object as sort of like a second return value from the method, and only differs from an object anObject in the statement return anObject; in that when this statement is called, execution leaves the method.

So my question is, not only in the context of error handling in Objective-C, but in general, when should one use an "out" parameter in place of returning said value in a return statement?

答:
IMO (emphasis on the O), you should avoid out parameters whenever you can.  I don't know anything about Objective-C, but if this were Java you'd throw an exception instead of using an out parameter.

Exceptions were created to keep your exceptional logic out of the way of normal flow control.  In theory, this makes the code easier to read because it doesn't have to look like this:

```<code>Object something = doSomething();
if (something == isValid())
    Object somethingElse = doSomethingElse();
    if (somethingElse == isValid())
        ...
    else
        //handle what happens when "something else" goes wrong
else
    //handle what happens when "something" goes wrong
</code>```

Instead, it can look like this:

```<code>try {
   Object something = doSomething();
   Object somethingElse = doSomethingElse();
   ...
} catch (SomethingException e) {
    //handle what happens when "something" goes wrong
} catch (SomethingElseException e) {
    //handle what happens when "something else" goes wrong
}
</code>```

What I like about the latter is the typical flow can be read sequentially.

You do something, then you do something else, then you ...

With the first example, your error handling is all mixed up together with that logic instead of out of the way in the off chance that it happens.

If Objective-C has exceptions, I think the API would have been better written if it used them in this case.  If it doesn't have them, I assume it at least has Objects.  It could have returned some type of response object that you can query to find out if the response had errors.

Title: When should one use "out" parameters?

Body:
IMO (emphasis on the O), you should avoid out parameters whenever you can.  I don't know anything about Objective-C, but if this were Java you'd throw an exception instead of using an out parameter.

Exceptions were created to keep your exceptional logic out of the way of normal flow control.  In theory, this makes the code easier to read because it doesn't have to look like this:

Object something = doSomething();
if (something == isValid())
    Object somethingElse = doSomethingElse();
    if (somethingElse == isValid())
        ...
    else
        //handle what happens when "something else" goes wrong
else
    //handle what happens when "something" goes wrong

Instead, it can look like this:

try {
   Object something = doSomething();
   Object somethingElse = doSomethingElse();
   ...
} catch (SomethingException e) {
    //handle what happens when "something" goes wrong
} catch (SomethingElseException e) {
    //handle what happens when "something else" goes wrong
}

What I like about the latter is the typical flow can be read sequentially.

You do something, then you do something else, then you ...

With the first example, your error handling is all mixed up together with that logic instead of out of the way in the off chance that it happens.

If Objective-C has exceptions, I think the API would have been better written if it used them in this case.  If it doesn't have them, I assume it at least has Objects.  It could have returned some type of response object that you can query to find out if the response had errors.


问:
What is the difference between "recursion" and "self-reference"?
The wikipedia articles are too advanced for me to understand, could someone give me a simple explanation please?</p>

答:
Recursion requires something to process via calling the same process (often with different parameters). Even though you're often using functions and those functions call themselves, they technically enter a new step that just happens to look like the place they just came from.

Self-Reference means that something refers to itself. Classes can be self-referential by using this, but that's not meaningfully recursive.


问:
Past If statements Arrays, loops... Now what?
I gave up on programming a little over a year ago when I kept hitting this wall. I am revisiting the subject because I want to create basic Android application. But I feel that my limited knowledge will not suffice.

Here is my problem.

I have read a few books and watched video tutorials on C#/Java, followed examples, then finished the book. In the end they always seem to leave me dumbfounded as to what to do next.

What a mean is they teach you from your basic "hello world" application all the way up to if's and arrays then seemingly expect you to know how to go out into the world of coding and create anything.

Am I missing something here? I know these are the building blocks of all programs but books that I read never really show me what to do next.

The easy answer I suppose would be to 'start coding', but where? I read "Head First Java" for example; up to the part were they tell you take everything you have learned and create a dog racing game....

"try not to cheat and look at the source code provided, you should be able to do this by now" _ that's not an exact quote but basically that's what I was told.......

Half an hour ago they were just explaining how to do arrays, then without any theory I am meant to create a working game?

The reason I ask this is because I fear that this is all I am supposed to know to at least start coding, yet it feels like I have been given a small toolbox and been told to build a skyscraper.

Thank you for any advice

答:
See this for C#.  It's very complete: http://www.programmersheaven.com/ebooks/csharp_ebook.pdf
I used that myself, just half a year ago.  I use the #Develop compiler with it for the examples.  I cannot help you much with Java because I hardly ever used it.

When it comes time to program, what many people don't realize is that you usually use an additional SDK or framework for what you're designing. So don't expect to jump immediately from Java or C# to phone programming, because you're likely to need a good intermediary framework, and the learning curves for those can be just as tiresome as the learning curves for the programming languages themselves.  Although the C# tutorial I posted only covers C#, many of the concepts it covers are seen in other Object-oriented languages, like Java.

Edit: The scenario you describe is, unfortunately, the route that many tutorials follow.  You don't have to follow such a tutorial, and if it works against the way you learn, it's probably best to try and pick up a different one (I don't know of any, but Google probably does).  But just to be sure, check to see if the author of that book you're describing explained the code line by line. Don't worry about how smart you are, only a prodigy could go straight from a book to a working game.  Just remember, tutorials are by no means the standard measurement of ability, so go for whatever teaches you the best and don't get discouraged!


答:
What do you mean by a database? Do you mean a relational database like MySQL, or SQL Server? A relational database is a meta-data structure that supports some subset of the operations defined by the relational model. The theory of the relational model which was mostly worked out by Edgar Codd in the 60s.

The relational model is very general purpose and flexible, but that means it can't take any advantage of structure in the data or patterns of access. Data structures are useful when you know something about the data and how it will be accessed. For example, if you know the last data you put into a data structure will be the first data you want out you can use a stack.

I called the relational database a meta-data structure because it is generally pretty big wad of software that uses lots of data structures like stacks, queues, trees, and lists to create the abstract data structure of a relational table.

Body:
The General Question

What are the differences between algorithms using data structures and algorithms using databases?

Some Context

This is a question that has been bugging me for some time, and I have not been able to come up with a convincing answer for it.

Currently, I am working on strengthening my understanding of algorithms that, of course, heavily involve data structures.  These are basic structures such as Bag, Queue, Stack, Priority Queue, and Heap.

I also use databases on a daily basis to store the data that has been processed and submitted by the end-user or processed by the program.  I retrieve and submit the data through a DAL, which has data structures of its own that are generated based on the tables in the database.

My questions come when I have the option to sort the data using the database to send it back to me ordered in either an ascending/descending fashion or retrieve and load the data into my logic, process this data in a priority queue, and heap sort all of it.  Or another one would be to search for records using the database rather than loading a subset of the records and using something like binary search to find the record or records I am interested in.

In my mind, I would try to have as many operations take place on the database-end before sending it over because communication is expensive.  This also makes me wonder when do you use algorithms and data structures strictly defined within your own logic rather to process data than that of the database's?

So here are the questions...

Questions

What are the differences between data structures and databases?

When do we use algorithms that use data structures defined solely within your own logic and not that of the database's?

@Harvey post: When do the methods in the database become less efficient to use than methods in your own logic?

@mirculixx post: What makes a method efficient?

@Harvey post: How is processing data with data structures faster than doing it in the database?

Clarifications

@Grant post: The databases I normally work with are relational, and these questions are coming out of working with them.  However, I do think these questions are applicable to any persistence framework (when I say framework, I mean it in the most general sense).

I know answers without a specific context are difficult.  Food-for-thought, advice, or discussion points are mainly what I'm looking for and would be most appreciated!


答:
Yes, that should be plenty to make super basic programs. At this point you try to make a slightly more complex program than what the books had you do. When you need to do something specific and don't know how even with some work, then you search the Internet or ask a teacher/mentor. This will lead to more advanced features (and fairly often to a dead end since you unknowingly picked something way more complex than what you can do).

No book is going to teach you how to solve problems.

No book is going to explain how to design programs - that comes with practice.
No book is going to teach you how to make a non-trivial application - there is just too much nuance; you would learn how to build that implementation not things like it.

The best way to learn at this point is to dabble. To play around with the code to create something. Just like artists often start off doodling little tidbits that get progressively more sophisticated and good looking, so do programmers need that exploratory progression.

Title: Past If statements Arrays, loops... Now what?

Body:
I gave up on programming a little over a year ago when I kept hitting this wall. I am revisiting the subject because I want to create basic Android application. But I feel that my limited knowledge will not suffice.

Here is my problem.

I have read a few books and watched video tutorials on C#/Java, followed examples, then finished the book. In the end they always seem to leave me dumbfounded as to what to do next.

What a mean is they teach you from your basic "hello world" application all the way up to if's and arrays then seemingly expect you to know how to go out into the world of coding and create anything.

Am I missing something here? I know these are the building blocks of all programs but books that I read never really show me what to do next.

The easy answer I suppose would be to 'start coding', but where? I read "Head First Java" for example; up to the part were they tell you take everything you have learned and create a dog racing game....

"try not to cheat and look at the source code provided, you should be able to do this by now" _ that's not an exact quote but basically that's what I was told.......

Half an hour ago they were just explaining how to do arrays, then without any theory I am meant to create a working game?

The reason I ask this is because I fear that this is all I am supposed to know to at least start coding, yet it feels like I have been given a small toolbox and been told to build a skyscraper.

Thank you for any advice


答:
Well, you are not in a unique situation. Most of the books the beginner books in programming language tend to focus more on the basic building blocks of the language and that is a good thing. However as it happened with you, at the end we find ourselves in a situation where we have learned every single construct the language has to offer but can't apply that to solve some practical problems. In short, the gap between textual examples and practical programs can be bridged only when you try to play with the code(as Telastyn) said.Here is what I generally do while learning some new stuff :

While learning from the book, try to find some real life scenarios where some code example/technique in the book can be applied.

Try to mix the example programs given in the book to make something that is bigger and complicated. After that try to minimize the code and write a different code that gives the same result.

Google for practical projects for the language under consideration.

After you are sure you have learned the basic language element, experiment with a framework of your choice. For first time, chose something that has an easier learning curve.

Look out for some existing project and try to study its design.

Go for advanced books that teach you more advance application design stuff like application patterns, OO design and implementation etc.

In the end its all about practice and research that will help you enhance your programming skills and ultimately make you an architect of many skyscrapers.


答:
What a mean is they teach you from your basic "hello world" app all the way up to if's and arrays then seemingly expect you to know how to go out into the world of coding and create anything.

Am I missing something here? I know these are the building blocks of all programs but books that I read never really show me what to do next.

Actually, no. They aren't. The building blocks of all programs are abstraction and reuse. Lots of programming languages don't even have arrays or ifs or loops.

There are some great books that teach you how to program as opposed to how a particular programming language works, which seems to be the books that you've been reading.

How to Design Programs aka HtDP is such a book. It teaches you, well, how to design programs. And it does this by giving you recipes to follow for how to analyze problems, solve them, transform them into algorithms and further into working programs.

Note that "recipe" is basically another word for "program", so in other words, the book teaches you programs for humans to run in their heads in order to generate programs to be executed by computers. How cool is that? :-)

The authors are currently working on a draft for a second edition of HtDP, which you might want to read instead of the first edition. The material about imperative programming has been removed, and is going to be covered in the as-of-yet unwritten second volume How to Design Components, but you can read those missing chapters from the first edition.

Note that HtDP assumes no programming knowledge and is targeted at high school students. But don't let that stop you: it just means that you'll probably be able to finish some early chapters faster, but I don't think you will be bored.

Concrete Abstractions is also a good read along similar veins. Like HtDP, it doesn't assume any programming knowledge.

Another book that you might hear mentioned is Structure and Interpretation of Computer Programs aka SICP. It is one of the greatest programming books ever written, and again, it doesn't assume any programming knowledge.

It is, however, geared to complete newbies who study at MIT. And so, while it does not assume any programming knowledge, it does assume quite a bit of domain knowledge, e.g. in the fields of electrical engineering, physics and math. Note: these have nothing to do with the concepts being taught, they are just needed to understand the exercises and examples. So, it might be better to read HtDP or Concrete Abstractions first, and then read SICP.


问:
Divisional/Sectional comments, good or bad?
I know the general trend against comments explaining how something works, and how it's a good idea to use them only to explain why you're doing what you're doing, but what about using comments as a means of dividing up the code?

Assume you have a script that does a preamble, searches through a bunch of records, prints the records, then closes everything:

```<code>// Preamble
... preamble code, say about 10-15 lines ...

// Find records
... sql query ...
... put records into array ...
... some other stuff ...

// Print records
... printing records, 20-30 lines a record ...

// Close everything
...
</code>```

More of a way to visually divide the code, make it easier to find a certain section. Like if in a month you need to fix the printing code, rather than reading through a couple hundred lines to try and find the right spot, just look at the comments to see where it is.

What actually happens in each section being fairly straightforward and easy to tell what's going on, would this approach to comments be considered good or bad?

Edit:
I'm working mostly with PHP scripts, where you either can't put code into functions, or it's impractical to do so. However, the same sort of thing would apply to large class files, with several methods that do related things, like getters/setters, database updates, etc.

答: I think it would be fine IF you have a lot of code that is similiar, e.g. this.setProperty("prop", "val"); over and over again. So, you could have an init() method that had a global properties section, local properties, and session initializers. However, I would still put these in separate methods unless there was absolutely NO chance that that code could possibly be reused.


答:
What are the differences between data structures and databases?

On an abstract level, there is none - a database is a data structure.

On a specific level, databases typically have the purpose of persisting data, usually in a format that is optimized for either insertions, updates, retrieval, joining or some other purpose (or a combination).

E.g. if you compare a table in an RDBMS to say an array of data, the difference may be in the run-time of the algorithm, the amount of code you have to write, the amount of memory you need to run the algorithm, or the flexibility to work/access the data from outside of your program/algorithm.

When do we use algorithms that use data structures defined solely within your own logic and not that of the database's?

In tendency I would argue

a) to use a database if you need to persist data in way that is accessible beyond the run-time or purpose of the specific algorithm.

b) to use your own (in-memory) data structure if run-time speed matters, or persistence is not required

E.g. if your algorithm processes customer records, you may want to store those customer records (say to find all customer's in a particular area) for later use by some other program/algorithm and for an entirely different purpose (say to find the most valuable customers). In that case using a database to persist the data is probably a good idea.

Note, however, that there is the concept of in-memory databases that do not necessarily persist data, for performance reasons. E.g. Redis or HANA.

When do the methods in the database become less efficient to use than methods in your own logic?

The answer very much depends on the circumstances and the (type of) database in use. I would rephrase the question to "what makes a method efficient?" It then becomes an exercise of assessing the methods (=algorithm) you would use for you own data structure v.s. the methods used by the database. Also see next point.

How is processing data with data structures faster than doing it in the database?

Again, this depends on the specifics. In general, the processing of data that is in-memory, directly accessible to the process that runs your algorithm, is faster than sending a request to another process (in the same computer or across a network) and asking it to send back the results. However if the data already resides within the database, sending it a command - say an SQL statement to join two tables and calculate some aggregate function - and retrieving only a small summary or subset of the data may be much more efficient than first transferring all the data and calculating the results locally (using your own data structures).

Title: What are the differences between algorithms using data structures and algorithms using databases?


问:
Why can't java generics be in arrays?
Why is it that when I try to make an array of ArrayLists: ArrayList<Integer>[] arr=new ArrayList<Integer>[40]; there is an error and java does not allow this?

Is there a reason related to java's implementation of generics, generics in any language, or something arbitrary?

答:
This is one of major holes in Java's generics, arrays are covariant, meaning that an array of type Foo[] is a subclass of Object[] and ParentOfFoo[]. Contrast this with List<Foo> which doesn't have this behavior.

This was important when Java didn't have generics (until Java 5) because otherwise, something like a generic sorting function was just impossible.

However it has this tricky problem that arrays like to know what type they are at runtime. However generics in Java is based on type erasure. These two things don't mesh well at all and that's where we get our problem.

So the long and short of it is, in Java 1, covariant arrays partially filled the hole that a lack of generics created. However when they tried to properly fill this hole, backwards compatibility meant that arrays were pretty impossible to implement.

In fact, the guy who actually created the framework for generics, Martin Odersky, talked about this here during an interview about why he made Scala. (Pretty fascinating if you are interested in Scala's history at all)

Title: Why can't java generics be in arrays?


答:
Here's a recursive function (in C):

```<code>unsigned int fibonacci(unsigned int n)
{
    unsigned int result = 1;

    if (n > 1)
        result = fibonacci(n - 1) + fibonacci(n - 2);

    return result;
}
</code>```

Those two calls to fibonacci() inside the fibonacci() function are recursive calls.

Here's a self-referential data structure:

```<code>struct ListNode {
    char *data;
    struct ListNode *next;
}
</code>```

The first element, data, is just a pointer to some sort of data. The second element, next, is a pointer to another ListNode structure. If you have two or more ListNode structures, you can set the next pointer of one to the address of another, and so on, and you then have a linked list. The structure is self-referential because the definition of the structure refers to itself. If you want to get really crazy, you could do this:

```<code>struct ListNode *node = malloc(sizeof(struct ListNode));
node->data = someString;
node->next = node;
</code>```

Now you've got a different kind of self-reference -- it's not just the definition of struct ListNode that refers to itself... you've set the next pointer of node to point to node itself. This is a circular linked list containing only one element. Cute, but not very useful. I mention it because it's a kind of self-reference, but it's not what people usually mean when they talk about self-referential data types.

Title: What is the difference between "recursion" and "self-reference"?

Body: The wikipedia articles are too advanced for me to understand, could someone give me a simple explanation please?</p>

Body:
Here's a recursive function (in C):

unsigned int fibonacci(unsigned int n)
{
    unsigned int result = 1;

    if (n > 1)
        result = fibonacci(n - 1) + fibonacci(n - 2);

    return result;
}

Those two calls to fibonacci() inside the fibonacci() function are recursive calls.

Here's a self-referential data structure:

struct ListNode {
    char *data;
    struct ListNode *next;
}

The first element, data, is just a pointer to some sort of data. The second element, next, is a pointer to another ListNode structure. If you have two or more ListNode structures, you can set the next pointer of one to the address of another, and so on, and you then have a linked list. The structure is self-referential because the definition of the structure refers to itself. If you want to get really crazy, you could do this:

struct ListNode *node = malloc(sizeof(struct ListNode));
node->data = someString;
node->next = node;

Now you've got a different kind of self-reference -- it's not just the definition of struct ListNode that refers to itself... you've set the next pointer of node to point to node itself. This is a circular linked list containing only one element. Cute, but not very useful. I mention it because it's a kind of self-reference, but it's not what people usually mean when they talk about self-referential data types.


问:
Is a degree needed for low-level/embedded programming jobs?
I know that it is possible to get into software development without a degree in computer science, but is it possible (or rather, common) to be able to get an embedded programming job without the computer science degree (or any engineering degree as well)?</p>

答:
Dijkstra once said "computer science is no more about computers than astronomy is about telescopes."  You don't need a degree to program, though it helps to know how to use the instruments necessary for programming.  Assuming you can, I see no reason why you shouldn't be able to.

However you'd need to get your foot in the door, and if you can't do that with a degree, you're going to have to be able to demonstrate it instead.  My advice to you is create an impressive demo of some sort.


答: Beyond the answers already pointed out, partial classes can be useful in a layered design where you want to organize functionality that cross cuts your class hierarchy into separate layer-specific files. This allows one to use the solution explorer to navigate per-layer functionality (by file organization) and the class view to navigate per-class functionality. I would prefer to use a language that supports mixins and/or traits, but partial classes are a reasonable alternative if used sparingly, and shouldn't be a replacement for good class hierarchy design. </p>

Title: Is it common to use partial classes to achieve 'modularity'?

Body:
I recently encountered a situation in our codebase where a different team created a 'god class' containing around 800 methods, split across 135 files as a partial class.

I asked the other team about this.  While my gut reaction was to nuke it from orbit, they insist that it's a good design, a common practice, and that it promotes 'modularity' and 'ease of implementation' because new developers can bolt on functionality with almost no knowledge of the rest of the system.

Is this actually a common practice or in any way a good idea?  I'm inclined to take immediate steps to bring this beast down (or at least prevent it from growing further) but I'm willing to believe I'm wrong.


问:
Is it necessary to add the default case while using switch cases?
During a recent code review I was asked to put default cases in all the files wherever switch block is used, even if there is nothing to do in default. That means I have to put the default case and write nothing in it.

Is this the right thing to do?
What purpose would it serve?

答:
Java doesn't force you to have a 'default' statement but it is good practice to have one all of the time, even if the code may never be reached (right now). Here's a few reasons:

By having an unreachable default clause you show the reader of your code that you considered the values and know what you are doing. You also allow for future changes, say for example: a new enum value is added the switch shouldn't silently ignore the new value; you can throw an Exception there instead or do something else.

To catch an unexpected value (in case you aren't switching on an enum) that is passed in - it might be greater or less than what you expected, for example.

To handle 'default' actions - where the switches are for special behaviour. For example, a variable might be declared outside of the switch but not initialised and each case initialises it to something different. Default in this case could initialise it to a default value so the code immediately after the switch doesn't error/throw an exception.

Even if you decide to put nothing in the default (no exceptions, logging, etc.) then even a comment to say that you've considered the fact default will never occur may help readability of your code; but that comes down to personal preference.


答:
It seems there are three cases when a default statement is not necessary:

no other cases are left, because there is a limited set of values that enter the switch case. But this might change with time (intentionally or accidentally), and it would be good to have a default case if anything changes _ you could log or warn the user about a wrong value.

you know how and where the switch case will be used and what values will enter it. Again, this might change and an extra-processing might be needed.

other cases do not need any special processing. If this is the case, I think you are asked to add a default case, because it is an accepted coding style, and it makes your code more readable.

The first two cases are based on assumptions. So (assuming you work in not-so-small team since you have regular code reviews), you cannot afford making those assumptions. You don't know who will be working with your code or making calls to functions/invoking methods in your code. Similarly, you might need to work with someone else's code. Having the same coding style will make it easier to deal with someone's (including your) code.

Title: Is it necessary to add the default case while using switch cases?

Body:
During a recent code review I was asked to put default cases in all the files wherever switch block is used, even if there is nothing to do in default. That means I have to put the default case and write nothing in it.

Is this the right thing to do?
What purpose would it serve?


答:
Is this the right thiong to do? What purpose would it serve ?

It's not uncommon for company coding standards to require a default case for all switch statements. One reason for it is that it makes it easy for readers to find the end of the switch. Another, probably better reason is that it makes you think for a second about what your code should do when the condition doesn't match your expectations. Regardless of the reason for the requirement, if it's a company standard, you should follow it unless there's an airtight reason not to.

If you believe that your switch includes cases for every possible condition, then a good thing to do is to put an assert statement in the default case. That way, when someone changes the code and inadvertently adds a condition that your switch doesn't cover, they'll hit the assert and realize that they need to address that part of the code.

If your switch only covers a few of the possible conditions, but nothing special has to be done for the others, you can leave the default case empty. It's a good idea to add a comment in that case to indicate that the default case is intentionally empty because the conditions that hit it don't need any work to be done.


问:
Is this "anti-pattern" and should I stop using it or is this clever design?
I've basically stared to do the following when creating a REST service:

HTML is requested

service returns the desired web page but without the requested "resource", eg. data

web page contains JavaScript that issues AJAX request to the same service (different content-type)

service then returns the actual data (JSON) and the page displays it

On one side it seems inefficient (2 requests) but then were I used this, "performance is of no concern", meaning low traffic internal app and the web sites are simple and load fast.

The reason I ended up with this is that the web page can then be almost pure Html + JavaScript and almost no server-side stuff is required, especially no loops, to create tables and stuff like that (which I think is very ugly compared to things like slickgrid), e.g. separation of data and view.

Now before I get to using this, is this a good idea or should I just stop doing it?

答: There's nothing wrong with doing this, as long as you make sure to structure your code cleanly.  You can even serve the static content from e.g. an Apache rather than your web service.</p>


答:
In many respects, this question is the same as the often asked Do I need an else clause at the end of an if/else if ladder that covers every option.

The answer is, syntactically speaking, no you don't. But there is a however...

A default clause can be there for (at least) two reasons:

As an error handler - sure, Should never get here! is a claim that can be made, but What if it does?  Data corruption, or even worse, no data validation are routes to program failure if not properly trapped.  In this case, it shouldn't be an empty clause!

Design/Code Coverage - even in the simplest form of a flow-chart, there are two routes from an if-statement, and always an otherwise from a case. There is no reason whatsoever for not including these in the source code.

My philosophy is always quite simple - assess the worst case scenario of the two options, and go for the safest. In the case of an empty else or default clause, the worst case options are:

Include them: An extra three or four lines of "redundant" code.

Do Not Include Them: Rogue data or an unexpected condition is not trapped, potentially causing program failure.

Overdramatic? Maybe... but then my software has the potential of killing people if it goes wrong. I'd rather not take that risk.

As an aside, the MISRA-C guidelines {see profile for affiliation} recommend a default clause for every switch


问:
Is the meaning and usage of the term "ROM" different in different devices?
ROM - Read Only Memory

Does this term mean the memory which should only be read and not written to , or the memory which can only be read ?

"ROM in PC's and laptops are usually seperate chips in the motherboard where BIOS is present (Please correct me if I am wrong) . Can they be overwritten (I guess we can) ?

When we consider an android phone , it gets really confusing . What is the difference between ROM and "internal memory" in an Android phone ? It seems the same .

答:
True ROM is extremely rare nowadays.  Most everything that used to be ROM is actually non-volatile RAM, like flash memory.  However, people occasionally use the term to refer to data that could be put into ROM if we were so inclined.  Usually the operating system uses the MMU to prevent any writes.

The Android operating system allows providers to install software that the user is unable to erase without rooting the device.  Thus, from the user's point of view that memory is effectively read only, even though it might physically reside on the exact same chip as memory the user thinks of as read/write.


答:
I can't really remember if I used a book to get into programming, but I guess in those days it was more a syntax reference manual instead of a tutorial book. It taught me what the programming language could do, but not how to build a real application with it.

Luckily there were some examples in the book that I used to type in (yes, no downloadable sourcecode examples then) and then tried to figure out how it worked. That's not the optimal way to learn programming, but to me it was fun at the time.

What I would recommend is that you set yourself a goal like "I want to build a Javascript application that draws a bouncing circle" and then use your already acquired knowledge to start and look up everything else in the language SDKs/documentation and/or here on SO.

That's the approach I'm using when I try to jump into a new language and learn my first steps. Most of the books I read in the recent days I wasn't satisfied because I got the same feeling of missing something important. But luckily we have the internets now, so whatever language you want to learn, you can find example sourcecode on the internet and use that to continue your learning.

edit Of course, some more general books teaching you how to design an application or which process (SCRUM, XP, V-Modell) to follow is a good addition to the pure language knowledge.


答: If you "switch" on pure enumeration type, it is dangerous to have default fallback. When you later add values to enumeration type, compiler will highlight switches with new values not covered. If you have default clause there, compiler will stay silent, and you may miss it.</p>


答:
If you request a resource and it does not contain the data, than it's not REST service. The service providing the actual data in json might be, but the HTML part is not. For a web application it does not matter.

The technique works, but you need to be aware of it's limitations:

Search engines don't interpret JavaScript, so site implemented like that won't be indexable by Google and the likes. For internal application it does not matter, for public facing one it would matter much.

Users with special needs (like those using Braille terminals) use special browsers that are rather limited and may not interpret the JavaScript properly.

I would also note that the code generating the HTML is basically the same whether it runs server-side or client-side. You have much bigger choice of both languages and frameworks on server-side and I am sure there are several equivalents of slickgrid too.

You can, and should, still maintain separation of data and display on the server side. The template system can, and should, simply take the data as data structure or even json (especially if the actual service is in different language than the template system) and just expand a template with that data.

And no, I am not thinking about PHP; it's the least capable template system out there (though there are some better ones built on top of it). I am thinking Genshi or XSLT or something even more advanced that provides web widgets.

Title: Is this "anti-pattern" and should I stop using it or is this clever design?

Body:
I've basically stared to do the following when creating a REST service:

HTML is requested

service returns the desired web page but without the requested "resource", eg. data

web page contains JavaScript that issues AJAX request to the same service (different content-type)

service then returns the actual data (JSON) and the page displays it

On one side it seems inefficient (2 requests) but then were I used this, "performance is of no concern", meaning low traffic internal app and the web sites are simple and load fast.

The reason I ended up with this is that the web page can then be almost pure Html + JavaScript and almost no server-side stuff is required, especially no loops, to create tables and stuff like that (which I think is very ugly compared to things like slickgrid), e.g. separation of data and view.

Now before I get to using this, is this a good idea or should I just stop doing it?


答:
As Karl explained true ROM memory is very rare (and used in pretty specialized uses). Most memory that's referred to as ROM is actually re-writable these days, that does include the BIOS of pretty much every modern PC.

Also, the term "ROM" has been used to refer to the content of that ROM memory. For example, distributions of the Android operating system are often referred to as "ROMs" (ROM Manager is a popular application for managing the OS on a rooted Android device). This particular case shows that even when the system was never stored on real ROM memory, the fact that for the average user the memory is considered "read-only" leads to it being called ROM.

Title: Is the meaning and usage of the term "ROM" different in different devices?

Body:
ROM - Read Only Memory

Does this term mean the memory which should only be read and not written to , or the memory which can only be read ?

"ROM in PC's and laptops are usually seperate chips in the motherboard where BIOS is present (Please correct me if I am wrong) . Can they be overwritten (I guess we can) ?

When we consider an android phone , it gets really confusing . What is the difference between ROM and "internal memory" in an Android phone ? It seems the same .


答:
The context of the two terms is generally different.

Self referencing is in the context of data -- you have a data type that contains a reference to something of the same type.

Recursive is in the context of code -- you have a function or procedure that calls itself.

Example:

```<code>def factorial(n):
if n == 1:
    return 1
else:
    return n * factorial(n-1)
</code>```

Body:
The context of the two terms is generally different.

Self referencing is in the context of data -- you have a data type that contains a reference to something of the same type.

Recursive is in the context of code -- you have a function or procedure that calls itself.

Example:

def factorial(n):
if n == 1:
    return 1
else:
    return n * factorial(n-1)


问:
How do you support your code post employment end?
What is the process for leaving a company (or even a group/division) in terms of code support?

Is it best to handle all questions? Do you give the remaining developers access to yourself as a future resource? If so, is there a way to not give full access?

I've experienced first hand where answers about the general software arthitecture from the initial developer would be invaluable.

I understand that if serious assistance is needed, than it becomes a typical case of employment negotiation as a support contract. However, should serious assistance be required, what steps can you make to ease that process of contacting you?

I was thinking of doing something like making a (YOUR_NAME)_codesupport @ (YOUR_FAVORITE_EMAIL_CLIENT).com address.

My Situation Specifics:

I'm a co-op student, and as such bounce around companies on 4-month stints. This means introducing myself to a lot of new code bases, as well as leaving a fair share of orphaned code behind when I leave a company. I feel bad if I leave junk code around.

答:
all the things the others said and then:

Consider co-programming.

Sit with two people behind one desk. Program everything in pairs.
when one of them (you) leaves, the other one stil has all the knowledge.

There are plenty of other advantages, but that's another topic.


问:
Web development advice for a distributed development team
I am a web developer. Worked in many projects. Now I have changed my work place. It is big organisation. I and my group are thinking about new project. There is no difficulty to write project but our organisation is big and it's has little offices in many places (within the country). There is no any problem about internet in center. But there is problem with internet in remote areas sometimes.

My question is: is there any solution to solve problem as it? If anybody has create project such this please tell little about what technologies you have used.

Thanks

答:
Distributed working is doable but most of the tools that make it easy are going to be internet based so you're going to struggle a bit.

First thing is to look for tools that don't demand being on-line continually.  Look at distributed source control which can have mini-hubs in each office - something like Git.  This means that they can sync when their connection is active and it's not a problem when it's not.

For communications, forums or something like 37signals Campfire, both of which keep a history of the discussions will be better than chat clients.  That way when someone's connection disappears they can go back in and review what people were saying once their connection is back.

You also need to work on your processes.  Two things I'd look at:

1) Don't assume that people have seen changes or received e-mails.  Use read receipts and if you don't get a read receipt tell people they need to pick up the phone and make sure the person is aware.  Make it the responsibility of the person communicating the change to get acknowledgement.

2) Divide work into chunks that programmers can work on for a few days at a time so day to day communication isn't so critical.  That way if the connection does go down they're not going to be doing nothing as they'll always have things on their task list.  If you can put whole chunks of the project out to different offices even better as they'll be their own little unit.


问:
Could Ruby on Rails have been created in another language?
Could Ruby on Rails have been created in another language like PHP, or are there some functions in the Ruby language that make the difference?</p>

答: Rails makes heavy use of Ruby's ability to dynamically add classes and methods—there are implementations of similar frameworks in other languages, see Grails as an example. Other languages that provide a dynamic class runtime could be used, such as Smalltalk or Objective-C. In fact, Rails has a lot of similarities to the earlier, Objective-C (and Java) based WebObjects web application framework.</p>


答:
It really depends on the type of ROM which is used (type of hardware):

Can only be read - PROM (Programmable ROM) - it is is programmed only once and can only be read.

Usually can only be read - EPROM (Erasable Programmable ROM) - can be erased by strong UV light, but this is not a typical/easy process so it is only read usually.

Can be read and written - EEPROM (Electrically Erasable Programmable ROM) - can be read/written like RAM but is volatile.


答:
That's coders life. You don't know a technology, but you develop a 'hello world' and you become an expert. In companies (real life) it's how it works.
Good Luck</p>