答:
integers and real (float,double) numbers are conceptually different types with different sets of operations and intrinsic properties.

Integers are enumerable but floats are not, etc.

In fact Float/double number is a structure that combines two integer fields: mantissa and exponent. Complex numbers (that you excluded from consideration) are even more, well, complex.

Any practical language should have at least integers and floats as distinct types - too different operations on them.


问:
Why are there so many numeric types (bit, int, float, double, long)?
I've learned PHP, Java, and C. Now I'm curious as to why there are so many types of numerical data types like bit, int, float, double, and long. Why not make only one type for numericals?

Is there any benefit to this? Maybe if we use integers to hold such small numbers we can save memory?

答:
In addition to cpmjr123's excellent points about memory scarcity and precision and range trade offs, thers is also potentially a CPU trade off.

Most modern machines have special hardware for performing floating point operations called an FPU. There are also systems that do not have FPU's (nowadays these are typically small embeded devices), consequently, depending on your target hardware, you would either have to not use floating point types at all or use a software floating point library. Even if your machine has an FPU there were historically differences in what functions it could provide. Any functions not done in hardware would have to be done in software (or avoided)

Doing floating point calculations in software is done by performing many simpler operations the hardware does support. You therefore get a potential speed trade off as well.

ContentLicense: CC BY-SA 3.0


问:
Ship Early, Ship Never
This started as a "Note to Self," so please excuse me if the frustration is all too evident and the writing is less than stellar...

Three major subjects I've had at the forefront of my mind lately:

Motivation

Learning (Curiosity)

Doing (Making)

I've been studying motivation and incentives for months now. It seems there are an infinite number of different motivations that people might have for doing things (I realize that sounds trite but bear with me). I've been really drawn to it because I'm desperate to find out why I do the things I do and why I don't do the things that I want to do but don't do.

I'm in the midst of reading Paul Graham's excellent Hackers and Painters book. In it, he makes the case that hackers and painters are very similar because they are both "makers." Painters make paintings. Hackers make software. Painters don't necessarily need to understand the chemical composition of paint to make beautiful paintings. And hackers don't necessarily need to know 1's and 0's to make beautiful software.

Graham then draws the distinction between disparate computer science fields:

some people seem to be studying mathematics

some people seem to be studying the computers themselves

the hackers are making software.

The difference is incredibly important. It seems the motivation for some is to make beautiful things. And the motivation for the others is to learn out of curiosity. Certain motivations seem obvious to me, but curiosity seems a bit less obvious. I would certainly consider myself as a curious person with a seemingly unquenchable thirst to learn just about everything I can. But this is exactly where the problem comes up.

The thing that scares me so much is that I desperately want to make things. I desperately want to do things. I want to write a book. I want to paint a painting. I want to compose a song. I want to do things like travel. But the strangeness is that I also want to learn things. I want to learn to play guitar. I want to learn about art history. I want to learn more about philosophy and literature.

The key seems to be the balance between learning and doing... between studying and making.

While I'm not sure how much one should learn about a given thing before doing it, I know for certain that I find myself constantly on one side rather than the other. As it stands now (and as far as I can tell I've always been this way), I am a learner and not a doer. I've read great books. I've practiced guitar for years. I've spent countless hours studying programming.

But I've written 0 books. I've composed 0 songs. I've coded 0 beautiful programs. I've painted 0 beautiful paintings. I've started 0 viable businesses.

The scary part of all this is that there are probably countless unfinished works of art in the world. Is this my misanthropic revenge against society and culture to never produce or finish any of the works of art that I start? Perhaps the worst part (aside from this being my natural inclination), is the fact that I f***ing know better. I just finished books like "Getting Things Done" and "Making Ideas Happen." I've aggregated and synthesized countless words of wisdom on how to do things and how to make things.

Imagine the horror of going through life without being able to do the things you want to do. If this is something you've struggled with (and hopefully overcome), please share. If not... perhaps some delicious pity would make me feel better.

