答: As your code base grows, you will want to add a test suite. My experience is that this should be done sooner rather than later, and that your nightly (or whatever) build should run all the tests every time. Start small, the auto-generated XML is probably fine. When you're scared to change something for fear of breaking something else, that's a good incentive to write up a few test cases.</p>

Title: Convince a lone developer to use a separate build tool instead of the IDE one-click build

Body:
In my years of programming Java and more recently Scala, I've never used Ant, Maven, Gradle or any of those build tools for Java.  Everywhere I've worked there was a build manager who took care of all of that -- I'd compile locally with the IDE for development and unit testing, then check in the source code and notify the build manager who did what was necessary to compile everybody's files for the shared environment.

Now that I'm between contracts I've been working on my own self-funded project and it's getting to the point where it could be good enough to actually make money.  I even have a potential investor lined up and plan to show them a beta version in the next few weeks.

But all along I just click the build button on the IDE, and it creates the Jar file and it works just fine.  Of course, the conventional wisdom suggests that I "should" be writing my own Ant/Maven/Gradle scripts and using that instead of the IDE, but what are the concrete advantages of that in my situation (working alone)?

I've done some reading about how to use those build tools, and it just looks like I'd be writing hundreds of lines of XML (or Groovy or whatever) to do to what the IDE does in one click (the IDE-generated Ant XML for the project is over 700 lines).  It just looks error-prone and time-consuming and unnecessary for my situation.  Not to mention the learning curve, which would take away time from all the other work I'm doing to get the product ready to show people.

OwnerDisplayName: tripleee


问:
Convince a lone developer to use a separate build tool instead of the IDE one-click build
In my years of programming Java and more recently Scala, I've never used Ant, Maven, Gradle or any of those build tools for Java.  Everywhere I've worked there was a build manager who took care of all of that -- I'd compile locally with the IDE for development and unit testing, then check in the source code and notify the build manager who did what was necessary to compile everybody's files for the shared environment.

Now that I'm between contracts I've been working on my own self-funded project and it's getting to the point where it could be good enough to actually make money.  I even have a potential investor lined up and plan to show them a beta version in the next few weeks.

But all along I just click the build button on the IDE, and it creates the Jar file and it works just fine.  Of course, the conventional wisdom suggests that I "should" be writing my own Ant/Maven/Gradle scripts and using that instead of the IDE, but what are the concrete advantages of that in my situation (working alone)?

I've done some reading about how to use those build tools, and it just looks like I'd be writing hundreds of lines of XML (or Groovy or whatever) to do to what the IDE does in one click (the IDE-generated Ant XML for the project is over 700 lines).  It just looks error-prone and time-consuming and unnecessary for my situation.  Not to mention the learning curve, which would take away time from all the other work I'm doing to get the product ready to show people.

答:
Here are my top 4 reasons to use build tools:

dependency handling (avoid errors)

testing (your change did not break other modules - much easier to test)

safe commits

easier to deploy local distributable (no one has time in QA env to wait for the builder to build your project and its dependencies)

OwnerDisplayName: Gigatron

ContentLicense: CC BY-SA 3.0

OwnerDisplayName: RoiG


答:
In the book Pragmatic Programmer, Andrew Hunt and David Thomas say that 'checkout-build-test-deploy' should be a single command.(Chapter : Pragmatic Projects).   You wrote..

I even have a potential investor lined up and plan to show them a beta
  version in the next few weeks

Then, I am sure your team is going to grow.. It is even more important to have automatic test-deploy abilities done.

The large XML (script) you saw, is typically a one time job. Most of the time, the same scripts can be uses across  many projects.

It is  not clear how large is the project. If your integrated tests/acceptance tests takes large CPU/memory you may consider using another machine as your test server. You could also deploy host of tools to analyse the source code/byte code.

OwnerDisplayName: StackTrace


问:
How close have we gotten to automating code writing?
And I don't mean Autocomplete or automatic code snippets as inserted by modern day editors, or polymorphic code. But what is the state-of-the-art in programs that can go through given inputs and types and information of the desired outputs and output a valid piece of code in a language of choice. I am aware of Genetic Programming, Gene Expression Programming but I don't know of any other efforts. Also googling doesn't turn up much.

Is anyone aware of any advancements on this front?

Edit: When i say "output a valid piece of code", I mean an AI or something similar working out the logic and the flow of control and implement it in an imperative language. Imperative language only, since that's the tough part. Nevertheless, if you know of any new languages being developed to support this kind of idea, please do mention, as maybe our current set of languages are not suitable for the kind of early AI we may first chance upon.

答:
One of the most discussed approach to automated code generation is "MDA" a.k.a Model driven architecture. Mostly (but not necessarily) one puts up UML through visual GUI editor from which relevant classes are generated.

While, i think the expression of fully functional code might be still far, there are pretty good enough systems that generates complete skeletons.

Check out: http://www.actifsource.com/actifsource/index.html

Also: http://www.win.tue.nl/~mchaudro/cbse2007/programgenerators.pdf

http://proglang.informatik.uni-freiburg.de/teaching/mda/2006ss/09-code-gen.pdf


问:
What are the drawbacks of elastic tabstops?
Look here: a typical holy war on tabs vs spaces.

Now look here: elastic tabstops. All problems solved, and a bunch of very useful new behaviours added.

Are elastic tabstops even mentioned in that tabs vs spaces discussion? Why not? Are there drawbacks to the elastic tabstop idea so serious that nobody has ever implemented them in a popular editor?

EDIT: I apologise for putting too much emphasis on "why aren't they mentioned". That wasn't really what I intended; that question is possibly even off topic. What I really mean is, what are the biggest drawbacks of this that prevent wider adoption of an obviously beneficial idea? (in an ideal world where everything supports it already)

(Turns out there's already a request on the Microsoft Connect for a Visual Studio implementation of elastic tabstops, and a request in Eclipse too. Plus there's a question asking about other editors that implement elastic tabstops)

答:
The biggest problem I would have with it is inconsistent spacing throughout the documentation.  I know as a programmer I would get annoyed to see a loop or if statement at 'standard' indentation and then to notice at different indentations.  I know personally I like seeing all my curly braces alined throughout the documentation, not just in the block of code I am looking at.

Overall I think it is a nice idea however, but personally, I would not like it.


答:
Does declarative programming count, e.g. Prolog or SQL?

You just describe what the program should accomplish, or what conditions the results should satisfy. Then you query the system, and get results (or "no solutions").

Of course under the hood, there's a program running, but you never see the code.

Unfortunately declarative programming is not a silver bullet: beyond elementary cases, describing the declarative goal precisely enough still requires considerable effort and skill, not to even mention that in order to get decent performance, you have to take into account various imperfections of the actual, under the hood implementation (e.g. understanding the role of SQL indexes or tail call in recursive definitions...)

Depending on the type of the problem, it could actually be easier to just solve the "how" than to precisely describe the "what". For humans, or most average programmers at least, thinking about "how" seems to come more naturally, and "what exactly" requires more mental gymnastics.

Title: How close have we gotten to automating code writing?

Body:
And I don't mean Autocomplete or automatic code snippets as inserted by modern day editors, or polymorphic code. But what is the state-of-the-art in programs that can go through given inputs and types and information of the desired outputs and output a valid piece of code in a language of choice. I am aware of Genetic Programming, Gene Expression Programming but I don't know of any other efforts. Also googling doesn't turn up much.

Is anyone aware of any advancements on this front?

Edit: When i say "output a valid piece of code", I mean an AI or something similar working out the logic and the flow of control and implement it in an imperative language. Imperative language only, since that's the tough part. Nevertheless, if you know of any new languages being developed to support this kind of idea, please do mention, as maybe our current set of languages are not suitable for the kind of early AI we may first chance upon.


问:
Do I really need a unit test framework?
Currently at my job, we have a large suite of unit tests for our C++ application. However we don't use a unit test framework. They simply utilize a C macro that basically wraps an assert and a cout. Something like:

```<code>VERIFY(cond) if (!(cond)) {std::cout << "unit test failed at " << __FILE__ << "," << __LINE__; asserst(false)}
</code>```

Then we simply create functions for each of our tests like

```<code>void CheckBehaviorYWhenXHappens()
{
    // a bunch of code to run the test
    //
    VERIFY(blah != blah2);
    // more VERIFY's as needed
}
</code>```

Our CI server picks up "unit test failed" and fails the build, emailing the message to the developers.

And if we have duplicate setup code, we simply refactor it like we would any other duplicated code we'd have in production. We wrap it behind helper functions, make some  test classes wrap setting up frequently used scenarios.

I know there's frameworks out there like CppUnit and boost unit test. I'm wondering what value do these add? Am I missing what these bring to the table? Is there something useful I could gain from them? I'm hesitant to add a dependency unless it adds real value especially since it seems what we have is dead simple and works well.

答:
As others have already said, you already have your own, simple, home made framework.

It seems to be trivial to make one. However, there are some other features of a unit-test framework that are not so easy to implement, because they take some advanced knowledge of the language. The features I generally require from a test framework and are not so easy to homebrew are:

Automatic collection of test cases. I.e. defining new test method should be enough to get it executed. JUnit automatically collects all methods whose names start with test, NUnit has the [Test] annotation, Boost.Test uses the BOOST_AUTO_TEST_CASE and BOOST_FIXTURE_TEST_CASE macros.

It's mostly convenience, but every bit of convenience you can get improves the chance developers will actually write the tests they should and that they will connect them in correctly. If you have long instructions, somebody will miss part of them now and than and perhaps some tests won't be running and nobody will notice.

