问:
Feedback on a Kanban Board for Solution Architectects
Before I get started I need to issue a pre-emptive apology:

It is very likely that some of the terminology / vocabulary I use in this post is plain wrong there is also a good chance I have entirely misinterpreted some of the keys aspects.  I am new to this so don't be too critical, more than welcome constructive feedback ;)

Background

We are currently transitioning a development department of 200 people from multi-methodology into "Agile".  The whys, wherefores, pros and cons of this are well beyond the scope of this question.

This development department contains an Architecture Service team that is made up of 10 people that are officially known as "Solution Architects".  In reality they cover more than just the solution, these are technical people that cover every technical architectural aspect of a project (i.e. hardware, software, security, governance etc).  They also provide ad-hoc functions to the development team (code reviews, standards guidance etc) and wider business (technical input into tenders, pre contract technical preview of customer requirements)

As part of this transition I have been tasked with creating a Kanban board for the purposes of getting a view of the work activities that the Architecture Service team are accountable for.  There are a myriad example boards for development / coding teams, but none that I can find for Architecture.  So I have taken from various sources and created "something", I would really appreciate genuine feedback on it.

It is also worth noting that this will be presented to the team as a starting point / work in progress.  It is their board and I want them to own it, all I am doing is setting a foundation for the guys to build on (and change if necessary)

So far I have something like this

The Main Board

The main board is where we hold all active / backlog projects - all active work will be on this board.  This will be short reviewed in the daily architectural scrum with a more in-depth review at the end of every week.

```<code>           ------------------------------------------------------------------------
           | Evaluation            | Implementation       | Ad- Hoc               |
           | Todo  | Doing  | Done | Todo  | Doing | Done | Todo  | Doing  | Done |
    -------------------------------------------------------------------------------
    Person |       |        |      |       |       |      |       |        |      |
    --------       -----------------       ----------------       -----------------
    Person |       |        |      |       |       |      |       |        |      |
    --------       -----------------       ----------------       -----------------
    Person |       |        |      |       |       |      |       |        |      |
    --------       -----------------       ----------------       -----------------
    Person |       |        |      |       |       |      |       |        |      |
    -------------------------------------------------------------------------------
</code>```

The column descriptions / purposes are:

Evaluation: Projects where the person is doing an initial technical analysis, i.e. running through technical options with a product owner, determining the size of the project.  As an example an Evaluation project may be the Architect evaluating a new technology or working with a customer to produce a mutually agreed technical solution.

Implementation: Projects that are actively in development (coding, testing etc) and the person is acting in an SA function for the wider project team.  As an example this could be the development of coding aspects of the "mutually agreed technical solution" mentioned above, equally it could also be architecturally overseeing the implementation of some new hardware.

Ad-Hoc: All the weird and wonderful stuff that comes up that can't be put into the other two columns.  As an example in a strange recursive world there is a card for me in the ad-hoc column to create a KanBan board :).

Person: Fairly self explanatory, the person who "owns" the cards in that row. To make things a little more fun this actually contains an avatar of that persons choice.

Todo: Is effectively our backlog, the cards in here are ordered top to bottom in priority.  As space in a persons doing cell becomes available we take from the top of todo.

Doing: Fairly self explanatory

Done: Items that have been completed since the last full board review (Friday afternoon every week)

WIP Limits

Rather than do what we do now (i.e. give out work until somebody squeals), I would like the main board to work with objective / evidence based WIP limits.  The intention is to size each of the board cards with:

XS (Extra Small) : 3 points

S (Small) : 5 points

M (Medium) : 8 points

L (Large) : 13 points

XL (Extra Large) : 21 points

The size is very much from an Architects workload perspective, for example a project that requires 1 year of coding for 10 people but minimal Architectural input would be XS or S.  However a project that has massive Architectural input but minimal coding could be an XL.

Over time we should be able to work out the WIP limit for each person.  So we know that Jonny Smith can work with a velocity of 42 points and therefore allocate projects up to that level.

As we have not done this before my intention is to set the initial limit high, the idea being that when a person squeals we can (as a team) look at this objectively and determine if it is genuinely too much or is it because our processes etc are too onerous and should be streamlined.

NOTE: Of everything here these WIP calculations are the bit that "feel" the least right*

The Funnel Board

In order to keep track of all the random things that fly through the team we also have a funnel board.  This is a relatively simple board that looks like this:

```<code>    ------------------------------------------------------------------------
    | Evaluation            | Implementation       | Ad- Hoc               |
    ------------------------------------------------------------------------
    |                       |                      |                       |
    |                       |                      |                       |
    |                       |                      |                       |
    |                       |                      |                       |
    |                       |                      |                       |
    ------------------------------------------------------------------------
</code>```

As the team is made aware of a "project" but this is not yet officially sanctioned (i.e. can be put into the Todo columns on the Main Board) then it goes onto the funnel board.  Items here are not allocated to a person.  The idea being that we can track those random things that come through and ensure they are not forgotten.  Also, as the person completes an evaluation project this then moves from Main Board Evaluation Done to the Implementation funnel board (unless it immediately becomes an implementation project)

A member of the team will occasionally be tasked with following up everything on the funnel board, i.e. quick phone call to the product owner asking if this is still relevant (this would be an ad-hoc project on the main board)

The Successes Board

This is just a simple board to track what we have done over the last X months.  It holds the cards that have been through the Funnel and / or Main boards

```<code>    ------------------------------------------------------------------------
    | Successes                                                            |
    ------------------------------------------------------------------------
    |                                                                      |
    |                                                                      |
    |                                                                      |
    |                                                                      |
    |                                                                      |
    ------------------------------------------------------------------------
</code>```

The idea being that we can occasionally get around this board and give each other mutual pats on the back :)

Board Cards

The cards that are on the boards contain the following information:

```<code>    ------------------------------------------------------------------------
    | SIZE (XS,S,M,L,XL)          | OWNING TEAM MEMBER             |  RAG  |
    ------------------------------------------------------------------------
    |                                                                      |
    |                         PROJECT TITLE                                |
    |                                                                      |
    ------------------------------------------------------------------------
    |                                  |                                   |
    |        DEPENDENTS                |          DEPENDENCIES             |
    |                                  |                                   |
    ------------------------------------------------------------------------
    |                                                                      |
    |                         MISC INFORMATION                             |
    |                                                                      |
    ------------------------------------------------------------------------
    |                WIDER PROJECT TEAM (AS APPLICABLE)                    |
    | Other Architects, Project Manager, Principal Developer, Business     |
    | Analyst, Scrum Master                                                |
    ------------------------------------------------------------------------
</code>```

As you will notice the granularity of the card is at a fairly high "Project" level, I am not planning on doing a developer style board that is split into tasks (thoughts on this welcome).  Also worth mentioning that depending on where the card is not all sections will be applicable.  I am also planning on colour coding the cards, as a first stab I have:

Yellow : Anything that is customer contractual
Pink : Anything that is internal (i.e. not end user facing)
Green : Anything that is a company group project

The cards will be magnetic rather than post-it, I am hoping to find some that are like mini white boards as this will make life easier as things change

Other Stuff

If its not on a card on a board then as far as the team is concerned it doesn't exist

The boards themselves are Whiteboards with Wheels, we can take them wherever we want

We may consider going to a virtual whiteboard in the future (physical whiteboards are easier to change when we decide that the X column is best on the left of Y not the right)

Questions

After reading my newbie Kanban War and Peace what are your thoughts? (please go easy on me :))

答:
Wow! That took some time to fully digest and understand.  Congratulations on deciding to adopt Kanban for your Agile initiative.   Really nice analysis and modeling so far.  Thanks for sharing it here and allowing us to help and contribute to that initiative!

I have some thoughts and suggestions – hope these help!

A. First, just to get an overall “system view”, I gather the three boards you have shown are ONLY for tracking the Architects’ work, not the rest of the Development Department’s work, is that correct?

B. Given the way you have described it, it would appear that each of the Funnel Board columns is essentially the “Ready” column for the corresponding sections of the Main Board.

Is it necessary to have the separate Funnel board? Would it not be simpler to have a single board – where you have “Funnel” or “Ready” columns for each section of the Main Board?

Similarly, the Successes Board can be seen as a large column to the right of the Main Board where all successfully completed work accumulates for a period of time?

So, depending on the number of projects in the funnel and in progress (in any of the stages) at any time, would it be simpler to manage these all in a single Board which has the following design -

Of course, it is very likely you have already evaluated this and decided it might be too big to manage in a single Board! (You could consider dropping the To-Do lanes in each section since the Funnel lane might serve that same purpose?)

C. In terms of the Main Board design, it really depends on what your overall goals are for implementing Kanban.  Some questions on the board design:

