问:
Best practice to query data from MS SQL Server in C#?
What is the best way to query data from a MS SQL Server in C#?

I know that it is not good practice to have an SQL query in the code.

Is the best way to create a stored procedure and call it from C# with parameters?

```<code>using (var conn = new SqlConnection(connStr))
using (var command = new SqlCommand("StoredProc", conn) { CommandType = CommandType.StoredProcedure }) {
   conn.Open();
   command.ExecuteNonQuery();
   conn.Close();
}
</code>```

答:
Best practice is really overblown here -- there are lots of good ways to do it and the one you pick really should depend on what your app is and what you need to do. That said, there are only two things you can do really wrong:

As @Bill points out, you should always parameterize your queries. String building is an easy vector for SQL injection as well as all manner of hard to track down bugs. Much smarter people figured out how to tupelize and escape sql so you don't need to figure it out yourself.

Close your connections. The bestest way is to wrap everything a using statement, but try / catch / finally is cool too if that floats your boat. But always make sure you use a connection like a cheap car -- drive it hard and fast and get rid of it quick.

The other practice I would argue vehamently for is that you should make sure to concentrate your data access code in as few places as possible. We do not allow front-end web apps to hold a direct reference to System.Data.SqlClient to help enforce this caveat.


问:
Learning event driven programming
I want to learn more about event driven programming. Especially where and why I would consider using events. What resources/books should I consider reading to this end? (note: I'm indifferent to language. )</p>

答:
Consider this an addendum to the real answers. But you could look into hardware interrupts on the hardware platform of your choice. Say, on an Arduino or some such micro-controller. </p>

<p>These are what drive event-driven programming. Higher level programmers don't usually interface with them directly, but it's good to know about the underlying hardware. </p>

ContentLicense: CC BY-SA 3.0

Title: Learning event driven programming

Body:
Consider this an addendum to the real answers. But you could look into hardware interrupts on the hardware platform of your choice. Say, on an Arduino or some such micro-controller.

These are what drive event-driven programming. Higher level programmers don't usually interface with them directly, but it's good to know about the underlying hardware.


问:
IDEs for dynamic languages - how far can you get?
I find it frustrating how the speed of development that dynamic languages should offer gets significantly compromised by the lack of completions and other assets that IDEs would give you in their static counterparts.

It's not just about typing less - it's the productivity boost and plain fun you get by browsing APIs without constantly having to refer to a documentation that is not integrated with the editor.

To date all IDE + dynamic language combinations -which to be fair aren't that much- I've tried were:

buggy

slow

clueless/overenthusiastic (as in showing all completions ever possible)

or simply not as complete as, say, Eclipse + Java.

I'm aware that dynamic code analysis is not a trivial task. But one can't help wondering - is this piece of code really so hard to figure out?

So my question is:

Have any particular IDEs (or less all-in-one setups) achieved a totally outstanding support for a dynamic language, or is this still an 'unsolved' problem?

答:
Smalltalk - a highly dynamic language - has always had a superb IDE, in which little things like automatic refactoring, SUnit (the grandparent of all *Unit frameworks), "who sends this message?", "who implements this method?" and the like were pioneered. So yes, IDEs can indeed support dynamic languages to a level that, until very recently, far surpassed those of statically typed languages.

S. Lott says that "Dynamic languages cannot have the same kind of code completion that static languages do. It's essentially impossible."

"Essentially impossible" in a theoretical, absolutist sense? Sure. In a practical sense? Not really. There are many ways to infer type for dynamic languages, statically (k-CFA, RoelTyper), at run time (PICs), and other methods, like using a programmer's recent history - "How Program History Can Improve Code Completion".

Certainly the Pharo and Squeak communities are very happy with their code completion tools.


问:
System Decoupled in the Wrong Places: Meta-Problem?
At a meta level, I often find that when I grow a codebase organically, parts of the system that I eventually find need to know about each other (at least through some interface) have been mercilessly decoupled.  This often occurs in research prototype code, where one tends to frequently think of tweaks and small improvements that weren't planned for in the original codebase.

Usually, some setting or piece of data needs to be plumbed through about 15 zillion layers of function calls in ways that I never anticipated when I designed the code.  This leads to a very ugly dilemma:

Use an ugly hack.  This can be yet another global variable, bolting the data onto a class that it clearly doesn't belong in, putting a bunch of print statements in the middle of code that previously had nothing to do with I/O logic, doing a seemingly straightforward task in a very roundabout way to make it fit in my original codebase, etc.

Shotgun surgery refactoring.  This almost never gets done in practice because the code will likely have to be rewritten anyhow if it is to become production quality, was hard to get working the first time, is hard to test, or I just plain have higher priorities than writing clean, maintainable code when either I have a deadline or I know it's just a prototype for now.  Furthermore, the next tweak may break whatever nice abstractions I come up with.

Are there any good meta-tips or design principles that will help me avoid situations like this in the first place?  I am NOT looking for answers that simply recommend refactoring after the fact, as a nightmarish shotgun surgery refactoring session is exactly the kind of thing I'm trying to avoid.

答:
I think that, like a lot of other things in programming, you need balance.

Find a solution that is both good enough and doesn't require too much work (as it is a prototype anyway and you will probably change lots of other things). Next when you got the things mostly finished, you can try to see where it can be made truly good.

Don't skimp too much on the good enough part though, if your code is too bad (usually I think that adding a variable is not a problem, the big problem is lack of structure) you won't see the good change that needs to be done later.

I think as long as you keep a somewhat clear structure in your design, the rest is not that much important as it will be easily refactored out later.

Again, in the end, you are the programmer and you are the one in charge of taking the right decision regarding code clarity, time to implementation, etc. Don't try to fit a one-size-fit-all rule if you think it won't work.

ContentLicense: CC BY-SA 2.5


问:
Why do .NET shops seem to prefer Crystal Report over RDLC reports?
I am currently using RDLC reports. But when interviewing for .NET jobs, they frequently ask "Have you worked with Crystal Reports?".

Why do they like Crystal Reports when Visual Studio already has RDLC reports integrated?

答:
I work in an all .NET shop in a 'big company' and we have never used Crystal Reports for anything! Every single report that we have is run using SQL Server Reporting Services and so far it's been absolutely great for us. Once you get the hang of it it's actually a really powerful tool, especially coupled with Report Builder 3.0. It's very easy to get a report whipped up and out to the user quickly; I really hate writing reports so the less painful the better for me.

On an entirely other note, I have been using the amazingly awesome DoddleReport for all of our asp.net mvc 3 development. It has truly been a time saver and just a great experience. I've even used it in my own personal web apps and can't see using anything else, especially when using the cloud since it's impossible to get hosted SSRS working.


问:
How do you manage your knowledge base?
As programmers we have a lot of inputs:

Ebooks

Code snippets

Interesting emails

Documents

Web articles

Blog posts

StackOverflow questions

Podcasts
...

Which tools do you use to store, organize, search and consult all of this stuff?

Is there a silver bullet solution to handle this huge amount of data?

答: We came across a similar situation where we had a lot of documents, FAQs to be shared among team members and website visitors and we decided to opt for PHPKB knowledge base software. We have been using it for over 2 years now and I can recommend it to you as well.</p>

Title: How do you manage your knowledge base?


问:
Is it a really required skill to program without API documentation?
I barely passed my Java programming exam today. I had to answer some general questions about threading which I did well and to write a little threaded program which was worse. I had to connect my laptop to the projector screen and write the program right away. My first attempt was to use anonymous classes but I forgot the exact syntax. Maybe because of some excitement or maybe because last two weeks I was coding mostly in php. Then I asked is it allowed to use the API documentation. The answer was "NO". So I decided to go another way around and I implemented Runnable. The program was doing what was requested at the end. Of course the examiners noticed my first fail and that affected my score greatly. I was amazed that it was not allowed to use the API documentation.

So, my question is: Is it really important to be able to code flawlessly without API documentation? Should I develop this skill? Is it really important in the real world and in the work environment? While on programming courses I focused on learning patterns, developing skills to write good design applications, skills to use API and find the necessary information fast. I was not trying to learn how to program without API documentation. Is it must-have during job interviews (coding without API documentation)?

答:
In Eclipse you can write obj. and press ctrl+space and it will try to auto-complete by giving you all the method options for the given object. If that fails me for some reason the Java API has the rest of the answers. I'd be hard pressed to think of a day when I didn't Google how to do something.

School is a completely different story though.


问:
Easiest way to create static HTML file with sortable and filterable table?
I want to create a static HTML file I can email to someone with a lot of data, and have that data sortable and filterable.  What is the easiest to use library or package I can use to get this off the ground?</p>

答:
You Can achieve this easily by using the following,

   HTML & CSS - Presentation,

   Java Script / jQuery - Logic,

   XML - You Raw Data,

Since you have asked for the open sources, so i would suggest you this one Click Here Which has documentation and source for both filter and sort functionality.

Happy coding,

Cheers,

Arun


问:
Make a big deal out of == true?
There is a colleague of mine who constantly writes:

```<code>if (someBool == true)
</code>```

It drives me up the wall!  Should I make a big deal of it or just drop it?

答:
Comparing booleans can actually cause major problems. I recently ran into some intern code that read:

```<code>if(foo == false && bar == 2) {...}
</code>```

Now, this seems pretty straight-forward, right? Just simplify it down to:

```<code>if(!foo && bar == 2) {...}
</code>```

Wrong. In this case, order of operations dictates that the && gets evaluated first, meaning that this really evaluates to:

```<code>if(foo == (false && bar == 2))
</code>```

also known as

```<code>if(!foo)
</code>```

That extra thing we were supposed to be checking for, bar == 2, is totally gone. That is why I will never, ever approve a code review that contains someBool == [true|false].

(You can see how the reverse statement, == true and ||, would also cause problems.)

Title: Make a big deal out of == true?

Body:
Comparing booleans can actually cause major problems. I recently ran into some intern code that read:

if(foo == false && bar == 2) {...}

Now, this seems pretty straight-forward, right? Just simplify it down to:

if(!foo && bar == 2) {...}

Wrong. In this case, order of operations dictates that the && gets evaluated first, meaning that this really evaluates to:

if(foo == (false && bar == 2))

also known as

if(!foo)

That extra thing we were supposed to be checking for, bar == 2, is totally gone. That is why I will never, ever approve a code review that contains someBool == [true|false].

(You can see how the reverse statement, == true and ||, would also cause problems.)


问:
Which arguments pass by value and which pass by reference in Java?
I am starting to learn Java with the Java Trails tutorials offered by Oracle. I am in the section where it talks about passing arguments to methods The Java™ Tutorials: Passing Information to a Method or a Constructor.

It says that primitive types are passed by value, which makes sense to me. Right after that it says:

Reference data type parameters, such as objects, are also passed into
  methods by value. This means that when the method returns, the
  passed-in reference still references the same object as before.
  However, the values of the object's fields can be changed in the
  method, if they have the proper access level.

Now this doesn't make sense to me. If an object is passed by value, then changing the fields of that object will change the fields of the copy inside the method, not the original one.

When testing with the program below:

```<code>class Point {
    int x;
    int y;

    public static void movePoint(Point p, int x, int y) {
        p.x+=x;
        p.y+=y;
    }
}
</code>```

```<code>class App {
    public static void main(String argv[]) {
        Point p1;

        p1 = new Point();
        p1.x = 2;
        p1.y = 3;

        p1.movePoint(p1,2,2);

        System.out.println("x = " + p1.x +  " y = " + p1.y);
    }
}
</code>```

It worked as if the object was being passed by reference (it prints out x = 4 y = 5 after all).

So what exactly did Oracle mean in the passage above? Also, can anyone summarize what's passed by value and what's passed by reference in Java?

答: Java is pass by value. Think of it like a pointer language like C, the value of the pointer (memory address) is being passed, so you have a reference to the same object. Primitives aren't stored internally the same way as Objects, so when you pass a primitive's value, it's the content, not a pointer.


问:
Managers X Motivation
As a programmer what do you think that is the thing that your manager does that mostly decreases your motivation?

My manager insists in blocking web content (this week was msdn content and Microsoft domain sites) This is so stupid, make me think I am not a reliable professional or that I am stealing his internet. And not, it is not a small business. It is a huge enterprise where such dinossaurs should not exist anymore.

答:
Lack of recognition and reward for effort...

This is a common issue in software development (and in salaried knowledge work in general), but it is particularly pronounced in my current role - where the product I'm working on is a massive, 7-figure per month cash cow for the company.

It's very demotivating to think of the huge packages, options, and big fat bonuses the higher-ups get (often in a year when a feature I implemented sells a large number of extra licenses) - while I get the same salary no matter how much, or how little, effort I put in. It tends to put me in the burned out, unmotivated, "working just hard enough not to get fired" mentality of Peter Gibbons from Office Space.

Title: Managers X Motivation


答:
Notebook for Macintosh. I've been using it for several years.

A notebook metaphor - with tabbed pages, automatic table of contents, automatically indexes every word in the notebook

Outline pages, to-do lists

free-form pages

templates, customizable look

imbed links, images, video

free-form content layout

diagramming, notes, bookmarks, highlights - can overlay other content

Clip any highlighted anything from any application or web page directly to notebook - without even opening notebook.

export as a web site

Title: How do you manage your knowledge base?

Body:
As programmers we have a lot of inputs:

Ebooks

Code snippets

Interesting emails

Documents

Web articles

Blog posts

StackOverflow questions

Podcasts
...

Which tools do you use to store, organize, search and consult all of this stuff?

Is there a silver bullet solution to handle this huge amount of data?


答:
From all IDEs for dynamic languages (languages that resolve type at runtime) the best one is... Visual Studio for Python

Bulling type information for Intellisense

Navigation

Debuging

It's worth to try.

Title: IDEs for dynamic languages - how far can you get?

Body:
I find it frustrating how the speed of development that dynamic languages should offer gets significantly compromised by the lack of completions and other assets that IDEs would give you in their static counterparts.

It's not just about typing less - it's the productivity boost and plain fun you get by browsing APIs without constantly having to refer to a documentation that is not integrated with the editor.

To date all IDE + dynamic language combinations -which to be fair aren't that much- I've tried were:

buggy

slow

clueless/overenthusiastic (as in showing all completions ever possible)

or simply not as complete as, say, Eclipse + Java.

I'm aware that dynamic code analysis is not a trivial task. But one can't help wondering - is this piece of code really so hard to figure out?

So my question is:

Have any particular IDEs (or less all-in-one setups) achieved a totally outstanding support for a dynamic language, or is this still an 'unsolved' problem?


问:
Performance of Scala compared to Java
First of all I would like to make it clear that this is not a language-X-versus-language-Y question to determine which is better.

I have been using Java for a long time and I intend to keep using it. Parallel to this, I am currently learning Scala with great interest: apart from minor things that take some getting used to my impression is that I can really work very well in this language.

My question is: how does software written in Scala compare to software written in Java in terms of execution speed and memory consumption?
Of course, this is a difficult question to answer in general, but I would expect that higher level constructs such as pattern matching, higher-order functions, etc, introduce some overhead.

However, my current experience in Scala is limited to small examples under 50 lines of code and I haven't run any benchmarks up to now. So, I have no real data.

If it turned out that Scala does have some overhead wrt Java, does it make sense to have mixed Scala / Java projects, where one codes the more complex parts in Scala and the performance-critical parts in Java? Is this a common practice?

EDIT 1

I have run a small benchmark: build a list of integers, multiply each integer by two and put it in a new list, print the resulting list. I wrote a Java implementation (Java 6) and a Scala implementation (Scala 2.9). I have run both on Eclipse Indigo under Ubuntu 10.04.

The results are comparable: 480 ms for Java and 493 ms for Scala (averaged over 100 iterations). Here are the snippets I have used.

```<code>// Java
public static void main(String[] args)
{
    long total = 0;
    final int maxCount = 100;
    for (int count = 0; count < maxCount; count++)
    {
        final long t1 = System.currentTimeMillis();

        final int max = 20000;
        final List<Integer> list = new ArrayList<Integer>();
        for (int index = 1; index <= max; index++)
        {
            list.add(index);
        }

        final List<Integer> doub = new ArrayList<Integer>();
        for (Integer value : list)
        {
            doub.add(value * 2);
        }

        for (Integer value : doub)
        {
            System.out.println(value);
        }

        final long t2 = System.currentTimeMillis();

        System.out.println("Elapsed milliseconds: " + (t2 - t1));
        total += t2 - t1;
    }

    System.out.println("Average milliseconds: " + (total / maxCount));
}

// Scala
def main(args: Array[String])
{
    var total: Long = 0
    val maxCount    = 100
    for (i <- 1 to maxCount)
    {
        val t1   = System.currentTimeMillis()
        val list = (1 to 20000) toList
        val doub = list map { n: Int => 2 * n }

        doub foreach ( println )

        val t2 = System.currentTimeMillis()

        println("Elapsed milliseconds: " + (t2 - t1))
        total = total + (t2 - t1)
    }

    println("Average milliseconds: " + (total / maxCount))
}
</code>```

So, in this case it seems that the Scala overhead (using range, map, lambda) is really minimal, which is not far from the information provided by
World Engineer.

Maybe there are other Scala constructs that should be used with care because they are particularly heavy to execute?

EDIT 2

Some of you pointed out that the println's in the inner loops take up most of
the execution time. I have removed them and set the size of the lists to 100000 instead of 20000. The resulting average was 88 ms for Java and 49 ms for Scala.

答: According to the Benchmarks Game for a single core, 32 bit system, Scala is at a median 80% as fast as Java. The performance is approximately the same for a Quad Core x64 computer. Even memory usage and code density are very similar in most cases. I would say based on these (rather unscientific) analyses that you are correct in asserting that Scala adds some overhead to Java. It does not appear to add tons of overhead so I'd suspect the diagnosis of higher order items taking up more space/time is the most correct one. </p>

Title: Performance of Scala compared to Java


问:
Why do we have so many flavors of .NET? Is it a good thing?
There are many "flavors" of the .NET Framework:

Full ("normal")

Client profile subset

Silverlight in web browsers

"Silverlight" on Windows Phone

Compact framework

WinRT

When C# code is needed on a new platform, it would seem that Microsot prefer to take the full CLR and strip it down to a small subset, creating new assemblies and moving types around, instead of just using existing assemblies such as those in the BCL. Silverlight for example has different classes/methods to WPF (even down to some methods having slightly different signatures or very different implementations), instead of simply referencing the same implementation of List<T> as WPF.

Is this the ideal architecture, or a sign of legacy? Shouldn't the BCL run on all platforms, with just different presentation/IO libraries on each? Or are the BCL and other libraries too bloated, and splitting them out would create too many backward compatibility problems, to be acceptable?

If we started from a blank canvas and weren't worried about backwards compatibility, would the current situation really be the best way to handle multiple platforms?

答:
What Microsoft is doing, splitting the routines into multiple packages, is common. There is a version of .NET that runs on single board computers (.Net Micro Framework) with limited memory. It would not make any sense to include in that version everything required to run a full graphical user interface for example.

If you look at Apple, the iPhone does not contain all the routines that one would find on a Mac.


问:
Node.js, socket.io vs User Initiated Refresh button and Server Load Considerations
I'm dealing with a situation here on a high volume multi-tenant web app with over 100k users from companies who do not appreciate performance issues. We have a need for "real-time" updates.. we're basically sending out a request to a 3rd party system, and we'd like to see the results real-time, there's about 5 statuses returned, and the first three statuses happen very quickly (within a minute or so)..

Our current implementation is to have a refresh cycle which happens every five minutes.. (partial page postback with Jquery), the user can override this by clicking on a refresh button..

The reason we went with this approach is because of the potential server load with "long-polling", or frequent post backs (every 2 seconds), and the burdon it would put on our server (we have a few Databases and Webservers, so maintaining a changelog is out of the question) at the time we hadnt looked into node.js / socket.io, which brings me to my question:

if socket.io only works on modern browsers and has to revert to either Flash or Long-polling if the required functionality is not available in the browser, is there really any benefit to using this technology today (as opposed to 2 years from now when the last of the i.e 6 users are forced to update)? the problem is we dont want to bring the server to it's knees because worst case this thing is going to keep the http connections open for an extended duration and really mess up our users experience (our apps on the webserver, i did not design the system)

答:
So you have a web application with over 100k users and you do not already have performance stats?  Shame shame.

The issue with polling overloading your web servers is likely not going to be fixed with a single solution.  A Flash object will still need to communicate with a server somewhere but even with this approach you cannot be verified that all users have Flash installed.  I don't have Flash on my workstation, and iPad users will likely not be able to correctly use your site (if that is even an issue).  You are guaranteed that in a few years IE6 will virtually disappear but there will always be browser clients who do not accept Flash.

HTTP communication for polling is expensive but you may want to check the User Agent and use that information to decide which polling method you can use.  TCP/IP socket communication has slightly less overhead and is preferable.


问:
Is querying KeyValue Pairs efficient compared to two-property objects?
I'm working on a webservice and I'm returning JSON. However, I'm returning a List<KeyValuePair<string, int>>, since that's all I'm really ever going to be dealing with (property => value)

Now sometimes I myself will be calling these functions to aggregate the results, so I end up with something like

```<code>List<KeyValuePair<string, int>> myList = resultList.where(o => o.Key =="StringKEY");
</code>```

and sometimes

```<code>List<KeyValuePair<string, int>> myList = resultList.sum(o => o.Key =="StringKEY");
</code>```

My question is, would it be more efficient to do the following (custom class vs dictionary):

```<code>List<MyObject> myObj = resultObjList.where(o => o.Property1 == "stringProperty")
</code>```

and so on.

Is there any benefit to using custom objects? I will not ever need to be adding properties, and in this case I can say there will never be a need for additional properties.

答:
You're asking what is the difference between a KeyValuePair and a two-property object? There is none, KeyValuePair is a two-property object. Actually, there might be a difference: KeyValuePair is a value type and your custom object will probably be a reference type. The difference between a reference type and value type can have an impact on the performance (especially in some specific environments, like XNA on XBox). But if this difference is important for you, you can always make your custom type into a value type.

So, my advice is to use KeyValuePair for things that actually are a key and a value. If the relation between the two values is different, you should create your custom type, for readability sake.

Another option in C# 7.0 and newer is to use tuples. They're value types, just like KeyValuePar, but using them does not imply you have a key and a value.


答:
I don't think .NET is the problem.  While there are various runtimes, they are still compatible, which is why technologies like the Portable Class Libraries works (for the majority of the runtimes you listed).

For example, shouldn't each flavor reference a single, shared assembly called "System.Collections.dll", instead of each runtime having its own copy of System.dll/mscorlib.dll with various copies of the collections?

Why is this needed?  As long as they are all compatible (again, see the Portable Class Libraries), this shouldn't matter, as the BCL is part of the runtime itself, and distributed in tandem.

Title: Why do we have so many flavors of .NET? Is it a good thing?

Body:
There are many "flavors" of the .NET Framework:

Full ("normal")

Client profile subset

Silverlight in web browsers

"Silverlight" on Windows Phone

Compact framework

WinRT

When C# code is needed on a new platform, it would seem that Microsot prefer to take the full CLR and strip it down to a small subset, creating new assemblies and moving types around, instead of just using existing assemblies such as those in the BCL. Silverlight for example has different classes/methods to WPF (even down to some methods having slightly different signatures or very different implementations), instead of simply referencing the same implementation of List<T> as WPF.

Is this the ideal architecture, or a sign of legacy? Shouldn't the BCL run on all platforms, with just different presentation/IO libraries on each? Or are the BCL and other libraries too bloated, and splitting them out would create too many backward compatibility problems, to be acceptable?

If we started from a blank canvas and weren't worried about backwards compatibility, would the current situation really be the best way to handle multiple platforms?


问:
MVVM Reporting App Approach ? Data Access Layer?
I'm trying to follow the MVVM pattern in a reporting / statistics application that I'm making in C# / WPF.

I have made many model classes to hold properties as a starting point. Some of these models are made to encapsulate different statistics so that I can present data that can be cross refrenced.

I'm thinking the next step is to create a data access layer with classes and methods to connect to a database and grab the values to populate these models.

I was thinking of creating a connection and query passing class. Then other classes for each specific set of data that I will need for the models. (constructing queries to pass)

From what I understand I will be calling these data access layer methods from the view model to populate instances of my models. Which I will present with the view.

Is my approach in theory the correct standard way to approach this problem? Any suggestions? Or Reference Material?

答:
You're definitely on the right track in making a Data Access Layer, although I would suggest making it more like a mysterious black box whose inner workings are unknown.

What I mean by this is your objects should be able to use the DAL to get/save objects, but they should have no idea how the data is actually obtained.

For example, instead of your ViewModel saying DAL.GetDataSet(someConnection, someQuery), you should call DAL.GetAccounts() which returns a list of AccountModel objects. The ViewModel should not care how or where the data is obtained from, only that it can magically get the objects it needs from the mysterious DAL object.

This keeps your data layer entirely separate, so if you ever need to change it out or adjust the queries, its all in one central location.

As a side note, your ViewModels should be the layer accessing the DAL. Models are simply dumb objects which contain data. They should have no advanced functionality, such as data access.


答: .NET is essentially replacing and expanding com objects in a windows environment. It's also used to identify a lot of vastly different technologies, imagine if Adobe renamed all their products to have a common word in their name, that's sort of whats happening with .NET</p>


问:
I am trying to figure out how difficult or expensive it would be to add this feature
I am trying to figure out how difficult/time consuming it would be to add the following feature:

We have a database with our subscribers and we want to send updates to paying subscribers. The catch is that we want these updates to be date dependent. Let me clarify.

Joe signed up in June last year. He has been receiving monthly newsletters since June. Now Fred signed up in April, cancelled in May and resubscribed in August. We want to send an update to Joe regarding his June newsletter. Fred was no longer a subscriber in June and we don't want him to receive the same update for various reasons.

Is this a feature that you would expect to cost 100's, 1000's, 10,000's dollars to implement?

**Edit: I should've been more clear, I was looking for a magnitude not an exact cost. It's evident, I know very little about programming which is why I came here. If someone asked me what it would cost abandon a well, I could easily give them an order of magnitude. I appreciate all of the responses; this is an incredible resource.

答: Your database is not really "date-based" - your logic is. Most databases have a date or datetime data type. Your program needs to look at the dates that users subscribed and look at the current date and then look at which users are currently subscribed... using that information, your program should be able to figure out who gets a newsletter. As for cost, it's impossible to say for sure (not knowing what other systems you have and need to integrate with), but this feature should not be very complex based on how it's described here.</p>


答:
Use socket.io and configure it to do polling over a 5 minute interval as the websocket fallback.

Seriously websockets are awesome, use them if possible and fallback to something that has an acceptable server load.

because worst case this thing is going to keep the http connections open for an extended duration

If this brings your web server to it's knees then your web server is a crap one. Get one that can handle open sockets and scale.

Title: Node.js, socket.io vs User Initiated Refresh button and Server Load Considerations

Body:
I'm dealing with a situation here on a high volume multi-tenant web app with over 100k users from companies who do not appreciate performance issues. We have a need for "real-time" updates.. we're basically sending out a request to a 3rd party system, and we'd like to see the results real-time, there's about 5 statuses returned, and the first three statuses happen very quickly (within a minute or so)..

Our current implementation is to have a refresh cycle which happens every five minutes.. (partial page postback with Jquery), the user can override this by clicking on a refresh button..

The reason we went with this approach is because of the potential server load with "long-polling", or frequent post backs (every 2 seconds), and the burdon it would put on our server (we have a few Databases and Webservers, so maintaining a changelog is out of the question) at the time we hadnt looked into node.js / socket.io, which brings me to my question:

if socket.io only works on modern browsers and has to revert to either Flash or Long-polling if the required functionality is not available in the browser, is there really any benefit to using this technology today (as opposed to 2 years from now when the last of the i.e 6 users are forced to update)? the problem is we dont want to bring the server to it's knees because worst case this thing is going to keep the http connections open for an extended duration and really mess up our users experience (our apps on the webserver, i did not design the system)


答:
This can easily be done with a database that is free like MySQL or one of the free edition of Microsoft's SQL Server provided you are not talking about hundreds of millions of records.

As for the programming to set this up, I would guess this could be done in one day or less. Cost is a function of your local wage rates and negotiating skills.

Title: I am trying to figure out how difficult or expensive it would be to add this feature

Body:
I am trying to figure out how difficult/time consuming it would be to add the following feature:

We have a database with our subscribers and we want to send updates to paying subscribers. The catch is that we want these updates to be date dependent. Let me clarify.

Joe signed up in June last year. He has been receiving monthly newsletters since June. Now Fred signed up in April, cancelled in May and resubscribed in August. We want to send an update to Joe regarding his June newsletter. Fred was no longer a subscriber in June and we don't want him to receive the same update for various reasons.

Is this a feature that you would expect to cost 100's, 1000's, 10,000's dollars to implement?

**Edit: I should've been more clear, I was looking for a magnitude not an exact cost. It's evident, I know very little about programming which is why I came here. If someone asked me what it would cost abandon a well, I could easily give them an order of magnitude. I appreciate all of the responses; this is an incredible resource.


答:
For each project, I keep a project Wiki using WikiDPad. It is heavyweight enough to do what I need to do, but not overkill like MediaWiki. The trick to keeping organized is to use one medium-sized Wiki per project, not one enormous Wiki for everything.

Home Page

Title: How do you manage your knowledge base?


答: I program all day in javascript/php and ruby working on web applications and the best IDE that I have found for this is  Aptana.  It has code completion for all three of those languages (and python) it picks up my local vars and on top of that when working with html and css it picks up id's in the html for use in the css/javascript, and picks up function names for when I am doing something quick and dirty and writing inline javascript (I know bad, but sometimes useful for proof of concept). It has built in rake tasks and built in support for git and a command line console. It took me a bit to get up but once I did I find that I hardly ever leave my IDE when coding and it saves me tons of time.</p>


答:
Scala performance is very decent if you just write Java/C-like code in Scala. The compiler will use JVM primitives for Int, Char, etc. when it can. While loops are just as efficient in Scala.

Keep in mind that lambda expressions are compiled to instances of anonymous subclasses of the Function classes. If you pass a lambda to map, the anonymous class needs to be instantiated (and some locals may need to be passed), and then every iteration has extra function call overhead (with some parameter passing) from the apply calls.

Many classes like scala.util.Random are just wrappers around equivalent JRE classes. The extra function call is slightly wasteful.

Watch out for implicits in performance-critical code. java.lang.Math.signum(x) is much more direct than x.signum(), which converts to RichInt and back.

Scala's main performance benefit over Java is specialization. Keep in mind that specialization is used sparingly in library code.

Title: Performance of Scala compared to Java

Body:
First of all I would like to make it clear that this is not a language-X-versus-language-Y question to determine which is better.

I have been using Java for a long time and I intend to keep using it. Parallel to this, I am currently learning Scala with great interest: apart from minor things that take some getting used to my impression is that I can really work very well in this language.

My question is: how does software written in Scala compare to software written in Java in terms of execution speed and memory consumption?
Of course, this is a difficult question to answer in general, but I would expect that higher level constructs such as pattern matching, higher-order functions, etc, introduce some overhead.

However, my current experience in Scala is limited to small examples under 50 lines of code and I haven't run any benchmarks up to now. So, I have no real data.

If it turned out that Scala does have some overhead wrt Java, does it make sense to have mixed Scala / Java projects, where one codes the more complex parts in Scala and the performance-critical parts in Java? Is this a common practice?

EDIT 1

I have run a small benchmark: build a list of integers, multiply each integer by two and put it in a new list, print the resulting list. I wrote a Java implementation (Java 6) and a Scala implementation (Scala 2.9). I have run both on Eclipse Indigo under Ubuntu 10.04.

The results are comparable: 480 ms for Java and 493 ms for Scala (averaged over 100 iterations). Here are the snippets I have used.

```<code>// Java
public static void main(String[] args)
{
    long total = 0;
    final int maxCount = 100;
    for (int count = 0; count < maxCount; count++)
    {
        final long t1 = System.currentTimeMillis();

        final int max = 20000;
        final List<Integer> list = new ArrayList<Integer>();
        for (int index = 1; index <= max; index++)
        {
            list.add(index);
        }

        final List<Integer> doub = new ArrayList<Integer>();
        for (Integer value : list)
        {
            doub.add(value * 2);
        }

        for (Integer value : doub)
        {
            System.out.println(value);
        }

        final long t2 = System.currentTimeMillis();

        System.out.println("Elapsed milliseconds: " + (t2 - t1));
        total += t2 - t1;
    }

    System.out.println("Average milliseconds: " + (total / maxCount));
}

// Scala
def main(args: Array[String])
{
    var total: Long = 0
    val maxCount    = 100
    for (i <- 1 to maxCount)
    {
        val t1   = System.currentTimeMillis()
        val list = (1 to 20000) toList
        val doub = list map { n: Int => 2 * n }

        doub foreach ( println )

        val t2 = System.currentTimeMillis()

        println("Elapsed milliseconds: " + (t2 - t1))
        total = total + (t2 - t1)
    }

    println("Average milliseconds: " + (total / maxCount))
}
</code>```

So, in this case it seems that the Scala overhead (using range, map, lambda) is really minimal, which is not far from the information provided by
World Engineer.

Maybe there are other Scala constructs that should be used with care because they are particularly heavy to execute?

EDIT 2

Some of you pointed out that the println's in the inner loops take up most of
the execution time. I have removed them and set the size of the lists to 100000 instead of 20000. The resulting average was 88 ms for Java and 49 ms for Scala.


答:
The logic is not difficult. I recommend reading the book "Developing Time-Oriented Database Applications in SQL." While this book is out of print, the author has graciously made available the PDF of the book as well as the associated CD on his website.

http://www.cs.arizona.edu/~rts/publications.html (look for the first item under "books").


答:
The main difference between statically typed languages and dynamically typed languages is that the system can know, for sure, Just what a symbol reference means at compile time.

This makes it really easy to gather the information you need to make a good IDE directly from the info generated by the compiler at compile time (which is simply moved up to "edit" time for the most part).

If you have a stand-alone method signature that just says the method takes a "Thing" how can an editor help you know what to send?  How can it help suggest ways to use the thing?

Duck-typing doesn't help here either--even the most intelligent editor possible won't be able to tell you that simply because your object has a .executeFooOp() method that it can code-complete ".executeBarOp" on that object (Although it could scour the rest of the code base and make some intelligent guesses).

If you know that it's a "String" in the signature, however, you know all the methods that you might call on that string AND you are able to suggest that variable when that user is in the middle of typing a method call that requires a String as a parameter.  You could even suggest sub-classes that it could be cast into if you wanted to.

The information just isn't there with dynamically typed languages unless you can do a complete scan of the entire codebase with something MUCH more intelligent than your typical compiler.


答:
There's one thing that you can do concisely and efficiently in Java that you can't in Scala: enumerations. For everything else, even for constructs that are slow in Scala's library, you can get efficient versions working in Scala.

So, for the most part, you don't need to add Java to your code. Even for code that uses enumeration in Java, there's often a solution in Scala that is adequate or good -- I place the exception on enumerations that have extra methods and whose int constant values are used.

As for what to watch out for, here are some things.

If you use the enrich my library pattern, always convert to a class. For example:

```<code>// WRONG -- the implementation uses reflection when calling "isWord"
implicit def toIsWord(s: String) = new { def isWord = s matches "[A-Za-z]+" }

// RIGHT
class IsWord(s: String) { def isWord = s matches "[A-Za-z]+" }
implicit def toIsWord(s: String): IsWord = new IsWord(s)
</code>```

Be wary of collection methods -- because they are polymorphic for the most part, JVM does not optimize them. You need not avoid them, but pay attention to it on critical sections. Be aware that for in Scala is implemented through method calls and anonymous classes.

If using a Java class, such as String, Array or AnyVal classes that correspond to Java primitives, prefer the methods provided by Java when alternatives exist. For example, use length on String and Array instead of size.

Avoid careless use of implicit conversions, as you can find yourself using conversions by mistake instead of by design.

Extend classes instead of traits. For example, if you are extending Function1, extend AbstractFunction1 instead.

Use -optimise and specialization to get most of Scala.

Understand what is happening: javap is your friend, and so are a bunch of Scala flags that show what's going on.

Scala idioms are designed to improve correctness and make the code more concise and maintainable. They are not designed for speed, so if you need to use null instead of Option in a critical path, do so! There's a reason why Scala is multi-paradigm.

Remember that the true measure of performance is running code. See this question for an example of what may happen if you ignore that rule.

Title: Performance of Scala compared to Java

Body:
There's one thing that you can do concisely and efficiently in Java that you can't in Scala: enumerations. For everything else, even for constructs that are slow in Scala's library, you can get efficient versions working in Scala.

So, for the most part, you don't need to add Java to your code. Even for code that uses enumeration in Java, there's often a solution in Scala that is adequate or good -- I place the exception on enumerations that have extra methods and whose int constant values are used.

As for what to watch out for, here are some things.

If you use the enrich my library pattern, always convert to a class. For example:

// WRONG -- the implementation uses reflection when calling "isWord"
implicit def toIsWord(s: String) = new { def isWord = s matches "[A-Za-z]+" }

// RIGHT
class IsWord(s: String) { def isWord = s matches "[A-Za-z]+" }
implicit def toIsWord(s: String): IsWord = new IsWord(s)

Be wary of collection methods -- because they are polymorphic for the most part, JVM does not optimize them. You need not avoid them, but pay attention to it on critical sections. Be aware that for in Scala is implemented through method calls and anonymous classes.

If using a Java class, such as String, Array or AnyVal classes that correspond to Java primitives, prefer the methods provided by Java when alternatives exist. For example, use length on String and Array instead of size.

Avoid careless use of implicit conversions, as you can find yourself using conversions by mistake instead of by design.

Extend classes instead of traits. For example, if you are extending Function1, extend AbstractFunction1 instead.

Use -optimise and specialization to get most of Scala.

Understand what is happening: javap is your friend, and so are a bunch of Scala flags that show what's going on.

Scala idioms are designed to improve correctness and make the code more concise and maintainable. They are not designed for speed, so if you need to use null instead of Option in a critical path, do so! There's a reason why Scala is multi-paradigm.

Remember that the true measure of performance is running code. See this question for an example of what may happen if you ignore that rule.


答:
a) From my limited knowledge, I have to remark, that code in the static main method can't be optimized very good. You should move the critical code to a different location.

