答:
If this is what you want:

```<code>(Client A) ---> (Server) ---> (Client B)
</code>```

then the simplest solution is to split the problem in two parts, have the "Client A" send the file to the server, then have "Client B" grab the file once it's completely uploaded by "Client A". You can easily do that with HTTP, and if the clients use the typical asymmetric cheap broadband connections available at home, it would probably be just fine: 90% of the time is used by Client A to send the file to the server, then 10% is used by Client B to grab the file.

If the clients both have symmetric connections, then the same solution would probably still be just fine, since symmetric connections are mostly only seen with the better providers. Sending 3Mb would be so fast, it would not even matter if it's a two-stage job.

If you're ambitious and want "Client B" to start downloading as soon as the first byte hits the server, then you should still use HTTP, but use something on the server that allows you to "block" (ie: not a PHP script or similar). You'd still use HTTP because HTTP is almost universally available, no one blocks it, works through proxies. If you try implementing your own service based on TCP then you'll need to solve the exact same problem as you'll need to solve with HTTP, but on top of that you'll need to re-implement the "application" part of it (how dows client B tell the server what file to grab, etc). And on top of that you'll be dealing with all the proxies and blocked TCP ports yourself!

An other option for the ambitious scenario is to have the Server implement a VPN service (or an other kind of tunneled network), have both ends connect to the server then have Client A send straight to Client B.

Body:
If this is what you want:

(Client A) ---> (Server) ---> (Client B)

then the simplest solution is to split the problem in two parts, have the "Client A" send the file to the server, then have "Client B" grab the file once it's completely uploaded by "Client A". You can easily do that with HTTP, and if the clients use the typical asymmetric cheap broadband connections available at home, it would probably be just fine: 90% of the time is used by Client A to send the file to the server, then 10% is used by Client B to grab the file.

If the clients both have symmetric connections, then the same solution would probably still be just fine, since symmetric connections are mostly only seen with the better providers. Sending 3Mb would be so fast, it would not even matter if it's a two-stage job.

If you're ambitious and want "Client B" to start downloading as soon as the first byte hits the server, then you should still use HTTP, but use something on the server that allows you to "block" (ie: not a PHP script or similar). You'd still use HTTP because HTTP is almost universally available, no one blocks it, works through proxies. If you try implementing your own service based on TCP then you'll need to solve the exact same problem as you'll need to solve with HTTP, but on top of that you'll need to re-implement the "application" part of it (how dows client B tell the server what file to grab, etc). And on top of that you'll be dealing with all the proxies and blocked TCP ports yourself!

An other option for the ambitious scenario is to have the Server implement a VPN service (or an other kind of tunneled network), have both ends connect to the server then have Client A send straight to Client B.


问:
Does it make sense and is it to acceptable to say ".NET code"?
There is C# code, VB.NET code... Can I also say ".NET code" as an umbrella term that covers all the languages you can use with the .NET framework?

I've seen people using it as well as people saying it shouldn't be used...

答:
Common Language Infrastructure or CLI is  the executable code and runtime environment that form the core of the Microsoft .NET Framework and the free and open source implementations Mono

Common Language Runtime (CLR) is the virtual machine component of .NET

Common Intermediate Language (CIL, formerly MSIL) is the lowest-level human-readable programming language defined by the Common Language Infrastructure (CLI) specification and is used by .NET

ContentLicense: CC BY-SA 3.0


问:
CMS updates into subversion -> review process
We manage a range of client sites built in Wordpress and Joomla and these require regular updates to the core CMS and extensions. We keep these sites in subversion and place updates in subversion. We try to use a single revision for this.

We face some difficulties in making this process efficient, over time we would like to automate it, so we can offer the process on a fixed price basis

The process is currently as follows

make copy of whole folder

svn status |grep '^!' |sed 's/^!\s*/svn delete "/g' |sed 's/$/"/g' |sh

svn update

svn status |grep '^?' |sed 's/^?\s*/svn add "/g' |sed 's/$/"/g' |sh

svn ci -m "Commit message"

svn remove -m"temporarily remove" http://subversion.repository.com/svn/automatem/projects/client/trunk/project/foldername

Steps 5-6 are usually repeated multiple times.

What I'm looking for help with

we are using subversion version 1.6 and 1.7, because there are no .svn folders in 1.7 in subdirectories, I wonder if the process is much easier on 1.7?

we've added step 3 because it reduces the number of repeats in steps 5-6. However this was just trial and error and I can't quite get my head around why this is

As I understand it, the issue in step 5-6 is that when the an extension is updated, it may delete a whole folder and then re-insert that folder with changed files. In subversion 1.6, this would remove the .svn folder, which causes a 405 Access denied error (the folder gets added, but already exists in svn). What I would need is something that inserts all .svn folders back into my working copy if the folder already exists in svn. Is there a way to accomplish this?

Any other improvements of course appreciated.

答:
The problem you are facing is better solved using tools other than SubVersion. As a gross (mis)characterisation, SubVersion was developed around 10 years ago, with the main goal of being better than CVS because it managed directories as well as files. As a version control product its very capable, and one that I have used in the past on serious projects. However....

What you need is not version control, but change management. You need to manage the delta that a change creates in the software, but also where that change should be applied.

The free option, I'd use GIT, but if your company has the money, then Accurev is a better technical choice for this kind of problem.

With git, you would create a branch that just contains the base code for joomla, and then do each of your customer sites in seperate branches. When you are ready to pull in the current joomla version you would issue a git command such as 'git pull origin joomla' to pull in changes from branch 'joomla'  Whilst this would work, the weakness is that you would need to know that an update was in joomla, and that you need to remember to pull in the changes.

With Accurev, you would create a stream that contains the joomla code, and you would tag each release.  Then, in your projects stream heirachy, you would then cross link your joomla directory to the tagged revision level.

The advantages Accurev gives you over git is that you can explicitly change your cross link to any tagged version of joomla. Including rolling back a version. You have visibility of which version is currently being used, and you can easily find where each taged version is currently used. (e.g. look for the projects that are still using a old and vulnerable version of joomla).  The downside is the cost of the product, the learning curve for the developers to adjust to the new way of thinking (that some will just not get it), and that the developers will inevitably grumble about the Accurev GUI.


答:
Depends on the where the term is being used.  If its marketing blurb about your company product technology then i'd guess it would do, but on your CV, looking for a job its a bad choice.

Think about the recruitment process from the side of the recruiter. They have 50 CV's on their desk and need to shortlist 5 for interview. Assuming you have the legal right to work in the country where the job is based (yep, people apply for jobs they cannot legally do) and have not too many spelling mistakes then the focus goes onto your technical ability.

If you are wanting to join a team of C# developers, and have C# development experience then for heavens sake, say it clearly. If your experience is VB, say that clearly too. The recruiter is then able to make a decision on if they are willing to cross train you.

On the other side, If you just say '.NET' then you create uncertainty. Uncertainty is another way of saying 'risk'. For the person recruiting, they want to interview candidates that are likely to be recruitable for the job. Are there 5 other people out there that have shown clearly how they could have the skills to do the job? If so, you've just missed the cut for interview.

Title: Does it make sense and is it to acceptable to say ".NET code"?

Body:
There is C# code, VB.NET code... Can I also say ".NET code" as an umbrella term that covers all the languages you can use with the .NET framework?

I've seen people using it as well as people saying it shouldn't be used...


答:
Well I work with .Net for a living and we (as in the organisation) always refer to it as .Net, irrespective of whether the code is written in C#.Net, VB.Net or when writing web front ends aspx.Net

I would have thought this is fairly widespread ussage. Certainly people in other componies use the same language. My current job title is .Net Developer.

So, yes, we call it .Net programming as an umbrella term.


问:
How does a symbol table relate to a namespace?
The official tutorial uses the term symbol table in a few places where I would expect the term namespace.

1. Defining functions

The execution of a function introduces a new symbol table used for the
  local variables of the function. More precisely, all variable
  assignments in a function store the value in the local symbol table;
  whereas variable references first look in the local symbol table, then
  in the local symbol tables of enclosing functions, then in the global
  symbol table, and finally in the table of built-in names.

2. More on modules

Each module has its own private symbol table, which is used as the
  global symbol table by all functions defined in the module. Thus, the
  author of a module can use global variables in the module without
  worrying about accidental clashes with a user’s global variables.

I found Eli Bendersky's blog where he quotes the symtable module:

Symbol tables are generated by the compiler from AST just before
  bytecode is generated. The symbol table is responsible for calculating
  the scope of every identifier in the code.

So it seems like a symbol table precedes a namespace. Yet another quote, from the first source, leads me to believe they also exist at the same time.

The actual parameters (arguments) to a function call are introduced in
  the local symbol table of the called function when it is called; thus,
  arguments are passed using call by value (where the value is always an
  object reference, not the value of the object).1

Is a symbol table involved with the creation of a namespace? Does a symbol table "contain" a namespace or simply information that a namespace contains?
In short,
how does a symbol table relate to a namespace?

答: A symbol table is an implementation detail. Namespaces are implemented using symbol tables, but symbol tables are used for more than just namespaces. For example, functions have their own symbol table for local variables, but those variables do not exist in any namespace (that is, it is impossible to somehow access the local variables of a function using a fully-qualified name).</p>


问:
"Public APIs are forever: Only one chance to get it right"?
In an OS book I just read that, "Public APIs are forever: Only one chance to get it right". Is it true? Is it applicable only in APIs of Operating Systems or other APIs too? For example, will this be true for the APIs of Android Applications such as Tasker, Locale and Pushover?</p>

