问:
Securely storing secret data in a client-side web application
I have this web application that is going to be all client-side technology (HTML, CSS, JavaScript/AngularJS, etc...).  This web application is going to be interacting with REST API in order to access and modify data.  Right now it is undecided on what type of authentication system the REST API is going to use.

From my understanding, any type of API authentication system (API Keys, OAuth 1/2, etc...) is going to have certain data that needs to be kept secret otherwise access can be compromised.  For API Keys, they keys themselves need to be secret, for OAuth 2 the client secret/access tokens/refresh tokens need to be kept secret, I am sure a few of the 4 keys involved in OAuth 1 needs to be kept secret (not too much experience with OAuth 1).  I have been trying to think if there is a way to store this secret stuff in a pure client-side web application without a middle layer of sorts on the server side.

I have been trying to think about this and I can't think of any place to do that.  I mean I can't store it in javascript because anyone can just view the source or open up the console and get the data.  I am not 100% sure how secure localStorage is and if users can access/modify that data.  Even if local storage was secure, the two ways I can think of getting data into it are not.  One way is to just store the data in the javascript source code which is the most insecure thing I can think of.  Now if I was using something like OAuth 2 in which the rest api itself would give me the tokens, that would still not be that secure (better than the first option) because those tokens would be returned as plain text that anyone who can see the requests the computer is making could see.

Is there any way to have an application that is completely running client side be able to store secret pieces of data securely without some sort of middle layer on the server side?

答:
No, it can never be completely secure. The user is in control of the hardware, and you are trying to keep something out of their hands. Ultimately, they CAN get it through one means or another. Since you are working from javascript, your position is MUCH worse than a normal computer application, as not only does the user control the hardware, they control the sandbox that you are running in.

You can hide things, and make it hard to get to stuff, but in the end they CAN get it out, if they try hard enough.


问:
Why have a wrapper constructor when storing a function in a data type?
I can never do too many Haskell tutorials.  There is always something to refine and learn.  So, I am working through chapter 10 of Real World Haskell, and everything makes sense.

but

Why do

```<code>newtype Parse a = Parse { runParse :: ParseState -> Either String (a, ParseState) }

identity :: a -> Parse a
identity a = Parse (\s -> Right (a, s))

getState :: Parse ParseState
getState = Parse (\s -> Right (s, s))

putState :: Parse ()
putState = Parse (\s -> Right ((), s))
</code>```

Why not simply do

```<code>type Parse a = ParseState -> Either String (a, ParseState)

identity :: a -> Parse a
identity a = \s -> Right (a, s)

getState :: Parse ParseState
getState = \s -> Right (s, s)

putState :: Parse ()
putState = \s -> Right ((), s)
</code>```

In other words, what is the purpose of the wrap and unwrap pattern in here (which I see used in a lot of different places in Haskell)?  We get the same Parse Whatever data type, but without the extra indirection.

答: The answer is that Haskell doesn't have arbitrary type lambdas, so when we want to eventually make our Parse type an instance of Monad, a newtype is required.

ContentLicense: CC BY-SA 3.0


问:
Why Object.clone() is able to "see" fields defined in subclasses?
I was wandering how can Object.Clone() access field fields that are actually defined in the subclasses, and not the actual implementation of this feature.

What is bothering me is that I cannot see the logic to allow base class (even if it is "special") to access the fields defined in the subclasses - doesn't this breaks whole object inheritance concept?

Consider this:

```<code>class Test implements Cloneable
{
    private String test_field;

    public Test()
    {
    }

    public Test clone() throws CloneNotSupportedException
    {
       return (Test)super.clone();
    }
}
</code>```

Here, calling Test.clone() will copy the test_field also. Things are even getting weirder for me when it comes to the situation where Test is declared as an abstract class - calling clone() will allow me (in some way) to get the instance of the abstract class.

答:
See this answer on SO https://stackoverflow.com/a/2326801/643483

The short answer to your question is yes, it is problematic to have the clone method on the Object class. According to Josh Bloch (via above link), it would have been better for the clone method to be defined on the Cloneable interface.


问:
Structuring the XML Response
I'm designing an XML response for a consuming application to take in, and I'm weighing two different designs.  Currently I have a design as follows (where the Product element can repeat):

```<code><Response>
    <AccountType>
    <ProductType>
    <Products>
       <Product>
           <ProductID />
           <ProductStatus />
           <ProductName />
       </Product>
       <Product>
           <ProductID />
           <ProductStatus />
           <ProductName />
       </Product>
    </Products>
</Response>
</code>```

An alternate design is:

```<code><Response>
    <AccountType>
    <ProductType>
    <Product>
        <ProductID />
        <ProductStatus />
        <ProductName />
    </Product>
    <Product>
        <ProductID />
        <ProductStatus />
        <ProductName />
    </Product>
</Response>
</code>```

In the first design I have a master element called Products, under which each Product element exists and can repeat within Products.  The second design is a little flatter - where Product exists under the main Response node.

Which one of the two is more optimal for a consuming application to read from and process?

答:
The one that wraps all of the products into a single element. You can treat it as a collection in most programming languages that offer serialization/deserialization.

See XML Serialization of Arrays and Collections

Arrays and collections can be serialized to XML. The standard action when using the default serializer is for the name of the collection property to be added to the XML, with a contained element for each item named according to the items' data types...

Title: Structuring the XML Response


问:
Cyclomatic Complexity Ranges
What are the categories of cyclomatic complexity? For example:

1-5: easy to maintain

6-10: difficult

11-15: very difficult

20+: approaching impossible

For years now, I've gone with the assumption that 10 was the limit. And anything beyond that is bad. I'm analyzing a solution, and I'm trying to make a determination of the quality of the code. Certainly cyclomatic complexity isn't the only measurement, but it can help. There are methods with a cyclomatic complexity of 200+. I know that's terrible, but I'm curious to know about the lower ranges, like in my example above.

I found this:

The aforementioned reference values from Carnegie Mellon define four
  rough ranges for cyclomatic complexity values:

methods between 1 and 10 are considered simple and easy to understand

values between 10 and 20  indicate more complex code, which may still be comprehensible; however testing becomes more difficult due to the greater number of possible branches the code can take

values of 20 and above are typical of code with a very large number of potential execution paths and can only be fully grasped and tested with great difficulty and effort

methods going even higher, e.g. > 50, are certainly unmaintainable

When running code metrics for a solution, the results show green for anything below 25. I disagree with this, but I was hoping to get other input.

Is there a generally accepted range list for cyclomatic complexity?

答:
I suppose it depends on the capabilities of your programming staff, and in no small part on your sensibilities as a manager.

Some programmers are staunch advocates of TDD, and will not write any code without writing a unit test first.  Other programmers are perfectly capable of  creating perfectly good, bug free programs without writing a single unit test.  The level of cyclomatic complexity that each group can tolerate is almost certainly going to vary substantially.

It's a subjective metric; evaluate the setting on your Code Metrics solution, and adjust it to a sweet spot that you feel comfortable with that gives you sensible results.

Title: Cyclomatic Complexity Ranges


问:
Using a DAO to abstract our ORM from the rest of the application
We're using MySQL with Sequelize.js as the ORM.

What we're wondering is whether a DOA layer of abstraction is worthwhile. Here are our options:

To use the Sequelize models throughout the application.

To abstract Sequelize by building a layer that converts Sequelize
    models to Backbone models so that we're using Backbone throughout
    the rest of the application instead.

Is abstraction important in this case or is it normal to use Models from the ORM throughout the other layers?

答:
Don't do it.  An extra layer of hand-written code will cost you far more than you think, and return far less.

Building a DAO layer is worthwhile only if: Sequelize proves inadequate, and you can't modify Sequelize to meet your requirements, and there is another ORM that can do what you need, and the cost of building the DAO layer is less than the cost of switching your code to a new ORM.

I expect that it will cost just as much, and probably more, to create and maintain the DAO layer than you would spend later changing ORMs.


问:
What is the difference between "Syntax" and "Syntactic Sugar"

Background

The Wikipedia page on Syntactic Sugar states:

In computer science, syntactic sugar is syntax within a programming language that is designed to make things easier to read or to express. It makes the language "sweeter" for humans to use: things can be expressed more clearly, more concisely, or in an alternative style that some may prefer.

I don't really understand what the difference is between Syntactic Sugar and Syntax.

I appreciate the point that the sugary version can be clearer, more concise, perhaps boil off some boilerplate. But I feel at some level, all the syntax is essentially doing that to form an abstraction over what the code gets compiled down to.

From the same Wikipedia page:

Language processors, including compilers, static analyzers, and the like, often expand sugared constructs into more fundamental constructs before processing, a process sometimes called "desugaring".

As a thought exercise, if I take "often" in this statement to mean "always": If the difference were just whether the compiler "desugars" the syntax before moving to a next stage, how might a coder who does not know the innards of the compiler know (or care) what is Sugar'd Syntax or not?

A very much related question on this site "Rigorous Definition of Syntactic Sugar?" has an answer which commences:

IMHO I don't think you can have a definition for syntactic sugar, because the phrase is BS and is likely to be used by people that talk about "real programmers" using "real tools" on "real operating systems"

Which might indicate to me that perhaps there isn't a huge difference to the coder using the language?
Perhaps the difference is only perceptible to the compiler writer? Though there may be instances in which it's helpful for the coder using the language to know what's under the hood of the Syntactic Sugar? (But perhaps in reality any discourse on the subject tends to use the term as flame bait?)

The heart of the question

So... the short version of the question:

Is there a real difference between Syntax and Syntactic Sugar?

Who does it matter to?

Extra Food for Thought

Bonus on topic contradiction:

On the Wikipedia page an example is given:

For instance, in the C language the a[i] notation is syntactic sugar for *(a + i)