b) From long observations I would recommend not to do heavy output on performance test (except it is exactly what you like to optimize, but who should ever read 2 Million values?). You're measuring println, which isn't very interesting. Replacing the println with max:

```<code>(1 to 20000).toList.map (_ * 2).max
</code>```

reduces the time from 800 ms to 20 on my system.

c) The for-comprehension is known to be a little slow (while we have to admit it's getting better all the time). Use while or tailrecursive functions instead. Not in this example, where it is the outer loop. Use the @tailrec-annotation, to test for tairecursiveness.

d) Comparing with C/Assembler fails. You don't rewrite scala code for different architectures for example. Other important difference to historic situations are

JIT-compiler, optimizing on the fly, and maybe dynamically, depending on input data

The importance of cache misses

The rising importance of parallel invocation. Scala today has solutions to work without much overhead in parallel. That's not possible in Java, except you do much more work.

Title: Performance of Scala compared to Java

Body:
a) From my limited knowledge, I have to remark, that code in the static main method can't be optimized very good. You should move the critical code to a different location.

b) From long observations I would recommend not to do heavy output on performance test (except it is exactly what you like to optimize, but who should ever read 2 Million values?). You're measuring println, which isn't very interesting. Replacing the println with max:

(1 to 20000).toList.map (_ * 2).max