Ability to run selected test cases, without tweaking code and recompiling. Any decent unit-test framework allows you to specify which tests you want to run on command-line.
If you want to debug on unit tests (it's most important point in them for many developers), you need to be able to select just some to run, without tweaking code all over the place.

Say you just received bug report #4211 and it can be reproduced with unit test. So you write one, but than you need to tell the runner to run just that test, so you can debug what's actually wrong there.

Ability to mark tests expected failures, per test case, without modifying the checks themselves. We actually switched frameworks at work to get this one.

Any decently sized test suite will have tests, that are failing because the features they test were not implemented yet, were not finished yet, nobody had time to fix them yet or something. Without ability to mark tests as expected failures, you won't notice another failure when there are some regularly, so the tests stop serving their main purpose.

Title: Do I really need a unit test framework?


问:
Why doesn't java use a radix sort on primitives?
java.util.Arrays.sort(/* int[], char[], short[], byte[], boolean[] */) is implemented as a 'tuned quicksort' rather than a radix sort.

I did a speed comparison a while ago, and with something like n>10000, radix sort was always faster. why?

答:
Back2dos has said it all, I will just try to further clarify the point which I think is the most important:

Radix sort can only sort the actual primitive values that are contained within the array, based on their binary digit patterns. In actual real-world software engineering scenarios, this case is encountered almost never.  What we tend to do far more often is sort arrays of more complex (non-primitive) data structures, and some times we sort arrays of indexes to other entities.

Now, an array of indexes to other entities is in fact an array of primitives, but the sort order is provided by the comparator interface (and/or delegate in C#) which compares not the indexes, but the entities indexed by the indexes. Thus, the sort order bears absolutely no relationship to the order of the values of the primitives, and therefore radix sort is absolutely useless for this scenario.

An example:

We have an array of strings: [0]="Mike", [1]="Albert", [2]="Zoro". Then we declare an array of indexes to those strings: [0]=0, [1]=1, [2]=2. Then, we sort the array of indexes, passing it a comparator which compares not the indexes themselves, but the actual strings referred to by these indexes. After sorting, the resulting array of indexes will look like this: [0]=1, [1]=0, [2]=2.  As you can see, this sort order has nothing to do with the binary patterns of the values contained within the array, and yet by traversing this array of indexes and fetching each corresponding string, we visit the strings in sorted order.


问:
Servicing background tasks on a large site
We're dealing with an interesting problem on StackOverflow.

We've got a whole bunch of little "needs to be done soon-ish" tasks.  An example is updating "Related Questions" lists.  What we've done in the past is to piggy-back those tasks onto some users' page loads.

This was never ideal, but it wasn't really noticeable.  Now that SO has passed the 1,000,000 question mark, those unlucky users are starting to feel it.

The natural solution is to actually push these tasks into the background.  There are two broad ways of doing this I'm considering.

1. In IIS as a custom Thread-Pool/Work-Queue

Basically, we spin up a few (non-ThreadPool, so as to not interfere with IIS) threads and have them services some collections we're shoving Funcs into.

The big pro here is simplicity.  We don't have to worry about marshaling anything, nor do we have to make sure some external service is up and responding.

We also get access to all of our common code.

The con is, well, that we shouldn't use background threads.  The objections I know of are all centered around starving IIS (if you use ThreadPool) and the threads dieing randomly (due to AppPool recycling).

We've got existing infrastructure to make the random thread death a non-issue (its possible to detect a task has been abandoned, basically), and limiting the number of threads (and using non-ThreadPool threads) isn't difficult either.

Am I missing any other objections to in IIS process thread-pooling/work-queues?

Moved to StackOverflow, as it wasn't really addressed here.

2. As a Service

Either some third-party solution, or a custom one.

Basically, we'd marshal a task across the process boundary to some service and just forget about it.  Presumably we're linking some code in, or restricted to raw SQL + a connection string.

The pro is that its the "right way" to do this.

The cons are that we're either very restricted in what we can do, or we're going to have to work out some system for keeping this service in sync with our code base.  We'll also need to hook all of our monitoring and error logging up somehow, which we get for free with the "In IIS" option.

Are there any other benefits or problems with the service approach?

In a nutshell, are there unforseen and insurmountable problems that make approach #1 unworkable and if so are there any good third-party services we should look into for approach #2?

答: How about having a very simple Windows service that runs on the web server and periodically hits a maintenance URL which does your miscellaneous tasks.  Have it throttle how much work it does in any given request.</p>

ContentLicense: CC BY-SA 2.5


问:
Is it possible to analyse the API surface of a set of class libraries to automatically determine inter-assembly dependencies?
I'm sure we've all been in the situation where we've inherited code that was "overly public", becomes obsolete or needs to be refactored. In these situations, it is easy to spend many days analysing the API surface to see where methods or classes are consumed; with the .Net runtime, it seems logical that it should be relatively trivial to map these inter-assembly dependencies, but there doesn't seem to be any tools out there that do this already?

For example, let's suggest that we have a CRM class library that encapsulates the interface to all the customer data; it's not unreasonable that a quotations application may rely on this, but it seems non-trivial to identify on which bits. A naive approach would be to say that the public interfaces (types, etc.) is the API surface, but it may be the case that some of these interfaces are only public for consumption in a particular use case, that may become invalid.

Is it possible to automatically determine and map the inter-assembly dependencies for a given set of assemblies?

答:
Static analysis tools like nDepend do this.

It has views that tell you what types are used where and how often, recognized circular dependencies and more.


问:
How does one decide if a data object type should be designed to be immutable?
I love the immutable "pattern" because of its strengths, and in the past I have found it beneficial to design systems with immutable data types (some, most or even all). Often when I do so, I find myself writing fewer bugs and debugging is much easier.

However, my peers in general shy away from immutable. They are not inexperienced at all (far from it), yet they write data objects the classic way - private members with a getter and a setter for every member. Then usually their constructors take no arguments, or maybe just take some arguments for convenience. So often, creating an object looks like this:

```<code>Foo a = new Foo();
a.setProperty1("asdf");
a.setProperty2("bcde");
</code>```

Maybe they do that everywhere. Maybe they don't even define a constructor that takes those two strings, no matter how important they are. And maybe they don't change the value of those strings later and never need to. Clearly if those things are true, the object would be better designed as immutable, right? (constructor takes the two properties, no setters at all).

How do you decide if an object type should be designed as immutable? Is there a good set of criteria to judge it by?

I currently am debating whether to switch a few data types in my own project to immutable, but I would have to justify it to my peers, and the data in the types might (VERY rarely) change - at which time you can of course change it the immutable way (create a new one, copying the properties from the old object except for the ones that you want to change). But I'm not sure if this is just my love for immutables showing through, or if there is an actual need for/benefit from them.

答: Seems like you're approaching it backwards.  One should default to immutable.  Only make an object mutable if you absolutely have to/just can't make it work as an immutable object.</p>


问:
Should there be separate database schemas for each developer or should there be just one that all developers share?
During development, should developers each have their own copy of the database to work on ? Or should there be a common shared development database ?

The former will give developers more flexibility. For ex., they can run their own regression tests during development and unit testing without worrying about corrupting the data for other developers. However, it is difficult to maintain for database adminstrators.

The latter is easier to maintain (less integration overheads as everyone's working on the same schema) but requires more effort to ensure data sanctity (developers should be careful and not make changes that will impact others).

答:
The answer is that local database copies are good and should be done.

I think the real question behind this, though, is "what is the process for managing database changes"

Key things to consider are:

How local developers 'make' a change.
How local db changes get pushed up.
How central db changes get pushed down/out to developers.

Ruby in Rails for instance allows developers to do database migrations using ruby code, then the migration gets pushed to staging, testing and production and run there ('centrally') and pushed out to other developers (who pull it) to do the same.

Ay the end of the day what is critical for any system is communication, be it a standardized process or just emails about changes.


答:
I've written many code generators for Java and C# that produce working code for various tasks.  There are packages like JAXB, which analyzes an XML document and produces corresponding Java classes and marshalling/unmarshalling code to do the translation, and Entity Framework which produces DTO classes for marshalling data to/from a database.  There are also tools like Rational XDE (of whatever it's called now) which do round-trip code generation between a class diagram and Java.

If you're looking for something that can take business requirements or a functional spec and turn it into code, I haven't seen much progress in that area.  I know OMG is working on some kind of "executable UML", but aside from some DoD prototypes I don't know of any practical implementations.


问:
What does mathematics have to do with programming?
I just started a diploma in software development. Right now we're starting out with basic Java and such (so right from the bottom you might say) - which is fine, I have no programming experience apart from knowing how to do "Hello World" in Java.

I keep hearing that mathematics is pertinent to coding, but how is it so? What general examples would show how mathematics and programming go together, or are reliant on one another?

I apologize of my question is vague, I'm barely starting to get a rough idea of the kind of world I'm stepping into as a code monkey student...

答:
It honestly depends on what sort of programming you're doing.

If you're making light web apps with some logic, you probably don't need the more advanced math classes that many degrees require. If you're working with things that are a bit more processor heavy, than you're going to need more math. If you're doing work with any kind of scientific field, you'll really want to keep your calc references at hand.

Another place where you'll need math is if you want to write games. The second you want to move diagonally, you'll need to start doing some careful calculations so that you don't end up with characters that accelerate if the move to a block to the NE.

That said, you don't necessarily need to learn math, then learn programming. It's perfectly valid to learn programming, then pick up some advanced math. I started coding before I ever set foot inside a Calc or Trig class and did just fine. When I did start learning advanced math, I found that coding really helped me, as I could explore the topic more by changing variables in a quick script than I could with pen and paper.


答:
Here's how I see it: if most of the popular tools already supported elastic tabstops, many people would be using them. The same happened with vi’s navigate/edit mode, with syntax highlighting, and later with Intellisense. In each case, the established wisdom was that it is not useful or not needed, but it got implemented and it took off.

Elastic tabstops do, of course, have a relatively low impact. Most people are sufficiently happy with the status quo and so don’t care. A similar reasoning is applied to many situations in which some people are just happy with what they’ve got and see no reason to switch to something more advanced. In other words, the biggest problem with elastic tabstops is the same as for almost every other good idea: it needs to gain traction.

But that doesn’t mean the feature can’t be adopted incrementally. Every single programming language was adopted incrementally, even though an entire team requires a new compiler and a new IDE to start using it. The same is true of every single hardware architecture and many other examples. It is also not the case that lack of integration with existing tools is a show-stopper: the same is true, for example, of “unified-diff format”, which incrementally replaced an earlier less readable format that was nonetheless understood by automated tools (such as patch). Those tools have been upgraded over time.

I appreciate the interop issues others have mentioned, but despite them, there certainly will be teams (like mine) who would adopt this without hesitation, in our entirety. External tools such as diffing, merging etc. will initially not support it, but we would do our part to encourage vendors to include the feature. This is how progress has always been made. It requires some pains for a temporary transitionary period, but in the end, it is worth it.

Title: What are the drawbacks of elastic tabstops?

Body:
Look here: a typical holy war on tabs vs spaces.

Now look here: elastic tabstops. All problems solved, and a bunch of very useful new behaviours added.

Are elastic tabstops even mentioned in that tabs vs spaces discussion? Why not? Are there drawbacks to the elastic tabstop idea so serious that nobody has ever implemented them in a popular editor?

EDIT: I apologise for putting too much emphasis on "why aren't they mentioned". That wasn't really what I intended; that question is possibly even off topic. What I really mean is, what are the biggest drawbacks of this that prevent wider adoption of an obviously beneficial idea? (in an ideal world where everything supports it already)

(Turns out there's already a request on the Microsoft Connect for a Visual Studio implementation of elastic tabstops, and a request in Eclipse too. Plus there's a question asking about other editors that implement elastic tabstops)


问:
Should I use title case in URLs?
We are currently deciding on a consistent naming convention across a site with multiple web applications. Historically, I've been an advocate of the 'lowercase all the letters!' when creating URLs:

```<code>http://example.com/mysystem/account/view/1551
</code>```

However, within the last year or two, specifically since I began using ASP.NET MVC & had more dealings with REST based URLs, I've become a fan of capitalizing the first letter of each section/word within the URL as it makes it easier to read (imho).

```<code>http://example.com/MySystem/Account/View/1551
</code>```

We're not in a situation where people need to read or be able to understand the URLs, so that's not a driver per se. The main thing we are after is a consistent approach that is rational and makes sense.

Are there any standards that declare it good to do one way or another, or issues that we may run into on (at least realistically modern) setups that would choose a preference over another? What is the general consensus for this debate currently?

答:
For internal websites, it doesn't matter so much as long as you're consistent with it.

For external, public facing, sites, you probably want to stick with lower case which is more or less the standard in Linux/Apache web hosting. As I recall, some versions of Firefox also seem to handle URL casing differently than IE. This might also apply to Chrome as well.

Having consistent casing also matters for search engine optimization. You don't want Google to see lower-case.aspx and Lower-Case.aspx as different pages with duplicate content. While their algorithms try to prevent this mistaken identity, it does happen from time to time and can cause a page to be penalized.

Title: Should I use title case in URLs?


答:
The primary benefit of immutable objects is guaranteeing thread safety.  In a world where multiple cores and threads is the norm, this benefit has become very important.

But using mutable objects is very convenient.  They perform well, and as long as you're not modifying them from separate threads, and you have a good understanding of what you are doing, they are quite reliable.

Title: How does one decide if a data object type should be designed to be immutable?

Body:
I love the immutable "pattern" because of its strengths, and in the past I have found it beneficial to design systems with immutable data types (some, most or even all). Often when I do so, I find myself writing fewer bugs and debugging is much easier.

However, my peers in general shy away from immutable. They are not inexperienced at all (far from it), yet they write data objects the classic way - private members with a getter and a setter for every member. Then usually their constructors take no arguments, or maybe just take some arguments for convenience. So often, creating an object looks like this:

```<code>Foo a = new Foo();
a.setProperty1("asdf");
a.setProperty2("bcde");
</code>```

Maybe they do that everywhere. Maybe they don't even define a constructor that takes those two strings, no matter how important they are. And maybe they don't change the value of those strings later and never need to. Clearly if those things are true, the object would be better designed as immutable, right? (constructor takes the two properties, no setters at all).

How do you decide if an object type should be designed as immutable? Is there a good set of criteria to judge it by?

I currently am debating whether to switch a few data types in my own project to immutable, but I would have to justify it to my peers, and the data in the types might (VERY rarely) change - at which time you can of course change it the immutable way (create a new one, copying the properties from the old object except for the ones that you want to change). But I'm not sure if this is just my love for immutables showing through, or if there is an actual need for/benefit from them.


问:
Term for Performance Issues Due to Looping
Is there a term for performance issues caused by someone creates a loop that performs hundreds or thousands of actions that could have been done in bulk?

My example is that I keep running into loops that loop through a group of IDs and then perform a single query for each ID to retrieve the associated row instead of creating a single query.

答:
The term is "Performance Issues Due to Excessive Looping."

Or, if you like, Schlemiel the Painter's algorithm.

Seriously, it's simply a performance problem, a case of using an improper algorithm.  "Needz better Big O."


答:
I suppose, to date, you've been taught elements of calculus and some trigonometry. And you call that Mathematics. That's like calling a pair of legs "a human being."

Calculus have little to do with programming, and is more tightly related to physics and engineering. You will need physics for game engines and calculus for statistical analysis. (Statistical analysis drives more jobs that it is comfortable to admit)

Calculus, for us, is more about relating programming to the real world. Computational calculus is the branch that studies how bad that relation is going so far. (spoiler: it's going pretty bad, but we can keep it in check indefinitely)

Trigonometry is a crazy jack in the box that comes out when you least expect it and then signal analysis, audio generation and many other stuff depend on it.

Go trough Algebra 101 and Logic 101, study the history of Pascal, Leibniz, (yeah he almost invented calculus, got it halfway wrong, argued with Newton until it all started making almost sense - and still conceived the binary coding thing) and Babbage and many of your doubts will wane. (your definition of Mathematics will be forever changed, though)

Title: What does mathematics have to do with programming?

Body:
I just started a diploma in software development. Right now we're starting out with basic Java and such (so right from the bottom you might say) - which is fine, I have no programming experience apart from knowing how to do "Hello World" in Java.

I keep hearing that mathematics is pertinent to coding, but how is it so? What general examples would show how mathematics and programming go together, or are reliant on one another?

I apologize of my question is vague, I'm barely starting to get a rough idea of the kind of world I'm stepping into as a code monkey student...


问:
How to not take risks with new collaborators?
My team is going to add new team members and my manager doesn't want to take any risks. I don't think it's a large problem but my manager is concerned that a new programmer would sabotage and accidentally destroy parts of the code or the data e.g. cause data disaster. I say that probability is not very high but still I've been told that it's important to limit the rights of what new collaborators can do.

But this is not practical and we can't eat the cake and have it - adding a collaborator to source control gives the new collaborator access to all the source code and even if there was a way to only let a new member in to parts of the source code (we're using bitbucket for source control) it still wouldn't work since technically the whole project is usually needed to build it so one can't just take a part of the code and expect it to work and able to build on independently.

We're using Google App Engine and nor is it a working idea to create a clone of the app that my collaborator can build on.

I said that we are not the first ones with this problem and that a solution that works for someone else should work for us but my manager seemed not satisfied with that answer.

Can you comment on my situation or give concrete advice what could be done about the "problem" / scenario since it's just a scenario that a newly added developer accidentally deletes the whole datastore, but we don't want it to be possible.

答:
Disaster Recovery Plan. New hires, disgruntled old hires, innocent errors, and problems with Google happen. If we could prevent errors from happening 100% of the time (Pin-headed managers love absolutes.), we wouldn't have backups.

Auditing - your system should know who deleted all the data.

Hiring Quality People - get references and do background checks. Most professionals lose sleep at night worring about losing code and accidentally causing problems with their data and not finding ways to ruin their careers. Your boss should focus on doing his/her job better when hiring.

Testing and Staging Areas - I don't know about Google App Engine, but this is unacceptable and not common. If it is a cost issue, your boss needs to get back to doing his job and justify it based on the obvious risks. Don't test or code on production systems and data.


答:
There are two major ways to decide if an object is immutable.

a) Based on the nature of the Object

It is easy to catch these situations because we know that these objects will not change after it is constructed. For example if you are have a RequestHistory entity and by nature history entities do not change once it is constructed. These objects can be straight forward designed as immutable classes. Keep in mind that Request Object is mutuable as it can change its state and whom it is assigned to etc over the time but request history do not change. For example, there was a history element  created last week when it moved from submitted to assigned state AND this history entitiy can never change. So this is a classic immutable case.

b) Based on the design choice, external factors