答: If you have the foresight to include a version number in the API itself. Either on the connection/initialisation call, or, somewhere near the beginning of the parameter list on each call, then your API can evolve and mutate over time without disrupting existing clients.</p>


问:
A multi tenant data architecture
We are at a planning & redesign stage of our loyalty card application. As it is understood it will be a multi-tenant application. And I need to take your thoughts.  Here are the some key points we should take in to account to redesign logical and physical data structure:

Campaigns: We may organize cross tenant campaigns like if you buy this from tenant A you may buy that from tenant B with 10% discount.

Tenant Hierarchy: From the security point of view branches of tenants can only see their transactions not the other branch or tenant.

Customization for tenants will be rare to be ignored: We consider customization will be on card holder data only (at least we will not have a  chance to make customizations per tenant base in next one or two years).

Card holder (not a tenant user, Also we may login for administrating and reporting all tenants) may login to system to see the transaction she made.

In general i agree with the idea of separating tenant dbs or sharding at some level. Since we have #1 criteria, it requires us to query all dbs to decide whether her transaction is shooted a campaign or not. It may be a huge performance problem. Or what do you think about sharding, does it really make performance issues? Also what would you prefer if you have to create OLAP system you have to query on multiple-sharded db for reporting and decision making purposes?

On the other hand with separating db, more active tenants will take more performance gain from system especially while taking reports. Because their transactional data will reside in their own db and one query will be executed. We may allocate more resources on system and quote meaningful price for their usage of application. Sharding will also be helpful if we consider to place this app on cloud because sqlServer azure has limit of 10gb per db.

One idea is separating dbs but maintaining a master db for cross decisions like campaigns etc (like the one mentioned here at edit part of the question). But all reports will be taken from the dbs they owned. A second idea is separation of much more active tenants and handling the others by tenantID approach in master db. Lastly we may consider nosql graph db to process transactions on campaign server.

We will also be using NHibernate for ORM tool. But sharding project left undone and we should take into account to implement one for us to implement seperate db approach using sharding or master db approach. What do you think about using nhibernate at transaction handling service? Will it be a performance penalty using NHibernate in a real time service that should perfom high speed response? If so what would you suggest?

EDIT

@rae1n To be more understandable on my certain needs :

1 -  According to key point i mentioned above what data architecture would you suggest ?

One db and TenantID per table, replicate the db when needed.

Using shards with master table.

Using mix of sharding and tenantID.

Your own suggestion.

2 - Is NHibernate suitable for you suggestion for #1 and how? Could you please suggest a sample app or link to a article ?

3 - Is NHibernate suitable for campaign assessment service. Please take into account that there may be very complex campaigns amoung 1 to n tenants and we should support these behaviours.

4- Would you suggest nosql graph db for campaign assessment and do you know a sample for that usage?

答:
First, I am going to suggest that you may want to post follow-up questions to dba.se.  Multi-tenant applications are tricky and different RDBMSs have different tools for solving some of the problems.  Without knowing exactly what your environment is, specific answers are often impossible.  So I am going to look at conceptual problems and sample answers here.

For customization of cardholder data, my recommendation generally is to store the extra fields in something like XML or JSON format because this gives you a basic framework for storage which is flexible and gives your application a way to handle the data without eav pains.  Some db's may even be able to index xpath search results against xml records.

Multi-tenant security is a very different matter and it is hard.  The traditional standby is to use a view which can be used to filter out rows only to those which are authorized.  Oracle has some ways to bolt these on to the table directly.  PostgreSQL has some ways to make sure that other functions applied don't leak information.

If this becomes large, some sort of division of storage is going to be needed. How this gets divided by partitioning tables will be something you will have to decide based on your observed workload.  If you are on Oracle thinking about being able to move to RAC as needed may be helpful, and if you are on PostgreSQL, Postgres-XC is the technology to keep in mind.  However your current requirements make a normal sharding scheme somewhat questionable and it isn't clear what your usage patterns are going to be.  How many cross-tenant cardholders are there likely to be?  How much tenant vs cardholder queries are there going to be?  These are the sorts of decisions which really should be made when they become problems and premature optimization here will make thins hard.

OwnerDisplayName: erman olca

Title: A multi tenant data architecture


问:
Barter vs. Cash for a Retailer's eCommerce Site
I am putting together a proposal for a local store with both a brick-n-mortar and web presence. It's an upscale shop that also happens to be one of my wife's favorites. I am considering offering the option of barter for part of the payment. I have two questions in this regard:

What would be a reasonable “exchange rate” for such a transaction? That is, in lieu of $1000 cash money, I should ask for about how much in store credit?

In your own experience, has using barter introduced any complications into the client relationship? Are there particular pitfalls to be concerned about?

答:
In my experience, it was worth it, but it depends on how you think about it.

I did some light web work for a friend of a friend who owned an electronics store. Instead of paying me the ~$200 cash I'd have charged, he got me a monitor. Like I said, I feel we both came out ahead, but it depends on how you break it down; I know that I'd have paid well over $200 for what I got out of the deal. On the other hand, he's getting supplier pricing so he probably paid a lot less than $200 for the same.

That's pretty much the only time I've gone in for a barter, and I don't regret it. I'm still using the monitor.

Not sure how the equation would have changed if he wanted to effectively pay me in gift cards. I certainly wouldn't have taken a 1:1 on dollars to store credit. Probably would have pushed into the 1:1.2 - 1:1.4 range. It still needs to be worth it for both parties.

ContentLicense: CC BY-SA 2.5


问:
Accessing the history of a `ref` in Clojure
The documentation for ref shows a :max-history option and states that "refs accumulate history dynamically as needed to deal with read demands."  I can see that there is history at the REPL, but I don't see how to find previous values of a ref:

```<code>user=> (def the-world (ref "hello" :min-history 10))
#'user/the-world
user=> (do
          (dosync (ref-set the-world "better"))
          @the-world)
"better"
user=> (let [exclamator (fn [x] (str x "!"))]
          (dosync
           (alter the-world exclamator)
           (alter the-world exclamator)
           (alter the-world exclamator))
          @the-world)
"better!!!"
user=> (ref-history-count the-world)
2
</code>```

Presumably the-world has had the values "hello", "better", and "better!!!".  How do I access that history?

If it is not possible to access that history, is there a datatype that keeps a history of its values that can be queried afterwards?  Or is that why the datomic database was created?

答:
I believe :min-history and :max-history only refer the history of a ref during a transaction.

However, here's a way to do it with an atom and a watcher:

```<code>user> (def the-world (ref "hello"))
#'user/the-world
user> (def history-of-the-world (atom [@the-world]))
#'user/history-of-the-world
user> history-of-the-world
#<Atom@6ef167bb: ["hello"]>
user> (add-watch the-world :historian
                 (fn [key world-ref old-state new-state]
                   (if (not= old-state new-state)
                     (swap! history-of-the-world conj new-state))))
#<Ref@47a2101a: "hello">
user> (do
        (dosync (ref-set the-world "better"))
        @the-world)
"better"
user> (let [exclamator (fn [x] (str x  "!"))]
        (dosync
          (alter the-world exclamator)
          (alter the-world exclamator)
          (alter the-world exclamator))
        @the-world)
"better!!!"
user> @history-of-the-world
["hello" "better" "better!!!"]
</code>```

Body:
I believe :min-history and :max-history only refer the history of a ref during a transaction.

However, here's a way to do it with an atom and a watcher:

user> (def the-world (ref "hello"))
#'user/the-world
user> (def history-of-the-world (atom [@the-world]))
#'user/history-of-the-world
user> history-of-the-world
#<Atom@6ef167bb: ["hello"]>
user> (add-watch the-world :historian
                 (fn [key world-ref old-state new-state]
                   (if (not= old-state new-state)
                     (swap! history-of-the-world conj new-state))))
#<Ref@47a2101a: "hello">
user> (do
        (dosync (ref-set the-world "better"))
        @the-world)
"better"
user> (let [exclamator (fn [x] (str x  "!"))]
        (dosync
          (alter the-world exclamator)
          (alter the-world exclamator)
          (alter the-world exclamator))
        @the-world)
"better!!!"
user> @history-of-the-world
["hello" "better" "better!!!"]


答:
The symbol table means the same thing as for any compiler, that is, a data structure containing identifiers of a source code.

Modules, classes and functions constitute blocks of code having their own symbol table, in Python.

The term namespace is used in place of symbol table in Python doc of class SymbolTable, an instance of which gives access to the symbol table of a block of code as built by the specific interpreter you are using.

Hence, namespace and symbol table, in Python, relate to the same thing. The former is the symbol table as exposed to the developer, and the latter is the symbol table itself.

See the parallel between those two quotes taken from the Python doc:

"The local namespace for a function is created when the function is called"

"The execution of a function introduces a new symbol table used for the local variables of the function"

Title: How does a symbol table relate to a namespace?

Body:
The official tutorial uses the term symbol table in a few places where I would expect the term namespace.

1. Defining functions

The execution of a function introduces a new symbol table used for the
  local variables of the function. More precisely, all variable
  assignments in a function store the value in the local symbol table;
  whereas variable references first look in the local symbol table, then
  in the local symbol tables of enclosing functions, then in the global
  symbol table, and finally in the table of built-in names.

2. More on modules

Each module has its own private symbol table, which is used as the
  global symbol table by all functions defined in the module. Thus, the
  author of a module can use global variables in the module without
  worrying about accidental clashes with a user’s global variables.