reduces the time from 800 ms to 20 on my system.

c) The for-comprehension is known to be a little slow (while we have to admit it's getting better all the time). Use while or tailrecursive functions instead. Not in this example, where it is the outer loop. Use the @tailrec-annotation, to test for tairecursiveness.

d) Comparing with C/Assembler fails. You don't rewrite scala code for different architectures for example. Other important difference to historic situations are

JIT-compiler, optimizing on the fly, and maybe dynamically, depending on input data

The importance of cache misses

The rising importance of parallel invocation. Scala today has solutions to work without much overhead in parallel. That's not possible in Java, except you do much more work.


答:
It is not easy to estimate the cost: it depends on the complexity of your system. It also depends on your development process.

Storing dates and filtering according to these dates is not difficult to implement in a database. But still, it needs to be well designed. You might choose between an implicit and an explicit storage of the user subscription history.

In some databases, you can let the dbms store versions of a row, with change dates being stored automatically. For example in Sql Server (starting from 2008), you might use Change data capture ( http://msdn.microsoft.com/en-us/library/bb522489.aspx ).

As an example of an explicit storage of the history, you might read this question
: https://stackoverflow.com/questions/296017/what-is-the-best-way-to-store-historical-data-in-sql-server-2005-2008 .


问:
What are the different methods of dividing and organizing work among project team members?
In my team, everyone would like to do everything, including backend, frontend, middle layer. I told them that we should divide the work according to roles and area of expertise.

What are the pros and cons of dividing the work vertically (each user story is done by the same person from the back end to the front end) versus dividing the work horizontally (each abstraction layer is done by the same person)?

答:
You're dealing with people and each team has a different DNA. What works best for your team & product, might be bad practice in another situation.

Just let the team try it their way, and discuss after a few weeks what went well and what went wrong.


问:
Project organization with professionals and students
I am working as a PhD student developing scientific/engineering simulations and algorithms to be tested in these simulations. These days the first student started to work on my project (for his Bachelor thesis) and I am wondering: how should I organize the project now? I think I have some good C++ knowledge (although I still want to improve everyday!) and the code contains some design patterns, lots of templated classes etc. These techniques are new to the student and I wonder if it's a good idea to have him work directly in the trunk of the project.

Do you have any experiences what happens if programming newbies and more experienced programmers are mixed? Does the code get messed up or do the newbies learn more by this? Is it wise to have a branch for the student to test his algorithms and maybe merge them into the trunk later? Should I first give him a book like The Pragmatic Programmer for reading (better suggestions?)?

Thanks for every answer!

PLEASE NOTE: I asked this question on Stackoverflow. The answer was about code reviews and I think this is a good way, but I was also advised that this site might be the more correct one, so I wanted to see if there are more things that might help or other opinions?

答: I agree with the code review and branching advise already given. I would also have them participate in design reviews. Have them peer review your design and you peer review their design. That way they learn and hopefully implement better code and design and sometimes newbies point out things that you missed just because they don't assume as much as experienced people.</p>


问:
Interface naming: prefix 'Can-' vs suffix '-Able'
It's common to use '-able' as a suffix for interfaces e.g.

Serializable
Printable
Enumerable
Drinkable
Shootable
Rotatable

I was thinking that 'Can-' might better because it may be more descriptive. Yes, it is more wordy and it adds noise to the interface name. In particular, passive verbs can be used.

E.g. 1 does Shootable mean that the object is able to shoot (a gun might implement this), or does it means that it can be shot at (a target board might implement this). With the 'Can-' prefix, the former would be "CanShoot" and the latter would be "CanBeShotAt" or "CanShootAt".

E.g. 2 A document 'CanBePrinted' and a printer 'CanPrint'

Or, should we stick with '-Able' and let the documentation provide the context?

Any opinions.

答: In my opinion the "-able" variant is much more readable then your proposed "CanDoSomething" which imposes much more camel humps.</p>


答: I think you may wish to distinguish between capability and permission. While Serializable and CanSerialize imply that something is capable of being serialized, there are also permission issues (or perhaps lack of disk space) and you may need to consider MaySerialize. Leaving things at ~able removes the need to distinguish between can and may.

Title: Interface naming: prefix 'Can-' vs suffix '-Able'

Body:
It's common to use '-able' as a suffix for interfaces e.g.

Serializable
Printable
Enumerable
Drinkable
Shootable
Rotatable

I was thinking that 'Can-' might better because it may be more descriptive. Yes, it is more wordy and it adds noise to the interface name. In particular, passive verbs can be used.

E.g. 1 does Shootable mean that the object is able to shoot (a gun might implement this), or does it means that it can be shot at (a target board might implement this). With the 'Can-' prefix, the former would be "CanShoot" and the latter would be "CanBeShotAt" or "CanShootAt".

E.g. 2 A document 'CanBePrinted' and a printer 'CanPrint'

Or, should we stick with '-Able' and let the documentation provide the context?

Any opinions.


答:
Perhaps you want Is-able?

Some examples from .Net:

```<code>NetworkStream.Readable
NetworkStream.Writable
Stream.CanRead
Stream.CanWrite
Type.IsSerializable
</code>```

There doesn't appear to be a uniform standard.  Go with what reads well.

```<code>if (document.IsPrintable && printer.CanPrint) { printer.Print(document) }
</code>```

EDIT: As pointed out, the question was about Interfaces, not Properties.

In that case, I can't find any interfaces named Can-.  Interfaces tend to always use -able.  I'd agree with this terminology.  A method may request as a parameter a ISerializable object or IPrintable document.  Asking for a ICanBeSerialized object or a ICanBePrinted document is very awkward to read.

On the other side, the Printer, I'd suggest simply calling the interface IPrinter.  Your method will be asking for a IPrinter device.

Read the method signature below out loud.  (Personally, I consider the "I" prefix to be silent.)  Does it read well?  Does it sound right?

```<code>void PrintDocument(IPrinter device, IPrintable document)
{
    device.Print(document)
}
</code>```

Body:
Perhaps you want Is-able?

Some examples from .Net:

NetworkStream.Readable
NetworkStream.Writable
Stream.CanRead
Stream.CanWrite
Type.IsSerializable

There doesn't appear to be a uniform standard.  Go with what reads well.

if (document.IsPrintable && printer.CanPrint) { printer.Print(document) }

EDIT: As pointed out, the question was about Interfaces, not Properties.

In that case, I can't find any interfaces named Can-.  Interfaces tend to always use -able.  I'd agree with this terminology.  A method may request as a parameter a ISerializable object or IPrintable document.  Asking for a ICanBeSerialized object or a ICanBePrinted document is very awkward to read.

On the other side, the Printer, I'd suggest simply calling the interface IPrinter.  Your method will be asking for a IPrinter device.

Read the method signature below out loud.  (Personally, I consider the "I" prefix to be silent.)  Does it read well?  Does it sound right?

void PrintDocument(IPrinter device, IPrintable document)
{
    device.Print(document)
}


答:
Personally I would stick with the -able version. Here is my reason: Most (all?) graphical editors suggest identifiers based on what you have typed. Although some of them are 'smart' enough to also search within identifiers some still just offer search beginnings of identifiers.

To speed up typing you'd like to shorten the list of suggested identifiers with as few keystrokes as possible. The more identifiers have the same beginning, e.g. 'ICan-' the more characters you will have to type.

If you think this is not a problem in your case then that's great and I would recommend using other criteria to choose a naming convention. In some case, e.g. in our team, we prefer identifiers that distinguish after as few keystrokes as possible.

Apart from that I would recommend to use the naming convention that makes your code most understandable for those working on the project. Have a conversation within your team. There is no right or wrong as such. Just conventions that work and conventions that work less.

Don't forget that good refactoring tools allow you to rename things as often as you like. So it's easy to experiment with different approaches.


答:
When subclassing/implementing interfaces I think the rule of thumb is that you should be able to say "B is a A" (where B implements A). It doesn't sound right to say:

A Document is a CanBePrinted

But it sounds right (or at least better) to say:

A Document is a Printable


问:
Handling tough or unexpected technical questions in meetings
Depending on the project I'm working on, I may be required to attend more meetings with both internal stakeholders or technical management in client companies.

During the course of these meetings, there will inevitably be a few questions crop up that either:

You do not have an answer to.

You have not thought about for one reason or another.

You deem to be irrelevant or completely out of scope of the
current meeting.

In each case, how do you answer these questions? Any tips or tricks on remaining authoritative while remaining honest?

答:
The above suggestions are definitely great ones, and work well in most contexts.  Like the other responders indicated this is bound to happen - especially if you are presenting ideas to smart people and looking for their critique or feedback (for example, trying to raise funding for a start-up).

However you respond you want to achieve a few things:

Retain creditability and authority for your topic/clients (this also means not fabricating or making up things you truly don't know aren't sure about)

Acknowledge their response (so they feel heard and understood)

Keep the presentation/meeting on track

While the suggestions are definitely helpful, a great design pattern to this questions works as follows:

Restate the question and make sure you understand what they are asking and why (since sometimes this isn't obvious, and you want to make sure you address their root cause).  For example "Why are you using [insert technology here] instead of [insert a technology here that you may not have looked at]?"  with this question it would be good to follow up with a question (or series of questions) on why they asked it and if they had experience with different technologies, or relationships with the vendors, etc.  Make sure you understand what they are getting at and why (since they may be really experienced with something, or just heard of it off the cuff, etc - and you need to treat each situation differently).

Acknowledge the "asker" and question non-confrontational way - i.e. "That is a great question...." or "That is an interesting perspective....."

Identify how to you plan to follow up "...let me get back to you on that in email" (a) or "...that is definitely a topic for further consideration, but let's table it for now and perhaps you and I can discuss about it offline." (b) or "...that is a good point, but since of the goal of the meeting is {insert here}, let's move on right now but we can come back to this if time allows."

Generally understanding "why" they are asking something, will help you select the best follow up, and make sure that they feel heard and understood.


问:
What should every programmer know about programming?
Please, stay on technical issues, avoid behavior, cultural, career or political issues.

答:
Some of these have been posted already, but here is my list:

Build to the requirements, don't add things you don't need, especially if you "think" you will. If you need it later, add it then.

How to use Google search. Don't bother your co-worker, until you've looked.

Don't be clever.

It's not done till it's meets ALL the requirements, tested, documented, and checked into SVN.

Proper coding standards, eg: naming conventions


答:
Profiling whenever in doubt is definitely a good way to go. Since I can't profile your code (nor would I probably want to), I'll share my two cents of theory:

Both two-property object and your KeyValuePair essentially store exactly the same data and in both instances you are storing your data in a List collection which means that in order to find individual entries, you have to perform a full collection scan, O(n) operation.

Theoretically, KeyValuePair<> might be tad faster (not sure if even profiler would notice it) because there's one less level of indirection that has to take place.

ListEntry(KeyValuePair) --> string; ListEntry(KeyValuePair)

ListEntry(obj ref) --> Object --> string; ListEntry(obj ref) --> Object(int)

However, one change that you could do to improve performance if your collection gets rather large, is use a different type instead of a List.  With List you are stuck with linear searches and can't really get away from that (unless you'll spend extra effort manually sorting it, but why would you).

Since you have a notion that each object has a key, use Dictionary<> or SortedDictionary<> which would be keyed of your key.

In this case, just to give you a comparison, if your List has 1000 entries and you need to find one, worst case will require you to do 1000 compares. If you use a keyed collection, in worst case, you will only perform 10 compares.  When performing a sum or looking for multiple items with same key, they will all be located together in the collection, so it also becomes much easier (computationally) to do that operation, rather than searching for them everywhere.

Title: Is querying KeyValue Pairs efficient compared to two-property objects?

Body:
I'm working on a webservice and I'm returning JSON. However, I'm returning a List<KeyValuePair<string, int>>, since that's all I'm really ever going to be dealing with (property => value)

Now sometimes I myself will be calling these functions to aggregate the results, so I end up with something like

```<code>List<KeyValuePair<string, int>> myList = resultList.where(o => o.Key =="StringKEY");
</code>```

and sometimes

```<code>List<KeyValuePair<string, int>> myList = resultList.sum(o => o.Key =="StringKEY");
</code>```

My question is, would it be more efficient to do the following (custom class vs dictionary):

```<code>List<MyObject> myObj = resultObjList.where(o => o.Property1 == "stringProperty")
</code>```

and so on.

Is there any benefit to using custom objects? I will not ever need to be adding properties, and in this case I can say there will never be a need for additional properties.


问:
First languages with generic programming support
Which was the first language with generic programming support, and what was the first major staticly typed language (widely used) with generics support.

Generics implement the concept of parameterized types to allow for multiple types. The term generic means "pertaining to or appropriate to large groups of classes."

I have seen the following mentions of "first":

First-order parametric polymorphism is now a standard element of statically typed programming languages. Starting with System F [20,42] and functional programming lan- guages, the constructs have found their way into mainstream languages such as Java and C#. In these languages, first-order parametric polymorphism is usually called generics.

From "Generics of a Higher Kind", Adriaan Moors, Frank Piessens, and Martin Odersky

Generic programming is a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters. This approach, pioneered by Ada in 1983

From Wikipedia Generic Programming

答: Before generics there were templates, and before that macro substitution.</p>


答:
I haven't seen this mentioned, but the worst thing you can do is to try to BS them. It's always fair to respond:

a) you do not know the answer to

   Response: "Don't know, but I will find out"