Do you want to improve Lead/ Cycle Times for individuals (which would be easy to do in the current design) or for different types of Projects (which might be more tricky (but not too much given your color-coding)?  If it were the latter, you might prefer to have the lanes defined not by people but by Project type (similar to class of service)?

Is it ever possible that you might have two architects working on a single project? If so, having lanes by people would make it difficult to model that, unless you had two cards for the same project against each person?

Is it possible that different types of Projects may have a different workflow? For example, might a customer project require greater scrutiny (validation or testing or reviews) than the others? If so, Kanban allows you to have different workflows for different types of work, which would not be possible in this design.

If any of the above points 1-3 make sense in your situation, I would suggest that you might want to consider lanes not based on people but on some other aspect.  From what you have talked about, doing it by Project Type seems to be one option – but I am sure there are other criteria possible as well.

Another suggestion, just for more intuitive visualization – since people associate the left-to-right flow (or right-to-left in some parts of the world) to be the direction of the flow, do you think having the Ad Hoc section to the right of the Implementation columns might be confusing? My own preference would be to have Ad Hoc projects having their own separate Swim Lane.

So, the Main Board might look as follows –

In all of the above, you could have some “avatar stickers” to show which architect(s) was work on each project that you could stick on the Project cards. If needed, a legend on one side of the board might explain which avatar was which Architect.

Finally, a bigger question – you stated initially that these boards were meant to track projects that the Architects were accountable for.  These projects, I presume, are part of (larger) projects that are being done by the overall Development department.  How are you planning to show dependencies between those (bigger) projects and the architects’ work?

D. On the WIP Limits, based on what I have seen a number of our customers do – is not to sweat it too much initially!  But as you go, it is critical to establish WIP Limits – and change them as and when needed, rather than not have WIP Limits. If you already have some data on how many projects did each Architect or the entire Architect team handled in the last several months, you could use that to define some initial WIP limits already.

If you do consider going to a virtual Kanban board in the future, some of these might be easier to manage, change and play around with – such as –

Showing people working on cards

Setting up and showing intra- and inter-board card dependencies

Filtering the Board by people, project-type or other attributes

Making changes to board and card designs, etc.

I hope this helps - at least in throwing up some ideas for you to consider.

Best,

Mahesh


问:
What does the implementation of .NET string.Split(char[], StringSplitOptions) look like from inside?
That is if we were to see how Microsoft wrote this method what would it look like?
I'm mainly interested in the use of the StringSplitOptions enumeration with the other parameter and how they probably structured their code to account for each option.</p>

答:
To find out what the implementation looks like for any part of the Framework, you can do one of two things:

You can download the .NET Framework Source Code from here, or

You can use a decompiler, like Telerik JustDecompile.

The latter choice is by far the easiest.

I downloaded and installed JustDecompile, and loaded up .NET Framework 3.5.  Then I opened up mscorlib.dll (where the String class is located) and looked at the Split methods.

Without getting into too much detail, there's an if statement that checks the StringSplitOptions enumeration, and runs one of two different methods depending on which StringSplitOptions setting is specified.  The two methods are called  InternalSplitKeepEmptyEntries and InternalSplitOmitEmptyEntries.  They are pretty much two completely different implementations.

ContentLicense: CC BY-SA 3.0


问:
Handling login errors with User Class
We have a User class which handles all things related to users within a Content Management System. As you'd expect, the class contains a function login(). This function accepts three arguments: $username, $password and $remember (the latter defaulting to true).

My question is: what is the best way to handle login errors so that they can be displayed to the user? We're using a custom MVC model here, so we have controllers and views that need to remain abstract from the class itself. I have identified the following possible solutions:

Return signed integers from the login() function that can be interpreted inside the controller.

Add a variable to the User object containing the error message in plain text

Output the error directly from within the function call

Point 3 is moot, since we won't be doing that (coupling output with a class == bad).

Point 2 seems to be the most logical, but will make multi-language (a feature that may well be added later) difficult. For example, we might do something like this:

```<code>class User
{
    public $loginError;

    public function login($username, $password, $remember = true)
    {
        if($password !== $ourStoredPassword)
        {
            $this->loginError = 'Password does not match';
            return false;
        }
    }
}
</code>```

I think the best option is #1. For example, we could do this inside the Class:

```<code>class User
{
    public function login($username, $password, $remember = true)
    {
        if($password !== $ourStoredPassword)
        {
            return -1;
        }
    }
}
</code>```

Then inside our controller, just look at the return value from login(), and handle it therein. What are people's thoughts? Is there a better way to tackle this?

答:
When it comes to user login errors I recommend a simple true/false return value.

By giving additional information above and beyond either success or failure, you tell potential malicious users what names are associated with the system (by continuously guessing names and logging the error results). If email addresses can be used as a login you'd risk letting spambots scan your system for valid email addresses.

Additionally, this helps adhere to the KISS principle; the less moving parts you have the less likely things are to break later. If you program several things around a verbose error system and you decide to change it later, it could break in other areas.

By having the system return "username or password incorrect" people know to double-check their information. And since it should wipe the password between attempts users will only get to double-check the name anyway.

Title: Handling login errors with User Class


问:
How can I layout this class to make it easier to use for API developers?
I have an application that allows the user to place a string of text into a PDF document.  I have three different ways that they can do this:

Use a Form Field. Then they have four properties to define:

Provide field name

provide instance of the field

provide an X-axis Offset

provide a Y-axis Offset

Search for a string of text. Then they have four properties to define:

Provide string of text to search for

provide instance of that string of text

provide an X-axis Offset

provide a Y-axis Offset

Define Page Coordinates. Then they have three properties to define:

Provide page number

provide an X-axis Offset

provide a Y-axis Offset

In my API, I want the object to be setup intuitively so that it is clear they are choose one of the three different methods and then whichever one they choose, they have the options for each.

In my old API, all of those options are grouped together as a list of properties like this:

```<code>Placement.FormField_FieldName
Placement.FormField_Instance
Placement.SearchText_Text
Placement.SearchText_Instance
Placement.PageCoordinates_PageNumber
Placement.XOffset
Placement.YOffset
</code>```

I find this to be a little confusing for the developer using the API because you could never use all of the properties together.

You would either use Form Field like this:

```<code>Placement myPlacement = new Placement();
myPlacement.FormField_FieldName = "MyPdfFormFieldName";
myPlacement.FormField_Instance = ;
myPlacement.XOffset = 0;
myPlacement.YOffset = 0;
</code>```

Or use Text Search like this:

```<code>Placement myPlacement = new Placement();
myPlacement.SearchText_Text = "My String Of Text";
myPlacement.FormField_Instance = 1;
myPlacement.XOffset = 0;
myPlacement.YOffset = 0;
</code>```

Or use Page Coordinates like this:

```<code>Placement myPlacement = new Placement();
myPlacement.PageCoordinates_PageNumber = 1;
myPlacement.XOffset = 0;
myPlacement.YOffset = 0;
</code>```

Is there a better way to setup the class (or sub classes) to make it easier for the developer to understand how to use this functionality?

答:
How about:

```<code>Placement myPlacement = new FormFieldPlacement("MyPdfFormFieldName", instance, 0, 0);
Placement myPlacement = new TextSearchPlacement("My String Of Text", instance, 0, 0);
Placement myPlacement = new CoordinatePlacement(instance, 0, 0);
</code>```

Make sure to have sane default arguments though, especially for the offsets.

Body:
How about:

Placement myPlacement = new FormFieldPlacement("MyPdfFormFieldName", instance, 0, 0);
Placement myPlacement = new TextSearchPlacement("My String Of Text", instance, 0, 0);
Placement myPlacement = new CoordinatePlacement(instance, 0, 0);

Make sure to have sane default arguments though, especially for the offsets.


问:
Is "White-Board-Coding" inappropriate during interviews?
This is a somewhat subjective quesiton but I'd love to hear feedback/opinions from either interviewers/interviewees on the topic.

We split our technical interview into 4 parts. Write Code, Read & Analyse Code, Design Session & Code on the white board.

For the last part what we ask interviewees to do is write a small code snippet (4-5 lines) on the whiteboard and explain as they go through it. Let me be clear the purpose is not to catch people out. We're not looking for perfect syntax. Hell it can even be pseudo-code. but the point is to give them a very simple problem and see if their brain can communicate the solution to us. By simple problems I mean "Reverse a string", "FizzBuzz" etc...

Note that we always ask for an explicit language first. We're a .NET C# house. we've only said "pseudo-code" where someone has been blanking/really struggling with the code.

My question is "Is it inappropriate / unreasonable to expect a programmer to write a code snippet on a whiteboard during an interview ?"

答:
Let me respond with another question:

Does writing code on a white board offer any real advantage in assessing programming ability, compared to typing and executing the code on a computer?

I think it's absolutely appropriate to ask a candidate to write code in an interview. However, to me, being able to execute the code is a critical part of the feedback loop that makes up programming. On a white board, you're tying one hand behind my back, and you're not getting the full picture of how I work through a problem.


问:
Why can't native machine code be easily decompiled?
With bytecode-based virtual machine languages like Java, VB.NET, C#, ActionScript 3.0, etc., you hear sometimes about how easy it is to just go download some decompiler off the Internet, run the bytecode through it one good time, and oftentimes, come up with something not too far from the original source code in a matter of seconds.  Supposedly this sort of language is particularly vulnerable to that.

I've recently started wondering why you don't hear more about this concerning native binary code, when you at least know which language it was written in originally (and thus, which language to try to decompile into).  For a long time, I figured it was just because native machine language is so much crazier and more complex than typical bytecode.

But what does bytecode look like?  It looks like this:

```<code>1000: 2A 40 F0 14
1001: 2A 50 F1 27
1002: 4F 00 F0 F1
1003: C9 00 00 F2
</code>```

And what does native machine code look like (in hex)?  It, of course, looks like this:

```<code>1000: 2A 40 F0 14
1001: 2A 50 F1 27
1002: 4F 00 F0 F1
1003: C9 00 00 F2
</code>```

And the instructions come from a somewhat similar frame of mind:

```<code>1000: mov EAX, 20
1001: mov EBX, loc1
1002: mul EAX, EBX
1003: push ECX
</code>```

So, given the language to try to decompile some native binary into, say C++, what's so hard about it?  The only two ideas that immediately come to mind are 1) it really is that much more intricate than bytecode, or 2) something about the fact that operating systems tend to paginate programs and scatter their pieces causes too many problems.  If one of those possibilities is correct, please explain.  But either way, why do you never hear of this basically?

NOTE

I'm about to accept one of the answers, but I want to kind of mention something first.  Almost everybody is referring back to the fact that different pieces of original source code might map to the same machine code; local variable names are lost, you don't know what type of loop was originally used, etc.

However examples like the two that were just mentioned are kind of trivial in my eyes.  Some of the answers though tend to state that the difference between machine code and the original source is drastically much more than something this trivial.

But for example, when it comes down to things like local variable names and loop types, bytecode loses this information as well (at least for ActionScript 3.0).  I've pulled that stuff back through a decompiler before, and I didn't really care whether a variable was called strMyLocalString:String or loc1.  I could still look in that small, local scope and see how it's being used without much trouble.  And a for loop is pretty much the same exact thing as a while loop, if you think about it.  Also even when I would run the source through irrFuscator (which, unlike secureSWF, doesn't do much more than just randomize member variable and function names), it still looked like you could just start isolating certain variables and functions in smaller classes, figure out how they're used, assign your own names to them, and work from there.