This is similar to java.lang.String example. Strings can actually change over the time but by design, they have made it as immutable due to caching/string pool/concurrency factors. Similary the caching/concurrency etc can play a good role in making an object immuatble if caching/concurrency and related performance is vital in the application. But this decision should be taken very carefully after anlyzing all the impacts.

The main advantage of immutable objects is they are not subjected to tumble-weed pattern.i.e the object will not pick up any change over the life time and it makes the coding and maintenance very very easier.


答:
Call it "missed occasion for performance optimization by using bulk operations instead".

Of course, I have often seen situations where using one complex SQL can improve performance greatly, but will result in code harder to maintain than using a loop and simple SQLs (and yes, I have also seen situations where the faster SQL will be also easier to maintain than an overcomplicated loop).

My point is: performance should not be the only, perhaps not even the first criteria for deciding which solution is better, also think about maintainability. When a loop is "fast enough" and gives you cleaner code, prefer the loop.

Title: Term for Performance Issues Due to Looping

Body:
Is there a term for performance issues caused by someone creates a loop that performs hundreds or thousands of actions that could have been done in bulk?

My example is that I keep running into loops that loop through a group of IDs and then perform a single query for each ID to retrieve the associated row instead of creating a single query.


答:
Your specific example is an "N+1 problem". It's commonly seen in ORMs that "lazy-load" data, when the model has a collection of a child object. The ORM queries the DB when a particular record is absolutely needed, so they'll first query for a list of IDs of the child objects (along with a query for the parent object), then as each child object is referenced the ORM will query that specific record, resulting in N + 1 queries being executed to retrieve N child objects. The problem is if you know you need ALL the records you have queried for, this behavior drastically increases the number of "round trips" as opposed to simply "eager-loading" the data using a single query based on the FK relationship.

