问:
Where has Cloud Computing gone?
I have been hearing about this term for close to 5 years now. I have read about services from Microsoft (Azure), but I have never saw it adopted in the mainstream usage. The thing I am trying to understand is this:

What happened to cloud computing? Is the infrastructure at present insufficient to implement this?

Is it still in its infancy?

Is it being used in other forms, like all the services Google seems to provide (plus Plus Google OS, etc)?

If it has failed, then why?

答:
Think of the  simplest of  programmers dilemmas:- You want to allocate an array ( whose  size is to be decided upfront) to store some program data in working memory.

 Now this is fairly analogous  to the dilemma that a start up faces; its very hard to accurately predict the IT infrastructure/data requirements upfront.  You just don't know the future. So a smaller initial allocation will likely require a costly reallocation and copying of the array's contents at some point in future if the startup picks up growth. On the other hand a larger initial allocation risks being a dangerous waste of meager resources if growth does not happen as expected or very slow to come by.

Large companies providing cloud services is like someone  pre allocating a large array for you upfront, without you having to worry about the future  cost of the entire array. Now this makes perfect economic sense for both the provider (the cloud company ) and the consumer of the array(that is the startup). The consumer uses as much of the array as it needs at a given point in time; no more no less. So it can enjoy a seamless scaling up (pay as you go) experience. For the provider it makes sense as he is not bound to just one app. using the array. He can lease a certain range of array locations to one app. and other ranges to other apps. The cost of maintenance and management per array location decreases as the size of the array grows. Thus the provider accrues the benefits of economies of scale.

So the basic idea behind the cloud hype is economically sound and feasible. Now, how much of an impact it has on the industry in the real world .... too early to say.

Title: Where has Cloud Computing gone?

OwnerDisplayName: mumtaz

LastEditorDisplayName: mumtaz


问:
Class Design -- Multiple Calls from One Method or One Call from Multiple Methods?
I've been working on some code recently that interfaces with a CMS we use and it's presented me with a question on class design that I think is applicable in a number of situations.  Essentially, what I am doing is extracting information from the CMS and transforming this information into objects that I can use programatically for other purposes.  This consists of two steps:

Retrieve the data from the CMS (we have a DAL that I use, so this is essentially just specifying what data from the CMS I want--no connection logic or anything like that)