Whereas another answer on the above linked question talks about the same example:

Now consider a[i] == *(a + i). Think about any C program that uses arrays in any substantive way.

And summarizes that:

The [] notation facilitates this abstraction. It's not syntactic sugar.

The opposite conclusion for the same example!

答:
Usually syntax sugar is the part of language that can be expressed by existing part of language (syntax) without loss of generality but with possibly lossing clarity. Sometimes the compilers have explicit desugaring step which transforms the AST created by the source code and apply simple steps to remove nodes corresponding to sugar.

For example Haskell have syntax sugar for monads with following rules applied recursivly

```<code>do { f }            ~> f
do { g; h }         ~> g >> do h
do { x <- f; h }    ~> f >>= \x -> do h
do { let x = f; h } ~> let x = f in do h
</code>```

Right now it doesn't matter what it means exactly - however you can see that special syntax on LHS can be transformed into something more basic on RHS (namely function applications, lambdas and let's). This steps allows to keep best of both worlds:

The syntax on LHS is easier for programmer (syntax sugar) expressing the existing ideas in more clear manner

However as the support in compiler for RHS constructs do exists already in compiler it doesn't need to treat it as something special outside parser and desugaring (except for error reporting).

Similarly in C you can imagine desugaring rewrite rule (due to operator overloading etc. it is not true for C++):

```<code>f->h ~> (*f).h
f[h] ~> *(f + h)
</code>```