I found Eli Bendersky's blog where he quotes the symtable module:

Symbol tables are generated by the compiler from AST just before
  bytecode is generated. The symbol table is responsible for calculating
  the scope of every identifier in the code.

So it seems like a symbol table precedes a namespace. Yet another quote, from the first source, leads me to believe they also exist at the same time.

The actual parameters (arguments) to a function call are introduced in
  the local symbol table of the called function when it is called; thus,
  arguments are passed using call by value (where the value is always an
  object reference, not the value of the object).1

Is a symbol table involved with the creation of a namespace? Does a symbol table "contain" a namespace or simply information that a namespace contains?
In short,
how does a symbol table relate to a namespace?


问:
(Why) Should I learn a new programming language?
I'm quite proficient with Java, C/C++, JavaScript/jQuery and decently good at Objective-C. I'm quite productive with the languages and their corresponding frameworks too and do produce enterprise level systems (and also small scale ones) with sufficient ease all the while keeping code 'clean' and maintainable (yes, I can read my own code after six months :)

Unless mandated by the platform (iPhone, iPad, etc.) or by the client/implementation organization, just "why" should I learn a new programming language? Just for "fun"? And do what with that fun if I'm not going to do anything worthwhile with it?

A lot of my peers are ready to dive in to learn the "next new thing/language" and it's usually Python, Ruby or PHP (just naming a few popular ones). Now, just knowing the language by itself is futile IMHO. You also need to know the frameworks, learn their usage/APIs as well as 'good implementation practices', etc.

So from an 'economic' sense, is there any benefit in learning a new programming language? If the language is learned in a quick and dirty fashion, it'll probably also be used for quick and dirty prototyping/implementation - but I don't see THAT as a justifiable investment of time/effort.

So just WHY should I (or anyone for that matter) learn a new programming language other than "it's fun so let's try it out" - if the investment of time may not be worth it in the long run?

答:
Most or all of the answers above are related to the profession. Programming.
I want to remind that before we are programmers - we are human beings.

One good reason why not learning a new programming language, in your case, is to let your self rest or do other things beside programming.

From my experience, working in agriculture and working with wood, thought me a lot about programming - more then learning a new language.
i.e. To be a good programmer you should first be a good human being. If you don't have much experience in life, beside programming, your idea about programming might be totally wrong - even if you are an expert.

Many concepts in programming are coming directly from the daily life: simplicity, maintainable, practical, useful, fast - and sometimes slow, modularity, etc; are all concepts which are used by a carpenter, for example.

Believe it or not: personally I've learned much about programming concepts, by taking a long vacation for picking oranges. The main concept I've learned from it was - simplicity.
From working as a builder I've learned another concept: build the base as good as possible - if you want the walls to stand straight.

Finally, the answer for your question might be: take a vacation, join a taekwondo class, or take care of the garden - then your question may not bother you anymore.


问:
Should you version web applications?
I've recently had a discussion with a coworker about versioning web applications.

I don't think you need it at all, and if you just want a sanity check to confirm your latest release is live, I think a date (YYMMDD) is probably good enough.

Am I off base?  Am I missing the point?  Should I use web application version numbers

答:
Just to be clear, I'm assuming that you are talking about a user-visible version number of some sort, and not giving up on version control in development. (if you think you don't need version control in development, then you are wrong, you do need version control).

For a single-hosted project it's not strictly necessary, because if any questions arise you can always look at the host and confirm what's really running. It's kind of nice, though, because it might come in handy once or twice. It's really up to you as to whether you think it will be useful or not.

For a multi-hosted project, it's not really optional. Different hosts will eventually end up with different versions and you'll need to be able to tell them apart at the user end.

Title: Should you version web applications?


问:
How do I correctly include copyright statements for included libraries?
How do I correctly include copyright statements for included libraries?

I have a program that uses libraries which are licensed under the GPL and MIT (either jointly under both, just only MIT) licences.

How do I specify this at the top of a combined and minified file?

I have this currently:

```<code>My Program (GPL)
Copyright 2009-2013, Me

jQuery (GPL/MIT)
Copyright 2005, 2012 jQuery Foundation, Inc. and other contributors

Some other library (MIT)
Copyright 2013, Some other person

This file is part of My Program.

My Program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

My Program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with My Program.  If not, see <http://www.gnu.org/licenses/>.

...jQuery's code...
...my code...
...some other libraries code...
</code>```

答: You mention all the copyright holders, that's all that's needed. The overall code must be under GPL, so you don't even need to mention that parts were originally under MIT; only files that are completely MIT-licensed should retain MIT license header.</p>


问:
Should I try to persuade my manager that code tidying should take priority over meeting deadlines?
My manager has tight deadlines to meet.

The current project I am working on is currently on schedule, but I've noticed a couple of quite significant areas in the code that are really badly written. (Bits of code get called two or three times, when they only need to be called once.)

The problem is, as far as my manager is concerned, the program works. As he sees it, there's no point making lengthy changes to code that will make us miss the release date, for no tangible improvement that he can see. He keeps saying "That's not a priority. It's working fine as it is."

Should I keep trying to persuade him, or should I just do what he suggests and leave it?  Why or why not?  Note that how to persuade management has already been covered.

答:
he's the boss, it's his decision. And I agree with him. NEVER change code for the sake of changing it. If there is a valid reason for the change (say things perform below requirements as they are) things should change, but "I think it's not pretty enough" is not a valid reason.