b) you have not thought about for one reason or another

   Response: "The subject never came up. I'll do some research and get back to you"

c) you deem to be irrelevant or completely out of scope of the current meeting

   Response: "We should discuss this in another meeting"

Title: Handling tough or unexpected technical questions in meetings

Body:
Depending on the project I'm working on, I may be required to attend more meetings with both internal stakeholders or technical management in client companies.

During the course of these meetings, there will inevitably be a few questions crop up that either:

You do not have an answer to.

You have not thought about for one reason or another.

You deem to be irrelevant or completely out of scope of the
current meeting.

In each case, how do you answer these questions? Any tips or tricks on remaining authoritative while remaining honest?


答:
Where all this fanboyism is comming from? "Crappy servers" because not "thread pool", "event loop", "scale"... at least I haven't seen any rant about external plugins yet, so only 8/10 trolling :)

Well i guess that alpha-websocket browsers and alpha-version event loop servers are not "crappy" :)

Just slogans not a real solution. Have all those "fashionable" devs even used some of those new technologies with cool names on anything beside localhost? :)

As for my solution: use nginx, lighty, etc. (eg. in reverse proxy mode or even normal with scripting as fcgi), assign each "task" an unique id, then check the server every 5 seconds (ajax) for a presence of static file that you'll create from your script in some predefined dir. When the file will be present you can run a script that'll get you results via ajax. Simple, and won't overload the server because you'll be checking for static file, doesn't do fallback in 50% of the browsers on market, translation for fanboys is "always works as it should".