You could imagine writing all programs without using -> or [] in C that use this construction today. However it would be harder for programmers to use it hence provided syntax sugar (I guess in 70's it might simplified work for compilers too). It is possibly less clear as you can technically add the following, perfectly valid, rewrite rule:

```<code>*f ~> f[0] -- * and [] have the same expressiveness
</code>```

Is syntax sugar bad? Not necessarily - there is danger that it will be used as cargo cult without understanding deeper meaning. For example following functions are equivalent in Haskell yet many beginners would write the first form without understanding that they are overusing syntax sugar:

```<code>f1 = do x <- doSomething
        return x
f2 = doSomething
</code>```

In addition syntax sugar might overcomplicate the language or be too narrow to allow generalized idiomatic code. Also it might mean that language is not powerful enough to do certain things easily - it might be by design (don't give developers sharp tools or very specific niche language that adding more powerful construct would hurt other goals) or by omission - the latter form gave the syntax sugar the bad name. If the language is powerful enough to use other constructs without adding syntax sugar it is considered more elegant to use those.

Body:
Usually syntax sugar is the part of language that can be expressed by existing part of language (syntax) without loss of generality but with possibly lossing clarity. Sometimes the compilers have explicit desugaring step which transforms the AST created by the source code and apply simple steps to remove nodes corresponding to sugar.

For example Haskell have syntax sugar for monads with following rules applied recursivly

do { f }            ~> f
do { g; h }         ~> g >> do h
do { x <- f; h }    ~> f >>= \x -> do h
do { let x = f; h } ~> let x = f in do h

Right now it doesn't matter what it means exactly - however you can see that special syntax on LHS can be transformed into something more basic on RHS (namely function applications, lambdas and let's). This steps allows to keep best of both worlds:

The syntax on LHS is easier for programmer (syntax sugar) expressing the existing ideas in more clear manner

However as the support in compiler for RHS constructs do exists already in compiler it doesn't need to treat it as something special outside parser and desugaring (except for error reporting).

Similarly in C you can imagine desugaring rewrite rule (due to operator overloading etc. it is not true for C++):

f->h ~> (*f).h
f[h] ~> *(f + h)

You could imagine writing all programs without using -> or [] in C that use this construction today. However it would be harder for programmers to use it hence provided syntax sugar (I guess in 70's it might simplified work for compilers too). It is possibly less clear as you can technically add the following, perfectly valid, rewrite rule:

*f ~> f[0] -- * and [] have the same expressiveness

Is syntax sugar bad? Not necessarily - there is danger that it will be used as cargo cult without understanding deeper meaning. For example following functions are equivalent in Haskell yet many beginners would write the first form without understanding that they are overusing syntax sugar:

f1 = do x <- doSomething
        return x
f2 = doSomething

In addition syntax sugar might overcomplicate the language or be too narrow to allow generalized idiomatic code. Also it might mean that language is not powerful enough to do certain things easily - it might be by design (don't give developers sharp tools or very specific niche language that adding more powerful construct would hurt other goals) or by omission - the latter form gave the syntax sugar the bad name. If the language is powerful enough to use other constructs without adding syntax sugar it is considered more elegant to use those.


答:
one option is for the REST API to grant access or not based on a user login; it can return a session-based token (guid, hashed string, whatever you like) which can be passed to the other REST API calls to authenticate access

if you're worried about storing the user login info on the client machine, then don't, but the user will have to enter the account and password information every time

not that familiar with OAuth et al, but I see no compelling reason above to store authentication information persistently at all...

Title: Securely storing secret data in a client-side web application

Body:
I have this web application that is going to be all client-side technology (HTML, CSS, JavaScript/AngularJS, etc...).  This web application is going to be interacting with REST API in order to access and modify data.  Right now it is undecided on what type of authentication system the REST API is going to use.

From my understanding, any type of API authentication system (API Keys, OAuth 1/2, etc...) is going to have certain data that needs to be kept secret otherwise access can be compromised.  For API Keys, they keys themselves need to be secret, for OAuth 2 the client secret/access tokens/refresh tokens need to be kept secret, I am sure a few of the 4 keys involved in OAuth 1 needs to be kept secret (not too much experience with OAuth 1).  I have been trying to think if there is a way to store this secret stuff in a pure client-side web application without a middle layer of sorts on the server side.

I have been trying to think about this and I can't think of any place to do that.  I mean I can't store it in javascript because anyone can just view the source or open up the console and get the data.  I am not 100% sure how secure localStorage is and if users can access/modify that data.  Even if local storage was secure, the two ways I can think of getting data into it are not.  One way is to just store the data in the javascript source code which is the most insecure thing I can think of.  Now if I was using something like OAuth 2 in which the rest api itself would give me the tokens, that would still not be that secure (better than the first option) because those tokens would be returned as plain text that anyone who can see the requests the computer is making could see.

Is there any way to have an application that is completely running client side be able to store secret pieces of data securely without some sort of middle layer on the server side?


问:
Storing User Form Data
I am trying to come up with a data schema/methodology for storing the data collected from various different user application forms.

All forms contain the basic info like name, address, etc but then they diverge in what they collect.  Each application will have its own unique subset of questions they want to ask.  Because of this one "answers" table is out of the question.  Would i be better off normalizing the database into a questions table and answers table? Another option considered would be to have a table of answers for the standard/universal questions and then serializing and storing the other answers in a field.  Given that, would i be better moving to a straight up nosql database option? Maybe nosql is overkill and i really just need EAV?

Once information is collected, it won't be edited.  Just needs to be read.

答: If the forms don't change too often, and their structures are well-defined, I'd suggest going with one table to hold common info, and then other tables to hold values particular to certain forms, linked back to the main table. I think an EAV-based approach would be more appropriate if your system will be expected to handle data from forms that are added/updated very frequently (too fast for you to create/update tables), or if you have a need to have a form-creation tool connected to your system, where users can author whatever type of form they want. I haven't used any nosql solution but it might also help.</p>

Title: Storing User Form Data


答:
There are no predefined categories and no categorization would be possible for several reasons:

Some refactoring techniques just move the complexity from one point to another (not from your code to the framework or a well-tested external library, but from one location to another of the codebase). It helps reducing cyclomatic complexity and helps convincing your boss (or any person who loves presentations with constantly increasing graphics) that you spent your time making something great, but the code stays as bad as it was previously.

At the opposite, sometimes, when you refactor a project by applying some design and programming patterns, cyclomatic complexity can become worse, while the refactored code is expected to be clear: developers know programming patterns (at least they are expected to know them), so it simplifies the code for them, but cyclomatic complexity doesn't take this in account.

Some other non-refactoring techniques don't affect the cyclomatic complexity at all, while severely decreasing the complexity of a code for developers. Examples: adding relevant comments or documentation. "Modernizing" the code by using syntactic sugar.

There are simply cases where cyclomatic complexity is irrelevant. I like the example given by whatsisname in his comment: some large switch statements can be extremely clear and rewriting them in a more OOPy way would not be very useful (and would complicate the understanding of the code by beginners). At the same time, those statements are a disaster, cyclomatic complexity-wise.

As Robert Harvey already said above, it depends on the team itself.

In practice, I've seen source code which had good cyclomatic complexity, but which was terrible. At the same time, I've seen code with high cyclomatic complexity, but I hadn't too much pain understanding it.

It's just that there is no and couldn't be any tool which would indicate, flawlessly, how good or bad is a given piece of code or how easy is it to maintain. As you can't program an application which will tell that a given painting is a masterpiece, and that another one should be thrown away, because it has no artistic value.

There are metrics which are broken by design (like LOC or the number of comments per file), and there are metrics which can give some raw hints (like the number of bugs or the cyclomatic complexity). In all cases, those are just hints, and should be used with caution.

Title: Cyclomatic Complexity Ranges

Body:
What are the categories of cyclomatic complexity? For example:

1-5: easy to maintain

6-10: difficult

11-15: very difficult

20+: approaching impossible

For years now, I've gone with the assumption that 10 was the limit. And anything beyond that is bad. I'm analyzing a solution, and I'm trying to make a determination of the quality of the code. Certainly cyclomatic complexity isn't the only measurement, but it can help. There are methods with a cyclomatic complexity of 200+. I know that's terrible, but I'm curious to know about the lower ranges, like in my example above.

I found this:

The aforementioned reference values from Carnegie Mellon define four
  rough ranges for cyclomatic complexity values:

methods between 1 and 10 are considered simple and easy to understand

values between 10 and 20  indicate more complex code, which may still be comprehensible; however testing becomes more difficult due to the greater number of possible branches the code can take

values of 20 and above are typical of code with a very large number of potential execution paths and can only be fully grasped and tested with great difficulty and effort

methods going even higher, e.g. > 50, are certainly unmaintainable

When running code metrics for a solution, the results show green for anything below 25. I disagree with this, but I was hoping to get other input.

Is there a generally accepted range list for cyclomatic complexity?


问:
When is it better to offload work to the RDBMS rather than to do it in code?
Okay, I'll cop to it: I'm a better coder than I am at databases, and I'm wondering where thoughts on "best practices" lie on the subject of doing "simple" calculations in the SQL query vs. in the code, such as this MySQL example (I didn't write it, I just have to maintain it!) -- This returns the username, and the users age as of the last event.

```<code>SELECT u.username as user,
       IF ((DAY(max(e.date)) - DAY(u.DOB)) < 0 ,
       TRUNCATE(((((YEAR(max(e.date))*12)+MONTH(max(e.date)))
       -((YEAR(u.DOB)*12)+MONTH(u.DOB)))-1)/12, 0),
       TRUNCATE((((YEAR(max(e.date))*12)+MONTH(max(e.date))) -
       ((YEAR(u.DOB)*12)+MONTH(u.DOB)))/12, 0)) AS age
FROM users as u
JOIN events as e ON u.id = e.uid
...
</code>```

Compared to doing the "heavy" lifting in code:

Query:

```<code>SELECT u.username, u.DOB as dob, e.event_date as edate
FROM users as u
JOIN events as e ON u.id = e.uid
</code>```

code:

```<code>function ageAsOfDate($birth, $aod)
{    //expects dates in mysql Y-m-d format...
     list($by,$bm,$bd) = explode('-',$birth);
     list($ay,$am,$ad) = explode('-',$aod);

     //Insert Calculations here
     ...
     return $Dy; //Difference in years
}

echo "Hey! ". $row['user'] ." was ". ageAsOfDate($row['dob'], $row['edate']) . " when we last saw him.";
</code>```

I'm pretty sure in a simple case like this it wouldn't make much difference (other than the creeping feeling of horror when I have to make changes to queries like the first one), but I think it makes it clearer what I'm looking for.

Thanks!

答:
Each case is different

Is the logic...

needed by other clients? DRY: in the database

used for further processing? eg sort by age descending: in the database

requires regional settings? dd/mm/yyyy or mm/dd/yyyy: in the client

used often? Why calculate it again and again: use computed and persisted column in the database

In this case, I might use a computed and persisted column in the database

It could be worse: you could have this in the database:

```<code>"Hey! ". u.username." was ". <datecalc>. " when we last saw him."
</code>```

ContentLicense: CC BY-SA 2.5

Body:
Each case is different

Is the logic...

needed by other clients? DRY: in the database

used for further processing? eg sort by age descending: in the database

requires regional settings? dd/mm/yyyy or mm/dd/yyyy: in the client

used often? Why calculate it again and again: use computed and persisted column in the database

In this case, I might use a computed and persisted column in the database

It could be worse: you could have this in the database:

"Hey! ". u.username." was ". <datecalc>. " when we last saw him."


问:
Suggestions to improve small team workflow (CI / Deployment)
I'd like to improve my team's workflow and architecture.

Right now we have a LAMP dev server on which every member of the team has a subdirectory. We work directly in this directory via LAN. There is also a "release" directory for when we're ready to upload via FTP to the production server.

We use a github private repo that serves as a centralized repo.

Example of a programmer's current daily workflow :

Choose a user story to work on after a quick daily meeting
Open a git branch named after the user story
Work, commit some changes
Push to github
When I decide to deploy, I pull the changes, perform a code review, change the needed variables for production and upload via FTP. If changes were made to the dev database I replicate them on the production server's database as well.

Any ideas where I should begin to improve this situation ? Current issues :

Members of the team can't easily work from home since they'd have to edit on the dev server directly (lag issues)

Deployment process is awful (changing variables manually and FTPing to production)

EDIT :
I'll try to add better questions.

Setting up subdirectories for each developer on a common dev server : good idea or not ? Possible alternative : each developer setups his own dev environment (using WAMP or similar) and pushes to test server.

For the deployment aspect I feel manually changing config variables and FTPing to production is a bad idea. Possible alternative : setting up git on production server, set config files in .gitignore (maintain them manually directly on production server) and git pushing the changes.

For remote developers, should they replicate the dev environment (again, WAMP or similar) but work on the dev server's database ? I think it's better than copying the database on local machines.

答:
Give each dev his own environment, doesn't matter if that's on a shared box or a local install (local installs do have many advantages though)

Next, get your server to build and automatically deploy to a test (or integration) environment. As commits are pushed on a dev branch, they get deployed to this central test environment so you can give it some testing preferably using automated tools.

Then get a similar setup to the test environment for the release branch - so when the code gets merged, it also gets deployed but to a more representative system. Typically the test and pre-production environments will start off the same, but the test one will end up with more cruft built up on it, the pre-prod should be much cleaner as only code that's merged onto the release branch will end up on it, with no 'experimental' code or rollbacks.

Configs - this is a standard SCM problem, I'd keep a separate area for the config for each environment (inc. production too) and store all versions in there, then pick the right one for whichever deployment is happening. Obviously you will need to script all this so it works correctly, and it can be a PiTA, but it seems you already have the necessary steps to perform for deploy, so just script them. I'd recommend Jenkins as a CI server which will help you with this if you don't want to code it directly in githooks.


问:
Application architecture for subscriber based system
I am planning on building a system where users "subscribe" to "records".

Records are updated on a schedule, several times a day.

When records are updated, the user should be notified that these records have been added/updated.

I don't want each user to have their own copy of the records due to storage space and the overhead of inserting many records, one for each subscriber, each time the schedule runs.

However, each user will need to add metadata against each record they are subscribed to. Such as notes and flags that the record has been read etc.

Can anyone give me any advice or how to structure such a system or where I can learn more about this sort of application architecture?

Is this the correct place to ask?

At the moment, I'm not even sure what to Google for ;)

答:
In the past, I've accomplished this with Event tables.

```<code>Events                   EventTypes           Records                 Users

EventID
UserID  ------------------------------------------------------------  UserID
RecordID  ----------------------------------  RecordID                Name
EventTypeID  ----------  EventTypeID          Description             Title
DateTime                 Name                 DateTime                Phone
Notes                    Description          LinkToDocument
</code>```

Each event record is a reckoning of something that a user did to a document, what that action was (the Event Type: Add, change, delete, print, etc.), which document the action was performed on, what date and time the action occurred, and any notes associated with the action.

Body:
In the past, I've accomplished this with Event tables.

Events                   EventTypes           Records                 Users

EventID
UserID  ------------------------------------------------------------  UserID
RecordID  ----------------------------------  RecordID                Name
EventTypeID  ----------  EventTypeID          Description             Title
DateTime                 Name                 DateTime                Phone
Notes                    Description          LinkToDocument

Each event record is a reckoning of something that a user did to a document, what that action was (the Event Type: Add, change, delete, print, etc.), which document the action was performed on, what date and time the action occurred, and any notes associated with the action.


答:
Syntactic sugar is a subset of the languages syntax.  The basic idea is that there is more than one way to say the same thing.

What makes it difficult to say which pieces are syntactic sugar and which pieces are "pure syntax" are statements like "it's hard to say which form came first" or "it's hard to know which way the author of the language intended" or "it's somewhat arbitrary to decide which form is simpler".

What makes it easy to decide which pieces are pure or sugary are to ask the question within the frame of a specific compiler or interpreter.  The pure syntax is the stuff that a compiler converts directly to machine-code or that the interpreter directly responds to.  The sugar is the stuff that first gets turned into some other syntax stuff before these direct things happen.  Depending on the implementation, this may or may not be the same as what the author intended or even what the language spec claims.

In practice, this is the way that the reality of the matter is decided.

Title: What is the difference between "Syntax" and "Syntactic Sugar"

Body:
Background

The Wikipedia page on Syntactic Sugar states:

In computer science, syntactic sugar is syntax within a programming language that is designed to make things easier to read or to express. It makes the language "sweeter" for humans to use: things can be expressed more clearly, more concisely, or in an alternative style that some may prefer.

I don't really understand what the difference is between Syntactic Sugar and Syntax.

I appreciate the point that the sugary version can be clearer, more concise, perhaps boil off some boilerplate. But I feel at some level, all the syntax is essentially doing that to form an abstraction over what the code gets compiled down to.

From the same Wikipedia page:

Language processors, including compilers, static analyzers, and the like, often expand sugared constructs into more fundamental constructs before processing, a process sometimes called "desugaring".

As a thought exercise, if I take "often" in this statement to mean "always": If the difference were just whether the compiler "desugars" the syntax before moving to a next stage, how might a coder who does not know the innards of the compiler know (or care) what is Sugar'd Syntax or not?

A very much related question on this site "Rigorous Definition of Syntactic Sugar?" has an answer which commences:

IMHO I don't think you can have a definition for syntactic sugar, because the phrase is BS and is likely to be used by people that talk about "real programmers" using "real tools" on "real operating systems"

Which might indicate to me that perhaps there isn't a huge difference to the coder using the language?
Perhaps the difference is only perceptible to the compiler writer? Though there may be instances in which it's helpful for the coder using the language to know what's under the hood of the Syntactic Sugar? (But perhaps in reality any discourse on the subject tends to use the term as flame bait?)

The heart of the question

So... the short version of the question:

Is there a real difference between Syntax and Syntactic Sugar?

Who does it matter to?

Extra Food for Thought

Bonus on topic contradiction:

On the Wikipedia page an example is given:

For instance, in the C language the a[i] notation is syntactic sugar for *(a + i)

Whereas another answer on the above linked question talks about the same example:

Now consider a[i] == *(a + i). Think about any C program that uses arrays in any substantive way.

And summarizes that:

The [] notation facilitates this abstraction. It's not syntactic sugar.

The opposite conclusion for the same example!


问:
Why is Lisp useful?
Lisp obviously is an advantage for the AI stuff, but it doesn't appear to me that Lisp is any faster than Java, C#, or even C. I am not a master of Lisp, but I find it incredibly difficult to understand the advantage one would get in writing business software in Lisp.

Yet it is considered as a hacker's language.

Why does Paul Graham advocate Lisp? Why did ITA Software choose Lisp over other high-level languages? What value does it have over these languages?

答:
A big draw is the community. Lisp has had a draw for the most ambitious and bright developers since the language was invented. Wherever researchers are trying to solve problems that have never been solved you are likely to find Lisp, as in artificial intelligence (AI) research, computer vision, planning, knowlege representation, and complex heuristic optimization. The language lends itself to solving problems both from the bottom up and the top down at the same time, which seems to help in confronting the hairiest challenges.

The exensible syntax via macros means that there is seldom a need to extend the language definition. Much of what would require a language extension in a more restricted language is just a macro away with Lisp. So Lisp programmers are free to make use of newly invented language concepts without a new language standard and without necessarily a real speed penalty. On a basic level, reams of boilerplate code are made unnecessary by small extensions. Whole new ideas in control flow, like Prolog style unification, are implemented efficiently and compactly as extensions.

The OOP system, CLOS, is in a class of its own in terms of flexibility. It is very difficult to go back to rudimentary C++/Java/C# OOP after getting a taste. GoF 5 design patterns become unnecessary as they can be expressed simply and directly.

The language has had no single corporate owner and no single definitive implementation, though it does have an ANSI standard with many conforming implementations. Major new implementations come along every decade and the old ones are still quite active. Experts can plan to use their specialized knowledge for a long time to come. This does cause some anarchistic friction and community fragmentation, but it also means the carpet cannot be pulled out and the language can't become moribund for corporate or project political reasons. There are always multiple commercial and open source implementations being worked on. The more performance focused ones regularly benchmark within a 2x factor of the very fastest, heavily funded imperative language implementations.

The Achilles heel of early Lisp commercialization was memory footprint to accomodate both the type safety features of the language and the advanced software development environments they included, with incredible features like full online documentation including graphics. A 64 MB Symbolics Lisp Machine was not viable cost-wise against an 8 MB Sun workstation. Today, RAM prices have collapsed and there is tremendous interest in the Lisp languages especially considering that the mainstream Java, C#, PHP languages today have advanced only minimally over those of 30 years ago.

There are modern languages now in competition with Lisp for mindshare with intelligent developers: Python, Lua, Erlang, Haskell, and OCaml. But none offers the same mix of maturity, adaptibility, multiple standards-compliant implementations and speed.

Title: Why is Lisp useful?


问:
Why should I use List<T> over IEnumerable<T>?
In my ASP.net MVC4 web application I use IEnumerables, trying to follow the mantra to program to the interface, not the implementation.

```<code>Return IEnumerable(Of Student)
</code>```

vs

```<code>Return New List(Of Student)
</code>```

People are telling me to use List and not IEnumerable, because lists force the query to be executed and IEumerable does not.

Is this really best practice? Is there any alternative? I feel strange using concrete objects where an interface could be used. Is my strange feeling justified?

答:
There are times when doing a ToList() on your linq queries can be important to ensure your queries execute at the time and in the order that you expect them to. Those scenarios are however rare and nothing one should worry too much about until they genuinely run into them.

Long story short, use IEnumerable anytime you only need iteration, use IList when you need to index directly and need a dynamically sized array (if you need indexing on a fixed size array then just use a standard array).

As for the execution time thing, you can always use a list as an IEnumerable variable, so feel free to return an IEnumerable by doing a .ToList();, or pass in a parameter as an IEnumerable by executing .ToList() on the IEnumerable to force execution right then and there. Just be careful that anytime you force execution with .ToList() you don't hang on to the IEnumerable variable which you just did that to and execute it again, or else you'll end up doubling the iterations in your LINQ query unnecessarily.

In regards to MVC, there is really nothing special to note here. It's going to follow the same execution time rules as the rest of .NET, I think you might have someone who was bit by confusion caused by the delayed execution semantics in the past and blamed it on MVC telling you this is somehow related, but it's not. The delayed execution semantics confuse everybody at first (and even for a good while afterwards; they can be a touch tricky). Again though, just don't worry about it until you really care about ensuring a LINQ query doesn't get executed twice or require it executed in a certain order relative to other code, at which point assign your variable to itself.ToList() to force execution and you'll be fine.


答:
There are two issues.

```<code>IENumerable<Data> query = MyQuery();

//Later
foreach (Data item in query) {
  //Process data
}
</code>```

By the time the "Process Data" loop is reached, the query may no longer by valid.  For example, if the query is being run on a DataContext that has already been Disposed, your code will throw an exception.  This kind of thing becomes very confusing when you are processing a query in a different context than where you created it.

A secondary issue is that your connection will not be released until the "Process Data" loop completes.  This is only a problem if "Process Data" is complex.  This is mentioned at http://msdn.microsoft.com/en-us/library/bb386929.aspx :

Q. How long does my database connection remain open?

A. A connection typically remains open until you consume the query
  results. If you expect to take time to process all the results and are
  not opposed to caching the results, apply ToList to the query. In
  common scenarios where each object is processed only one time, the
  streaming model is superior in both DataReader and LINQ to SQL.

So, these issues are why you are being encouraged to ensure that the query is actually executed, e.g. by calling ToList().  However, as Jimmy Suggests there is nothing stopping you from returning your List as an IEnumerable .

As a general rule, I recommend avoiding iterating over an IEnumerable more than once.  Assuming consumers of your code follow this rule, I don't consider it a concern that someone might hit the database twice by executing the query twice.

Title: Why should I use List<T> over IEnumerable<T>?

Body:
In my ASP.net MVC4 web application I use IEnumerables, trying to follow the mantra to program to the interface, not the implementation.

```<code>Return IEnumerable(Of Student)
</code>```

vs

```<code>Return New List(Of Student)
</code>```

People are telling me to use List and not IEnumerable, because lists force the query to be executed and IEumerable does not.

Is this really best practice? Is there any alternative? I feel strange using concrete objects where an interface could be used. Is my strange feeling justified?

Body:
There are two issues.

IENumerable<Data> query = MyQuery();

//Later
foreach (Data item in query) {
  //Process data
}

By the time the "Process Data" loop is reached, the query may no longer by valid.  For example, if the query is being run on a DataContext that has already been Disposed, your code will throw an exception.  This kind of thing becomes very confusing when you are processing a query in a different context than where you created it.

A secondary issue is that your connection will not be released until the "Process Data" loop completes.  This is only a problem if "Process Data" is complex.  This is mentioned at http://msdn.microsoft.com/en-us/library/bb386929.aspx :

Q. How long does my database connection remain open?

A. A connection typically remains open until you consume the query
  results. If you expect to take time to process all the results and are
  not opposed to caching the results, apply ToList to the query. In
  common scenarios where each object is processed only one time, the
  streaming model is superior in both DataReader and LINQ to SQL.

So, these issues are why you are being encouraged to ensure that the query is actually executed, e.g. by calling ToList().  However, as Jimmy Suggests there is nothing stopping you from returning your List as an IEnumerable .

As a general rule, I recommend avoiding iterating over an IEnumerable more than once.  Assuming consumers of your code follow this rule, I don't consider it a concern that someone might hit the database twice by executing the query twice.


问:
Attempt at understanding the double-dispatch pattern
I've been trying to grok the double-dispatch pattern and having a hard time. I finally attempted a sample program to help myself understand. Here's the gist. But then I decided to attempt it without Double dispatch and the solution didn't look any more terrible than usual. What am I doing wrong?</p>

答:
I've answered the question at SO. This is essentially the same answer as over there.

In single dispatch---what you see in most modern OO languages---a method is dispatched based on the run-time type of a single object. This shows up as the dot operator (in ruby, java, javascript, etc.) or the arrow operator (perl, c++).

```<code># look, ma single dispatch!
# method on obj's run-time type that is called
dentist.work_on(patient)
</code>```

Double dispatch, then, would be based on the run-time type of two objects. There are a few ways this could look; and on which object should the method live?

```<code># Hmm, this looks weird.
# Is the method in to dentist.class or patient.class?
(dentist, patient).do_dentistry()

# okay, this looks more familiar; the method lives on obj1.class
# This only works in static-typed languages which support double dispatch
# in which you declare the type of the method parameters.
dentist.work_on(patient)

class Dentist
   def work_on(Adult patient); ...; end
   def work_on(Child patient); ...; end
end
</code>```

Languages like groovy that have multiple dispatch generalize the second example above; they consider the run-time types of all parameters when choosing which method to run. See for example this blog post about groovy and multiple dispatch.

Most modern OO languages only have single dispatch and the Multiple Dispatch Pattern is an attempt to get the benefits of multiple dispatch into the language. It even works for dynamic languages like ruby. It works by doing single dispatch twice in a row. The first method call will call a method on the second object.

```<code>class Dentist
    def work_on(param)
       param.dispatch_work(self)
    end
    def work_on_adult(patient)
      drill_as_hard_as_you_can(patient)
    end
    def work_on_child(patient)
      use_bubble_gum_toothpaste(patient)
    end
end

class Adult
    def dispatch_work(dentist)
      dentist.work_on_adult(self)
    end
end

class Child
    def dispatch_work(dentist)
      dentist.work_on_child(self)
    end
end
</code>```

The double dispatch pattern is what I call a low-level pattern because other patterns are built on it. For example, the Visitor pattern relies heavily on the double dispatch pattern.

Looking at your gists, your first gist doesn't really doing double dispatch. Sure, you're dispatching twice, but you're not changing the behavior in that second dispatch. To change it to double dispatch I'd do something like this.

```<code>class Chicken
  def make_dispatch dish
    dish.make_with_chicken self
  end
end

class Beef
  def make_dispatch dish
    dish.make_with_beef self
  end
end

module Dish
  def make meat
    meat.make_dispatch self
  end
end

class Sandwich
  include Dish

  def make_with_chicken chicken
    puts "Grilled Chicken Sandwich"
  end

  def make_with_beef beef
    puts "Roast Beef Sandwich"
  end
end

class Stew
  include Dish

  def make_with_chicken chicken
    puts "Thai curry"
  end

  def make_with_beef beef
    puts "Beef stew"
  end
end

class Casserole
  include Dish

  def make_with_chicken chicken
    puts "Chicken Pot Pie--or something"
  end

  def make_with_beef beef
    puts "Shepard's Pie"
  end
end

Sandwich.new.make(Chicken.new)
Stew.new.make(Chicken.new)
Casserole.new.make(Beef.new)
</code>```

Body:
I've answered the question at SO. This is essentially the same answer as over there.

In single dispatch---what you see in most modern OO languages---a method is dispatched based on the run-time type of a single object. This shows up as the dot operator (in ruby, java, javascript, etc.) or the arrow operator (perl, c++).

# look, ma single dispatch!
# method on obj's run-time type that is called
dentist.work_on(patient)

Double dispatch, then, would be based on the run-time type of two objects. There are a few ways this could look; and on which object should the method live?

# Hmm, this looks weird.
# Is the method in to dentist.class or patient.class?
(dentist, patient).do_dentistry()

# okay, this looks more familiar; the method lives on obj1.class
# This only works in static-typed languages which support double dispatch
# in which you declare the type of the method parameters.
dentist.work_on(patient)

class Dentist
   def work_on(Adult patient); ...; end
   def work_on(Child patient); ...; end
end

Languages like groovy that have multiple dispatch generalize the second example above; they consider the run-time types of all parameters when choosing which method to run. See for example this blog post about groovy and multiple dispatch.

Most modern OO languages only have single dispatch and the Multiple Dispatch Pattern is an attempt to get the benefits of multiple dispatch into the language. It even works for dynamic languages like ruby. It works by doing single dispatch twice in a row. The first method call will call a method on the second object.

class Dentist
    def work_on(param)
       param.dispatch_work(self)
    end
    def work_on_adult(patient)
      drill_as_hard_as_you_can(patient)
    end
    def work_on_child(patient)
      use_bubble_gum_toothpaste(patient)
    end
end

class Adult
    def dispatch_work(dentist)
      dentist.work_on_adult(self)
    end
end

class Child
    def dispatch_work(dentist)
      dentist.work_on_child(self)
    end
end

The double dispatch pattern is what I call a low-level pattern because other patterns are built on it. For example, the Visitor pattern relies heavily on the double dispatch pattern.

Looking at your gists, your first gist doesn't really doing double dispatch. Sure, you're dispatching twice, but you're not changing the behavior in that second dispatch. To change it to double dispatch I'd do something like this.

class Chicken
  def make_dispatch dish
    dish.make_with_chicken self
  end
end

class Beef
  def make_dispatch dish
    dish.make_with_beef self
  end
end

module Dish
  def make meat
    meat.make_dispatch self
  end
end

class Sandwich
  include Dish

  def make_with_chicken chicken
    puts "Grilled Chicken Sandwich"
  end

  def make_with_beef beef
    puts "Roast Beef Sandwich"
  end
end

class Stew
  include Dish

  def make_with_chicken chicken
    puts "Thai curry"
  end

  def make_with_beef beef
    puts "Beef stew"
  end
end

class Casserole
  include Dish

  def make_with_chicken chicken
    puts "Chicken Pot Pie--or something"
  end

  def make_with_beef beef
    puts "Shepard's Pie"
  end
end

Sandwich.new.make(Chicken.new)
Stew.new.make(Chicken.new)
Casserole.new.make(Beef.new)


问:
Separation of Concerns While Creating a Generic Concept of a "Cart Item"
Pretty simple setup: I've got a Cart and the cart has Items. I've got many varying types of "products" that can't really be boiled down into one thing or even a common ancestor, so I've instead decided to simply create a representation of the product as a CartItem, which contains all the information from the product needed to make the sale.

That's where the question comes in. I could handle this in three ways that I see. For these examples we'll just say I have two types of "products": Widgets and Gizmos. Again, these two things are so vastly different that it doesn't make sense for them to inherit from any base class.

1) Both a Widget and a Gizmo have the ability to create a Cart Item to represent themselves, but this requires both to have knowledge of CartItem and any change to CartItem will require me to touch both Widget and Gizmo (not ideal, obviously)

2) A CartItem can create itself from either a Widget or a Gizmo. This would essentially be a factory pattern and would require CartItem to have knowledge of both Widget and Gizmo. This is better than #1 in that I don't have to make changes to every kind of "product" if I change CartItem, but I do have to remember that if I change a particular "product" then I must change the factory method of CartItem for that. (still not ideal, because Murphy says I will forget).