As far as a general term for inefficiencies due to looping, there really isn't one.


答:
I've heard problems similar to this described as an "N+1 SELECT issue".

The idea being that you make 1 SELECT statement to work out which records you need to deal with, and then another for each individual record.

Strictly speaking of course, this is for SELECT operations rather than UPDATE, but it seems pretty close.


答: I've run into this a couple of times when developing web applications. We've been solving it by creating a windows console application that carries out the task, and creating a scheduled task that runs every so often to actually do the task.</p>

Title: Servicing background tasks on a large site

Body:
We're dealing with an interesting problem on StackOverflow.

We've got a whole bunch of little "needs to be done soon-ish" tasks.  An example is updating "Related Questions" lists.  What we've done in the past is to piggy-back those tasks onto some users' page loads.

This was never ideal, but it wasn't really noticeable.  Now that SO has passed the 1,000,000 question mark, those unlucky users are starting to feel it.

The natural solution is to actually push these tasks into the background.  There are two broad ways of doing this I'm considering.

1. In IIS as a custom Thread-Pool/Work-Queue

Basically, we spin up a few (non-ThreadPool, so as to not interfere with IIS) threads and have them services some collections we're shoving Funcs into.

The big pro here is simplicity.  We don't have to worry about marshaling anything, nor do we have to make sure some external service is up and responding.

We also get access to all of our common code.

The con is, well, that we shouldn't use background threads.  The objections I know of are all centered around starving IIS (if you use ThreadPool) and the threads dieing randomly (due to AppPool recycling).

We've got existing infrastructure to make the random thread death a non-issue (its possible to detect a task has been abandoned, basically), and limiting the number of threads (and using non-ThreadPool threads) isn't difficult either.

Am I missing any other objections to in IIS process thread-pooling/work-queues?

Moved to StackOverflow, as it wasn't really addressed here.

2. As a Service

Either some third-party solution, or a custom one.

Basically, we'd marshal a task across the process boundary to some service and just forget about it.  Presumably we're linking some code in, or restricted to raw SQL + a connection string.

The pro is that its the "right way" to do this.

The cons are that we're either very restricted in what we can do, or we're going to have to work out some system for keeping this service in sync with our code base.  We'll also need to hook all of our monitoring and error logging up somehow, which we get for free with the "In IIS" option.

Are there any other benefits or problems with the service approach?

In a nutshell, are there unforseen and insurmountable problems that make approach #1 unworkable and if so are there any good third-party services we should look into for approach #2?


答: I'm sure you could identify some of the dependencies, but not all.  E.g., what about a web service call that's either dynamically generated or read from a resource?

Title: Is it possible to analyse the API surface of a set of class libraries to automatically determine inter-assembly dependencies?

Body:
I'm sure we've all been in the situation where we've inherited code that was "overly public", becomes obsolete or needs to be refactored. In these situations, it is easy to spend many days analysing the API surface to see where methods or classes are consumed; with the .Net runtime, it seems logical that it should be relatively trivial to map these inter-assembly dependencies, but there doesn't seem to be any tools out there that do this already?

For example, let's suggest that we have a CRM class library that encapsulates the interface to all the customer data; it's not unreasonable that a quotations application may rely on this, but it seems non-trivial to identify on which bits. A naive approach would be to say that the public interfaces (types, etc.) is the API surface, but it may be the case that some of these interfaces are only public for consumption in a particular use case, that may become invalid.

Is it possible to automatically determine and map the inter-assembly dependencies for a given set of assemblies?


答:
Sure, it's harder to see the benefits when you're working alone. Personally, I've worked on plenty of solo projects and not only would I write a build script, I go through the trouble of setting up a CI Server (like Jenkins).

There's overhead of course, why would it be worth it?

A reproducible build, not tied to the IDE (or your machine, if you run it externally). If a build server runs it, other machines can run it.

The fun begins after building and unit testing (by the way: are you sure you test before every commit? I sometimes forget). Generate documentation, build installers, run your favorite code analysis tools.

Your favorite CI server lets you see graphs of code coverage, unit test failures, etc. over time. Does your IDE do that?

For my current project, the script builds, runs static analysis tools, compresses js/css, unit tests, and packages into a web archive. Jenkins runs it after each commit and deploys the project to a test server.