Beside event loop webserver won't work if you won't have event loop scripting backend.

Then in 5 years when websockets status will change from fashionable to production ready you can use this without compromising usability. And of course new kids will rant because you won't use those "quantum", "cloudum", etc. servers and specs that doesn't work :)

I mean really guys? Are you serious? WebSockets is available in IE10 Preview and you want to write serious app using this TODAY when around 50% of your userbase will be IE? I know it's cool play toy and it'll work good in your Chrome, but you're not going to be the only user for something you write at work.


问:
Should one bind data with Eval on aspx or override ItemDataBound in code-behind?
For data bound controls (Repeater, ListView, GridView, etc.), what's the preferred way of binding data?

I've seen it where people use Eval() directly on the aspx/ascx inside the data bound control to pull the data field, but to me, it just seems so...inelegant. It seems particularly inelegant when the data needs to be manipulated so you wind up with shim methods like <%# FormatMyData(DataBinder.Eval(Container.DataItem, "DataField")) %> inside your control.

Personally, I prefer to put in Literal controls (or other appropriate controls) and attach to the OnItemDataBound event for the control and populate all the data to their appropriate fields in the code-behind.

Are there any advantages of doing one over the other? I prefer the latter, because to me it makes sense to compartmentalize the data binding logic and the presentation layer. But maybe that's just me.