3) Use something like the controller as the "glue". WidgetController and GizmoController will have AddToCart actions that translate a Widget or Gizmo, respectively, into a CartItem. This really sort of presents the same problems as #1, in that if CartItem changes, I need to update all the "product" controllers, and in fact mixes in the problems of #2, in that I must remember to always maintain this mapping if something on either side changes. However, it feels more like a job for the controller: it's oriented for dealing with multiple types, whereas it just feels wrong to mix in types at the model level.

4) Three that I can see; #4 would be something I have yet to consider that one of you kind individuals may happen to suggest.

I'm open to any comments here. If I'm missing something completely obvious, feel free to call me a moron and point how just how big a moron I am. I like feeling stupid; that's when I'm learning ;).

答:
It really smells to me like you want an ICartItem interface. If it's contract needs changing, every single implementer will break the build until they all have been updated appropriately, so it'll keep you honest.

If you're in a dynamically typed language however then I would say the same thing except as an interface exists to be a contract that keeps objects honest, in dynamically typed languages the only technique you have available to keep your objects honest is run-time tests, so I'd write some tests that ensure all the objects you expect to implement the ICartItem interface actually implement all of it's parts with expected signatures. If you're in a static-typed language though then you get these guarantees for free at compile-time.

I think all 3 you're mentioning is thinking too much in the framework of common objects, when common contracts are lighter weight while maintaining greater compile-time guarantees. Common objects are for when you have shared functionality you don't want to repeat, but in your situation you're claiming zero logical shared functionality. You just want to treat different types like the same type, that's the definition of polymorphism and the entire singular purpose of interfaces.