I took the time to set this up (the build script is maybe 300 lines by the way, haven't touched it in months) and  can say it's worth it, even for one person. For more than one person, it's necessary. My involvement in the build/deployment process consists of the commands "hg commit" and "hg push."


答:
What you have is simple and gets the job done. If it works for you, great. You don't need a mainstream unit testing framework, and I would hesitate to go to the work of porting an existing library of unit tests over to a new framework. I think the biggest value of unit testing frameworks is to reduce the barrier to entry; you just start writing tests, because the framework is already in place. You're past that point, so you won't get that benefit.

The other benefit of using a mainstream framework--and it's a minor benefit, IMO--is that new developers may already be up to speed on whatever framework you're using, and so will require less training. In practice, with a straightforward approach like what you've described, this shouldn't be a big deal.

Also, most mainstream frameworks have certain features that your framework may or may not have. These features reduce plumbing code, and make it faster and easier to write test cases:

Auto-running of test cases, by using naming conventions, annotations/attributes, etc.

Various more specific asserts, so that you don't have to write conditional logic for all of your assertions or catch exceptions to assert their type.

Categorization of test cases, so you can easily run subsets of them.

Title: Do I really need a unit test framework?

Body:
Currently at my job, we have a large suite of unit tests for our C++ application. However we don't use a unit test framework. They simply utilize a C macro that basically wraps an assert and a cout. Something like:

```<code>VERIFY(cond) if (!(cond)) {std::cout << "unit test failed at " << __FILE__ << "," << __LINE__; asserst(false)}
</code>```

Then we simply create functions for each of our tests like

```<code>void CheckBehaviorYWhenXHappens()
{
    // a bunch of code to run the test
    //
    VERIFY(blah != blah2);
    // more VERIFY's as needed
}
</code>```

Our CI server picks up "unit test failed" and fails the build, emailing the message to the developers.

And if we have duplicate setup code, we simply refactor it like we would any other duplicated code we'd have in production. We wrap it behind helper functions, make some  test classes wrap setting up frequently used scenarios.

I know there's frameworks out there like CppUnit and boost unit test. I'm wondering what value do these add? Am I missing what these bring to the table? Is there something useful I could gain from them? I'm hesitant to add a dependency unless it adds real value especially since it seems what we have is dead simple and works well.


答:
To be honest, I don’t find them that useful once you get over the initial excitement. For instance, I don’t like comments at the end of a line anyway – I always put my comments on a separate line. With that, elastic tabs lose their main use.

After that, you can of course still use them to align function arguments (and parameters) and long lists of assignments.

But for the former I tend to just indent all arguments by one additional level and that works entirely fine with me:

```<code>void foo(
    int x,
    int y,
    string z
)
</code>```

And I don’t see any need to change that.

And as for aligning assignments, I don’t do that. I put single spaces around assignments, that’s it. I also tend not to cluster lots of assignments together so there is rarely any readability issue.

In summary, elastic tabs have absolutely zero usefulness for me. This is of course a very personal preference that may vary but I find that it works well and I guess that the lack of support for elastic tabs is because other people think similarly.

If an editor would implement them, I still wouldn’t use them.

Body:
To be honest, I don’t find them that useful once you get over the initial excitement. For instance, I don’t like comments at the end of a line anyway – I always put my comments on a separate line. With that, elastic tabs lose their main use.

After that, you can of course still use them to align function arguments (and parameters) and long lists of assignments.

But for the former I tend to just indent all arguments by one additional level and that works entirely fine with me:

void foo(
    int x,
    int y,
    string z
)

And I don’t see any need to change that.

And as for aligning assignments, I don’t do that. I put single spaces around assignments, that’s it. I also tend not to cluster lots of assignments together so there is rarely any readability issue.

In summary, elastic tabs have absolutely zero usefulness for me. This is of course a very personal preference that may vary but I find that it works well and I guess that the lack of support for elastic tabs is because other people think similarly.

If an editor would implement them, I still wouldn’t use them.


问:
Users creating instances from a template - is there a software pattern that corresponds to this use case?
I am looking into designing a system where users build a template item and then create many instances based on this template.They then need to be able customise each instance but I also need for them to be able to make changes to the template and have all instances updated. These items are fairly complex, each consisting of many components that will be stored in numerous database tables.

I see two implementation paths.

Store complete copies of the templates to create the instances and
migrate updates to the instances.

Store records only for the changes and build each instance from a combination of the template and instance changes.

I believe the first option would create a lot of unneeded extra data however the 2nd way introduces complexities in querying the data.

This seems like it has probably been implemented many times before but I am having trouble finding much reading material. Are there common names for data models or pattern options used in implementations of such systems?

Any advice on benefits or pitfalls of each option, other options, or implementation guidance would be useful too.

edit:

Sorry I may not have been clear. I was looking more for a name for the general architecture not a design pattern. It is the end users who create instances not developers.

For example the system might allow users to define templates to model manufacturing processes of many items. Then at different sites where facilities or requirements are different, the end user would would use one of these templates to define a process specific for that site. Things will be added, removed and modified for each site.

I believe I will go with option two mentioned above - storing only delta changes, not complete copies.

答:
I think what you are looking for is the Abstract Factory Pattern.

Consider phone numbers:

Phone numbers have a particular rule on which they get generated
  depending on areas and countries. If at some point the application
  should be changed in order to support adding numbers form a new
  country, the code of the application would have to be changed and it
  would become more and more complicated.

In order to prevent it, the Abstract Factory design pattern is used.
  Using this pattern a framework is defined, which produces objects that
  follow a general pattern and at runtime this factory is paired with
  any concrete factory to produce objects that follow the pattern of a
  certain country.

http://www.oodesign.com/abstract-factory-pattern.html


答:
Sounds like chunky v chatty communication.

Chatty = lots of calls across the network.
Chunky = a bulk call across the network.

Psuedocode:

```<code>for each Item in ListOfItems
 someNetworkCall(Item)
</code>```

versus

```<code>someMoreEfficientNetworkCall(ListOfItems)
</code>```

Body:
Sounds like chunky v chatty communication.

Chatty = lots of calls across the network.
Chunky = a bulk call across the network.

Psuedocode:

for each Item in ListOfItems
 someNetworkCall(Item)

versus

someMoreEfficientNetworkCall(ListOfItems)


答:
Holy Wars are Subjective

Nick's elastic tabstops are an amazing concept that could help a lot of people agree on a workable solution, though I highly doubt it would entirely end this Holy War: it is, after all, also a matter of taste and many programmers will not move an inch from their position on this matter, even at the cost of compromise. So that would be a first reason.

For instance, a lot of people on the "spaces" side will still dislike it as it requires an additional piece of logic in your software for a decent rendering (e.g. simply viewing a changeset in your SCM's webview).

Implementation Issues

But the most obvious reason is just its technical barrier to entry: it's a fundamentally different concept from what has been implemented for a number of years (if not decades) in IDEs and text editors. It would require to rewrite some of them to process lines in a fairly different fasion, which makes it difficult for older and bigger systems that have a higher chance of suffering of deep and tight coupling in their line processing code. It is, however, a lot easier to do when you start from scratch (think of Nick's demo or of Go's tabwriter package).

For a personal anecdote, I remember approaching the author a while back to ask if there was any emacs support in sight, and in this particular case he mentioned this as the reason for it not being trivial. He also asked for help from the community to help implement this feature and bring it to the masses.

Do We Care Enough?

A third reason, is that some developers are not that hung up on the matter and don't really care so much that they would go the extra mile to support the effort. In most cases, the spaces-vs-tabs conflict is not a business blocker, so there's not so much drive behind the issue.

If you want it, you'll have to fight for it. Which is doable in open-source software. And if you change enough of these, closed-source ones will have to follow at the risk of losing to some of their userbase, if an ever so small part of it.

So, if you want it, give Nick a hand.


问:
Is Object Oriented stuff really that important?
For years, I have been doing Algorithmic stuff, writing scalable data structures for internet search, for example Randomized Binary Search Trees for Auto Recommendation, BitMaps, Wisdom of Crowd based Algorithms using Graphs, writing some interesting Machine Learning Algorithms like Clustering, Anomaly Detection, working on Information Retrieval stuff and so on

There is a common thing in the things that I have mentioned above. All the above stuff;each if coded in a language like C++ requires handful of classes. I mean they are interesting problems but they are not complex in terms of heavily loaded Object Oriented stuff. I have never used Inheritance, virtual stuff etc. Though I have heavily used Generic Programming, Templates and so on.

I love C++ (- Bulky OO stuff, As I like what Joe Armstrong's, creator of Erlang says, In OO World if you ask for a banana you get a big jungle alongwith gorilla holding the banana). I enjoy coding in other languages like Java, Python too.

Now my question is since I am enjoying the kind of projects/Algorithms I am working on do I need to really learn OO stuff, will I be a better coder/designer just by using the stuff like Inheritance, Dynamic Polymorphism (virtuals)? OR can I move to the world of Functional Programming (I have not done it till now) which attracts me more as I can just focus on tasks/algorithms and not let Kingdom Of Noun based OO stuff, has-a, is-a rule me?

In short will/can OO stuff help me at all for the kind of projects/Algorithms that I have mentioned above?

EDIT:

One extremely interesting link to add here:

http://steve-yegge.blogspot.in/2006/03/execution-in-kingdom-of-nouns.html

答:
Object oriented programming is really good at hiding your complex fancypants mathy stuff behind easy to understand words and making it easier for the lessers among you to actually use the things you've written.  It doesn't replace functional programming ... it just gives you a really easy way to switch out implementations or add behavior.

In your Randomized Binary Search Trees example above, what if you were given the requirement that on April Fools Day, the Randomizer was replaced with an order-by-distance-from-three-stooges.  It's really handy to create StoogeBinaryTree : RandomBinaryTree and override the protected int GetSortOrder (Tree a, Tree b) method, so on April 2nd, you can switch implementation back to the RandomBinaryTree without having to have changed any of that code.

In one simple example, I've shown both adding tiny sliver of behavior and switching implementation...


答:
```<code>Foo a = new Foo();
a.setProperty1("asdf");
a.setProperty2("bcde");
</code>```

If Foo only has two properties, then it's easy to write a constructor that takes two arguments. But suppose you add another property. Then you have to add another constructor:

```<code>public Foo(String a, String b, SomethingElse c)
</code>```

At this point, it's still manageable. But what if there are 10 properties? You don't want a constructor with 10 arguments. You can use the builder pattern to construct instances, but that adds complexity. By this time, you'll be thinking "why didn't I just add setters for all the properties like normal people do"?

Body:
Foo a = new Foo();
a.setProperty1("asdf");
a.setProperty2("bcde");

If Foo only has two properties, then it's easy to write a constructor that takes two arguments. But suppose you add another property. Then you have to add another constructor:

public Foo(String a, String b, SomethingElse c)

At this point, it's still manageable. But what if there are 10 properties? You don't want a constructor with 10 arguments. You can use the builder pattern to construct instances, but that adds complexity. By this time, you'll be thinking "why didn't I just add setters for all the properties like normal people do"?


答:
It seems like you have only been focused on solving a single problem at a time, i.e. writing algorithms. But consider how you'd write a GUI application, for instance, or some other huge application which possible requires you to use a lot of your algorithm. In that case, knowing OO will be essential, since it'll help you simplify your code to make it more readable and easier for other developers to use, e.g. by creating a library that could be a loaded as an object.

One of the most important design patterns in Object Oriented Programming is the Strategy Pattern, which in the above scenario also will help you greatly. Consider an example where the user would present you with input on which you'd allow the user to perform an algorithm. This could easily be a messy if/else or switch/case construction. By creating a common interface for your algorithm and using Strategy Pattern, your code would be much more flexible, readable, easier to extend, and thus easier to maintain.

Title: Is Object Oriented stuff really that important?

Body:
For years, I have been doing Algorithmic stuff, writing scalable data structures for internet search, for example Randomized Binary Search Trees for Auto Recommendation, BitMaps, Wisdom of Crowd based Algorithms using Graphs, writing some interesting Machine Learning Algorithms like Clustering, Anomaly Detection, working on Information Retrieval stuff and so on

There is a common thing in the things that I have mentioned above. All the above stuff;each if coded in a language like C++ requires handful of classes. I mean they are interesting problems but they are not complex in terms of heavily loaded Object Oriented stuff. I have never used Inheritance, virtual stuff etc. Though I have heavily used Generic Programming, Templates and so on.

I love C++ (- Bulky OO stuff, As I like what Joe Armstrong's, creator of Erlang says, In OO World if you ask for a banana you get a big jungle alongwith gorilla holding the banana). I enjoy coding in other languages like Java, Python too.

Now my question is since I am enjoying the kind of projects/Algorithms I am working on do I need to really learn OO stuff, will I be a better coder/designer just by using the stuff like Inheritance, Dynamic Polymorphism (virtuals)? OR can I move to the world of Functional Programming (I have not done it till now) which attracts me more as I can just focus on tasks/algorithms and not let Kingdom Of Noun based OO stuff, has-a, is-a rule me?

In short will/can OO stuff help me at all for the kind of projects/Algorithms that I have mentioned above?

EDIT:

One extremely interesting link to add here:

http://steve-yegge.blogspot.in/2006/03/execution-in-kingdom-of-nouns.html


答:
Though I have heavily used Generic Programming, Templates and so on.

Arguably, templates are simply a different form of OOP. Virtual functions and explicit inheritance have a specific use case- run-time, binary interchangability. Templates are compile-time interchangability. However, at the most basic level, they offer the same feature- abstraction over any type which offers the correct interface. Over-use of run-time inheritance is a significant code smell, and in this case, I agree with you- it simply isn't needed for much of the time.

```<code>template<typename T> void func(T t) { t(5); }
void func(std::function<void(int)> t) { t(5); }
</code>```

These two snippets are effectively identical, even though one uses templates exclusively and the other uses run-time inheritance and classes as it's implementation. They both abstract over the function you're calling. This is trivially obvious when you substitute T for std::function<void(int)>, for example. The only difference is the time at which that abstraction is made. The template version excels for functions, and std::function is generally better off as member variables. You don't want to have to create a new class every time you want a new callback.

OOP is not particularly well-suited for algorithms. It is more intended for large-scale constructs, breaking down the pieces of the program. If you are writing a specific algorithm operating on specific data then it's unlikely you will need classes.

It's easy, and it's great, to compose algorithms of functions. However, as soon as you get beyond that, then classes emerge as the dominant method.

Body:
Though I have heavily used Generic Programming, Templates and so on.

Arguably, templates are simply a different form of OOP. Virtual functions and explicit inheritance have a specific use case- run-time, binary interchangability. Templates are compile-time interchangability. However, at the most basic level, they offer the same feature- abstraction over any type which offers the correct interface. Over-use of run-time inheritance is a significant code smell, and in this case, I agree with you- it simply isn't needed for much of the time.

template<typename T> void func(T t) { t(5); }
void func(std::function<void(int)> t) { t(5); }

These two snippets are effectively identical, even though one uses templates exclusively and the other uses run-time inheritance and classes as it's implementation. They both abstract over the function you're calling. This is trivially obvious when you substitute T for std::function<void(int)>, for example. The only difference is the time at which that abstraction is made. The template version excels for functions, and std::function is generally better off as member variables. You don't want to have to create a new class every time you want a new callback.

OOP is not particularly well-suited for algorithms. It is more intended for large-scale constructs, breaking down the pieces of the program. If you are writing a specific algorithm operating on specific data then it's unlikely you will need classes.

It's easy, and it's great, to compose algorithms of functions. However, as soon as you get beyond that, then classes emerge as the dominant method.


答:
The answer is somewhat language-dependent.  Your code looks like Java, where this problem is about as difficult as possible.  In Java, objects can only be passed by reference, and clone is completely broken.

There is no simple answer, but for certain you want to make small-ish value objects immutable.  Java correctly made Strings immutable, but incorrectly made Date and Calendar mutable.

So definitely make small value objects immutable, and implement a copy constructor.  Forget all about Cloneable, it's so badly designed that it's useless.

For larger value objects, if it is inconvenient to make them immutable, then make them easy to copy.


答:
As others have said, object-orientation is the dominant paradigm in industry. You've said that you've worked mostly with programs that can be addressed by a handful of classes, but in an industrial application there are hundreds or thousands of use-cases that need to be addressed and object-orientation has proved a very reliable and broadly comprehensible way to structure such large codebases.

You talk about functional programming, which is a solid contender for The Next Big Paradigm, but FP is not yet familiar in industry. Especially as you are a C++ programmer, you should know that industry can be conservative and the C/C++ world, with its emphasis on performance, is a place where the imperative nature of hardware is seen as a very real consideration. In general, embedded systems programmers are extremely skeptical of FP, in my experience.

Even if FP does become a more dominant paradigm in industry, it is certainly the case that it will succeed in the form of object-functional hybrid languages such as F# and Scala and not in the form of "pure" FP languages such as Haskell.

All of which is to say that, yes, object-oriented "stuff" is important to professional codebases and your career.


答:
I'm going to buck the apparent trend here and suggest going for the in-IIS model. I've used it myself and it works really well. It's really not that hard to implement a decent thread-pool class (over the years, I've extended my thread pool class to support dynamic creation and destruction of threads, retrying of jobs and so on). Advantages are:

No external service to monitor

Simplicity of implementation: no cross-process marshalling, no advanced job monitoring

You're still inside your IIS process, so you can do all of your usual logging and so on (no need for multiple log files)

Vastly simplified deployment (when you update a service, you have to stop the service, copy the files, start the service - this is in addition to your usual updates to the website code)

In my opinion, an in-IIS solution is simply the "next step up" from piggybacking the work onto random page views.


答:
I currently am debating whether to switch a few data types in my own project to immutable, but I would have to justify it to my peers, and the data in the types might (VERY rarely) change - at which time you can of course change it the immutable way (create a new one, copying the properties from the old object except for the ones that you want to change).

Minimizing the state of a program is highly beneficial.

Ask them if they want to use a mutable value type in one of your classes for temporary storage from a client class.

If they say yes, ask why?  Mutable state doesn't belong in a scenario like this.  Forcing them to create the state where it actually belongs and making the statefulness of your data types as explicit as possible are excellent reasons.


答:
Do functional programming, it will be a very good experience for you, even if you decide not to continue. As you can read out of some of the answers here, many people don't even know what it is.

Functional languages concepts, eg lazy evaluation and referential transparancy, are a very very good thing to learn. Especially if you like recursion.

for example:

```<code>lenth :: [a] -> Integer
length (x:xs) = 1+length(xs)
length [] = 0
</code>```

is a very simple haskell function that recurses through a list and calculates the lenght.
If you are interested in numbers bigger than long long and want to use infinite Lists and other fancy stuff, give functional programming a try.

Body:
Do functional programming, it will be a very good experience for you, even if you decide not to continue. As you can read out of some of the answers here, many people don't even know what it is.

Functional languages concepts, eg lazy evaluation and referential transparancy, are a very very good thing to learn. Especially if you like recursion.

for example:

lenth :: [a] -> Integer
length (x:xs) = 1+length(xs)
length [] = 0

is a very simple haskell function that recurses through a list and calculates the lenght.
If you are interested in numbers bigger than long long and want to use infinite Lists and other fancy stuff, give functional programming a try.


问:
Is there any reason to use "plain old data" classes?
In legacy code I occasionally see classes that are nothing but wrappers for data. something like:

```<code>class Bottle {
   int height;
   int diameter;
   Cap capType;

   getters/setters, maybe a constructor
}
</code>```

My understanding of OO is that classes are structures for data and the methods of operating on that data. This seems to preclude objects of this type. To me they are nothing more than structs and kind of defeat the purpose of OO. I don't think it's necessarily evil, though it may be a code smell.

Is there a case where such objects would be necessary? If this is used often, does it make the design suspect?

答:
Data classes are valid in some cases.  DTO's are one good example mentioned by Anna Lear.  In general though, you should regard them as the seed of a class whose methods haven't yet sprouted.  And if you are running into a lot of them in old code, treat them as a strong code smell.  They are often used by old C/C++ programmers who have never made the transision to OO programming and are a sign of procedural programming.  Relying on getters and setters all the time (or worse yet, on direct access of non-private members) can get you into trouble before you know it. Consider an example of an external method that needs information from Bottle.

Here Bottle is a data class):

```<code>void selectShippingContainer(Bottle bottle) {
    if (bottle.getDiameter() > MAX_DIMENSION || bottle.getHeight() > MAX_DIMENSION ||
            bottle.getCapType() == Cap.FANCY_CAP ) {
        shippingContainer = WOODEN_CRATE;
    } else {
        shippingContainer = CARDBOARD_BOX;
    }
}
</code>```

Here we've given Bottle some behavior):

```<code>void selectShippingContainer(Bottle bottle) {
    if (bottle.isBiggerThan(MAX_DIMENSION) || bottle.isFragile()) {
        shippingContainer = WOODEN_CRATE;
    } else {
        shippingContainer = CARDBOARD_BOX;
    }
}
</code>```

The first method violates the Tell-Don't-Ask principle, and by keeping Bottle dumb we have let implicit knowledge about bottles, such as what makes one fragle (the Cap), slip into logic that is outside the Bottle class.  You have to be on your toes to prevent this sort of 'leakage' when you habitually rely on getters.

The second method asks Bottle only for what it needs to do its job, and leaves Bottle to decide whether it is fragile, or larger than a given size.  The result is a much looser coupling between the method and Bottle's implementation.  A pleasant side-effect is that the method is cleaner and more expressive.

You'll rarely make use of this many fields of an object without writing some logic that ought to reside in the class with those fields.  Figure out what that logic is and then move it to where it belongs.

Body:
Data classes are valid in some cases.  DTO's are one good example mentioned by Anna Lear.  In general though, you should regard them as the seed of a class whose methods haven't yet sprouted.  And if you are running into a lot of them in old code, treat them as a strong code smell.  They are often used by old C/C++ programmers who have never made the transision to OO programming and are a sign of procedural programming.  Relying on getters and setters all the time (or worse yet, on direct access of non-private members) can get you into trouble before you know it. Consider an example of an external method that needs information from Bottle.

Here Bottle is a data class):

void selectShippingContainer(Bottle bottle) {
    if (bottle.getDiameter() > MAX_DIMENSION || bottle.getHeight() > MAX_DIMENSION ||
            bottle.getCapType() == Cap.FANCY_CAP ) {
        shippingContainer = WOODEN_CRATE;
    } else {
        shippingContainer = CARDBOARD_BOX;
    }
}

Here we've given Bottle some behavior):

void selectShippingContainer(Bottle bottle) {
    if (bottle.isBiggerThan(MAX_DIMENSION) || bottle.isFragile()) {
        shippingContainer = WOODEN_CRATE;
    } else {
        shippingContainer = CARDBOARD_BOX;
    }
}

The first method violates the Tell-Don't-Ask principle, and by keeping Bottle dumb we have let implicit knowledge about bottles, such as what makes one fragle (the Cap), slip into logic that is outside the Bottle class.  You have to be on your toes to prevent this sort of 'leakage' when you habitually rely on getters.

The second method asks Bottle only for what it needs to do its job, and leaves Bottle to decide whether it is fragile, or larger than a given size.  The result is a much looser coupling between the method and Bottle's implementation.  A pleasant side-effect is that the method is cleaner and more expressive.

You'll rarely make use of this many fields of an object without writing some logic that ought to reside in the class with those fields.  Figure out what that logic is and then move it to where it belongs.


问:
What do you do when you can't seem to understand a certain part of programming?
I'm learning new languages as I go along, I write code for very basic programs in multiple languages, and I go to classes. I've read books, articles, lessons, videos, you name it, however I can't seem to get the hang of certain things.

For example I never understood pointers - what they are good at. (NOT PART OF THE QUESTION - retagging with "Pointers" is not required...)

My question however, is not what pointers do, but instead how can I understand things like that? If, after reading a book or an article about a certain part of programming, and I don't understand, what do I do? Writing code in a certain feature of programming surely helps, however it doesn't actually help with understand that much. The theoretical part is important in understanding.

答:
You have to change your focus for a while, not 5 min. or 5 hours...I mean something like 1 day without looking at that code....just chill about it...go read something different...

If you have to understand it now...ask for help from friends or here =)