答:
I suggest you to go through this SO Question : Eval and ItemDataBound or RowDataBound event to display data, which one is better?

Base on the performance comparsion on the title : Real World ASP.NET Best Practices Using inline format expression mechanism (i.e. tag) is better than event hanlder mechanism (via ItemDataBound).

As i explored about this that the DataBinder.Eval syntax uses reflection and should be avoided if you can determine the object type at design time. Ref: Avoiding DataBinder.Eval in ASP.NET

Check this for Asp.net performance and  scalibilty :


问:
How to structure unit tests for a GUI app using C# and NUnit
I've been asked to do a small side-project to supply a simple application to one of our customers. Normally I would be working on back-end code where I have all of my testing needs figured out, and I've not yet had the dubious pleasure of writing tests for the GUI, so it's a little unclear to me how I should set up the testing code and tools for an EXE.

My first instinct was to simply include the tests with the application code, however that would require supplying a number of test-specific dependencies, which I have been instructed to specifically not ship to the customer. I am also unable to squeeze out any cash for a purpose built test tool, so I need to use the tools I have at hand (StoryQ, RhinoMocks, and NUnit), which really should be more than enough to test the behavior of a simple GUI app. So as far as I can see, this leaves me with trying to strike a good balance between keeping the design really simple, or purposefully over-engineering for the sake of the tests. It seems I'm either building the app with the business logic in a separate library and testing against the library as I usually would, or finding some other mechanism to allow me to the executable without breaking out additional modules that the application design doesn't really need.