[UPDATE: Just wanted to send a quick thanks to everyone that shared their thoughts. I deliberately left the question somewhat open-ended in hopes of encouraging discussion and having others refashion the central problem around their similar experience, and I think it worked out great... there's a lot of amazing insight here to work with and it was really helpful. Thanks again.]

答:
I'd suggest you get a book called The Artist's Way by Julia Cameron.

It is about how to break those blocks.

One thing to remember is none of us start out as experts at making anything. Not art not software, not music, not writing. The way people learn best is to try and fail and try it differntly and fail and try it differnently again until you succeed (watch a child learn to walk). If you don't do the try and fail steps, you won't get to the succeed part. Every piece of software doesn't have to be a work of art, every painting doen't have to be good, etc. as long as you learn something from them. I create fractal art and I make some every day - some of it works and some doesn't but I wouldn't get to the pieces that work if I didn't keep plugging away creating and finding out what doesn't work. Professional photographers take thousands of photos but only a very small percentage of them are good enough to publish or sell. Look at the stuff that didn't work and try to figure out something to do differntly next time to make it work better. You sound like an analytic person, so this step should be easy for you. Just don't keep making the same mistakes repeately without trying to change something.

ContentLicense: CC BY-SA 2.5

Title: Ship Early, Ship Never


问:
Cold, neutral attitude to programming languages - sign of a pro developer or not
A profesional developer Zed Shaw says this:

Which programming language you learn and use doesn't matter. Do not
  get sucked into the religion surrounding programming languages as that
  will only blind you to their true purpose of being your tool for doing
  interesting things.

So, being neutral to languages is a sign of a good/pro developer?
We see worshipping and holywars what language is better.

The good coder does not care about tools, he only thinks what software he writes
(like writer does not care about pen he uses - he thinks about the BOOK content)

should a programmer develop total ignorance to language as tool he uses?

is it a sign of pro developer, if he does not care what language to use?

答:
"Total ignorance" is not the right thing.

A developer should know about the strengths and weaknesses of his tool: Don't use a screwdriver to drive a nail into a wall. (And if all you have is a screwdriver, you should at least know that a hammer would be better.)

Fandom, on the other hand, should be avoided. ("I would never touch anything but an ACME hammer!")


答:
A good coder, like any good craftsman, does and should care about his tools.

In answer to point 1. A professional developer should gain a deep knowledge of the tools he is using as far as it is relevant to the task at hand.

In answer to point 2. "Not caring" is perhaps too strong a wording. But unless he or she is specifically tasked with selecting the tooling and programming language,  then they should accept the chosen tool set and get on with the job.

Having said that I personally carry a "box of tools" around. Some are programs, scripts, perls, awks of my own devising, some, are freely available tools like gvim, squirrel, SOAPUI.
I often use these in preference to the "official" tool sets purely because they work well, and, improve my productivity.

As for language "wars" any professional should get over this. Depending on the task at hand you will find yourself implementing solutions in a variety of languages. My current task, which is admittedly somewhat weird, involves coding in C#,VBA,COBOL,Rexx and JCL with a little bit of Java thrown in. Whereas its a pleasure to code in C# and a pain to code in COBOL, COBOL is the right tool for that part of the project so there is no point in complaining about it; I just write the best COBOL I can.

Title: Cold, neutral attitude to programming languages - sign of a pro developer or not

Body:
A profesional developer Zed Shaw says this:

Which programming language you learn and use doesn't matter. Do not
  get sucked into the religion surrounding programming languages as that
  will only blind you to their true purpose of being your tool for doing
  interesting things.

So, being neutral to languages is a sign of a good/pro developer?
We see worshipping and holywars what language is better.

The good coder does not care about tools, he only thinks what software he writes
(like writer does not care about pen he uses - he thinks about the BOOK content)

should a programmer develop total ignorance to language as tool he uses?

is it a sign of pro developer, if he does not care what language to use?


答:
Perhaps the most important thing is that there are really three different basic number types.

integer, fixed decimal and floating point.

They all behave differently.

A simple operation like 7/2 could give answers of 3, 3.50 and 3.499 depending on the data type used.

"fixed decimal" is the Cinderella type, it is only supported natively in a few languages like COBOL and VisualBasic. It is of little interest to computer scientists but is vital to anyone submitting a set of accounts or calculating sales tax on an invoice.

Title: Why are there so many numeric types (bit, int, float, double, long)?

Body:
I've learned PHP, Java, and C. Now I'm curious as to why there are so many types of numerical data types like bit, int, float, double, and long. Why not make only one type for numericals?

Is there any benefit to this? Maybe if we use integers to hold such small numbers we can save memory?


答:
Programming languages are at the heart of programming and a professional programmer can care deeply about them. Nevertheless in lots of cases with mainstream languages the differences are marginal or not fundamental. Therefore for a professional developer these should not be reasons to complain loudly about trivial differences.

However, there are subtle differences between languages and these are real concerns because when switching between them even a professional programmer will end up doing mistakes, just because she/he thinks that C# is really not that different from java, or javascript is ruby with curly braces...

With the programming world becoming more and more polyglot and more and more languages with different concepts being available there is definitely the need to discuss plattforms' strengths and weaknesses. This is actually more relevant than some "language wars" of the past (C vs. Pascal or C vs. C++ that was a proxy discussion about programming paradigms). Evaluating your tools is professional.

There are sites and examples that are at times bashing certain programming languages. These range from quite negative to "funny awkward things in my favourite programming language". One way is to view those as negative critique that does not lead anywhere, but in the end they give valuable information on the programming language:

http://wtfjs.com/ on JavaScript

http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/

Without thinking about our tool, we cannot be professional. That being said you should be able to work with bad tools as a programmer.

Conclusion: The professional programmer cares about programming languages because she/he cares about tools. Like a car driver she/he has favourites and knows the weaknesses and benefits (and the dangers of a car without Airbags). In the end he will drive them all if necessary or be really cautious (when driving that australian road-train truck).


问:
Two libraries connecting to the database, leading to code smell?
In the current company that I work for there is a very large Utilities library. It was written a few years back (long before I joined) and has grown ergonomically over time to now do everything:

Sending Emails

Exporting Files in different formats, i.e. CSV, tab delimited

Receiving data from 3rd party providers, i.e. Bloomberg, Facset

Sending files to SFTP sites

Generic database connection

The list goes on and it is pretty ugly really.

The original developer here used it in every application that he wrote for convenience sake and added to it as necessary. The utilities library itself has references to 3rd party API’s to do some data receiving from Bloomberg/Factset. Using these 3rd party API’s means that any project that wants to reference the large Utilities library also then needs to have the Bloomberg API’s and Facset API’s with it. The list is starting to grow too and it is becoming very unmaintainable and unnecessary to have all these 3rd party DLL’s accompanied with this large Utilities project but are required to compile it.

I want to rewrite this entire library it to more manageable libraries. i.e:

CompanyName.Email

CompanyName.FileExporter

CompanyName.Bloomberg

Each project will then only reference the necessary projects it needs to get its job done. i.e. reference the CompanyName.Email to send emails.
I have no issues doing that, but the complication facing me is that some of the new libraries will require their own database connection and queries.
The example below is:

```<code>[HolidayChecker]
[HolidayChecker.DAL]
</code>```

We store a list of holiday days in the database. What I would want the HolidayChecker project to do is expose a method (amongst others) to check if a particular date is a holiday.

```<code>public interface IHolidayChecker
{
    bool IsHoliday(DateTime dateToCheck);
}
public class HolidayChecker : IHolidayChecker
{
    public bool IsHoliday(DateTime dateToCheck)
    {
        //Query database for date logic...
    }
}
</code>```

Many applications will then reference this HolidayChecker project and use the IsHoliday method. These applications will also have their own connection and queries to the database to perform their own tasks.

```<code>[GenericApplication (References HolidayChecker)]
[GenericApplication.BusinessLogic]
[GenericApplication.DAL]
</code>```

If the application and the HolidayChecker project both access the database and query the data, this comes across heavily as code smell. Is anyone aware of a tidier way of achieving this? Or is there? Is this something I will just have to live with?

EDIT:

Thinking about this overnight, I don't think it is a bad as first thought. Projects like ELMAH are stand alone that also connect to the database and do their own queries. As @Allan pointed out, it is just a matter of designing my HolidayChecker project correctly.

答:
If I need to deal with the database, I would like to have a single library that provides all the functionality for that database. It's OK if you have a large database with lots of operations, the key is to divide the operations into logcal namespaces and classes.

You just want to make sure you are not using the database for a lot of unrelated things. This would be like having a class with low cohesion (there is weak connection between the public methods). If this is the case then split it into two databases and then you can have one library for each.


问:
In languages that don't allow underscores in integer constants, is it a good practice to create a constant for 1 billion?
In languages that don't allow underscores in integer literals, is it a good idea to create a constant for 1 billion?  e.g. in C++:

```<code>size_t ONE_BILLION = 1000000000;
</code>```

Certainly, we shouldn't create constants for small numbers like 100.  But with 9 zeros, it's arguably easy to leave off a zero or add an extra one in code like this:

```<code>tv_sec = timeInNanosec / 1000000000;
tv_nsec = timeInNanosec % 1000000000;
</code>```

答:
Most languages feature some kind of exponential notation. A million is 1e6, (meaning 1 times 10 to the power of 6). This basically solves the issue even better than most propositions here.

In a lot of C-like languages, the scientific notation is however defining a floating point type, which is unfortunate if you really need an int. However, you can easily type-cast that constant to avoid implicit conversions in your formular.

n / int(1e9) would divide by a billion.

In your example, dealing with physical quantities (time in nanosecond), I would generally ask myself whether integer is the right type. In fact a floating point double might be better suited when dealing with measurable quantities (although there are of course cases where you would prefer a long long).


问:
Suitable algorithm for joining records from multiple databases
I am in the process of writing a library that is used to be able to access data from a database. The library requires the initial definition of all the tables that the application will be using in the form of classes that extend an abstract class within the library.

These classes contain the database connection the table is stored in, the table name, the columns, the indices, and the relationships between tables. The abstract class contains static functions that allow a user to select or insert rows into that particular database.

The select function returns an object that allows a query to be assembled, that provides options for the fields, joins, where, group, having, order, and limit, which culminates in a fetch function that returns an object that contains the resultant records along with save and delete functions.

Now, this works fine when it is working between tables within the same database, when being combined with tables in other database, but I am trying to get it so that I can do something like this:

```<code>class tabA extends tableBase {
    public static $database  = 'mySqlDB';
    public static $tablename = 'tableA';
    public static $columns   = array(
        'tableAID'       => 'int(11)',
        'tableAKey'      => 'varchar(128)',
        'tableBRefID'    => 'int(11)',
    );
}

class tabB extends tableBase {
    public static $database  = 'oracleDB';
    public static $tablename = 'tableB';
    public static $columns   = array(
        'tableBID'       => 'int(11)',
        'tableBSpecial'  => 'boolean',
        'tableBValue'    => 'text',
    );
}

tabA::select()->join('tabB', 'LEFT')->where(andCondition(eqCondition(tabA::tableAKey, 'foo'), eqCondition(tabB::tableBSpecial, true)))->fetch()
</code>```

Where the return of fetch would comprise of rows containing the found columns from the two databases.

The drivers for the databases use a common interface, of which the select function looks like:

```<code>function select ($columns, $from, $joins, $where, $group, $having, $order, $limit, $offset)
</code>```

I am aware that the tableBase class will have to break up the query it will be performing into two separate queries, one to query from tabA, and one from tabB, then join the results in the defined type (in this case, LEFT join). But I am having problems coming up with a suitable algorithm for dividing the query into two separate query blocks, then how to combine the results (satisfying the where condition) in an efficient manor.

My thoughts so far would entail stripping out the columns (excluding fields that are derived from operations between data over the two databases) and conditions that are relevant to each database, using those searches on each database, passing through the results of the main database table results and joining data (discarding rows that don't match the join), (at this point, if there are any derived fields as stated above, they are computed), then finally passing through all the resultant rows to ensure that any remaining where or having conditions are matched, and applying any final orderings.

But to my mind, this doesn't seem the most efficient manor, and creates issues when using limits, unless fetches all the rows, then applies the limit operation on the final result.

So, are there any resources, or information on how such a thing could be accomplished in a better/more efficient/neater way?

ADDITIONAL

Although these are SQL databases, a NoSQL database could work as long as the driver built operates within the confines of the database driver interface. At the moment, there is only one driver that uses PDO, but I am working on building drivers for XML and MongoDB datastores.

答:
Bear with me if this is a simplistic answer, but I don't think I see anything specifically forbidding this in your question.

If you added database specifiers to the table specifiers in your SELECT, then you'd pass the burden of cross-database handling to the database servers. Several RDBMS allow this.

E.g. instead of

```<code>USE a; SELECT x FROM test;
USE b; SELECT x, y FROM test;
(emulation of JOIN between the two cursors)
</code>```

you would use

```<code>SELECT db2.test.y FROM db2.test JOIN db1.test ON db1.test.x = db2.test.x;
</code>```

Of course your driver would then be less than "universal", and less (or not at all) parallelizable, and you would not be able to split tables between two different servers, or two different RDBMSes (MySQL and Postgres), or even two different access levels to the same server. But maybe the advantages in development time and debugging garnered this way would be worth these limitations?

Body:
Bear with me if this is a simplistic answer, but I don't think I see anything specifically forbidding this in your question.

If you added database specifiers to the table specifiers in your SELECT, then you'd pass the burden of cross-database handling to the database servers. Several RDBMS allow this.

E.g. instead of

USE a; SELECT x FROM test;
USE b; SELECT x, y FROM test;
(emulation of JOIN between the two cursors)

you would use

SELECT db2.test.y FROM db2.test JOIN db1.test ON db1.test.x = db2.test.x;

Of course your driver would then be less than "universal", and less (or not at all) parallelizable, and you would not be able to split tables between two different servers, or two different RDBMSes (MySQL and Postgres), or even two different access levels to the same server. But maybe the advantages in development time and debugging garnered this way would be worth these limitations?


问:
Strategy for reading and understanding Node.js code
Concretely I am looking at this 2000 line file of what I will pretty arbitrarily call "mediocre" code.

It's not well-commented

variable names and function names seem consistently intelligent

functions are not well-documented

functions are good length

In short:  its lines and small structures are readable, but it's impossible to infer architecture or design at a glance.  Most code I've worked on can be described thusly, to be fair.

So I need to understand this.  And work on it.  This is an important skill in software development I'm still weak at, and it's extremely important when working in a nascent system.

So my question is, when encountering foreign code like this that I am employing as client code but now need to understand and modify, what is a quick strategy for having a good understanding?

答:
I would suggest a top-down approach:

Investigate the build system, including the versioning system, make sure you are not looking at "experimental" branch.

Investigate the overall structure of the code.

Investigate the structure, the test system uses and use the implemented tests to help you understand the code itself.

Investigate each module and ascertain its purpose and document it.

Now you should be able to pinpoint the module which needs changing.


答:
Does the code have tests? (there weren't any in that link). If it does that's a great place to start as the tests should tell you the expected behavior of each module.

If it doesn't then write some. Make an educated guess  about a function or group of functions and how it performs then write a test to verify if it works as you expect. When your ready to move on to changing the code you will have a set of tests which should help you modify the code without introducing new bugs,

Title: Strategy for reading and understanding Node.js code

Body:
Concretely I am looking at this 2000 line file of what I will pretty arbitrarily call "mediocre" code.

It's not well-commented

variable names and function names seem consistently intelligent

functions are not well-documented

functions are good length

In short:  its lines and small structures are readable, but it's impossible to infer architecture or design at a glance.  Most code I've worked on can be described thusly, to be fair.

So I need to understand this.  And work on it.  This is an important skill in software development I'm still weak at, and it's extremely important when working in a nascent system.

So my question is, when encountering foreign code like this that I am employing as client code but now need to understand and modify, what is a quick strategy for having a good understanding?


答:
I like James Anderson's answer, but I want to look more closely at your interpretation of Zed Shaw's comments.  I don't think Shaw is saying to be "neutral to languages". In fact, the only way one doesn't become "blinded" is to care enough to learn enough to form a positive or negative opinion so that you can choose the best "tool for doing interesting things."

Given that, in my estimation (as a long time developer and manager of such people) a good coder does care very deeply about tools used and not just the output, because he or she knows enough to be aware of what will work and what will not work for the situation at hand.

Looking at your writer analogy, "like writer does not care about pen he uses - he thinks about the BOOK content", I would actually make the analogy this way (although believe me, writers care about pens :) ) -- a writer wants to put forth a message, and the medium through which he or she does it could be a sonnet, a haiku, a novel, or a song (and so on).

A "pro developer" wants to put forth a solid architecture and an application that scales,  that meets the needs of the stakeholders and so on -- he or she could do that with Ruby, Python, Java, whatever, and the decision about what is best hopefully comes from a person or team that has the ability and knowledge to take all the factors into consideration.

So, as to your question, "is it a sign of pro developer, if he does not care what language to use?" My answer is that a "pro developer" does care what language is used, has a well-formed opinion about it (as opposed to an answer like "use Ruby because all the cool kids are doing it"), and if needed can roll up their sleeves and do the work even if it means working in Java instead of Ruby (and so on).

However, remember that people who work in places where the language is dictated for them, and are quite good at what they do in that one language, are still very much "pro developers", but they might be less able to have lengthy discussions about suitability of language for task if they only know the one language. Doesn't make them less "pro", just that they wouldn't be the only people I would have in a room when I'm soliciting thoughts on languages to use for an upcoming application.


问:
The rationale behind Falsy values
I'm wondering what the arguments for/against Falsy values are. On what principles would you decide to add or exclude them from a language? Are there any problems you could see them causing off-hand?

For users of languages that support Falsy values:

Where specifically have you used them to your advantage?

Where have you had unpleasant run-ins with them?

Are there any rules or finer points in your language/project/team about where it's appropriate or inappropriate to use them?

For users of other languages:

Have you ever seen a situation where you've thought "I wish I could use a Falsy value here"?

I'm tagging the question haskell and python because AFAIK those two represent opposite ends of the spectrum (Haskell demanding Bools when you use if, and Python treating None and some "empty" values as Falsy), but feel free to talk about your experience from other languages. Just mention where on the spectrum they stand.

答:
I use them to my advantage in Javascript all the time. In Javascript, the falsy values are undefined, null, false, NaN, 0 and ""

It is just much easier to read:

```<code>if( !str ) {

}
</code>```

instead of

```<code>if( str == null || str.length() == 0 ) {

}
</code>```

or str == null || str.equals("") or bunch of other just as bad equivalents that you need to use in Java.

I do recall an instance where I was bitten by this, doing x || y, when a certain falsy value was desirable as x. But this is very rare.

However, the check is relatively sane in Javascript. Consider PHP, where additionally the string "0", an empty array or, and I quote:

SimpleXML objects created from empty tags

are considered falsy values. Also, NaN is truthy in PHP! So in this mess of completely arbitrary inconsistency, I wouldn't find the truthy/falsy concept
as good.

Title: The rationale behind Falsy values

Body:
I use them to my advantage in Javascript all the time. In Javascript, the falsy values are undefined, null, false, NaN, 0 and ""

It is just much easier to read:

if( !str ) {

}

instead of

if( str == null || str.length() == 0 ) {

}

or str == null || str.equals("") or bunch of other just as bad equivalents that you need to use in Java.

I do recall an instance where I was bitten by this, doing x || y, when a certain falsy value was desirable as x. But this is very rare.

However, the check is relatively sane in Javascript. Consider PHP, where additionally the string "0", an empty array or, and I quote:

SimpleXML objects created from empty tags

are considered falsy values. Also, NaN is truthy in PHP! So in this mess of completely arbitrary inconsistency, I wouldn't find the truthy/falsy concept
as good.


问:
What information should be in the github README.md?
What information would you expect to see in the github README?

Should everything go in the README? i.e.

Introduction

Installation

Versions

User Guide

Implementation

Testing

Related Resources

Or should you just put certain things in the README (Introduction, Installation, Versions) and the other information is best placed in the Github wiki?

答: I expect to see an introduction and brief overview. There should be something there to convince me that the project solves a particular problem. After reading the README, I should know enough information to  know what the project does, what it requires, how to build it, and how to use it. That information doesn't all need to be in the README, but links to that information should be. </p>


答:
All developers should understand the basic precepts of writing clean code as well as (generally speaking here) Object Oriented Programming.

To the extent of knowing the above, then the developer can be confident that he/she can code in any applicable language, and this is a good thing; HOWEVER, being able to code in any language doesn't necessarily make you a GREAT developer.

As many others on this post have pointed out, GREATNESS comes from understanding the fundamentals BUT ALSO having enough domain knowledge to select the right tool for the right job.

Choosing the right tool for the job is a complex decision and is made from an architectural context that involves the needs of the stake holders, the intended use, the intended audience, key performance metrics, and so forth.

As the developer, it is good to be able to confidently accept the coding task, along with a prescribed language.  If you disagree with a prescribed language, then just be able to provide substantive reasons beyond, "because I don't know that language".

One thing I have learned about this business is that there is plenty of work out there.  You don't have to take on jobs that are to be executed with tools that make you uncomfortable.  At the same time, I personally look forward to the challenge of taking on an unfamiliar language, and I usually learn something new thanks to doing so.

Hope this helps!


问:
The Proper UML Model of a System for Non-Technical Boss
I've taken on some side work for this non-profit and last week was my first week on the job. They have two SQL Server Databases each with many tables in them that represent over 20 different applications such as

Course signup - Trainers can signup to teach different available classes

Course Approval form - trainers complete this form to get new courses approved to be added to the list of available classes.

Schedule - schedule of important dates for a term (holidays, start date for classes, etc.)

Trainer - list of all trainers and other information about a trainer (contact info, education, etc.)

Training Calendar - List that students can look at to see what's available for the current term

Training plan - a report that is printed for student with all of the classes they've signed up for

Certificate - Print a certificate for a student once the training course has been completed

There are about 15 other applications but it's all related to trainers, training, courses, students, etc.

This data is all over the place as there are no relationships between tables and very tedious processes have to be done to complete simple task. For example, for every new term you have to copy the data in the "old" table, create a new table, paste the old data into the new table and append the new data for the current term to the new table. So there's a table for every term (3 terms per year) for the past 10 years and that's only the beginning.

There's a lot of copying and pasting from Excel to SQL Server to get the data into the database and their front-end to manipulate the data isMS Access which I'd like to replace with ASP.NET (they have IIS 7).

To properly architect this and have good documentation, I've installed Visio 2013 and I'm learning about UML. So that boss can know exactly how this system will be re-architected, and how all the pieces will fit together what UML diagram should I create for him? Would that be a component diagram? I need to give him the 10,000 foot view so something like use-case, sequence, or database diagrams is way to low-level for him.

答:
don't, unless he actually asked for it.

Unless the manager wants to know what's going on beyond "your databases were written inefficiently", and the text in your question.  DO document the old and new designs, but do it for the programmer doing your job.

If management wants specifics, Visio its a good tool.  But an abstract diagram listing "apps" and "data" should suffice.  A separate diagram for how the "data" is stored, with consistent  names to the first diagram, should suffice.


答:
No. no. no. Absolutely not the sign of a pro-developer. A pro-developer is often the most vocal about which languages to use.

A Pro-Developer Has Failed Before

True knowledge of the strengths and weaknesses of a programming language comes from failure, and not text books or user manuals on how to write in that language.

I've worked on a wide range of projects that have failed. People were fired and businesses lost money. The programming language used played a role in what happen, and I've learned a lot about the risks involved when using that language.

Success Alone Is Not Enough

A developer can be certified by a credible organization for a programming language. He/she may read books extensively on a nightly basis. They may have several open-source projects they publish in that language.

Being successful in a programming language doesn't give you the wisdom to avoid problems. It makes you overconfident, and I've worked on many projects where the lead developer was overly successful. As a result, they wouldn't listen when trying to voice caution that the team was headed for problems.

What's The Sign Of A Pro-Developer?

Fear when presented with the opportunity to join a project that is using the wrong tool for the job. The developer who shows signs of ignorance or calm is an inexperienced fool.

Reverse Evaluation: I assume we're talking in terms of a job interview. How to tell if a developer knows his stuff. A pro-developer will turn the tables in an interview when he detects a mismatch between the problems at hand, and the programming language chosen to solve them. He'll want to know why the interview represents a company that has made what he thinks is an obvious mistake, and he knows changing programming languages is like trying to redirect a huge asteroid headed for New York.

Why Does This Happen So Often?

It's a multi-phase process. Here's the short form.

A business starts a new project with inexperienced people because they're cheaper.

Inexperienced people pick the programming language they are most comfortable with. Not what is right for the project (often this is done by people who won't be writing the code).

90% of those projects fail, but 10% survive.

Those 10% suddenly need to fix up the project because now it's selling.

Now there is a criticise so they decide to invest in an experienced developer.

The experienced developer comes in and demands the programming language be changed (all the other pro-developers interviewed wouldn't take the job).

He is now thought to be worshipping a particular language and a holy war starts.

This scenario plays out over and over again in industry, and it's because of this that so many developers debate the pros/cons of each language. We all don't want to be that guy who has to fight a way to change languages. So these debates can become very heated at the start of a project.

No Turning Back Once You Start

Picking a programming language is like taking the first stab with the shovel into the dirt. You are either planting a tree, or digging your own grave.


问:
What does "deploy to a physical machine" mean
I was asked whether I've ever "deployed to a physical machine" and I'm seeing this terminology when googling, but not getting a definition. What does it mean? What other way could someone deploy an application if not to a physical machine?</p>

答:
This usually translates to 'have you deployed to production servers' which in itself usually means

"Have you pushed stuff 'over the wire' to servers outside of the organization which are used in production mode?

It's frequently seeing if you have any ops experience as well as development.


答: Every professional developer should be looking at, and clamouring for, scientific repeatable evidence for or against the multitude of tools and methodologies they use. We need to get away from the "Oh this book says its good so lets bet the project on that" or "we can only hire programmers that know X so lets use X" way of pouring money down the drain on so many projects and try and put some science behind the shouting.</p>


问:
Help me understand how to index a pixel in an image
I had a look at the code for the implementation of this paper  Graph-Based segmentation by Pedro F. Felzenszwalb

But I didn't understand how in the below code that y * width + x is used to build a graph from an image.

```<code>// build graph
edge *edges = new edge[width*height*4];
int num = 0;
for (y = 0; y < height; y++) {
    for ( x = 0; x < width; x++) {
        if (x < width-1) {
             edges[num].a = y * width + x;
             edges[num].b = y * width + (x+1);
             edges[num].w = diff(smooth_r, smooth_g, smooth_b, x, y, x+1, y);
             num++;
         }

         if (y < height-1) {
            edges[num].a = y * width + x;
            edges[num].b = (y+1) * width + x;
            edges[num].w = diff(smooth_r, smooth_g, smooth_b, x, y, x, y+1);
            num++;
         }

         if ((x < width-1) && (y < height-1)) {
            edges[num].a = y * width + x;
            edges[num].b = (y+1) * width + (x+1);
            edges[num].w = diff(smooth_r, smooth_g, smooth_b, x, y, x+1, y+1);
            num++;
         }

         if ((x < width-1) && (y > 0)) {
            edges[num].a = y * width + x;
            edges[num].b = (y-1) * width + (x+1);
            edges[num].w = diff(smooth_r, smooth_g, smooth_b, x, y, x+1, y-1);
            num++;
         }
     }
}
</code>```

答: When you read an image file, it's a linear series of pixels. Let's take an example. Say you have a 32x32 image. This results in a series of 1024 points. In order to get the linear index of the pixel at y=4 and x=16, you'll use the formula y * witdth + x, which in this case is 4 * 32 + 16 = 144


答:
A 2D matrix can be stored in a 1D vector as a sequence of consecutive fixed-width rows, and the formula for accessing position (x, y) is y*width + x.

Here's a visual example. Suppose you have a 3x3 matrix filled with 0 and a $ at position (1, 2) (that's column first, row second, using 0-based indices). You can store it as a 1D vector as follows:

```<code>[0 0 0 0 0 0 0 $ 0]
</code>```

And here it is visually re-arranged to make sense as a 3x3 matrix:

```<code>          y
 [0 0 0   0
  0 0 0   1
  0 $ 0]  2

x 0 1 2
</code>```

Because it is a 1D vector (see first figure), we need a single index to get at that $ value. But because we think of it as a 2D matrix, all we have is the (1, 2) location. We need a formula to convert it to a single index.

That formula is the y*width + x, like you saw. It roughly means "y is how many full rows I have to skip, before moving to the correct column using x". Note the formula as written works because we are using 0-based indices, otherwise it requires minor modification.

So in this example, y = 2, x = 1 and width = 3:

```<code>2 * 3 + 1 = 7
</code>```

And index 7 of our original vector [0 0 0 0 0 0 0 $ 0] has the value $ that we wanted. (Again, note 7 is a zero-based index).

Title: Help me understand how to index a pixel in an image

Body:
I had a look at the code for the implementation of this paper  Graph-Based segmentation by Pedro F. Felzenszwalb

But I didn't understand how in the below code that y * width + x is used to build a graph from an image.

```<code>// build graph
edge *edges = new edge[width*height*4];
int num = 0;
for (y = 0; y < height; y++) {
    for ( x = 0; x < width; x++) {
        if (x < width-1) {
             edges[num].a = y * width + x;
             edges[num].b = y * width + (x+1);
             edges[num].w = diff(smooth_r, smooth_g, smooth_b, x, y, x+1, y);
             num++;
         }

         if (y < height-1) {
            edges[num].a = y * width + x;
            edges[num].b = (y+1) * width + x;
            edges[num].w = diff(smooth_r, smooth_g, smooth_b, x, y, x, y+1);
            num++;
         }

         if ((x < width-1) && (y < height-1)) {
            edges[num].a = y * width + x;
            edges[num].b = (y+1) * width + (x+1);
            edges[num].w = diff(smooth_r, smooth_g, smooth_b, x, y, x+1, y+1);
            num++;
         }

         if ((x < width-1) && (y > 0)) {
            edges[num].a = y * width + x;
            edges[num].b = (y-1) * width + (x+1);
            edges[num].w = diff(smooth_r, smooth_g, smooth_b, x, y, x+1, y-1);
            num++;
         }
     }
}
</code>```

Body:
A 2D matrix can be stored in a 1D vector as a sequence of consecutive fixed-width rows, and the formula for accessing position (x, y) is y*width + x.

Here's a visual example. Suppose you have a 3x3 matrix filled with 0 and a $ at position (1, 2) (that's column first, row second, using 0-based indices). You can store it as a 1D vector as follows:

[0 0 0 0 0 0 0 $ 0]

And here it is visually re-arranged to make sense as a 3x3 matrix:

          y
 [0 0 0   0
  0 0 0   1
  0 $ 0]  2

x 0 1 2

Because it is a 1D vector (see first figure), we need a single index to get at that $ value. But because we think of it as a 2D matrix, all we have is the (1, 2) location. We need a formula to convert it to a single index.

That formula is the y*width + x, like you saw. It roughly means "y is how many full rows I have to skip, before moving to the correct column using x". Note the formula as written works because we are using 0-based indices, otherwise it requires minor modification.

So in this example, y = 2, x = 1 and width = 3:

2 * 3 + 1 = 7

And index 7 of our original vector [0 0 0 0 0 0 0 $ 0] has the value $ that we wanted. (Again, note 7 is a zero-based index).


问:
what is the transferability of changes in terms of a GPL license
I have a program that is offered to the public on the web as a GPL program. This is a hobby type project that i stated 3.5  years ago and i have had one collaborator for most of that duration who has contributed some code me and my collaborator  both like to see the program develop as it's both our hobbies.

A person has adopted its game board to a play against the computer program. He wrote his own engine and his game he plays on the board uses a different set of rules. I think both me and my collaborator are ok with a more permissive licence grant. I've told the the derived work author that code he modifies he can add his copyright, and any java files that are all his code he can have sole copyright.   I can grant a more permissive grant.    But if i do what would his right of transferability be. By granting him a modification of gpl and he makes his code open source, could he in turn give the same grant to anyone else or does he not have a right of transferability?

The first question (that would cause the second to be not applicable) is: would GPL work for what i'm doing to promote my brand and allow others somewhat permissive use. The secondary question is would my lack of enforcement or accepting modifications of terms be inherited by any users of his work.

My open source software is in a hobby area, chess. Understanding the open source licences helps me be persuasive and helps with communication as the eventual adapters of code begin.

答:
The GPL is probably the right license to use. Note that by licensing your software to anybody, you are not giving away your trademark (your brand) with it. An example is the Firefox browser, which is shipped as "Iceweasel" in some Linux distributions as they modified the code and the Mozilla Foundation does not grant the right to brand derivative works with the "Firefox" brand.

With the GPL the licensee has to keep all copyright information intact (and can add her own). All changes made to the software must be documented as well, and it needs be indicated where the original sources can be obtained as well as the modified sources.

If anybody wants to make money out of the software, she would still have to provide copyright information and source code to the customer, as well as license the product under the terms of the GPL to the customer. Which means that anybody has the possibility to sell the software GPL-licensed. So you would also be allowed to sell their version of the software.

The GPL by itself includes unrestricted transferability, but under defined strict terms which seem to suit your needs well.

OwnerDisplayName: LanternMike

OwnerDisplayName: ypnos


答:
Additionally to the fact that floating-point types behave completely different from integer types, I want to give a more extreme example why size per number really matters.

Imagine you want to sort a (long) array. For example in C:

```<code>int numbers[100000000];
</code>```

So here we have 100 Million numbers.

If each number is only one byte long (so using unsigned char instead of int), then this needs 100 Million bytes of space.

If you use double, then this usually are 8 bytes per number, so 800 Million bytes of space.

So each time you operate with a lot of objects (numbers in this example), size per object (size per number in this example) really does matter.

Body:
Additionally to the fact that floating-point types behave completely different from integer types, I want to give a more extreme example why size per number really matters.

Imagine you want to sort a (long) array. For example in C:

int numbers[100000000];

So here we have 100 Million numbers.

If each number is only one byte long (so using unsigned char instead of int), then this needs 100 Million bytes of space.

If you use double, then this usually are 8 bytes per number, so 800 Million bytes of space.

So each time you operate with a lot of objects (numbers in this example), size per object (size per number in this example) really does matter.


答:
Haskell too has the concept of falsy and I use them all the time.

Assume I have a handful of values and I need to fail if any one of those values are "false" (bools would be false, lists would be empty...). I can use the Maybe monoid to easily check if any of them are considered false based on their type.

True, the "if" statement in Haskell still only allows a boolean test condition, But Haskell makes it easy enough to create your own control structures to circumvent the problem.

The key is that in Haskell they are completely type checked so you know exactly what's happening. I've longed for them in C# but got around it by just explicitly checking for "false"

Title: The rationale behind Falsy values

Body:
I'm wondering what the arguments for/against Falsy values are. On what principles would you decide to add or exclude them from a language? Are there any problems you could see them causing off-hand?

For users of languages that support Falsy values:

Where specifically have you used them to your advantage?

Where have you had unpleasant run-ins with them?

Are there any rules or finer points in your language/project/team about where it's appropriate or inappropriate to use them?

For users of other languages:

Have you ever seen a situation where you've thought "I wish I could use a Falsy value here"?

I'm tagging the question haskell and python because AFAIK those two represent opposite ends of the spectrum (Haskell demanding Bools when you use if, and Python treating None and some "empty" values as Falsy), but feel free to talk about your experience from other languages. Just mention where on the spectrum they stand.


问:
Making a class pseudo-immutable by setting a flag
I have a java project that involves building some pretty complex objects. There are quite a lot (dozens) of different ones and some of them have a HUGE number of parameters. They also need to be immutable.

So I was thinking the builder pattern would work, but it ends up require a lot of boilerplate. Another potential solution I thought of was to make a mutable class, but give it a "frozen" flag, a-la ruby.

Here is a simple example:

```<code>public class EqualRule extends Rule {
    private boolean frozen;
    private int target;

    public EqualRule() {
        frozen = false;
    }

    public void setTarget(int i) {
        if (frozen)
            throw new IllegalStateException(
                "Can't change frozen rule.");

        target = i;
    }

    public int getTarget() {
        return target;
    }

    public void freeze() {
        frozen = true;
    }

    @Override
    public boolean checkRule(int i) {
        return (target == i);
    }
}
</code>```

and "Rule" is just an abstract class that has an abstract "checkRule" method.

This cuts way down on the number of objects I need to write, while also giving me an object that becomes immutable for all intents and purposes. This kind of act like the object was its own Builder... But not quite.

I'm not too excited, however, about having an immutable being disguised as a bean however.

So I had two questions:
1. Before I go too far down this path, are there any huge problems that anyone sees right off the bat? For what it's worth, it is planned that this behavior will be well documented...
2. If so, is there a better solution?

Thanks

答:
If you don't want to pass a mutable object into an immutable object (or vice versa) you can use a map.

```<code>public class EqualRule extends Rule {

    private final int target;

    public EqualRule(final Map<String,Object> config) {
      this.target = config.get("target");
    }

    public int getTarget() {
        return target;
    }

    @Override
    public boolean checkRule(int i) {
        return (target == i);
    }
}
</code>```

You can automate this using the Jackson library. It can inject data to immutable objects (final members) or fake immutability (private setter) automatically. See the @JsonProperty annotation in the Jackson library:

```<code>public class EqualRule extends Rule {

    private final int target;

    @JsonCreator
    public EqualRule(@JsonProperty("target") int target) {
      this.target = target;
    }

    public int getTarget() {
        return target;
    }

    @Override
    public boolean checkRule(int i) {
        return (target == i);
    }
}

final ObjectMapper mapper = new ObjectMapper(); //singleton
final ObjectNode node = mapper.createObjectNode();
node.put("target", 1);
// not as efficient since internally causes serialization/deserialization.
EqualRule rule = mapper.convertValue(node, EqualRule.class);
</code>```

There is a side benefit that the conversion would allow you to make the code less vulenrable to schema changes and more backwards compatible. For example when converting from json to pojo you can handle or ignore unknown properties.

Body:
If you don't want to pass a mutable object into an immutable object (or vice versa) you can use a map.

public class EqualRule extends Rule {

    private final int target;

    public EqualRule(final Map<String,Object> config) {
      this.target = config.get("target");
    }

    public int getTarget() {
        return target;
    }

    @Override
    public boolean checkRule(int i) {
        return (target == i);
    }
}

You can automate this using the Jackson library. It can inject data to immutable objects (final members) or fake immutability (private setter) automatically. See the @JsonProperty annotation in the Jackson library:

public class EqualRule extends Rule {

    private final int target;

    @JsonCreator
    public EqualRule(@JsonProperty("target") int target) {
      this.target = target;
    }

    public int getTarget() {
        return target;
    }

    @Override
    public boolean checkRule(int i) {
        return (target == i);
    }
}

final ObjectMapper mapper = new ObjectMapper(); //singleton
final ObjectNode node = mapper.createObjectNode();
node.put("target", 1);
// not as efficient since internally causes serialization/deserialization.
EqualRule rule = mapper.convertValue(node, EqualRule.class);

There is a side benefit that the conversion would allow you to make the code less vulenrable to schema changes and more backwards compatible. For example when converting from json to pojo you can handle or ignore unknown properties.


问:
Good way to manage database test data?
Standard LAMP stack: CentOS, Apache, PHP, MySQL plus Java (via Google Web Tools), eclipse, mercurial

Currently we have a manual integration step where a feature branch is pushed to a staging server where QA tests the feature by poking at it with the GUI. We use a shared dev database. We're running into the problem where feature branches require different database schema creating a bottleneck between feature branch development and acceptance testing.

We'd like to start having separate dev databases but do not know how to handle populating the database with test data (the web app requires some base amount of data to be present to start up i.e. users) and keep that test data in sync with the merging of feature branches, etc.

I read lots of suggestions and tools regarding database schema changes, but not managing database test data. We're only a two person shop so keeping things simple is important. We've thought of just maintaining scripts (SQL files or otherwise) to populate the test database.

Does anyone have resources, success stories, or advice to share?

答:
In my work we have two main ways of doing it: SQL inserts in a version controlled package, and setting up as much data as we can via internal tools.

Since the SQL inserts are versioned then we can branch those alongside any application updates and create a modified set. This can then be merged just as with any other code. One word of advice with this method would be to always use named columns in the SQL inserts. Trying to run in your data and getting the "column count does not match error" is annoying.

A lot of our test data concerns users of our system. This used to be set up by manually inserting it as well, but we extended our internal admin tools to allow scripted setups. This means that we keep the user data in schema-agnostic files (in our case, we have Perl scripts) which use a webservice exposed by the admin webapp to set up the test data.

Title: Good way to manage database test data?


问:
What's an incorporated software developer?
I saw a job posting asking for "incorporated software developers" and asking them to state their "incorporated rate" when applying. What's the difference between an incorporated developer and a contractor/freelancer? Google isn't helping.

My best guess is that an incorporated developer is just a freelancer/contractor who sets up a corporation and works as the sole employee of that corporation, rather than freelancing under their own name. But since (I assume) you would have to pay both corporate and income taxes if you did that, rather than just income taxes, what would be the point of doing that? There would be some protection from legal liability, but that generally isn't a big risk for software developers.

答:
Not sure it's relevant to you, but an incorporated engineer can be one that has standing in the relevant professional (sometimes chartered) body.

The BCS appears to be one such organization.

Quoted from that web-site:

Incorporated Engineers maintain and manage applications of current and developing technology, and may undertake engineering design, development, manufacture, construction and operation.

IEng registrants are also variously engaged in technical and commercial management and possess effective interpersonal skills.

IEng registration shows your employer and peers that you have demonstrated a commitment to professional standards, and to developing and enhancing your competence.


问:
Tracking progress via a burndown chart when sprints overlap
Our team has adopted some agile practices to help us develop and deliver our software to our client. We adopt practices as needed (as problems/challenges were identified) rather than jumping wholesale into the agile camp. The big ones for us are maintaining a product and sprint backlog and developing and delivering new versions in roughly one month sprints. We do estimate the items in our sprint backlog to guesstimate what we can deliver within a sprint. However we do not track progress very well so it's difficult to know whether or not we are on target.

The next step in our evolution appears to be to improve our progress tracking ability. We are looking at using burn down charts to aid us. However, our sprints overlap significantly due to established and procedures for our software promotion schedule. We have the following established events:

Development begins on Sprint 1 and continues until code freeze. That said we do test our software throughout this phase with the development and test groups.

Code freeze stops development on Sprint 1 functionality. We have a small window to finish or fix any issues before the next event acceptance promotion 1. In addition development begins on Sprint 2.

Acceptance promotion 1 promotes the application to the client's acceptance environment where it is tested by our test group. Issues identified in testing may be fixed during a small window before acceptance promotion 2. Meanwhile Sprint 2 development continues.

Acceptance promotion 2 promotes the application one last time to the client's acceptance environment to validate any issues identified during acceptance promotion 1. Sprint 2 development continues.

Production promotion promotes the application to production and it is tested by our test group and Sprint 1 is officially completed. This is when it is truly done.

A visual depiction of this can be seen below. The average calendar time between development begins and code freeze is four weeks. The average time between code freeze and production promotion is two weeks.

larger resolution version

This schedule of events is not within our control. Client policy dictates when application software is promoted from Test to Acceptance to Production. No application code may be modified beyond our second fix window. We do not perform the promotions. This is accomplished by '3rd' parties at the client's site, again, due to policy.

In addition, some tasks such as data updates, can and do happen outside of this schedule. Certain data updates follow the code (for instance, when there is a schema dependency) but others such as data bugs or new data can and do occur outside of this schedule. This is due to fewer restrictions as to what may be modified on the clients environment and when. Only application code is restricted to these specific milestones. Data and configuration are exempt and technically may be modified as needed. We are considering tightening this up so that data updates follow the same schedule as the code.

Given this scenario, our overlapping sprints, I have a several questions?

What is the proper way to create/handle a burn down chart when we burn development, testing, and data hours from the previous sprint while also working towards the next one?

I think we have 2 concurrent burn down charts on for each sprint.

Assuming we at most have two burn down charts how do we best display the cumulative burn down when the sprints overlap so as to understand our actual workload progress on each so as to best set us up for success?

If items are found in Sprint 1 after code freeze that need to be addressed in Sprint 2 how does that our Sprint 2 backlog and burn down?

I assume that for critical items we need to bump out less critical Sprint 2 items to make room for the incomplete Sprint 1 items. Non critical items will be bumped to Sprint 3 or later.

What would be the proper start and end dates for the burn down chart?

It seems the best option would be to reflect reality. Sprint 1 is not truly done (including testing and data updates) until production promotion and its final testing. So the start date would be development begins
and the end date be production promotion despite any overlap.

What else am I missing? What else could or will bite us?

答:
I don't think how you have your development setup is good idea. One of the reasons for sprints being bounded and non-overlapping are exact problems you just encountered. I would recommend focusing more on simplifying your sprint cycle than bothering how do make burndown chart.

First 4 weeks is on border of recommended sprint length and along with 2 weeks of "testing" basically makes your whole spring 6 weeks long, which is definitely not normal for agile practice.

Usually customer testing happens during sprint and errors/suggestions based on this testing are taken into account in the next available sprint. The exact reason for having short sprint is to quickly react for problems customer might have with project without need for such complex development/testing process.

Also, you should try thinking about implementing automated acceptance tests with automated deployment into customer's testing environment. If you have those, you can easily run them in between short time between the sprints. This will probably require much closer collaboration with your customer, what is one of the basics of agile practice.


答:
In my jurisdiction, it is common to require contractors to be incorporated.  There are a number of reasons this is good for both parties.  In part, it helps ensure that the contractor will not be considered an employee.

Taxes will need to be filed for both the corporation and the contractor.  However, the corporation may be able to deduct expenses which would not be applicable otherwise.  Amounts paid by the corporation to the contractor are generally deductions for the corporation.

Corporate tax rates may be lower than the top rate the contractor would pay.  In this case it may make sense to leave some earnings in the corporation and pay them out during lean time, or after retirement.

Title: What's an incorporated software developer?

Body:
I saw a job posting asking for "incorporated software developers" and asking them to state their "incorporated rate" when applying. What's the difference between an incorporated developer and a contractor/freelancer? Google isn't helping.

My best guess is that an incorporated developer is just a freelancer/contractor who sets up a corporation and works as the sole employee of that corporation, rather than freelancing under their own name. But since (I assume) you would have to pay both corporate and income taxes if you did that, rather than just income taxes, what would be the point of doing that? There would be some protection from legal liability, but that generally isn't a big risk for software developers.


问:
Why aren't user-defined operators more common?
One feature I miss in from functional languages is the idea that operators are just functions, so adding a custom operator is often as simple as adding a function. Many procedural languages allow operator overloads, so in some sense operators are still functions (this is very true in D where the operator is passed as a string in a template parameter).

It seems that where operator overloading is allowed, it is often trivial to add additional, custom operators. I found this blog post, which argues that custom operators don't work nicely with infix notation because of precedence rules, but the author gives several solutions to this problem.

I looked around and couldn't find any procedural languages that support custom operators in the language. There are hacks (such as macros in C++), but that's hardly the same as language support.

Since this feature is pretty trivial to implement, why isn't it more common?

I understand that it can lead to some ugly code, but that hasn't stopped language designers in the past from adding useful features that can be easily abused (macros, ternary operator, unsafe pointers).

Actual use cases:

Implement missing operators (e.g. Lua doesn't have bitwise operators)

Mimic D's ~ (array concatenation)

DSLs

Use | as Unix pipe-style syntax sugar (using coroutines/generators)

I'm also interested in languages that do allow custom operators, but I'm more interested in why it has been excluded. I thought about forking a scripting language to add user-defined operators, but stopped myself when I realized that I haven't seen it anywhere, so there's probably a good reason why language designers smarter than me haven't allowed it.

答:
I've always found operator overloads in C++ to be a convenient shortcut for a single-developer team, but which causes all sorts of confusion in the long term simply because the method calls are being "hidden" in a way that isn't easy for tools like doxygen to pick apart, and people need to understand the idioms in order to make use of them properly.

Sometimes it's a lot harder to make sense of than you'd expect, even.  Once upon a time, in a large cross-platform C++ project I decided it'd be a good idea to normalize the way that paths were built by creating a FilePath object (similar to Java's File object), that would have operator/ used to concatenate another path part on it (so you could do something like File::getHomeDir()/"foo"/"bar" and it would do the right thing on all of our supported platforms).  Everyone who saw it would essentially say, "What the hell? String division? ... Oh, that's cute, but I don't trust it to do the right thing."

Similarly, there's a lot of cases in graphics programming or other areas where vector/matrix math happens a lot where it's tempting to do things like Matrix*Matrix, Vector*Vector (dot), Vector%Vector (cross), Matrix*Vector (matrix transform), Matrix^Vector (special-case matrix transform ignoring the homogenous coordinate - useful for surface normals), and so on, but while it saves a bit of parsing time for the person who wrote the vector math library, it only ends up confusing the issue more for others. It just isn't worth it.


问:
What did Rich Hickey mean when he said, "All that specificity [of interfaces/classes/types] kills your reuse!"
In Rich Hickey's thought-provoking goto conference keynote "The Value of Values" at 29 minutes he's talking about the overhead of a language like Java and makes a statement like, "All those interfaces kill your reuse."  What does he mean?  Is that true?

In my search for answers, I have run across:

The Principle of Least Knowledge AKA The Law of Demeter which encourages airtight API interfaces.  Wikipedia also lists some disadvantages.

Kevlin Henney's Imperial Clothing Crisis which argues that use, not reuse is the appropriate goal.

Jack Diederich's "Stop Writing Classes" talk which argues against over-engineering in general.

Clearly, anything written badly enough will be useless.  But how would the interface of a well-written API prevent that code from being used?  There are examples throughout history of something made for one purpose being used more for something else.  But in the software world, if you use something for a purpose it wasn't intended for, it usually breaks.

I'm looking for one good example of a good interface preventing a legitimate but unintended use of some code.  Does that exist?  I can't picture it.

答:
Haven't watched the full Rich Hickey presentation, but if I understand him correctly, and judging from what he says about the 29-minute mark, he seems to be arguing about types killing reuse. He is using the term "interface" loosely as a synonym for "named type", which makes sense.

If you have two entities { "name":"John" } of type Person, and { "name": "Rover" } of type Dog, in Java-land they probably cannot interoperate unless they share a common interface or ancestor (like Mammal, which means writing more code). So the interfaces/types here are "killing your reuse": even though Person and Dog look the same, one cannot be used interchangeably with the other, unless you write additional code to support that. Note Hickey also jokes about projects in Java needing lots of classes ("Who here has written a Java application using just 20 classes?"), which seems one consequence of the above.

In "value-oriented" languages, however, you won't assign types to those structures; they are just values which happen to share the same structure (in my example, they both have a name field with a String value) and therefore can easily interoperate, e.g. they can be added to the same collection, passed to the same methods, etc.

To sum up, all this seems to be something about structural equality vs explicit type/interface equality. Unless I missed something from the portions of the video I haven't watched yet :)


答:
In most parts of Canada it's trouble for a business to hire a contractor and provide them with a desk, computer and software to do their job. A contracted software developer often doesn't have vacation pay, sick leave or severance pay.

With the exception to corporations. A software developer operating under the name of his own corporation is exempt from these rules. He will have no rights to claim that a business hired him on contract, and that he's entitled to employee privileges.

Therefore there are a lot of businesses here that will only hire contractors who are incorporated.

The incorporated contractor industry here is huge, with large companies like (Rogers, Bell, IBM, etc.) making up a percentage of their workforce with external contractors who operate under the name of their own corporation. They sit in desks along side regular employees doing exactly the same work.

There are lot of people working like this who enjoy it, and those who don't. Incorporating just so you can find contract work is a decision that usually means a long term commitment to contractor status.


问:
How does one start mocking up a mobile app?
I have this idea for the "best app in the world". I know what it's going to do, the need it's going to fill, a high to mid-level idea of the code, and who i'm going to target. Now i'm ready to begin: I grab my pen, paper, thinking-cap, can-do-attitude, set the clock to GO-TIME--This app is gonna be awesome!......2 hours later, all i have on my paper is a big rectangle...

One would think that the mockup would be the easy part, but drawing a "simple & sleek" design harder than it sounds. Are there any techniques/advice that you can give on mocking up an app? Any references or rules-of-thumb guidelines you can provide would also be greatly appreciated.

Thanks in advance.

答:
One would think that the mock up would be the easy part, but drawing a "simple & sleek" design harder than it sounds.

Well there's your problem.

A mock up is not sleek or simple. It's non-functional and that means it doesn't do anything.

Before you begin you need to decide what type of mock up you are going to create?

A throwaway mock up to just feel out an idea.

An evolving mock up that you will keep making changes too until you get it right.

An incremental mock up where you keep filling in the pieces until it's a fully finished app.

Each of those have their pros/cons but which one you pick helps decide which tools you use. A throwaway mock up can just be some photoshopped images. It shows what you want, but it's useless and you throw it away (good for business meetings).

An evolving mock up requires more work to create some kind of base for the app. Either native code or HTML5, but the idea is that you can make changes to the mock up to fix design issues. The only limitation is it'll never turn in the actual app. It's just a mock up.

The incremental mock up is harder. You're mocking up the groundwork that will eventually be the app itself.

Why Should You Do A Mock Up?

It's good to flush out your idea and fix holes that might exist.

It can improve the quality of the final app.

It can reduce the time and cost to develop the app.

Disadvantages Of Doing A Mock Up?

It can be distracting from the original idea. Let's face it. No one does a perfect mock up, and when it's done it'll be different from the idea. You risk losing the idea.

You'll get confused between working on a mock up and actually developing the app. Often when people start working on something they start wanting to see it finished, and changing direction from mock up to developing app is a risk in doing a mock up.

You'll become overly attached to the mock up. Spending too much time working on it until you've simply run out of time.


问:
Difference between sending a message and emitting it
Halfway through the RabbitMQ tutorial, I noticed that the tutorial stops referring to producers "sending" messages and starts using the verb "emit" instead — and pretty consistently, too; after the second tutorial, the verb "send" is no longer used to describe a producer transmitting messages.

Example:

Second Tutorial

The main idea behind Work Queues ... encapsulate a task as a message and send it to the queue. A worker process running in the background ....

Fourth Tutorial

We'll use this model for our logging system. ... Let's focus on emitting logs first.

What is the difference between sending a message vs. emitting one?

答:
I agree with Ratchet Freak with his definitons:

Sending has a destination emitting is detected by something else

However in this case I think it's just poor word choice by the author, as when writing logs, you do in fact have a destination.


问:
Should I allow my client to self host?
I'm just starting out as a web designer. I'm trying to build up a portfolio for my own website.

I'm concerned about designing a site and handing it over to the client. Once I do this I could lose access to the site. They can change the login information and they may not need to me manage it. If the client changes anything on the site that compromises my design work, it will reflect my business. My business' name will be on the homepage of the website.

Is this a valid concern?

答:
You're planning on doing design work for hire.  Unless you really want to be a permanent web host as your full time job (and even if you do, really) you should let your client host their website wherever they want.

If you are concerned about your name being on it if they change the design, put a clause in your contact that you can demand they take your name off if they change the design.  Or don't clutter the design with your name, and rely on the good relationship you have with your customer to generate referral business.

Title: Should I allow my client to self host?


答:
Unless you have a previous agreement (i.e. a contract) that covers this, you probably have little choice in the matter from a legal stand-point.  (Talk to an IP / Copyright lawyer)

If the client changes anything on the site that compromises my design work, it will reflect my business. my business name will be on the homepage of the website. Is this a valid concern?

It might be valid to you ... but it won't be valid to your client.  They will have their own concerns too; e.g.

the costs and risks (as they see them) of external hosting ,

the costs and risks (as they see them) of depending on your services ... in perpetuity.

There is a "simple solution".  Change the site to remove your business name as part of the hand-over.  That's likely to reduce the prospect of further business from your client, but it certainly will address your immediate concern.

IMO, you should negotiate with your client, and try to come to a compromise that satisfies both of your concerns.  Your concerns are (at this stage) hypothetical.  If you come to a sensible compromise, they should never come to pass.  (And next time ... put it in the contract.)

There's another thing you should think about.  You could risk damaging your business reputation by making a big fuss about this.  Other potential clients might decide that they would prefer to take their website design work to someone who is going to be more cooperative when it comes to website hand-over time.

Title: Should I allow my client to self host?

Body:
I'm just starting out as a web designer. I'm trying to build up a portfolio for my own website.

I'm concerned about designing a site and handing it over to the client. Once I do this I could lose access to the site. They can change the login information and they may not need to me manage it. If the client changes anything on the site that compromises my design work, it will reflect my business. My business' name will be on the homepage of the website.

Is this a valid concern?


问:
How to record/store edits?
In many programs and web apps (stack exchange included) the program is able to backtrack what edits where made to the piece. My issue is similar: I want to be able to store a "timeline" of edits, where the user can go back and see what they typed at a specific time/when the typed certain words. What's the standard way to do this? Also, in things like google docs and other programs, they automatically "group" actions together (Like if I delete something by hitting back space 5 times, it knows I was deleting one word), any ideas on how to do that to?</p>

答:
it's actually pretty simple

for every action the user makes you create a Undoable with 3 key methods

undo() and redo(): for the actual undo and redo

combine(Undoable) which creates a new Undoable of the 2 combined if they can be combined (otherwise null)

the code will be something like:

```<code>public Undoable combine(Undoable other){
    if(other instanceof UndoType){
        return new UndoType(this.insertedString+((UndoType)other).insertedString),position);
    }
    return null;
}
</code>```

then when you add the Undoable to the undo stack you check with the combine of the last undoable whether it can be combined

Title: How to record/store edits?

Body:
it's actually pretty simple

for every action the user makes you create a Undoable with 3 key methods

undo() and redo(): for the actual undo and redo

combine(Undoable) which creates a new Undoable of the 2 combined if they can be combined (otherwise null)

the code will be something like:

public Undoable combine(Undoable other){
    if(other instanceof UndoType){
        return new UndoType(this.insertedString+((UndoType)other).insertedString),position);
    }
    return null;
}

then when you add the Undoable to the undo stack you check with the combine of the last undoable whether it can be combined


答:
I think in the context of the tutorial he is speaking in terms of broadcaster and listener objects. He is trying to explain that there is a logging object that broadcasts (or emits) messages and that is all it does.

Those messages don't go to a file.

The tutorial continues to explain that a listener has to attach to the logger to receive the messages. You can then attach a listener that does something with what it receives, for example: "writes it to a file."

In this context. The term emit is correct, because he's trying to explain an event system. Events have emitters and receivers.

Previously, I suspect he was using the term send correctly as well. You send things to a queue or place them in the queue. You do not emit or broadcast them into a queue.

A queue is a type of first-in last-out collection.

EDIT:

To clarify. lol

You do not send an event. You send data to the event listener. The event itself is emitted. I prefer the term triggered but that comes from naming event listeners OnSomething.

Title: Difference between sending a message and emitting it

Body:
Halfway through the RabbitMQ tutorial, I noticed that the tutorial stops referring to producers "sending" messages and starts using the verb "emit" instead — and pretty consistently, too; after the second tutorial, the verb "send" is no longer used to describe a producer transmitting messages.

Example:

Second Tutorial

The main idea behind Work Queues ... encapsulate a task as a message and send it to the queue. A worker process running in the background ....

Fourth Tutorial

We'll use this model for our logging system. ... Let's focus on emitting logs first.

What is the difference between sending a message vs. emitting one?


问:
How to design a good receipt number
I am developing a web application, this application will need to generate receipt number for every confirmed transaction.

What is a good receipt number? I think a receipt number should not be just a running number generated by database, but it should have some meaning beyond just a unique running number.

Here is what I have come up with so far,

```<code>Format: EYY-ddd-XXXXXXX
Example output: E13-146-0000001
</code>```

Where:

E : It is just a to signify this receipt number was generated by my system. This value is always E.

YY : Is the current year the receipt was generated, so in this case it is 13

ddd : Is the day of the year, 146 is May 26 (in 2013).

XXXXXXX : Is a 7 digit running number, up to 9,999,999

So my system can generate up to 10 million unique receipt numbers daily until 2099.

What do you think? Is this sensible? Any suggestion is appreciated.

Update

Judging from the comments so far, it looks like there is no specific 'pattern' or 'best practices' for receipt number. My intention in asking the question is to know whether there is specific best practises in generating the number that I should know about. Looks like I am free to use whatever pattern I feel sensible.

Other requirements

As short as possible (that is why I didnt go for YYYYMMdd-XXXXXXX)

Somewhat not to obvious (YYYMMdd is way to obvious).

Should be fixed length. (Easier to detect if customer entered invalid receipt number)

Can generate fairly large numbers (10 million a day seems sensible, though I doubt my system will be that popular)

Can be made into QR code (so staff can scan and verify the number is valid)

Someone mentions about error detection code like ISBN, seems good but I havent read it yet.

答:
Without more information it appears reasonable,  if not overly complex. No one here can say for sure it will meet your needs, as you have not said what they are.

Whats wrong with a sequential number starting at 0? - You state "you think its not good enough", what requirement does that not meet?.

What happens after 2099 - whats the requirement, what happens after 9,999,999 transactions in a day - whats the requirement, 'E' - what requirement does that meet?

Title: How to design a good receipt number


答: I would add a checksum digit. Makes it easier to tell if someone types it out and makes a mistake.</p>

Title: How to design a good receipt number

Body:
I am developing a web application, this application will need to generate receipt number for every confirmed transaction.

What is a good receipt number? I think a receipt number should not be just a running number generated by database, but it should have some meaning beyond just a unique running number.

Here is what I have come up with so far,

```<code>Format: EYY-ddd-XXXXXXX
Example output: E13-146-0000001
</code>```

Where:

E : It is just a to signify this receipt number was generated by my system. This value is always E.

YY : Is the current year the receipt was generated, so in this case it is 13

ddd : Is the day of the year, 146 is May 26 (in 2013).

XXXXXXX : Is a 7 digit running number, up to 9,999,999

So my system can generate up to 10 million unique receipt numbers daily until 2099.

What do you think? Is this sensible? Any suggestion is appreciated.

Update

Judging from the comments so far, it looks like there is no specific 'pattern' or 'best practices' for receipt number. My intention in asking the question is to know whether there is specific best practises in generating the number that I should know about. Looks like I am free to use whatever pattern I feel sensible.

Other requirements

As short as possible (that is why I didnt go for YYYYMMdd-XXXXXXX)

Somewhat not to obvious (YYYMMdd is way to obvious).

Should be fixed length. (Easier to detect if customer entered invalid receipt number)

Can generate fairly large numbers (10 million a day seems sensible, though I doubt my system will be that popular)

Can be made into QR code (so staff can scan and verify the number is valid)

Someone mentions about error detection code like ISBN, seems good but I havent read it yet.


答:
My sense here is that its better if the customer hosts.  If you host everything, you may be able to squeak out some hosting fees, but you also end up responsible for server outages and database crashes... and basically every other glitch that occurs with the site (real or imagined by the customer).  Unless you have a strong set of server administration skills, that doesn't seem like a wise responsibility to take on.

The other downside for hosting a customer's site is that if they dont pay their hosting fees... do you shut the site off?  What if there's a disagreement about what the fees are?  Are you prepared for the legal hassles that can entail?  I say avoid the complexity.

You are concerned about the customer locking you out.  If you provide a good service, thats not too likely.  And, if the customer ends up being a problem customer, it'll be all that much easier for you to cut your ties with them.

Title: Should I allow my client to self host?


答:
Another way to look at it, is that your 4-week sprint begins 2 weeks into you diagram, with first 2 weeks of development and another 2 weeks of code freeze etc. idle time in those last two weeks can be used to prepare for the next sprint. But that sprint officially starts 6 weeks into your diagram (after acceptance of the previous sprint). </p>

<p>Not only will this create a clearer priority (getting acceptance is more important than starting on new things), it also allows for a perfectly textbook release burn down. </p>

Title: Tracking progress via a burndown chart when sprints overlap

Body:
Our team has adopted some agile practices to help us develop and deliver our software to our client. We adopt practices as needed (as problems/challenges were identified) rather than jumping wholesale into the agile camp. The big ones for us are maintaining a product and sprint backlog and developing and delivering new versions in roughly one month sprints. We do estimate the items in our sprint backlog to guesstimate what we can deliver within a sprint. However we do not track progress very well so it's difficult to know whether or not we are on target.

The next step in our evolution appears to be to improve our progress tracking ability. We are looking at using burn down charts to aid us. However, our sprints overlap significantly due to established and procedures for our software promotion schedule. We have the following established events:

Development begins on Sprint 1 and continues until code freeze. That said we do test our software throughout this phase with the development and test groups.

Code freeze stops development on Sprint 1 functionality. We have a small window to finish or fix any issues before the next event acceptance promotion 1. In addition development begins on Sprint 2.

Acceptance promotion 1 promotes the application to the client's acceptance environment where it is tested by our test group. Issues identified in testing may be fixed during a small window before acceptance promotion 2. Meanwhile Sprint 2 development continues.

Acceptance promotion 2 promotes the application one last time to the client's acceptance environment to validate any issues identified during acceptance promotion 1. Sprint 2 development continues.

Production promotion promotes the application to production and it is tested by our test group and Sprint 1 is officially completed. This is when it is truly done.

A visual depiction of this can be seen below. The average calendar time between development begins and code freeze is four weeks. The average time between code freeze and production promotion is two weeks.

larger resolution version

This schedule of events is not within our control. Client policy dictates when application software is promoted from Test to Acceptance to Production. No application code may be modified beyond our second fix window. We do not perform the promotions. This is accomplished by '3rd' parties at the client's site, again, due to policy.

In addition, some tasks such as data updates, can and do happen outside of this schedule. Certain data updates follow the code (for instance, when there is a schema dependency) but others such as data bugs or new data can and do occur outside of this schedule. This is due to fewer restrictions as to what may be modified on the clients environment and when. Only application code is restricted to these specific milestones. Data and configuration are exempt and technically may be modified as needed. We are considering tightening this up so that data updates follow the same schedule as the code.

Given this scenario, our overlapping sprints, I have a several questions?

What is the proper way to create/handle a burn down chart when we burn development, testing, and data hours from the previous sprint while also working towards the next one?

I think we have 2 concurrent burn down charts on for each sprint.

Assuming we at most have two burn down charts how do we best display the cumulative burn down when the sprints overlap so as to understand our actual workload progress on each so as to best set us up for success?

If items are found in Sprint 1 after code freeze that need to be addressed in Sprint 2 how does that our Sprint 2 backlog and burn down?

I assume that for critical items we need to bump out less critical Sprint 2 items to make room for the incomplete Sprint 1 items. Non critical items will be bumped to Sprint 3 or later.

What would be the proper start and end dates for the burn down chart?

It seems the best option would be to reflect reality. Sprint 1 is not truly done (including testing and data updates) until production promotion and its final testing. So the start date would be development begins
and the end date be production promotion despite any overlap.

What else am I missing? What else could or will bite us?

Body:
Another way to look at it, is that your 4-week sprint begins 2 weeks into you diagram, with first 2 weeks of development and another 2 weeks of code freeze etc. idle time in those last two weeks can be used to prepare for the next sprint. But that sprint officially starts 6 weeks into your diagram (after acceptance of the previous sprint).

Not only will this create a clearer priority (getting acceptance is more important than starting on new things), it also allows for a perfectly textbook release burn down.


问:
Is there a loophole in the GPL that allows proprietary software to be linked with GPL libraries?
Let’s examine a hypothetical scenario:

Company X writes a proprietary program (A) that dynamically links with a proprietary library (B). Company Y wants to use a replacement library (C) licensed under the GPL, and so writes a wrapper library (D) that dynamically links to both A and C and translates the API calls used by A to the API calls used by C.

As D is intended to be used with C, and uses C’s API calls, it is a derivative work of C and must therefore be distributed under the terms of the GPL*. As a result, the combined work of A and D must also be distributed under the terms of the GPL, which is impossible given that Company Y does not possess the source code for A. That said, so long as Company Y distributes D by itself, there is no problem. However, regardless of Company Y’s actions, Company X does not violate the GPL by distributing A, even without B. The mere existence of D does not mean that A is suddenly a derivative work of C (through D) that must be licensed under the GPL as well.

Now this is the loophole: there is nothing that stops Company X from writing its own version of D, distributing it separately from A, and telling end-users to use D instead of B when running A. It seems that a company is capable of designing a proprietary program to use a GPL library without violating the GPL, so long as a wrapper module is used to insulate the proprietary program from the GPL library and that module is distributed separately.

Am I correct in my reasoning? Is this a real loophole in the GPL?

*D is also a derivative work of A, but for the purposes of this scenario, Company X has explicitly authorized the creation of D and allowed it to be licensed under the GPL.

答: I am not a lawyer, but as far as I can tell you are not correct, since the program depends on the library - it is still a deriviative work. The same way that a sequal is a deriviative work. At a minimum it is based on the APIs defined in the library.</p>


问:
In languages that don't allow underscores in integer constants, is it a good practice to create a constant for 1 billion?
In languages that don't allow underscores in integer literals, is it a good idea to create a constant for 1 billion?  e.g. in C++:

```<code>size_t ONE_BILLION = 1000000000;
</code>```

Certainly, we shouldn't create constants for small numbers like 100.  But with 9 zeros, it's arguably easy to leave off a zero or add an extra one in code like this:

```<code>tv_sec = timeInNanosec / 1000000000;
tv_nsec = timeInNanosec % 1000000000;
</code>```

答:
In general it's a bad idea to use scalar constants for unit conversions, and if you find yourself making constants for such things you're doing conversion in way too many places.

When you have a quantity of one unit (say, 10 seconds), and want to convert to another unit (i.e. nanoseconds); this is precisely the time to use the type system of your language to ensure that the units are actually scaled as you intend.

Make your function take a Nanoseconds parameter, and provide conversion operators and/or constructors in that class for Seconds, Minutes, or what-have-you.  This is where your const int or #define or 1e9 seen in other answers belongs.

This avoids having variables of ambiguous units floating around your code; and prevents entire swathes of bugs from where the wrong multiply/divide was applied, or was already applied, or the quantity was actually distance instead of time, or...

Also, in such classes it's good to make construction from plain scalarsprivate and use a static "MakeSeconds(int)" or similar to discourage sloppy use of opaque numbers.

More specifically to your example, in C++ check out Boost.Chrono.


问:
How will writing the transaction part in Java benefit the security of the application, when all other parts are being written in PHP?
A friend of mine while working on a PHP application asked me to write one part of the application in Java. The part that involved transactions. He said it will be better to write this portion in Java. He talked about how secure it will be!

Though I was too busy to  help him then, I want to know the essence of this idea. Why he was trying to use Java when he wrote the most part in PHP? Will it really boost up the security? And writing transactions in Java is only concerned with security?

The thing seems very interesting but I really have no idea, what it is! Please provide some insight into the topic.

Note: When I say transaction, it involves everything. From accessing account to transferring money.

答:
One area coding in Java can be considered more secure is in the region of file storage.

With Java, a byte-code file can be stored where the program will be run.  If a compiled Java file is found, it can only be run with a Java virtual machine, and not read or easily reverse engineered.

In PHP, a script file filled with readable text is what is stored.  So if somehow the file was found, then the program could be read with a simple text editor like Notepad or Emacs.

What this means for security is that the inner workings of the program would be hidden if written in Java.  And only in the event that someone had access to the program file.  Normally, with PHP the program exists on a web server and is executed without visibility in a Web Browser.  Your friend, however, probably wants to be extra careful.