答:
Practice makes perfect! (well better anyway).  Just keep trying and try to use as many different sources and senses as you can:

Sources: Books, Internet, UserGroups, friends, Video Learning, using sites that let you test little 'bit' of code like
jsfiddle (mostly html),

Rubular (Ruby expressions),

SQlzoo for trying out sql,

jslint for javascript,

code pad for many languages.

To remember abstract things consider mneomics - Doctors use them!

Consider yourself a life-long learner and stay humble and you can go far.

Title: What do you do when you can't seem to understand a certain part of programming?

Body:
I'm learning new languages as I go along, I write code for very basic programs in multiple languages, and I go to classes. I've read books, articles, lessons, videos, you name it, however I can't seem to get the hang of certain things.

For example I never understood pointers - what they are good at. (NOT PART OF THE QUESTION - retagging with "Pointers" is not required...)

My question however, is not what pointers do, but instead how can I understand things like that? If, after reading a book or an article about a certain part of programming, and I don't understand, what do I do? Writing code in a certain feature of programming surely helps, however it doesn't actually help with understand that much. The theoretical part is important in understanding.


答:
What everyone else in IT does.

I use a search engine to look up the related concepts I don't understand until I can revisit the topic I initially wanted to understand.

Chances are you also don't fully understand the stack, heap, automatic variables, the C++ compilation process, assembly, managed memory vs unmanaged memory.