In order for this to be a big deal, the machine code would need to lose a lot more information than that, and some of the answers do go into this.

答:
The general principles here are many-to-one mappings and lack of canonical representatives.

For a simple example of many-to-one phenomenon you can think about what happens when you take a function with some local variables and compile it to machine code. All the information about the variables gets lost because they just become memory addresses. Something similar happens for loops. You can take a for or while loop and if they are structured just right then you might get identical machine code with jump instructions.

This also brings up lack of canonical representatives from the original source code for the machine code instructions. When you try to decompile loops how do you map the jump instructions back to looping constructs? Do you make them for loops or while loops.

The issue is further exasperated by the fact that modern compilers perform various forms of folding and inlining. So by the time you get to the machine code it's pretty much impossible to tell what high level constructs the low level machine code came from.


问:
Should I always start with UML as a good practice when designing classes?
I am in the middle of creating a Bundle for PHP application based on Symfony 2.

I want the bundle to be clear and good designed, so I constantly move and refactor code, rename methods, reorder classes, move them to other folders, add some factories and adapters, proxies, and follow other oop design concepts.

I'm thinking if I should design UML diagram first, then start to work with IDE.

What is the best practice for designing good architecture?

When I start with draw of UML class diagrams before, then after coding, even with empty methods and tests first, I stop following the diagram I drew before, because I found it not matching what I need.

Can you share good practices for designing architecture for a libraries? I'm not talking about model (if so I could follow DDD).

答:
In a question is something should always (or never) be done, the only reasonable answer is: No, there are always exceptions.

Whether it is a good idea to start with a design in UML depends on the scale of the design, the ramifications if you get it wrong and your own comfort level.

If you do decide to start with an UML design, there are still two ways to use UML:

As a specification language. In this case, the UML diagrams are a direct representation of your code and contain the same level of detail. Often, you can use RAD tooling to generate code from the UML diagrams.

As a communication tool. UML is a powerful tool for communicating designs to others (or your future self), but there are no requirements that the diagrams contain all the minutiae in detail. For effective communication, it is often even better not to show all the details and that includes even stuff like helper classes or relations that are irrelevant to the point you want to make with the diagram.

If you use UML in the second way, then it is very much to be expected that the resulting code only looks like the diagram in broad strokes if you look from a mile away. Closer inspection will show large differences, but that does not necessarily invalidate the diagram.


答:
Apologies -- I'm going to say "I" a lot because I can only speak from my experience. Take "I" as a qualifier rather than the opposite.

