问:
Are there security implications to using dynamically-assigned TCP port numbers?
I'm getting pushback from operations for having a server process listen on a dynamically-assigned port number (i.e. it binds a socket to a port number of 0, triggering a dynamic assignment by the OS, which it retrieves using getsocketname()).  The argument was that is "creates all kinds of issues for firewalling, routing, ACL, and security purposes".  I haven't run across anything about this.

This is CentOS, our applications are in-house and restricted to a set of machines on a LAN that's heavily firewalled from the outer world.

Can someone knowledgeable weigh in on the subject?

UPDATE 1: FTP dynamically assigns a port number, too, although I don't know if it's from the same range of numbers that I've seen elsewhere (32768-61000?).  How do firewalls etc. deal with this?

答:
Network administrators like to know exactly what ports your software will listen on, so that they can open only the required ports on the firewall defending their network from intrusion attacks. Protecting a network is all about knowing where an attack could come from. If your network, via its firewall, will never expect traffic on port 699, then if you ignore, discard or actively refuse all traffic requesting or transmitting on that port, an attacker can't get in to do his dirty deeds dirt cheap.

Your dynamic port scheme leaves the selection of the port up to the OS. If the OS can choose any non-reserved port for your service, then your network admin must keep all of those ports open between any two network addresses that may be using your software to communicate.

A "trusted" network environment is a misnomer. Most things you "trust" in IT security are things that are simply infeasible to not trust, or for which the reasons for your trust extend beyond the boundaries of the digital world. You may, for instance, have been given a public key certificate "offline" (via thumb drive, etc) and told it belongs to a particular website. By installing said certificate, you tell your computer that you trust the assertions made by the person who gave it to you. The computer then trusts your own judgement, but verifies that the certificate presented by the website matches exactly the cert it was told to trust.

To the case in point; your heavily-firewalled LAN is "trusted" only because using TLS (based partially on the above certificates) for all traffic inside the LAN, based on a PKI that touches every client machine, and administering firewalls between subnets and VLANs inside this environment, is more work than the network admin is willing to take responsibility for. He instead directs his efforts towards building a solid outer wall and gatekeeper system, ensuring that anything attempting to cross the boundary from the outside in (or the inside out) is doing so with at least apparently valid purpose.

Now, in fact, your network admin may want to put firewalls up at key gateways between LAN subnets and across leased lines or VPNs. By having this program use any port it chooses, you force the network admin not to add this "defense in depth" as long as your program works this way. He's not going to like that, and he's going to push back, hard, on any attempt to tell him he can't do his job the way he sees fit.

As far as the argument that dynamic ports are used all the time to connect, that's true - for the client machine. The port your server computer listens on must be static. FTP was mentioned, so we'll use that. FTP uses two ports, usually 20 and 21, for data transfer and command/control respectively. These ports are the ports the server computer will keep open and listen on, and which a firewall on the server side must allow all incoming requests to pass through.

FTP has two connection modes; "Active" and "Passive", and the client machine chooses which. In "active mode", the client will itself begin listening on a second dynamic port, and as part of the negotiation on port 21, will tell the FTP server which other port to SYN. When the client computer is not behind a firewall or other NAT layer, this is better for the server, as the server can now use a dynamic outbound port to "push" messages to the client instead of waiting for the client to send a request to which it can respond, and the server can also distinguish traffic on this port as being between itself and only one client. However, because the client can't tell a firewall protecting the client's network that it's expecting a valid incoming connection on the dynamic port it chose, this scheme is incompatible with a client behind a firewall or other NAT layer, because the firewall will simply deny the incoming request from the server as being unexpected "inbound" traffic.

Instead, for clients that know or presume they are being firewalled/NATed, the client can request "passive" connection negotiation. When the server receives a "passive" request on port 21, it begins listening on a second one of its ports (port 20 is reserved for this purpose, for situations involving a firewall in front of the server as well) and sends this port identifier to the client, who can then make a second "outgoing" connection to the server on which the client's firewall will then expect traffic. As virtually all clients are at least NATed in current times (home networks are ubiquitous), many FTP client programs don't even bother trying an active connection, and FTP servers are built to take all the traffic they'll get on just the two static ports.

In your model, from what you've said, you're basically trying to use an "active" connection scheme, where your software begins listening on a dynamic port and ostensibly tells the remote computer this port to facilitate a return connection. This is, as described, incompatible with a firewall, and so as long as your software behaves this way and cannot behave in any other way, no firewall can exist between two computers using your software. This may be contrary to your network admin's plans for his network.


问:
Am I required to memorize coding in a work space or can I fall onto references to provide me edge to finishing my development?
I would like to know if I am expected to memorize coding in a workspace or am I allow to fall into references whenever I am unsure.

In a week of non-stop self learning, I feel I can understand the basics html and CSS, but am I required to memorize every single code once I get a position in this field or is it fair to use references to provide you the edge to finish your development. I was always under the impression you had to hand-code everything but I am wondering if I'll be looked as less of a developer if I fall to references. Understanding that if I do memorize most things, it will save me the time it will take me to code something but I don't want to feel penalized if I need to refer back to a code because I need refresh myself.

This Programmers question held a lot of good answers, but they don't quite fit for me.  My role is as a graphic designer/illustrator not a developer, and I am still relative new with how the process works. I'll definitely like a strong input to make sure I go along the right path in my learnings Because HTML and CSS are just a starting point, I want to excel in other areas as well.