Your religious zeal (and that's what it is at this stage, or appears to be) would cost money, introduce risk (every code change risks breaking the product, requiring more changes, more testing, more delays). That's never a good thing.

Instead make notes, and pick up those changes when and if the affected parts of the application need to change anyway.


答:
Many managers don't understand the concept of "technical debt" which is exactly what you are trying to stop from building up.

The manager is correct when taken in the context of just this section you would like to fix, but this really becomes an issue when many sections degrade over time, and other developers come in and build on top of it.

Then a bug is discovered in part of the code, but only gets fixed in one section, not in the copy and pasted sections.

While you have not went live yet, there are other things that you need to keep in mind that the manage is probably thinking about.

Maybe this code rework will mean that a large testing phase needs to be repeated. There is also the possibility that you will introduce bugs into a previously working feature.

Title: Should I try to persuade my manager that code tidying should take priority over meeting deadlines?

Body:
My manager has tight deadlines to meet.

The current project I am working on is currently on schedule, but I've noticed a couple of quite significant areas in the code that are really badly written. (Bits of code get called two or three times, when they only need to be called once.)

The problem is, as far as my manager is concerned, the program works. As he sees it, there's no point making lengthy changes to code that will make us miss the release date, for no tangible improvement that he can see. He keeps saying "That's not a priority. It's working fine as it is."

Should I keep trying to persuade him, or should I just do what he suggests and leave it?  Why or why not?  Note that how to persuade management has already been covered.


问:
Encountering the same issue in an application
I've often come across the situation when the same mistake is made in many places in an application. For example, in a web application when the user creates an item and clicks the Add button to save it. If they click the button several times, multiple items are added instead of one because UI wasn't blocked and backend check wasn't performed properly.

How to create bug tickets in such cases?  Here are the solutions I could think of:

create one single bug ticket and list where the situation occurs

for every case found create a separate ticket

when finding the bug tell the development to pay attention, wait till they are finished and test again

答:
In that case I would create one bug, and in it, list all the areas where the issue should be fixed.

With things like this it makes sense to group them together as one work package. The developer responsible can then fix them all relatively easily if it is one repeatable fix.


答:
Here's some points:

Every change causes more errors. Modifying complex code causes more errors than it can ever fix. Ideally you would write it once and never modify it. Adding new code is ok, but changing existing logic causes more errors. If the end result is a mess the first time you wrote it, think how bad it'll be if you modify it without remembering all the rules that gave you the original mess.

Complex code always looks bad. The code is complicated for a reason. It encodes the important business logic, and that is always complex. All complex code looks like a mess to people who do not know the rules the code follows. Once the rules are known, it's nice logical system that just works correctly. You'll forget the rules (or worst, someone else wrote the code and you never had the rules), and you'll start thinking the important business logic is a mess. Cleaning up such code is a big mistake.

Over time, business rules gets outdated. Now you have a huge mess, and half the rules encoded to your software are outdated. Is it already time to rewrite? Definitely NOT. Only way to get rid of business rules that are already encoded to software source code is by dumping the whole system. Otherwise you'll end up with cascade failures where one missing piece of software activates failures in unrelated code that has worked fine for last 10 years.

Maintainance is difficult activity. Maintaining the mess takes skill. You need to know to all the business rules collected in last 10 years to make any modifications. Forget one of them and your change is causing more damage than it is fixing. Good plan is to insert new logic, but never modify old logic. Refactoring or rewriting is wrong way to approach the problem. You need to start writing working code, and never never rely on chance to fix it later; the chance will never appear. Once it's encoded to code, it's like concrete; it's always there and breaking it is dangerous.


答:
This is subjective question, and here is my viewpoint.

YOU SHOULD try to persuade him. Fact that you wrote this question here answers that.
How hard you should try is different question..

Think about different parts of system:

How far into development of that module you are?

How likely is that same module will be significantly changed in future (spec. changes).

Is public interface of module changing?

Just ask yourself those questions and make your own pros/cons.

For example if module is almost finished and likely to be changed after release, I just leave refactoring for later. But if it is in early stage, and specifications are not likely to change, refactor ASAP. Because specs WILL change, and after not looking at messy code in two years you will have hard time implementing new spec. changes. It might be so bad that you decide to write module from scratch,and just use some parts of code from earlier version of module.

There are some trick that can convince manager to let you refactor.

Find a bug in existing code. You can spend time refactoring while fixing bug.


答:
A parent Task or Story to which separate bug logs are linked to.

So that responsibility could be shared in fixing various occurrences of the issue. Work load and effect on a project commitments can also be shown if more and more bugs are logged against the main log.

If the guilty pary is made the OWNER of the parent story (in Jira for example) then they could be notified of every bug added and they can then be fully aware of what broke where AND their progress in fixing the issues can be tracked.

Title: Encountering the same issue in an application

Body:
I've often come across the situation when the same mistake is made in many places in an application. For example, in a web application when the user creates an item and clicks the Add button to save it. If they click the button several times, multiple items are added instead of one because UI wasn't blocked and backend check wasn't performed properly.

How to create bug tickets in such cases?  Here are the solutions I could think of:

create one single bug ticket and list where the situation occurs

for every case found create a separate ticket

when finding the bug tell the development to pay attention, wait till they are finished and test again


问:
Naming guard clauses that throw exceptions
I have a function evaluate() that parses a String for some variables and replaces them with their corresponding value:

```<code>public String evaluate() {
    String result = templateText;
    for (Entry<String, String> entry : variables.entrySet()) {
        String regex = "\\$\\{" + entry.getKey() + "\\}";
        result = result.replaceAll(regex, entry.getValue());
    }
    if (result.matches(".*\\$\\{.+\\}.*")) {    //<--check if a variable wasn't replaced
        throw new MissingValueException();
    }
    return result;
}
</code>```

Since the evaluate() function now does 2 things, it first replaces the variables with the values AND check for any variables that weren't replaced, I thought about refactoring it to:

```<code>public String evaluate() {
    String result = templateText;
    for (Entry<String, String> entry : variables.entrySet()) {
        String regex = "\\$\\{" + entry.getKey() + "\\}";
        result = result.replaceAll(regex, entry.getValue());
    }
    checkForMissingValues(result);
}

private void checkForMissingValues(String result) {
    if (result.matches(".*\\$\\{.+\\}.*")) {
        throw new MissingValueException();
    }
}
</code>```

Now is this a good name for the function checkForMissingValues? I mean it does check for missing values, but it also throws an exception.

I thought about renaming it to throwExceptionIfMissingValueWasFound(), but this name tells HOW the function does it more than WHAT the function is doing.

Is there a standard for naming such functions that check for a condition then throw an exception?

答:
I usually use ensureThisOrThatAttribute, which, in combination with an explicit throws CustomMadeException declaration makes things clear enough.

However, more important than conforming to some alleged general standard is that you conform to your own code base's standard. If you don't have one yet, well, just pick a format now and stick with it.


问:
Terminology for class
I am integrating with a Financial Management System (FMS). I have a class that prepares a set of objects (each of these objects is called a TransactionEntity). These are then passed to the FMS.

I give particular importance to correct terminology. What should I name this class that prepares the transactions? I am thinking TransactionSomething. Example TransactionBuilder, TransactionFactory etc. But I don't think these names are correct.

For the record, I use .Net but I don't think the framework should have an impact on this.

答: If the objects being prepared are (each) named TransactionEntity, then I think TransactionEntityBuilder is a good name.

Title: Terminology for class


答:
I usually prefer a convention such as this:

```<code>static class Guard {
  public static void IsNotNull(value) {
    if(value == null) {
      throw new MyCustomGuardException();
    }
  }
}
</code>```

Later on when using it:

```<code>public function DoSomething(DateTime startedAt) {
  Guard.IsNotNull(startedAt);
}
</code>```

A more complete example of a fluent guard class can be found in the NetFX package here:

http://netfx.codeplex.com/SourceControl/changeset/view/89b72bee718c#Extensions/System/Guard/Source/content/netfx/System/Guard.cs

Title: Naming guard clauses that throw exceptions

Body:
I have a function evaluate() that parses a String for some variables and replaces them with their corresponding value:

```<code>public String evaluate() {
    String result = templateText;
    for (Entry<String, String> entry : variables.entrySet()) {
        String regex = "\\$\\{" + entry.getKey() + "\\}";
        result = result.replaceAll(regex, entry.getValue());
    }
    if (result.matches(".*\\$\\{.+\\}.*")) {    //<--check if a variable wasn't replaced
        throw new MissingValueException();
    }
    return result;
}
</code>```

Since the evaluate() function now does 2 things, it first replaces the variables with the values AND check for any variables that weren't replaced, I thought about refactoring it to:

```<code>public String evaluate() {
    String result = templateText;
    for (Entry<String, String> entry : variables.entrySet()) {
        String regex = "\\$\\{" + entry.getKey() + "\\}";
        result = result.replaceAll(regex, entry.getValue());
    }
    checkForMissingValues(result);
}

private void checkForMissingValues(String result) {
    if (result.matches(".*\\$\\{.+\\}.*")) {
        throw new MissingValueException();
    }
}
</code>```

Now is this a good name for the function checkForMissingValues? I mean it does check for missing values, but it also throws an exception.

I thought about renaming it to throwExceptionIfMissingValueWasFound(), but this name tells HOW the function does it more than WHAT the function is doing.

Is there a standard for naming such functions that check for a condition then throw an exception?

Body:
I usually prefer a convention such as this:

static class Guard {
  public static void IsNotNull(value) {
    if(value == null) {
      throw new MyCustomGuardException();
    }
  }
}

Later on when using it:

public function DoSomething(DateTime startedAt) {
  Guard.IsNotNull(startedAt);
}

A more complete example of a fluent guard class can be found in the NetFX package here:

http://netfx.codeplex.com/SourceControl/changeset/view/89b72bee718c#Extensions/System/Guard/Source/content/netfx/System/Guard.cs


答:
It's your job to point these things out, but still the manager's decision.

However, you should try to make changes to you development process to avoid these problems in the future.

Identify the repeated problems and train the all developers on a prefered method. Everyone isn't going to get this right the first time, so be prepared to catch them in a code review. This way, you can take the time to make the change before a manager knows the code is working well enough/goes on to further testing.

Start factoring #1 into your estimates. Your team will improve over time, but you better manage expectations upfront.

Hopefully your deadlines were established based on how long the develpers thought it would take to build and not some other arbitrary method. Some developers feel like they're the bearer of bad news if they make lengthy project estimates, so they avoid it by being overly optimistic.


问:
Is there a reason that tests aren't written inline with the code that they test?
I've been reading a bit about Literate Programming recently, and it got me thinking... Well-written tests, especially BDD-style specs can do a better job at explaining what code does than prose does, and have the big advantage of verifying their own accuracy.

I've never seen tests written inline with the code that they test. Is this just because languages don't tend to make it simple to separate application and test code when written in the same source file (and nobody's made it easy), or is there a more principled reason that people separate test code from application code?

答:
I can think of some:

Readability.  Interspersing "real" code and tests will make it harder to read the real code.

Code bloat.  Mixing "real" code and test code into the same files / classes / whatever is likely to result in larger compiled files, etc.  This is particularly important for languages with late binding.

You may not want your customers / clients to see your test code.  (I don't like this reason ... but if you are working on a closed source project, the test code is unlikely to help the customer anyway.)

Now there are possible workarounds for each of these issue.  But IMO, it is simpler not to go there in the first place.

It is worth observing that in the early days, Java programmers used to do this kind of thing; e.g. including a main(...) method in a class to facilitate testing.   This idea has almost completely disappeared.  It is industry practice to implement tests separately using a test framework of some kind.

It is also worth observing that Literate Programming (as conceived by Knuth) has never caught on in the software engineering industry.


答: If tests were inline, it would be necessary to remove the code you need for testing when you ship the product to your customer. So an extra place where you store your tests simply separates between the code you need and the code your customer needs.

Title: Is there a reason that tests aren't written inline with the code that they test?

Body:
I've been reading a bit about Literate Programming recently, and it got me thinking... Well-written tests, especially BDD-style specs can do a better job at explaining what code does than prose does, and have the big advantage of verifying their own accuracy.

I've never seen tests written inline with the code that they test. Is this just because languages don't tend to make it simple to separate application and test code when written in the same source file (and nobody's made it easy), or is there a more principled reason that people separate test code from application code?


问:
JavaEE server experience matters for a developer?
Lately I am seeing quite a few application development job ads asking for experience with this or that Java EE server. I can understand this if it is for a server administrator, however I find it stupid and ridiculous to ask for some one with a specific server implementation experience when the job is Java software development. The whole idea behind Java EE as I studied in my initial days was for development of standards and to deploy to any platform of choice that including servers, OS, etc.

My question is, are the various Java EE application container implementations so vastly different that they can be considered their own career path for development?  What kinds of features exist amongst Java application containers that require such specialized skill that I might not want to not consider applicants with otherwise impressive software development qualifications?

答:
I find it stupid and ridiculous to ask for some one with a specific server implementation experience.

Based on my limited experience, our development team is also responsible for the J2EE container. We make sure that the code and server together solve the problem we're working on. Who else would have such insight as to what tools or frameworks are needed for the code to run effectively? The sysadmin is then responsible for the machine itself and for making the J2EE container play nice with everything else (firewalls, etc.).

What kinds of features exist amongst Java application containers that require such specialized skill?

I think it comes down to frameworks here. A codebase built upon Struts and Hibernate need not care, really, which container it's running on.

In the end, experience in a specific J2EE container need not matter so long as the application or the frameworks it's built on handle the differences for you. Yet, even if this is true, experience with that container could still be seen as a plus.

(3+ years developing on JBoss)


问:
What is the relationship between a framework like RoR and a database?
I'm a front end developer...I've never done ANY backend, although I did take a course in databases once. (I have a comp sci degree; I'm a competent programmer, I just haven't done any backend web stuff before.)

So I'm trying to figure out how the framework relates to the database. Presumably they're set up separately, and the framework receives requests from the website and sends them to the database, then receives the response and handles it appropriately to deliver the content correctly? It's basically a complex intermediary for all the web-app logic? Am I far off?

Need a good explanation of this.

答:
The way frameworks function in relation to the user's request and the database is not very different from any tiny piece of code acting as an intermediary between the two. Any 'web-app logic' is situation between the two, be it a complex MVC/MVP framework or a 5 line PHP file. They function to determine the user's request, make a connection to the database and retrieve stuff, and present this to the user.

A framework subdvidides several steps that often occur in this intermediary step. As the name implies MVP has Models that structure the data retrieved from the database in a useful way, a View where the end-result is given to the user, and a Presenter which ties these two together and may perform some additional logic.


答:
Here are some additional reasons I can think of:

having tests in a separate library makes it easier to link only that library against your testing framework, and not your production code (this could be avoided by some preprocessor, but why to build such a thing when the easier solution is to write the tests in a separate place)

tests of a function, a class, a library are typically written from a "users" point of view (a user of that function/class/library). Such "using code" is typically written in a separate file or library, and a test may be clearer or "more realistic" if it mimics that situation.


答:
The only advantage I can think of for inline tests would be reducing the number of files to be written. With modern IDEs this really isn't that big a deal.

There are, however, a number of obvious drawbacks to inline testing:

It violates separation of concerns. This may be debatable, but to me testing functionality is a different responsibility than implementing it.

You'd either have to introduce new language features to distinguish between tests/implementation, or you'd risk blurring the line between the two.

Larger source files are harder to work with: harder to read, harder to understand, you're more likely to have to deal with source control conflicts.

I think it would make it harder to put your "tester" hat on, so to speak. If you're looking at the implementation details, you'll be more tempted to skip implementing certain tests.


问:
When would you need "hundreds of thousands" of threads?
Erlang, Go, and Rust all claim in one way or another that they support concurrent programming with cheap "threads"/coroutines.  The Go FAQ states:

It is practical to create hundreds of thousands of goroutines in the same address space.

The Rust Tutorial says:

Because tasks are significantly cheaper to create than traditional threads, Rust can create hundreds of thousands of concurrent tasks on a typical 32-bit system.

Erlang's documentation says:

The default initial heap size of 233 words is quite conservative in order to support Erlang systems with hundreds of thousands or even millions of processes.

My question: what sort of application requires so many concurrent threads of execution?  Only the busiest of web servers receive even thousands of simultaneous visitors.  Boss-worker/job-dispatching type applications I've written hit diminishing returns when the number of threads/processes is much greater than the number of physical cores.  I suppose it might make sense for numerical applications, but in reality most people delegates parallelism to third party libraries written in Fortran/C/C++, not these newer generation languages.

答:
In a language where you're not allowed to modify variables, the simple act of maintaining state requires a separate execution context (which most people would call a thread and Erlang calls a process).  Basically, everything is a worker.

Consider this Erlang function, which maintains a counter:

```<code>counter(Value) ->
    receive                               % Sit idle until a message is received
        increment -> counter(Value + 1);  % Restart with incremented value
        decrement -> counter(Value - 1);  % Restart with decremented value
        speak     ->
            io:fwrite("~B~n", [Value]),
            counter(Value);               % Restart with unaltered value
        _         -> counter(Value)       % Anything else?  Do nothing.
    end.
</code>```

In a conventional OO language like C++ or Java, you'd accomplish this by having a class with a private class member, public methods to get or change its state and an instantiated object for each counter.  Erlang replaces the notion of the instantiated object with a process, the notion of methods with messages and maintenance of state with tail calls that restart the function with whatever values make up the new state.  The hidden benefit in this model -- and most of Erlang's raison d'être --  is that the language automatically serializes access to the counter value through the use of a message queue, making concurrent code very easy to implement with a high degree of safety.

You're probably used to the idea that context switches are expensive, which is still true from the perspective of the host OS.  The Erlang runtime is itself a small operating system tuned so switching among its own processes is quick and efficient, all while keeping the number of context switches the OS does down to a minimum.  For this reason, having many thousands of processes isn't an issue and is encouraged.

Body:
In a language where you're not allowed to modify variables, the simple act of maintaining state requires a separate execution context (which most people would call a thread and Erlang calls a process).  Basically, everything is a worker.

Consider this Erlang function, which maintains a counter:

counter(Value) ->
    receive                               % Sit idle until a message is received
        increment -> counter(Value + 1);  % Restart with incremented value
        decrement -> counter(Value - 1);  % Restart with decremented value
        speak     ->
            io:fwrite("~B~n", [Value]),
            counter(Value);               % Restart with unaltered value
        _         -> counter(Value)       % Anything else?  Do nothing.
    end.

In a conventional OO language like C++ or Java, you'd accomplish this by having a class with a private class member, public methods to get or change its state and an instantiated object for each counter.  Erlang replaces the notion of the instantiated object with a process, the notion of methods with messages and maintenance of state with tail calls that restart the function with whatever values make up the new state.  The hidden benefit in this model -- and most of Erlang's raison d'être --  is that the language automatically serializes access to the counter value through the use of a message queue, making concurrent code very easy to implement with a high degree of safety.

You're probably used to the idea that context switches are expensive, which is still true from the perspective of the host OS.  The Erlang runtime is itself a small operating system tuned so switching among its own processes is quick and efficient, all while keeping the number of context switches the OS does down to a minimum.  For this reason, having many thousands of processes isn't an issue and is encouraged.


答:
Problems in code can create impractical timelines for maintenance in the future, especially if the problems aren't properly documented with comments in the code.

Most managers have enough of a technical understanding to allow them to perform their job, but they won't know how to code, nor with they understand how problems can impact timelines in the future.

I would approach your manager in writing and outline to them what can (and likely will) happen down the road by allowing the issues to remain untouched and unresolved. This can include timelines that will be affected when modifying it in the future for updates, poor performance of the application (resulting in poor user satisfaction), etc. When they understand the impact of the problems and make their decision, accept it and move on. At this point you will have done your job as a credible and reliable programmer (with written proof that you have), and now the ball is in their court for taking responsibility for any problems associated with the issue that you have outlined.


答:
This is where I feel the Sun enterprise vision for Java failed.  The idea is that application servers only vary by implementation and any Java app can be dropped into any container and "just work".

If you read their literature from the early days, they also had specific roles called out, like developers who just wrote beans, assemblers who just took beans and assembled them into ejb jar's and setup deployment descriptors, and of course, system admins who manage the application server itself, which as previously stated, is completely decoupled from the apps within it.

In reality, it never works out that way.  There always needs to be something different about the app to deploy it into another container.

Examples:

Database connection pooling - every app server is different.  Some web apps even do it themselves.

Caching - JBoss in particular has classes within its packages that facilitate cluster-wide cache invalidations.  Can't just drop your code into Jetty anymore.

Testing - if ops wants to upgrade Tomcat, what needs to be tested?  Is it safe?  Only engineering can tell and QA can verify.

Configuration management - because container configuration is not part of the Java EE spec, configuration files are always container-specific.  It's very common for application installers to configure the container for you, by either checking configuration files into source control or writing scripts to update the container's config files.

Class paths - where do all of your JAR's go?  I know they say to put everything into WEB-INF/lib and WEB-INF/classes.  Hah.  What about JDBC driver?  Oh yea, that goes under $TOMCAT_HOME/lib.  Or $JBOSS_HOME/server/servername/deploy/lib or something like that.  Then you upgrade JBoss and now it's $JBOSS_HOME/standalone/lib.  Don't expect ops to upgrade that without dev.  And don't get me started on log4j classpath issues.

Containers often have prebuilt ways to solve problems for you, but you sacrifice portability.  For example, I often see HTTP compression handled at the container or web server level  If, as a developer, you want to enable this, would you setup a servlet filter within your web app for it, or "flip the switch" on your container and/or web server?

My list could go on and on.

Title: JavaEE server experience matters for a developer?

Body:
Lately I am seeing quite a few application development job ads asking for experience with this or that Java EE server. I can understand this if it is for a server administrator, however I find it stupid and ridiculous to ask for some one with a specific server implementation experience when the job is Java software development. The whole idea behind Java EE as I studied in my initial days was for development of standards and to deploy to any platform of choice that including servers, OS, etc.

My question is, are the various Java EE application container implementations so vastly different that they can be considered their own career path for development?  What kinds of features exist amongst Java application containers that require such specialized skill that I might not want to not consider applicants with otherwise impressive software development qualifications?


答:
Recommendation is to create a single bug record.  Within the bug, you have 2 choices;

You can note only the specific occurrences found and/or have random checks of several areas to determine scope of the issue.

List all of the areas of the application that have similar behavior and note if they have been tested for the bug.  Dev can start on the first areas found, while QA continues testing additional areas of the application.  Just be sure they communicate and coordinate on any additional areas found.

The general rule of thumb is, if the bug is most likely to be due to the same cause and require the same fix, then create a single bug.  If while diagnosing or fixing the issue, the developer or tester finds different causes/fixes, then the developer or tester is responsible for splitting the bug.

Note that part of your process should also be to identify these types of issues and have periodic meetings with the development team on the top issues.  As a team you will then need to decide on training, more thorough unit testing or some other requirement in order to effectively address the issue cause.


问:
How do remote interfaces work with JavaEE and glassfish?
I would like to know what is going on "under the hood" if I use remote interfaces in JavaEE. In the project I use a stateless enterprise bean that implements a remote interface. And I can call methods in this remote interface from a client (it all runs on the same glassfish server but it should work from a different machine as well).

The remote interface is within a Java Class Library, the enterprise bean and the client both include this library, but only in the bean it gets implemented.

I am quite new to JavaEE and glassfish. I know there is a container that manages the beans and a lot of stuff which makes everything super easy, but I don´t know yet what happens behind the scenes. Could you give me a brief description of what happens on a remote call? I think it has to do something with JNDI. And if I would start my client on a completely different machine, how would JNDI find my bean on the other machine?? (Since I use netbeans with glassfish I didn´t have to configure anything in glassfish)

Thanks!

EDIT: I use dependency injection, so everything I need to access the bean is the annotation @EJB (this works because of the class library)

答: RMI is the standard for distributed object computing in Java. An EJB with a remote interface is an RMI object. RMI enables an application to obtain references to other objects located elsewhere in the network, and to invoke method on that object as though it where co-located with the client on the same JVM locally in client's virtual machine. On the server side bytecode (stub) is generated for remote classes on the fly and these dynamically generated classes are bound to JNDI. On the client side a proxy is also generated for the remote interfaces. Calls to the proxies are routed to the stub. Naming service resolution still need to be configured on your remote client</p>


问:
iOS App Signing and Certificates
In order to sign an application for the Apple App Store, we need to create a certificate by saving a certificate request file from keychain and then upload it to the Apple store.

I was wondering, what does this certificate request file contain?

Does the certificate contain any information (like a finger print) about the OS or hardware?

答:
No, there's no personal information or information about your hardware configuration stored within the CSR (certificate signing request).  The CSR is part of an asymmetric encryption key, ie. it is the public portion of a public and private key.

Essentially, both keys are just a bunch of random* numbers that enable Public key encryption.

Have a look at this SO question for additional details.

* No, the numbers aren't truly 'random' but it's a good enough description for this question.

Title: iOS App Signing and Certificates


答:
A certificate signing request contains information about the distinguished name of the individual who generated it along with the public key.

The standard form of the request that on sees is a Base64 encoded request that contains the above mentioned distinguished name, the public key and the method that was used to generate the public key.

The RSA public (and private) key does not contain any information about your hardware.

Title: iOS App Signing and Certificates

Body:
In order to sign an application for the Apple App Store, we need to create a certificate by saving a certificate request file from keychain and then upload it to the Apple store.

I was wondering, what does this certificate request file contain?

Does the certificate contain any information (like a finger print) about the OS or hardware?


答:
My manager has tight deadlines to meet.

Most do.

The current project I am working on is currently on schedule

Good. Keep it that way!

I've noticed a couple of quite significant areas in the code that are really badly written. (Bits of code get called two or three times, when they only need to be called once.)

If that's not a major correctness or performance problem then it doesn't sound that bad. Calling the same code twice unnecessarily is often better than calling it once and caching the result. I've seen lots of bugs due to faulty caching logic. But let's take your word for it that this is bad code.

The problem is, as far as my manager is concerned, the program works. As he sees it, there's no point making lengthy changes to code that will make us miss the release date, for no tangible improvement that he can see. He keeps saying "That's not a priority. It's working fine as it is."

Your manager is correct. You're in the business of delivering value to stakeholders, not in the code prettification business. If you can't make an argument that making the code prettier delivers more value to stakeholders than hitting the release date then don't make the argument.

Should I keep trying to persuade him?

No.

Should I just do what he suggests and leave it?

No.

You should rather attempt to convince your management to schedule a "code quality milestone" after the deadline has been met. When your deadlines have been met and you're planning the next version the first thing you should do is schedule a post-release analysis that goes over in detail what went well and what went poorly. That includes analyzing risks to future success, risks such as poor quality code that was checked in with known problems in order to meet a deadline. Use the time put aside for the "quality milestone" to mitigate those risks. It will help if you can arrive in that meeting with an accurate list of problems you'd like to address.

The argument to make there is that by doing so, you help ensure that your manager will continue to meet deadlines in the future.


答:
No, you shouldn't. Deadlines are more important than tidying code, because you probably have no idea why the deadline was set in the first place. Maybe you have to finish before your competitor, who would steal your customers. Or some laws are coming into force. Or it's just getting too expensive for your starving CIO. Or...

If you think releasing it would be a great risk, then explain it to your manager. Valid reasons are: customer data could be lost, the company's reputation will suffer or something else what would have a negative impact on the company. But your manager has to ponder risks and opportunities, and he has to decide if it's worth to move the deadline.

But ask your manager to schedule some extra ressources next time, so that the software won't become a big, unmaintainable monolith. Then your manager can keep his deadline and you will have enough time to create a fine piece of software.

Whatever you do, please don't give managers a reason to think of programmers as people in ivory-towers who don't know anything about business.

Update because I read that it is a newly-written application:

Your first priority should be to do a root cause analysis to find out why that bad code was written in the first place. Did requirements change? Is one of the programmers not skilled enough? Does the deadline provoke a send-and-forget attitude?


问:
A Web application as a REST API client: how to handle resource identifiers
Several concepts related to REST conflict in my head when I try implementing it.

I have a REST-ful back-end API system that holds the business logic, and a web application that provides the UI. From various resources about REST (particularly, REST in Practice: Hypermedia and Systems Architecture) I know that I should not expose raw identifiers of my entities, but rather return hyperlinks with rel="self".

Consider the example. The REST api has a resource that returns a person:

```<code><Person>
  <Links>
    <Link rel="self" href="http://my.rest.api/api/person/1234"/>
  </Links>
  <Pets>
    <Link rel="pet" href="http://my.rest.api/api/pet/678"/>
  </Pets>
</Person>
</code>```

The problem arises with the web application. Let's assume it returns a page that contains a hyperlink to browsers:

```<code><body class="person">
  <p>
    href="http://my.web.app/pet/???????" />
  </p>
</body>
</code>```

What should I put into the href attribute? How do I keep the API entity URL in the web application to be able to get the entity when a user opens the target page?

The requirements seem conflicting:

The hyperlink href should lead to the web application because it is the system hosting the UI

The href should have some id of the entity because the web app must be able to address the entity when the target page opens

The web app should not parse/construct REST URLs beacuse it's not REST-ful, The mentioned book says

URIs should be opaque to consumers. Only the issuer of the URI knows how to interpret it and map it to a resource.

So, I cannot just take 1234 from the API response URL because as a RESTful client I should treat it as if it was something like http://my.rest.api/api/AGRIDd~ryPQZ^$RjEL0j. On the other hand, I must give some URL that leads to my web app and is enough for the app to somehow restore the API's original URL and use that URL to access the API resources.

The simplest way is probably just using the API URLs of resources as their string identifiers. But web page urls like http://my.web.app/person/http%3A%2F%2Fmy.rest.api%2Fapi%2Fperson%2F1234 are ugly.

It all seems quite easy for a desktop app or a single-page javascript app. Since they live continuously, they can just keep the URLs in memory together with the service objects for the application lifetime and use them when necessary.

With a web app I can imagine several approaches, but all seem weird:

Replace the host in the API URLs and keep the result only. The huge downside is that it requires the web application to handle whatever URL the API generates, meaning monstrous coupling. Moreover, it's not RESTful again, because my web app starts interpreting the URLs.

Expose the raw ids in the REST API together with the links, use them to build Web App's URLs, and then use the ids on the web app server to find the required resources in the API. This is better, but will affect the web app server performance because the web app will have to go through the REST service navigation issuing a chain of get-by-id requests of some form to handle any request from a browser. For a somewhat nested resource this might be costly.

Store all self URLs returned by the api in a persistent (DB?) mapping on the web app server. Generate some ids for them, use the ids to build the web app page URLs and to get the URLs of the REST service resources. I.e. I keep the http://my.rest.api/pet/678 URL somewhere with a new key, say 3, and generate the web page URL as http://my.web.app/pet/3. This looks like a HTTP Cache implementation of some sort. I don't know why, but it seems weird to me.

Or Does it all mean that RESTful APIs cannot serve as backends for web applications?

答:
Preface

This answer specifically addresses the question of how to manage your own URL scheme including unique bookmarkable URLs for resources for which the back-end REST API doesn't explicitly expose an identifier, and without interpreting the URLs provided by the API.

Discoverability requires a certain amount of knowledge, so here's my take on a real-world scenario:

Let's say we want a search page at http://my.web.app/person where the results include a link to the details page for each person. The one thing our front-end code must know in order to do anything at all is the base URL for its REST data source: http://my.rest.api/api. The response to a GET request to this URL might be:

```<code><Links>
    <Link ref="self" href="http://my.rest.api/api" />
    <Link rel="person" href="http://my.rest.api/api/person" />
    <Link rel="pet" href="http://my.rest.api/api/pet" />
</Links>
</code>```

Since our intent is to display a list of people, we next send a GET request to the href from the person link href, which might return:

```<code><Links>
    <Link ref="self" href="http://my.rest.api/api/person" />
    <Link rel="search" href="http://my.rest.api/api/person/search" />
</Links>
</code>```

We want to display search results, so we'll use the search service by sending a GET request to the search link href, which might return:

```<code><Persons>
    <Person>
        <Links>
            <Link rel="self" href="http://my.rest.api/api/person/1"/>
        </Links>
        <Pets>
            <Link rel="pet" href="http://my.rest.api/api/pet/10"/>
        </Pets>
    </Person>
    <Person>
        <Links>
            <Link rel="self" href="http://my.rest.api/api/person/2"/>
        </Links>
        <Pets>
            <Link rel="pet" href="http://my.rest.api/api/pet/20"/>
        </Pets>
    </Person>
</Persons>
</code>```

We finally have our results, but how do we build our front-end URLs?

Let's strip off the part that we know for certain: the API base URL, and use the rest as our front-end identifier:

known API base: http://my.rest.api/api

given URL for individual entity: http://my.rest.api/api/person/1

unique id: /person/1

our base URL: http://my.web.app

our generated front-end URL: http://my.web.app/person/1

Our results might look like:

```<code><ul>
    <li><a href="http://my.web.app/person/1">A person</a></li>
    <li><a href="http://my.web.app/person/2">A person</a></li>
</ul>
</code>```

Once a user follows that front-end link to the details page, to what URL do we send the GET request for details of that specific person? We know our method for mapping back-end URLs into front-end URLs, so we just reverse it:

front-end URL: http://my.web.app/person/1

our base URL: http://my.web.app

unique id: /person/1

known API base: http://my.rest.api/api

generated API URL: http://my.rest.api/api/person/1

If the REST API changes such that a person URL is now http://my.rest.api/api/different-person-base/person/1 and someone had previously bookmarked http://my.web.app/person/1, the REST API should (at least for a time) provide backward-compatibility by responding to the old URL with a redirect to the new. All generated front-end links would include the new structure automatically.

As you probably noticed, there are several things we have to know in order to navigate the API:

the API base URL

the person relation

the search relation

I don't think there's anything wrong with this; we're not assuming a specific URL structure at any point, so the structure of the entity URL http://my.rest.api/api/person/1 could change, and as long as the API provides backward-compatibility, our code will still work.

You asked how our routing logic could tell the difference between two front-end URLs:

http://my.rest.api/api/person/1

http://my.rest.api/api/pet/3.

First I'll point out that you used the API base in your comment when in our example we're using separate base URLs for the UI and REST API. I'm going to continue the example using separate bases, but sharing a base isn't a problem. We can (or should be able to) map UI routing methods using the media type from the request's Accept header.

As for routing to a specific detail page, we can't differentiate those two URLs if we're strict about avoiding any knowledge about the structure of the self URL provided by the API (i.e. the opaque string id). To make this work, let's include another of our known pieces of info - the entity type that we're working with - in our front-end URLs.

Previously our front-end URLs were in the format: ${UI base}/${opaque string id}

The new format could be: ${UI base}/${entity type}/${opaque string id}

So using the /person/1 example, we'd end up with http://my.web.app/person/person/1.

With this format, our UI routing logic would be working with /person/person/1, and knowing that the first token in the string was inserted by ourselves, we can pull it out and route to the appropriate (person, in this example) detail page based on it. If you feel sheepish about that URL, so we could insert a little more in there; maybe:
    http://my.web.app/person/detail/person/1

In which case we'd parse out the /person/detail for routing and use the rest as the opaque string id.

I think this introduces extremely tight coupling of the web app to the
  api.

I'm guessing you mean that, since our generated front-end URL contains part of the API URL, if the API URL structure changes without supporting the old structure, we'll need a code change in order to translate the bookmarked URL into the new version of the API URL. In other words, if the REST API changes a resource's ID (the opaque string), then we can't talk to the server about that resource using the old ID. I don't think we can avoid a code change in that situation.

What if I wanted the URL structure for the web app to differ from that
  of the api?

You can use any URL structure you want. At the end of the day, a bookmarkable URL for a specific resource must include something that you can use to get an API URL that uniquely identifies that resource. If you generate your own identifier and cache it with the API URL as in your approach #3, that will work until someone tries to use that bookmarked URL after that entry is cleared from the cache.

What if my web app's entities did not map to the api entities 1-1?

The answer depends on the relationship. Either way, you would need a way to map front-end to API URLs.

Body:
Several concepts related to REST conflict in my head when I try implementing it.

I have a REST-ful back-end API system that holds the business logic, and a web application that provides the UI. From various resources about REST (particularly, REST in Practice: Hypermedia and Systems Architecture) I know that I should not expose raw identifiers of my entities, but rather return hyperlinks with rel="self".

Consider the example. The REST api has a resource that returns a person:

```<code><Person>
  <Links>
    <Link rel="self" href="http://my.rest.api/api/person/1234"/>
  </Links>
  <Pets>
    <Link rel="pet" href="http://my.rest.api/api/pet/678"/>
  </Pets>
</Person>
</code>```

The problem arises with the web application. Let's assume it returns a page that contains a hyperlink to browsers:

```<code><body class="person">
  <p>
    <a href="http://my.web.app/pet/???????" />
  </p>
</body>
</code>```

What should I put into the href attribute? How do I keep the API entity URL in the web application to be able to get the entity when a user opens the target page?

The requirements seem conflicting:

The hyperlink href should lead to the web application because it is the system hosting the UI

The href should have some id of the entity because the web app must be able to address the entity when the target page opens

The web app should not parse/construct REST URLs beacuse it's not REST-ful, The mentioned book says

URIs should be opaque to consumers. Only the issuer of the URI knows how to interpret it and map it to a resource.

So, I cannot just take 1234 from the API response URL because as a RESTful client I should treat it as if it was something like http://my.rest.api/api/AGRIDd~ryPQZ^$RjEL0j. On the other hand, I must give some URL that leads to my web app and is enough for the app to somehow restore the API's original URL and use that URL to access the API resources.

The simplest way is probably just using the API URLs of resources as their string identifiers. But web page urls like http://my.web.app/person/http%3A%2F%2Fmy.rest.api%2Fapi%2Fperson%2F1234 are ugly.

It all seems quite easy for a desktop app or a single-page javascript app. Since they live continuously, they can just keep the URLs in memory together with the service objects for the application lifetime and use them when necessary.

With a web app I can imagine several approaches, but all seem weird:

Replace the host in the API URLs and keep the result only. The huge downside is that it requires the web application to handle whatever URL the API generates, meaning monstrous coupling. Moreover, it's not RESTful again, because my web app starts interpreting the URLs.

Expose the raw ids in the REST API together with the links, use them to build Web App's URLs, and then use the ids on the web app server to find the required resources in the API. This is better, but will affect the web app server performance because the web app will have to go through the REST service navigation issuing a chain of get-by-id requests of some form to handle any request from a browser. For a somewhat nested resource this might be costly.

Store all self URLs returned by the api in a persistent (DB?) mapping on the web app server. Generate some ids for them, use the ids to build the web app page URLs and to get the URLs of the REST service resources. I.e. I keep the http://my.rest.api/pet/678 URL somewhere with a new key, say 3, and generate the web page URL as http://my.web.app/pet/3. This looks like a HTTP Cache implementation of some sort. I don't know why, but it seems weird to me.

Or Does it all mean that RESTful APIs cannot serve as backends for web applications?

Body:
Preface

This answer specifically addresses the question of how to manage your own URL scheme including unique bookmarkable URLs for resources for which the back-end REST API doesn't explicitly expose an identifier, and without interpreting the URLs provided by the API.

Discoverability requires a certain amount of knowledge, so here's my take on a real-world scenario:

Let's say we want a search page at http://my.web.app/person where the results include a link to the details page for each person. The one thing our front-end code must know in order to do anything at all is the base URL for its REST data source: http://my.rest.api/api. The response to a GET request to this URL might be:

<Links>
    <Link ref="self" href="http://my.rest.api/api" />
    <Link rel="person" href="http://my.rest.api/api/person" />
    <Link rel="pet" href="http://my.rest.api/api/pet" />
</Links>

Since our intent is to display a list of people, we next send a GET request to the href from the person link href, which might return:

<Links>
    <Link ref="self" href="http://my.rest.api/api/person" />
    <Link rel="search" href="http://my.rest.api/api/person/search" />
</Links>

We want to display search results, so we'll use the search service by sending a GET request to the search link href, which might return:

<Persons>
    <Person>
        <Links>
            <Link rel="self" href="http://my.rest.api/api/person/1"/>
        </Links>
        <Pets>
            <Link rel="pet" href="http://my.rest.api/api/pet/10"/>
        </Pets>
    </Person>
    <Person>
        <Links>
            <Link rel="self" href="http://my.rest.api/api/person/2"/>
        </Links>
        <Pets>
            <Link rel="pet" href="http://my.rest.api/api/pet/20"/>
        </Pets>
    </Person>
</Persons>

We finally have our results, but how do we build our front-end URLs?

Let's strip off the part that we know for certain: the API base URL, and use the rest as our front-end identifier:

known API base: http://my.rest.api/api

given URL for individual entity: http://my.rest.api/api/person/1

unique id: /person/1

our base URL: http://my.web.app

our generated front-end URL: http://my.web.app/person/1

Our results might look like:

<ul>
    <li><a href="http://my.web.app/person/1">A person</a></li>
    <li><a href="http://my.web.app/person/2">A person</a></li>
</ul>

Once a user follows that front-end link to the details page, to what URL do we send the GET request for details of that specific person? We know our method for mapping back-end URLs into front-end URLs, so we just reverse it:

front-end URL: http://my.web.app/person/1

our base URL: http://my.web.app

unique id: /person/1

known API base: http://my.rest.api/api

generated API URL: http://my.rest.api/api/person/1

If the REST API changes such that a person URL is now http://my.rest.api/api/different-person-base/person/1 and someone had previously bookmarked http://my.web.app/person/1, the REST API should (at least for a time) provide backward-compatibility by responding to the old URL with a redirect to the new. All generated front-end links would include the new structure automatically.

As you probably noticed, there are several things we have to know in order to navigate the API:

the API base URL

the person relation

the search relation

I don't think there's anything wrong with this; we're not assuming a specific URL structure at any point, so the structure of the entity URL http://my.rest.api/api/person/1 could change, and as long as the API provides backward-compatibility, our code will still work.

You asked how our routing logic could tell the difference between two front-end URLs:

http://my.rest.api/api/person/1

http://my.rest.api/api/pet/3.

First I'll point out that you used the API base in your comment when in our example we're using separate base URLs for the UI and REST API. I'm going to continue the example using separate bases, but sharing a base isn't a problem. We can (or should be able to) map UI routing methods using the media type from the request's Accept header.

As for routing to a specific detail page, we can't differentiate those two URLs if we're strict about avoiding any knowledge about the structure of the self URL provided by the API (i.e. the opaque string id). To make this work, let's include another of our known pieces of info - the entity type that we're working with - in our front-end URLs.

Previously our front-end URLs were in the format: ${UI base}/${opaque string id}

The new format could be: ${UI base}/${entity type}/${opaque string id}

So using the /person/1 example, we'd end up with http://my.web.app/person/person/1.

With this format, our UI routing logic would be working with /person/person/1, and knowing that the first token in the string was inserted by ourselves, we can pull it out and route to the appropriate (person, in this example) detail page based on it. If you feel sheepish about that URL, so we could insert a little more in there; maybe:
    http://my.web.app/person/detail/person/1

In which case we'd parse out the /person/detail for routing and use the rest as the opaque string id.

I think this introduces extremely tight coupling of the web app to the
  api.

I'm guessing you mean that, since our generated front-end URL contains part of the API URL, if the API URL structure changes without supporting the old structure, we'll need a code change in order to translate the bookmarked URL into the new version of the API URL. In other words, if the REST API changes a resource's ID (the opaque string), then we can't talk to the server about that resource using the old ID. I don't think we can avoid a code change in that situation.

What if I wanted the URL structure for the web app to differ from that
  of the api?

You can use any URL structure you want. At the end of the day, a bookmarkable URL for a specific resource must include something that you can use to get an API URL that uniquely identifies that resource. If you generate your own identifier and cache it with the API URL as in your approach #3, that will work until someone tries to use that bookmarked URL after that entry is cleared from the cache.

What if my web app's entities did not map to the api entities 1-1?

The answer depends on the relationship. Either way, you would need a way to map front-end to API URLs.


问:
Name convention for Reader and Writer
I'm trying to name a component that will be capable of both reading from an InputStream (file or otherwise), and writing to an OutputStream; thus serving both as a Reader and as Writer.

So far the best I've come up with is:

ReaderWriter

IOStreamManager

StreamManager

Any good ideas?

答: I would suggest StreamIO. I don't like the word "Manager" for class or component names, it is too much of a loaded word.</p>

Title: Name convention for Reader and Writer


问:
Ideal programming language learning sequence?
What do you think? What is the ideal programming language learning sequence which will cover most of the heavily used languages and paradigms today as well as help to grasp common programming basics, ideas and practices?
You can even suggest learning sequence for paradigms rather than languages.

N.B. : This is port of the question I asked in stackoverflow and was closed for being subjective and argumentative.

答:
You need fundamentals:

Machine code

Assembly language

C

Lisp

After that it probably doesn't matter.


答: Convenience.  Back when I started doing multi-threaded programming, I was doing a lot of simulation and game development on the side for fun.  I found it to be of great convenience to just spin off a thread for every single object and let it do it's own thing rather than process each one through a loop.  If your code isn't disturbed by non-deterministic behaviour and you don't have collisions, it can make coding easier.  With the power available to us now, if I were to get back into that, I can easily imagine spinning off a couple thousand threads due to having enough processing power and memory to handle that many discrete objects!</p>

Title: When would you need "hundreds of thousands" of threads?

Body:
Erlang, Go, and Rust all claim in one way or another that they support concurrent programming with cheap "threads"/coroutines.  The Go FAQ states:

It is practical to create hundreds of thousands of goroutines in the same address space.

The Rust Tutorial says:

Because tasks are significantly cheaper to create than traditional threads, Rust can create hundreds of thousands of concurrent tasks on a typical 32-bit system.

Erlang's documentation says:

The default initial heap size of 233 words is quite conservative in order to support Erlang systems with hundreds of thousands or even millions of processes.

My question: what sort of application requires so many concurrent threads of execution?  Only the busiest of web servers receive even thousands of simultaneous visitors.  Boss-worker/job-dispatching type applications I've written hit diminishing returns when the number of threads/processes is much greater than the number of physical cores.  I suppose it might make sense for numerical applications, but in reality most people delegates parallelism to third party libraries written in Fortran/C/C++, not these newer generation languages.


问:
WYSIWYG Editor - Inline Comments
I am working on a user driven cms site.  Think of it like stack overflow.  The users can write posts, and publish them to the web.  I am using a WSGI editor to generate the content.

One of the features I am implementing is the ability for users to comment on particular section of a user post. I am trying to think of a clean way to implement this feature.

My current plan is to customize the WYSIWYG editor to generate a unique id per
 and then store the comments separately, and when the page loads also read the comments and do some jquery magic. All users that are going to be generating content will be admin users, so I am not afraid of someone messing around with ids.

This is one approach I have found, but I was hoping to either get some feedback or alternative ways to accomplish what I need.  Another thing I am trying to figure out is how I can handle a user editing a post that has been commented on...

答:
Don't let the browser do anything that has some relevance to the database (like generating IDs). Very bad idea. People will use this to send trash data just to see what happens.

Let it send the text, then split into elements, preferably by line endings, you may or may not get those
 tags. Then let the controller generate ID's for them.

But all in all this sounds complicated and I would just do what most other forums do in similar situations quotes within the answering text:

This is one approach I have found, but I was hoping to either get some feedback or alternative ways to accomplish <Nix>

Maybe add the name of the quoted user. Maybe a "parent" link that shows the original text (similar to Reddit).

Title: WYSIWYG Editor - Inline Comments

Body:
Don't let the browser do anything that has some relevance to the database (like generating IDs). Very bad idea. People will use this to send trash data just to see what happens.

Let it send the text, then split into elements, preferably by line endings, you may or may not get those <p> tags. Then let the controller generate ID's for them.

But all in all this sounds complicated and I would just do what most other forums do in similar situations quotes within the answering text:

This is one approach I have found, but I was hoping to either get some feedback or alternative ways to accomplish <Nix>

Maybe add the name of the quoted user. Maybe a "parent" link that shows the original text (similar to Reddit).


问:
Many small classes vs. logical (but) intricate inheritance
I'm wondering what is better in terms of good OOP desing, clean code, flexibility and avoiding code smells in the future. Image situation, where you have a lot of very similar objects you need to represent as classes. These classes are without any specific functionality, just data classes and are different just by name (and context) Example:

```<code>Class A
{
  String name;
  string description;
}

Class B
{
  String name;
  String count;
  String description;
}

Class C
{
  String name;
  String count;
  String description;
  String imageUrl;
}

Class D
{
  String name;
  String count;
}

Class E
{
  String name;
  String count;
  String imageUrl;
  String age;
}
</code>```

Would it be better to keep them in separate classes, to get "better" readability, but wit many code repetitions, or would it be better to use inheritance to be more DRY?

By using inheritance, you will end up with something like this, but class names will lost it contextual meaning (because of the is-a, not has-a):

```<code>Class A
{
  String name;
  String description;
}

Class B : A
{
  String count;
}

Class C : B
{
  String imageUrl;
}

Class D : C
{
  String age;
}
</code>```

I know inheritance is not and should not be used for code reuse, but I don't see any other possible way how to reduce code repetition in such case.

答:
You question seems to be framed in the context of a language that does not support multiple inheritance but does not specifically specify this.  If you are working with a language that supports multiple inheritance, this becomes trivially easy to solve with only a single level of inheritance.

Here is an example of how this can be solved using multiple inheritance.

```<code>trait Nameable { String name; }
trait Describable { String description; }
trait Countable { Integer count; }
trait HasImageUrl { String imageUrl; }
trait Living { String age; }

class A : Nameable, Describable;
class B : Nameable, Describable, Countable;
class C : Nameable, Describable, Countable, HasImageUrl;
class D : Nameable, Countable;
class E : Nameable, Countable, HasImageUrl, Living;
</code>```

Body:
You question seems to be framed in the context of a language that does not support multiple inheritance but does not specifically specify this.  If you are working with a language that supports multiple inheritance, this becomes trivially easy to solve with only a single level of inheritance.

Here is an example of how this can be solved using multiple inheritance.

trait Nameable { String name; }
trait Describable { String description; }
trait Countable { Integer count; }
trait HasImageUrl { String imageUrl; }
trait Living { String age; }

class A : Nameable, Describable;
class B : Nameable, Describable, Countable;
class C : Nameable, Describable, Countable, HasImageUrl;
class D : Nameable, Countable;
class E : Nameable, Countable, HasImageUrl, Living;