More clarity on these and other pointer related concepts would probably clear everything up.


答:
In no order, books, friends, and reading well documented code are good sources.  Practice is the only way to learn: try to write small unit tests.  For example, for pointers write code that deal with strings: reverse a string, reverse each word in a string, test for palindrome, replace a letter with a number...

Ask questions on stackexchange... ;>


答:
I have tried and used just about every possible way of doing this in my current application. I started out doing the same thing that you currently do, piggy back on a user request to fill the data and then cache it going forward. I realized this was a bad idea as well (especially as you scale to multiple web servers, more users take the hit).

I also have had a scheduled job that hits a URL in the ASP.NET app - this is a decent solution but it starts to break down the minute you scale past 1 web server.

Currently I use two different methods, both using Quartz.NET which is a great little library. The first is Quartz.NET running in-process with ASP.NET, it is setup in the global.asax and runs every couple of minutes. I use this to update the ASP.NET cache out of band which is the only reason it is run as part of ASP.NET.

The second is that I wrote a library to wrap Quartz.NET called DaemonMaster - it makes it easy to drop a DLL into a directory and have it run in a Windows service. I found it helps avoid some of the annoying parts of working with a Windows Service and also cleans up the Quartz.NET api some. The services that run through DaemonMaster are of two different flavors, the first are jobs that need to run every night or every X minuts. The other jobs work off of a queue based on data coming in from the ASP.NET application. The ASP.NET app drops JSON objects on RabbitMQ and the services poll RabbitMQ then process the data.

Based on this I would suggest you go with a Windows service (and check out DaemonMaster) and if needed use a queue like RabbitMQ for passing the data from the ASP.NET app to the services - it has worked the best out of all these solutions. If you are loading cache then running in ASP.NET makes sense, otherwise I don't think it does.

DaemonMaster: http://github.com/adzerk/DaemonMaster

Quartz.NET: http://quartznet.sourceforge.net/


答:
Read any relevant documentation and Google your doubts.

Try writing code examples, see what they do.

Try executing code in debug, and watch it step by step.

If you still don't understand a certain behaviour, ask someone,
either in person or in a website like this. If you tried all of the above, you should have all the elements to compose a good question. Don't be shy :)

I think it is pretty much what everyone else does.


答:
Keep researching and learning.  I have had the same problem with various other aspects of programming.  But talking to others and reading articles eventually leads to an "AHA" moment.  Generally, it is some other Blog post or SO answer that presents the information that I am able to follow.

Basically, keep looking and be patient for the understanding to come.


答:
In my experience, it's all about input and feedback. You want to get input in as many forms as you can, and feedback on your mistakes as quickly as you can.

In my experience, my CS degree was very dry, very formal, and utterly worthless at teaching any programming whatsoever. I attended two-three lectures a week and if you don't get it then that's pretty much it- the lecturer has another class to teach and can't stick around to help you. And, odds are, that one guy understands it in a certain way, and he will teach it in a certain way and that's it, so if you don't think like him, you will never ever get it. What's worse is that since he likely understands a billion other related concepts, he will likely frame it in terms of those other concepts, which may well be way over your head or simply not even in the course material.

I went to Stack Overflow and asked in the C++ chat channel and got five different explanations in five minutes. They were all tailored specifically to me and the exact problem that I had, so it's no surprise that one of them struck home for me and I got it. The rate at which you can learn from getting live feedback from multiple experts is vastly in excess of what you can get from a dried-paper source.

So ideally, take a break, and then you would find a small to mid size group of like-minded people who have nothing better to do and chat with them live. By the way, Stack Overflow is an excellent place to get this kind of high-quality high-speed personal feedback.


答: If you have troubles with understanding an abstract concept, just go one level down. If you cannot get the pointers in C - go down to the assembly level. Still having problems? Learn more about the hardware, all the way down to the logic gates.</p>


答:
Short Incremental Learning Lifecycle

Try and fail to understand the concept.

Try to implement something illustring the concept.

Try to diagram the concept on whiteboard (if applicable)

Try to talk it through with someone who understands the concept.

Try to explain the bits you understand to this person (helps to see the light, sometimes).

Re-start from 1 until you can finally explain it to someone who is in state 1 and make them get it.

Additional Steps

To use with caution.

Search for additional reading and study material:

online (popular search engines and Wikipedia are great friends),