Thanks for taking the time to read my post.
P.S (if you have any other additional references or advice, I'll gladly appreciate it)

答:
You don't need to waste time memorizing the precise particulars of any computer language.  learn the basic syntax, get a handle on your defence documentation, and start creating.  Memorization will occur by itself, as you find yourself remembering the details of css or html after looking them up for the Nth time.

Do get in the habit of doing small things yourself to observe behavior and result, though.  In both markup and programming, too often I've seen things done by rote or by guessing, instead of doing a clean test to ensure the basic behavior is as expected.

ContentLicense: CC BY-SA 3.0


问:
Should we avoid object creation in Java?
I was told by a colleague that in Java object creation is the most expensive operation you could perform. So I can only conclude to create as few objects as possible.

This seems somewhat to defeat the purpose of object oriented programming. If we aren't creating objects then we are just writing one long class C style, for optimization?

答:
I think your colleague must have said from the perspective of unnecessary object creation.
I mean if you are creating the same object frequently then it is better to share that object.
Even in cases where object creation is complex and takes more memory, you might want to clone that object and avoid creating that complex object creation process(But that depends on your requirement). I think the statement "Object creation is expensive" should be taken in context.

As far as JVM memory requirements are concerned, wait for Java 8, you don't even need to specify -Xmx, meta space settings will take care of JVM memory need and it will grow automatically.


问:
How does a non-technical manager add value to team of self-motivated software developers?
I am seeing a lot of programmers turning away from management and administration roles. They want to build stuff. And as a result, a lot of these positions are filled by non-technical people. I fail to see how they add value. Is scheduling meetings, booking offsites and other administrative work enough to justify their role?</p>

答: In my experience non-technical manager are best suited for this role, besides adding value by avoiding company stuff interfering with developers work, they foment partnership between developers(cause it's well know that developers are introverts http://www.unwesen.de/2012/03/16/introversion-productivity-work-environments/), good ones let the team work at their rhythm but caring about visibility.</p>


问:
How can I determine the minimum requirements of a piece of software?
Some software producers provide minimum requirements, some examples: Skype, Diablo III, Ubuntu-Server and OpenOffice.

I wonder how those minimum requirements are determined, especially RAM, CPU frequency in general? Is there a logic behind it or is it just determined by testing the program with different hardware to find out what would be okay for the end user?

If there is a logic to determine such parameters, e.g., how could I prepare such requirements for C or Java code (assuming that it has >10k lines)?

答:
Profiling the application when running an end-to-end transaction/process on machines/VMs with different settings might help. That could help you see how long it takes to run different methods/processes by CPU time vs number of invokes, and adjusting the underlying VM/hardware can help tweak it. Profiler will also tell you how much heap memory is allocated during your runs. So for minimum memory requirements you certainly want to exceed those. Major Java IDEs - Netbeans and Eclipse have those.

For web applications you might consider placing them under a load tool, e.g. LoadUI. Using those you'd be able to compare stats such as number of hits on your web app/time vs CPU usage/memory usage on your server.

OwnerDisplayName: angs

ContentLicense: CC BY-SA 4.0

OwnerDisplayName: Evgheni Crujcov


答:
There is a bunch of things you should remember to specify.

Mainly:

Software: platform, APIs, drivers, etc. This is easy once you know your code and your dependencies;

Hardware:

Architecture:

CPU/memory: try using some profiler or measuring your application in different environments by using 'Task manager' or 'Activity monitor'

Storage: What about your app installation? What more is needed?

Video: Minimum resolution, 3d graphics?

Peripherals: webcam? etc

Some other recommendations:

Do not forget to test your application in simple usage and in high usage. Test the worst scenario;

Once you found and test your application in a machine that works fine, it helps a lot to define the minimum specification. I mean, you do not need to look for a smaller specification;

There are things you can find in your current language/framework. E.g.: java virtual machine minimum requirements + your app needs.

Title: How can I determine the minimum requirements of a piece of software?

Body:
Some software producers provide minimum requirements, some examples: Skype, Diablo III, Ubuntu-Server and OpenOffice.

I wonder how those minimum requirements are determined, especially RAM, CPU frequency in general? Is there a logic behind it or is it just determined by testing the program with different hardware to find out what would be okay for the end user?

If there is a logic to determine such parameters, e.g., how could I prepare such requirements for C or Java code (assuming that it has >10k lines)?

OwnerDisplayName: Danilo Muñoz


问:
Clarify the Single Responsibility Principle
The Single Responsibility Principle states that a class should do one and only one thing.  Some cases are pretty clear cut.  Others, though, are difficult because what looks like "one thing" when viewed at a given level of abstraction may be multiple things when viewed at a lower level.  I also fear that if the Single Responsibility Principle is honored at the lower levels, excessively decoupled, verbose ravioli code, where more lines are spent creating tiny classes for everything and plumbing information around than actually solving the problem at hand, can result.

How would you describe what "one thing" means?  What are some concrete signs that a class really does more than "one thing"?

答:
It all depends on the definition of responsibility and how that definition is going to impact maintenance of your code. Everything boils down to one thing and that is how your design is going to help you in maintaining your code.

And Like someone said "Walking on water and designing software from given specs is easy, provided both are frozen" .

So, if we are defining  responsibility in more concrete way, then we don't need to change it.

Sometimes responsibilities will be glaringly obvious, but sometimes it might be subtle and we need to judiciously decide.

Suppose, we add another responsibility to Dog class named catchThief().
Now it might be leading towards an additional different responsibility.
Tomorrow, if the way Dog is catching thief has to be changed by Police Dept, then Dog class will have to be changed. It would be better to create another subclass in this case and name it ThiefCathcerDog. But in a different view, if we are sure that it is not going to change in any circumstance, or the way catchThief has been implemented is dependent on some external parameter, then it is perfectly ok to have this responsibility. If responsibilities are not strikingly odd then we have to decide it judiciously based on the use case.

ContentLicense: CC BY-SA 2.5


答:
In terms of measurable resources like CPU and memory, there's no formula. Modern, megalithic, multithreaded software written in modern, "magic" languages on busy, modern operating systems is impossible to predict. You just have to run some benchmarks.

Find the point at which your software becomes nearly unusable. Then, pad the numbers a little to account for all the naughty software your users have installed, downloading illegal movies and so forth in the background ... Well, or if you just want to ensure more of your users experience great performance.


答:
I wonder how those minimum requirements are determined, especially RAM, CPU frequency in general? Is there a logic behind it or is it just determined by testing the program with different hardware to find out what would be okay for the end user?

Well, it is not possible to give a definite answer.  (Different people, groups, companies are likely to have different ideas / approaches.)

But in general, the only way that is likely to work is empirical measurement; i.e. try it and see.

Install the software on a variety of supported platforms and measure the disc space.

Run it1 on a range of systems with various CPU speeds and various amounts of memory:

See whether it works acceptably well (subjective).

Look at the system stats for signs of stress on lower-end systems.

Incorporate feedback from in-house users and external beta testers.

1 - Depending on the nature of the application, you may need to try with different sized problems, datasets, numbers of online users, whatever ... up to a point that is reasonable.

I have not come across a case where you could get reliable platform recommendations by simply applying some logic.  At a minimum you need to run some tests to calibrate your "performance model".

Even when there is a correlation between problem size and performance, you usually cannot reliably predict when you are going to run into scaling-related performance problems ... until you hit the problems.


问:
LSP vs OCP / Liskov Substitution VS Open Close
I am trying to understand the SOLID principles of OOP and I've come to the conclusion that LSP and OCP have some similarities (if not to say more).

the open/closed principle states "software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification".

LSP in simple words states that any instance of Foo can be replaced with any instance of Bar which is derived from Foo and the program will work the same very way.

I'm not a pro OOP programmer, but it seems to me that LSP is only possible if Bar, derived from Foo does not change anything in it but only extends it. That means that in particular program LSP is true only when OCP is true and OCP is true only if LSP is true. That means that they are equal.

Correct me if I'm wrong. I really want to understand these ideas.
Great thanks for an answer.

答:
I would look at it from client's point of view. if Client is using features of an interface, and internally that feature has been implemented by Class A.
Suppose there is a class B which extends class A, then tomorrow if I remove class A from that interface and put class B, then class B should also provide same features to the client. Standard example is a Duck class which swims, and if ToyDuck extends Duck then it should also swim and does not complain that it can't swim, otherwise ToyDuck should not have extended Duck class.</p>


问:
Why should a column in a Relational Database have a single purpose?
Consider a table in which a column represents a monetary value in some cases and a link to the value of another record in other cases so that we have the following:

```
TABLE 1
Id Product Composite
1  Apple   False
2  Orange  False
3  Pear    True

TABLE 2
Product  Date        Price
1        2010-01-01  0.45
2        2010-01-01  0.50
3        2010-01-01  1.00
1        2010-01-02  0.46
2        2010-01-02  0.49
3        2010-01-02  2.00
```

The tables above represent the fact that the price for an Apple and Orange are given on each date by the corresponding Price column in Table 2 so that the price of an Apple on 2010-01-01 is 0.45 and the price of an Orange is 0.50 on that same date, however, the price for a Pear on 2010-01-01 is 0.45 and the price for a pear is 0.49 the following day by allowing the Pear's price to be determined by the price of an Apple on the first day and the price of an Orange on the second day.

Please indicate the pros and cons of this approach?

答:
I think the word "purpose" phrases the question on a level that's unnecessarily abstract.

On a simpler level, we can say that all the values in a single column should be drawn from the same domain, and have the same semantics.  So the same value in the column in two different rows ought to mean the same thing.

In particular, if the values in a column are foreign keys, then they should all be foreign keys to the same table.  I've seen the opposite done, where references to multiple tables are stored in a single column.  The result is invariably a mess.  A companion column is always needed to disambiguate, and this leads to one of two problems.

Whenever the disambiguation is done correctly, the code is more complicated than it needs to be, and also runs more slowly than it should.  And of course, if the programmer forgets to disambiguate correctly on a join, the wrong stuff gets joined together.  I've seen both cases.

Foreign keys is the most obvious case,  but even in other cases the need to disambiguate is just an awkward consequence of introducing ambiguity in the first place.  If you keep different data in different columns, you don't have to disambiguate.


问:
Handling Deployment to Multiple Environments
How should I handle deploying web applications to multiple servers?

Constraints

I have a dev, test and prod environment. No build server is available. Developers can't deploy to prod. The people that do deploy to prod copy files from test to prod. They don't have VS installed.

Currently

The way it's handled is using web.config transform. However, to deploy to prod involves putting prod code on the test server where it's copied over.

Problem

Sometimes simple mistakes are made, such as forgetting to change test back to the right environment after deployment. Or the test config gets moved to prod instead of the prod config.

Solution

So the question is, what is the best way to prevent mistakes from happening?

My first thought is let the app determine which server it's on at runtime and use the appropriate settings/connection strings/etc... However, the server names could change in the not too distant future. So if multiple apps are hard coded, that would mean updating all of them. The easiest way to handle that situation would be to place a DLL in the GAC that determines the environment.

Are there any drawbacks or possible complications that this would cause? Or is there a better solution to the problem than this?

答:
Normally the higher the deployment process is automated, the lower risk there will be. To achieve better automation, i think command line procedures (with different modes, for example, interactive v.s. quiet mode) could be a good option:

I believe you won't have many environments (DEV/QA/UAT/PROD/etc.) and they are already fixed. So a fixed xslt transformation could be defined and included in your project, for example, call it web.config.xslt, in which, a list of configuration sections per environment could be defined (or a switch-case conditional configuration)

use MSBuild to build the solution, and output the built files to a newwork location (preferably accessible to all developers), and at the end, transform web.config based on web.config.xslt and produce a couple of config files: web.Dev.config, web.QA.config, web.UAT.config and web.Prod.config

give an option at the command line, say which environment the user wants to deploy, then batch copy all the files to the desired server (of course, you have to allow these folders shared and accessible to the deployer) and at the end copy the corresponding web.[ENV].config file as web.config to destination folder

other bit and pieces (such as versioning, DLL signing and etc.) could also be included and automated through out the MSBuild process.

all these steps could be stored in a predefined solution level file, let's say it mySolution.BuildRelease.proj (all up to you) and set MSbuild (or your self-defined bat file, which calls MSBuild and your own console app) as the default app to open it.

of course, if some of the processes could not be done using command line, you might want to try write a console application and call it during MSBuild.

if you are fancy with interactive approaches, you may also define a html app (hta) to wrap up the process


答:
In a past life I managed a group faced with this issue.

We chose to manually set the config files as needed (i.e., a code promotion from test to production would explicitly exclude the web.config file).  Like you, it was a different group that did the promoting.

One major advantage we saw was that "what you saw on Test was what you'd get on Prod".  If your code has ANY environment-dependent code in it, you're in trouble because you're putting untested code into production.

We learned this the hard way when a dev put if (servername != "prodServer") in the code.  All was fine until the server group renamed prodServer to prodServer2 and all our connection strings, etc. switched back to their dev environment settings.  That was a tough day -- difficult to explain to the business why their production system crashed so thoroughly.

tl; dr

Your code should never know which environment (dev/test/production) it's in.

Config files are not code and should never be promoted.

Keep your code promotion process as simple as possible.  I think we used Robocopy.  Setting it up to copy everything except web.config from dirA to dirB is pretty foolproof.

Title: Handling Deployment to Multiple Environments

Body:
How should I handle deploying web applications to multiple servers?

Constraints

I have a dev, test and prod environment. No build server is available. Developers can't deploy to prod. The people that do deploy to prod copy files from test to prod. They don't have VS installed.

Currently

The way it's handled is using web.config transform. However, to deploy to prod involves putting prod code on the test server where it's copied over.

Problem

Sometimes simple mistakes are made, such as forgetting to change test back to the right environment after deployment. Or the test config gets moved to prod instead of the prod config.

Solution

So the question is, what is the best way to prevent mistakes from happening?

My first thought is let the app determine which server it's on at runtime and use the appropriate settings/connection strings/etc... However, the server names could change in the not too distant future. So if multiple apps are hard coded, that would mean updating all of them. The easiest way to handle that situation would be to place a DLL in the GAC that determines the environment.

Are there any drawbacks or possible complications that this would cause? Or is there a better solution to the problem than this?


问:
When can you call yourself good at language X?
This goes back to a conversation I've had with my girlfriend. I tried to tell her that I simply don't feel adequate enough in my programming language (C++) to call myself good. She then asked me, "Well, when do you consider yourself good enough?"

That's an interesting question. I didn't know what to tell her. So I'm asking you.

For any programming language, framework or the like, when do you reach a point were you sit back, look at what you've done and say, "Hey, I'm actually pretty good at this."? How do you define "good" so that you can tell others, honestly, "Yeah, I'm good at X".

Additionally, do you reach these conclusions by comparing what others can do?

Additional Info

I have read the canonical paper on how it takes ten-thousand hours before you are an expert on the field. (Props to anybody that knows what this paper is called again)

I have also read various articles from Coding Horror about interviewing people. Some people, it was said, "Cannot function outside of a framework." So they may be "good" for that framework, but not otherwise in the language. Is this true?

答:
You know you're good at it when you like what you're doing (and it's not just a trivial task).

You know you're bad (yet) when you keep swearing randomly while you code.


问:
What would the general design for an XSD to C# class converter look like?
I am looking to create a simple code generator to convert XSD definitions to C# classes.  This is partly as a learning exercise, but I would also like to get some practical use out of it eventually.

What would the general design of such an application look like?  I assume that I will need to use one of the XML parsers in the .NET framework, but which one? And what will the resulting data structure look like?  Will it be an expression tree?

From there, what happens?  Do I generate code by concatenating strings, or are there better, more sophisticated ways to do it?

Important:  I'm not looking for someone to write code for me (although very brief code samples are welcome, if they are applicable), and I don't need someone to do the research for me.  I'm perfectly capable of reading about parsers, expression trees and code generators myself.  I just need someone to help me with the broad brush strokes, so that I don't walk into too many blind alleys.

I'm also aware of open source projects like XSD2Code, but I'd rather make the attempt myself first, for learning reasons, and because the resulting tool is likely to be highly specific to my particular scenario.

答:
What would the general design of such an application look like?

Leaving aside trivalities like UI, you'll want to have at least three major parts:

The "core" app, that translates the XML object into a C# string.

The portion that locates and reads the XSD file as XML, and passes each object over to the core app to process.

The portion that writes out the C# strings.

You'll want #1 to have a fair bit of available recursion, since XSD elements can be of types that contain elements and types and elements.

I assume that I will need to use one of the XML parsers in the .NET framework, but which one?

I'd load the whole XSD as a single System.XML.XMLDocument class, but I'm from the web and learned XML via the DOM.  It's also the older model, and starting with things like selectSingleNode is probably better to start out with than performance-optimizing interfaces like XmlReader, or non-microsoft XML parsers.

And what will the resulting data structure look like? Will it be an expression tree?

Why wouldn't it be a namespace of structs or classes?

From there, what happens? Do I generate code by concatenating strings, or are there better, more sophisticated ways to do it?

There are no better ways to output strings from a program than concatenating strings.  There is just syntactic sugar to make the code easier to write.  But you want to use a System.Text.StringBuilder here, instead of mucking about with code like follows:

```<code>string Line = new String();
Line = "public class " + xmlDoc.localName + "() {\n";
Line += "etc, etc.";
</code>```

Body:
What would the general design of such an application look like?

Leaving aside trivalities like UI, you'll want to have at least three major parts:

The "core" app, that translates the XML object into a C# string.

The portion that locates and reads the XSD file as XML, and passes each object over to the core app to process.

The portion that writes out the C# strings.

You'll want #1 to have a fair bit of available recursion, since XSD elements can be of types that contain elements and types and elements.

I assume that I will need to use one of the XML parsers in the .NET framework, but which one?

I'd load the whole XSD as a single System.XML.XMLDocument class, but I'm from the web and learned XML via the DOM.  It's also the older model, and starting with things like selectSingleNode is probably better to start out with than performance-optimizing interfaces like XmlReader, or non-microsoft XML parsers.

And what will the resulting data structure look like? Will it be an expression tree?

Why wouldn't it be a namespace of structs or classes?

From there, what happens? Do I generate code by concatenating strings, or are there better, more sophisticated ways to do it?

There are no better ways to output strings from a program than concatenating strings.  There is just syntactic sugar to make the code easier to write.  But you want to use a System.Text.StringBuilder here, instead of mucking about with code like follows:

string Line = new String();
Line = "public class " + xmlDoc.localName + "() {\n";
Line += "etc, etc.";


问:
High traffic chat - how to check if there is new message and show it for all users
I already had question about this but obviously it was not accepted very well, apparently too long when it's actually more information so you could have given me better answer.

Ok, I will be much clearer now. Best possible logic to develop scalable chat in terms of stability, storing/reading messages on chat, updating chat on new message for all users etc.? I have most of this developed, the logic I think I miss is --> check if there is new message and show it for all users. I have this implemented but it crashes the site due to its traffic of 300k-400k people, so that's my main question.

The chat is PHP based and uses Pusher (www.pusher.com) for instant messaging but it lacks what I need because it's more like a websocket.

I'm using hardcoded files to keep messages (want to avoid database as much as possible). It's a no extension type of file, I'm sure you know. I'm getting crash with

```<code>$fp = fopen(..., "w"); // pretend ... is the path and filename
fwrite($fp, $msg); //hardcode the message
fclose($fp);
</code>```

where $msg is the message itself. I'm having 1 file per message. I show last 150 messages = 150 file accesses and reads, yeah it's too much I guess. I have better logic now which I'm pursuing and that is 1 file with last 50-100 messages at all time. Sure it should be much better.

How does it crash, that's the trickiest part because everything seems ordinary, believe me it is difficult to determine what exactly crashes the site, but in like 5 minutes when I try to open the site it's gone, then I put the old content without chat and is back online again.

I'm having jquery post every 1 second to check if there is new message. I'm using timestamp in a special file where I keep the time last message was sent and if ((time() - time in file) <= 2) = reload last 150 messages including the last one. Too much input/output, write/read or however to say it I think is what crashes the site.

答:
Personally in your case of High Traffic i would honestly try a redis server or some form of memory cache of the messages.

In any language from PHP web apps to desktop applications as soon as I know I might need to read something from a file more then 2 times in a second and the chance of it changing in that second is so low I cache the result. Caching helps a ton when looking at these kind of performance issues. HDD's always have the worst IO and on production servers I like using increased amounts of ram and cache where possible.

EDIT
I would try and use Xdebug to analyse where my costly php functions are. I would also try another server and then a more powerful server. There is no point trying to run your website on a 1gig mem and 1 core cpu. You would need at lease a dedi and a couple cores.

If that does not work you could try clustering and using a redis server.

Also What you could try is increase the chat time to 4 or 5 seconds. Or look into customising the chat script to use web sockets.


问:
Design in one team, coding in another
I will be involved in a project where all the software design is made by a local team and these designs are sent to an offshore team for coding.

This is the first time I face a project with this characteristics and for me it feels kind of odd: The managers expects us to make very detailed design documents so there's no space for error for the offshore team; from my perspective they are making us coding in paper while we can do it in an IDE.

So, my question is is this approach good, or proven right? What are the main considerations our software process has to have to have success in our project?

答:
The major cost of the offshore development is the communication. Documentation is one way of communication, however, documents are not able to cover all the details and potential changes usually.

Not sure how big your project is. I am assuming it's big otherwise it's not valuable to use the offshore development team. Thus, my experience is

Define the skeleton code, public interface, service interface, etc., and review together

Define the acceptance tests with the other side

Split the big document to small stories, work based on the small stories. The big document is just a big picture of the whole system

Set up the check points of the stories, one week or two weeks

1 and 2 is actually about the development, to make sure the other side understand the requirement well, and both side are using the same pattern. 3 and 4 is a part of agile development methodology, but for the offshore development, it's hard to use the full agile process.

Title: Design in one team, coding in another


问:
How to incorporate existing open source software from a licensing perspective?
I'm working on software that uses the following libraries:

Biopython

SciPy

NumPy

All of the above have licenses similar to MIT or BSD.

Three scenarios:

First, if I don't redistribute those dependencies, and only my code, then all I need is my own copyright and license (planing on using the MIT License) for my code. Correct?

What if I use py2exe or py2app to create a binary executable to distribute so as to make it easy for people to run the application without needing to install python and all the dependencies. Of course this also means that my binary file(s) contains python itself (along with any other packages I might have performed a pip install xyz).

What if I bundle Biopython, SciPy, and NumPy binaries in my package?

In the latter two cases, what do I need to do to comply with copyright laws.

答:
You need to read the licenses, and follow their particular terms.  For some, it's as easy as just including a copyright notice and not saying "written with help of the bioPython folks!"

If you are not comfortable understanding and following a two-paragraph license, YOU NEED A LAWYER.  No one else is allowed to tell you that you performing a sequence of specific steps is or is not legal.  There are simply too many complexities to trust anyone without malpractice insurance and a reputation behind what they say.

(Or, of course, you could get specific permission from the copyright holder.  Which is harder than you'd think for an open source project.  There's a reason the FSF asks contributors to actually assign them copyright.)

That said, in general, if you make a copy of someone else's code, in whole or in part or just by using it as a guide to write your own, you can't do anything with that code without the someone else's permission.  That's what licenses are for; they're written permission with some defined conditions.

If you include someone else's source code or binaries, you cannot give or sell your application to anyone, even once, without that permission.  And depending on how deeply you used their libraries, you might not even be able to send the code you wrote yourself without getting their permission.

(There is a fuzzy line between "I copied their source code" and "I did only what was needed to be compatible."  There are lawsuits over this all the @#$@ing time  But those involve lawyers, and big budgets, and corporate liability shields.)

Thankfully, Python itself and bioPython and even Microsoft and the FSF have available libraries that have absurdly sensible redistribution terms.  Even if your code is legally a derivative work, you can almost certainly license just your code via MIT, and bundle it with an installer that either has permission to include thier libraries or just points to where the user can get them from the source.


答:
Abstract Algorithm

Transform(input)

When Transform is called with the argument input.

If input is not valid XML then report error

Let xml be the result of transforming input into an abstract representation of XML

If xml does not conform to XSD then report error

Let CSharp be the result of transforming xml into an abstract representation of CSharp code

Let output be the result of transforming CSharp into a String

Return output

C# Stub

```<code>public static string Transform(string input)
{
    var xml = ConvertStringToXml(input);
    ValidateXsdSchemaConformance(xml);
    var csharp = ConvertXmlToCSharp(xml);
    return ConvertCSharpToString(csharp);
}
</code>```

Title: What would the general design for an XSD to C# class converter look like?

Body:
I am looking to create a simple code generator to convert XSD definitions to C# classes.  This is partly as a learning exercise, but I would also like to get some practical use out of it eventually.

What would the general design of such an application look like?  I assume that I will need to use one of the XML parsers in the .NET framework, but which one? And what will the resulting data structure look like?  Will it be an expression tree?

From there, what happens?  Do I generate code by concatenating strings, or are there better, more sophisticated ways to do it?

Important:  I'm not looking for someone to write code for me (although very brief code samples are welcome, if they are applicable), and I don't need someone to do the research for me.  I'm perfectly capable of reading about parsers, expression trees and code generators myself.  I just need someone to help me with the broad brush strokes, so that I don't walk into too many blind alleys.

I'm also aware of open source projects like XSD2Code, but I'd rather make the attempt myself first, for learning reasons, and because the resulting tool is likely to be highly specific to my particular scenario.

Body:
Abstract Algorithm

Transform(input)

When Transform is called with the argument input.

If input is not valid XML then report error

Let xml be the result of transforming input into an abstract representation of XML

If xml does not conform to XSD then report error

Let CSharp be the result of transforming xml into an abstract representation of CSharp code

Let output be the result of transforming CSharp into a String

Return output

C# Stub

public static string Transform(string input)
{
    var xml = ConvertStringToXml(input);
    ValidateXsdSchemaConformance(xml);
    var csharp = ConvertXmlToCSharp(xml);
    return ConvertCSharpToString(csharp);
}


问:
Should we design programs to randomly kill themselves?
In a nutshell, should we design death into our programs, processes, and threads at a low level, for the good of the overall system?

Failures happen. Processes die. We plan for disaster and occasionally recover from it. But we rarely design and implement unpredictable program death. We hope that our services' uptimes are as long as we care to keep them running.

A macro-example of this concept is Netflix's Chaos Monkey, which randomly terminates AWS instances in some scenarios. They claim that this has helped them discover problems and build more redundant systems.

What I'm talking about is lower level. The idea is for traditionally long-running processes to randomly exit. This should force redundancy into the design and ultimately produce more resilient systems.

Does this concept already have a name? Is it already being used in the industry?

EDIT

Based on the comments and answers, I'm afraid I wasn't clear in my question. For clarity:

yes, I do mean randomly,

yes, I do mean in production, and

no, not just for testing.

To explain, I'd like to draw an analogy to multicellular organisms.

In nature, organisms consist of many cells. The cells fork themselves to create redundancy, and they eventually die. But there should always be enough cells of the right kinds for the organism to function. This highly redundant system also facilitates healing when injured. The cells die so the organism lives.

Incorporating random death into a program would force the greater system to adopt redundancy strategies to remain viable. Would these same strategies help the system remain stable in the face of other kinds of unpredictable failure?

And, if anyone has tried this, what is it called? I'd like to read more about it if it already exists.

答:
It is possible that a random bit flip happens due to cosmic radiation. This problem was recognized, and various techniques were developed to prevent bit flipping from happening.

However, it is not possible to fix it 100%, and memory corruption can still cause problems, and these problems are still happening (with very low probability).

Now to answer your question. Whether or not you need to design a very robust system, it depends on what you are doing. If you need to create a space craft, you better make it super robust, and then you will need to take into account every possible issue.

If you need to design a normal desktop application, then you should look at random crashes as bugs in your code.


问:
Code execution time out occasionally
I am working on an e-commerce website. There is a case where I need to fetch the whole data in database through a third-party API and send it to an indexing engine. This third-party API has many functions like getproducts, getproductprice, etc., and each of those functions will return the data in XML format.

From there I will take charge, I will use various API calls and will handle the XML data with XSLT. And will write to a CSV file. This file will be uploaded to an Indexing engine.

Right now I have details of 8000 products to feed the engine, and almost all time the this process takes about 15 min to complete, and sometimes fails. I can't find a better solution for this. I am thinking about handling the XML data in C# itself and get rid of XSLT. As I think, XSLT is far slower than C#.

Is it a good Idea? Or what else I can do to solve this issue?

答:
XSLT is made for this type of processing.  Even if it were slower, it would be ludicrous to try to rewrite it yourself.  It would be like saying you don't like how slow regular expressions are, so you want to write a program to do the pattern matching yourself.

The problem is not a technical but rather conceptual.  Why are you having to feed 8000 products from a third party database?  Likely most of this data hasn't changed since the last time you did it.  Surely there must be some way of getting the differences between the last time you fetched the data and now.

Have you considered using an ETL program to port data from your client's database to your own on a regular basis?  These programs are made for porting data, and they rarely fail.  However in the case that they do fail, most allow the possibility of reattempts or performing alternative operations on fail.  They could be scheduled to run on a regular basis in the morning when nobody is paying much attention.  I assume your indexing engine is designed to import all this data from the csv file, in which case your job would be finished if you used the ETL to update the database instead.  The web application doesn't have to know about the existence of this ETL and can continue to operate using the data it loads from the local database.

Title: Code execution time out occasionally


答:
AIUI, expression trees are for internal manipulation of a single lambda function, not for representing an entire class. For the intermediate representation to output half of the design your main options are a custom AST and string concatenation (as suggested in another answer) or CodeDOM. The latter is quite verbose but would give you flexibility if you decide that you want to emit VB, JS, or whatever else Microsoft chooses to add in the future.

At heart it's the old tradeoff between KISS and enterprisy.


答:
At the very least, have you considered harnessing the third party API's methods to multiple to retrieve the data from the DB in multiple trips (i.e. one subset at a time)? You could send it to the indexing engine in smaller chunks (if possible) or at least build the returned XML data in memory until retrieval of all data completes.

There'd be more round trips, but each wouldn't take as long (you used the word "timeout" - I'm not sure how literally). Furthermore, if one of these smaller operations did fail, you could just retry that single operation rather than having to restart the entire process.

Title: Code execution time out occasionally

Body:
I am working on an e-commerce website. There is a case where I need to fetch the whole data in database through a third-party API and send it to an indexing engine. This third-party API has many functions like getproducts, getproductprice, etc., and each of those functions will return the data in XML format.

From there I will take charge, I will use various API calls and will handle the XML data with XSLT. And will write to a CSV file. This file will be uploaded to an Indexing engine.

Right now I have details of 8000 products to feed the engine, and almost all time the this process takes about 15 min to complete, and sometimes fails. I can't find a better solution for this. I am thinking about handling the XML data in C# itself and get rid of XSLT. As I think, XSLT is far slower than C#.

Is it a good Idea? Or what else I can do to solve this issue?


问:
Are immutable/stateless singletons bad?
Lately there have been some kind of revolution against singletons, but is there something wrong with them if they are stateless?

I know the overuse talk and all... this applies to everything not just singletons.

答:
The main problem with singleton is that it hides dependecies and coupling expecially when used in cross-cutting concerns scenario. See Singletons are Pathological Liars or Why Singletons are Evil for further reading.

From the other side, a state less singleton, if not abused, may be helpful and improve performance. Consider an example:

```<code>interface Interface
{
    void Method();
}

class StatelessSingleton : Interface
{
    public static readonly StatelessSingleton Instance = new StatelessSingleton();
    private StatelessSingleton() { }

    public void Method() { }
}

class User
{
    public User(Interface i) { /* ... */ }
}
</code>```

Here, the StatelessSingleton acts as default implementation of the Interface and is put into the User constructor. There is no hard-coded coupling and hiden dependencies. We are unable to use a static class due to the underlying interface but there is no reason to create more than one instance of a default. That's why a stateless singleton seems to be an appropriate choice.

However, maybe we should use another pattern for a default implementation:

```<code>class Implementation : Interface
{
    private readonly Action _method;

    public Implementation()
    {
        _method = new Action(() => { /* default */ });
    }

    public Implementation(Action custom)
    {
        _method = custom;
    }

    public void Method()
    {
        _method();
    }
}
</code>```

It hits the performance with respect to StatelessSingleton but constitutes a generic implementation of the Interface. Similar solution is used by IProgress interface.

Altough again, why allow to create more than one implementation of default behaviour? Yet we can combine the two:

```<code>class Implementation : Interface
{
    public readonly Implementation Default = new Implementation();

    private readonly Action _method;

    private Implementation()
    {
        _method = new Action(() => { /* default */ });
    }

    public Implementation(Action custom)
    {
        _method = custom;
    }

    public void Method()
    {
        _method();
    }
}
</code>```

In conclusion, I believe that there are places (as depicted defaults) where Singletons are useful. The main definition of Singleton states that it disallow to create more than one instance of a class. It's as nuclear power. Can produce an energy or a bomb. It depends on human.

Title: Are immutable/stateless singletons bad?

Body:
The main problem with singleton is that it hides dependecies and coupling expecially when used in cross-cutting concerns scenario. See Singletons are Pathological Liars or Why Singletons are Evil for further reading.

From the other side, a state less singleton, if not abused, may be helpful and improve performance. Consider an example:

interface Interface
{
    void Method();
}

class StatelessSingleton : Interface
{
    public static readonly StatelessSingleton Instance = new StatelessSingleton();
    private StatelessSingleton() { }

    public void Method() { }
}

class User
{
    public User(Interface i) { /* ... */ }
}

Here, the StatelessSingleton acts as default implementation of the Interface and is put into the User constructor. There is no hard-coded coupling and hiden dependencies. We are unable to use a static class due to the underlying interface but there is no reason to create more than one instance of a default. That's why a stateless singleton seems to be an appropriate choice.

However, maybe we should use another pattern for a default implementation:

class Implementation : Interface
{
    private readonly Action _method;

    public Implementation()
    {
        _method = new Action(() => { /* default */ });
    }

    public Implementation(Action custom)
    {
        _method = custom;
    }

    public void Method()
    {
        _method();
    }
}

It hits the performance with respect to StatelessSingleton but constitutes a generic implementation of the Interface. Similar solution is used by IProgress interface.

Altough again, why allow to create more than one implementation of default behaviour? Yet we can combine the two:

class Implementation : Interface
{
    public readonly Implementation Default = new Implementation();

    private readonly Action _method;

    private Implementation()
    {
        _method = new Action(() => { /* default */ });
    }

    public Implementation(Action custom)
    {
        _method = custom;
    }

    public void Method()
    {
        _method();
    }
}

In conclusion, I believe that there are places (as depicted defaults) where Singletons are useful. The main definition of Singleton states that it disallow to create more than one instance of a class. It's as nuclear power. Can produce an energy or a bomb. It depends on human.


问:
What is the intention behind asking weight of plane?
I was asked this question "How would you find weight of Aeroplane" in an interview and I am not sure why this question was one of the two question asked in the interview.

I tried to answer it using all possible ways but could not give the correct answer.(found the correct answer after google search)

How much such questions decide your selection in the interview?

Here was my approach:
1. If measurement of plane is given then i will calculate volume and multiply by density, will consider fuel weight plus other dead weight.
2. Using water displacement method if i can put plane in water and somehow measure how much water is displaced.

But found using google search that right approach was to put place on a ship and mark the level of water on the hull, then remove plane and then ship will go up.
And start putting weight on the ship till marked hull reaches the water level.

答:
Reminds me of the Niels Bohr "measure the hieght of a building using a barometer" story

The purpose of these questions is twofold.

Is to see how you logically go about solving a problem (dos not matter if you don't come up with an answer as long as you demonstrate some reasonable thought process).

Is to see how you react under pressure. An unexpected question in a job interview is very stressful, will you prevaricate gracefully until you come up with an answer or break into a cold sweat and lose the power of speech.

Personally I would like to have answered ( but as it took me 10 minutes to think this up I probably would not have -- I am more of a cold sweat and silence kind of a guy :-) )

Count the number of wheels. Measure the air pressure of one of the wheels before and after takeoff ( after tires cool down) and calculate the difference in pressure.

```<code> footprint of tire in inches * pressure difference in psi * number of wheels
      = weight in pounds.
</code>```

Simple, unobtrusive and very approximate.

Body:
Reminds me of the Niels Bohr "measure the hieght of a building using a barometer" story

The purpose of these questions is twofold.

Is to see how you logically go about solving a problem (dos not matter if you don't come up with an answer as long as you demonstrate some reasonable thought process).

Is to see how you react under pressure. An unexpected question in a job interview is very stressful, will you prevaricate gracefully until you come up with an answer or break into a cold sweat and lose the power of speech.

Personally I would like to have answered ( but as it took me 10 minutes to think this up I probably would not have -- I am more of a cold sweat and silence kind of a guy :-) )

Count the number of wheels. Measure the air pressure of one of the wheels before and after takeoff ( after tires cool down) and calculate the difference in pressure.

 footprint of tire in inches * pressure difference in psi * number of wheels
      = weight in pounds.

Simple, unobtrusive and very approximate.


答:
If I remember correctly, this is one of the riddles described in the book "How Would You Move Mount Fuji?: Microsoft's Cult of the Puzzle -- How the World's Smartest Companies Select the Most Creative Thinkers"

The basic idea of these kind of question is to see the way people think about the problem, how do they analyse it, how do they solve it. The "correct" answer isn't always relevant. Microsoft idea was that thanks to such a interview questions, they could select inexperienced but very smart people, and train them to be great developers, rather than directly look for good experienced developers. While the concept might have been good idea in 1980s, it's been long phased out by Microsoft and other big tech companies. Still, the myth that "this is how MS/Google/FB hires best people" lingers on.

Title: What is the intention behind asking weight of plane?

Body:
I was asked this question "How would you find weight of Aeroplane" in an interview and I am not sure why this question was one of the two question asked in the interview.

I tried to answer it using all possible ways but could not give the correct answer.(found the correct answer after google search)

How much such questions decide your selection in the interview?

Here was my approach:
1. If measurement of plane is given then i will calculate volume and multiply by density, will consider fuel weight plus other dead weight.
2. Using water displacement method if i can put plane in water and somehow measure how much water is displaced.

But found using google search that right approach was to put place on a ship and mark the level of water on the hull, then remove plane and then ship will go up.
And start putting weight on the ship till marked hull reaches the water level.


问:
Any good, easy to learn from books or tutorials for learning assembly?
I've been a developer since 2009 and I've learnt a lot of languages since, but I've always wanted to understand and be able to code in the lowest level language so I can directly (or at least very close to directly) speak to machines through my code.

There was a point in time when someone showed me how to do an if statement in assembly, but out of all the books that I got, I could never really understand where/how to start learning to code in assembler.

any help please? I'm obsessed with learning this!

PS: if you have any software suggestions, I use ubuntu and am looking to convert to backtrack soon, so it would be preferred if you could give me something that'll be easily installed on debian linux, otherwise don't sweat it, give me the name of the windows software and I'll find an equivalent myself

答:
I am having a hard time answering this one tbh.

I found learning assembly language to be quite difficult indeed as a lot of knowledge is required on how the computer actually works before even considering to start looking into assembly language.

To get you started and if you do not posses the knowledge already, you should check out some college book lists on logic and computer design fundamentals or Digital Design and Computer Architecture.

I will not link any books regarding this topic as I find learning from books very subjective. I read them parallel while slowly starting to look into assembly languages.

Second problem is which assembly language to learn and with which tool:

I learnt SPARC Assembly back in the day, but my university switched to Intel x86 architecture which seems to make a little more sense.

Perhaps you should look into ths gcc compiler as a debugger, MASM for Windows or the GAS >.

There are tons of links and forums from there.

I would also advise you to join a group or find some like minded people after obtaining some fundamental knowledge on the topic. A few pair of eyes can really helped me out as i was programming Assembly.

Start small and slowly. Also Comment your code frequently and constantly.

It's tough but I found it very rewarding. Good luck.

**** edit ****

Here you go should give you a taste:

gcc assembly


问:
metro style on windows and android
I want to develop a rather simple app using windows 8 metro style for GUI. But i need this app to have the same appearance, GUI, for both platforms, so that end users that uses it both on PC and a mobile device to have the same visual experience and a flawless navigation.

So, does anyone have knowledge of a Java framework or library to satisfy these needs? Or maybe a method to create a web-based app using HTML, PHP, JScript etc. (maybe something using a local server, on the same machine, because a web server is out of discussion, at least for the moment)? Any idea, method, technology related to the subject is also helpful. And if what you are thinking at can be used for IOS too, the better.

答:
If I were to write a metro themed application on android, I'd probably see if I couldn't write  the equivalent in html and try to build an android application from that html page.

I noticed that Android does support the concept of web pages being shown.  Combine this with metro js which should greatly simplify your task towards making a metro themed web page and what you have is the workings of a perfectly functional android web application that would be easy to fix and could probably be ported to other devices quite easily as well.

However this is my approach.  You mentioned html and javascript, and so I assume you have some basic knowledge of these technologies.  If not, now is as good a time as any to learn.

Just a tip for you though, make sure the web application looks proper at low resolutions before porting it to android.  It will probably save you time.

Title: metro style on windows and android


答:
I know it's one of your constraints, but I'd honestly push as hard as you can to get a build server. Really.

Now I've got that off my chest, if one isn't available in the short term, potentially each environment could have its own settings repository that it looks to for server names, connection strings etc, so that a config or machine name change doesn't require physical files to change, but your admin staff (or who ever has responsibility) can change the settings in one place. Obviously each app contacts the repository via web services / wcf or whatever you fancy to get the settings. The app therefore only needs to know the location of the repository, and everything else is controlled by the admins.

Ultimately the way to get rid of manual mistakes from happening is to automate them, as you've said.


问:
What is the best way to track / record the current programming project you work on?
I have been in this problem for long time and I want to know how it's done in real / big companies project?

Suppose I have the project to build a website. Now I divide the project into sub tasks and do it.

But you know that suppose I have task1 in hand like export the page to pdf. Now I spend 3 days to do that , came across various problems, many Stack Overflow questions and in the end I solve it.

Now 4 months after someone told me that there is some error in the code.

Now by that I completely forgot about (60%) of how I did it and why I do this way. I document the code but I can't write the whole story of that in the code.

Then I have to spend much time on code to find what was the problem so that I added this line etc.

I want to know that is there any way that i can log steps in completing the project.
So that I can see how I end up with code, what errors I got, what questions I asked on SO and etc.

How people do it in real time? Which software to use?

I know in our project management software called JIRA we have tasks  but that does not cover what steps I took to solve that tasks.

What is the best way so that when I look back at my 2 year old project, I know how I solve particular task?

答:
If you are programmer, and want to remember why you wrote some piece of code(and you are very serious about it), then write unit tests(specifying the behaviour of the code) and functional tests(specifying behaviour of the modules).
This will not only help you to have specifications right there with the code and also will allow you to  make big  changes without producing any regression issues.
I can go on stating the advantages of unit and functional tests , but you will only realize their importance once you actually start writing them.
Initially it will take some time writing unit tests , but trust me that will be way less painful and time consuming then solving the regression issues.
And Jira do cover steps taken to make a feature , you can configure it to automatically attach commits made to solve a ticket to the ticket.
In our project we have configured it in such a way that if someone is commiting code to solve a ticket say HT-121 , then every commit with "HT-121  " in it is dirctly attached to that ticket. SO what code went for what commit can always be tracked with jira.</p>


问:
Do delegates defy OOP
I'm trying to understand OOP so I can write better OOP code and one thing which keeps coming up is this concept of a delegate (using .NET). I could have an object, which is totally self contained (encapsulated); it knows nothing of the outside world... but then I attach a delegate to it.

In my head, this is still quite well separated as the delegate only knows what to reference, but this by itself means it has to know about something else outside it's world! That a method exists within another class!

Have I got myself it total muddle here, or is this a grey area, or is this actually down to interpretation (and if so, sorry as that will be off topic I'm sure). My question is, do delegates defy/muddy the OOP pattern?

答:
If OOP means each object is responsible for its own interface, then logically delegates could break OOP if it were not used properly.   For example, if I made a FileStream class which, when asked to write, called a delegate to perform the write on behalf of the FileStream class, then it would breach OOP.  This is because the responsibility of the write operation of the FileStream is purely upon FileStream if we're following OOP to the letter.

However, this doesn't mean that using delegates always goes against OOP.  Using the same example, if I used a delegate to handle events before and after writes, this is still following OOP because it is not the responsibility of FileStream to know what should happen before and after writes.  It should merely notify the classes which are responsible.

If passing delegates to an object were breaching OOP because it knows something outside its world, then also passing variables would breach OOP since you could think of delegates as passing code rather than data to classes.  Acknowledging that there exists code outside of a single OOP class is not breaching anything.

Title: Do delegates defy OOP


答:
In my head, this is still quite well separated as the delegate only knows what to reference, but this by itself means it has to know about something else outside it's world!

But it doesn't. Your delegate is just a variable that when invoked calls something. If you have a string variable, it could contain anything. Your class isn't somehow breaking encapsulation if another class sets your string variable to "foobar". Likewise, your class' encapsulation is not broken if your delegate is set to "hide this UI widget when triggered".

Title: Do delegates defy OOP

Body:
I'm trying to understand OOP so I can write better OOP code and one thing which keeps coming up is this concept of a delegate (using .NET). I could have an object, which is totally self contained (encapsulated); it knows nothing of the outside world... but then I attach a delegate to it.

In my head, this is still quite well separated as the delegate only knows what to reference, but this by itself means it has to know about something else outside it's world! That a method exists within another class!

Have I got myself it total muddle here, or is this a grey area, or is this actually down to interpretation (and if so, sorry as that will be off topic I'm sure). My question is, do delegates defy/muddy the OOP pattern?


答:
The usual IANAL aside (I'm not a lawyer, this is not legal advice, get yourself a real lawyer if you want anything conclusive):

Both MIT and BSD (any flavor) are very permissive licenses, and you can bundle them with your application under any license you like, as long as you include the original copyright notice. BSD-3 adds the "no endorsement" clause, which means you cannot use the name of the copyright holders to promote your product.

So as long as you comply with the terms of those licenses (include the original copyright notices as to attribute the code to its authors), all three scenarios are probably OK. For the distributed executable, you'll have to check the license of whatever Python implementation you use, as well as those of any libraries you or Python itself link against, but my guess is that you should be fine.

Again, if you want to be 100% sure, ask a lawyer.

Title: How to incorporate existing open source software from a licensing perspective?

Body:
I'm working on software that uses the following libraries:

Biopython

SciPy

NumPy

All of the above have licenses similar to MIT or BSD.

Three scenarios:

First, if I don't redistribute those dependencies, and only my code, then all I need is my own copyright and license (planing on using the MIT License) for my code. Correct?

What if I use py2exe or py2app to create a binary executable to distribute so as to make it easy for people to run the application without needing to install python and all the dependencies. Of course this also means that my binary file(s) contains python itself (along with any other packages I might have performed a pip install xyz).

What if I bundle Biopython, SciPy, and NumPy binaries in my package?

In the latter two cases, what do I need to do to comply with copyright laws.


问:
What standards can be expected from graduate/junior engineers?
Are buffer overflows acceptable from a graduate developer? Are we setting the bar too high? What are the expected capabilities of graduate/junior engineers?

Context:

We are currently recruiting for a Junior Developer position working mainly in C on Linux.

As part of the process, we require candidates to complete a code test at their leisure in C.

So far we have rejected two candidates on the basis that their code, although readable and in one case rather idiomatic, suffered from buffer overflow errors due to unbounded buffer writes.

[Edit]:

We explicitly ask for error-checked, production quality code.

We provide a test & build framework for the candidates

[Update]:

As a result of this thread, and conversations we have had with other developers in person, we are changing the way we carry out code tests and who we target with our recruiting.

We decided that a candidate being unable to fix or understand a buffer overflow means that he would be unsuitable for the work we carry out, in particular he would take more mentoring than we are comfortable with. We will therefore still reject candidates that cannot eventually submit a robust code sample.

However, we have put in place some measures to make the recruitment process more productive for both us and the candidates.

In particular:

We make our expectation more explicit, with clear explanation of what we mean by production quality, and a warning that the code is expected to be robust with respect to input and errors.

We now link candidates to resources on defensive programming and the C standard library in the description of the code test.

We changed our target audience from Junior developers and graduates to target people with some relevant experience.

In case the submitted code fails in some way but would otherwise be accepted, we now provide a minimum test case that causes the error condition and give the candidates a chance to correct their mistakes (unless the code is rejected for some other reason). We'll also point out problematic lines/functions if appropriate.

The goal of the tests itself has now slightly changed from a front end filter to a chance to build a better picture of the candidate, in particular it will inform our phone discussion. That said, we are still willing to reject based solely on code.

[Update 2015-07-09]:
Andy Davis from Nujob has written an interesting and relevant article on the use of a code test from the candidate's perspective, and the article is worth looking at. Find it here.

答:
I don't think you've set the bar too high, I think you might need a different bar.

I think code tests are useful for determining the competency of a candidate, but they shouldn't be pass/fail. You should use the results of the code test to start a dialog with the candidate.

If you see mistakes that they've made (especially if they're junior developers) point them out and ask them what they'd do differently or if they understand why there is a problem.


答:
I think the junior qualifier is what makes all the difference here. Juniors shouldn't be tested for competence, they should be tested for learning ability, curiosity, passion, ethic, and definitely humility. The assumption with a junior should be that they are not competent, it's your job as the senior to make them so.

Obviously they should be able to write basic code like fizzbuzz and have a general knowledge of concepts; if you pointed it out to them and they didn't even know what a buffer overflow was, then I would say it's a no go, but I don't expect a junior to write more than 5 lines of code without a bug.

The day you trust your junior's competence is the day yours should be questioned, juniors should be treated with a lot of mentoring and a healthy dose of "trust but verify". I was a junior once, and to all those who were there at the time: I'm sorry. Remember the terrible things you did as a junior? (Please don't tell me it was just me; you'll give me a complex..)

Title: What standards can be expected from graduate/junior engineers?

Body:
Are buffer overflows acceptable from a graduate developer? Are we setting the bar too high? What are the expected capabilities of graduate/junior engineers?

Context:

We are currently recruiting for a Junior Developer position working mainly in C on Linux.

As part of the process, we require candidates to complete a code test at their leisure in C.

So far we have rejected two candidates on the basis that their code, although readable and in one case rather idiomatic, suffered from buffer overflow errors due to unbounded buffer writes.

[Edit]:

We explicitly ask for error-checked, production quality code.

We provide a test & build framework for the candidates

[Update]:

As a result of this thread, and conversations we have had with other developers in person, we are changing the way we carry out code tests and who we target with our recruiting.

We decided that a candidate being unable to fix or understand a buffer overflow means that he would be unsuitable for the work we carry out, in particular he would take more mentoring than we are comfortable with. We will therefore still reject candidates that cannot eventually submit a robust code sample.

However, we have put in place some measures to make the recruitment process more productive for both us and the candidates.

In particular:

We make our expectation more explicit, with clear explanation of what we mean by production quality, and a warning that the code is expected to be robust with respect to input and errors.

We now link candidates to resources on defensive programming and the C standard library in the description of the code test.

We changed our target audience from Junior developers and graduates to target people with some relevant experience.

In case the submitted code fails in some way but would otherwise be accepted, we now provide a minimum test case that causes the error condition and give the candidates a chance to correct their mistakes (unless the code is rejected for some other reason). We'll also point out problematic lines/functions if appropriate.

The goal of the tests itself has now slightly changed from a front end filter to a chance to build a better picture of the candidate, in particular it will inform our phone discussion. That said, we are still willing to reject based solely on code.

[Update 2015-07-09]:
Andy Davis from Nujob has written an interesting and relevant article on the use of a code test from the candidate's perspective, and the article is worth looking at. Find it here.


问:
Should Item Grouping/Filter be in the ViewModel or View layer?
I'm in a situation where I have a list of items that need to be displayed depending on their properties. What I'm unsure of is where is the best place to put the filtering/grouping logic of the viewmodel state?

Currently I have it in my view using converters, but I'm unsure whether I should have the logic in the viewmodel?

e.g.

ViewModel Layer:

```<code>class ItemViewModel
{
    DateTime LastAccessed { get; set; }
    bool IsActive { get; set; }
}

class ContainerViewModel
{
     ObservableCollection<Item> Items {get; set;}
}
</code>```

View Layer:

```<code><TextView Text="Active Items"/>
<List ItemsSource={Binding Items, Converter=GroupActiveItemsByDay}/>
<TextView Text="Active Items"/>
<List ItemsSource={Binding Items, Converter=GroupInActiveItemsByDay}/>
</code>```

or should I build it like this?

ViewModel Layer:

```<code>class ContainerViewModel
{
   ObservableCollection<IGrouping<string, Item>> ActiveItemsByGroup {get; set;}
   ObservableCollection<IGrouping<string, Item>> InActiveItemsByGroup {get; set;}
}
</code>```

View Layer:

```<code><TextView Text="Active Items"/>
<List ItemsSource={Binding ActiveItemsGroupByDate }/>
<TextView Text="Active Items"/>
<List ItemsSource={Binding InActiveItemsGroupByDate }/>
</code>```

Or maybe something in between?

ViewModel Layer:

```<code>class ContainerViewModel
{
   ObservableCollection<IGrouping<string, Item>> ActiveItems {get; set;}
   ObservableCollection<IGrouping<string, Item>> InActiveItems {get; set;}
}
</code>```

View Layer:

```<code><TextView Text="Active Items"/>
<List ItemsSource={Binding ActiveItems, Converter=GroupByDate }/>
<TextView Text="Active Items"/>
<List ItemsSource={Binding InActiveItems, Converter=GroupByDate }/>
</code>```

I guess my question is what is good practice in terms as to what logic to put into the ViewModel and what logic to put into the Binding in the View, as they seem to overlap a bit?

答:
I'm not sure there is a single correct answer here but I prefer to do the grouping in the XAML using a CollectionViewSource where I can.  For example, something like the following might work for you:

```<code><CollectionViewSource x:Key="groupedItems" Source="{Binding Items}">
    <CollectionViewSource.GroupDescriptions>
        <PropertyGroupDescription PropertyName="IsActive"/>
        <PropertyGroupDescription PropertyName="LastAccessed"/>
    </CollectionViewSource.GroupDescriptions>
</CollectionViewSource>

<ListBox ItemsSource="{Binding Source={StaticResource groupedItems}}"/>
</code>```

Body:
I'm not sure there is a single correct answer here but I prefer to do the grouping in the XAML using a CollectionViewSource where I can.  For example, something like the following might work for you:

<CollectionViewSource x:Key="groupedItems" Source="{Binding Items}">
    <CollectionViewSource.GroupDescriptions>
        <PropertyGroupDescription PropertyName="IsActive"/>
        <PropertyGroupDescription PropertyName="LastAccessed"/>
    </CollectionViewSource.GroupDescriptions>
</CollectionViewSource>

<ListBox ItemsSource="{Binding Source={StaticResource groupedItems}}"/>


答:
A buffer overflow is an absolute no-go. You could have a corresponding code question.
In a what all is wrong (can go wrong) with this piece of code the candidate should be able to pinpoint the problem. The question is, whether the issue is irrelevant, as you are running clint anyway.

However in an artificial free-form code test I would be mild on a violation like sprintf. Too little time (assumed), mind hyperactive, too large an urge to present something working.


问:
What grammatical tense should I write my specifications in?
We are currently writing functional and technical specifications in a two column format; summary sentence and technical detail. The details often refer to an appendix with diagrams, layout designs ect.

However I am struggling with what tense to write it in:

With past tense as if the work is done I struggle to show highlight extensions of exiting work. Future tense as in it needs to do X starts to sound like a to do list or Tense neutral very hard as it has either going to be done or is done.

To add further confusion this specification may be read by people who do not have English as a first language.

答: When I create designs for software I favor present tense, even if I create the designs before the software exists. Even after a software application is implemented from the design, the design is still relevant and important document. It's quite possible that a design document may remain relevant for longer period of time after software is implemented than before it is implemented.</p>


答:
Grouping and filtering is one of the explicit purposes of a View Model as opposed to just using a Model. The view model takes the data from the model and organizes it precisely for the given view.

That means where a model may often be a robust data representation, and the view only needs a subsection or aggregate of that model, the view model exists to give you the data your view needs so that your view does not need to do that leg work.

It can be confusing because often times people write code that has the view going straight to the model and in these cases the view does end up responsible for this work, but if you do use view models as an intermediary, you don't need to and shouldn't be doing this non-presentational work in the view.

Title: Should Item Grouping/Filter be in the ViewModel or View layer?

Body:
I'm in a situation where I have a list of items that need to be displayed depending on their properties. What I'm unsure of is where is the best place to put the filtering/grouping logic of the viewmodel state?

Currently I have it in my view using converters, but I'm unsure whether I should have the logic in the viewmodel?

e.g.

ViewModel Layer:

```<code>class ItemViewModel
{
    DateTime LastAccessed { get; set; }
    bool IsActive { get; set; }
}

class ContainerViewModel
{
     ObservableCollection<Item> Items {get; set;}
}
</code>```

View Layer:

```<code><TextView Text="Active Items"/>
<List ItemsSource={Binding Items, Converter=GroupActiveItemsByDay}/>
<TextView Text="Active Items"/>
<List ItemsSource={Binding Items, Converter=GroupInActiveItemsByDay}/>
</code>```

or should I build it like this?

ViewModel Layer:

```<code>class ContainerViewModel
{
   ObservableCollection<IGrouping<string, Item>> ActiveItemsByGroup {get; set;}
   ObservableCollection<IGrouping<string, Item>> InActiveItemsByGroup {get; set;}
}
</code>```

View Layer:

```<code><TextView Text="Active Items"/>
<List ItemsSource={Binding ActiveItemsGroupByDate }/>
<TextView Text="Active Items"/>
<List ItemsSource={Binding InActiveItemsGroupByDate }/>
</code>```

Or maybe something in between?

ViewModel Layer:

```<code>class ContainerViewModel
{
   ObservableCollection<IGrouping<string, Item>> ActiveItems {get; set;}
   ObservableCollection<IGrouping<string, Item>> InActiveItems {get; set;}
}
</code>```

View Layer:

```<code><TextView Text="Active Items"/>
<List ItemsSource={Binding ActiveItems, Converter=GroupByDate }/>
<TextView Text="Active Items"/>
<List ItemsSource={Binding InActiveItems, Converter=GroupByDate }/>
</code>```

I guess my question is what is good practice in terms as to what logic to put into the ViewModel and what logic to put into the Binding in the View, as they seem to overlap a bit?


问:
Is Moving Entity Framework objects over a webservice really the best way?
I've inherited a .NET project that has close to 2 thousand clients out in the field that need to push data periodically up to a central repository. The clients wake up and attempt to push the data up via a series of WCF webservices where they are passing each entity framework entity as parameter. Once the service receives this object, it preforms some business logic on the data, and then turns around and sticks it in it's own database that mirrors the database on the client machines.

The trick is, is that this data is being transmitted over a metered connection, which is very expensive. So optimizing the data is a serious priority. Now, we are using a custom encoder that compresses the data (and decompresses it on the other end) while it is being transmitted, and this is reducing the data footprint. However, the amount of data that the clients are using, seem ridiculously large, given the amount of information that is actually being transmitted.

It seems me that entity framework itself may be to blame. I'm suspecting that the objects are very large when serialized to be sent over wire, with a lot context information and who knows what else, when what we really need is just the 'new' inserts.

Is using the entity framework and WCF services as we have done so far the correct way, architecturally, of approaching this n-tiered, asynchronous, push only problem? Or is there a different approach, that could optimize the data use?

答:
I would say that transfering the entity framework objects over WCF is a bad idea. Any time you do any kind of operation on an EF object, it will generally result in database calls. This can be bad enough for performance when it is all being done in the one service, and adding an extra tier over network connection will really slow things down!

There is concept/pattern called the DTO (data transfer object) pattern that involves creating new simpler types that just contain all the information that will be required in the client and passing this instead.

You then create a DTO Assembler which is responsible for building DTOs from your entity framework models.

Googling DTO's will hopefully be a good starting point for you.  Here is an example link at MSDN


答:
You can use some Data Transfer Objects (DTO) only  to transfer objects from the clients to the server and the other way around. Obviously the structure of this  lightweight objects should be shared aross the system (clients) in order to have the ability of serializing and deserializing. This approach is commonly used to reduce the amount of data tranferred and to avoid the exposition of the domain.

I guess that your current implementation is like that so the domain objects are used across the system and all the clients are able to understand the objects that they recieve/send. It would be the same concept with DTO's.

This process of converting Domaing models to DTO's will also have an impact in the performance, however is much smaller and probably not a problem in your context.

In the Application Layer that will be responsible for mapping Domin Models to DTO (and viceversa) you can use AutoMapper, which is a very nice library to do this work.

Title: Is Moving Entity Framework objects over a webservice really the best way?

Body:
I've inherited a .NET project that has close to 2 thousand clients out in the field that need to push data periodically up to a central repository. The clients wake up and attempt to push the data up via a series of WCF webservices where they are passing each entity framework entity as parameter. Once the service receives this object, it preforms some business logic on the data, and then turns around and sticks it in it's own database that mirrors the database on the client machines.

The trick is, is that this data is being transmitted over a metered connection, which is very expensive. So optimizing the data is a serious priority. Now, we are using a custom encoder that compresses the data (and decompresses it on the other end) while it is being transmitted, and this is reducing the data footprint. However, the amount of data that the clients are using, seem ridiculously large, given the amount of information that is actually being transmitted.

It seems me that entity framework itself may be to blame. I'm suspecting that the objects are very large when serialized to be sent over wire, with a lot context information and who knows what else, when what we really need is just the 'new' inserts.

Is using the entity framework and WCF services as we have done so far the correct way, architecturally, of approaching this n-tiered, asynchronous, push only problem? Or is there a different approach, that could optimize the data use?


问:
Sorting versus hashing
My problem is as follows.  I have an array of n strings with m < n of them distinct.  I want to create a one-to-one function which assigns each of the m distinct strings to the numbers 0 ... m-1.  For example, if my strings are:

Bob, Amy, Bob, Charlie, Amy

then the function:

Bob -> 0, Amy -> 1, Charlie -> 2

would meet my needs.  I have thought of three possible approaches:

Sort the list of strings, remove duplicates, and construct the function using a search algorithm.

Create a hash table and check each string to see if it is already in the table before inserting it.

Sort the list of strings, remove duplicates, and put the resulting list into a hash table.

My code will be written in Java, and I will likely use standard Java algorithms: merge sort for sorting, binary search for searching, and whatever the standard Java hash table algorithm is.

Question: Assume that after creating the function I will have to evaluate it on each of the n original strings.  Which of the three approaches is fastest?  Is there a better way?

Part of the problem is that I don't really know what's going on "under the hood" in standard hashing algorithms.  Any help would be appreciated.

答:
Firstly, I'll note that there are two different things to be concerned with. How long will it take to assign all the numbers, and how long will it take to lookup the number later.

Sort the list of strings, remove duplicates, and construct the function using a search algorithm

Sorting will take O(n log n) time, you can remove the duplicate in O(n) time. To lookup the number you can use binary search which will take O(log m) time for each search.

Create a hash table and check each string to see if it is already in the table before inserting it.

Hash table operations are typically considered to be O(1). This is a bit of lie because it depends on the number of collisions you get. But its close to O(1) and definitely better then O(log m). Checking and inserting all values will then be O(n). Fetching the counts later will be O(1) for each fetch.

Sort the list of strings, remove duplicates, and put the resulting list into a hash table.

Sorting and deduplicating will take O(n log n) time. Inserting all of that into a hash will take O(m) time. Then fetching the individual elements will take O(1) time. This is basically the same as the previous option except that you spend O(n log n) extra time sorting.

The second option will be fastest, at least for large enough cases.

Title: Sorting versus hashing


答:
A delegate is just another piece of data, an invokable bit of data, true, but still just data.  It can be passed to another object, or exposed to and then changed by another object.  Your object does not necessarily know about another object -- your object could have the delegate set to a method inside itself.

You as the programmer know more, but the class doesn't have to. Delegates make methods into data, and that is a good thing...

Title: Do delegates defy OOP


问:
Class instance clustering in object reference graph for multi-entries serialization
My question is on the best way to cluster a graph of class instances around specifically marked objects (objects are the graph nodes and the references to each other are the directed edges of the graph). To better explain my question, let me explain my motivation:

I currently use a moderately complex system to serialize the data used in my projects:

"marked" objects have a specific attributes which stores a "saving entry": the path to an associated file on disc (but it could be done for any storage type providing the suitable interface)

Those object can then be serialized automatically (eg: obj.save())

The serialization of a marked object 'a' contains implicitly all objects 'b' for which 'a' has a reference to, directly s.t: a.b = b, or indirectly s.t.: a.c.b = b for some object 'c'

This basically define specific storage entries to specific objects. I then have "container" type objects that:

can be serialized similarly (in fact their are or can-be "marked")

they don't serialize in their storage entries the "marked" objects (with direct reference): if a and a.b are both marked, a.save() calls b.save() and stores a.b = storage_entry(b)

So, if I serialize 'a', it will serialize automatically all objects that can be reached from 'a' through the object reference graph, possibly in multiples entries. That is what I want, and it usually provides the functionalities I need. However, there are some structural limitations to this approach:

the multi-entry saving can only works through direct connections in "container" objects, and

there are situations with undefined behavior such as if two "marked" objects 'a'and 'b' both have a reference to an unmarked object 'c'. In this case my system will stores 'c' in both 'a' and 'b' making an implicit copy which not only double the storage size, but also change the object reference graph after re-loading.

I am thinking of generalizing the process. Apart for the practical questions on implementation (I am coding in python, and use Pickle to serialize my objects), there is a general question on the way to attach (cluster) unmarked objects to marked ones.

So, my questions are:

What are the important issues that should be considered? Basically why not just use any graph parsing algorithm with the "attach to last marked node" behavior.

Is there any work done on this problem, practical or theoretical, that I should be aware of?

Example of a simple object graph to serialize:

Circles are objects and arrow references. Orange circles are marked objects.

When serializing A, object B to E should be serialized but not blue objects because they are not reachable from A. Now, B is serialized in its own entry (i.e. file) and the question is how to choose where to serialize objects C to E, to A or B entry?

Some thinking on this example:

object C is only reachable from A, so its should be attached to it

to reach E, it is necessary to pass by B, so E should be attached to B

what about D? Because after serialization if B is loaded (and not A), D should also be loaded but not A. Thus D should be serialized in B entry.

Note:
I added the tag database because I think the answer might come from that fields, even if the question is not really.

答:
It looks like there's a missing conceptual step going on here. An object reference is not the object itself. So, perhaps consider serializing object references, and don't serialize object c inside a or b, for example. Serialize object c outside of them, and you save space and processing time.

Edit:
Basically, it would work like this:

```<code>foreach(object reference in serializeable)
    serialize(object in global)
    serialize(object reference)
</code>```

Then, when you deserialize, you just make the object reference point back to the correct object.

Body:
It looks like there's a missing conceptual step going on here. An object reference is not the object itself. So, perhaps consider serializing object references, and don't serialize object c inside a or b, for example. Serialize object c outside of them, and you save space and processing time.

Edit:
Basically, it would work like this:

foreach(object reference in serializeable)
    serialize(object in global)
    serialize(object reference)

Then, when you deserialize, you just make the object reference point back to the correct object.


问:
When does "proper" programming no longer matter?
I've been building an android game in my spare time. It's using the libgdx library so quite a bit of the heavy lifting is done for me.

While developing, I carelessly selected datatypes for some procedures. I used a hashtable because I wanted something close to an associative array. Human readable key values. In other places to achieve similar things, I use a vector. I know libgdx has vector2 and vector3 classes, but I've never used them.

When I come across weird problems and search Stack Overflow for help, I see a lot of people just reaming the questions that use a certain datatype when another one is technically "proper." Like using an ArrayList because it does not require defined bounds versus re-defining an int[] with new known boundaries. Or even something trivial like this:

```<code>for(int i = 0; i < items.length; i ++)
{
    // do something
}
</code>```

I know it evaluates item.length on every iteration. However, I also know items will never be more than 15 to 20 items. So should I care if I evaluate items.length on every iteration?

I ran some tests to see how the app performs using the method I just described versus the proper, follow the tutorial and use the exact data types suggested by the community. The results: Same thing. Average 45 fps. I opened every app on the phone and galaxy tab. No difference.

So I guess my question to you is this: Is there a threshold when it no longer matters to be proper? Is it ok to say - "so long as it gets the job done, I don't care?"

答:
Your question is "so long as it gets the job done, I don't care?"

My answer is, "you never know what will happen to your code."  I've been involved in so many projects that started out as "hey let me write this quick thing to take care of a user's problem."  Write it, put it out there, never think about it again.

One time, that thing I wrote morphed into "oh, now the user's entire department wants to use that code," which before I could turn around became "the entire company is using that code and now I have to prove it will survive an audit and there's a 20-person code review scheduled for tomorrow and some vice president has already sold it to our customers."

I realize you're "just writing an android game in your spare time" but you never know if that game will take off and become your ticket to fame and fortune.  Worse yet, that game could become your ticket to infamy because it keeps crashing people's phones.  Do you want to be the person who gets a job offer because someone's kids can't stop playing your game on their phones, or do you want to be the person who gets vilified on message boards like this one?