答:
It depends a little on how complex it is to create a CartItem, but I would either go with option (1), or option (1) that delegates the actual creation to another class.

(2) violates the open-closed principle - if you are to add a new third product type Gadget you would have to change CartItem so it can create itself from a Gadget as well.

(3) is less reusable than having it in the model. If you need a new controller that serves a different view you would be tempted to call methods from the other WidgetController just to create a CartItem.

Also, I don't think your objections to #1 is justified. I think it's natural that a product knows how to create a CartItem of itself. But if you think it seems smelly, perhaps it is more natural to have a addToCart(cart, quantity) method in Widget and Gizmo instead, hiding where the actual CartItem is created?

Title: Separation of Concerns While Creating a Generic Concept of a "Cart Item"

Body:
Pretty simple setup: I've got a Cart and the cart has Items. I've got many varying types of "products" that can't really be boiled down into one thing or even a common ancestor, so I've instead decided to simply create a representation of the product as a CartItem, which contains all the information from the product needed to make the sale.

That's where the question comes in. I could handle this in three ways that I see. For these examples we'll just say I have two types of "products": Widgets and Gizmos. Again, these two things are so vastly different that it doesn't make sense for them to inherit from any base class.

1) Both a Widget and a Gizmo have the ability to create a Cart Item to represent themselves, but this requires both to have knowledge of CartItem and any change to CartItem will require me to touch both Widget and Gizmo (not ideal, obviously)

2) A CartItem can create itself from either a Widget or a Gizmo. This would essentially be a factory pattern and would require CartItem to have knowledge of both Widget and Gizmo. This is better than #1 in that I don't have to make changes to every kind of "product" if I change CartItem, but I do have to remember that if I change a particular "product" then I must change the factory method of CartItem for that. (still not ideal, because Murphy says I will forget).

3) Use something like the controller as the "glue". WidgetController and GizmoController will have AddToCart actions that translate a Widget or Gizmo, respectively, into a CartItem. This really sort of presents the same problems as #1, in that if CartItem changes, I need to update all the "product" controllers, and in fact mixes in the problems of #2, in that I must remember to always maintain this mapping if something on either side changes. However, it feels more like a job for the controller: it's oriented for dealing with multiple types, whereas it just feels wrong to mix in types at the model level.

4) Three that I can see; #4 would be something I have yet to consider that one of you kind individuals may happen to suggest.

I'm open to any comments here. If I'm missing something completely obvious, feel free to call me a moron and point how just how big a moron I am. I like feeling stupid; that's when I'm learning ;).


问:
How to time the sprints in Scrum to allocate time for TDD?
We have sprints of 4 weeks duration. What I have been doing is 3 weeks dev time and 1 week of pure manual/automated testing, stabilization and shipment assurance testing.

