问:
Softpedia published some of my open source projects — how to react?
(FYI: I've just moved this question over from Stackoverflow on recommendation.)

I just received a few emails, informing me that softpedia.com has added some of my "products" to their "database of scripts, code snippets and web applications". My products are in this case some smaller open source projects, which I have hosted and published on github.

Now I'm wondering how to react to this. This site is indirectly making money of my free work through ads on three pages before the actual download. They also seem to "invent" version numbers and I can't find out if they're hosting the latest or all versions of my projects. — I can see how this could lead to problems in the future, since I don't control what's "the latest" everywhere.

On the other hand I don't mind some extra publicity. I want as many people as possible to know about the projects, use them, fork them and hopefully improve them.

The projects in questions are really fairly small, but this might not be the case in the future for me and/or other people reading this question.

I'm sure that this must have happened to others around here. What's your opinion? Should I try to get the downloads removed?

Update 1

I've requested the removal and mentioned that I don't feel that Softpedia can provide the right environment for this kind of project.

Their team got back to me instantly with a friendly email saying, that they'll remove the links for now:

If you are worried that your projects won't be updated, then I must
  tell you that I have them bookmarked in my RSS reader, so any version
  changes will be forwarded to me when needed. So I promise I'll keep
  your script up to date as soon as I see an update in the repository.

I have to say, that I appreciate this kind of reaction quite a lot and so I sent them another email, describing in more detail what I'm worried about and what bothers me. I also stated, that I'm aware that my license clearly permits them to host the projects in any case, but that I'd be even happy if they would host the projects as long as they could convince me of a few details and maybe make some small changes to the way the projects are represented. — Let's see where this goes.

Update 2

After discussing with their contact and requesting some changes regarding display of version (they had given the possibility to do so) and authorship they put the projects back up on their site.

All in all a positive and definitely interesting experience.

答:
There are several aspects to this question, legal, commercial and moral.

If they are distributing your software according to the terms of your license then legally they are doing exactly what you have required of them.

If they are not adhering to your license then you should reasonably expect them to take it down if you ask them to. Don't even think about getting a lawyer involved though, unless you want to spend lots of money on being told "there's no money in it".

Commercially, they probably aren't making much money in ad. revenue and if you want to gain wider exposure, it may be good for your project to appear in softpedia search results.

Morally, you have to decide whether you want this kind of free advertising, which is essentially what it is. If softpedia were misrepresenting this work as their own then that would obviously be wrong, but that doesn't appear to be what they are doing.

You probably should enter into a dialogue with them though, if only to sort out versioning issues, and make sure that they link back to the original github projects, so that people can easily check if the version on softpedia is the latest version or not.

While DVCS's have many advantages, they don't often have a nice simple, linear version history, so it isn't always obvious when a new release version has been released. Using tags or having obviously named release branch can help with this, and can be equally important for end users as for services like softpedia.


问:
Downsides of GNU LGPL v3 vs. GNU LGPL v2.1?
Firstly, I realize that this is a programming Q&A site, and not a place for legal advice....  Just trying to get a basic idea of what the downsides to using an LGPLv3 library might be.

What are the differences between GNU LGPL v2.1 and GNU LGPL v3?

In particular, I know that regular GPLv3 has many anti-drm and anti-patent clauses.  In principal I don't have anything against these clauses, but I will these suddenly apply to the main application if I choose to use an LGPLv3 library.

The rules of LGPL v2.1 seems to only apply to the library that you use or modify. It says nothing about the main application. (Assuming no static linking etc.)

Thus, in the niche-market software provider where I work, we regularly use (and contribute to) LGPL licensed libraries, without needing to open-source our main application.

Does this change in LGPLv3?

The question https://stackoverflow.com/questions/1108238/differences-between-gnu-lgpl-v2-1-and-gnu-lgpl-v3 got a couple of answers, but none that address any new obligations that the main application might have.

To clarify:  I'm asking about the LGPL v3, not plain GPLv3. Do any of the Tivoization / patent grant requirements "bleed through" from an LGPLv3 library to the host application?

答:
The main difference in GPL 2->3 is Tivoisation and patents.

You cannot use a GPL app but prevent people replacing it with their own version (even if you give them the source) by encrypting/signing the binaries or restricting the ability to install new software.

The sections on patents is trickier, it's not entirely clear how much you can require this in a licence agreement, where it would apply and even if software is patentable in your location.

For a conventional desktop app there isn't really much difference from GPL2.1->3

ContentLicense: CC BY-SA 3.0


问:
Is there any comercial application written in Visual Basic .NET?
In my work the language used to write applications is Visual Basic .NET.

I read on internet and almost all the examples and questions are about C#.

Is there any comercial application written in Visual Basic .NET? Is there any field for a VB Net developer?

答:
I think your question is related to whether you can get a job as a VB.NET developer.

You can get VB.NET jobs, they do exist - but don't restrict yourself by something as unimportant as a language. Learn C# and then you can choose from a much bigger range of jobs. All of your understanding of the .NET framework is immediately useful if you switch to C#, so it becomes a simple exercise of learning the syntactical differences.


问:
How to get familiarized with certificate generation
I am supposed to work on web Services (using  Apache CXF and Spring )

I was asked to get familiarized with certificate generation, as we will need to generate certificates going forward for the web services.

One thing I knew is that  they are using Glassfish server.

I googled , but I didn't understand anything.

I know that the information I provided is not sufficient, to expect a relevant answer

But Could anybody please let me know , what will be the best starting point on this ?? and what other information should we need from the client to make it clearer ??

答:
To secure web services you can use PKI (private key infrastructure), this uses asymmetric keys, a key pair with the property that what a key encrypt only the other one decrypt. This key pair is composed by a private and a public key. usually a certificate is generated for a public key, in order to identify the key owner. You can use keytool or openSSL to generate keys and certificates. I made this fast introduction just to throw some keywords that you can search for.

In a fast search i found this, maybe help you:
https://stackoverflow.com/questions/5724631/understanding-keystore-certificates-and-alias

If you need anymore help, I can get you more information.

OwnerDisplayName: Luis P.


问:
Forgetting basic language functions due to use of IDE, over reliance?

Possible Duplicate:

  Should newbies use IDE autocomplete (Intellisense)?

  Is it wrong or bad to use autocomplete?

Having used an IDE for the last 3-4 years, the other day a few of my coworkers and I came to a fairly sad realization that we had forgotten some basic Java methods/functions because we always relied on our IDE (Eclipse/STS/IntelliJ) to complete them for us (such as what a function takes in terms of parameters), is this a sign that our skills are deteriorating, that we're over relying on IDEs? (This whole discussion came about us talking about taking the Oracle Java 7 EE certification test and looking over a few practice questions, questions such as, what parameters does function X take, etc)

If so, how do you guys fight off this sort of thing? Just re-read books and stuff? I myself can't imagine not coding with an IDE because in all honesty, it does make me code a lot faster with things such as auto complete, etc while some of my co-workers suggested we code sans IDE for a few months.

I do realize that sometimes one doesn't need to know everything about a function, but I do remember a college professor telling us that IDEs are terrible because when the time comes that you need some sort of function, you'll have to waste time looking it up instead of just banging out the code from rote memory.

答:
Is programming about using the right function, or coming up with the right design?

I consider that knowing that some method or paradigm exists (or even might/should exist) is enough to look it up when you need to - that's what the IDE, Javadoc and Google are for. Of course good knowledge of the library is a time saver (although I find myself looking at the doc of a lot of APIs I 'know' already - just to be sure).


问:
Why is naming a table's Primary Key column "Id" considered bad practice?
My t-sql teacher told us that naming our PK column "Id" is considered bad practice without any further explanations.

Why is naming a table PK column "Id" is considered bad practice?

答:
Because when you have a table with a foreign key you can't name that foreign key "Id".  You have table name it TableId

And then your join looks like

```<code>SELECT * FROM cars c JOIN manufacturer m ON m.Id = c.ManufacturerId
</code>```

And ideally, your condition should have the same field name on each sides

```<code>SELECT * FROM cars c JOIN manufacturer m ON m.ManufacturerId = c.ManufacturerId
</code>```

So while it seems redundant to name the Id as ManufacturerId, it makes it less likely that you have errors in your join conditions as mistakes become obvious.

This seems simple, but when you join several tables, it gets more likely you'll make a mistake, find the one below...

```<code>SELECT *
    FROM cars car
    JOIN manufacturer mfg
        ON mfg.Id = car.ManufacturerId
    JOIN models mod
        ON mod.Id = car.ModelId
    JOIN colors col
        ON mfg.Id = car.ColorId
</code>```

Whereas with proper naming, the error sticks out...

```<code>SELECT *
    FROM cars car
    JOIN manufacturer mfg
        ON mfg.ManufacturerId = car.ManufacturerId
    JOIN models mod
        ON mod.ModelId = car.ModelId
    JOIN colors col
        ON mfg.ManufacturerId = car.ColorId
</code>```

Another reason naming them Id is "bad" is that when you are querying for information from several tables you will need to rename the Id columns so you can distinguish them.

```<code>SELECT   manufacturer.Id as 'ManufacturerId'
        ,cars.Id as 'CarId'
        --etc
    FROM cars
    JOIN manufacturer
        ON manufacturer.Id = cars.Id
</code>```

With accurate names this is less of an issue

Body:
Because when you have a table with a foreign key you can't name that foreign key "Id".  You have table name it TableId

And then your join looks like

SELECT * FROM cars c JOIN manufacturer m ON m.Id = c.ManufacturerId

And ideally, your condition should have the same field name on each sides

SELECT * FROM cars c JOIN manufacturer m ON m.ManufacturerId = c.ManufacturerId

So while it seems redundant to name the Id as ManufacturerId, it makes it less likely that you have errors in your join conditions as mistakes become obvious.

This seems simple, but when you join several tables, it gets more likely you'll make a mistake, find the one below...

SELECT *
    FROM cars car
    JOIN manufacturer mfg
        ON mfg.Id = car.ManufacturerId
    JOIN models mod
        ON mod.Id = car.ModelId
    JOIN colors col
        ON mfg.Id = car.ColorId

Whereas with proper naming, the error sticks out...

SELECT *
    FROM cars car
    JOIN manufacturer mfg
        ON mfg.ManufacturerId = car.ManufacturerId
    JOIN models mod
        ON mod.ModelId = car.ModelId
    JOIN colors col
        ON mfg.ManufacturerId = car.ColorId

Another reason naming them Id is "bad" is that when you are querying for information from several tables you will need to rename the Id columns so you can distinguish them.

SELECT   manufacturer.Id as 'ManufacturerId'
        ,cars.Id as 'CarId'
        --etc
    FROM cars
    JOIN manufacturer
        ON manufacturer.Id = cars.Id

With accurate names this is less of an issue


答:
Why not just ask your teacher?

Think about this, when all your tables PK columns are named ID it makes using them as foreign keys a nightmare.

Column names need to be semantically significant. ID is to generic.

Title: Why is naming a table's Primary Key column "Id" considered bad practice?

Body:
My t-sql teacher told us that naming our PK column "Id" is considered bad practice without any further explanations.

Why is naming a table PK column "Id" is considered bad practice?


答:
Common or key column names like "Name" or "Id" should be prefixed with the TableName.

It removes ambiguity, easier to search for, means far less column aliases when both "Id" values are needed.

A lesser used or audit column or non-key (say LastUpdatedDateTime) doesn't matter


答:
Is this a sign that our skills are deteriorating, that we're over relying on IDEs?

I'm unable to hunt an animal, because I rely on the fact that when I need food, I buy it in a market nearby. Is this a sign that our skills of hunters are deteriorating over generations and that we're over relying on our society?

There are skills you need today as a developer. When somebody hires you, he expects from you:

to have an intellectual ability to solve complex problems,

to know the practices and patterns which help you to work in an efficient way,

to know the standards, to understand requirements, etc.

to be able to use a given programming language efficiently, i.e. have enough knowledge to find quickly how to translate a solution to a problem into the given language.

But this does not include knowing every name of every method in a given framework. This is because:

It's a waste of time,

If you use the tools you have to use to be efficient, they will remember those method names for you (and help you through code completion),

Soon or later, the names will change, old ones will be removed, new ones will be added: it's easy for an IDE to be constantly up to date; it's a bit harder to do for a human.

In other words, I would rather hire somebody who knows very well how to use tools he have to do the job, rather than someone who spent weeks learning the names of the methods.

Title: Forgetting basic language functions due to use of IDE, over reliance?

Body:
Possible Duplicate:

  Should newbies use IDE autocomplete (Intellisense)?

  Is it wrong or bad to use autocomplete?

Having used an IDE for the last 3-4 years, the other day a few of my coworkers and I came to a fairly sad realization that we had forgotten some basic Java methods/functions because we always relied on our IDE (Eclipse/STS/IntelliJ) to complete them for us (such as what a function takes in terms of parameters), is this a sign that our skills are deteriorating, that we're over relying on IDEs? (This whole discussion came about us talking about taking the Oracle Java 7 EE certification test and looking over a few practice questions, questions such as, what parameters does function X take, etc)

If so, how do you guys fight off this sort of thing? Just re-read books and stuff? I myself can't imagine not coding with an IDE because in all honesty, it does make me code a lot faster with things such as auto complete, etc while some of my co-workers suggested we code sans IDE for a few months.

I do realize that sometimes one doesn't need to know everything about a function, but I do remember a college professor telling us that IDEs are terrible because when the time comes that you need some sort of function, you'll have to waste time looking it up instead of just banging out the code from rote memory.


答:
I'm going to come out and say it: It's not really a bad practice (and even if it is, its not that bad).

You could make the argument (as Chad pointed out) that it can mask errors like in the following query:

```<code>SELECT *
    FROM cars car
    JOIN manufacturer mfg
        ON mfg.Id = car.ManufacturerId
    JOIN models mod
        ON mod.Id = car.ModelId
    JOIN colors col
        ON mfg.Id = car.ColorId
</code>```

but this can easily be mitigated by not using tiny aliases for your table names:

```<code>SELECT *
    FROM cars
    JOIN manufacturer
        ON manufacturer.Id = cars.ManufacturerId
    JOIN models
        ON models.Id = cars.ModelId
    JOIN colors
        ON manufacturer.Id = cars.ColorId
</code>```

The practice of ALWAYS using 3 letter abbreviations seems much worse to me than using the column name id. (Case in point: who would actually abbreviate the table name cars with the abbreviation car? What end does that serve?)

The point is: be consistent. If your company uses Id and you commonly make the error above, then get in the habit of using full table names. If your company bans the Id column, take it in stride and use whatever naming convention they prefer.

Focus on learning things that are ACTUALLY bad practices (such as multiple nested correlated sub queries) rather than mulling over issues like this. The issue of naming your columns "ID" is closer to being a matter of taste than it is to being a bad practice.

A NOTE TO EDITORS : The error in this query is intentional and is being used to make a point. Please read the full answer before editing.

Body:
I'm going to come out and say it: It's not really a bad practice (and even if it is, its not that bad).

You could make the argument (as Chad pointed out) that it can mask errors like in the following query:

SELECT *
    FROM cars car
    JOIN manufacturer mfg
        ON mfg.Id = car.ManufacturerId
    JOIN models mod
        ON mod.Id = car.ModelId
    JOIN colors col
        ON mfg.Id = car.ColorId

but this can easily be mitigated by not using tiny aliases for your table names:

SELECT *
    FROM cars
    JOIN manufacturer
        ON manufacturer.Id = cars.ManufacturerId
    JOIN models
        ON models.Id = cars.ModelId
    JOIN colors
        ON manufacturer.Id = cars.ColorId

The practice of ALWAYS using 3 letter abbreviations seems much worse to me than using the column name id. (Case in point: who would actually abbreviate the table name cars with the abbreviation car? What end does that serve?)

The point is: be consistent. If your company uses Id and you commonly make the error above, then get in the habit of using full table names. If your company bans the Id column, take it in stride and use whatever naming convention they prefer.

Focus on learning things that are ACTUALLY bad practices (such as multiple nested correlated sub queries) rather than mulling over issues like this. The issue of naming your columns "ID" is closer to being a matter of taste than it is to being a bad practice.

A NOTE TO EDITORS : The error in this query is intentional and is being used to make a point. Please read the full answer before editing.


答:
All that's deteriorating is the space you reserve for trivia1.  There's only so much detail you can keep in your head at one time, so it's best to focus on solving the bigger problem and not worrying so much about memorizing the parameter lists for methods you don't use all the time (there should be at least a few methods that you use constantly and have internalized; I mean, you shouldn't have to look up how to call println, for example).

I cut my teeth on C and Fortran in a command-line environment, so I was always suspicious of people who claimed they needed an IDE to perform their tasks.  Then I started working in Java a couple of years ago.  Java's a freaking huge language compared to C, with a correspondingly huge class library, and there's no way anyone could be expected to memorize all of that.

The name of the game in software development is productivity; using a tool to make you more productive shouldn't be a problem.

If you really do feel like your skills really are deteriorating, though, maybe you should spend some cycles working in a plain ol' text editor (vi, Notepad++, etc.) and compile on the command line.

1 Syntax is not trivia.  If you're starting to forget how to actually structure a class or program, then that's a real problem that needs to be remedied.


问:
Is it a good practice to code in English?

Possible Duplicate:

  Do people in non-English-speaking countries code in English?

I have a development comming that is intended to be sold across Latin America (Spanish speakers), but I've heard from some partners that is a good practice to always code in English, I mean just code (methods, classes, pages names, etc), labels on GUI are going to be all in Spanish...

Code will be edited in the future by developer of companies across Latin America and just maybe some from outside.

What do you think?, any experience with this?

答:
This is a tough one. The problem with having all the variable names in English is that you have to translate the customer's domain from their native language into English. And that is really hard sometimes, as naming stuff is one of the more difficult problems in programming. If you are trying to practise DDD then creating an ubiquitous domain language is nearly impossible. There will always be two versions of every concept and meaning gets lost in translation.

But on the other hand if you mix another language into the code base (besides English) then it will always look messy and be unreadable for everyone that cannot speak that language.

As a native English speaker living in Sweden, I lean towards translating everything to English except for the odd word that just cannot be translated without losing some of its meaning.


问:
Is the cloud ready to replace core business systems?
Questions like this have been asked before (like here), but a lot can change in a year.

My company is very interested in migrating core systems to the "cloud".  Non-technical upper-management doesn't quite know what that means, but they are excited at the idea and have already started adopting cloud-based systems.

Having gone through an ERP migration, and experiencing first-hand what a pain it is to deal with legacy systems, I'm really concerned that by going to the cloud, losing control of our data, we are going to begin a cycle of never-ending migration as cloud services come online and then blink out of existence. To say nothing of the technical demands of learning, programming, and keeping up with multiple non-stable APIs in order to get disparate cloud-based systems to talk with one another.

I have other concerns such as privacy, uptime, data ownership, maintenance, etc.

Is the cloud really ready for the prime time?  If you were a business owner, would you choose to place your key, business-critical, systems on the cloud?  As a programmer, do you trust the cloud and the companies providing those services to be reliable and have the longevity of a traditional software solution?  If it is not ready now, when will it be, if ever?

答:
Privacy: Corporate networks and websites get hacked all the time.

Uptime: Ever get that email that "We will be doing some maintenance on Saturday..." from your company admin?

Data Ownership: probably need to improve contracts and practices in this area. Most will offer a reasonable data dump in a managable format (Your 57 DVD's are in the mail.).

Maintenance: better them doing it than me.

Did anyone ever think the mainframe would leave the lab? PC's are toys and have no place in a serious/critical business. Why email when you can fax or call on the phone?

It will be determined by a business model and not a lack of technology. I can't wait for the iCloud to take off so I can buy an iPhone and not have to deal with iTunes desktop app.

Someone will figure out a better way to jam 60 gogillan servers in a closet than Google. Maybe they fit a few in my pocket and this "cloud thing" will be just a bunch of devices everyone is carrying around and have sitting on shelves at home.


答:
I firmly believe that no serious developer can be uncapable of, at the very least, understanding English in written form. How else would you refer to any library's documentation, read a book on a highly specialized matter or even use Stack Overflow?

In your particular case, chances are that if a client "requires" the source code to be in their local language, they could be a quite low-profile company, and perhaps you wouldn't like to establish a relationship with such a customer.

Title: Is it a good practice to code in English?

Body:
Possible Duplicate:

  Do people in non-English-speaking countries code in English?

I have a development comming that is intended to be sold across Latin America (Spanish speakers), but I've heard from some partners that is a good practice to always code in English, I mean just code (methods, classes, pages names, etc), labels on GUI are going to be all in Spanish...

Code will be edited in the future by developer of companies across Latin America and just maybe some from outside.

What do you think?, any experience with this?


答:
This is actually a more complex question than you thing. It depends on many scenerios. But to address a few of you points:

privacy, uptime, data ownership, maintenance

When questioning yourself about reliability you have to consider which cloud service you are targeting. Now you have Microsoft and Amazon both with attractive offers that scale to you every need. This is not your mom n pop stores, you can probably trust Microsoft to keep the cloud service running. One phrase I heard was: "Who do you trust to do a better job of backing you infrastructure? the 3 - 5 guys on your IT dept or a team of experts at microsofts data centers"

What you really have to consider are thing more closely related to performance. Anyway you look at it, you have to consider the latency of your data traveling from the cloud to your onsite apps. But again, you might have more processing power on the cloud when you need it (dynamic balancing).

It all comes down to your actual requirements. But most likely the correct answer is a merge between cloud and on-site.

Title: Is the cloud ready to replace core business systems?

Body:
Questions like this have been asked before (like here), but a lot can change in a year.

My company is very interested in migrating core systems to the "cloud".  Non-technical upper-management doesn't quite know what that means, but they are excited at the idea and have already started adopting cloud-based systems.

Having gone through an ERP migration, and experiencing first-hand what a pain it is to deal with legacy systems, I'm really concerned that by going to the cloud, losing control of our data, we are going to begin a cycle of never-ending migration as cloud services come online and then blink out of existence. To say nothing of the technical demands of learning, programming, and keeping up with multiple non-stable APIs in order to get disparate cloud-based systems to talk with one another.

I have other concerns such as privacy, uptime, data ownership, maintenance, etc.

Is the cloud really ready for the prime time?  If you were a business owner, would you choose to place your key, business-critical, systems on the cloud?  As a programmer, do you trust the cloud and the companies providing those services to be reliable and have the longevity of a traditional software solution?  If it is not ready now, when will it be, if ever?


答:
I work for a company and roughly 95% of our servers (out of 400+) live 'in the cloud', mostly at Amazon EC2. Cloud providers have matured a lot in just the past few years, and you will find that many other emerging companies live in the cloud too, like Netflix and Quora.

Now some problems we've faced as a result:

Random downtimes due to maintenance or royal screw ups - Amazon had some pretty fantastic downtimes last year because one of their sys admins hit the wrong button and caused their EBS (block storage service) system to basically die. That caused some pain and suffering for us, as well as others.

Other random blips in our instances - Amazon's normal EC2 instances are ephemeral and sometimes just randomly die, perhaps the node they lived on had a problem or something else happened

Benefits we've had:

Really fast spin up time - if we want to move to a new server, we can easily create a new one through the Amazon API

Easier scaling - we can create more instances and load balance them for our applications

Redundancy - it's easy to spin up servers in different data centers to mitigate the risks of having a truck drive through one (this has happened before, true story)

Less in-house IT overhead - we do have an on-call guy, but he doesn't have to concern himself managing 400 physical machines, or any of the other litany of services you can obtain via a cloud provider

Easier services - Stuff like Amazon RDS is usable if you just want a managed database instance, and you don't need some custom database instance

Reliability - we put separate applications on separate cloud servers, much easier than saying we'd put in 10 different physical servers to host 10 different apps

Concerns:

Data ownership - we put some pretty sensitive data out on the cloud, namely stuff like customer data - this can encompass a lot of legal domains, and if you have any concerns like HIPAA or PCI, then you should really talk with lawyers and other providers about stuff like this

Data Backup - do remember that regardless of whether or not you use the cloud or not, you still have to back up your data in case something happens, like someone accidentally kills an instance. We have nightly backup jobs for our databases, and the database dumps are stored in S3, and also transferred over to another data center

Security - Stuff can happen, DDOSes can happen, site breaks can happen - this is not just a problem with the cloud

Revolving door of providers - I don't think companies like Amazon, Rackspace, or Heroku (owned by Salesforce.com) are going the way of the dodo anytime soon

And some really cool stuff we do with the cloud:

Since we have 400 servers, and are constantly adding new ones, it's a chore to spin them up via the Amazon (or whatever) console, then tweak each one - that's not a repeatable process.

We automate server deployments and configuration with puppet, which allows us to say stuff like "Make a new server for running python and django, and install apache httpd and 3 other things on it"

We can quickly colocate cloud servers in different regions for better response times for that region.

Elastic load balancing for servers

And of course, it's a good idea to keep up with other big cloud users, as they always write about ways they're using the cloud. Here's an example from Netflix talking about what they learned after the EBS incident this past April:

http://techblog.netflix.com/2011/04/lessons-netflix-learned-from-aws-outage.html


问:
The relation between Business Rules Engines and Constraint Programming languages
If one looks at (perhaps older) manuals of Drools or some other rule engines,
one of the illustrations of their added value is solving puzzles such
as the Miss Manners puzzle (listed in the Drools Documentation). Now, such puzzles are naturally formulated
and solved using Prolog or the more recent Constraint Programming languages, and
one wonders why would anyone use Drools for this purpose. The added value
which Prolog and CPL give in this case is their ability to naturally
formulate the puzzle as a set of logical predicates and to automatically
search the space of solutions (with CPL being more efficient in this respect).
But what is the added value of product such as Drools (I mean besides of
the bells and whistles of taking, for example, an Excel file and translating
it into a set of rules)?

More specifically, Prolog implements backtrack search, CLP implements backtrack search
with constraint propagation, and therefore instead of searching, so to speak, the
whole Cartesian product of spaces for individual variables, they prune away large portions
of this product space. This is what makes them effective and useful. Both Prolog and
CLP are discussed amply in the literature.

On the other hand, while it is clear that Rete algorithm caches the set of rules
in the form of some data structure(s), thus (to my understanding) making it more
effective to evaluate the output if some of the inputs have changed, and giving
means to effectively update this data structure for incremental changes, it is
difficult (for me) to understand the basic idea, and even more so, its effectiveness (compared to what? to Prolog? to CLP)? Unfortunately, it is hard to find good
references that view Rete algorithm in this wider context.

The documentation of Drools is unfortunately not very informative in this respect.
The most I could find was "The Rete algorithm, Leaps algorithm, and its descendants such as Drools' Reteoo (and Leaps), provide very efficient ways of matching rule patterns to your domain object data. These are especially efficient when you have datasets that do not change entirely (as the rule engine can remember past matches). These algorithms are battle-proven". Very efficient - compared to what? Battle proven - could one point to real-world
applications?

I would appreciate it if one could throw some more light on this subject or give a valid
reference.

答:
I agree with you that Prolog is more powerful than Drools.  But I think Drools is appealing to enterprise client because of the fancy front end tools and integrations Drools has with other popular enterprise applications.  I think these rules are then persisted to the database where many Drools engines can use them immediately.

Changing rules during runtime is a pretty dynamic way of using the Drools engine and it is supported.  I believe Prolog could have a similar system, but this doesn't exist AFAIK.  Where would these rules or edited rules go?  asserted in the db of the program?  On restart, these rules would be lost.  Would we persist them to a shared db and then assert them into the program as needed?  Prolog might be useable, but Drools is already well integrated into the enterprise application stack, so why make yourself crazy (except for fun)?

"I agree with you that Prolog is more powerful than Drools. But I think Drools is appealing to enterprise client because of the fancy front end tools and integrations Drools has with other popular enterprise applications"

As per my comment above, Drools now implements goal based derivation trees in the same manner as Prolog. Further Drools can do somethign with that deivation tree that most other Prolog systems can't. Drools can materialise the derivation tree into a view and receive reactive updates as the underlying grouond terms change.

OwnerDisplayName: John Donn

ContentLicense: CC BY-SA 4.0


问:
How should I react to diminishing application performance?
Sometimes it comes to me that the biggest challenge for an engineer when he find his application getting worse in performance is lack of enough information.

Imagine that you go through the weekly performance report from your application's access log, and find you get much lower response times from July. All you can do is to pray for it not to get worse the next time.

答:
Performance tuning is a critical skill in any application that hits a database. Every database has a large book written about how to perfromance tune. Get the book for your dabase backend, read it cover to cover and then start taking the steps you need to identify and resolve performance issues. If your database was designed by someone without this knowldge to begin with, likely you have a  bad design that has badly designed queries as well and possibly poor indexing.  In this case you might want to read about refactoring datbases as well as you will likely need structural changes as well as fixes to the indexes and queries. This is complex stuff, you can't learn it all from questions on a website like this one. Just praying it will get better is counterproductive, there are many things you can do to make it better. And yes as time goes one and more data is added the queries will get slower and slower especially if they are poorly designed.

There are also non-database reasons for poor performance, but get the database tuned properly and it is likely that many of your issues will go away.


问:
Thoughts on Development using Virtual Machines
I'll be working as a development lead for a startup and I've suggested that we use VMs for development.  I'm not talking about each developer having a desktop with VMs for testing/development, I mean having a server rack where all VMs are managed and have the developers work from a microPC (ChromeOS anyone?) locally, or even remotely from their home computer.

To me, the benefits are the fact that it's extremely scalable, cheaper in the long run, easier to manage and that we utilize the hardware its maximum potential.  As for cons, I can't think of any particular showstoppers other than we'll need someone to setup/maintain said setup.

I was hoping that some of you might of had a similar setup at your place of employment and be able to weight in with your opinions.  Thanks.

答:
As stated by others, it really depends on what problem you're trying to solve with the VM Desktops and then weighing the benefits of resolving that problem against the disadvantages the VM environment will incur.

We're moving towards a hybrid environment where all of our onshore developers will have traditional physical machines but out offshore developers (working with a small outsourcing company right now) will use virtual desktops.  The problems we're trying to solve with the remote desktops are security and performance related. The virtual environment will obviously provide us greater control from a security perspective and for performance we will be transferring only "changed pixels" rather than full source code and having to implement proxy servers and such.

Still not sure if this is the right way to go, but it's where we're headed.


问:
Using HBase or Cassandra for a token server
I've been trying to figure out how to use HBase/Cassandra for a token system we're re-implementing. I can probably squeeze quite a lot more from MySQL, but it just seems it has come to clinging on to the wrong tool for the task just because we know it well. Eventually will hit a wall (like happened to us in other areas). Naturally I started looking into possible NoSQL solutions. The prominent ones (at least in terms of buzz) are HBase and Cassandra.

The story is more or less like this:

A user can send a gift other users.

Each gift has a list of recipients or is public in which case limited by number or expiration date

For each gift sent we generate some token that uniquely identifies that gift.

For each gift we track the list of potential recipients and their current status relating to that gift (accepted, declinded etc).

A user can request to see all his currently pending gifts

A can request a list of users he has sent a gift to today (used to limit number of gifts sent)

Required the ability to "dump" or "ignore" expired gifts (x day old gifts are considered expired)

There are some other requirements but I believe the above covers the essentials.

How would I go and model that using HBase or Cassandra?

Well, the wall was performance. A few 10s of millions of records per day over 2 tables kept for 2 weeks (wish I could have kept it for more but there was no way). The response times kept getting slower and slower until eventually we had to start cutting down number of days we kept data. Caching helps here but it's not an ideal solution since a big part of the ops are updates.

Also, as I hinted in my original post. We use MySQL extensively. We know exactly what it can and can't do both in naive implementations followed by native partitioning and finally by horizontally sharding our dataset on the application level to reside on multiple DB nodes. It can be done, but that's not really what I'm trying to get from this. I asked a very specific question about designing a solution using a NoSQL solution since it's very hard to find examples for designs out there.

Brainlag, not trying to come off as rude. I actually appreciate it a lot that you are the only one who even bothered to respond. but I see it over and over again. People ask questions and others assume they have no idea what they're talking about and give an irrelevant answer. Ignore RDBMS please. The question is about nosql.

答: Due to the lack of answers for the two DBs you mentioned I'd like to suggest you have a look at MongoDB or Redis. Both are extremely fast and modeling your data to fit either system should be fairly simple.</p>

OwnerDisplayName: crippy


答:
It makes it hard (and confusing) to perform a natural join on the table, therefore yeah, it's bad if not very bad.

Natural Join is an ancient artifact of SQL Lore (i.e. relational algebra) you may have seen one of these:  ⋈  in a database book perhaps. What I mean is Natrual Join is not a new fangled SQL idea, even though it seemed to take forever for DBMS's to have implemented it, therefore it's not a new fangled idea for you to implement it, it might even be unreasonable for you to ignore its existence nowadays.

Well, if you name all your primary key's ID, then you lose the ease and simplicity of the natural join. select * from dudes natural join cars will need to be written select * from dudes inner join cars where cars.dudeid = dudes.id or select * from dudes inner join cars where dudes.carid = cars.id.  If you are able to do a natural join, you get to ignore what the relation actually is, which, I believe, is pretty awesome.


问:
What can be done to stop losing resources and unify Mercurial and Git?
Both Mercurial and Git were created as a replacement for the same program and to solve the same problem which you can read about in Martin Beckett's answer to How did Git and Mercurial develop so similarly at the same time? question.

These two tools are very similar and borrow from each other according to Scott Chacon in his
Hg and Git: Can't we all just get along? presentation at PyCon 2010.

I think we, the people, do waste huge amount of resources by having these two tools which do the same, yet operate differently. Is it possible to unify Mercurial and Git and stop wasting our resources? What actions should be taken?

答:
You'd have a lot more of a chance if they weren't so similar. No one is screaming out for a combination. This is the first time I've heard an argument that the existence of two products wastes anything and you haven't provided evidence of that.

The only successful open-source merges I can think of off the top of my head are Rails with Merb and Selenium with WebDriver. In both cases, this was because the two products solved very different problems and people were crying out for a product that solved both.


答:
For some companies, I'd imagine the cloud could work well for them.  Note that this could be small businesses that don't want a lot of infrastructure and like the idea of what the cloud can offer here to some degree particularly in how quickly things can be up and running with relatively low initial investments compared to all the stuff in a traditional on-site solution.

If I were a business owner, the question would be what I am currently running and how well is that working for me?  If I were starting a new business I could imagine the cloud being cheaper upfront than trying to bring in some big ERP or CRM software.  At the same time, if I had a business of a few years, there may be various sunk costs that may make a migration challenging.

As a programmer, some of my work can involve cloud services so in a way I get to deal with some of the cloud headaches that can pop up if some software comes in a cloud-based solution.  I don't really see this going away though I do wonder if there will be shake-ups and which providers have enough resources backing them to survive at least the next few years.  There will likely be changes and some will go out of business, but there will likely be a few left standing.

The better question here would be prime time for who.  If you run some mega multinational conglomerate like Proctor & Gamble or GE, I'm not sure how easy a cloud solution could be accepted given the scale involved.  If you run some little mom and pop shop, then maybe using the cloud to store your books like you store your tax returns isn't such a horrible idea.


问:
Is there such a thing as a "when" statement?
Is there a language or language feature that can handle "when" cases? That is, whenever some condition becomes true, in any scope or context, that extra code could be specified to execute?

Note that this is different from a simple if, which must be in a particular scope and explicitly written. This when clause would almost be like an if that applied to every case in the execution of the program after it.

答:
If you consider Drools a language, then yes.

An example:

```<code>rule "Rule 08 - Debit"
when
    AccountingPeriod( $start : start, $end : end )
    $cashflow : AllocatedCashflow( $account : account, $date : date <= $end, $amount : amount, type==TypedCashflow.DEBIT )
    not AccountingPeriod( start < $start)
then
    $account.setBalance($account.getBalance()-$amount);
    retract($cashflow);
end
</code>```

Body:
If you consider Drools a language, then yes.

An example:

rule "Rule 08 - Debit"
when
    AccountingPeriod( $start : start, $end : end )
    $cashflow : AllocatedCashflow( $account : account, $date : date <= $end, $amount : amount, type==TypedCashflow.DEBIT )
    not AccountingPeriod( start < $start)
then
    $account.setBalance($account.getBalance()-$amount);
    retract($cashflow);
end


答:
I know where I work I highly doubt that we could legally move to the cloud. Government contracts mandate that we hold certain data on separate servers. Now, since we don't deal solely with government contracts, we could move some of our functionality to the cloud but not all of it.

For some companies, it is unlikely a day will come where they will be able to operate solely "in the cloud" because of who they have their contracts with.


问:
Organizing Git repositories with common nested sub-modules
I'm a big fan of Git sub-modules.  I like to be able to track a dependency along with its version, so that you can roll-back to a previous version of your project and have the corresponding version of the dependency to build safely and cleanly.  Moreover, it's easier to release our libraries as open source projects as the history for libraries is separate from that of the applications that depend on them (and which are not going to be open sourced).

I'm setting up workflow for multiple projects at work, and I was wondering how it would be if we took this approach a bit of an extreme instead of having a single monolithic project.  I quickly realized there is a potential can of worms in really using sub-modules.

Supposing a pair of applications: studio and player, and dependent libraries core, graph and network, where dependencies are as follows:

core is standalone

graph depends on core (sub-module at ./libs/core)

network depdends on core (sub-module at ./libs/core)

studio depends on graph and network (sub-modules at ./libs/graph and ./libs/network)

player depends on graph and network (sub-modules at ./libs/graph and ./libs/network)

Suppose that we're using CMake and that each of these projects has unit tests and all the works.  Each project (including studio and player) must be able to be compiled standalone to perform code metrics, unit testing, etc.

The thing is, a recursive git submodule fetch, then you get the following directory structure:

```<code>studio/
studio/libs/                    (sub-module depth: 1)
studio/libs/graph/
studio/libs/graph/libs/         (sub-module depth: 2)
studio/libs/graph/libs/core/
studio/libs/network/
studio/libs/network/libs/       (sub-module depth: 2)
studio/libs/network/libs/core/
</code>```

Notice that core is cloned twice in the studio project.  Aside from this wasting disk space, I have a build system problem because I'm building core twice and I potentially get two different versions of core.

Question

How do I organize sub-modules so that I get the versioned dependency and standalone build without getting multiple copies of common nested sub-modules?

Possible solution

If the the library dependency is somewhat of a suggestion (i.e. in a "known to work with version X" or "only version X is officially supported" fashion) and potential dependent applications or libraries are responsible for building with whatever version they like, then I could imagine the following scenario:

Have the build system for graph and network tell them where to find core (e.g. via a compiler include path).  Define two build targets, "standalone" and "dependency", where "standalone" is based on "dependency" and adds the include path to point to the local core sub-module.

Introduce an extra dependency: studio on core.  Then, studio builds core, sets the include path to its own copy of the core sub-module, then builds graph and network in "dependency" mode.

The resulting folder structure looks like:

```<code>studio/
studio/libs/                    (sub-module depth: 1)
studio/libs/core/
studio/libs/graph/
studio/libs/graph/libs/         (empty folder, sub-modules not fetched)
studio/libs/network/
studio/libs/network/libs/       (empty folder, sub-modules not fetched)
</code>```

However, this requires some build system magic (I'm pretty confident this can be done with CMake) and a bit of manual work on the part of version updates (updating graph might also require updating core and network to get a compatible version of core in all projects).

Any thoughts on this?

答: I would flatten it down to have sub-module depth of just one and have a repository which would hold all the modules as sub-modules and nothing else apart from README and  the build scripts. There would be a separate build script for each of the packages linking its dependencies. Otherwise you can have a separate repo for a package.</p>


答: The problem with Git as summarized by Joel Spolsky is that Linus Torvalds refuses to add any features to Git that would benefit Windows. So you'd get less traction with Windows guys if you merge toward the Git arm. And Torvalds evidently doesn't want to support Windows stuff so merging toward Mercurial wouldn't work either. So what do we do? Meet in the middle? How and where?</p>

Title: What can be done to stop losing resources and unify Mercurial and Git?

Body:
Both Mercurial and Git were created as a replacement for the same program and to solve the same problem which you can read about in Martin Beckett's answer to How did Git and Mercurial develop so similarly at the same time? question.

These two tools are very similar and borrow from each other according to Scott Chacon in his
Hg and Git: Can't we all just get along? presentation at PyCon 2010.

I think we, the people, do waste huge amount of resources by having these two tools which do the same, yet operate differently. Is it possible to unify Mercurial and Git and stop wasting our resources? What actions should be taken?


问:
What are the legal considerations when forking a BSD-licensed project?
I'm interested in forking a project released under a two-clause BSD license:

Copyright (c) 2010 {copyright holder}
  All rights reserved.

Redistribution and use in source and binary forms, with or
  without modification, are permitted provided that the following
  conditions are met:

(1) Redistributions of source code must retain
  the above copyright notice, this list of conditions and the disclaimer
  at the end. Redistributions in binary form must reproduce the above
  copyright notice, this list of conditions and the following disclaimer
  in the documentation and/or other materials provided with the
  distribution.

(2) Neither the name of {copyright holder} nor the names of its
  contributors may be used to endorse or promote products derived from
  this  software without specific prior written permission.

DISCLAIMER

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

I've never forked a project before, but this project is very similar to something that I need/want. However, I'm not sure how far I'll get, so my plan is to pull the latest from their repository and start working. Maybe, eventually, I'll get it to where I want it, and be able to release it. Is this the right approach?

How, exactly, does this impact forking of the project? How do I track who owns what components or sections (what's copyright me, what's copyright the original creators, once I start stomping over their code base)? Can I fork this project? What must I do prior to releasing, and when/if I decide to release the software derived from this BSD-licensed work?

答:
To answer your questions:

Is this the right approach?  Maybe, if your changes are generally useful I would attempt to contribute to the project instead of forking.

Can I fork this project? Yes. The BSD license allows you to fork it.  You don't need to ask permission to fork.

How to track changes...? Add your name to the copyright notice for the files you changed.  And make sure it is in files you add.  If you want more details your SCM tool will keep track of who changed what.

What must I do before releasing...? If you are releasing the source the copyright notices in the source is enough if you are releasing binaries make sure the original copyright notice is in your supporting documentation.


问:
what is the purpose of arrows?
I am learning functionnal programming with Haskell, and I try to grab concepts by first understanding why do I need them.

I would like to know the goal of arrows in functional programming languages. What problem do they solve? I checked http://en.wikibooks.org/wiki/Haskell/Understanding_arrows and http://www.cse.chalmers.se/~rjmh/afp-arrows.pdf. All I understand is that they are used to describe graphs for computations, and that they allow easier point free style coding.

The article assume that point free style is generally easier to understand and to write. This seems quite subjective to me. In another article (http://en.wikibooks.org/wiki/Haskell/StephensArrowTutorial#Hangman:_Main_program), a hangman game is implemented, but I cannot see how arrows makes this implementation natural.

I could find a lot of papers describing the concept, but nothing about the motivation.

What I am missing?

答:
This is kind of a "soft" answer, and I'm not sure if any reference actually states it in this manner, but this is how I've come to think of arrows:

An arrow type A b c is basically a function b -> c but with more structure in the same way that a monadic value M a has more structure than a plain old a.

Now what that extra structure happens to be depends on the particular arrow instance you're talking about.  Just as with monads IO a and Maybe a each have different additional structure.

The thing that you get with monads is an inability to go from an M a to an a.  Now this may seem like a limitation, but it's actually a feature: the type system is protecting you from turning a monadic value into a plain old value.  You can only make use of the value by participating in the monad via >>= or the primitive operations of the particular monad instance.

Likewise the thing that you get from A b c is an inability to construct a new b-consuming c-producing "function".  The arrow is protecting you from consuming the b and creating a c except by participating in the various arrow combinators or by using the primitive operations of the particular arrow instance.

For example the signal functions in Yampa are roughly (Time -> a) -> (Time -> b), but additionally they have to obey a certain causality restriction: the output at time t is determined by the past values of the input signal: you can't look into the future.  So what they do is instead of programming with (Time -> a) -> (Time -> b), you program with SF a b and you build your signal functions out of primitives.  It so happens that since SF a b behaves a lot like a function, so that common structure is what's called an "arrow".

Title: what is the purpose of arrows?


答: Ruby's ActiveRecord library and Groovy's GORM use "id" for the surrogate key by default.  I like this practice.  Duplicating the table name in each column name is redundant, tedious to write, and more tedious to read.  </p>


答:
The common thing I see to handle this is basically using some kind of version control and when a file is changed by a large amount, adding a copyright header.

For instance, in OpenBSD I believe they follow a convention like this:

```
--top of file--
[copyright header of recent "major" editor]

[copyright header of previous major editor]

[copyright header of creator]
```

(where copyright header is BSD license or whatever)

This handles the copyright issue for the most part. Basically anytime a major edit is done on a file, a copyright header will be added. Major is subjective, but usually involves more than trivial refactoring or porting.

Title: What are the legal considerations when forking a BSD-licensed project?

Body:
I'm interested in forking a project released under a two-clause BSD license:

Copyright (c) 2010 {copyright holder}
  All rights reserved.

Redistribution and use in source and binary forms, with or
  without modification, are permitted provided that the following
  conditions are met:

(1) Redistributions of source code must retain
  the above copyright notice, this list of conditions and the disclaimer
  at the end. Redistributions in binary form must reproduce the above
  copyright notice, this list of conditions and the following disclaimer
  in the documentation and/or other materials provided with the
  distribution.

(2) Neither the name of {copyright holder} nor the names of its
  contributors may be used to endorse or promote products derived from
  this  software without specific prior written permission.

DISCLAIMER

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

I've never forked a project before, but this project is very similar to something that I need/want. However, I'm not sure how far I'll get, so my plan is to pull the latest from their repository and start working. Maybe, eventually, I'll get it to where I want it, and be able to release it. Is this the right approach?

How, exactly, does this impact forking of the project? How do I track who owns what components or sections (what's copyright me, what's copyright the original creators, once I start stomping over their code base)? Can I fork this project? What must I do prior to releasing, and when/if I decide to release the software derived from this BSD-licensed work?

Body:
The common thing I see to handle this is basically using some kind of version control and when a file is changed by a large amount, adding a copyright header.

For instance, in OpenBSD I believe they follow a convention like this:

--top of file--
[copyright header of recent "major" editor]

[copyright header of previous major editor]

[copyright header of creator]

(where copyright header is BSD license or whatever)

This handles the copyright issue for the most part. Basically anytime a major edit is done on a file, a copyright header will be added. Major is subjective, but usually involves more than trivial refactoring or porting.


答: Drools started off by being based on CLIPS. CLIPS was an older "production system", and like all production systems is a forward chaining system. A lot of research on Rete has "gone dark" as the originator ended up going to work for companies where the algoritms were intellectual property. Rete version 3 is owned by the folks who make FICO scores, so yeah, it is "battle proven". </p>

Title: The relation between Business Rules Engines and Constraint Programming languages

Body:
If one looks at (perhaps older) manuals of Drools or some other rule engines,
one of the illustrations of their added value is solving puzzles such
as the Miss Manners puzzle (listed in the Drools Documentation). Now, such puzzles are naturally formulated
and solved using Prolog or the more recent Constraint Programming languages, and
one wonders why would anyone use Drools for this purpose. The added value
which Prolog and CPL give in this case is their ability to naturally
formulate the puzzle as a set of logical predicates and to automatically
search the space of solutions (with CPL being more efficient in this respect).
But what is the added value of product such as Drools (I mean besides of
the bells and whistles of taking, for example, an Excel file and translating
it into a set of rules)?

More specifically, Prolog implements backtrack search, CLP implements backtrack search
with constraint propagation, and therefore instead of searching, so to speak, the
whole Cartesian product of spaces for individual variables, they prune away large portions
of this product space. This is what makes them effective and useful. Both Prolog and
CLP are discussed amply in the literature.

On the other hand, while it is clear that Rete algorithm caches the set of rules
in the form of some data structure(s), thus (to my understanding) making it more
effective to evaluate the output if some of the inputs have changed, and giving
means to effectively update this data structure for incremental changes, it is
difficult (for me) to understand the basic idea, and even more so, its effectiveness (compared to what? to Prolog? to CLP)? Unfortunately, it is hard to find good
references that view Rete algorithm in this wider context.

The documentation of Drools is unfortunately not very informative in this respect.
The most I could find was "The Rete algorithm, Leaps algorithm, and its descendants such as Drools' Reteoo (and Leaps), provide very efficient ways of matching rule patterns to your domain object data. These are especially efficient when you have datasets that do not change entirely (as the rule engine can remember past matches). These algorithms are battle-proven". Very efficient - compared to what? Battle proven - could one point to real-world
applications?

I would appreciate it if one could throw some more light on this subject or give a valid
reference.


问:
Is it necessary to understand what's happening at the hardware level to be a good programmer?
I'm a self-taught programmer, just in case this question is answered in CS 101. I've learned and used lots of languages, mostly for my own personal use, but occasionally for professional stuff.

It seems that I'm always running into the same wall when I run into trouble programming. For example, I just asked a question on another forum about how to handle a pointer-to-array that was returned by a function. Initially I'm thinking that I simply don't know the proper technique that the designers of C++ set up to handle the situation. But from the answers and discussions that follow I see that I don't really get what happens when something is 'returned'.

How deep a level of understanding of the programming process must a good programmer achieve?

答:
You're not talking about the hardware level, you're talking about what the compiler really does with what you tell it to do.

You most certainly do need this level of understanding in order to figure out what went wrong when it's not obvious, especially when dealing with a memory stomp situation.


答:
Understanding Program Memory != Understanding Hardware

Understanding the Memory Hierarchy == Understanding Hardware

To answer your generic question: It depends. It can't hurt to understand hardware, but understanding it will not help in all cases.

Based on your example, you just need to understand more about how memory is divided up and how it is organized when you are running a program. Understanding hardware will not help you in this regard, because memory (as visible to a program) does not even truly represent the hardware thanks to the magic of virtual memory.

If you were curious about performance issues based on the order in which you access memory, NOW you would benefit from understanding hardware, the memory heirarchy, cache misses, page faults, and all the glorious wonderful goodness that comes from hardware.

Title: Is it necessary to understand what's happening at the hardware level to be a good programmer?

Body:
I'm a self-taught programmer, just in case this question is answered in CS 101. I've learned and used lots of languages, mostly for my own personal use, but occasionally for professional stuff.

It seems that I'm always running into the same wall when I run into trouble programming. For example, I just asked a question on another forum about how to handle a pointer-to-array that was returned by a function. Initially I'm thinking that I simply don't know the proper technique that the designers of C++ set up to handle the situation. But from the answers and discussions that follow I see that I don't really get what happens when something is 'returned'.

How deep a level of understanding of the programming process must a good programmer achieve?


答:
Different languages work at different levels of abstraction from the hardware.  C and C++ are very low-level.  Scripting languages, on the other hand, require you to know less about the underlying detail.

However, I would still say that in all cases, the more you know, the better of a programmer you'll be.  Part of programming is being able to juggle multiple levels of abstraction at the same time.

If you're programming in C++, you do need to have a pretty good understanding of how a modern CPU works, at least at the level of abstraction that the compiler works at.  (There are things going on inside the CPU that are transparent to the compiler, too).


问:
Should a development machine be inside a VM?
This post by Rob Conery (note the slug) says that development environment should be run inside a virtual machine. I see what he's saying and tend to agree, but still feel a little uneasy. Now that virtualization is so mature that even production systems run inside VMs speed is pretty much a non-issue, but as I say something bothers me here.

What's your take on virtualizing your development machine? Have you already done so? If you did, any pitfalls or gotchas along the road?

答:
I used them at the previous company. Several third party controls did not co-exist well with other versions by the same company. I also used a couple for testing and debugging other operating systems (XP vs Vista vs 7). One virtual had VB6 and VS2003 for the older products. Yes, on a typical developer's machine it can be slow and cumbersome, but I had a few spare hard drives that I "donated" and put the virtuals on their own hard drives on their own drive controllers. I was the last guy to keep using virtuals, and for some bugs, only I could work on them (due to operating system and component concerns).

Some of the guys got burned installing beta software, and some of the betas from MS could not be removed, so they were forced to use virtuals until they reformatted their hard drives.

For developing in virtuals, my advice is to get something with a min of 8GB of RAM. 16 or more would be better, as you'll find any visual studio equipped virtual needs about 1.5GB of the host's RAM to run at speeds above "glacial". Also, get lots of hard drives when buying a computer. For drives you pick out of your spare hardware pile, look for ones at least 2x the size of the VHD you will be running.


问:
Delegate vs Interfaces-Any more clarifications available?
After reading the article-
When to Use Delegates Instead of Interfaces (C# Programming Guide),
I need some help  understanding the below given points, which I found to be not so clear (for me).
Any examples or detailed explanations available for these?

Use a delegate when:

An eventing design pattern is used.

It is desirable to encapsulate a static method.

Easy composition is desired.

A class may need more than one implementation of the method.

Use an interface when:

There are a group of related methods that may be called.

A class only needs one implementation of the method.

My Questions are,

What do they mean by an eventing design pattern?

How the composition turns out to be easy if a delegate is used?

if there is a group of related methods that may be called,then use interface-What benefit it has?

if a class only needs one implementation of the method,  use interface-how is it justified in terms of benefits?

答:
If my memory of .NET still holds, a delegate is basically a function ptr or functor.  It adds a layer of indirection to a function call so that functions can be substituted without the calling code having to change.  This is the same thing an interface does, except that an interface packages multiple functions together, and an implementor has to implement them together.

An event pattern, broadly speaking, is one where something responds to events from elswhere (such as Windows messages).  The set of events is usually open ended, they can come in any order, and are not necessarily related to each other. Delegates work well for this in that each event can call a single function without needing a reference to a series of implementing objects that might also contain numerous irrelevant functions. In addition (this is where my .NET memory is vague), I think multiple delegates can be attached to an event.

Compositing, though I am not very familiar with the term, is basically designing one object to have multiple sub-parts, or aggregated children to which the work is passed down.  Delegates allow the children to be mixed and matched in a more ad-hoc way where an interface might be overkill or cause too much coupling and the rigidity and fragility that comes with it.

The benefit to an interface for related methods is that the methods can share the state of the implementing object.  Delegate functions cannot so cleanly share, or even contain, state.

If a class needs a single implementation, an interface is more suitable since within any class implementing the whole collection, only one implementation can be done, and you get the benefits of an implementing class (state, encapsulation. etc).  If the implementation might change due to runtime state, delegates work better because they can be swapped out for other implementations without effecting the other methods.  For instance, if there are three delegates that each have two possible implementations, you would need eight different classes implementing the three-method interface to account for all the possible combinations of states.


问:
Do you need to buy Visual Studio to develop/deploy an ASP.NET web application?
Since the .NET Framework SDK is free, is Visual Studio anything more than an IDE? If yes, do I need to buy Visual Studio to deploy my ASP.NET web application (written in C#)? I'm using MySQL for the database.

I'm a student that is going to graduate college soon, and I'm exploring technologies for a web application that I'm building for a startup.

答:
No, you don't need Visual Studio to build web applications - you can use the SDK directly if you wish.

However, Visual Studio also exists in free Express editions. These are stripped-down single-language/single-platform versions of Visual Studio (for example, there is no support for plugins), but otherwise completely usable for building your applications.

In your case, you can use Visual Web Developer Express to work with ASP.NET applications.


答:
The cloud comes in a variety of shapes and sizes. Amazon is one end of the spectrum (lots of cheap unreliable machines that you can build a reliable system out of) through to private clouds that replace dedicated servers.

We've enjoyed the SLAs we get with a hosted private VMWare cloud (you get guaranteed Ghz, disk io and memory) plus all the HA/failover. A server is no longer dependent on one mainboard/power supply/rack/etc. We also added the DR option to replicate the virtual machines to another DC.

It isn't the cheapest cloud solution but you never select the cheapest option for a business systems, right?

And the P2V tools mean you can easily take an image of an existing physical server (while it is running), upload it and then deploy. Then use rsync or similar to update it before the cutover. No tedious re-installing and configuring.


答:
Twenty years ago it was important, but not so much now - there are a lot more abstraction layers between software and modern hardware.

It is useful to know things like needing multiple threads to take advantage of multiple cores or that using more memory than exists on the system is a bad thing, but beyond that you don't really need it unless it is your job to write those abstraction layers.

The rest of your question suggests that you may be more concerned with the compiler than the hardware, which is a bit different. You may run into cases where it is important, but these tend to be either trivial (infinite recursion doesn't work very well) or the kind of edge cases where you can feel good about solving it but will likely never run into the same problem again.


答:
No. Nobody understands what's going on at the hardware level.

Computer systems are like onions -- there are many layers, and each one depends on the layer underneath it for support. If you're the guy working on one of the outer layers, you shouldn't care too much what happens in the middle of the onion. And that's a good thing, because the middle of the onion is always changing. As long as the layer or layers that support your particular layer continue to look the same and support your layer, you're good.

But then again...

Yes. I mean, you don't need to understand what's really happening inside the onion, but it helps a lot to have a mental model of what the inside of a typical onion looks like. Maybe not the deepest part, where you've got gates made up of transistors and such, or the next layer or two, where you've got microcode, a clock, instruction decoding units etc. The next layers, though, are where you've got registers, the stack, and the heap. These are the deepest layers where you have a lot of influence over what happens -- the compiler translates your code into instructions that run at this level, and if you want you can usually step through these instructions and find out what's "really" happening.

Most experienced programmers have a slightly fairy-tale version of these layers in their head. They help you understand what the compiler is talking about when it tells you that there was an "invalid address exception" or a "stack overflow error" or something like that.

If you're interested, read a book on computer architecture. It doesn't even need to be a particularly new book -- digital computers have been working in approximately the same way for a long time. The more you learn about the inside of the onion, the more astounded you'll be that any of this stuff works at all! Learning (approximately) what's going on in the lower layers makes programming both less mysterious and, somehow, more magical. And really, more fun.

Another thing you might look into is embedded onions. Er, I mean embedded systems. There are a number of embedded platforms that are pretty easy to use: Arduino and BASIC Stamp are two examples. These are basically small microprocessors with a lot of built-in features. You can think of them as onions with fewer layers than your typical desktop PC, so it's possible to get a pretty thorough understanding of just what's going on in the whole system, from the hardware on up to the software.


答:
I don't consider it bad practice. Consistency is king, as usual.

I think it's all about context. In the context of the table on its own, "id" just means exactly what you expect, a label to help uniquely identify it against others that might otherwise be (or appear) identical.

In the context of joins, it's your responsibility to construct the joins in such a way as to make it readable to you and your team. Just as it is possible to make things look difficult with poor phrasing or naming, it is equally possible to construct a meaningful query with effective use of aliases and even comments.

In the same way a Java class called 'Foo' doesn't have its properties prefixed by 'Foo', don't feel obliged to prefix your table IDs with table names. It is usually clear in context what the ID being referred to is.


答:
It helps a lot to know and understand the abstraction presented by the hardware, and a little of the general idea about how that illusion is created -- but trying to truly understand how modern hardware really works is a tremendous amount of work from which you're likely to see only minimal return.

If you'll pardon a minor diversion: this reminds me of something I noted a few years ago. Decades ago (up through the late 1970's or so), most people thought computers were one step short of magical -- hardly affected by the laws of physics, capable of all manner of things that made little real sense, and so on. At the time, I spent a fair amount of time trying (mostly unsuccessfully) to convince people that no, they weren't magic. They were really fairly ordinary machines that did a limited number of things very quickly and dependably, but were otherwise extremely mundane.

Nowadays, most people's view of computers have changed. They're now fairly ordinary -- to the point that quite a few very ordinary people have a practical grasp of them. Just for example, a while back while I was having supper, I saw/heard a waiter and waitress on their break discussing what she should get in her new computer. The advice he was giving was entirely reasonable and realistic.

My view of computers has changed too though. I've gone to Hot Chips, and before that the Microprocessor Forum going back to the mid-1990's or so. I probably know more about microprocessor hardware than at least 99% of programmers -- and knowing what I do, I'll say this: they're not ordinary anymore. They do almost break the laws of physics. I've done a lot of low level testing and I can say this for sure: getting past the illusion created by the CPU and into the level of showing how the hardware really works is often incredibly difficult. I wish I could post a picture of one of our setups with a computer buried under cables from no fewer than 4 logic analyzers just to properly measure one aspect of how caching works on a modern CPU (not to mention some truly fastidious programming to ensure that what we measured was exactly what the CPU was doing, and nothing else).


问:
Does business logic really belong on the server?
A typical stack for a web application is a database, a server with server-side code, and a user with a browser with HTML/CSS/JavaScript.

Before extensive AJAX, MVC in which the controller was the server-side code rulled.  A server had to route answer requests for Dynamic web pages (i.e. templated html solutions like JSP and ASP).  The server to coordinate the calls to the database and decide which dynamic page to use to answer the page request.  The result of all of this is that server ended up containing the business logic, even though business logic isn't strongly tied to the idea of serving pages.

Now that we are moving to "Web 2.0" a server servers static pages that use JavaScript to fill themselves and change what they are presenting.  The can be in the JavaScript.  The JavaScript often implements a RESTful service meaning that it is specifying database query.

So the server is left to the roles of serving actual files and answering AJAX calls.  And answering AJAX calls is merely session management and providing security.  And really, what a user should even be able to see is data that should be specified in the database.

So from there, should the server be relegated to the role of a dumb intermediary that only occasionally does something like send out an email or fire off a webservice?  Could business logic all live in JavaScript (when it is not secret) or live in stored procedures when it is?

Will it make sense to maybe even combine servers and databases or make ERP solutions like SAP function as servers?

答:
Business logic almost always has to run on a server you control, for security reasons.  If by "server" you mean "web server", then I agree, it doesn't need to have almost any business logic.  But you almost always need an application server with the business logic, whether that's inside a database or a web server or is separate and called by the web server.

There are real world applications where the web server does nothing but expose the API of the application server via web services or JSON.

Even prior to Web 2.0 and AJAX it really wasn't considered a best practice to mix your business logic with ASP pages.  It was considered better to have an independent business logic and to have the server portion of the presentation logic be in ASP, JSP, or whatever.  So the real change from web 2.0 is that the presentation layer can be entirely in javascript.  I kind of prefer that, personally.


答:
The JavaScript often implements a RESTful service meaning that it is
  specifying database query.

This is where you got it wrong.  REST is not CRUD.

The resources exposed by REST are not your database records; they're fully managed objects that behave according to your business logic.  When the server receives a POST or PUT, it shouldn't just validate and store.  It has to perform anything that's appropriate for the application.

Simple example: a twitter-like app receives tweets as POST messages on a given container.  The server then analyzes the context ("who are you?", "which channel is this?") and content ("any hashtags?", text indexes, etc.) and stores all this in the respective queues.  Probably adds a reference directly to all your followers.

That's a lot of work beyond simply adding the resource to the container, it's all defined by your business logic.  And it belongs on the server.

Title: Does business logic really belong on the server?

Body:
A typical stack for a web application is a database, a server with server-side code, and a user with a browser with HTML/CSS/JavaScript.

Before extensive AJAX, MVC in which the controller was the server-side code rulled.  A server had to route answer requests for Dynamic web pages (i.e. templated html solutions like JSP and ASP).  The server to coordinate the calls to the database and decide which dynamic page to use to answer the page request.  The result of all of this is that server ended up containing the business logic, even though business logic isn't strongly tied to the idea of serving pages.

Now that we are moving to "Web 2.0" a server servers static pages that use JavaScript to fill themselves and change what they are presenting.  The can be in the JavaScript.  The JavaScript often implements a RESTful service meaning that it is specifying database query.

So the server is left to the roles of serving actual files and answering AJAX calls.  And answering AJAX calls is merely session management and providing security.  And really, what a user should even be able to see is data that should be specified in the database.

So from there, should the server be relegated to the role of a dumb intermediary that only occasionally does something like send out an email or fire off a webservice?  Could business logic all live in JavaScript (when it is not secret) or live in stored procedures when it is?

Will it make sense to maybe even combine servers and databases or make ERP solutions like SAP function as servers?


答:
My concerns with this approach may be due to misunderstanding of your design, so please feel free to shoot me down.

however, think about the scaleability, maintanability and security of the product.

If your product grows massively, the database becomes the bottleneck, so whilst "performance" suggests putting business logic into stored procedures, it puts additional CPU load on your database server, bringing forward the day when the server reaches max capacity. Unlike webservers, ACID databases do not easily scale up by using parallel hardware.  If your product will never be that successfull, this is not an issue.

The thought of maintaining business logic in javascript running on webbrowswers, where different browsers will requrire different javascriopt, multiple versions of browsers, etc...  Why make this issue any more complicated than it already is?

As Javiar has said though, using a REST approach as a database API for your product is really not sensible. Its a benefit of a REST interface is that other people will then think of different ways to use and query your REST interface.  However this is public post business logic resources and not low level table record resources.  The thought of making such low level data queries available over the HTTP api sounds like a security nightmare.


答:
While there are many schools of thought on this, and certainly no one way can be called "the right way" universally, while all others are "the wrong way" universally, there are a number of reasons to isolate business logic on the server side, and access those objects and services through a RESTful service.

The short answer is that it's mostly about risk management, and performance monitoring and improvement.

In detail:

The number 1 paramount reason is security.  Clients should never be trusted to submit anything other than garbage to the server, and by keeping the security aspects server side, you isolate the potential risk of a rogue user damaging your system. Remember, Javascript is completely client side, and trivially changeable, so you CANNOT TRUST THE OUTPUT.

The number 2 reason is separation of concerns.  Your javascript programmer may not be an expert on security, and your security guru may not be that great at Javascript.  By isolating the business logic from the presentation logic, you avoid crossing these concerns, as the javascript will not be allowed to access resources beyond its permission levels, and be given errors, the handling of which is within the prevue of the Script Programmer.  Likewise, the Security guy won't be debugging Javascript to see how security is maintained.

The number 3 reason is performance.  Business logic can potentially be demanding of server and database resources.  By keeping that logic isolated from your UI elements, you can then scale out just that portion of your application, making it that much easier to address bottlenecks.  Additionally, it's much easier to isolate which business process is loading your system or database backends if the business processes are executed on the server.

A corollary here is that often several business processes will use the same data, and so you can implement caching on the server side to reduce overall system load that might not be possible/secure to give clients side code access to.

Finally, I would propose that in order to maintain ACID standards, Business Logic really does need to be on the server.  I remember maintaining a billing product that ran in the web browser, with only a database connection to the server.  If the daily billing (which could take an hour or more on a good day!) were interrupted, say, by the browser being closed or crashing, it could take several hours to sort out the mess it made of the database, which was left in an inconsistent state.  Remember, this also involved credit cards, so the billing records had to be checked against the processor too!

Server side business logic is mostly trivial to ensure ACID updates, as there any frameworks for any language to maintain transactions, either at an application or database level.  If you're doing this via multiple updates from a web client... you're going to get inconsistent state at some point, and it's likely going to affect your application.

While it can be tempting to think of RESTful services as simply a way to access the database, you shouldn't fall into this trap, as it's a good recipe for disaster.  The object model you expose via a RESTful service can be related to your database, but should really encapsulate your business logic instead of just using it as a CRUD engine.


答:
If you do decide to learn a bit of assembler, you should probably learn something like 6502 assembler on a Commodore 64 (emulated, of course), or 68000 on an Amiga.

You can get some idea of the Commodore 64 here...

http://thepiratebay.org/torrent/4609238/Tag3-Saal2-Slot16_00--ID2874-the_ultimate_commodore_64_talk-Main

The classic everything-you-need-to-know book is the one described here...

http://reprog.wordpress.com/2010/03/12/programming-books-part-3-programming-the-commodore-64/

You can probably find a PDF scan if you look around.

IMO, 6502 is easier than Z80, and 68000 is easier than 8086 - more regular instruction sets etc.

But the CPU is only one aspect of the hardware. Also, a modern CPU is a massively different beast, and it does things that are transparent even from the point of view of compilers - such as presenting a virtual address space.

A particular advantage of the 6502 on the C64 is that not only is the CPU simple, but there's some very simple to hack-around-with hardware too. I used to have great fun playing around with the SID music chip.

So - it's probably a worthwhile exercise if you don't spend too much time on it. I learned 6502 assembler as my second language when I was about 14, right after Commodore Basic. But mostly it's getting that very simple working model so that you can add more sophisticated ideas to it with a minimum of misunderstanding.

Some useful things you can learn working in assembler...

How CPU registers work.

How memory addressing works, including indirection.

How the CPU stack works.

How bitwise logic works.

How the CPU controls I/O devices.

How interrupts work.

One particular reason I'd recommend it is to get a better intuition of the way simple steps operate entirely deterministically and mechanically and utterly without intelligence or common sense. Basically getting used to the imperative execution model in it's purest and most stubbornly ignorant form.

Precisely how useful it is to know most of those things now, though, is a difficult question.

One thing you won't learn is how to play well with a memory heirarchy. Those old machines mostly had a simple memory model with no layers of cache and no virtual memory. You also won't learn much about concurrency - they were certainly ways to handle that, but it mostly meant interrupts. You didn't need to worry about mutexes etc.

Sometimes, a mental model of how these things once worked, or of how assembler works, can even mislead. For example, thinking of a C pointer as an address can lead to undefined behaviour issues. A C pointer is normally implemented as an integer containing an address, but there's no guarantee that that's strictly true. For example, on some bizarre platforms, different pointers may point into different address spaces. This becomes important when you want to do arithmetic or bitwise-logic with two pointers.

Unless you have one of those bizarre platforms, you may not think you care about that - but compilers these days are more and more likely to exploit standards-undefined behaviour for optimisation.

So a mental model of the system architecture can be useful, but it's still important to code to the language spec., not to a hypothetical model that your language and platform may not respect.

Finally, a lot of useful mental model stuff comes from getting an idea of how compilers generate code - and code generation for modern languages is very different from the quite trivial compilers available back then.

This is a favorite book of mine for that...

http://dickgrune.com/Books/MCD_1st_Edition/

Along with the stuff about parsing and ASTs etc, it covers code generation for a range of language paradigms - imperative, OOP, functional, logic, parallel and distributed - and also for memory management. If you want to know how polymorphic method calls work without getting bogged down in CPU instruction set details, a book like this one is your friend - and there's a new edition due out soon.


问:
In what situations is it a bad idea to use open source code for a corporate project?
Are there any situations where it may not be a good idea to use the code of an open source project, even if your company might allow you to do so?

Some cases that I think might be valid include:

The code may be implemented in a different languages.

It is not portable

It may need some other close-source libraries

What might be some other reasons?

答:
The most obvious to me are...

When the terms of the license are incompatible with the way the company will want to deploy the code - e.g. the GPL may require you to distribute other code in your project which your company may not even have the right to distribute.

When the open source code overlaps strongly with your companies core expertise. If your companys core expertise is designing games and graphics rendering engines, for example, it makes little sense to use Ogre3D. See http://www.joelonsoftware.com/articles/fog0000000007.html

When the open source code is badly written, badly documented and/or horribly buggy. If it'll take you longer to figure out how to use and fix the code than to roll your own, where's the benefit?

It may also be an issue if you suspect the open source project will take a different direction in the future than the one you need it to take. You have the option to maintain your own fork, but then you lose most of the longer-term benefits of open source anyway - the further your fork diverges from the original project, the less likely it is that others will find and fix your bugs for you and contribute useful new features.


问:
ternary or something similar for choosing function?
I posted this question on stackoverflow and it got a poor reception. In reality, the problems I'm facing are minor and any workaround can be considered impractical. However, I believe it might be of general interest in the abstract computer science domain, so I'm giving it a go here.

I'm working with Drupal's automated testing in PHP. It's a class that has two methods I'm concerned about: pass() and fail(). Each one produces a separate line on a results page indicating whether a particular operation passed or failed, e.g.

```<code>if ( $value == "expected_value" ) {
  $this->pass("Name of Test");
} else {
  $this->fail("Name of Test");
}
</code>```

(The reason drupal does it this way is so that in the results, you can see "Name of Test" in a green bar if it passed, and in a red bar if it failed. In other words "Testing Feature A: failed" or "Test of Feature A: passed". Of course you can put two different messages in there, but in my situation, I want to put the same message in)

What I notice about the above is that it seems verbose, in that I repeat the same message twice. It seems to me that there should be a way of expressing this where I only declare the message once. Of course I could put it in a variable, but that takes up extra space and I pass it twice, also.

I'd like to do something like ternary assignment, only instead where I decide which function to call. Is there a way I can define this logic while only expressing Name of Test one time?

Something like:

```<code>$function = ($value == "expected_value") ? "pass" : "fail" ;
$this->$function("Name of Test");
</code>```

Is this the most concise, elegant way I can phrase this logic? I tried

```<code>$this->(($value == "expected_value") ? "pass" : "fail")("Name of Test");
</code>```

But I got a parse error. Is there a way to get it down to one line, like ternary assignment?

Edit Here's the best formulation of my question to date: "What's a syntax I can use, in any language or pseudo-code , to express this without saying Name of test twice?"

I feel like I should be able to express this logic without saying Name of Test twice (anywhere -- including within another function that I call elsewhere in code). It seems that PHP does not allow me to express this in this way, so I'm looking for examples in other languages (and people have already posted C, javascript, and python examples) that allow you to concisely express this without repeating yourself.

答:
Since you said in a comment you were curious about other languages as well, this works in javascript.

(value == "expected_value" ? pass : fail) ("Name of Test");