Edit:

Please note that this question is about how to structure the relationship between NUnit and my executable - as opposed to a DLL - and not about how to separate presentation and business logic.

/Edit

So my question is:

Is there a specific/recommended method for configuring a simple GUI application with unit tests to allow me to adequately check state and behavior, using the tools I have at hand, and without resorting to over-engineering?

Have I missed something fundamental about the way NUnit should be invoked/configured when testing an EXE (as opposed to a DLL)?

Can you provide or point me in the direction of examples of how achieve all of this?

I realize that there may be more than one way to do this so I'm looking for specific implementation guidelines based on your experience.

答:
Just because project is small (initially) doesn't mean proper architecture is over-engineering. The fact that you want to write tests tells that your project isn't a completely trivial one-off hack.

You didn't mention which GUI-Framework you are using. WPF MVVM (Model-View-ViewModel) is good and allows you to write tests for all the logic quite easily. With WinForms I've heard good things about MVP (Model-View-Presenter)


答:
Clearly the prefix and suffix are almost obvious choices for different types of actions or rather, different directions of an action.

Current usage and preferences may be inconsistent due to many reasons, though.

Action is performed by the object:

CanShoot --> It shoots (at) something

CanFly --> It flies

CanChange --> It changes

Action is performed on the object:

Readable --> You can read it

Writable --> You can write (to) it

Printable --> You can print it

While it may not be a rule or even necessarily logical, it helps to adopt the convention and maintain consistency of use in variable naming.


问:
How can I debug exceptions that are not easily reproducible and only occur in a production environment?
I am working on an issue where the exception only occurs in our production environment. I don't have access to these environments, nor do I know what this exception means. Looking at the error description, I'm unable to understand the cause.

```<code>javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
</code>```

Would someone please advise me on how to approach this kind of problem?

答:
In general, better debug logging.  Figure out what you want to know, add it to the code, and have that in the logs so that you can work it out.  Capturing more details of the environment at the time also help - what request, when, etc.

In specific, I would look for a common pattern in clients hitting this - and if you found one optimise - but then go and capture the TCP layer traffic.

Looking at the SSL messages exchanged should give you some idea what is going wrong in the protocol, or at least what the common properties of the request are.  Once you have that it should be closer to being debugged.

As a guide, I would guess this comes from one of three things:

Something that isn't SSL talked to the SSL port.  (port scans are common, but HTTP to the HTTPS port also happens.)

The client doesn't share an acceptable set of ciphers with the server.

The client offers a certificate, and the server has a hissy-fit.  (Uncommon, but possible.)


答:
These 2 tie for my top one:

Turn my work into a nasty hydra.  This where for anything I do finish, 3 new tasks appear as something to do ASAP.  Repeat this enough and suddenly I have a 101 things on my to-do list and I know that some of those will never get done.  The lack of getting something done is rather annoying here.  I call it a hydra as this was the mythical beast that any head it lost was replaced by two new ones.

Constantly reorganizing my work as I'm trying to do it.  So something that would take 3 days gets a day in and then it is "Drop everything and get THIS done NOW!" though I have seen worse.  Imagine only getting 20 minutes to get into something before getting a, "Hold everything, this will make us millions!" or a "Boo-ya, this will make billions!" and so nothing is getting done as even basic work like what is to be done hasn't been flushed out really.

Title: Managers X Motivation

Body:
As a programmer what do you think that is the thing that your manager does that mostly decreases your motivation?

My manager insists in blocking web content (this week was msdn content and Microsoft domain sites) This is so stupid, make me think I am not a reliable professional or that I am stealing his internet. And not, it is not a small business. It is a huge enterprise where such dinossaurs should not exist anymore.


问:
How long does it take for one to become really comfortable in a programming language and coding starts being fun?
I am just starting out in programming learning Aspect and I'm nearing the end of the introduction. I've learned about algorithms and functions and types of code and Python and briefly the basic ideas of programming. And I have to say it totally fits the description of a language it is like learning how to speak again.

So what I would like to know is after this trivial and trying stages of learning just how to get into this gate of overstanding, does programming become easier and more fun?

Also I would like to get an idea of how long or far into the learning process it is, before you can speak this language and do things like write an application or design on the web and all these electrifying things are graspable and doable?

答:
I find that in general I have to write about 1000 lines of code before a language really clicks. Of course if there is a major mental shift (Like say Haskell) it will be a bit more, while going from Javascript to CoffeeScript took a bit less.

Of course it also gets easier if you know a bunch of languages already and have been doing this for a while.


答:
I'll talk from personal experience. I find that a programming language (and programming in it) become fun when you can control it at will, where you know exactly how to make it operate in the manner you want.

During my final year project at university for example: I started writing the code and it would frustrate me due to my lack of understanding surrounding the language and the application of the language to the problem, a few weeks down the line and I could not stop coding in it. To relate to your question : Stick out the trivial stages because the fun you will have later on is worth it, and you will find you use some of this code in your 'fun' work too.

In terms of writing something useful my advice is to get stuck in. Find something that would be useful for you to have on your system and write an application that does it, a long the way you will learn alot of the stuff you would otherwise learn during the 'testing and trying' days.

Most of all have fun!

Title: How long does it take for one to become really comfortable in a programming language and coding starts being fun?

Body:
I am just starting out in programming learning Aspect and I'm nearing the end of the introduction. I've learned about algorithms and functions and types of code and Python and briefly the basic ideas of programming. And I have to say it totally fits the description of a language it is like learning how to speak again.

So what I would like to know is after this trivial and trying stages of learning just how to get into this gate of overstanding, does programming become easier and more fun?

Also I would like to get an idea of how long or far into the learning process it is, before you can speak this language and do things like write an application or design on the web and all these electrifying things are graspable and doable?


问:
Search algorithm with co-ordinate (x,y) hints?
I am about to start writing a UI view where many small text items are laid-out over the view and when the user hovers over a text item a dynamically-generated image is displayed (like a tooltip), relevant to the context of that text item.  When the user clicks the text item, another view will change with a larger version of that image.

I will obviously need to hold the items in a collection along with the rect hit-area that surrounds the text, and I am wondering if anyone can suggest an storage format and search algorithm I can use to find the text item as quickly as possible using the position of the mouse as a hint to localise the search, rather than do hit-tests for every item in the collection?

答:
What you are looking for is called a spatial index and the problem you are trying to solve is collision detection.

More specifically I would use a quadtree data structure, which subdivides your space into four subspaces each time you descend one level in the tree. This is in 2D, if you are trying to solve the problem in 3D the appropriate structure would be an octree.

I would probably deviate from the traditional quadtree and subdivide your area to the pixel level and hash the leave nodes, so you can get the corresponding leave node for (x,y) more quickly. The algorithm would be roughly:

On initialization build the tree and the hash.

When inserting a new item into your collection then you calculate the hit area and you store it in the node that represents the smallest quadrant possible that still holds your entire hit box.

If you receive a click on (x,y), you look up the leaf for x,y using the hash. Once you have the leaf all you need to do is work up your way to the root and compare the hitbox of every item that you encounter on your way up with your (x,y)


答:
According to this good article "ten years"!

Well ... may be not so long, but your question is in fact two distinct questions: one about "language mastering", and the other about "fun".

They are not necessarily related. What is required to have fun is having an understanding and control on what is around it. That's not necessarily the whole space of the computing science.

Of course, the more humility you'll have, the before your fun will start.
The most prominent and profitable you want to be, the harder your job will be (and will not necessarily be fun).


问:
How important is it to finish projects?
I'm a student (yet to go to uni) and I've been programming for about 5 years now. Over that time, I've flitted around from language to language, from API to API, and project to project. I've tried setting myself on one thing, but I lose interest. My entire PC is full of half finished projects (and at least four times as many have been formatted off my disk).

I start to wonder if my lower motivation towards programming for the fun of it (it is one activity I really enjoy) is because I never get a finished project at the end. I can't tell if I just have too open ended goals, or just a low attention span. I tried doing some smaller projects just to finish them, but they do not interest me at all.

Could this be a cause for my drop in motivation? Also, when I apply to go to uni (and in the future hopefully, a software job) is it likely to be an issue?

In summary:

How important is it to finish side/hobby projects, be it for career, motivation, or education?

答:
I have similar experience and that last 5-10% of even a small pet project can be a killer.

My advice if you want to finish? Tell friends, coworkers, family or whoever might be interested about this cool new thing you're working on. Involve them, ask them questions. Hopefully you will gain a few followers that will ask about your progress. The pressure of knowing that will motivate you to keep going through the mundane but necessary steps to ship your project.

Title: How important is it to finish projects?


答:
Never improvise or make up facts you don't know or aren't adequately prepared to give. Questions you can't answer, ask to come back after you've checked it out.

If something is out of scope for the current discussion, say so and suggest you can discuss this with that person after the meeting

Always invite people to send questions before the meeting, giving you opportunity to prepare answers. If you are organizing the meeting, make sure you have an agenda that you send out beforehand (can be just a few lines, as long as it outlines what the meeting is about).

If you are not organizing the meeting, ask the organizer to provide you with an agenda unless one is posted.

In my experience, one of the most common causes of out-of-scope discussions or questions you are not prepared for are agenda-less meetings. Always demand a meeting have a clear agenda. If the meeting is supposed to render a decision on something, that should be clearly indicated in the agenda, and it should be reflected (and acknowledged) in minutes or notes sent out after the meeting.