Map the parsed data to my own [C#] objects

There are basically two ways I can approach this:

One call from multiple methods

```<code>public void MainMethodWhereIDoStuff()
{
    IEnumerable<MyObject> myObjects = GetMyObjects();
    // Do other stuff with myObjects
}

private static IEnumerable<MyObject> GetMyObjects()
{
    IEnumerable<CmsDataItem> cmsDataItems = GetCmsDataItems();
    List<MyObject> mappedObjects = new List<MyObject>();
    // do stuff to map the CmsDataItems to MyObjects
    return mappedObjects;
}

private static IEnumerable<CmsDataItem> GetCmsDataItems()
{
    List<CmsDataItem> cmsDataItems = new List<CmsDataItem>();
    // do stuff to get the CmsDataItems I want
    return cmsDataItems;
}
</code>```

Multiple calls from one method

```<code>public void MainMethodWhereIDoStuff()
{
    IEnumerable<CmsDataItem> cmsDataItems = GetCmsDataItems();
    IEnumerable<MyObject> myObjects = GetMyObjects(cmsDataItems);
    // do stuff with myObjects
}

private static IEnumerable<MyObject> GetMyObjects(IEnumerable<CmsDataItem> itemsToMap)
{
    // ...
}

private static IEnumerable<CmsDataItem> GetCmsDataItems()
{
    // ...
}
</code>```

I am tempted to say that the latter is better than the former, as GetMyObjects does not depend on GetCmsDataItems, and it is explicit in the calling method the steps that are executed to retrieve the objects (I'm concerned that the first approach is kind of an object-oriented version of spaghetti code).

On the other hand, the two helper methods are never going to be used outside of the class, so I'm not sure if it really matters whether one depends on the other.  Furthermore, I like the fact that in the first approach the objects can be retrieved from one line-- most likely anyone working with the main method doesn't care how the objects are retrieved, they just need to retrieve the objects, and the "daisy chained" helper methods hide the exact steps needed to retrieve them (in practice, I actually have a few more methods but am still able to retrieve the object collection I want in one line).

Is one of these methods right and the other wrong? Or is it simply a matter of preference or context dependent?

答:
The key is "are never going to be used outside of the class"

Structure doesn't matter when the implementation remains private. You're free to change/modify it however you want because nobody will depend on the structure.

Public members/interfaces OTOH, do matter. When you expose a member publically/internally, you should have an explicit reason for doing so because somebody may/will depend on it in the future. That's the dividing line between application and API development. In APIs access control becomes very important because any member/interface that people depend on is one that can't be changed/removed without breaking somebody's code.

In essence:

your private parts are nobody's business but your own

ContentLicense: CC BY-SA 3.0


问:
Using Exception Emails as a System Status Indicator
I'm working through our bug list today and I'm trying to clear up/fix issues that we commonly receive exception emails for.  Although all the exceptions (so far) are handled, some don't actually represent an error in the code.  For instance, if a third party service goes down temporarily, our code fails, handles the exception and sends us an email.

This can be especially useful during business hours because it allows us to quickly see if something is down and react to it.  However, there are also scheduled down times and the exception emails can quickly fill an inbox.

My question is, is there a best practice for gaining insight into your system status?  Is an exception email as I've outlined here an acceptable practice or should exception notifications only ever be unexpected?

答:
I don't think emails are the best way to report errors like this.

Email obviously doesn't guarantee fast delivery and you need to have someone on the end of those emails.

If you have too many error reports, then things get missed and you start to ignore them due to the low signal to noise ratio.

Best practise in this area would probably be to use some third party monitoring and alerting software.  There are hundreds of these products on the market which will do a better job than most home grown solutions.  Nagios is a good open source tool in this area.

Re exceptions, sorry for the pithy answer but I think exceptions should only be used for exceptional circumstances.

If you regularly have scheduled downtime on your partner systems, then that should probably be handled cleanly either in the code or via some process rather than allowing your application to start throwing exceptions.


答:
The former example you give more thoroughly insulates the "main" code section (which I assume sees the most developer traffic) from side-concerns, so I believe that is the better approach. However, like you, I don't like having a lot of helper methods clogging up my main classes. To make that a little cleaner, consider separating the helper methods into a helper class. You could do this with a separate internal class or if you want the class private for encapsulation concerns, create a partial class file and make your helper a private nested class. Like so:

```<code>// helper class definition file
public partial class MyClass
{
    // private class modifier only works on nested classes like this one
    // only the parent class MyClass will be able to see this class
    private static class MyHelper
    {
        public static IEnumerable<MyObject> GetMyObjects() { ... }
        private static IEnumerable<CmsDataItem> GetCmsDataItems() { ... }
    }
}

// normal, high traffic file
public partial class MyClass
{
    public void MainMethodWhereIDoStuff()
    {
        IEnumerable<MyObject> myObjects = MyHelper.GetMyObjects();
    }

    // removed side-concerns of getting / transforming data into MyObjects
}
</code>```

Something like this isn't strictly necessary, but may help clarify concerns if that is important to you.

As a side note, for your data transformations (e.g. from CmsDataItem to MyObject), you might consider using a mapping library like AutoMapper (which is available through NuGet in Visual Studio). Although you will still have to maintain mapping transformations, it will make your code semantically more clear that you are just mapping properties from one object to another. Plus AutoMapper will do a lot of simpler mappings automatically.

Title: Class Design -- Multiple Calls from One Method or One Call from Multiple Methods?

Body:
I've been working on some code recently that interfaces with a CMS we use and it's presented me with a question on class design that I think is applicable in a number of situations.  Essentially, what I am doing is extracting information from the CMS and transforming this information into objects that I can use programatically for other purposes.  This consists of two steps:

Retrieve the data from the CMS (we have a DAL that I use, so this is essentially just specifying what data from the CMS I want--no connection logic or anything like that)

Map the parsed data to my own [C#] objects

There are basically two ways I can approach this:

One call from multiple methods

```<code>public void MainMethodWhereIDoStuff()
{
    IEnumerable<MyObject> myObjects = GetMyObjects();
    // Do other stuff with myObjects
}

private static IEnumerable<MyObject> GetMyObjects()
{
    IEnumerable<CmsDataItem> cmsDataItems = GetCmsDataItems();
    List<MyObject> mappedObjects = new List<MyObject>();
    // do stuff to map the CmsDataItems to MyObjects
    return mappedObjects;
}

private static IEnumerable<CmsDataItem> GetCmsDataItems()
{
    List<CmsDataItem> cmsDataItems = new List<CmsDataItem>();
    // do stuff to get the CmsDataItems I want
    return cmsDataItems;
}
</code>```

Multiple calls from one method

```<code>public void MainMethodWhereIDoStuff()
{
    IEnumerable<CmsDataItem> cmsDataItems = GetCmsDataItems();
    IEnumerable<MyObject> myObjects = GetMyObjects(cmsDataItems);
    // do stuff with myObjects
}

private static IEnumerable<MyObject> GetMyObjects(IEnumerable<CmsDataItem> itemsToMap)
{
    // ...
}

private static IEnumerable<CmsDataItem> GetCmsDataItems()
{
    // ...
}
</code>```

I am tempted to say that the latter is better than the former, as GetMyObjects does not depend on GetCmsDataItems, and it is explicit in the calling method the steps that are executed to retrieve the objects (I'm concerned that the first approach is kind of an object-oriented version of spaghetti code).

On the other hand, the two helper methods are never going to be used outside of the class, so I'm not sure if it really matters whether one depends on the other.  Furthermore, I like the fact that in the first approach the objects can be retrieved from one line-- most likely anyone working with the main method doesn't care how the objects are retrieved, they just need to retrieve the objects, and the "daisy chained" helper methods hide the exact steps needed to retrieve them (in practice, I actually have a few more methods but am still able to retrieve the object collection I want in one line).

Is one of these methods right and the other wrong? Or is it simply a matter of preference or context dependent?

Body:
The former example you give more thoroughly insulates the "main" code section (which I assume sees the most developer traffic) from side-concerns, so I believe that is the better approach. However, like you, I don't like having a lot of helper methods clogging up my main classes. To make that a little cleaner, consider separating the helper methods into a helper class. You could do this with a separate internal class or if you want the class private for encapsulation concerns, create a partial class file and make your helper a private nested class. Like so:

// helper class definition file
public partial class MyClass
{
    // private class modifier only works on nested classes like this one
    // only the parent class MyClass will be able to see this class
    private static class MyHelper
    {
        public static IEnumerable<MyObject> GetMyObjects() { ... }
        private static IEnumerable<CmsDataItem> GetCmsDataItems() { ... }
    }
}

// normal, high traffic file
public partial class MyClass
{
    public void MainMethodWhereIDoStuff()
    {
        IEnumerable<MyObject> myObjects = MyHelper.GetMyObjects();
    }

    // removed side-concerns of getting / transforming data into MyObjects
}

Something like this isn't strictly necessary, but may help clarify concerns if that is important to you.

As a side note, for your data transformations (e.g. from CmsDataItem to MyObject), you might consider using a mapping library like AutoMapper (which is available through NuGet in Visual Studio). Although you will still have to maintain mapping transformations, it will make your code semantically more clear that you are just mapping properties from one object to another. Plus AutoMapper will do a lot of simpler mappings automatically.


问:
How can I express recursive composition in UML class diagrams?
I have one class called "Institution" which represents a public institution (with properties like id_inst, name_inst, tel_inst, fax_inst...). The institution can have affiliated institutions, for example a university is composed of different faculties (which are also institutions with the same properties and methods). Theses faculties can also have affiliated institutions : laboratories, annexes, etc.

How can I express this concept in a UML class diagram?

答:
Recursive composition (or aggregation) is simply the composition or aggregation arrow looped back to the individual class. You can use the multiplicity notation to indicate any "can have" or "must have" relationships.

Figure 8 of Scott Ambler's tutorial on class diagrams provides an image of this.


答:
An exception email would be reasonable depending, of course, on the system, the company, the urgency of the error, etc.  I would suggest that the error also get written to some log (I would prefer an error table in a database assuming the database is available but a log file would be perfectly acceptable) and that the decision about whether to send the email involve looking at that log file.  If you encountered a particular error and sent an email 5 seconds ago, it's unlikely that sending another one is going to be helpful-- you probably don't want to send emails more than every few minutes for any particular error (possibly adding a counter to the emails to tell you how many times it happened since the last email).  That prevents you from flooding an inbox with thousands of duplicate messages.

The larger the organization and the more critical the application, the more likely that you'd want to build some sort of status dashboard that someone could monitor and the more likely that you'd want to expose monitoring information in a way that a centralized piece of enterprise monitoring software can handle.  If you've got a team of folks wearing pagers and watching dozens or hundreds of enterprise applications, getting thousands of emails from hundreds of sources is going to be slow, inefficient, and error prone.  If you've got a small team of developers that also happen to be responsible for troubleshooting something if it happens to go wrong, email alerts may be an appropriate trade-off.

Title: Using Exception Emails as a System Status Indicator

Body:
I'm working through our bug list today and I'm trying to clear up/fix issues that we commonly receive exception emails for.  Although all the exceptions (so far) are handled, some don't actually represent an error in the code.  For instance, if a third party service goes down temporarily, our code fails, handles the exception and sends us an email.

This can be especially useful during business hours because it allows us to quickly see if something is down and react to it.  However, there are also scheduled down times and the exception emails can quickly fill an inbox.

My question is, is there a best practice for gaining insight into your system status?  Is an exception email as I've outlined here an acceptable practice or should exception notifications only ever be unexpected?


答:
Hopefully you have a few customers that are paying a lot for this service. I'm working with an app that determines how to handle error notifications in a config file. Each error type is flagged to email or not and to what address(s). Some even email on success. Everything is logged in a file for each client app (errors could occur here and never make it to the server) and the app server.

For a service that is out of order, the client should know about it or at least on of their admins (email?), but I don't know if the developers/support staff need to.

As different companies mature with the system, many of these notifications are turned off or limited to a customers's own support email address.


问:
How does agile work when replacing a working system?
In an ideal Agile world, you quickly build a small, but useful subset of the desired end system, and give it to users. They're excited, because it's useful, they start using it and give feedback. You then work out what to add on to it, build that, and repeat until you run out of time.

I've had a couple of projects recently that involved replacing some kind of working system. The above model just didn't work at all: until you'd built a system that included virtually all the functionality of the existing system, users had no interest at all. They wouldn't use it.

How do you apply Agile when "the smallest useful subset" is "all of it"?

答:
I worked on a massive line of business application replacement for a major national cable tv network. The new system development was done with SCRUM, it was about a 18-24 month development project to re-implement almost all the major sub-systems; which were approaching 10 years old.

There was a planning phase of like 6 months before the development started, but it was approached as SCRUM as well. This is where the product owner wrote high level stores and epics after existing system analysis and interviewing the customers.

The existing system was extremely stable as went into critical maintenance mode; only show stopper issues were fixed, everything just logged for historical purposes and to make sure the same issues didn't appear in the new system.

The new system evolved as described in an Agile process, it was extremely smooth for the most part. When the replacement system reached feature partity, it didn't go into production, but into parallel production trials. A sub-set of non-critical workers started using both systems, to validate that the new system behaved like the old one; with the old bugs fixed of course.

When the new system achieved almost 100% new features complete it was rolled out for general parallel production runs, which lasted a couple of months.

Once it was deemed by the customer to meet their needs, the old system was backed up, switched off and sat. I assume they have re-purposed the old system hardware because they never needed to revert to the old system after cut over.


答:
It works the same, but this approach will be harder to sell to existing users. They may not want the new system and they don't want to be interupted with periodic testing. They want to wait as long as possible and then just test it in the end. Most users feel this way to a certain extent, but it's up to those in charge to educate them. In their mind, you're working with an existing application, so you should know what it's suppose to do, why bother them?

Make them understand that you don't want to do it this way because you think it will be fun and you get lonely using a waterfall process. It will make a better app in the long run.

A key selling point may be to implement that one change during the building of the new app they've always wanted, but could never get in the old system.

Title: How does agile work when replacing a working system?

Body:
In an ideal Agile world, you quickly build a small, but useful subset of the desired end system, and give it to users. They're excited, because it's useful, they start using it and give feedback. You then work out what to add on to it, build that, and repeat until you run out of time.

I've had a couple of projects recently that involved replacing some kind of working system. The above model just didn't work at all: until you'd built a system that included virtually all the functionality of the existing system, users had no interest at all. They wouldn't use it.

How do you apply Agile when "the smallest useful subset" is "all of it"?


问:
why are both index[array] and array[index] valid in C?
For example consider:

```<code>int index = 3;
int array[4] = {0, 1, 2, 3};
</code>```

then both index[array] and array[index] are valid expressions, much like *(index + array) and *(array + index).

In C arrays why is this true? array[5] == 5[array] explains how it works. My question is: Why did the language designers choose to allow this? Why not just enforce that index[array] is invalid, for clarity's sake?

答:
According to James Curran the reason for this was that when C was developed, computers were slower + had less memory, so such checks and optimizations were not worth the cost.

https://stackoverflow.com/a/381554/277800


答:
Because, like several other features of C, it just wasn't thought through. I doubt anyone was really thinking about the mathematical logic behind array fetching in memory. As it turns out, though, both operations result in the same math (basically).

And Mr. Curran might say that, but I'd guess it didn't have a lot to do with computation cost. I could be wrong though.

Title: why are both index[array] and array[index] valid in C?

Body:
For example consider:

```<code>int index = 3;
int array[4] = {0, 1, 2, 3};
</code>```

then both index[array] and array[index] are valid expressions, much like *(index + array) and *(array + index).

In C arrays why is this true? array[5] == 5[array] explains how it works. My question is: Why did the language designers choose to allow this? Why not just enforce that index[array] is invalid, for clarity's sake?


答: We may never know for certain why the feature was allowed in the first place, but it stands to reason that it remains in the language today for backward compatibility with older versions of the language. There's no obvious and compelling reason to remove it, so it doesn't make sense to gratuitously break existing code.</p>


答:
The choice to use array[index] was probably made to follow mathematical convention and the precedent set for arrays by other languages like ALGOL, FORTRAN, and BASIC (the latter two use parentheses instead of brackets).  That decision does make the operator an odd duck because it's binary operator but requires that you throw in an additional token after the right-hand expression.

The operator could just as easily have been a single character (@ isn't spoken for in C, so let's call that the "pointer addition operator").  Because, as David Thornley's answer in the aforementioned SO question points out, pointer addition is commutative, a @ 5 and 5 @ a make equal sense.  (C forerunner BCPL used ! for this.)

In some ways it's natural to look at the array operator as behaving like a function, which makes sense in the context of languages that do f(x) to call a function and a(i) to access an array.  Since operators in C don't work that way, you have to think of it as a commutative, binary operator with baggage.


问:
How can I apply Six Sigma in a software development environment?
I am a Java developer, but I was asked to learn about applying Six Sigma with the goal of increasing our organization's profits. I have read that Six Sigma can be applied in all environments, but I'm interested in the nuances of applying it to software development.

Which concepts of Six Sigma can be applied to a software development environment and how can I effectively apply them?

My understanding is that Six Sigma focuses on:

identifying and removing root causes of defects

minimizing variability in applying manufacturing or business processes

It appears to me that these concepts could be applied to software development, but can that be applied effectively to an Software Development Lifecycle (SDLC)?

答:
The basic Six Sigma activities are captured by the acronym DMAIC, which stands for: Define, Measure, Analyze, Improve, Control. You apply these to the process that you want to improve: define the process, measure it, use the measurements to form hypotheses about the causes of any problems, implement improvements, and ensure that the process remains statistically "in control".

As it relates to software, the process is your software development lifecycle (SDLC) or some part of it. You probably wouldn't try to apply Six Sigma principles to the whole SDLC (or at least, not initially). Instead, you'd look for areas where you think you've got a problem (e.g. our defect rate is too high; too many regressions; our schedule slips too often; too many misunderstandings between developers and customer; etc.). Let's say for now that the problem is that too many bugs are being produced (or at least reported) each week. So you'd define the software development/bug creation process. Then you'd start collecting metrics such as the number of lines of code written each day, frequency of requirements changes, number of hours each engineer spends in meetings, and other possibly-relevant facts.

Next, you look at the data and try to discern patterns. Maybe you notice that engineering team A hits every deadline that they're given, and often even finishes tasks early! Initially, team B doesn't seem quite so on the ball -- they miss their deadlines by a day or two at least half the time, and are occasionally late by a week or more. Management sees team B as something of a problem and is looking to shake things up. However, a closer look at the data shows that team B's bug rate is much lower than team A's, and what's more, team B is often asked to fix bugs attributable to team A because management feels that team A is to valuable to spend a lot of time on maintenance.

So, what do you do? Using the data you've collected and the analysis you've performed, you suggest a change: team A and team B will each fix their own bugs. With management's blessing (and against team A's vehement opposition) you implement that change. Then you continue collecting metrics, and you continue to analyze the data to see if your change made a difference. Repeat this measure/analyze/implement cycle until the bug rate is deemed acceptable. But you're not done yet. In fact, you're never done... you need to keep measuring the bug rate and checking that the bug rate remains within the acceptable range, i.e. it's statistically "in control".

Notice that there's nothing here that's specific to software development other than the specifics of the process you're improving, the kinds of metrics that you collect, etc. The activities that you use to improve a software development process are the same as those you'd use for a widget manufacturing process, even though software development is quite different from widget manufacturing. All that means is that you need to apply some common sense in the kinds of goals that you set for your process.


问:
Prolog parallelism
Are there any prolog interpreters that can functionally decompose your 'programs' in order to improve efficiency?

I know there's been research on prolog interpreters that reach near-C speeds through parallelism (the kind that a typical C programmer can't "see").  Does anyone know more about this topic?

答:
Some starting points

You might want to look into this research paper: http://www.mendeley.com/research/implementation-parallel-prolog-interpreter-multiprocessors/

Also, this Prolog on Python proof of concept paper has some interesting leads: http://www.mendeley.com/research/a-prolog-interpreter-in-python/

Title: Prolog parallelism


问:
Is it fair to reduce OOP to mere hierarchical composition of data structures?
Meaning that OOP allows me to have data-trees, of arbitrary depth and breadth, with some leafs being functions (and those leafs would be called methods) ?

Because everything else that people often put near "OOP" mark, just don't seem to have anything to do with it. (Inheritance, subtype polymorphism and encapsulation seem to be orthogonal to OOP).

Am I right? Or I'm missing something ?

答: I'd say that you are missing that OOP is tighly linked to OOA/D which is about modelling the problem domain in a meaningfull and sustainable way. This leads to considerations of coupling, cohesion, responsibilities, separation of concerns, and in turn considerations of encapsulation, composition, inheritance etc. </p>


答:
You're missing something. Probably several somethings, in fact.

Objects are a powerful means of abstraction. They don't just organize data, they organize code. You could argue that that abstraction isn't necessary, that you could produce equivalent code using purely procedural techniques, but that'd be like arguing that high level languages aren't necessary -- it's perfectly possible to write equivalent code in assembly language. Such arguments may be technically true, but they're completely false from a practical standpoint.

Title: Is it fair to reduce OOP to mere hierarchical composition of data structures?

Body:
Meaning that OOP allows me to have data-trees, of arbitrary depth and breadth, with some leafs being functions (and those leafs would be called methods) ?

Because everything else that people often put near "OOP" mark, just don't seem to have anything to do with it. (Inheritance, subtype polymorphism and encapsulation seem to be orthogonal to OOP).

Am I right? Or I'm missing something ?


答: It's sort of like asking why people would design cars that can hit pedestrians.  They don't.  They design cars to do what their drivers tell them to do.  C was designed with the crazy, arcane notion that programmers are in charge of their own programs, and if they write something stupid in a programming language, it's their own responsibility.  Design decisions erred on the side of removing programmer restrictions.


问:
Resource/Thread Allocation and Deadlock
Here is the question I'm having trouble with:

Give the resource graph and determine whether a deadlock state results.  Assume that when a thread requests an available or unallocated resource, the OS immediately allocates that resource to the thread.

There are three threads: T1, T2, T3

There are three resources:  R1, R2, R3

Here is the sequence of events:

T1 requests R1

T1 requests R3

T2 requests R2

T2 requests R3

T3 requests R1"

Now, I have written out the graph for the problem.

Have I drawn the graph appropriately?  Based off of this graph, I assume there is no deadlock because there are no cycles.  I am unsure if my solution is correct.  Can anyone help clarify this?  Thank you!

答:
You have two processes accessing the same resource but a deadlock will not occur.

T2 is requesting R3. Since T1 is already
using R3 T2 can wait or try again at a later time.

T3 requests R1 but can wait or try again later once T1 has finished. A deadlock would ONLY take place when t3 requests R1 and T1 has not released the lock because it is waiting for a process from T3 (which it wouldnt because it wants access to R1 first)

Title: Resource/Thread Allocation and Deadlock

OwnerDisplayName: Darren Davies


答:
the problem reside in the allocations 4 and 5

```<code>4. T2 requests R3
5. T3 requests R1
</code>```

you have to use a timelined graph (axis1 threads, axis2 cycles) and follow the evolution of the allocations in every cpu cycle.

Title: Resource/Thread Allocation and Deadlock

Body:
Here is the question I'm having trouble with:

Give the resource graph and determine whether a deadlock state results.  Assume that when a thread requests an available or unallocated resource, the OS immediately allocates that resource to the thread.

There are three threads: T1, T2, T3

There are three resources:  R1, R2, R3

Here is the sequence of events:

T1 requests R1

T1 requests R3

T2 requests R2

T2 requests R3

T3 requests R1"

Now, I have written out the graph for the problem.

Have I drawn the graph appropriately?  Based off of this graph, I assume there is no deadlock because there are no cycles.  I am unsure if my solution is correct.  Can anyone help clarify this?  Thank you!

Body:
the problem reside in the allocations 4 and 5

4. T2 requests R3
5. T3 requests R1

you have to use a timelined graph (axis1 threads, axis2 cycles) and follow the evolution of the allocations in every cpu cycle.

OwnerDisplayName: Karim Garram


答:
I'll summarize our conversation in the comments.

Have I drawn the graph appropriately? Based off of this graph, I assume there is no deadlock because there are no cycles.

You are correct, your question does not show any deadlock conditions.

For me deadlock is not about "cycles" but about multiple locks and different lock order.  As you mention in your comments the following is deadlock because they each lock 2 locks in a different order.

T1 requests R1. T2 requests R2. T1 requests R2. T2 requests R1.

Both T1 and T2 are blocking each other forever.  That is deadlock.

But in your OP, there is nothing stopping T1 from finishing with the resources and unlocking them.  Then T2 and T3 will get their locks and everything will continue.  That is just lock contention.

Title: Resource/Thread Allocation and Deadlock

OwnerDisplayName: Gray


答:
http://imageshack.us/photo/my-images/684/ploti.png/

here is how to make the graph, but you have to fix how many cycles the resources will be allocated and could they be allocated for two different threads.

deadlock happens when two threads request same resources and get mutually blocked.

Title: Resource/Thread Allocation and Deadlock


问:
Company wants us to use escrow or provide SLA
We have a SaaS business (we host everything) where people, using our software, pay for various services offered by a few "vendors." We collect this money and every week we deposit the balance into the vendor's account. Our cut is a small piece from each of these service payments; so if nobody buys anything the vendor doesn't pay anything.

This model has worked fine, but we're now in talks with a larger vendor (government) that was asking for escrow for our service. They asked the trigger (for the release of the code) to be bankruptcy, not providing the service at a reasonable level (can't remember the actual term used), or acquisition by a third party.

We told them that we don't have a problem with the bankruptcy trigger, but the acquisition part we can not agree with because who would want to buy us if our customers have the option of just running our software for free. Are we rightfully concerned about this scenario?

After we mentioned that a trigger cannot be acquisition by a separate company or if they think our software doesn't live up to some standard, they countered that in this case they would want some kind of SLA with "really high requirements" instead of the acquisition or service trigger -- but still have the escrow for bankruptcy.

Doesn't SLA imply some kind of monthly or yearly service fee? We structured our model so that if a company does use our software they don't pay anything. We thought this would be preferred over a monthly/yearly fixed cost.

Are we being unreasonable? Thoughts?

答:
A Service Level Agreement (SLA) doesn't imply a monthly or yearly service fee.  A SLA lays out an agreement about things like uptime, performance, data availability, downtime notifications, support response times, and other things of that nature.  A SLA with "really high requirements" might specify that the service is to be available 99.999% of the time and specify response times for various operations.  If the vendor has to make a bunch of web service calls, for example, they may want to ensure that, say, 99% of the calls return in < 0.5 seconds.  And the SLA generally specifies penalties for the service provider if these targets are not met-- generally, that would involve reducing or eliminating the fees the service consumer pays to the service provider but you could structure the SLA to involve the release of the escrowed code if the provider is consistently unable to meet the targets.

Of course, you'd want to make sure that the targets were sufficiently conservative that there would be no real risk that you'd violate them so long as the service was being actively looked after (either by you or by whoever bought the company).  But it would allow the escrowed code to be released if your company didn't go bankrupt but simply stopped providing active support and monitoring and let the service go down on a regular basis.


问:
How can I make my PHP development environment more efficient?
I want to start a home-brew pet project in PHP.

I've spent some time in my life developing in PHP and I've always felt it was hard to organize the development environment efficiently.

In my previous PHP work, I've used a windows desktop machine and a linux server for development.

This configuration had it's advantages: it's easy to configure Apache (and it's modules)/PHP/MySql on a linux box, and, at the time, this configuration was the same like on production server.

However, I never successfully set up a debug connection between my Eclipse install and X-debug on server. Transferring files from my local workspace to the server was also very annoying (either ftp or Bazaar script moving files from repository to web root).

For my new setup, I'm considering installing everything on my local machine. I'm afraid that it will slow down workstation performance (LAMP + Eclipse), and that compatibility problems will kick-in.

What would you recommend? Should I develop using two separate machines? On one? Do you have experience using one of above configurations in your work?

答:
As far as the debugging issue goes, I prefer PhpStorm as my IDE of choice because of the ease in which you can integrate it with Xdebug.  It costs a little bit (usually they run specials for 25%+ off) but it's well worth it. They even have a 30 day trial so you can test it out.

I used to use Eclipse and it's hard to go back now.  Like I mentioned before, you can integrate xdebug really easily and it comes with a Chrome plugin so you can turn debug listening off and on.  Here is the best tutorial I found on how to do it.

PhpStorm also works with SVN right out of the box.  Which brings me to my next point, use SVN (or Git if you prefer, just some sort of versioning).  That will make uploading changes to your server much easier. You'll also have backups and commit logs which will definitely help you in the future.

ContentLicense: CC BY-SA 2.5


答:
Full disclosure - I've been on the demanding side of an escrow request, so please pardon me for any overt bias.

Large organizations such as gov't and utilities generally don't change software applications frequently.  It's not unheard of for an application to live 10 - 15 years, with only a few version upgrades in there.  They can take "sweating the assets" to an art form...  New applications represent a large investment of resource in order to bring in and put to use.  Switching applications means throwing away that previous investment.

One of the big risks involved for them when evaluating new software is estimating the likelihood the vendor will be in business next, three, five, ten, and so on years from now.  The escrow requirement allows them a fallback option should their beloved application no longer be available in its preferred form.

Acquisitions can mean the death of a product as they bought it.  Your future client's perspective may be that they equate acquisition with death.  If they've been burned once before, then that's likely how they see it.  OTOH, I honestly don't see this as a big poison pill for an acquiring company.  Their rights to the software will be limited to just that client.  They can't turn around and provide the same service to others with the code they received via escrow.

The SLA clause is a little new from my point of view, but I think that's due to the SaaS model you're offering.

Once you apply a "fear-of-loss" viewpoint, you can see why they asked for the escrow.  And it also gives you the key to finding an agreeable solution.  On the flipside, it means they  want to use your software and will likely be customers for a long time.  Big orgs don't buy software just for giggles.

Having a steady stream of low-escape-risk clients can be very attractive to an acquiring firm, especially if they intend to continue or improve the service.  Even if the client has a copy of the old code, they'll continue with the new version if it meets their needs.

Initial demands and reactions are always unreasonable.  :-)  I think you can find a healthy solution.

Title: Company wants us to use escrow or provide SLA

Body:
We have a SaaS business (we host everything) where people, using our software, pay for various services offered by a few "vendors." We collect this money and every week we deposit the balance into the vendor's account. Our cut is a small piece from each of these service payments; so if nobody buys anything the vendor doesn't pay anything.

This model has worked fine, but we're now in talks with a larger vendor (government) that was asking for escrow for our service. They asked the trigger (for the release of the code) to be bankruptcy, not providing the service at a reasonable level (can't remember the actual term used), or acquisition by a third party.