at the library (don't underestimate books, and the people who go there to read them),

on your system (bundled documentation and doc tools are often alienating at first, but your best goto-buddy after a while: learn to find what you are looking for in them. e.g. man -k, apropos, etc...)

Try read some code using the concept ...

... and step through the code with a debugger.

These are sneakier as you need to re-evaluate yourself to ensure you got it right. Direct mentoring by a knowledgeable person is usually better, followed of course by your own validation of the acquired knowledge by re-implementing what you just learned (and by then trying to push it one step further and learn a higher-level concept built on top of that one, e.g. linked lists for your pointers).

Credits: Nupul (for diagraming)


答:
There's no sure-fire quick way to understand a subject matter. Your success depends on how much context you bring with you in your studies. You'll be very lucky to find someone who will explain things with your point of view in mind. Like Turing machines, anyone can learn what others know, and it's just a matter of persistence and acceptance that frustration is natural.

I remember the immense difficulty I had with pointers. It wasn't until a very patient dude explained it to me like I was a complete idiot that I understood it. That's sometimes what it takes.


答:
Object-oriented approach became successful because of one crucial aspect: it lets you tackle systems of significant essential complexity without introducing too much accidental complexity. This can be almost ignored when you work on homegrown systems, but becomes very important when you build large-scale systems.

The key elements of the object-oriented approach can be explained to a programmer with extensive exposure to procedural programming in a matter of a few days, which helped the technique gain popularity quickly (this is not to say that you can become an expert in a couple of days: it's similar to learning chess - you can learn how to move your pieces in under ten minutes, but it takes years to master the game).

Functional programming techniques are gaining more importance with the introduction of language support for them into mainstream languages (lambdas and anonymous delegates of C#, lambdas of C++, and even anonymous classes of Java, to a certain degree). It is very helpful to understand these techniques, but they are designed to address more localized problems on the tactical scale. Object-oriented techniques, on the other hand, remain relevant on the strategic scale, especially in the context of larger teams.


答:
Emacs already handles indentation in the presence of unclosed parentheses, and will automatically align wilma with fred.  I have no idea why Eclipse doesn't do the same.  Ok, I have an idea, but it's uncomplimentary.

You could get Emacs to align the comment too, without much trouble, but AFAIK no one but you has ever wanted that.


答:
You can shunt work onto a background thread ( or many background threads ) using Rx and something like the following:

```<code>var scheduler = new EventLoopScheduler( SchedulerThreadName );
_workToDo = new Subject<Action>();
var queueSubscription = _workToDo.ObserveOn( scheduler ).Subscribe( work => work() );
_cleanup = new CompositeDisposable( queueSubscription, scheduler );
</code>```

To use:

```<code>var work = () => { ... };
_workToDo.OnNext( work ); // Can also put on error / on complete in here
</code>```

Host all that inside a class that there is only ever one of ( aka a singleton, but do it properly - use you IoC container to determine the lifestyle ).

You can control the size of the thread pool etc by writing a custom scheduler in place of using the EventLoopScheduler ( which runs a single thread ).

Body:
You can shunt work onto a background thread ( or many background threads ) using Rx and something like the following:

var scheduler = new EventLoopScheduler( SchedulerThreadName );
_workToDo = new Subject<Action>();
var queueSubscription = _workToDo.ObserveOn( scheduler ).Subscribe( work => work() );
_cleanup = new CompositeDisposable( queueSubscription, scheduler );

To use:

var work = () => { ... };
_workToDo.OnNext( work ); // Can also put on error / on complete in here

Host all that inside a class that there is only ever one of ( aka a singleton, but do it properly - use you IoC container to determine the lifestyle ).

You can control the size of the thread pool etc by writing a custom scheduler in place of using the EventLoopScheduler ( which runs a single thread ).


问:
Developer to team leader
How much experience is considered enough for a developer to become a team leader?

For IT managment what is the measure to check if the current team member is good enough to become a team leader (technical level, interpersonal level)

updated: removed second part of the question for being duplicate (see comments)

答:
There are a lot of great answers already, but I am going to try to give a little bit more color to the other answers:

In terms of years, I think a minimum would be 3, but I would expect most of the time it to be 5-7 years as an individual contributor first.

In general, it is much easier to move into a management (or any leadership) role if you are totally awesome at your job.  This means technical skills, but also initiative, communication, and project management.

Here are some things I would want to see before moving someone into a leadership role on my team:

They are amazing at their job

Estimates are usually spot on (since I will need them to estimate the work for their team) and they always hit deadlines

Have a great attitude, and are always willing to work on whatever is needed, even if it isn't glamorous

Other teammates look up to them as an informal leader now (either as a domain expertise on our software, or a subject matter expert in the technologies we use - obviously the first is easier to achieve with less experience or a more junior team)

Desire and ambition to do more; the best leaders have been the ones that when I ask them to do something they always come back with a result that exceeds my expectation

Are empathetic, they genuinely care about their teammates and want to see everyone be successful (this is actually the hardest trait for more junior ambitious candidates - they are not able to put their team first - after all great managers should never take credit and always take blame - and that is hard if you are a glory hog)

They are committed to the company and vision

There are likely other qualities as well, but these would be key in any leadership role.  Almost everything else can be taught (from how to listen, to how to take/give critical feedback).

Hope this helps!

Title: Developer to team leader


答:
If you are going to do FP still with languages like Haskell and Erlang that do it well, there is no need to drink the OOP cool-aid. FP Is very powerful and can do a lot even in the real world

That being said, learning an OOP language would not be a bad thing. Understanding multiple ways to program and several methodologies will work in your favor. Plus if you move from Haskell or Erlang to Java you can wonder how in the world anyone can work without a REPL and lambdas.


答:
In the development world, languages are tools, programming paradigms are tools, and libraries are tools. The more tools you have, the better able you are to select the right tool for the job. So that would argue for you to learn OO, AOP, and Functional programming - as time permits.

The development world keeps growing larger and larger (in terms of languages, frameworks, etc), so you can't expect to learn everything.  However, the goal of all these innovations are to help developers become more productive (speed of development, and reusability), and to make code more maintainable (ease of understanding, ease of extending and modifying).

The best thing you can do is to do targeted, continuous learning, in the hope that something new you just learned helped you complete something better and faster in a way you never expected.


答:
We've been pretty happy with a Service Bus / Message Queue / Service approach. The basic architecture is this.

Website sends message to queue

```<code>bus.Send(new ProjectApproved()); // returns immediately
</code>```

Windows service receives and processes message in its own time

```<code>public class DoesSomethingAwesome : ConsumerOf<ProjectApproved>
{
   public void Consume(ProjectApproved Message)
   {
      // Do something "offline"
   }
}
</code>```

The advantage is that there is no delay for the front-end service that users are connected too. The windows service can be shutdown and be upgraded without interruption to the main site. Plus it's extremely fast.

If you cannot store all of your data within the message you can always store it and retrieve it later. I suggest using a document storage mechanism such as: RavenDB or MongoDB where it's very straight forward to store your classes without changes.

Website sends message to queue

```<code>// Save your object
store.Save(completeProject);

// Send a message indicating its ready to be processed
bus.Send(new ProjectApproved() { ProjectId = completeProject.Id });
</code>```

Windows service receives and processes message in its own time

```<code>public class DoesSomethingAwesome : ConsumerOf<ProjectApproved>
{
   public void Consume(ProjectApproved Message)
   {
      // Retrieve your object back
      var completeProject = store.Get(Message.ProjectId);
   }
}
</code>```

To make things simple we use: Rhino ESB and Topshelf. The configuration is extremely simple and putting this in place for an existing application has proved to take very little time.

Body:
We've been pretty happy with a Service Bus / Message Queue / Service approach. The basic architecture is this.

Website sends message to queue

bus.Send(new ProjectApproved()); // returns immediately

Windows service receives and processes message in its own time

public class DoesSomethingAwesome : ConsumerOf<ProjectApproved>
{
   public void Consume(ProjectApproved Message)
   {
      // Do something "offline"
   }
}

The advantage is that there is no delay for the front-end service that users are connected too. The windows service can be shutdown and be upgraded without interruption to the main site. Plus it's extremely fast.

If you cannot store all of your data within the message you can always store it and retrieve it later. I suggest using a document storage mechanism such as: RavenDB or MongoDB where it's very straight forward to store your classes without changes.

Website sends message to queue

// Save your object
store.Save(completeProject);

// Send a message indicating its ready to be processed
bus.Send(new ProjectApproved() { ProjectId = completeProject.Id });

Windows service receives and processes message in its own time

public class DoesSomethingAwesome : ConsumerOf<ProjectApproved>
{
   public void Consume(ProjectApproved Message)
   {
      // Retrieve your object back
      var completeProject = store.Get(Message.ProjectId);
   }
}

To make things simple we use: Rhino ESB and Topshelf. The configuration is extremely simple and putting this in place for an existing application has proved to take very little time.


问:
How close have we gotten to automating code writing?
And I don't mean Autocomplete or automatic code snippets as inserted by modern day editors, or polymorphic code. But what is the state-of-the-art in programs that can go through given inputs and types and information of the desired outputs and output a valid piece of code in a language of choice. I am aware of Genetic Programming, Gene Expression Programming but I don't know of any other efforts. Also googling doesn't turn up much.

Is anyone aware of any advancements on this front?

Edit: When i say "output a valid piece of code", I mean an AI or something similar working out the logic and the flow of control and implement it in an imperative language. Imperative language only, since that's the tough part. Nevertheless, if you know of any new languages being developed to support this kind of idea, please do mention, as maybe our current set of languages are not suitable for the kind of early AI we may first chance upon.

答:
In the 80's and 90's there was a lot of buzz about so called 4th generation languages. From the Wikipedia article:

All 4GLs are designed to reduce programming effort, the time it takes to develop software, and the cost of software development. They are not always successful in this task, sometimes resulting in inelegant and unmaintainable code. However, given the right problem, the use of an appropriate 4GL can be spectacularly successful

...

A number of different types of 4GLs exist:

Table-driven (codeless) programming, usually running with a runtime framework and libraries. Instead of using code, the developer defines his logic by selecting an operation in a pre-defined list of memory or data table manipulation commands. In other words, instead of coding, the developer uses Table-driven algorithm programming (See also control tables that can be used for this purpose). A good example of this type of 4GL language is PowerBuilder. These types of tools can be used for business application development usually consisting in a package allowing for both business data manipulation and reporting, therefore they come with GUI screens and report editors. They usually offer integration with lower level DLLs generated from a typical 3GL for when the need arise for more hardware/OS specific operations.

Report-generator programming languages take a description of the data format and the report to generate and from that they either generate the required report directly or they generate a program to generate the report. See also RPG

Similarly, forms generators manage online interactions with the application system users or generate programs to do so.

More ambitious 4GLs (sometimes termed fourth generation environments) attempt to automatically generate whole systems from the outputs of CASE tools, specifications of screens and reports, and possibly also the specification of some additional processing logic.

Data management 4GLs such as SAS, SPSS and Stata provide sophisticated coding commands for data manipulation, file reshaping, case selection and data documentation in the preparation of data for statistical analysis and reporting.

It is interesting to contrast 4GL's with Fifth-generation programming languages:

A fifth-generation programming language (abbreviated 5GL) is a programming language based around solving problems using constraints given to the program, rather than using an algorithm written by a programmer. Most constraint-based and logic programming languages and some declarative languages are fifth-generation languages.

While fourth-generation programming languages are designed to build specific programs, fifth-generation languages are designed to make the computer solve a given problem without the programmer. This way, the programmer only needs to worry about what problems need to be solved and what conditions need to be met, without worrying about how to implement a routine or algorithm to solve them. Fifth-generation languages are used mainly in artificial intelligence research. Prolog, OPS5, and Mercury are examples of fifth-generation languages.

Ultimately, even if you don't 'program' the computer, someone still has to explain your requirements to the computer.