If people insist on calling for meetings without an agenda, bring this up with them and suggest that it would be much more efficient with one. If that doesn't work, bring it up with your boss with the motivation that your time is being inefficiently wasted. If you feel you can get away with it (without getting a lot of bad will), feel free to start declining agenda-less meetings outright. I've had to resort to this a few times when things got too out of hand.


答:
every programmer should have a firm grounding in software engineering, and also system analysis/design and information systems concepts. this way if they are called upon to contribute substantially to systems analysis/design and/or information architecture, they will be in a position of knowledge + opionion..whereas normally it seems to be just personal opinion that usually simply stems from personal preferences instead of best problem solution. software engineering is a bit harder to measure, but the pre-requisite knowledge is available out there, and at suitable university degree courses where they teach more than just how to cobble a bit of code together.
anyway this is not meant to be negative because the main spirit is but improvement, but then i've worked with some people who have no IT knowledge whatsoever or there's the single minded "script kiddies" that code and re-code (and only in their language of choice) and only see every problem as a repeat of previously applied solutions (by that coder.)
so i would much prefer if programmers concentrated more on the larger picture in terms of software engineering (SSADM) and looked at problems as opportunities to do better for the client.</p>

Title: What should every programmer know about programming?

Body: Please, stay on technical issues, avoid behavior, cultural, career or political issues.

OwnerDisplayName: chris


问:
Should an application be designed without prototyping first?
I've just begun using a popular, well-documented graphics engine, and was given a month to create some small programs and get familiar with it.

The library is huge, and there are sections I haven't explored.

Due to a time-crunch, my tech-lead has asked me to start designing my software (sequence and class diagrams) even for the parts I haven't explored, just by looking at the documentation and figuring out the capabilities of those classes.

It's my understanding that designing software requires good knowledge of how something works. Does it make sense to create a design with only a vague understanding of how a class works, just by looking at the class's documentation? Shouldn't I be prototyping it with a small program, tweaking it here and there and understand how it behaves and THEN do the design for it?

答: Your own sequence and class diagrams probably do not depend that much on how the graphics engine behaves. During implementation, you will probably run into little quirks like 'I must call initFoo() before setupBar()' but those details most likely do not affect the design of your classes. Your tech-lead needs your design now, probably because other people depend on it, so I propose you create it.</p>


答:
Your underlying assumption is that the application of knowledge is fun, but aquiring such knowledge is not. But I suspect whether this is true or not depends on the individual personality and can't be answered in a general way.

Please let me rephrase your question then. Do you know the so-called flow theory regarding intrinsic motivation? In a nutshell, it describes the psychological effect how you get a positive motivation about doing things as long as the given task is not too hard and not too simple in relation to your abilities. In light of this theory your question can be rephrased to: "When will I know enough about a language to feel programming in it is not too hard?"

My answer then is that this is up to you or the tasks that lie ahead. By adjusting the difficulty of the programming tasks you can start very early on to feel very comfortable with a programming language. But pick a complex job too soon and you won't be happy. If the question was about body building the answer would be: Pick the right weights and don't start with the heavy ones, and the fun can start.


答:
Shouldn't I be prototyping it with a small program, tweaking it here and there and understand how it behaves and THEN do the designing for it?

That depends on what you want to do

if you want Big Design Up Front, then yes - you do need a detailed understanding of how things work

if you want some sort of agile iterative and incremental development, then no you do not need a detailed understanding of how the framework works in details. In this case, you should create your design to be flexible and expect the changes to it in the future

The answer is in how your company do things. I personally would choose the second (agile) approach.

By the way, your design shouldn't depend so much on a library's implementation.

Title: Should an application be designed without prototyping first?

Body:
I've just begun using a popular, well-documented graphics engine, and was given a month to create some small programs and get familiar with it.

The library is huge, and there are sections I haven't explored.

Due to a time-crunch, my tech-lead has asked me to start designing my software (sequence and class diagrams) even for the parts I haven't explored, just by looking at the documentation and figuring out the capabilities of those classes.

It's my understanding that designing software requires good knowledge of how something works. Does it make sense to create a design with only a vague understanding of how a class works, just by looking at the class's documentation? Shouldn't I be prototyping it with a small program, tweaking it here and there and understand how it behaves and THEN do the design for it?


答:
The 'fun' part is highly subjective - some people hate the first crippled steps in a new programming language, others, like me, enjoy every part of the way (especially when the language in question reveals new insights through the different mindset it supports).

The productivity part is less subjective, but can vary wildly. A few things:

the more languages you know, the easier it is to pick up a new one

a language that matches your mindset will come easier

a language that is similar to one you already know will be easier to learn

Also, every language and ecosystem has its own balancing of contradictory concerns (developer performance, maintainability, runtime performance, platform support, learning curve). Languages that focus on a shallow learning curve and high developer performance (e.g. python) obviously yield productive results faster than, say, C++, where runtime performance is God.


答: I find it gets fun when you have sorted out your tools and gotten used to the regular workflows for basic activities like testing/deployment etc. It is important to get the mundane stuff out of the way (or reduce their annoyance level down to something more palatable) before you can actually enjoy the fun stuff.</p>


答:
Grammatically speaking, "canFoobar" is a predicate, while "Foobarable" is an adjective or a noun (usually a noun in the context of an API).

Also note the subtle difference: -able implies a passive role to the noun it is applied to, that is, if Something is Foobarable, then it can be foobarred by something else; can- implies an active role, that is, if Something canFoobar, then it can foobar something else. Or, from a different angle: if A can foobar B, then A.canFoobar() and B is Foobarable.

In terms of OOP expressivity, I'd associate predicates with methods or properties, while nouns are classes or interfaces. So:

```<code>instance.canFoobar();

class Something implements Foobarable { ... }
</code>```

Body:
Grammatically speaking, "canFoobar" is a predicate, while "Foobarable" is an adjective or a noun (usually a noun in the context of an API).

Also note the subtle difference: -able implies a passive role to the noun it is applied to, that is, if Something is Foobarable, then it can be foobarred by something else; can- implies an active role, that is, if Something canFoobar, then it can foobar something else. Or, from a different angle: if A can foobar B, then A.canFoobar() and B is Foobarable.

In terms of OOP expressivity, I'd associate predicates with methods or properties, while nouns are classes or interfaces. So:

instance.canFoobar();

class Something implements Foobarable { ... }


答: In Scala, *Able is used for interfaces, but Can* is used for the type class pattern. Essentially, to be able to call certain methods, an implicit value of a certain type must exist in scope. The name of this type is sometimes prefixed with Can.


答:
There is a risk: just because the engine is popular and well documented, that might not reflect reality. I did use one game engine recently that used a wiki to documentation how the engine worked. What you found was a mixture of old pages that didn't reflect the most recent version, current pages, and ones that were talking about not yet implemented parts.

If I had been asked to design the application, based on the documentation alone, we would have been promising things that would not be available for years.


答:
I would recommend to use a logging strategy with a configurable maximum log level. A utility like log4j ( http://logging.apache.org/log4j/, http://en.wikipedia.org/wiki/Log4j) might do the job.

Configurable log level (or verbosity) is important to be able to find the reason of an error, possibly without having to re-deploy your software.

If such strategy is not enough to find the error, try to find how to produce/read the logs produced by the applications with which yours is communicating.

You might also implement some mechanism to automatically get more information about errors by e-mail.

More generally, you can read some articles about instrumentation, which is a larger topic that includes logging and tracing.

Title: How can I debug exceptions that are not easily reproducible and only occur in a production environment?

Body:
I am working on an issue where the exception only occurs in our production environment. I don't have access to these environments, nor do I know what this exception means. Looking at the error description, I'm unable to understand the cause.

```<code>javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
</code>```

Would someone please advise me on how to approach this kind of problem?


问:
Platform design Issues
Suppose I design a platform over a platform (say Java or Win32 or .NET), which consists of various layers like Database, User Interface, Cloud etc.

Now every team would be working to make their product, say database best and less focused on their relationship with other teams, hence resulting in various issues when doing an integration of it.

Now, these are my questions in order to achieve a stable and bug-free platform:

How could one ensure that while integrating all the layers, there is less overhead involved and also is there any other way to automate this process ?

Also, if one particular team is using the API calls provided by other team and if the other team is still not ready with the API calls, there comes a DEADLOCK . How to step over such situations ?

Say, I want to monitor and get feedback from various teams regarding their progress. Is there any automation available for such activities ?

答:
Your team sounds like it suffers from poor management and other problems.  In a typical Agile project you will see that sub-teams of technical specialists (Team A only does Database, Team B only does Web Services, Team C only does GUI, etc...) is frowned upon.

Ideally a team should exist to write software that meets user needs (User Stories).  No other subdivisions of that team are acceptable.  Every resource on that team should be able to be assigned a user story, and complete it from Database to GUI across all layers.  Sure some developers have strengths and weaknesses, but the team should be able to help each other out where needed.

Your team is broken up and there is a lack of coordination between teams now.  I know that restructuring the team may be difficult or impossible, so here are some other suggestions:

Answer 1: A good way to work out integration issues is to write a suite of integration tests that verify the proper communications between each layer.  If the integration tests are done correctly, they will notify if there is a failure at one of the layers.  Perhaps the web services were never deployed?  Perhaps the Test environment didn't get the latest database changes deployed? Etc...

Answer 2: You can't force the other team to complete before you do.  Integration tests will tell you ahead of time if the other team has completed or not.  Before this point however you should write independent Unit Tests for the code at your layer, so that you can verify your code and functionality before the layer you depend on has completed.

Answer 3: You should have issue tracking, or other project management tools that are publicly available to every member of the team.  As a developer, I should be able to look in the project management tool to see which tasks and issues are Open, In Progress, or Completed.

Title: Platform design Issues