We told them that we don't have a problem with the bankruptcy trigger, but the acquisition part we can not agree with because who would want to buy us if our customers have the option of just running our software for free. Are we rightfully concerned about this scenario?

After we mentioned that a trigger cannot be acquisition by a separate company or if they think our software doesn't live up to some standard, they countered that in this case they would want some kind of SLA with "really high requirements" instead of the acquisition or service trigger -- but still have the escrow for bankruptcy.

Doesn't SLA imply some kind of monthly or yearly service fee? We structured our model so that if a company does use our software they don't pay anything. We thought this would be preferred over a monthly/yearly fixed cost.

Are we being unreasonable? Thoughts?


问:
Completion time on a company where the supervisors don't know programming
We are in a small company with around 10 developers. I am the team leader and responsible for the development process.

Supervisors and salesmen are close to us since we are a small team, but have no clue on how software is developed.

When they ask me how much time I want for a change (bugfixes/features) in a product, my response is 'let me calculate it'. After giving them the schedule, they start by saying OK you can do it in XX time which differs a lot from my plan. We are using a model close to Agile basic principles and have circles per week or per three days.

Of course I argue and say that this cannot be done. They seem to have no idea on the effort we are doing. They do not want to see WHY my schedule is for that amount of time.

I know this behavior is stupid, but how can I make them see the problem?