How to manage TDD within dev time? In my previous experience writing tests and getting 80% coverage requires round about 50% of the development time. Following the same we would get only 1 and a half week of development which is not enough.

My actual problem is how to allocate time for TDD? I want to make TDD a mandatory but with these it becomes really difficult for me. Do you think this is correct approach we are using or are we missing something and alter our approach to Scrum?

答:
First I need to mention that 3 weeks of development and 1 week of testing is not Scrum, but instead time-boxed waterfall.  As the core philosophy in scrum is continual inspection and adaptation, I would strongly recommend looking at the interaction between programmers and testers and coaching them to work incrementally.

The correct Scrum answer will be "Ask the team" as this is what self organization, inspection and adaptation is about.  The problem they need to solve is how a programmer can write a small bit of code with a maximum of 1/2 day and give something to a tester to test.  This does not mean the feature has to be complete, but just incrementally added to source control and testable by a tester.

TDD is a good approach to look at as this will encourage programmers to think of how it is going to be tested, before coding and then doing the minimum to get the tests to pass.

OwnerDisplayName: Haris


答: I would prefer option (2) but put the factory in a separate class. This way you can avoid polluting your products with information about how to make cartitems. If the product changes the factory doesn't really have to change like you have mentioned. Only if the construction of the cartitem changes, which is exactly what the factory is for.</p>


问:
how to stay efficient when a build is almost always broken
I work in a middle sized team which shares the same source code and while have a continues integration in place, but as all of us has to work in the same branch, the build is almost always broken.

As we also have a rule, which has been introduced recently to alleviate the broken builds, which states that no one is allowed to check-in while to build is red.

Having said that, during a day everyone have a handful of 10-15 minutes windows where we allowed to check-in.

And as the team is growing, the windows of check-in opportunities shrinking even more. That forces developers to accumulate their changes locally, which results in a bigger change sets which even more difficult to ensure that the changes are not breaking anything. You can see the vicious cycle.

What can you recommend to allow me to stay effective working in environment like this.
Also, please keep in mind that I am a developer, not a manager, and can't change the process or other people behavior much.

答:
developers... accumulate their changes locally... You can see the vicious cycle.

It's vicious indeed. Accumulating changes locally is a big red flag indicating that something is severely rotten in dev process. It sort of trashes the whole purpose of having a version control system.

As long as you want to stay away from changing the process or other people behavior, the most natural solution would be to set up your own branch and use it to "accumulate" your changes (to be further integrated with team branch when you get a chance).

Actually, if there are more guys like you, you can even collaborate and establish shared development branch to freely exchange your updates without being interfered with incompetent management ideas. Branching allows for many different ways to simplify teamwork.

Side note, every time that manager does or says something that forces you to avoid commits, to keep the code locally, translate their words into bold and plain "I am incompetent".

please keep in mind that I am a developer, not a manager, and can't change the process or other people behavior much...

For the sake of precision, you actually can, these are matters of influence and communication skills and one doesn't really need to be in position of power to change things to their liking (search the web for something like "manage up" if you're interested in more details).

However that's rather cumbersome and effort consuming and I can perfectly understand if one simply prefers to stay focused on coding, with little involvement in politics - so if you don't want (even though in theory you can), that's understandable. :)


答: If you're processing it with XPath or XSLT it doesn't make much difference. If you're using a programming language less well adapted to XML, the wrapper element probably makes life easier.</p>

Title: Structuring the XML Response

Body:
I'm designing an XML response for a consuming application to take in, and I'm weighing two different designs.  Currently I have a design as follows (where the Product element can repeat):

```<code><Response>
    <AccountType>
    <ProductType>
    <Products>
       <Product>
           <ProductID />
           <ProductStatus />
           <ProductName />
       </Product>
       <Product>
           <ProductID />
           <ProductStatus />
           <ProductName />
       </Product>
    </Products>
</Response>
</code>```

An alternate design is:

```<code><Response>
    <AccountType>
    <ProductType>
    <Product>
        <ProductID />
        <ProductStatus />
        <ProductName />
    </Product>
    <Product>
        <ProductID />
        <ProductStatus />
        <ProductName />
    </Product>
</Response>
</code>```

In the first design I have a master element called Products, under which each Product element exists and can repeat within Products.  The second design is a little flatter - where Product exists under the main Response node.

Which one of the two is more optimal for a consuming application to read from and process?


答:
To start with, this comment:

... having a branch implies an extra complexity and thus extra work ...

is wholly false. I often hear it from people who aren't accustomed to branching, but it's still wrong.

If you have many developers accumulating changes locally, their local changes constitute a de-facto branch of the main repository.

When they finally push, this is a de-facto merge.

The fact that your branches and merges are implicit doesn't remove the extra complexity you're concerned about, it just hides it. The truth is that making this process explicit might help you (plural = the whole team) learn to manage it.

Now, you say

no one is allowed to check-in while to build is red

but in this case the build can never be fixed, so it can't be quite accurate.

In general, if it's reasonable to build locally (ie, the build isn't too big or slow), developers should do that before pushing anyway.

I assume this isn't the case, because then they wouldn't push broken builds in the first place, but it'd be great if you could clarify this point.

In general the answer to

how to stay efficient when a build is almost always broken

is: stop breaking the build.

Body:
I work in a middle sized team which shares the same source code and while have a continues integration in place, but as all of us has to work in the same branch, the build is almost always broken.

As we also have a rule, which has been introduced recently to alleviate the broken builds, which states that no one is allowed to check-in while to build is red.

Having said that, during a day everyone have a handful of 10-15 minutes windows where we allowed to check-in.

And as the team is growing, the windows of check-in opportunities shrinking even more. That forces developers to accumulate their changes locally, which results in a bigger change sets which even more difficult to ensure that the changes are not breaking anything. You can see the vicious cycle.

What can you recommend to allow me to stay effective working in environment like this.
Also, please keep in mind that I am a developer, not a manager, and can't change the process or other people behavior much.


问:
Worst coding standard you've ever had to follow?
Have you ever had to work to coding standards that:

Greatly decreased your productivity?

Were originally included for good reasons but were kept long after the original concern became irrelevant?

Were in a list so long that it was impossible to remember them all?

Made you think the author was just trying to leave their mark rather than encouraging good coding practice?

You had no idea why they were included?

If so, what is your least favorite rule and why?

Some examples here

答:
Writing anything in Fortran (WATFOR, FORTRAN 77) where a non-whitespace character in column 1 was a comment, and the compiler didn't warn you if you went beyond column 72, it would just silently ignore it.

At least I only spent seven years doing this.


问:
How to learn/become capable of thinking out of the box?
In every problem solving there's always people who think differently, who come with a 6th option when only 5 were suggested by others, who think "out of the box". Please tell how one can achieve such ability? And what it takes to achieve it?</p>

答:
Since we are adding varying amounts of cents here, I will add some of mine.

As someone who has consistently been described as an out of the box thinker by many of my clients and peers, here are some tips.

There is no algorithm..but here are helpful some activities..

1. Puzzles

One thing I have always enjoyed is having fun with my brain and doing puzzles. Lots and lots of puzzles, specifically the MENSA variety. Buy yourself a book or two of those MENSA puzzles that require lateral thinking. Don't get frustrated, if you get stuck, read the answer and learn how to solve it. Similar puzzles will have similar solutions, and once you learn how to solve it, you will learn the pattern.

2. Pet Programming Projects

Learn as much as you can about the language that you work in. Make pet projects for yourself and work on them in your spare time. The more you know what's available in your particular language, the more avenues for solution you will have. Take other peoples' code and make it do different things.

3. Question Everything, Don't be Shy

If asking questions makes you feel like you are stupid, then be stupid, no shame in that. Learning comes from admitting you know nothing and wanting to grow. Make sure you know the basics, because the advanced stuff always grows off of that, and if your foundation is not solid, the knowledge you build on top of that will always be flawed in some way.

4. Unexpected

Don't dismiss any fleeting idea you come up with until you know exactly what is wrong with it. The best solutions often come from the most unexpected ideas.

Good luck.


问:
HTTP Session or Database approach
I am confused a little as what should be my approach, Working on a design of shopping cart and i need to store shopping cart either in session or in database but not sure which approach would be best.here are the use case

User is not logged in and adding product to cart (Anonymous user)

User is logged in and adding product to cart.

First case is more confusing to me, since there can be many cases where user just visiting web-shop and adding product without logging in and can be quite possible that he might not going for a checkout process.

But still we need to create a Shopping-Cart for this user, in order to create and save shopping-cart i have two option.

When user adding a product, create a cart in the database and associate this cart with this user, moment he logged in move this cart to logged in user.

Create Cart, add product to it and save it to the Session, when user logged in create Cart in the database and associated logged in user with this cart with User.

I know that both database driven Cart system as well Session based can have there positive as well negative aspects, but not sure which one might be the best approach taking in to account following points

Scalability

Flexibility

Extensibility

Application Should take care of speed

Looking for input on this aspect to decide the path.

答:
Go for session when the user is not logged in. Even when logged in create the cart in the session first, and persist it into the database only when the user logs out or the session times out.

You need to keep a check on number of carts getting created in the session.

OwnerDisplayName: Umesh Awasthi

Title: HTTP Session or Database approach

OwnerDisplayName: Sudhanshu


答:
The question is assuming you need sessions at all which in my market of clients is not needed. I happen to run several hundred eCommerce websites and a handful of them are getting high traffic. We do not use sessions ever as they are not scalable unless farmed out then they are just slower or require more setup. Sessions use up memory and database fetching of session state is very slow and requires more moving parts.

Instead, we use HTML5 sessionStorage to persist any user information we need to pull again and again but without needing a cookie rountrip each time to increase bandwidth. This is IE8+ and all other modern browsers and mobile devices are compatible with this tech. BUT you could just easily store the cart in a cookie as a fallback as this is what we did previously. Here is a good cookie-cart: http://simplecartjs.org/