Whenever I'm on a team that's really having trouble getting our arms around a problem, I draw sequence diagrams (http://websequencediagrams.com ROCK -- is it OK to mention them?). That defines the service interactions or the class interactions.

Coincidentally, the service interactions will define directly the API calls to implement, if I'm showing interactions between services. Or methods to implement if it shows interactions between classes.

(A lot of the data requirements also come out of that, but I have to admit that for brevity's sake I'm pretty good about capturing methods but not so good at the parameters.)

10 years ago, I used a UML modelling tool that would generate Java from the class diagram, so I would, in fact, generate a UML diagram up front. Well, at least at the same time I was writing the classes.

Since then, I very rarely do any UML diagrams besides sequence diagrams. Sometimes a straightforward entity-relationship diagram is useful if, again, the model is getting confusing.

EDIT: Actually, I draw state diagrams a lot. So state diagrams and sequence diagrams can be really helpful. I used to draw UML activity diagrams, too, but the sequence diagrams just kind of won out. Still, that defines the high-water mark. No else on the team is doing that level of diagramming.

It can be helpful to go the other way: run a tool that generates a class diagram from the classes. Whenever I do that, I always find modelling errors to fix. But that's just me. ;)

EDIT EDIT: BTW whipping out a nice sequence diagram in an interview can have big wow value. Even with non-technical interviewers. Just sayin'

Title: Should I always start with UML as a good practice when designing classes?

Body:
I am in the middle of creating a Bundle for PHP application based on Symfony 2.

I want the bundle to be clear and good designed, so I constantly move and refactor code, rename methods, reorder classes, move them to other folders, add some factories and adapters, proxies, and follow other oop design concepts.

I'm thinking if I should design UML diagram first, then start to work with IDE.

What is the best practice for designing good architecture?

When I start with draw of UML class diagrams before, then after coding, even with empty methods and tests first, I stop following the diagram I drew before, because I found it not matching what I need.

Can you share good practices for designing architecture for a libraries? I'm not talking about model (if so I could follow DDD).


问:
Is there anyone who has used Python/Ruby and PHP for a long time and still prefer PHP?
I am usually fascinated by articles defending PHP and the arguments being used. Quite often authors of these types of articles don't mention what experience they have with other languages. Personally I find it hard to imagine that somebody would know either Python or Ruby, and PHP at a high level and still prefer PHP.

So if anyone fits this description, I would be interested in hearing why you prefer PHP to either of these languages.

答:
Yes, I flat out prefer the C-style syntax in PHP over Python or Ruby (perhaps over Ruby less so).  I could do without the sigils ($) for variables in PHP, though.

I've never had the problems with PHP that a lot of people seem to have.  If you develop your applications as applications, and not individual peieces that get inserted into web pages by intermingling HTML and PHP, PHP is not that much different from other langauges.  And the library support and available online resources are huge.  People moan about 'inconsistent' function parameters and such, but thats never been a huge hinderance to me.

PHP does give you a lot of rope to hang yourself, though, if you arent a disciplined programmer.  You can get yourself into a lot of trouble if you start using little PHP tricks all over the place (variable variables, using include() as function calls, etc).

ContentLicense: CC BY-SA 2.5


问:
Best practices in Application's flow diagram
I make web applications, mostly MVC, object oriented and database enabled. I always have trouble going back to project after a few months of release and work again. I don't even remember what I made on that project. How should I overcome this problem? I can't afford too much time consuming documentations and so many diagrams. Any quick way you guys practice to avoid this?</p>

答:
lol I'm repeating myself, but simple sequence diagrams (http://websequencediagrams.com) not only define the API methods from the service interactions, but is also a great way to get my head back into it coming back to it later.

Really simple, though. Just enough to understand the high points of client-server interaction.

Also, just a simple bullet point list, even in initial comments of:

client sends this

server sends that

is a simple way of capturing that. IMHO


问:
Multiple documentation issues in a single bug
It is clearly a bad practice to incorporate several issues in a single bug. It is not convenient, hard to maintain, difficult to keep track of what is done and what is not, etc.

But does all this concern bugs associated with documentation as well? By documentation, I mean only external documents (user guides, architecture overviews, etc.). I personally find it more convenient to create a single bug for multiple issues in the same document. It's easier to keep track of the updates in the document and review the document when the changes are done.

What are the cons of incorporating multiple issues of a document in a single bug?

答:
They're the same as conflating problems in code. The only difference is that one of them (changes in one place having unintended consequences in another) are slightly less like to occur in text than in code.

Most developers view computer code as an active, dynamic entity whose behaviour is not readily predicted and which you cannot understand properly without running it in the context of testing and production, and rightly so. But most developers also assume that text is a static, trivial thing which you can understand just by looking at it, and which you can therefore correct trivially without having the larger view. That is somewhat true, but even in text you need to preserve coherency (e.g. for ubiquitous language as defined by DDD), keep references intact, and be wary of unnoticed self-contradictions. Therefore documentation also profits from being changed in one way at a time, and with an understanding of the entire "code base".


问:
Can JavaScript be used as a general scripting language?
I've used JavaScript and some frameworks (jQuery, Prototype, some node.js) for client-side web programming, but never on the desktop, where I do most of my scripting work in either Python or Bash.

But IMHO, JavaScript would make a great scripting language if used outside of the browser. Has anyone tried this? Can JavaScript be an adequate replacement for Python/Perl/Bash for quick and dirty scripting tasks?

答:
Qt offers QtScript. Wikipedia said:

QtScript is a scripting engine that has been part of the Qt cross-platform application framework since version 4.3.0.

The scripting language is based on the ECMAScript standard with a few extensions, such as QObject-style signal and slot connections.[1] The library contains the engine, and a C++ API for evaluating QtScript code and exposing custom QObject-derived C++ classes to QtScript.

If you don't know what Qt is: It's a cross-platform application framework in C++. It is good in taking complexity out of C++ front-end development, and is also supported on mobile systems. It has been long ago since I last developed with Qt but I liked it.

With QtScript I could imagine that one writes a minimal GUI and does the application logic in JavaScript.


问:
How is same-origin policy implemented?
I was looking at cross-domain requests for a design and stumbled upon something that puzzles me. From a local site I'm firing an Ajax request to another domain (with jQuery and vanilla XMLHttpRequest). Sure, the request fails and I can only get a fail event, which seems perfectly normal du to same-origin policy. But I noticed in Fiddler that the request is actually made and succeeds! It's seems that it's just that I can't process the response.

Am I missing something, or is that a security hole? Sure, you can't access data, but what's the point of allowing sending data and just preventing response access?

答:
The browser is making a request just in case there's a CORS (Cross-Origin Resource Sharing) header there. Look closely at the http verb -- probably it's making an OPTIONS call to the remote server first.

If there is a CORS header, it's checking to see if the CORS header requires filtering out headers, or methods, or parts of the response.

If there's no CORS header, then it just throws the response on the floor and returns an incomprehensible error. Go browser!

The same-origin policy is a security feature strictly for the client side. Do search on CORS and you can get more information about what it entails.

BTW if you're implementing any authorization scheme at all, like OAuth, then the same-origin policy is pretty much redundant, and your service can safely use CORS to defeat it. Same if the service serves up "unprotected" or "public" information that you don't care if it gets out -- or you actively want it to be accessible.

Title: How is same-origin policy implemented?


问:
Django REST + Backbone/Ember/Angular Implementation Method
https://stackoverflow.com/questions/10941249/separate-rest-json-api-server-and-client

In light of this post, I wanted to ask questions regarding Django and specifically the implementation methods of getting one of these client side technologies to work with Django.

Currently, I have a backend that is setup that uses Django Rest Framework to serialize the data. My problem though, is I'm not sure how to get the client side to access the backend.

Django is a MVC framework. Originally I thought that I could just take out the View, and just implement the model and controller. Then, I would write complete separate View code so to speak using Backbone/Ember/Angularjs. Then the client would access the REST resources. How would I combine these two later if I wanted to deploy this to Heroku? Heroku only takes a whole Django application. How can I get the client code on there as well then?

The other option, which I've seen before, is to NOT take out the View completely, but to use Django templates WITH Backbone/Ember/Angularjs. Then, I can just simply put these js files in the "static" folder so to speak. But then that seems weird, because then I'd have a View on the server side (correct me if I'm wrong), that accesses my own REST resources. I tried this, but for some reason even though my page retrieves the javascript files, it does not seem to be working as expected.

答:
Quit thinking in terms of MVC. MVC alone only describes the interactions well if everything happens on the server-side. You need to think at a higher level of abstraction. For example, Data Layer (ex database), API layer (ex server-side), Client Layer (Webapp, IOS app, Android App).

A basic SPA works on the premise that the whole site runs on one big HTML file. Reloads don't require a round-trip to the server because you're basically showing/hiding different sections of code.

In practice that's not necessarily true because the framework (ex Angular) can pull template partials and data from URLs in the background. It sounds like you understand this much but can't figure out how concerns should be separated between server/client.

For templating, do it the same as you would in Django. Except, instead of loading the files from a local directory you fetch the partials from the server.

For generating views that include data you'll need to make a controller that can fetch the data and use it in the view partial. There are many ways to go about this but the most common is to simply create an API on the server-side that accepts data requests and responds with the results in JSON.

In MVC terms. The server and client will both still use models, views, and controllers:

On the server (ie the Data API). The models are the database/storage access classes. Instead of generating raw HTML the views will be used to format/serialize data for transfer. The controllers work out the messy details between the models and views.

On the client (ie the WebApp client). The models are the functions that handle fetching and deserializing data requests. The views are your html partials that get parsed into static HTML. The controllers /directives manage combining the two.

Can you still do HTML generation on the server-side?
  Of course. How much work you decide to do in the client vs server depends on your goals.

Then what's the benefit of client-side frameworks?
  If your goal is to create a SPA, then frameworks like Angular are a much more robust option than the alternitives which would consist of firing off a bunch of AJAX requests, then plugging it into the DOM using something like jQuery.

What's so special about client-side frameworks?
  Nothing really, they push the responsibility of HTML generation into the client. Instead of splitting HTML templating and dynamic manipulation between the client and server you can now do both in the client. It provides a cleaner separation of concerns and reduces load on the server.

If you need a data layer that can be accesses by multiple platforms (ex IOS, website, Android) then you've likely isolated the data requests into their own API already. If you have that done already, pushing the client-side code to the client makes sense since you're already doing that for the other platforms.

Simplifying the server to just a data layer makes life a simpler for those who develop on multiple platforms. Client-side frameworks made the process of fetching data and generating HTML dynamically on the client much easier. If your goal is to build a SPA, using a framework will provide a good scaffold to build on.

The major downside of client-side HTML generation is that it relies on JavaScript and most search engine webcrawlers are too dumb to use JavaScript. That means, if you have a content-heavy site you're going to have a bad time trying to get search engines to index your content. There are hybrid approaches to conditionally load content generated from the server to webcrawlers but they add another additional layer of complexity so the tradeoffs likely outweigh the benefits.


问:
Who should do code reviews?
In my company mostly the architect does code reviews. He is a very experienced and smart software guy, so he is very good at it. When developers do the code reviews they don't do it half as well. We tried giving developers to do more code reviews, but the quality of the code reviews wasn't good.  We use Scrum for as development methodology.

However with the current system there are two problems:

The architect becomes a bottleneck

Developers don't take the responsibility for the quality of the code and the architecture (which leads to all sorts of problems).

How can we address these issues?  Should we change who does the code reviews?

答:
I like the practice of occasional team code reviews that include the whole team the architects, but then lots and lots and lots of code reviews between two or three members of the team.

If it's really tricky or sensitive code, then enlist the architect or senior members of the team.

Honestly, though, it sounds kind of ridiculous having an architect do code reviews. He should be doing design reviews, or occasional code reviews informally to share his expertise. The engineering team should take responsibility for the code. If there are problems, then they will get better at it with time.

Title: Who should do code reviews?


问:
Why develop free, open source programs?
Why would someone use his own time to develop an open-source project for free and without compensation?</p>

答:
The outfit I work for, started with a public domain code (written by the business owner) [Open source was years from being invented]. His original business model was to be a consultant on using it (use is not straightforward, and many hundreds of people make a living consulting). Of course the demands for feature enhancements were so great it became a proprietary commercial code(s)*. But, still most of the salaries earned are in rapidly diminishing numbers up the scale: (1) Users doing their jobs, (2) Consultants to group (1), finally (3) Developers/testers etc.

I use the plural, because several other proprietary codes sprang from the same public domain source code release.

Title: Why develop free, open source programs?


答:
Cons appear when document changes are versioned (and when they aren't, anyone responsible for quality assurance will have tough time verifying whether issues are fixed or not) and when particular doc version integrates fixes for only part of the issues listed in the original bug.

Cases like this may become hard to track:

Issues listed in bug under 1 through 20 were resolved in version 25, but issues 15 and 17 reappeared again in version 27 and later, issues 40 through 50 were resolved in version 31, issues 70 through 80 were resolved in version 118 of the guide.

Worth noting that above doesn't mean that one necessarily has to open a dedicated bug for every single issue they discover. You're not alone finding it "more convenient to create a single bug for multiple issues in the same document" - in my experience it was typically the case in doc reviews: one studies the doc, lists the issues and puts them in a single bug for further tracking.

The way out that has been proven to work well to me is to allow for splitting the original list by extracting part of the issues into new, dedicated bugs as convenient, making it clear to the readers of the original bug where the "extracted" issues went.

Say, if one expects that next version doc is going to address 10 of 100 issues listed in original bug, then one can create a new bug that lists only these 10 issues and edit the original bug, informing readers that 10 issues are going to be addressed separately per new bug.

New bug clearly separates the issues to be checked and verified in a given release, while update made to original bug de-scopes these issues, leaving remaining 90 to deal with.

When 90 of 100 issues are expected to be addressed, approach is essentially the same, one "extracts" remaining 10 issues into a new, dedicated bug and proceeds with handling 90 issues that are relevant to coming doc version, using original bug to track the progress for these 90 issues and to inform reader that other issues are to be addressed per separate bug.

The way how list is split basically follows the way how issues are addressed in consequent doc versions; parts of the list that are expected to be handled in particular version are "extracted" to simplify tracking of how these are fixed.

Title: Multiple documentation issues in a single bug

Body:
It is clearly a bad practice to incorporate several issues in a single bug. It is not convenient, hard to maintain, difficult to keep track of what is done and what is not, etc.

But does all this concern bugs associated with documentation as well? By documentation, I mean only external documents (user guides, architecture overviews, etc.). I personally find it more convenient to create a single bug for multiple issues in the same document. It's easier to keep track of the updates in the document and review the document when the changes are done.

What are the cons of incorporating multiple issues of a document in a single bug?


问:
Using Scrum on small projects where Owner doesn't want to be involved
Recently I've been reading and learning quite a lot about scrum and I like it a lot. However, I do have a couple of likely scenarios in my head to which I don't know the solution. So let's say that I might want to organize an agile team of (for instance) four web developers (one of them UI/UX designer). This team would operate on scrum principles.

Initially we would probably be working on projects like landing pages for ordinary people's small businesses, like renting apartments, selling cookies... Such customers simply can't be set with Product Owner role (IMHO), because they usually expect to hire a company, give them the overall project goal with some details, and then expect the job to be done (including a lot of decision making) with as little of their involvement as possible (in their opinion, they have more important things to do). Let's say I'd like to engage myself in a developer/scrum master role (I know that even that is debatable, being a team member and scrum master at once), so I simply shouldn't take the role of the product owner as well.

So as for my questions: If I'm my company's business owner, do I simply need to be a product owner as well (do these roles include each other)? Can I employ a sales person which might have the product owner role? Would it be better if it is an experienced developer instead of a sales person? Is this even a smart move? Lastly, is there another agile approach that might better suit my position?

EDIT: Thank you everyone for good inputs. I added some comments, any aditional info will be greatly appreciated.

答:
I would say that your external client is a stakeholder and your product owner should come from within your own organization.

In my experience, business owner and product owner are rarely the same role. To check on the skills required of a Product Owner, as well as their responsibilities, look no further than the Scrum Guide.

Do choose your product owner with care. They will have a significant impact on how well you achieve the benefits of scrum.


问:
Usage of __ while declaring any variables or class member in python
Is it good practice to use __ convention while declaring the member variable?

This also imparts private kind of feature of that data member. There have been cases when I found that its good to have hidden members of a class. This is certainly exposes only that feature that will help the the object to behave in more protected manner.

答:
A lot of people erroneously use double underscores to simulate "private" members, because double underscores invokes code mangling and makes those members harder to reference outside the class. However, it does not actually make them inaccessible.

Most of the time, it mainly adds a road bump to unit testing.

Really the double underscore mangling mechanism is to hide those members from subclasses that you don't want clobbering the values inadvertently. Name mangling isn't intended to hide the member from other programmers; the mangling scheme is simple, and referencing the variables anyway is easy.

Single underscore is the common convention for internal members. That's saying, we're all adults here, and although you can see it, this variable is intended for internal use. If you reference it, there's no guarantee it will still be there in future versions.

The Pep8 doc talks about that, and says use of the double underscores for variables and functions should really be rare.

OwnerDisplayName: Bhupesh Pant


答:
The feature is specifically meant for preventing accidental clashes between a parent class member and subclasses.

The name is mangled by prepending it with the class name; the atribute __foo on a class Bar becomes _Bar__foo, and can still be accessed as such from outside.

This makes such attributes obscured at best, not private. The only real use-case for such attributes is for member attributes that are tied to the specific implementation of a parent class method that a subclass might accidentally overwrite with their own version.

Title: Usage of __ while declaring any variables or class member in python

Body:
Is it good practice to use __ convention while declaring the member variable?

This also imparts private kind of feature of that data member. There have been cases when I found that its good to have hidden members of a class. This is certainly exposes only that feature that will help the the object to behave in more protected manner.


问:
Methods to keep an external service up to date that polls your service periodically?
Sorry if the title is hard to understand, it is easier if I describe the scenario to get the question across.

I have a service that collects data, performs business logic and does all the normal stuff. I now have to perform an integration that will provide a set of data (for sage accounts) via an endpoint (http://example.net/import-feed).

This endpoint can be polled by the external service at any time to pull the latest changes.

When a piece of data is updated, say a payment or a date this needs to be added to the feed.

This payment or date could be changed multiple times before the service gets polled.

The question is what is the best methods to keep track of all or the last change (probably best) made to the record/row/data and pull all of these changes into the feed. The external service will then send notifications back to my service letting me know if adding that update was successful or not.

Currently the only method I can think of is track the last modified time and the last time it was imported, and a status saying if it needs to be imported/updated. These imports/updates would then be pulled from the feed.

I hope you understand the problem, I have had a hard time trying to find information on this type of integration. It may just be me not using the correct terms.

So, what are the methods for this?

答:
The method you've suggested using a last modified timestamp should work fine. If you need to store data specific to the external service, such as keeping track of whether the service has downloaded that information, then it might make sense to store this meta information in a separate table, eg:

sage_queue

id | table | table_id | modified_at

This way, when your sage endpoint is called, it should be a fairly straighforward procedure to run through this table and collect together all the associated data from your core tables.

When your sage endpoint receives confirmation that a certain entry has been processed, it could just be deleted from the table.

When a record gets updated in one of your core tables, then it gets entered as a reference into your sage_queue table (either triggered by an event-listener system, or by a periodic cron job). If a reference to that record already exists, then you could just update the modified_at field.


问:
Why are scientific programming languages so weird?
It seems to me that programming languages meant for use in science and engineering are consistently weird compared to general-purpose languages. Some examples off the top of my head:

In Matlab, each function has to be placed in a separate file

In R, <- is the assigment operator, as opposed to = in almost every other language

Matlab, R, Julia and others are all 1-indexed

Matlab uses % for comments, and not the standard # or //

Of course, these languages all have several design features that actually make them easier to use for scientific applications, such as more natural matrix notation. Still, they all inexplicably make all these bizarre choices which don't make anything easier and could easily have been avoided if the language designers had just chosen to do what 99% of other languages do. Is the reason vendor lock-in? A lack of contact with the wider software development community? Something else?

I read this thread and didn't find the explanations satisfactory. Just because R were designed as a scientific language doesn't mean it had to completely ignore conventions and use <- instead of =.

答:
Indexing from 1 is not weird, it is completely normal and expected except for programmers, because they've been conditioned to expect 0-based counting by C (which was conditioned from the properties of processor architecture).

Comments are denoted in many, many many different ways in different languages; there is no standard way, every language chooses a symbol or digraph that isn't already taken.

Assignment is likewise a strange and incomprehensible concept, except for programmers; most people couldn't care less whether it's = or := or <-, they struggle to understand the meaning (and for them, it is in fact better not to use =, because this emphasizes that assignment is not equality - the most common hurdle for non-programmers to understand code).

In short, programming languages intended for people other than professional programmers look different because the people who use them most want it that way.


答:
I guess it depends on your exposure to other languages. Off the top of my head:

C/C++ have separate source files (.c/.cpp & .h)

The -> characters are used in C# for lambda expressions

Old versions of VB used 1 as a default index (although this could be changed with Option Base)

Title: Why are scientific programming languages so weird?

Body:
It seems to me that programming languages meant for use in science and engineering are consistently weird compared to general-purpose languages. Some examples off the top of my head:

In Matlab, each function has to be placed in a separate file

In R, <- is the assigment operator, as opposed to = in almost every other language

Matlab, R, Julia and others are all 1-indexed

Matlab uses % for comments, and not the standard # or //

Of course, these languages all have several design features that actually make them easier to use for scientific applications, such as more natural matrix notation. Still, they all inexplicably make all these bizarre choices which don't make anything easier and could easily have been avoided if the language designers had just chosen to do what 99% of other languages do. Is the reason vendor lock-in? A lack of contact with the wider software development community? Something else?

I read this thread and didn't find the explanations satisfactory. Just because R were designed as a scientific language doesn't mean it had to completely ignore conventions and use <- instead of =.


答:
There are three problems:

You are unaware of certain traditions, and the good reasons for certain choices.

You put too much emphasis on syntax, too little on semantics.

Engineers and scientists have no experience in language design, leading to questionable syntax.

Now to your specific points:

I don't know Matlab, so I can't comment on the requirements of file organization. Note that Java wants you to use one file per public class.

In R, = can be used as an assignment operator as well. Note that it needs multiple assignment operators <- and <<- to deal with its concept of scoping (<<- assigns to a symbol in an outside scope instead of creating a new symbol inside a function). The arrows can be used in the other direction too, potentially making cleaner code: complex_calculation() -> x.

1-based indexing is the standard in mathematics, which is what Matlab's and R's users are more comfortable with than C. Julia follows Matlab in order to have a better learning curve.

% for comments is also used in TeX/LaTeX. The # is only a convention from Unix scripting languages, and their descendants.

You also ignore that “real” programming languages have many weird parts. Why doesn't Scheme use =? Instead:

```<code>(define foo 5)
</code>```

Why does C use * for dereferencing, when obviously a caret ^x is more common in other traditions?

Body:
There are three problems:

You are unaware of certain traditions, and the good reasons for certain choices.

You put too much emphasis on syntax, too little on semantics.

Engineers and scientists have no experience in language design, leading to questionable syntax.

Now to your specific points:

I don't know Matlab, so I can't comment on the requirements of file organization. Note that Java wants you to use one file per public class.

In R, = can be used as an assignment operator as well. Note that it needs multiple assignment operators <- and <<- to deal with its concept of scoping (<<- assigns to a symbol in an outside scope instead of creating a new symbol inside a function). The arrows can be used in the other direction too, potentially making cleaner code: complex_calculation() -> x.

1-based indexing is the standard in mathematics, which is what Matlab's and R's users are more comfortable with than C. Julia follows Matlab in order to have a better learning curve.

% for comments is also used in TeX/LaTeX. The # is only a convention from Unix scripting languages, and their descendants.

You also ignore that “real” programming languages have many weird parts. Why doesn't Scheme use =? Instead:

(define foo 5)

Why does C use * for dereferencing, when obviously a caret ^x is more common in other traditions?


答:
There are different conventions. Conventions in mathematics, logic, and applied sciences and conventions in IT. The first ones are far older.

The scientific languages are made to make the life of THEIR users more convenient. The user is seen as a scientist, who can realize some algorithm from time to time or to check some theory, without the need to learn something really new. So, the languages for scientists MUST be made up to non - IT standards. Because they are not meant for the use of IT people. They are up to OTHER standards and that is good because of the target auditory.  Because the good SW UI, and language is SW UI, must be done based on needs of user, not of the coder.

Our IT standards are industry standards. IT is industry. Science is not industry. Scientists are proud of it. And they would reluctantly take anything from our practice into theirs. And they don't like standards at all. And nobody likes foreign standards. So, if somebody will make a scientific language that will look up to IT standards, it would be hardly selling well, because of the dislike of the target auditory, even if it were objectively more convenient.

And even if we'll judge only according to IT standards... Sorry, what standards do you mean? Have you tried to write a prog in APL or SNOBOL?  These two language are, IMHO, the MOST powerful in appropriate fields (counting and strings). But the syntax is something VERY strange (and effective) Reading a line of APL code could take days. On the other hand, such line is a serious piece of SW. You'd return to Mathlab with tears of relief.

As for "=", many people have problems to be accustomed that it is not equality, but assignment. BTW, in Pascal it IS equality and assignment is ":=".

And you really think that == for equality is more natural? On the contrary, mixing = and == is the MOST common error in C programming, it happens very often even in contemporary IDEs, with their automatic control.

About indexing from 1 - it is the only natural one. When you were a child, you had learned poems and songs, where you counted: one, two, three... And not 0,1,2... In school math we studied that the counting starts from 1, and that 0 doesn't belong to natural/counting numbers. Only with the definition of functions non-natural indices come. After all, the 0 was invented many thousands of years after our ancestor raised a finger up.

0-start was more simple to realize and immediately got into IT practice after C appearance. But in Fortran, the first language, the 1-indexing is used. The same with other languages of the pre-industrial epoch.

And yes, I had read Dyjkstra's article on naturality of the 0-based counting. And totally disagree with his argumentation. It is natural for musicians ony.  And even 0 enthusiasts that create the C and Java compilers, count the lines of the code STARTING FROM 1!


答:
The loss of information as pointed out by the other answers is one point, but it is not the dealbreaker. After all, you don't expect the original program back, you just want any representation in a high-level language. If code is inlined, you can just let it be, or automatically factor out common computations. You can in principle undo many optimizations. But there are some operations that are in principle irreversible (without an infinite amount of computing at least).

For example, branches might become computed jumps. Code like this:

```<code>select (x) {
case 1:
    // foo
    break;
case 2:
    // bar
    break;
}
</code>```

might get compiled into (sorry that this is not real assembler):

```<code>0x1000:   jump to 0x1000 + 4*x
0x1004:   // foo
0x1008:   // bar
0x1012:   // qux
</code>```

Now, if you know that x can be 1 or 2, you can look at the jumps and reverse this easily. But what about address 0x1012? Should you create a case 3 for it, too? You'd have to trace the whole program in the worst case to figure out what values are allowed. Even worse, you might have to consider all possible user inputs! At the core of the problem is that you can't tell data and instructions apart.

That being said, I wouldn't be entirely pessimistic. As you might have noticed in the above 'assembler', if x comes from outside and is not guaranteed to be 1 or 2, you essentially have a bad bug that allows you to jump to anywhere. But if your program is free from this kind of bug, it is much easier to reason about. (It is no accident that "safe" intermediate languages like CLR IL or Java bytecode are much easier to decompile, even setting metadata aside.) So in practice, it should be possible to decompile certain, well-behaved programs. I'm thinking of individual, functional style routines, that have no side effects and well-defined inputs.  I think there are a couple of decompilers around that can give pseudocode for simple functions, but I don't have much experience with such tools.

Title: Why can't native machine code be easily decompiled?

Body:
With bytecode-based virtual machine languages like Java, VB.NET, C#, ActionScript 3.0, etc., you hear sometimes about how easy it is to just go download some decompiler off the Internet, run the bytecode through it one good time, and oftentimes, come up with something not too far from the original source code in a matter of seconds.  Supposedly this sort of language is particularly vulnerable to that.

I've recently started wondering why you don't hear more about this concerning native binary code, when you at least know which language it was written in originally (and thus, which language to try to decompile into).  For a long time, I figured it was just because native machine language is so much crazier and more complex than typical bytecode.

But what does bytecode look like?  It looks like this:

```<code>1000: 2A 40 F0 14
1001: 2A 50 F1 27
1002: 4F 00 F0 F1
1003: C9 00 00 F2
</code>```

And what does native machine code look like (in hex)?  It, of course, looks like this:

```<code>1000: 2A 40 F0 14
1001: 2A 50 F1 27
1002: 4F 00 F0 F1
1003: C9 00 00 F2
</code>```

And the instructions come from a somewhat similar frame of mind:

```<code>1000: mov EAX, 20
1001: mov EBX, loc1
1002: mul EAX, EBX
1003: push ECX
</code>```

So, given the language to try to decompile some native binary into, say C++, what's so hard about it?  The only two ideas that immediately come to mind are 1) it really is that much more intricate than bytecode, or 2) something about the fact that operating systems tend to paginate programs and scatter their pieces causes too many problems.  If one of those possibilities is correct, please explain.  But either way, why do you never hear of this basically?

NOTE

I'm about to accept one of the answers, but I want to kind of mention something first.  Almost everybody is referring back to the fact that different pieces of original source code might map to the same machine code; local variable names are lost, you don't know what type of loop was originally used, etc.

However examples like the two that were just mentioned are kind of trivial in my eyes.  Some of the answers though tend to state that the difference between machine code and the original source is drastically much more than something this trivial.

But for example, when it comes down to things like local variable names and loop types, bytecode loses this information as well (at least for ActionScript 3.0).  I've pulled that stuff back through a decompiler before, and I didn't really care whether a variable was called strMyLocalString:String or loc1.  I could still look in that small, local scope and see how it's being used without much trouble.  And a for loop is pretty much the same exact thing as a while loop, if you think about it.  Also even when I would run the source through irrFuscator (which, unlike secureSWF, doesn't do much more than just randomize member variable and function names), it still looked like you could just start isolating certain variables and functions in smaller classes, figure out how they're used, assign your own names to them, and work from there.

In order for this to be a big deal, the machine code would need to lose a lot more information than that, and some of the answers do go into this.

Body:
The loss of information as pointed out by the other answers is one point, but it is not the dealbreaker. After all, you don't expect the original program back, you just want any representation in a high-level language. If code is inlined, you can just let it be, or automatically factor out common computations. You can in principle undo many optimizations. But there are some operations that are in principle irreversible (without an infinite amount of computing at least).

For example, branches might become computed jumps. Code like this:

select (x) {
case 1:
    // foo
    break;
case 2:
    // bar
    break;
}

might get compiled into (sorry that this is not real assembler):

0x1000:   jump to 0x1000 + 4*x
0x1004:   // foo
0x1008:   // bar
0x1012:   // qux

Now, if you know that x can be 1 or 2, you can look at the jumps and reverse this easily. But what about address 0x1012? Should you create a case 3 for it, too? You'd have to trace the whole program in the worst case to figure out what values are allowed. Even worse, you might have to consider all possible user inputs! At the core of the problem is that you can't tell data and instructions apart.

That being said, I wouldn't be entirely pessimistic. As you might have noticed in the above 'assembler', if x comes from outside and is not guaranteed to be 1 or 2, you essentially have a bad bug that allows you to jump to anywhere. But if your program is free from this kind of bug, it is much easier to reason about. (It is no accident that "safe" intermediate languages like CLR IL or Java bytecode are much easier to decompile, even setting metadata aside.) So in practice, it should be possible to decompile certain, well-behaved programs. I'm thinking of individual, functional style routines, that have no side effects and well-defined inputs.  I think there are a couple of decompilers around that can give pseudocode for simple functions, but I don't have much experience with such tools.


问:
Use Of Exists clause in SQL
Just finished Stanford lecture on SQL (by Prof. Jennifer Widom). However I have developed a confusion regarding the use of EXISTS clause. I thought it is just like a condition and an expression so that if it's true, the above query proceeds (much like the Boolean AND). So having a slight doubt regarding this question:

Passenger = {pid, pname, Age}

  Reservation = {pid, class, tid}

and tables are populated with some data and following query is executed:

```<code>SELECT pid
FROM Reservation
WHERE class = 'AC' AND EXISTS
     (SELECT * FROM Passenger WHERE age > 65 AND Passenger.pid = Reservation.pid)
</code>```

Now the thing that is getting me troubled is that I thought that the use of EXISTS is simply that the above main query proceeds if the subquery returns something. So as the subquery was returning something, I expected the query to return all PID's where class = 'AC'. I didn't think that it was executed tuple by tuple. So how to remove this confusion?

答:
In this particular scenario, I would consider using a join on the Passenger table and a where clause to filter the results. Something like the below:

```<code>SELECT pid
FROM Reservation
INNER JOIN Passenger
  ON Passenger.pid = Reservation.pid
WHERE class = 'AC' and age > 65
</code>```

For me this is a clearer version and it is easier to understand what the query is actually doing.

The exists is operating on all rows in Reservation and checking whether they meet the exists query. For me this looks confusing and can be quicker to join directly on the table using the ids and filtering where necessary.

Title: Use Of Exists clause in SQL

Body:
In this particular scenario, I would consider using a join on the Passenger table and a where clause to filter the results. Something like the below:

SELECT pid
FROM Reservation
INNER JOIN Passenger
  ON Passenger.pid = Reservation.pid
WHERE class = 'AC' and age > 65

For me this is a clearer version and it is easier to understand what the query is actually doing.

The exists is operating on all rows in Reservation and checking whether they meet the exists query. For me this looks confusing and can be quicker to join directly on the table using the ids and filtering where necessary.


答:
It strikes me that you have a problem that might suit the Command Query Responsibility Segregation CQRS code pattern.

Essentially you wouldn't want to think about your code storing a single entry and constantly updating that entry, but rather, using a message queue to store all the add/edit statements so you could roll the data forward or backwards to any point in time.

Periodically (your polling/scheduling interval) you would simply pushing all data from the First in First Out queue and then just popping the oldest records off the queue.

I suspect you may need to manage the way you identify each entry from your system to SAGE Accounting API's using this approach, but I think this is a much safer approach as it provides an audit trail.

Title: Methods to keep an external service up to date that polls your service periodically?

Body:
Sorry if the title is hard to understand, it is easier if I describe the scenario to get the question across.

I have a service that collects data, performs business logic and does all the normal stuff. I now have to perform an integration that will provide a set of data (for sage accounts) via an endpoint (http://example.net/import-feed).

This endpoint can be polled by the external service at any time to pull the latest changes.

When a piece of data is updated, say a payment or a date this needs to be added to the feed.

This payment or date could be changed multiple times before the service gets polled.

The question is what is the best methods to keep track of all or the last change (probably best) made to the record/row/data and pull all of these changes into the feed. The external service will then send notifications back to my service letting me know if adding that update was successful or not.

Currently the only method I can think of is track the last modified time and the last time it was imported, and a status saying if it needs to be imported/updated. These imports/updates would then be pulled from the feed.

I hope you understand the problem, I have had a hard time trying to find information on this type of integration. It may just be me not using the correct terms.

So, what are the methods for this?


答:
Because it refers to an object in the outer query (Reservation), the subquery is a correlated subquery. As it says in that wikipedia article,

The subquery is evaluated once for each row processed by the outer query

If the subquery weren't correlated, your reasoning would be correct. For example, hypothetically,

```<code>SELECT pid
FROM Reservation
WHERE class = 'AC' AND EXISTS
     (SELECT * FROM Passenger WHERE age > 65)
</code>```

would, so long as there was at least one passenger over 65, return all Reservations with class='AC'.

Title: Use Of Exists clause in SQL

Body:
Just finished Stanford lecture on SQL (by Prof. Jennifer Widom). However I have developed a confusion regarding the use of EXISTS clause. I thought it is just like a condition and an expression so that if it's true, the above query proceeds (much like the Boolean AND). So having a slight doubt regarding this question:

Passenger = {pid, pname, Age}

  Reservation = {pid, class, tid}

and tables are populated with some data and following query is executed:

```<code>SELECT pid
FROM Reservation
WHERE class = 'AC' AND EXISTS
     (SELECT * FROM Passenger WHERE age > 65 AND Passenger.pid = Reservation.pid)
</code>```

Now the thing that is getting me troubled is that I thought that the use of EXISTS is simply that the above main query proceeds if the subquery returns something. So as the subquery was returning something, I expected the query to return all PID's where class = 'AC'. I didn't think that it was executed tuple by tuple. So how to remove this confusion?

Body:
Because it refers to an object in the outer query (Reservation), the subquery is a correlated subquery. As it says in that wikipedia article,

The subquery is evaluated once for each row processed by the outer query

If the subquery weren't correlated, your reasoning would be correct. For example, hypothetically,

SELECT pid
FROM Reservation
WHERE class = 'AC' AND EXISTS
     (SELECT * FROM Passenger WHERE age > 65)

would, so long as there was at least one passenger over 65, return all Reservations with class='AC'.


问:
In MV* pattern where does non-business model goes?
I am passing Menu items to View from ViewModel. My menu definition is a model with properties title, image, hasChildren and isEnabled. But this model is meant for UI unlike business domain models like Person, ContactDetail, Transaction, etc.

So, when i see this menu model sitting along with business domain models i felt like polluted. Is there a right place to put these kind of UI specific models?

Thanks.

答:
The MVC model is the model of the highest level. The UI, by itself can be considered as another SW, one abstraction level below. But it itself can have its own entities (the persistent UI configuration, set by user) and its model, mentioned by you.

Here we are coming to a contradiction, of course. Only the components of Controller layer should speak to each other, according to the model... But these control functions have nothing in common! But that is a contradiction only if we'll take the MVC conception literally. The pure three "layers" can serve only for the most primitive architectures, where there are only two poles - data and user, and we define layers along the tie between them. A real application has many such poles. And any tie between one pole and another one can and should be sliced into layers.

The definition of these poles is up to you, I don't know the complexity of your work, but as you obviously want the dynamic interface, there will be minimally tree poles - Business data, Interface data and user. There are two ties - User-BuD and User-InD. And you'll have two different controllers - for each of them. You can also have two interfaces - the normal interface and the inferface for interface settings. These latter two will have common elements. Funny enough, on this abstraction level the controllers won't cooperate with each other and interfaces - will do.

BTW, even this architecture is very simplified, for you need also the administration data? maybe license data? And you need to serve them, too.


问:
Feedback on a Kanban Board for Solution Architectects
Before I get started I need to issue a pre-emptive apology:

It is very likely that some of the terminology / vocabulary I use in this post is plain wrong there is also a good chance I have entirely misinterpreted some of the keys aspects.  I am new to this so don't be too critical, more than welcome constructive feedback ;)

Background

We are currently transitioning a development department of 200 people from multi-methodology into "Agile".  The whys, wherefores, pros and cons of this are well beyond the scope of this question.

This development department contains an Architecture Service team that is made up of 10 people that are officially known as "Solution Architects".  In reality they cover more than just the solution, these are technical people that cover every technical architectural aspect of a project (i.e. hardware, software, security, governance etc).  They also provide ad-hoc functions to the development team (code reviews, standards guidance etc) and wider business (technical input into tenders, pre contract technical preview of customer requirements)

As part of this transition I have been tasked with creating a Kanban board for the purposes of getting a view of the work activities that the Architecture Service team are accountable for.  There are a myriad example boards for development / coding teams, but none that I can find for Architecture.  So I have taken from various sources and created "something", I would really appreciate genuine feedback on it.

It is also worth noting that this will be presented to the team as a starting point / work in progress.  It is their board and I want them to own it, all I am doing is setting a foundation for the guys to build on (and change if necessary)

So far I have something like this

The Main Board

The main board is where we hold all active / backlog projects - all active work will be on this board.  This will be short reviewed in the daily architectural scrum with a more in-depth review at the end of every week.

```<code>           ------------------------------------------------------------------------
           | Evaluation            | Implementation       | Ad- Hoc               |
           | Todo  | Doing  | Done | Todo  | Doing | Done | Todo  | Doing  | Done |
    -------------------------------------------------------------------------------
    Person |       |        |      |       |       |      |       |        |      |
    --------       -----------------       ----------------       -----------------
    Person |       |        |      |       |       |      |       |        |      |
    --------       -----------------       ----------------       -----------------
    Person |       |        |      |       |       |      |       |        |      |
    --------       -----------------       ----------------       -----------------
    Person |       |        |      |       |       |      |       |        |      |
    -------------------------------------------------------------------------------
</code>```

The column descriptions / purposes are:

Evaluation: Projects where the person is doing an initial technical analysis, i.e. running through technical options with a product owner, determining the size of the project.  As an example an Evaluation project may be the Architect evaluating a new technology or working with a customer to produce a mutually agreed technical solution.

Implementation: Projects that are actively in development (coding, testing etc) and the person is acting in an SA function for the wider project team.  As an example this could be the development of coding aspects of the "mutually agreed technical solution" mentioned above, equally it could also be architecturally overseeing the implementation of some new hardware.

Ad-Hoc: All the weird and wonderful stuff that comes up that can't be put into the other two columns.  As an example in a strange recursive world there is a card for me in the ad-hoc column to create a KanBan board :).

Person: Fairly self explanatory, the person who "owns" the cards in that row. To make things a little more fun this actually contains an avatar of that persons choice.

Todo: Is effectively our backlog, the cards in here are ordered top to bottom in priority.  As space in a persons doing cell becomes available we take from the top of todo.

Doing: Fairly self explanatory

Done: Items that have been completed since the last full board review (Friday afternoon every week)

WIP Limits

Rather than do what we do now (i.e. give out work until somebody squeals), I would like the main board to work with objective / evidence based WIP limits.  The intention is to size each of the board cards with:

XS (Extra Small) : 3 points

S (Small) : 5 points

M (Medium) : 8 points

L (Large) : 13 points

XL (Extra Large) : 21 points

The size is very much from an Architects workload perspective, for example a project that requires 1 year of coding for 10 people but minimal Architectural input would be XS or S.  However a project that has massive Architectural input but minimal coding could be an XL.

Over time we should be able to work out the WIP limit for each person.  So we know that Jonny Smith can work with a velocity of 42 points and therefore allocate projects up to that level.

As we have not done this before my intention is to set the initial limit high, the idea being that when a person squeals we can (as a team) look at this objectively and determine if it is genuinely too much or is it because our processes etc are too onerous and should be streamlined.

NOTE: Of everything here these WIP calculations are the bit that "feel" the least right*

The Funnel Board

In order to keep track of all the random things that fly through the team we also have a funnel board.  This is a relatively simple board that looks like this:

```<code>    ------------------------------------------------------------------------
    | Evaluation            | Implementation       | Ad- Hoc               |
    ------------------------------------------------------------------------
    |                       |                      |                       |
    |                       |                      |                       |
    |                       |                      |                       |
    |                       |                      |                       |
    |                       |                      |                       |
    ------------------------------------------------------------------------
</code>```

As the team is made aware of a "project" but this is not yet officially sanctioned (i.e. can be put into the Todo columns on the Main Board) then it goes onto the funnel board.  Items here are not allocated to a person.  The idea being that we can track those random things that come through and ensure they are not forgotten.  Also, as the person completes an evaluation project this then moves from Main Board Evaluation Done to the Implementation funnel board (unless it immediately becomes an implementation project)

A member of the team will occasionally be tasked with following up everything on the funnel board, i.e. quick phone call to the product owner asking if this is still relevant (this would be an ad-hoc project on the main board)

The Successes Board

This is just a simple board to track what we have done over the last X months.  It holds the cards that have been through the Funnel and / or Main boards

```<code>    ------------------------------------------------------------------------
    | Successes                                                            |
    ------------------------------------------------------------------------
    |                                                                      |
    |                                                                      |
    |                                                                      |
    |                                                                      |
    |                                                                      |
    ------------------------------------------------------------------------
</code>```

The idea being that we can occasionally get around this board and give each other mutual pats on the back :)

Board Cards

The cards that are on the boards contain the following information:

```<code>    ------------------------------------------------------------------------
    | SIZE (XS,S,M,L,XL)          | OWNING TEAM MEMBER             |  RAG  |
    ------------------------------------------------------------------------
    |                                                                      |
    |                         PROJECT TITLE                                |
    |                                                                      |
    ------------------------------------------------------------------------
    |                                  |                                   |
    |        DEPENDENTS                |          DEPENDENCIES             |
    |                                  |                                   |
    ------------------------------------------------------------------------
    |                                                                      |
    |                         MISC INFORMATION                             |
    |                                                                      |
    ------------------------------------------------------------------------
    |                WIDER PROJECT TEAM (AS APPLICABLE)                    |
    | Other Architects, Project Manager, Principal Developer, Business     |
    | Analyst, Scrum Master                                                |
    ------------------------------------------------------------------------
</code>```

As you will notice the granularity of the card is at a fairly high "Project" level, I am not planning on doing a developer style board that is split into tasks (thoughts on this welcome).  Also worth mentioning that depending on where the card is not all sections will be applicable.  I am also planning on colour coding the cards, as a first stab I have:

Yellow : Anything that is customer contractual
Pink : Anything that is internal (i.e. not end user facing)
Green : Anything that is a company group project

The cards will be magnetic rather than post-it, I am hoping to find some that are like mini white boards as this will make life easier as things change

Other Stuff

If its not on a card on a board then as far as the team is concerned it doesn't exist

The boards themselves are Whiteboards with Wheels, we can take them wherever we want

We may consider going to a virtual whiteboard in the future (physical whiteboards are easier to change when we decide that the X column is best on the left of Y not the right)

Questions

After reading my newbie Kanban War and Peace what are your thoughts? (please go easy on me :))

答:
Interesting read, and mostly makes sense.

The one immediate thing I would comment on is that a Kanban board is meant to represent a flow of work, from left to right.  As I imagine that your work doesn't flow from Implementation to Ad-hoc, then this doesn't really work on your board.

A better (imo) option would be to have the horizontal lanes as Evaluation, Implementation and Ad-hoc, and then have the cards themselves contain the name(s) of the people on them.  This has the advantage of allowing more than one person to work on an activity (tho maybe you don't need this).

In addition, as the other poster says, you've not considered external dependencies.  It might worth having a 'Blocked' column to show work that is waiting for someone or something outside the team.

Hope this is useful


问:
Building a site with internalization support
When a user browses some page and then switches a language, then the following actions should occur:

If there's a translation for a page he's browsing now, then do redirect to that page.

If there's no translated version of that page, then do redirect to a home page.

So for example, a user browses /about-us page then he switched to German language, then he should be redirected to /uber-uns if a translation of /about-us in german exists.

Currently I have a structure like this,

```<code>CREATE TABLE `pages` (

  `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT
  `language` varchar(3),
  `urlSegment` varchar(250),
  `content` TEXT

) DEFAULT CHARSET=UTF8;
</code>```

What relationships/columns should be added to achieve that?

答:
I would try to explain whomever came up with the idea of localized URL slugs that it will be pretty difficult to maintain. As the site grows bigger and gets translated to more languages, you are likely to encounter words that are similar or even the same in different languages and then you'll have problems coming up with unique URLs, not to mention it will be difficult for the web master to find the translated page corresponding to some original. Because inevitably the webmaster will not understand all the languages.

So my recommendation is to use /en/about-us, /de/about-us, /fr/about-us, /zh_CN/about-us etc. That way you:

don't need any extra relations and

you can quickly see which page corresponds to which

On the other hand if you insist on the localized URLs, all you really need to add is a column enUrlSegment (properly indexed). Or numeric ID, which is a bit more efficient, but a bit more difficult to work with as you always need to select the English URL segment for any kind of administrative interface.

Even in that case I'd still recommend having /en/about-us, /de/uber-uns etc. to avoid any potential problems with same words in multiple languages.

Of course this is really the easy part, the support for multiple languages, or internationalization (i18n). The difficult part is keeping all the translations in sync, the localization (l10n). I can recommend splitting the pages up to paragraphs using html2po from Translate Toolkit and using one of the many tools available for the po format for the translation. This way when the copywriter modifies the master version, you just run the tooling, the translators will see exactly the paragraphs that changed and you'll run the tooling again and get translated versions exactly corresponding to the master version.


问:
Implementing bussiness logic with a large number of business rules and processes
We are currently working on a project that heavily relies on a database.
Among many tables the main focus is on table "data" which is linked to another table "data_type" as many-to-one, which is then linked to table "data_operation" as one-to-many.

The last table defines specific set of operations that has to be processed for each row in table "data" based on specific data type. The operation is processed against specific fields in table "data" and partially data from other tables, not mentioned in this example. The actual operation is mostly a complex calculation or specific formula. The result of a specific operation will be stored in yet another table.

So in general we have:

Projection for table "data" is approximately one million rows per year, while other tables should not change drastically on a yearly basis, but it will initially hold a few thousand rows, that is, each data type will define roughly 10-15 operations.

Each operation should be reversible (revert changes).

Processing speed is a very important factor.

The application will most likely process 2500 new table "data" rows per day.

My question is concerning the best approach to implement operations.
Do you think it is wiser to move business logic and rules to a database (procedures, triggers for each operation) or implement and process each operation in the application/business layer? What would be the ideal generic structure?

Also I am open for other approaches as well.

答:
The data table has a number of columns in it; one of the columns holds a type. A data_type table is keyed from the type and adds a name. An operation table is keyed by the name column of the data_type table and adds an action column.

1) I don't see the point of the data_type table. Mapping a type to a name doesn't really add value to this scenario. operation should be mapped directly to data.

2) The action column is the name of an operation to be carried out on every (new) row of data table that has the desired type. Is this simply a mapping exercise? Or do you frequently add new kinds of actions?

3) To what extent are operations reversible? Do you mean the entire collection of actions on a single data table row? Do you mean each individual action is reversible? Are you envisioning that transaction begin/commit would surround a set of actions on a single table? Or did you mean reversible on a larger scale, over minutes or days?

If your application layer is written in a modern object-oriented language, you have a Command Pattern. One facet of the command pattern is that you can add an Undo operation to the command.

Personal note: trying to make computations reversible when you have database triggers is an extremely hard thing to do. If you move consequences into the application layer, you will have some hope of being able to track the downstream activities of a data change and thus make the entire action or operation reversible.