答:
I've seen a lot of this negative, positional division in my career and I think the best way work with it is be as honest and transparent as possible. (Negative phrases like "behaviour is stupid", "have no clue", "cannot be done" should be avoided. Look for solutions/root causes.)

First, it looks like everyone is employing positional bargaining (book). They want what they want and you want what you want.But what is really driving that? Look at what drives their position and target that. E.g. sales just wants to get the product out as quickly as possible to make more sales and help the company's profits. What's wrong with that? And from your side you simply want to make the best quality software you can. So you just need to find a middle ground. I think the best way to do this is education, honesty and transparency. Treat them as part of your team and not "us vs. them".

Agile and Scrum methods try to incorporate this into the entire process.
Certain aspects of Scrum take care of this nicely:

A product owner that prioritizes features and chooses what goes in each sprint. This person is part of the team. This should be a person that has the clients' best intentions in mind. e.g. this could be a sales person or supervisor. They are involved on a regular basis in deciding what goes into the product so there's great motivation and responsibility (they'll learn to NOT push for time vs quality/features)

Any stakeholders are team members as well, they just don't get control in the the backlog/sprints/timeline. Treat them as such and they can learn how estimates are calculated and the inherit complexity behind software development.

A scrum master works at improving the process over time. It's not expected to be instantly scrum as that is unreasonable in any situation. They work at removing roadblocks for all team members (and the company).

In summary, just be honest, positive and try to educate - it will eventually improve. Even if you don't officially follow agile/scrum, read some literature to get a better understanding of these concepts and motivations.


答:
Any formal language is reducible to graphs, but the fact that a language is a graph or tree is insufficient to define what sort of language you have.

If you are trying to establish that a language as OO, then yes, it is a graph (possibly a tree if there is truly no multiple inheritance) where some nodes are functions, some are data types, etc., but the tree will also adhere to certain rules, such as encapsulated state, polymorphism, and inheritance.  If it does not, it's not OOP.


问:
Which style is better to check and log the error?
I have read some code and here are two ways to check and log the error in cpp code that repeats in my project many times. Which way is better?

1.

```<code>bool AClass::myMethod()
{
     if (!SomeCondition())
     {
         Warning("AClass::myMethod: your description");
         return false;
     }
    doSomthing();
    return true;
}
</code>```

2.

```<code>bool AClass::myMethod()
{
    if (SomeCondition())
    {
        doSomething();
    }
    else
    {
        Warning("AClass::myMethod： your description");
        return false;
    }
    return true;
}
</code>```

答:
I would go a step back and say why to limit yourself in those two cases? A cleaner and more defensive technique is suggested in the pragmatic defense. By following the article's suggestions you end up in a structure like that:</p>

```<code>bool AClass::myMethod() throw()
{
    bool myMethodReturn = false;

    try
    {
       // your preconditions here
       // on failure throw an exception

       // main code...

       // your postconditions here
       // on failure throw an exception

       // everything went fine
       myMethodReturn = true;
    }
    // catch all the possible exceptions
    catch (const std::domain_error& err)
    {
        // log the error
    }
    catch (...)
    {
        // log the critical error
    }

    return myMethodReturn;
}
</code>```

Body:
I would go a step back and say why to limit yourself in those two cases? A cleaner and more defensive technique is suggested in the pragmatic defense. By following the article's suggestions you end up in a structure like that:

bool AClass::myMethod() throw()
{
    bool myMethodReturn = false;

    try
    {
       // your preconditions here
       // on failure throw an exception

       // main code...

       // your postconditions here
       // on failure throw an exception

       // everything went fine
       myMethodReturn = true;
    }
    // catch all the possible exceptions
    catch (const std::domain_error& err)
    {
        // log the error
    }
    catch (...)
    {
        // log the critical error
    }

    return myMethodReturn;
}


答: My advice to you...get a lawyer. You're playing with the big boys now, asking a group of strangers on a Q&A site something this important to your company is not the right way to do it.</p>


问:
Any Course/Lecture videos on Design Patterns
I am planning to read some design patterns and I took the book on "design patterns in C++' by gang of four. However, I am not really some one who reads book and prefers reading slides/watching course lectures and then apply and read the book. I cannot find any course lecture videos on net(yeah, its not that important a course as algo/OS). Any one know any course website, preferably on C++ </p>

答:
Well, it's not a course, but...

C++ Programming/Code/Design Patterns looks like a good book to look at. It is a book from Wikibooks (by Wikimedia).

If you want a course...

Another thing to look at might be Design Patterns Course by Sourcemaking. It has 97 lessons (7 hours) and includes 2 great books in the price. The only major con is that it is currently $49.95. But if you ask me, that's a good price for two books and 7 hours worth of video.

Finally...

Take a look at the Design Patterns tag on Dimecasts. You might be able to find something there.

Finally...Finally...

This question has been asked on Stack Overflow. There are some great answers there, so take a look at that too.

Hope this helps!


问:
If I drop cookies with JavaScript will it still be compliant with the EU ICO Cookie Law?
The challenge proposed to me as to create a widget to apply in other sites that makes a website compliant with the cookie law[1].

Can I do this without changing server code?

I mean, if there's code on server-side that writes an affiliate cookie to the response and my JavaScript widget deletes it after on window.load event: will the site still be cookie law compliant?

Then comes the Google Analytics and share buttons cookies. How would I stop those scripts and iframes from being executed in JavaScript?

[1] The Information Commissioner's Office (ICO) : New ICO Cookie Law

答:
Your solution would probably end up being treated as malware

From your description, it appears that you want to create a JavaScript library that a website can include on their pages that will guarantee their compliance with the "cookie law".

Let's side-step the technical issues surrounding the actual implementation of this law when it comes to the location of the user, the client (remote session anyone?), the server and the owner of the web application running on the server. And, let's constrain further and only consider the UK guidance offered around the EU directive.

From the Information Commissioner's Office:

Cookies or similar devices must not be used unless the subscriber or
  user of the relevant terminal equipment:

(a) is provided with clear and comprehensive information about the
  purposes of the storage of, or access to, that information; and

(b) has given his or her consent.

This implies that your widget will have to act as the clearing house for this user consent. If you do not have control over the server code then your software will have to block the cookies emanating from the server until such consent is obtained. This means that your software will be interfering with third-party libraries (your Google Analytics and Facebook Likes etc).

Such interference, no matter how well-meant, is very likely to degrade the user experience and be looked upon extremely unfavourably by the owners of the third-party libraries. Thus it will be treated as malware.

I would think again before going down this road.


问:
Parallel Testing options in Agile Development?
I've read through some very good resources on the internet trying to find out if my initial proposed testing process is a valid option. So please any advice or recommendations are appreciated.

Currently we have a Dev and Test environment which has served our needs fairly well so far. We are having QA and UAT test off the same Test environment, however our QA testers are complaining that having both teams test in the same environment is causing problems with verifying test scripts and I can see how this could be a problem. However, I don't want to have to wait for QA to be done testing before UAT even takes a look at it, this seems to be against the ideal's in agile development.

I suggested the following new process/architecture to allow parallel QA and UAT testing:

Have separate QA and UAT environments that allow different modules/versions to be tested in parallel. So we can have QA testing ModuleA while UAT is testing ModuleB.

We basically need/want them to test different modules (or the same) in parallel without interfering with each other.

I presented this to our Systems Engineers (so they can build the environment) and they said that UAT should never happen until QA is done. From my understanding of the agile process at this time, I would like to push my proposed process further, but maybe I'm overlooking something?

Thanks!

答:
Your system engineers are right; in practically any SLDC including Agile, your users should not be given a version of the software for their testing until QA green-lights it.

However, Agile allows for the development of software in sprints, and when each sprint is complete and green-lit by QA, it should be pushed to UAT for the users to bang on and give feedback. This is as compared to Waterfall or similar SLDCs where the deliverables are spread further apart and the user doesn't get software to test until initial development is very near complete.

So, I say in this situation both parties are right, but you're more right. You need separate UAT and QA environments so that QA can test what they're testing and UAT can test what QA has green-lighted for UAT release. These will almost certainly be different release versions of the software; QA should be one or two iterations ahead of UAT, and Dev should probably stay at least one sprint ahead of QA.


答:
The continuous delivery book makes the point here that it makes sense to 'fan out' software into parallel environments as it gives you more throughput and flexibility in your testing.

http://continuousdelivery.com/wp-content/uploads/2010/09/optimized_pipeline.png

This sounds nice on paper, but the obvious downside of doing this is that you might UAT test a build that will be rejected by QA.

For this reason, I would probably stick with the serial pipeline and add a new UAT environment, but place builds in there AFTER the QA testing.

I say this because the last thing you want get into a situation where you UAT and sign off build X, and then have to go live with build X + 1 which includes just a small fix to satisfy the QA team.

Title: Parallel Testing options in Agile Development?

Body:
I've read through some very good resources on the internet trying to find out if my initial proposed testing process is a valid option. So please any advice or recommendations are appreciated.

Currently we have a Dev and Test environment which has served our needs fairly well so far. We are having QA and UAT test off the same Test environment, however our QA testers are complaining that having both teams test in the same environment is causing problems with verifying test scripts and I can see how this could be a problem. However, I don't want to have to wait for QA to be done testing before UAT even takes a look at it, this seems to be against the ideal's in agile development.

I suggested the following new process/architecture to allow parallel QA and UAT testing:

Have separate QA and UAT environments that allow different modules/versions to be tested in parallel. So we can have QA testing ModuleA while UAT is testing ModuleB.

We basically need/want them to test different modules (or the same) in parallel without interfering with each other.

I presented this to our Systems Engineers (so they can build the environment) and they said that UAT should never happen until QA is done. From my understanding of the agile process at this time, I would like to push my proposed process further, but maybe I'm overlooking something?

Thanks!


答: It's mostly Microsoft stuff but I like the video training at http://www.pluralsight-training.net/microsoft/Courses/TableOfContents?courseName=patterns-library.  They have a free trial.</p>

Title: Any Course/Lecture videos on Design Patterns

Body: I am planning to read some design patterns and I took the book on "design patterns in C++' by gang of four. However, I am not really some one who reads book and prefers reading slides/watching course lectures and then apply and read the book. I cannot find any course lecture videos on net(yeah, its not that important a course as algo/OS). Any one know any course website, preferably on C++ </p>


答:
First of all, it would help to read dmr's Development of the C Language to get some insights into some of C's quirks, particularly when it comes to array semantics (basically, blame BCPL and B for most of it).

As for the question "[w]hy not just enforce that index[array] is invalid, for clarity's sake," what would such a check buy you in exchange for the cost of performing it?  The form almost never appears outside of the IOCCC, so it's not like it's a major problem in production code (compared to the use of, say, gets, or unchecked array accesses (which disallowing i[a] won't help with), or <fill in the blank>).  It's not a bug; it doesn't introduce any undefined behavior; it doesn't introduce any security holes not already present with a[i]; the only complaints against it are stylistic in nature.

It's like asking why both T *p and T* p are valid; there is no "why" beyond it being an accident of the language syntax.  There's nothing deliberate behind allowing both, it's just a function of how the grammar works.  Same with a[i] and i[a].  Professional programmers are (usually) grown-ups, and don't deliberately introduce confusion where it isn't warranted, so most will naturally use a[i].

You're basically trying to guard against a problem that doesn't really exist.


问:
Functional Programming: Are Tuples a viable replacement for Types?
A while ago I decided to learn Haskell to help with learning more "pure functional" ideas that I could apply to F#.  Right off the bat it seems as if there's no real types in Haskell like the ones that F# has. I'm fine with that so I wanted to find a way to remove myself from the hybrid OO/Functional design I've used in F# and really try to go classless and truly develop a function centric design.  The first thing that came to mind when using Haskell was to just pass tuples around as they can hold information in key value pairs much like dynamic languages but don't have the constructor syntax like F# types.

For example in F#:

```<code>type DatabaseWorkValueItem(firstItem, secondItem, thirdItem) =
  member public x.FirstItem = firstItem
  member public x.SecondItem = secondItem
  member public x.ThirdItem = thirdItem
</code>```

And this would be in my new proposed design:

```<code>module DatabaseWorkValueItem =

  let firstItem (item, _, _) = item
  let secondItem (_,item, _) = item
  let thirdItem (_,_, item) = item

  --Replace constructor with method
  let CreateValueItem (parameter:String, value:Object, sqlType:SqlDbType) =
    (parameter, value, sqlType)

  --Replace properties with more methods
  let GetDataType (item :(String *Object * SqlDbType)) =
    thirdItem item

  let GetParameter (item :(String *Object * SqlDbType)) =
    firstItem item

  let GetValue (item :(String *Object * SqlDbType)) =
    secondItem item
</code>```

They both get the same idea.  One creates a class like Type with properties set on construction and the other uses all functions to create and read a tuple.

Question is: Am I crazy to bother with this?  Although I realize F# has the convenience of jumping between two paradigms, I can't help but feel that it's a comfort blanket to

答:
Generics exist because they make programming life easy.  Your question is similar to asking if using a List that takes Integer types in its generics argument is somehow less safe than designing a list called IntList that's hardcoded to accept only Ints.

In Java a C#, there's typically a geometric point object called Point3D that has float parameters x, y, z.  But it should be clear that a 3-tuple of types float is functionally equivalent to Point3D.

The continuation-passing style programs allow output to be returned in more than one variable.  The direct style programs allow output to be return in one variable only.  Tuples are a quick way allowing more than one output to be returned in a function and they prevent junk classes from polluting your library when you don't need to deal with them.


答:
First, SLA is the term for providing a service at a defined level, it can include both penalties and rewards, termination of agreements and commitment to higher level of usage.  Basically anything you can think to put in a contract, with terms dependent upon service levels (uptime, number of visitors, response time, failure rates,etc).

Secondly, non-corrupt goverments are not interested in stealing your code, they are interested in preserving their investment.  Assuming a non-corrupt goverment, they are simply doing risk abatement.  Larger organizations of any sort worry more about the cost of downtime and changes than do small companies, because they are more expensive for a large organization  -- just as a simple example considering using your service is probably costing several thousand dollars at the absolute minimum,  it could easily be tens of thousands; meetings, technical evaluations, memo's, etc...

Basically a large organization will be interested in two things: what happens if your service changes in a way that makes it unusable, and what if your service simply becomes unavailable.  To make your service attactive to them, focus on solutions to these problems, not the fact that if you go out of business they don't have to pay you any more -- not paying you is exactly what THEY are worried about.

So,  an escrow account (or even automatic release of the current or prior version) with a clear contract specifying that you retain ownership under all conditions, and a non-compete clause that says they can't offer the service to anyone else under any circumstances and can only do so for their own customers/users in the event of you not meeting the specified level of service.

You can actually use this as a selling point, possibly including using their computers as fall over servers (current/prior code releases can mean that their programmers/techs are always ready to do a switch over, fall over servers could mean zero downtime in the event that you pull the plug).  Don't forget to include penalties if they DO release your code due to error or dishonest employee.

Honestly, this sounds like a great opportunity.


问:
Choosing a rate to charge a client for training their programmer
We've been put in a bit of a difficult situation and I'm trying to figure out the best way to deal with it and how to charge for it.

We've built a custom web app for a customer and I've been maintaining it for the last 1.5 years. They sent email an email a couple weeks ago saying they've hired a developer and would like to take the project in house. (Nothing had been mentioned regarding taking it in house before.) I was of course surprised as I had expected to be working on the project for another year or more.

I met with the developer a week ago and went over the basics of the site. After my offer (including suggestion of a different rate) and follow-up email, they asked me if I'd be willing to do some training on how to continue development of the app using the libraries/techniques currently used. (The developer is experienced with the language, but not with the libraries.)

I'm wondering how much I should charge for 1-on-1 training tailored specifically for the site and the libraries (libraries which are reusable)? I'm thinking the training would between 3 and 6 hours, depending on how much the developer's skill level.

Here are my difficulties in coming up with the rate:

We're going to be loosing 10s of thousands of dollars by not having the client and project any more (not to mention future opportunities). So in part, I'd like to replace some of this income through training.

I'm essentially training someone to do what we do and giving them the opportunity to compete against us. They are a reasonably large company that has the possibility of competing against our company directly, although it's not likely our 2 companies will be direct competition.

We've spent years learning the libraries (50% external and 50% ours) and the technology behind them (which we haven't been paid for directly).

I'm not sure what the going rate for training is the area, specifically for 1-on-1 training.

I want to do the right thing because there is a slight possibility of affecting other business relationships.

My first thought was to to charge something around 5 times the rate we're charging them currently, but I have a feeling they'll think this is high.

(We're not terribly concerned with getting the contract to do the training, but it would be a unique opportunity where we could learn as well.)

Thanks for your suggestions and ideas. I know this is a bit of a subjective question, but I'm just looking for suggestions or something I'm not thinking of.

答: If the client has been reasonable, you can just lay out the situation and ask them how they think you should handle it.  They probably realize they're going to need help going forward.  You've got some negotiating power, they don't want you to cut them off.</p>


答:
5 times your current hourly rate seems like a realistic ballpark assuming you are going to have some sort of deliverables (documentation, presentations, etc.) simply on the grounds that it's likely to take 30 hours of work to put together 6 hours of good, solid training.  Figuring out the lesson plan, prioritizing what you have time to cover, figuring out how best to organize, explain, and illustrate the various libraries, etc. is not trivial.  And the documentation, presentations, etc. that you get with training is invaluable because no one is going to absorb everything you're saying in a 6 hour training class the first time around.  When you present it to the client, make sure to point out that what they're paying for is primarily the development of the curriculum, not the delivery of the material.

If the intention is for you to show up cold and answer questions or try to "wing it" for 6 hours, that is likely to be penny wise and pound foolish.  The developer you're training is going to absorb far less because you're not going to be as organized as you would be had you gone through the effort of putting together the training material.  And he's not going to be able to refer to documentation when he actually starts working on something a few weeks from now and can't quite remember some important bit of information.

From a client relations standpoint, you're far better off ensuring that the new developer is successful.  You may lose some future maintenance work, but you're far more likely to get future development work if the client is confident that you're going to make the transition as smooth as possible when they decide to bring an app inhouse.

Title: Choosing a rate to charge a client for training their programmer

Body:
We've been put in a bit of a difficult situation and I'm trying to figure out the best way to deal with it and how to charge for it.

We've built a custom web app for a customer and I've been maintaining it for the last 1.5 years. They sent email an email a couple weeks ago saying they've hired a developer and would like to take the project in house. (Nothing had been mentioned regarding taking it in house before.) I was of course surprised as I had expected to be working on the project for another year or more.

I met with the developer a week ago and went over the basics of the site. After my offer (including suggestion of a different rate) and follow-up email, they asked me if I'd be willing to do some training on how to continue development of the app using the libraries/techniques currently used. (The developer is experienced with the language, but not with the libraries.)

I'm wondering how much I should charge for 1-on-1 training tailored specifically for the site and the libraries (libraries which are reusable)? I'm thinking the training would between 3 and 6 hours, depending on how much the developer's skill level.

Here are my difficulties in coming up with the rate:

We're going to be loosing 10s of thousands of dollars by not having the client and project any more (not to mention future opportunities). So in part, I'd like to replace some of this income through training.

I'm essentially training someone to do what we do and giving them the opportunity to compete against us. They are a reasonably large company that has the possibility of competing against our company directly, although it's not likely our 2 companies will be direct competition.

We've spent years learning the libraries (50% external and 50% ours) and the technology behind them (which we haven't been paid for directly).

I'm not sure what the going rate for training is the area, specifically for 1-on-1 training.

I want to do the right thing because there is a slight possibility of affecting other business relationships.

My first thought was to to charge something around 5 times the rate we're charging them currently, but I have a feeling they'll think this is high.

(We're not terribly concerned with getting the contract to do the training, but it would be a unique opportunity where we could learn as well.)

Thanks for your suggestions and ideas. I know this is a bit of a subjective question, but I'm just looking for suggestions or something I'm not thinking of.


问:
Write once, run anywhere. Is it still relevant?
Since Oracle bought Sun and Apple have decided not to continue developing their JVM, is the "write once and run everywhere" model still relevant or has web services/SOA reduced it to an edge case?</p>

答: Its actually a pretty simple and straightforward case of a fundamental tension  that's not going away anytime soon. While its the developers dream, "write once, run anywhere"  commoditizes platforms. Platforms vendors' whole business depends on differentiation. For them , its "Write once, and write for me only". The two sides will continue to pull in opposite directions for some time to come.  </p>


问:
Class Design -- Multiple Calls from One Method or One Call from Multiple Methods?
I've been working on some code recently that interfaces with a CMS we use and it's presented me with a question on class design that I think is applicable in a number of situations.  Essentially, what I am doing is extracting information from the CMS and transforming this information into objects that I can use programatically for other purposes.  This consists of two steps:

Retrieve the data from the CMS (we have a DAL that I use, so this is essentially just specifying what data from the CMS I want--no connection logic or anything like that)

Map the parsed data to my own [C#] objects

There are basically two ways I can approach this:

One call from multiple methods

```<code>public void MainMethodWhereIDoStuff()
{
    IEnumerable<MyObject> myObjects = GetMyObjects();
    // Do other stuff with myObjects
}

private static IEnumerable<MyObject> GetMyObjects()
{
    IEnumerable<CmsDataItem> cmsDataItems = GetCmsDataItems();
    List<MyObject> mappedObjects = new List<MyObject>();
    // do stuff to map the CmsDataItems to MyObjects
    return mappedObjects;
}

private static IEnumerable<CmsDataItem> GetCmsDataItems()
{
    List<CmsDataItem> cmsDataItems = new List<CmsDataItem>();
    // do stuff to get the CmsDataItems I want
    return cmsDataItems;
}
</code>```

Multiple calls from one method

```<code>public void MainMethodWhereIDoStuff()
{
    IEnumerable<CmsDataItem> cmsDataItems = GetCmsDataItems();
    IEnumerable<MyObject> myObjects = GetMyObjects(cmsDataItems);
    // do stuff with myObjects
}

private static IEnumerable<MyObject> GetMyObjects(IEnumerable<CmsDataItem> itemsToMap)
{
    // ...
}

private static IEnumerable<CmsDataItem> GetCmsDataItems()
{
    // ...
}
</code>```

I am tempted to say that the latter is better than the former, as GetMyObjects does not depend on GetCmsDataItems, and it is explicit in the calling method the steps that are executed to retrieve the objects (I'm concerned that the first approach is kind of an object-oriented version of spaghetti code).

On the other hand, the two helper methods are never going to be used outside of the class, so I'm not sure if it really matters whether one depends on the other.  Furthermore, I like the fact that in the first approach the objects can be retrieved from one line-- most likely anyone working with the main method doesn't care how the objects are retrieved, they just need to retrieve the objects, and the "daisy chained" helper methods hide the exact steps needed to retrieve them (in practice, I actually have a few more methods but am still able to retrieve the object collection I want in one line).

Is one of these methods right and the other wrong? Or is it simply a matter of preference or context dependent?

答:
The first example is what is typically called a Method Chain.  There isn't really anything inherently wrong with method chains per-se, however long chains may be difficult to manage and understand, even while they might make the code appear cleaner and clearer to read. If necessary, then sometimes you just have to put up with them, however it can sometimes be preferable to replace a method chain with a helper method or class that handles all of the chained calls for you, particularly if you find yourself needing to use a particular chain often.

The second example is fine for relatively small methods that do not need to do more than a few things.  As the number of calls increases however, the code often becomes less clear and more difficult to read. Again, there is nothing inherently bad with having a method with multiple calls, however the risk is that for some operations you might find code being duplicated. If the method grows beyond a handful of lines, chances are there might be other methods and possibly even a class waiting to be discovered.

What is important, is to consider whether the technique you use is appropriate to the task involved, and whether it will have an impact on the interface of the class that the method belongs to. While the immediate goal is to satisfy a requirement, other goals may also include extensibility and low maintenance overhead.  Experience with your particular applications will teach you when to favour one technique over another.


问:
Why hasn't Caja been popular?
Google released Caja around 2008(Capability JavaScript). It is still mainly a laboratory language. But XSS and other attacks would be prevented if there was widespread integration of Caja.</p>

答:
I am the technical lead for Caja.  Since it's initial release, we've been iterating on the design and implementation of Caja. With each iteration we've made the input we accept as input larger (and closer to plain-old-javascript), and our output faster and more debuggable.  During our testing we found that the lack of these features made adoption by developers difficult.

Our current iteration is based on ES5-strict support in modern browsers and executes at full speed and with a sufficiently simple translation as to be negligible during debugging.  We're not quite done with all the features of the new version but you can try it out experimentally at http://caja.appspot.com/?es5=true .  We expect our modern version of Caja to see a lot greater adoption.

We will continue to support older browsers with our existing server-side translation version and existing sites can start using it today and start getting the modern version based on the version of the browser soon.  For example, Google Sites uses Caja to sandbox HTML Box in this way.

For more information on how to embed content using Caja, see https://developers.google.com/caja

Title: Why hasn't Caja been popular?


问:
Alternative IDEs
After seeing http://www.kickstarter.com/projects/ibdknox/light-table

I'm wondering if anyone has come across other alternative methods of developing.

When working on embedded things Notepad++ was ample, which isn't necessarily an IDE but it is a different way of handling things from using Xcode, Visual Studio, or Eclipse.  And even JDeveloper follows the same design as those.

As OS X and other OSes change, along with website methodologies, app structures, frameworks, can we start changing how we develop?  I've also seen quite a few "code on your iPad" apps.

Will we eventually move away from coding as we know it?  Will there be a split?  Can something like Light Table bring even low level C++ coding into the next generation of enterprise or embedded level development?

Especially since I feel like a small minority who even takes advantage of some non-default IDE settings such as custom syntax coloring (once you go Zenburn you don't go back)

答:
I haven't seen anything used mainstream other than text editor and standard IDEs that you already mentioned.

However, long before I saw the light-table video, I did come across Code Bubbles, which is another similar idea that developers should be working with functions and code segments instead of files.

Title: Alternative IDEs


问:
Where do you draw the line between quantity and quality?
My manager has talked with me and says that the quality of my work is excellent, but I need to step up the quantity of how much I crank out. I've only been working for a couple of years, so I still feel like I have a lot to learn. Which route do I take (or is there another?):

Quantity: If they want crap, I can give them lots of it.

Quality: Ignore the request, and hope that my productivity will increase with experience.

答:
Remember that you need to actually ship software for it to be useful: there's no point in writing the most awesome code in the world if it isn't available when it's needed.

It's one of many requirements that you need to balance. Assuming your manager is competent I'd be listening to them: they're more likely to know the quality/speed ratio required for the project than you (as a fairly new dev) are.

Or to use a common phrase: the perfect is the enemy of the good.


问:
Passing member variable as a method parameter
In a project, I've found a code like this:

```<code>class SomeClass
{
    private SomeType _someField;

    public SomeType SomeField
    {
        get { return _someField; }
        set { _someField = value; }
    }

    protected virtual void SomeMethod(/*...., */SomeType someVar)
    {
    }

    private void SomeAnotherMethod()
    {
        //.............
        SomeMethod(_someField);
        //.............
    }

};
</code>```

How do I convince my teammates that this is bad code?

I believe this is an unnecessary complication.  Why pass a member variable as a method parameter if you already have access to it?  This is also a violation of encapsulation.

Do you see any other issues with this code?

答:
The main reason for having a member variable in a class is to allow you to set it in one place, and have it's value available to every other method in the class. In general therefore you would expect that there is no need to pass the member variable into a method of the class.

I can however think of a couple of reasons why you might wish to pass the member variable into another method of the class. The first is if you need to guarantee that the value of the member variable needs to be used unchanged when used with the called method, even if that method will need to change the actual member variable value at some point in the process. The second reason is related to the first in that you might wish to guarantee the immutability of a value within the scope of a method chain - when implementing a fluent syntax for example.

With all of this in mind, I wouldn't go so far as to say that the code is "bad" as such if you pass a member variable to one of it's class's methods.  I would however suggest that it is generally not ideal, as it might encourage a lot of code duplication where the parameter is assigned to a local variable for example, and the extra parameters add "noise" in the code where it isn't needed.  If you are a fan of the Clean Code book, you'd know that it mentions that you should keep the number of method parameters to the barest minimum, and only if there isn't another more sensible way for the method to access the parameter.


答:
Things are moving towards feature rich, minimalistic and easily extended development tools. Sublime Text is a very good example of an editor which is shaking things up with its UI, plugin system and source view. As of right now you can work with languages like C, C++, C#, Java etc. using these editors but not without some setup and loss of critical features found in your larger, more bloated IDEs. I think eventually we will see these awesome, simple and lightweight tools become the standard for development.

Others I have used in the past that remind me of what you have posted include Coda, Textmate and inType.

Title: Alternative IDEs

Body:
After seeing http://www.kickstarter.com/projects/ibdknox/light-table

I'm wondering if anyone has come across other alternative methods of developing.

When working on embedded things Notepad++ was ample, which isn't necessarily an IDE but it is a different way of handling things from using Xcode, Visual Studio, or Eclipse.  And even JDeveloper follows the same design as those.

As OS X and other OSes change, along with website methodologies, app structures, frameworks, can we start changing how we develop?  I've also seen quite a few "code on your iPad" apps.

Will we eventually move away from coding as we know it?  Will there be a split?  Can something like Light Table bring even low level C++ coding into the next generation of enterprise or embedded level development?

Especially since I feel like a small minority who even takes advantage of some non-default IDE settings such as custom syntax coloring (once you go Zenburn you don't go back)


答:
I don't know how many ideas like this exist but they do. I have been thinking of starting something similar like Light Table but primarily as a tablet IDE environment concept.

Here is why they will become standard in my opion:
I believe concepts like Light Table are import to future program development.  Reasons why I do are because, with a growing number of programming languages and libraries, documentation becomes increasingly important.  Especially with the need to perform cross platform and language task.  One thing many programmers know is that it is difficult to read some APIs if not most, and there is no real great consistency to them.  Ideas like this will help create standards much like ANSI did for C.

The need for screen space on tablets will change the scope of how IDEs display information too.  I do believe we are on the path to be a tablet generation; mobile programming will become growing task as this happens.  A couple example of what I mean; situations when a client needs you at their office looking though files with them so you understand what they need in a small processing app.  Another could be because programmers get a sore butts from sitting to long; many of them would love to travel ( tremendous upside to innovation could come from this ). There are many reasons I can think of why mobile programming is gonna become increasingly an important feature.

Why it doesn't just happen:
There is a term I am sure most of you have heard " re-inventing the wheel " and have probably even been told not to do it.  There is merit in this statement but it isn't solid.  Programmers have created higher level languages ( modern practices ) to ease the learning curve and the same goes for libraries to those languages.  When you need to minimize the space being used and code being compiled you may have to enter into lower level languages ( older practices ) to have the best performance and power in your app.

So I don't deviate to far from my point, what this means is programmers are not completely ready to reinvent the wheel.  Some IDE's are very difficult to learn and programmers have had to spend huge amounts of training time into using these as efficiently as they can to become faster and better programmers ( older practices in a way ). To re-invent the wheel for IDEs they will have to add modern needs like tablet orientation or better documentation features ( newer practices (or needed)). In addition many IDEs have only become what they are due to many years of developing them to meet the needs of programmers.

Conclusion:
In short they will come ( I really want to start this an open source project for my above idea in my opening sentence. ) but in due time ( which is soon ).

Title: Alternative IDEs


问:
determine language limitations before development
It so happens that you are given a project specs and your knowledge about the language is very basic. There are features in the project that you have never worked with.  But you have some ideas and logic on how this can be implemented.

Later on as the development continues you discover that the required features cannot be developed because of some language limitations or any other issues. Now you have to convince your client about this, which is not easy.

Edit: the reason for working with not so comfortable technology is that,Company at times cannot afford to hire someone for this task. Hence relies on existing employees to learn something new and contribute.

So how do I avoid such situations? How do I research about the features before accepting the project ?

答:
The requirement collection phase in s/w development is crucial. Before accepting project you must take care of certain features like,

Purpose of project

man hours to complete project

design/UX

target audience (here you can filter for your language problem)

project scale

Project cost
etc...

The only way to research is ask as many questions to client as possible and get details out of them. Please refer to this wonderful wiki link on software requirement specification


答:
IMHO there are steady changes going on that will keep going and will make us change the way we develop software:

programs keep getting bigger and complexer.

people start working from home more.

programming with higher level abstractions is getting more common.

more diversity on the machines we want to develop on.

more diversity on the machines we want to develop for.

In a few places you see editors full filling some of the needs

MPS : a met programming system where you can create your own DSL's ( make your program like a table for the parts where it is handy) http://confluence.jetbrains.net/display/MPS/Welcome+to+JetBrains+MPS+Space

cloud9Ide : code from your browser anywhere anytime in collaboration http://c9.io/

Code Canvas : ms research that still works on an editor like code bubbles Link

MOBL : A dsl editor that makes it easy to develop for different mobile devices http://www.mobl-lang.org/

In my mind these can evolve and be combined.

Title: Alternative IDEs

ContentLicense: CC BY-SA 4.0


问:
Is it fair to reduce OOP to mere hierarchical composition of data structures?
Meaning that OOP allows me to have data-trees, of arbitrary depth and breadth, with some leafs being functions (and those leafs would be called methods) ?

Because everything else that people often put near "OOP" mark, just don't seem to have anything to do with it. (Inheritance, subtype polymorphism and encapsulation seem to be orthogonal to OOP).

Am I right? Or I'm missing something ?

答:
Is it fair to reduce OOP to mere hierarchical composition of data structures?
  Meaning that OOP allows me to have data-trees, of arbitrary depth and breadth, with some leafs being functions (and those leafs would be called methods) ?

I guess you can choose to look at it that way, but I don't believe it's a particularly useful way to look at it.  Specifically, your use of the word "data" (even if you specifically mention functions in there) seems to reduce OOP to a way to model data (or at least, to a data-centric approach).  In my opinion, this is missing the point.

OOP is a particular way to structure code; both behaviour as well as data.  Its main ideas are the normalisation of behaviour (DRY principle), as opposed to, say, the normalisation of data (as in the relational DB concept), and concepts like encapsulation.  At its simplest, encapsulation is achieved by providing an external interface to classes (your public stuff), and an internal implementation (private / protected stuff).  This is quite different to "traditional" modular programming, since your "module" boundaries are structured completely differently - in the case of OO, each class is a mini-module.

It is also important to note that the concept of encapsulation, in the generic sense, is quite different to a specific implementation of encapsulation.  OOP has a specific way that encapsulation is done, inherently (of course, I'm only referring to the core cases here, not patterns, etc).  Inheritance and polymorphism are much more OOP specific ways to achieve other principles (code reuse being one of them).  I'm not sure I'd lump them in the same sentence as encapsulation, they exist at a slightly different level.

OOP also tends to map quite nicely on to a problem domain, allowing you to model a problem in a way that remains understandable to semi-technical users.

What was the point of going through the above mini OOP discussion?  The above is the best I can do to summarise OOP in a few sentences - it highlights the main points of OOP from the perspective of someone who has worked with the technology for a long time.  I don't think reducing it to a hierarchical composition of data structures does it justice.  We can also reduce it to an array of characters in text files, but it doesn't mean that it captures the essence of the paradigm.


答:
Well, in most languages you can do most things. All the mainstream languages barely have limitations, or have some kind of work arounds. In the worst case, you can still call external code using some bindings if needed.

Where programming languages differ mostly is what they provide. What stuff is easy to do using this or that language.

Lastly, it is difficult to know beforehand where you'll face difficulties with barely no know-how of the language and of the project. The devil lies in details.

What I recommend is therefore to ask precise questions here, about one or the other specific aspect of the problem and how it is tackled with the programming language. That way you will be better informed to assess its difficulty.

Title: determine language limitations before development

Body:
It so happens that you are given a project specs and your knowledge about the language is very basic. There are features in the project that you have never worked with.  But you have some ideas and logic on how this can be implemented.

Later on as the development continues you discover that the required features cannot be developed because of some language limitations or any other issues. Now you have to convince your client about this, which is not easy.

Edit: the reason for working with not so comfortable technology is that,Company at times cannot afford to hire someone for this task. Hence relies on existing employees to learn something new and contribute.

So how do I avoid such situations? How do I research about the features before accepting the project ?


答:
Later on as the development continues you discover that the required features
  cannot be developed because of some language limitations or any other issues.

I have learned in risk management that features that may be impossible to be created could be developed as early as possible so you can find out soon that the project has to be canceled before too much money is wasted.

If you have the business goal that is behind a feature maybe you can offer an alternative feature that leads to a similar result.

Example: if an imaginary system does not support comboboxes. But you can implement a popup-dialog to select some item out of a list instead.

The feature "combobox" is not possible but the goal "select a product-time to be ordered" is possible.


答: Somehow, it reminds me of smalltalk. The IDE was not file based but also an "all-in-one" interactive solution. However, it never really took off.</p>

Title: Alternative IDEs


答:
In addition to what others have posted, I've always found dnrTV to be a fairly interesting: it's basically a screencast with a host and a special guest for each episode.  They generally work through some concepts and do some actual coding, which helps a lot when you are new to concepts.

(Unfortunately, they focus on .Net... but for design patterns this shouldn't matter - most design patterns are language agnostic, and the difficulty is understanding why and where they are useful.  Specific implementations can be looked up in minutes.)

They have a number of episodes dealing with design patterns - here is the first one, and their archives page.  It's been a while, so I can't really remember what they cover in those episodes.  In general though, they aren't bad, and it's fun to see some sharp people's opinions and toolsets.


问:
When should I use parallelism?
After asking this question, I got to realize that parallelism may not always be good.

So far I can see that parallelism (under c#) is

A little complicated code-wise

Will probably insert some concurrency complications

Will not always be faster

I am looking inside parallelism because I want to make existing and new applications work faster, but now I see that it is no silver bullet.

When should I use it? are there any best practices?
Is it just a waste of time in most cases?
Is it suitable for a specific kind of applications?

I am looking forward for your insights on this matter.

答:
I use it on server side applications where I have 8 cores at my fingertips. That's a lot of speed improvement of your application works with big data sets.

Still, I only use it when I know there are operations that can be parallelised: hits to the database (using different connections from the connection pool), requests to web services, disk IO (this one is arguable but I go on the presumption that threads will begin work as soon as they get their IO sorted and not have to wait for the other ones to do their work).

All this leads to marginal improvements but over large datasets parallel wins over serial in these conditions.

Still, I only when user interaction is impacted by slow operations as writing the code to perform parallel operations may not be trivial even with plinq.

Title: When should I use parallelism?


问:
Is it a responsibility of the software developer to understand what the customer meant with his request?
Kind of a yes / no question and why?

Is it the responsibility of the software developer to understand what the customer meant with his/her request or is it the responsibility of the customer to properly explain his/her request to the developer?

The situation at work is currently "the customer already explained us, what he wants. It's your responsibility to understand the request, not ask more questions".

While English is not my strong suite, all the requests are written in obscure English with misplaced words and hard to understand sentences, some requests assume previous understanding of the system on my part.

I'm the 3rd or 4th developer of the system (the last developers quit the job) and that might be the reason the customer expects some understanding on the developers side.

The system itself is quite messy both in the UI and source code level. This looks like monkey coding to me - code and hope you get the request right, while not actually understanding the request.

I'm actually thinking about quitting the job, but haven't yet, given I'm not sure about who's right and who's wrong.

答:
In a perfect world, there should be a list of features and specifications somewhere, something written on a contract bonding your company and your customer.

To answer your question, the developper should indeed understand what the customer wants, and have a written document so that both parties agree to the same vision.

Of course, this is not a perfect world and often there are no specifications, and if you don't have any written specification, well, this is going be hard. Is there anybody left in your company who work as relationship delegate with the customer, who could help you understand what the customer wants ?

If not, in your position, I'd try and get info from the previous developers, assuming they understood the task of course.