When users sign in or login we use an encrypted cookie with a time stamp baked in.

We are also moving toward using ApplicationCache where applicable which will further reduce web traffic as a side note since you can prefetch resources and even catalog data so the user perspective will be a super fast loading website and mobile will also work offline (minus transactions). Of course you must be careful to update the manifest when products change etc.

Title: HTTP Session or Database approach

Body:
I am confused a little as what should be my approach, Working on a design of shopping cart and i need to store shopping cart either in session or in database but not sure which approach would be best.here are the use case

User is not logged in and adding product to cart (Anonymous user)

User is logged in and adding product to cart.

First case is more confusing to me, since there can be many cases where user just visiting web-shop and adding product without logging in and can be quite possible that he might not going for a checkout process.

But still we need to create a Shopping-Cart for this user, in order to create and save shopping-cart i have two option.

When user adding a product, create a cart in the database and associate this cart with this user, moment he logged in move this cart to logged in user.

Create Cart, add product to it and save it to the Session, when user logged in create Cart in the database and associated logged in user with this cart with User.

I know that both database driven Cart system as well Session based can have there positive as well negative aspects, but not sure which one might be the best approach taking in to account following points

Scalability

Flexibility

Extensibility

Application Should take care of speed

Looking for input on this aspect to decide the path.


问:
Why it is not possible to Instantiating Types with Wildcards in Java
I am trying to instantiate

```<code>LinkedList<?> op = new LinkedList<?>();
</code>```

But I get error

```<code>Cannot instantiate the type LinkedList<?>
</code>```

Why is it that this cannot be instantiated in Java?

答:
If you don't know what object type will be inside the list, why are you using generics? <?> means I don't know (<? extends Object>).

It's been a long time since I programmed in Java but my understanding is that wildcard generics are made to match something, e.g. when you are declaring a method parameter, you can use a wildcard so that different generics can be passed to it.
Also, a variable can use a wildcard to accept different generic types.

However, when creating an instance, you have to supply a specific type. The wildcard just doesn't have any sense there.

That's why

```<code>List<?> list = new LinkedList();
List<?> list = new LinkedList<Object>();
List<?> list = new LinkedList<MyObject>();
</code>```

Are all possible but

```<code>List<?> list = new LinkedList<?>();
</code>```

isn't.

Body:
If you don't know what object type will be inside the list, why are you using generics? <?> means I don't know (<? extends Object>).

It's been a long time since I programmed in Java but my understanding is that wildcard generics are made to match something, e.g. when you are declaring a method parameter, you can use a wildcard so that different generics can be passed to it.
Also, a variable can use a wildcard to accept different generic types.

However, when creating an instance, you have to supply a specific type. The wildcard just doesn't have any sense there.

That's why

List<?> list = new LinkedList();
List<?> list = new LinkedList<Object>();
List<?> list = new LinkedList<MyObject>();

Are all possible but

List<?> list = new LinkedList<?>();

isn't.


问:
Are there any disadvantages to using the Agile methodology?
It seems most companies are practicing Agile methodologies these days for software development.

I'm curious to know if there are any downsides to using Agile, does it have shortcomings, is it always the right methodology to use?

Do you any of you have experiences of using Agile and it didn't really work, maybe it was due to the type of project, or the team?

答:
Agile is successful if you have an organization that is committed to doing it right.  No methodology will work if you don't have commitment and training in the methodology.

I would also say that agile works best at a certain scale.  You have to be able to divide your project into reasonable size deliverables.  You wouldn't be able to build an office building or a nuclear submarine using agile.

Similarly, in software, some projects are large and complex enough that you really can't start without doing a lot of the up-front design work using a more waterfall-like approach.  Think about something like an operating system, for example.  Another example would be a system that crosses many organizational boundaries, like a national health electronic record system.

Once you've done your overall architecture and design, you can use agile to build-out the features, but if you started with agile you probably wouldn't get off the ground.


问:
What are the advantages of server-side Javascript and when would you use it?
I have been looking at server side Javascript technologies like, Rhino and Node.js. What are the advantages of using server-side Javascript and where in the server-side to they fit in a stack?</p>

答:
I'll be talking exclusively about Node.js as I don't have any experience with Rhino. The main difference would be the environment they run in. Rhino runs on the JVM and V8 (Node.js) is merely a compiler to native code not an interpreter.

The difference between Node.js and Rhino is that Rhino is a JavaScript engine and Node.js is a set of libraries that run on V8 (The JavaScript engine). These libraries are primarily built with an asynchronous approach to provide a fast, scalable system. Async isn't new. Python has many frameworks like Tornado and Ruby has EventMachine. The issue with these is their 3rd party module systems. If you start an using asynchronous you need to only use asynchronous methods. Ruby and Python's 3rd party modules are mostly synchronous. This makes choosing libraries much more difficult and not very appealing.

You could say that Node.js is build around the asynchronous model and it's 3rd party model system are purely asynchronous (albeit some exceptions where they specifically state what's synchronous or when they give both asynchronous and synchronous methods).

There's lot of library fragmentation in other languages. Fragmentation is async vs sync and module systems. Node.js has arguably one module system: NPM. This creates standardization around 3rd party module.

There are many advantages to running Node.js:

You write JavaScript (A well known language)

You can share code between the client and server-side

Running on-top of V8 (which is extremely fast)

Asynchronous model (a ton of compatible modules to help you)

As to the questions in the comments (talking about distributed architecture)....

If you want to write high performance, CPU-bound tasks in C++, why not write native modules?

Most of the time you'd want to write these systems independently from Node.js. The purpose of a distributed architecture is:

Fault Tolerant (If a failure happens in a single system, it's much easier to replace them.)

Modular (You'd write smaller systems with a defined scope. You can also replace the inner workings of each system and everything will still work)

High Performance [1]

[1] When you're building high-performance systems you don't need it to be bound to Node.js or the V8 engine as working under v8 and node.js requires additional knowledge and is much much harder to debug as you complicate the layer even more.

THe last part might be a tad out-of-scope but I'll leave it in for now.


答:
The obvious simple solution is to have both Gizmo and Widget implement ICartItem, which would be an interface containing exactly what it takes for something to be represented in a cart, and nothing more (e.g., unit price, quantity, unit, description). Gizmo and Widget could have radically different ways of coming up with these, as long as they implement the interface correctly.

The obvious downside with the obvious simple solution is that now both Gizmo and Widget have to know a few things about shopping carts, which kind of violates the Single Responsibility principle. If you feel this is happening, consider splitting things up: Gizmo and Widget are completely unrelated, without any shared functionality whatsoever; GizmoCartItem and WidgetCartItem both implement the ICartItem interface and know how handle a Gizmo or a Widget as a cart item; the shopping cart still deals strictly with ICartItems; and you probably want some kind of factory that creates ICartItems for Gizmos and Widgets so that you never have to touch the glue classes directly. With this design, the Gizmo doesn't know anything about shopping carts, nor about Widgets; the shopping cart doesn't know anything about Gizmos; and the cart item glue know just enough about both Gizmos and shopping carts to interface them.


答:
One other thing to think about is the problem most agile methods are targeted to address.  The basic assumption is that "software work" is the bottleneck that needs to be attacked to get value sooner.  If development is a small % of the overall goal then it doesn't really matter how efficient that part is.

Agile methods have been used successfully for very complex problems, but this requires all the interested parties to be dedicated to the development team and eliminating its obstacles.  For some projects that makes sense, but for many, a software project isn't critical to the survival of the business.  In that case it makes more sense to de-prioritize the software team.

This sort of thinking presumes the organization is focused on value over resource utilization which is also pretty rare :)

Title: Are there any disadvantages to using the Agile methodology?

Body:
It seems most companies are practicing Agile methodologies these days for software development.

I'm curious to know if there are any downsides to using Agile, does it have shortcomings, is it always the right methodology to use?

Do you any of you have experiences of using Agile and it didn't really work, maybe it was due to the type of project, or the team?


问:
Choosing between Qt/C++ and .NET/C#
I have a desktop project I've been working on for a couple months that I want to run on Windows and Mac. When I started the project, I started writing it in Qt 4.8 in C++. Development has gone fine and the application runs fairly well on both Windows and Mac like I hoped. I would say it's about 40% complete at this point.

For a little background information, the application is a variation of an email client.

But I am thinking about abandoning what I've done so far in C++/Qt and purchasing a license for Xamarin Studio and writing the application in C#.

There are a few reasons I am strongly considering this:

I want to release mobile versions of this application too, and with C# a lot of the backend code could be reused on all platforms.

I want to publish this app on the Apple and Windows stores. I know that you publish Qt Apps on the Apple Store but I have not read or been able to find anything about anyone publishing Qt Apps to the Windows Store. Not to mention, Qt 4.8 has no built in support for Metro UI (I would have to use Qt 5.0, which would mean rewriting a large part of the code anyway).

Having worked in both C# and C++ for many years, overall I am "happier" developing in C#.

However, I have a few reasons the stay the course:

As I mentioned above, I am about 40% complete in the first incarnation of this project.

A large portion of my program rests upon Lua, for which I'm able to use the native Lua libraries quite easily in C++, and I'm not sure how well the Lua implementations I've seen for Mono/C# work.

Maintaining two separate UI code for the desktop app (hence, in Qt I can #include <QtCore> on Windows and Mac, but in C# I'd have to using System.Windows.Forms on Windows and 'using MonoMac.' on Mac)

Honestly, at this point I'm inclined to start over in C#, using what I have in C++ as a guide and delay my release for about a month (about how long it'll take me to catch up considering other responsibilities in my life).

I was looking for some input from people who have been in a similar situation. And I'm particularly interested in hearing from anyone who has used C# to publish apps on the Windows and Mac stores.

What do you think?

答:
Don't be fooled by the "grass is greener" syndrome. You have something that is getting complete, it works, and will be available on other platforms in the future like you want... so why would you want to change now!?

You know the situation you currently have, if you changed you'd have to discover the problems you'll face all over again - its one reason why you should never rewrite from scratch.

Title: Choosing between Qt/C++ and .NET/C#


答:
I don't think rewriting from scratch is a good idea in general, but to address a couple of the technical points you mentioned:

I want to release mobile versions of this application too, and with C# a lot of the backend code could be reused on all platforms.

There's not really any particular reason why you couldn't reuse your C++ code for mobile platforms. It's definitely not an ideal state of affairs for C++ aficionados, but it is feasible.

A large portion of my program rests upon Lua, for which I'm able to use the native Lua libraries quite easily in C++, and I'm not sure how well the Lua implementations I've seen for Mono/C# work.

Scripting in the .NET Framework in general is a .. little tricky. In order to reload scripts, you'll have to manage a/some AppDomain(s) specifically for scripting. If you intend on modifying scripts frequently as would be implied by some use cases for scripting, this is a significant factor to consider.

Additionally, last time I checked (though this could easily have changed since), the Lua bindings for .NET were really awkward to use because of the C heritage. There are some DLR Lua projects which may or may not be better than the libraries I was attempting to use at time. I can't post more than 2 links otherwise I'd link to a couple, but you can use your preferred search engine.

Title: Choosing between Qt/C++ and .NET/C#

Body:
I have a desktop project I've been working on for a couple months that I want to run on Windows and Mac. When I started the project, I started writing it in Qt 4.8 in C++. Development has gone fine and the application runs fairly well on both Windows and Mac like I hoped. I would say it's about 40% complete at this point.

For a little background information, the application is a variation of an email client.

But I am thinking about abandoning what I've done so far in C++/Qt and purchasing a license for Xamarin Studio and writing the application in C#.

There are a few reasons I am strongly considering this:

I want to release mobile versions of this application too, and with C# a lot of the backend code could be reused on all platforms.

I want to publish this app on the Apple and Windows stores. I know that you publish Qt Apps on the Apple Store but I have not read or been able to find anything about anyone publishing Qt Apps to the Windows Store. Not to mention, Qt 4.8 has no built in support for Metro UI (I would have to use Qt 5.0, which would mean rewriting a large part of the code anyway).

Having worked in both C# and C++ for many years, overall I am "happier" developing in C#.

However, I have a few reasons the stay the course:

As I mentioned above, I am about 40% complete in the first incarnation of this project.

A large portion of my program rests upon Lua, for which I'm able to use the native Lua libraries quite easily in C++, and I'm not sure how well the Lua implementations I've seen for Mono/C# work.

Maintaining two separate UI code for the desktop app (hence, in Qt I can #include <QtCore> on Windows and Mac, but in C# I'd have to using System.Windows.Forms on Windows and 'using MonoMac.' on Mac)

Honestly, at this point I'm inclined to start over in C#, using what I have in C++ as a guide and delay my release for about a month (about how long it'll take me to catch up considering other responsibilities in my life).

I was looking for some input from people who have been in a similar situation. And I'm particularly interested in hearing from anyone who has used C# to publish apps on the Windows and Mac stores.

What do you think?


问:
What does "if w in [1..5, 8, 11]" mean in pseudo code?
In some pseudocode, I saw the following:

```<code>if w in [1..5,8,11]
</code>```

Does it mean that if w is from 1 to 5 or 8 or 11? Or is it something else?

答: Yes, that's how I'd interpret that. That's not just pseudocode; it's actually valid code in Pascal, exactly as written.</p>


问:
In what way is JavaScript (ECMAScript) similar to Self and Scheme
When looking at the ECMAScript 4th Edition specification here it mentions that

ES3 is a simple, highly dynamic, object-based language that takes its major ideas from the languages Self and Scheme.

I'm not familiar with these two languages and cannot seem to find any mention of what exactly is similar to these languages in ECMAScript.

Would someone be able to explain to me the features that ECMAScript has taken from these languages?

答:
I've never used Self myself, but I believe that JavaScript's extensive use of prototypes came from Self.

As for Scheme's influence, you need look no further than JS's first-class functions and lexical scoping (okay, so JS doesn't implement full lexical scoping in the way Scheme does, it implements function-level scoping, but still, it's close).


问:
Distributed Issue Tracking
Distributed issue tracking seems like a belting idea to me, but it has never really taken off in a big way. Is there a good reason for that?

I am aware of:

bugz everywhere

too complex to set up

too many requirements

reasonably successful, used by some large projects

fossil

tries to integrate too many things, and ends up being a slightly worse version of all of them - except maybe for the distributed issue tracking part, which is decent (probably best I have seen)

several other smaller projects

none of which have gained any traction

I am thinking about making my own, but before I begin, I would like to know why none of the others have taken off in a big way.

Anticipated issues: (I think they can all be overcome)

merging distributed issues as they are updated is complex, as is merging any code files

conversation continuity can be destroyed, as comments can come in at any time, perhaps not in the correct flow

expectation of central server with issues up-to-date

答:
Just because source control + distributed was a huge success, issue tracking + distributed isn't necessarily a good idea.

What do we gain from distributed source control and would it apply to issue tracking?

Easy branching and merging: not really. Actually it is crucial that everybody is on the same page. So branching would be highly undesirable.

Performance: the amount of data transmitted by an issue tracker is rather small, and all the heavy lifting is done on the server, so this isn't an issue.

Advanced workflows (push, pull, staging etc.): issue trackers already have good (and often highly configurable) workflows. So we don't need a distributed system for that. Quite the contrary, it would make things much more difficult, as you have to deal with conflicting changes.

Offline capabilities: sure, these would be nice. However, these can also be had without going fully distributed.

Furthermore, (distributed) source control is used almost exclusively by programmers. Issue tracking is also used by testers, designers, technical writers, managers, marketing, and sometimes even end users. These less people without a computer science background might have difficulties to understand the intricacies of a distributed system.

Title: Distributed Issue Tracking


答:
By solving this puzzle. You must connect all the (equidistant) dots in exactly 4 straight lines:

. . .

. . .

. . .

BTW This was the original out of the box question, because...

Title: How to learn/become capable of thinking out of the box?

Body: In every problem solving there's always people who think differently, who come with a 6th option when only 5 were suggested by others, who think "out of the box". Please tell how one can achieve such ability? And what it takes to achieve it?</p>


问:
How can I get my progress reviewed as a solo junior developer
I am currently working for a 2 person company, as the solo primary developer. My boss gets the clients, mocks up some png design templates and hands them over to me.

This system has been working fine and i'm really enjoying it.

The types of projects I work on are for small - medium sized businesses and they usually want a CMS system. Developed from scratch i'll build a customised backend for the client to add/edit/remove categories, tags, products etc and then output them to the front end according to the design template handed to me. As time has gone on, the projects have increased in complexity, with shopping cart / ordering features and other common e-commerce type features.

Again, this system has been working fine and i'm really enjoying it.

My issue is my personal development as a programmer. I spend a lot of my spare time reading programming blogs, checking through stackexchange, reading suggested programming books (currently on 'The Pragmatic Programmer', really good so far), doing brain exercises (lumosity.com and khanacademy math problems), doing lots of physical exercise and other personal development type activities.

I can't help but feel though, that I'm missing out on feedback, critique. My boss is great and never holds back on praise in regards to my work, but he unfortunately is either to busy to check my code, or to be honest, I don't think it's one of his specialties and so can't provide feedback.

I want to know what i'm doing wrong and what i'm doing right. Should I be putting that much logic in the controller, am I modulating my code enough etc.

So what I have done is developed a little 'Family Budgeting' app and tried to do it as cleanly and effectively as I currently know how.

What i'm wanting to know is, is there somewhere I can submit this app, and have some seasoned developers provide feedback. It's not just a subsection of my code like 'codereview.stackexchange' appears to require, it's my entire workflow that I want critiqued.

I know this is a lot to ask, and I expect the main advice given will be to look for a job within a team, which is certainly something I will look into later down the track, but for now I want to persist with my current employment situation, but just don't want to develop too many bad habits.

Let me know if I can provide any further information to help clarify, or if this isn't the right place for this type of question I apologise in advance. Didn't want to use reddit as I felt this community fosters more well thought out responses.

答:
I'm in a similar situation as you, been hired as the sole programmer for a 5 person company, and only one of them is directly involved with the applications I am developing/adding to. Luckily, I did not have to create anything from scratch but up until now only modified applications my predecessor built. In doing so, I believe I have already improved myself by recognizing what parts of his code were good, what parts were bad and how one could improve them.

Reading code is a huge part of improving your own coding, so above all I suggest you search yourself an open-source project, read code, understand it, and try to judge what is good, what is bad and what could be improved. Maybe even write a code-review about it on your blog.

Cheers!


问:
How does API design differ from general web application development design?
If I was working on a web application designing and writing an API how does that differ from a general web application development?

What things would I need to consider and take into account? Are there any standard processes to follow when creating an API that could be used by thousands of clients?

答:
It depends.

In a recent project, I made the web application and the API nearly identical. If you had http://example.com/some/action/here used by the web application as a page or through AJAX, the same request with the same URI would also be used through the API, only served with different MIME types (HTML or JSON type for the web application, JSON or XML for the API).

It works, and has its huge advantage: you write the code once. At least for the most part of the codebase, since there would be discrepancies. For example, it wouldn't make sense to use CAPTCHA in your API; on the other hand, the API would probably have a few additional calls that are not used by the web application.

You may as well designate the API in a very different way, distinct from your web application. This gives you for example the opportunity to have a RESTful API, while the web application would use sessions.