问:
How do i put my head around ISAPI Filters
I am a newbie. I have decent command over C++ but i lack domain knowledge when it comes to servers and stuff. My current assignment is to write ISAPI filters for IIS Web Server. I have been googling for a couple of days and have found out that its quite a challenging task. I found some examples here. I need to understand and implement some filters which would log requests to the server and take a count of requests on each resource. I do not seem to understand the code examples. Can you guys please suggest a plan or list of to do's for me. I ask this because i know there are a lot of prerequisites to this project. Where should I start ? How should I proceed ? I am expecting you guys to look at the code examples here and tell me what stuff I should read up to grasp the examples. Then i could imagine writing my own filters. </p>

答:
There's a great tutorial on the MSDN magazine website

http://msdn.microsoft.com/en-us/magazine/cc301704.aspx

You should be able to follow through the above article and then read through the further reading down the bottom and it should help you to userstand what ISAPI filters are and how they work.

Edit: looks like the further reading is defunct (thanks microsoft).  So I've done a little more research and found 2 more article with code examles.  One of which is actually logging usernames from request cookies (code project).

Excerpt.

If you've reached this point, chances are you want the general
solution, one that maps any arbitrary URL to your implementation ASP
or ASPX files without the limitation of the file extension I've
discussed. The only way I know to do this is outside the .NET
Framework, using plain old ISAPI filters. You see, ISAPI filters are
HTTP handlers native to IIS and they are given a chance to run very
early, before any framework code in ASP.NET.
Conceptually, ISAPI filters are very similar to the ASP.NET
HTTPModules I discussed earlier. A major difference is that ISAPI
filters must be written in C or C++. There is plenty of literature on
ISAPI filters so I will only touch on them briefly here (see ISAPI,
and Tips and Tricks for ISAPI Programming for more information).
In practice, an ISAPI filter is a Windows DLL that provides the
following two entry points:

```<code>DWORD WINAPI HttpFilterProc(
  PHTTP_FILTER_CONTEXT pfc,
  DWORD notificationType,   LPVOID pvNotification
);

BOOL WINAPI GetFilterVersion(
   PHTTP_FILTER_VERSION pVer
);
</code>```

The IIS runtime calls the GetFilterVersion method when the filter is
initialized. The filter should use this opportunity to notify IIS
about the events it cares about. Then, when HTTP requests arrive, IIS
calls the HttpFilterProc once for every event for which the filter
asked to be notified. If you want to make things a little bit easier
you can use the MFC class CHttpFilter, which conveniently wraps the
raw C API and routes the events to one or more virtual methods that
you implement. The rest of the discussion will assume that you use the
MFC-provided wrapper (see Writing Interactive Web Apps is a Piece of
Cake with the New ISAPI Classes in MFC 4.1).
Figure 6 shows the C++ code that rewrites the URL and stores
part of the virtual path in a pseudoheader. The event that you need to
catch in order to rewrite the URL is OnPreprocHeaders. The trick here
is that you can use the special header URL to read the original URL.
Then, after rewriting the URL, you can use the SetHeader call to set
the special header URL, forcing IIS to call your file. The code shown
in Figure 6 changes a URL like /bestpayroll/msdnmag/ report2 to
/bestpayroll/report2.aspx. Notice how the company name has been
removed and the .aspx suffix has been added. Most of the ugly code
deals with extracting the company name and then piecing together the
rest of the URL for the request.
The last remaining task is to communicate either the original
URL or the company name to the ASP.NET form. There is no clean way to
communicate from an ISAPI filter to either ASP or ASP.NET. What I can
do is add a new header. A header called companyname can be read from
ASP.NET using the Request.ServerVariables collections, as shown here:

```<code><form id="test" method="post" runat="server">
     The company is
     <b><%=Request.ServerVariables["HTTP_COMPANYNAME"]%></b> </form>
</code>```

Here I hardcoded the logic that rewrites URLs into the C++ code. In
more realistic scenarios the logic should reside in a configuration
file that is parsed by the filter during initialization.

Perhaps better code examples of ISAPI Filters with a clearer explanation

http://blogs.msdn.com/b/rakkimk/archive/2007/03/01/writing-a-simple-isapi-filter.aspx

http://www.codeproject.com/KB/trace/isapilogger.aspx

Body:
There's a great tutorial on the MSDN magazine website

http://msdn.microsoft.com/en-us/magazine/cc301704.aspx

You should be able to follow through the above article and then read through the further reading down the bottom and it should help you to userstand what ISAPI filters are and how they work.

Edit: looks like the further reading is defunct (thanks microsoft).  So I've done a little more research and found 2 more article with code examles.  One of which is actually logging usernames from request cookies (code project).

Excerpt.

If you've reached this point, chances are you want the general
solution, one that maps any arbitrary URL to your implementation ASP
or ASPX files without the limitation of the file extension I've
discussed. The only way I know to do this is outside the .NET
Framework, using plain old ISAPI filters. You see, ISAPI filters are
HTTP handlers native to IIS and they are given a chance to run very
early, before any framework code in ASP.NET.
Conceptually, ISAPI filters are very similar to the ASP.NET
HTTPModules I discussed earlier. A major difference is that ISAPI
filters must be written in C or C++. There is plenty of literature on
ISAPI filters so I will only touch on them briefly here (see ISAPI,
and Tips and Tricks for ISAPI Programming for more information).
In practice, an ISAPI filter is a Windows DLL that provides the
following two entry points:

DWORD WINAPI HttpFilterProc(
  PHTTP_FILTER_CONTEXT pfc,
  DWORD notificationType,   LPVOID pvNotification
);

BOOL WINAPI GetFilterVersion(
   PHTTP_FILTER_VERSION pVer
);

The IIS runtime calls the GetFilterVersion method when the filter is
initialized. The filter should use this opportunity to notify IIS
about the events it cares about. Then, when HTTP requests arrive, IIS
calls the HttpFilterProc once for every event for which the filter
asked to be notified. If you want to make things a little bit easier
you can use the MFC class CHttpFilter, which conveniently wraps the
raw C API and routes the events to one or more virtual methods that
you implement. The rest of the discussion will assume that you use the
MFC-provided wrapper (see Writing Interactive Web Apps is a Piece of
Cake with the New ISAPI Classes in MFC 4.1).
Figure 6 shows the C++ code that rewrites the URL and stores
part of the virtual path in a pseudoheader. The event that you need to
catch in order to rewrite the URL is OnPreprocHeaders. The trick here
is that you can use the special header URL to read the original URL.
Then, after rewriting the URL, you can use the SetHeader call to set
the special header URL, forcing IIS to call your file. The code shown
in Figure 6 changes a URL like /bestpayroll/msdnmag/ report2 to
/bestpayroll/report2.aspx. Notice how the company name has been
removed and the .aspx suffix has been added. Most of the ugly code
deals with extracting the company name and then piecing together the
rest of the URL for the request.
The last remaining task is to communicate either the original
URL or the company name to the ASP.NET form. There is no clean way to
communicate from an ISAPI filter to either ASP or ASP.NET. What I can
do is add a new header. A header called companyname can be read from
ASP.NET using the Request.ServerVariables collections, as shown here:

<form id="test" method="post" runat="server">
     The company is
     <b><%=Request.ServerVariables["HTTP_COMPANYNAME"]%></b> </form>

Here I hardcoded the logic that rewrites URLs into the C++ code. In
more realistic scenarios the logic should reside in a configuration
file that is parsed by the filter during initialization.

Perhaps better code examples of ISAPI Filters with a clearer explanation

http://blogs.msdn.com/b/rakkimk/archive/2007/03/01/writing-a-simple-isapi-filter.aspx

http://www.codeproject.com/KB/trace/isapilogger.aspx


答: All of the books on this subject are obsolete, and dirt cheap used on Amazon. One. Two. Shipping will be the main cost for you. </p>

ContentLicense: CC BY-SA 3.0

Title: How do i put my head around ISAPI Filters

Body: I am a newbie. I have decent command over C++ but i lack domain knowledge when it comes to servers and stuff. My current assignment is to write ISAPI filters for IIS Web Server. I have been googling for a couple of days and have found out that its quite a challenging task. I found some examples here. I need to understand and implement some filters which would log requests to the server and take a count of requests on each resource. I do not seem to understand the code examples. Can you guys please suggest a plan or list of to do's for me. I ask this because i know there are a lot of prerequisites to this project. Where should I start ? How should I proceed ? I am expecting you guys to look at the code examples here and tell me what stuff I should read up to grasp the examples. Then i could imagine writing my own filters. </p>


问:
Why is there still case sensitivity in some programming languages?
I don't see any use for case sensitivity in a programming language, apart from obfuscating code.

Why implement this in a programming language?

Update:

It looks like someone you know made a statement on this.

答:
I think for statically-typed lanaguages like C# and Java, it doesn't actually add any value. Because in most cases, you've got an IDE that'll auto-correct case mismatches for you anyway, so at the end of the day, if I type in "VAriable" by accident, my IDE will auto-correct that to "Variable" for me. Add to that the MyClass myClass; style conventions and you can see that case-sensitivity is not necessarily a bad thing.

For dynamically-typed languages, there might be more of an argument, since it's harder for an IDE to guess an autocorrection, but in the case of dynamically-typed languages, you've already got so much more to worry about (in terms of typos) that using a consistent casing convention isn't going to add that much more burden.

So yes, while there's no real reason languages could not be case-insensitive, there's also no real reason why they should be either.

That article from Scott Hanselman about "SignOn" vs "Signon" was about string comparisons, and nothing to do with programming languages. I agree that strings that users type in should always compared case-insensitively, but I think that's a different ballgame to identifiers in a programming language.

ContentLicense: CC BY-SA 2.5


问:
Is there any evidence that Intellisense reduces productivity?

Possible Duplicate:

  Should newbies use IDE autocomplete (Intellisense)?

I was having a conversation with another developer the other night about the pros and cons of Visual Studio. He was of the opinion that Intellisense reduces productivity. Of course I thought that was insane but I could be wrong. Is there any evidence to support the idea that Intellisense reduces productivity?

答:
How can it possibly reduce productivity? Imagine having to hunt through the documentation every time you're looking for a namespace, class, method or property.

Intellisense is one of the great advances in IDE editors.

OwnerDisplayName: craigmoliver

OwnerDisplayName: flesh


答: In my opinion, the only time it may reduce productivity is when you need to do something where intellisense is not available (e.g. when doing something dynamic).  You're so used to it being there that you sort of think something is wrong when it's not there.

Title: Is there any evidence that Intellisense reduces productivity?

Body:
Possible Duplicate:

  Should newbies use IDE autocomplete (Intellisense)?

I was having a conversation with another developer the other night about the pros and cons of Visual Studio. He was of the opinion that Intellisense reduces productivity. Of course I thought that was insane but I could be wrong. Is there any evidence to support the idea that Intellisense reduces productivity?

OwnerDisplayName: Giovanni Galbo


答:
Your friend was probably implying that intellisense allows developers to never memorize all of the properies and methods of every type of object, which in turn reduces the speed at which they write code.

But for anyone who has ever used a type, control, class, or object with which he or she was unfamiliar, intellisense is infinitely useful in reducing wasted time due to reading through the entire class.

So, basically, according to me, your friend is generally wrong.

OwnerDisplayName: Justin Satyr


答: It actually can reduce productivity - outside of visual studio, because you have to look up a lot in the documentation. Due to intellisense, you might never have learned the important methods and classes by heart.

OwnerDisplayName: Femaref


答:
It reduces productivity by making Microsoft think it's okay to design functions to take 10 or 12 parameters, so virtually nobody ever can or will even come close to learning how to use them without the assistance of (something like) Intellisense.

Edit: Okay, let's take a look at the CreateAnimatedSprite example. First, a function name with two verbs is a nearly-certain sign of poor separation of concerns -- i.e., you have a single function that's really doing two things. Our first step is to fix that so we get a CreateSprite (or, since it's apparently being loaded from a file, it should probably be LoadSprite), and an AnimateSprite. For the moment, let's even assume @Mason is wrong, and you really do need all those parameters -- but when we've separate concerns decently, we're apparently left with something like:

```<code>sprite LoadSprite(std::string filename, int imageHeight, int imageWidth);
void AnimageSprite(sprite s, int frameWidth, int frameHeight, int numColumns, bool isLooped);
</code>```

By my count, we now have the parameter count down to a maximum of 5 -- half the number I'd mentioned as being excessive.

I'd consider this well short of ideal though. First of all, I'd advise against using a bool as a function parameter in most cases. Just glancing at a call to the function, it's not immediately obvious what true or false would refer to. It would be better to have something like:

```<code>enum {LOOP, NOLOOP};
</code>```

When somebody's reading a call to the function, LOOP is much more meaningful than true. Depending on the situation, there are a couple of other possibilities to consider. One would be using object-orientation, so we'd get:

```<code>class Sprite {
public:
    enum looping { LOOP, NOLOOP };

    load(std::string filename, int imageWidth, int imageHeight);
    animate(int frameWidth, int frameHeight, int numColumns, looping doLoop);
};
</code>```

That gets us down to only four parameters for a function, still providing the data you thought was necessary.

In reality, we can probably do better still. First of all, the file from which we load our sprite can store the size of the image(s) it holds, so we may not need to supply that (it's primarily useful if we're selecting one sprite from a file that may hold several). Second, as @Mason pointed out, we probably don't need to supply a frameWidth/frameHeight or numColumns either. In addition, single-pass animation and looped animation are enough different that it's frequently more sensible to supply those as two separate functions. Finally, it might well make sense to just pass the file name from which we're going to read the sprite as a parameter to the ctor. Incorporating all those, we get:

```<code>class Sprite {
public:
    Sprite(std::string const &filename);
    animate(page const &target);
    loop(page const &target);
};
</code>```

So to load an animate a sprite, we now need something like:

```<code>Sprite x("somefile.spr");
x.loop(animPage);
</code>```

Keep in mind that peoples' short-term memory ranges from about 4 items for a person of average intelligence to about 8 for the top geniuses.

That means 10 parameters is nearly always unreasonable. 7 parameters puts it within reach of a few, but honestly only a few. 4 puts it within reach of almost any programmer, and 1 (or even 3, if you really do need to specify resolution) puts it into the dead simple catgory.

Body:
It reduces productivity by making Microsoft think it's okay to design functions to take 10 or 12 parameters, so virtually nobody ever can or will even come close to learning how to use them without the assistance of (something like) Intellisense.

Edit: Okay, let's take a look at the CreateAnimatedSprite example. First, a function name with two verbs is a nearly-certain sign of poor separation of concerns -- i.e., you have a single function that's really doing two things. Our first step is to fix that so we get a CreateSprite (or, since it's apparently being loaded from a file, it should probably be LoadSprite), and an AnimateSprite. For the moment, let's even assume @Mason is wrong, and you really do need all those parameters -- but when we've separate concerns decently, we're apparently left with something like:

sprite LoadSprite(std::string filename, int imageHeight, int imageWidth);
void AnimageSprite(sprite s, int frameWidth, int frameHeight, int numColumns, bool isLooped);

By my count, we now have the parameter count down to a maximum of 5 -- half the number I'd mentioned as being excessive.

I'd consider this well short of ideal though. First of all, I'd advise against using a bool as a function parameter in most cases. Just glancing at a call to the function, it's not immediately obvious what true or false would refer to. It would be better to have something like:

enum {LOOP, NOLOOP};

When somebody's reading a call to the function, LOOP is much more meaningful than true. Depending on the situation, there are a couple of other possibilities to consider. One would be using object-orientation, so we'd get:

class Sprite {
public:
    enum looping { LOOP, NOLOOP };

    load(std::string filename, int imageWidth, int imageHeight);
    animate(int frameWidth, int frameHeight, int numColumns, looping doLoop);
};

That gets us down to only four parameters for a function, still providing the data you thought was necessary.

In reality, we can probably do better still. First of all, the file from which we load our sprite can store the size of the image(s) it holds, so we may not need to supply that (it's primarily useful if we're selecting one sprite from a file that may hold several). Second, as @Mason pointed out, we probably don't need to supply a frameWidth/frameHeight or numColumns either. In addition, single-pass animation and looped animation are enough different that it's frequently more sensible to supply those as two separate functions. Finally, it might well make sense to just pass the file name from which we're going to read the sprite as a parameter to the ctor. Incorporating all those, we get:

class Sprite {
public:
    Sprite(std::string const &filename);
    animate(page const &target);
    loop(page const &target);
};

So to load an animate a sprite, we now need something like:

Sprite x("somefile.spr");
x.loop(animPage);

Keep in mind that peoples' short-term memory ranges from about 4 items for a person of average intelligence to about 8 for the top geniuses.

That means 10 parameters is nearly always unreasonable. 7 parameters puts it within reach of a few, but honestly only a few. 4 puts it within reach of almost any programmer, and 1 (or even 3, if you really do need to specify resolution) puts it into the dead simple catgory.

OwnerDisplayName: Jerry Coffin


答:
I just ran into a situation where IntelliSense got so confused by nested macros in a particular header file that every edit operation took more than 30 seconds.  This definitely reduced my productivity.

edit:

It turns out that the culprit was not IntelliSense, but a refactoring plug-in which also did analysis of the source in the background.   So I still say it is possible for supposed productivity enhancers to slow you down, but I don't have a specific case against IntelliSense.

OwnerDisplayName: AShelly


问:
Java API vs. Other APIs
I'm more at the novice end of the software developer spectrum, but nevertheless I've had exposure to quite a few programming languages and frameworks. From all the technologies I've used, I haven't found any with an API as well-structured and user-friendly as Java's. Why is this? Why is it that robust languages such as C++, Perl and Python do not have APIs that come even close to Java's?</p>

答:
Have you checked Cocoa and Cocoa Touch frameworks? These two frameworks are as beautiful and well designed as Apple hardware machines.

As Kevin says:

Your opinion might change as you get more experience with other languages.

Absolutely true.

Title: Java API vs. Other APIs


答: The commitment the Java team has made to avoid introducing non-backwards compatible changes means that they probably think long and hard when they're extending their API, instead of just throwing something out there.  Compare this to (say) PHP, which completely changed the handling of XML in PHP5 - no deprecation, just gone.</p>

Title: Java API vs. Other APIs

Body: I'm more at the novice end of the software developer spectrum, but nevertheless I've had exposure to quite a few programming languages and frameworks. From all the technologies I've used, I haven't found any with an API as well-structured and user-friendly as Java's. Why is this? Why is it that robust languages such as C++, Perl and Python do not have APIs that come even close to Java's?</p>


问:
Is learning C# as a first language a mistake?
I know there are similar questions on here, which I've read, but I recently read this post by Joel Spolsky:

How can I teach a bright person, with no programming experience, how to program?

And it got me thinking about my way of learning and whether it might actually be harmful in the long run.

I've dabbled with various languages but C# is my first serious one, I've read "Head First C#" and created a few projects. But after reading the post above I've found it a bit disheartening that I may be going about it all wrong, obviously I respect Joel's opinion which is what has thrown me a bit.

I've started reading "Code" as recommended in the reading list and I'm finding it pretty hard going, although enjoyable. I feel like it's taken the shine off of my "noobish hacking about" in Visual Studio.

So now I'm unsure as to what path I should take? Should I take a step back and follow Joel's advice and start reading?

I guess my main aim is just to become a good programmer, like everyone else, but I don't want to be going into bad practice by learning a .NET language when someone who's opinion I respect thinks that it is harmful.

Thoughts?

答:
I've dabbed with various languages but C# is my first serious one,
  I've read "Head First C#" and created a few projects. But after
  reading the post above I've found it a bit disheartening that I may be
  going about it all wrong, obviously I respect Joel's opinion which is
  what has thrown me a bit.

I respect Joel's opinions too, but they are just that: opinions. There's absolutely nothing wrong with using C# as a starting language.

The biggest advice I can give you, or anyone doing any programming (even if they're starting in vanilla C!) is to not be stagnant, and don't be religious. I don't care what programming language you're starting with, or how pure or righteous that language is - in this day and age you cannot afford to sit in only world of programming.

For example, I started programming with PHP3 back when I was a teenager. I built some small web apps and a few web sites with it; I thought that I was a genius programmer and that I could do anything with PHP3, and frowned on people who were all about ASP or BASIC. Boy, was I wrong.

I didn't start to truly blossom as a developer until I began expanding my horizons and studying other programming languages and concepts. During high school I learned some RealBASIC, and then later Visual Basic. After business school, when I became a professional developer, I started learning C# and Javascript in earnest.

Now, don't misunderstand me here - I'm not advocating that you try to be a Jack of All Trades. At heart, and in trade, I'm still a PHP programmer. PHP is my bread and butter, and I know it inside and out. However, my PHP skills didn't become what they were just doing PHP. Here are some highly important concepts that I didn't grasp from PHP, despite working in it professionaly.

Javascript: Closures

jQuery (yes, separate): the DOM and Ajax

Visual Basic: Objected-oriented programming

C#: Generics and closures

Ruby (on Rails): The power of MVC design

I could go on, and so could many others on this site as well, for days. Even though I'm a PHP programmer I was able to bring all of these other wonderful concepts back with me into the work I do every day.

What's my point? Learn C#. Become a master of C# - you'll have a long, successful career and you'll probably accomplish some amazing things. But don't pigeon-hole yourself. Journey, and taste other languages and environments and concepts.


问:
Why does it matter that HTML and CSS are not programming languages?
Example here:

What languages should I know if I'm interested in building web applications?

Yes, I understand that HTML and CSS are not Turing-complete.  Yes, I understand that they are declarative, not imperative languages.  But why are people always clubbed over the head with this pedantic (and arguably obvious) fact when they ask a question about these languages?

答:
It matters to certain people because neither are rocket science on the surface but there is a great deal of arcana surrounding them due to the fact that they implement differently in typically 5 to  dozens of different environments that you actually care about. That sort of unpredictability and attention to craft scares a certain variety of tech professional who is horrified by unquantifiable risks and even more horrified by learning anything more then they absolutely have to after securing a degree.

If somebody asked me what languages I knew and I threw CSS out there and they said "but that's not a REAL language" I would ask them how they would handle vertically centering a div in IE 5, IEs 6-8 and IE9+. Then we could move on to rounded corners, alpha transparency issues, the REAL culprit behind all these ridiculous tables-as-layout arguments that are only just now starting to be become truly irrelevant and dozens more topics for said uber-coder who probably knows one language and claims one or two that he's barely functionally literate in due to classes he was forced to take in college 10 years ago.

They definitely are 'languages.' I would not call them 'programming languages.' I would feel comfortable describing the process of writing in these languages 'coding.'

As far as I'm concerned, however, anybody who has managed to grand master CSS has the chutzpa and work ethic to become an excellent programmer, already has some background in object oriented thinking, and no doubt has learned to think about how what he writes now could impact his work 25 projects into the future.


答:
You use the tool that you feel makes you the most productive, and the other guy can use the tool that he feels make him feel the most productive.  It'll never happen, but a world without the "my tool is the best because I use it therefore I must force it on everyone else" mentality would be really great.

On a related vector, I've noticed that people who use tools that highlight syntax tend to be less of the "bad Hungarian" style, there's no need to have mThis, mThat, aThing, and aNother if you have color to tell you the scope.


问:
Can I safely use an open source library in an internal closed-source project?
I m thinking of using iTextSharp, which is licensed under Affero GPL, in an internal closed-source WinForms project.  No one outside my company will be using it.

GPL (and Affero GPL as well) typically demands that the source be provided with the binary.  Given that this is an internal project, do I need to provide my employees with the source code of the project?

答:
You have to offer to supply the source and any modifications - to anyone you distribute the binary to.

Since you only distribute it to users inside your company that shouldn't be too much of a problem !

note: the AGPL is basically the GPL with the addition that you consider web users of a service based on the code to have had the software distributed to them - and so get the source.


答:
If you confine use of the library to within the walls of your corporation, you do not have to distribute the source (even to your employees), because you are not redistributing (selling or giving away a software product that includes the library) outside of your organization.

The GPL allows you to freely use the code inside a corporation without restrictions, and that includes (by necessity) your ability to prevent your employees (as a matter of company policy) from distributing the source code outside the organization.

From the Gnu Licensing FAQ:

Is making and using multiple copies within one organization or
  company “distribution”?
 No, in that case the organization is
  just making the copies for itself. As a consequence, a company or
  other organization can develop a modified version and install that
  version through its own facilities, without giving the staff
  permission to release that modified version to outsiders.

However, when the organization transfers copies to other organizations
  or individuals, that is distribution. In particular, providing copies
  to contractors for use off-site is distribution.

Title: Can I safely use an open source library in an internal closed-source project?

Body:
I m thinking of using iTextSharp, which is licensed under Affero GPL, in an internal closed-source WinForms project.  No one outside my company will be using it.

GPL (and Affero GPL as well) typically demands that the source be provided with the binary.  Given that this is an internal project, do I need to provide my employees with the source code of the project?


问:
Where do you find the time?
I find myself lagging behind on new skills, techniques, language features, etc, and I am finding the time to do so is lacking. Between work, professional, personal and family obligations, I'm lucky to find a few stray hours here and there to focus on any new technologies or reading that I want or need to do. I do make it out to relevant local user groups, but even those are sometimes hard to get to?

So I thought I would ask the community, where, or when, do you find the time to focus on honing your skills or learning new ones? Do you schedule time? Forgo some sleep during the week or weekend? Insomnia? Something else?

EDIT I want to thank all of you who took the time to answer and offer up your advice. There were some things I knew or had thought about, and others I hadn't considered as an option until you shed new light on it.

EDIT 2: In trying to find which answer among the many great ones to accept, I went with @Paddyslacker's since it is the one I feel is best suited for my current situation, although everyone had some very good nuggets of wisdom, such as @Elisha @Martin or @dash-tom-bang.

答:
There are 24 hours in a day, every day.  You need to decide what you want to do, and you need to prioritize these things versus the other things that you're doing.

Where is the time going?  Answering this question may be very sobering.  While it may be hard to say you want to cut the hours you spend with loved ones, it may well be here that changes need to be made if doing some "work related" study is important enough to you.

If you do not find that this study is more important than the other things, though, then that's ok (inasmuch as it does not affect your employment).  If you value the time you spend doing whatever you do then that's great.

I struggle with this, too, though.  Many nights I do "nothing," when in fact I could be writing software, blog posts, books.  I struggle with this to be sure, but it's not about finding the time as much as it is putting the things into that time that matter most.

Title: Where do you find the time?


问:
One global HashMap vs. many local HashMaps?
Which is more efficient; which is faster?  Trade-offs?

Goal is for fast look-ups in a web application.

UUIDs are the keys, so global will work.

Approx 50 million values.

A global cache is definitely more manageable than many smaller ones, even using JMX.  But, I had a hunch that maybe the total overhead of the hashtable's internals would somehow be less with a global hashtable vs many spread out through various classes.  However, I cannot find any evidence of this.

Edit:  Please, you must back-up your claim if it is that the overhead is minimal or even if it is significant.  Maybe this should be moved to the Computer Science forum?

答: There won't be any significant difference in space.  The per-table overhead is negligible compared to the 50 million table entries.  Just write the cleanest possible code.  </p>


答:
No, that answer is terrible.  Why?  Well, he does prescribe some good books which you def should read, but without classroom work and lab (computer lab) work, you'll be lost and frustrated.  You need to be with a bunch of other new programmers experimenting because there is soooo much to learn other than what's in those books.  I'm not saying you have to go for a BSCS, but you need access to a knowledgeable instructor as well when a whole slew of things can go wrong at any instant, such as compiler problems, build environments... you name it.  You won't be much of a programmer working in a vacuum.  Whatever books your courses require will be good enough as long as you pick a halfway decent school.

So, sign-up for some classes and it will be a LOT more fun!  Plus, if you plan on getting a job as a programmer you need connections and you'll hear all the buzz about companies recruiting at the campus, etc..

Finally, formal education is very important as programming requires a lot of theoretical background knowledge to understand how things are supposed to work at all levels (hw/sw) so you can figure out how to fix things.  Just about everything is a black box, so you have to be able to figure out why something is behaving the way it is so you can take the next logical stab in the dark.  Without at least a 2-year programming degree (whatever you call it) you'll be at a disadvantage.

P.S.  I wouldn't go near .Net, or C#, until you've experience Java.  C# is not pleasing to the eye.  It's messy and clutered looking code.  The .Net IDE sucks beyond belief.  It's in the dark ages of IDE standards.  Java:C# ~ Data:Lore

Title: Is learning C# as a first language a mistake?

Body:
I know there are similar questions on here, which I've read, but I recently read this post by Joel Spolsky:

How can I teach a bright person, with no programming experience, how to program?

And it got me thinking about my way of learning and whether it might actually be harmful in the long run.

I've dabbled with various languages but C# is my first serious one, I've read "Head First C#" and created a few projects. But after reading the post above I've found it a bit disheartening that I may be going about it all wrong, obviously I respect Joel's opinion which is what has thrown me a bit.

I've started reading "Code" as recommended in the reading list and I'm finding it pretty hard going, although enjoyable. I feel like it's taken the shine off of my "noobish hacking about" in Visual Studio.

So now I'm unsure as to what path I should take? Should I take a step back and follow Joel's advice and start reading?

I guess my main aim is just to become a good programmer, like everyone else, but I don't want to be going into bad practice by learning a .NET language when someone who's opinion I respect thinks that it is harmful.

Thoughts?


答:
when someone who's opinion I respect thinks that it is harmful.

This reminds me of a story involving Richard Feynman. A student at Caltech asked the eminent cosmologist Michael Turner what his "bias" was in favoring a type of particle as a candidate to comprise the dark matter, and Feynman snapped and said "Why do you want to know his bias? Form your own!...Don't pay attention to authorities, think for yourself."

Programmers come from all walks of life. Java is taught in many high schools and colleges today, yet it hadn't even been invented when Joel Spolsky was in school. There is no "one true path" when it comes to becoming a good programmer. There are certainly some classics like SICP that most programmers stumble across at some point, but there's no hard and fast standard. The main thing is to start somewhere, and focus on building concepts. A great programmer once said something like:

Bad programmers focus on code, good programmers focus on algorithms.

I think C# is a fine language to start with, but I warn you to be wary of Visual Studio. It is a tremendous IDE, but if you drag a DropDownList and bind a GridView to a ObjectDataSource and use a Button control to make a DropDownList based search, then most of the work is done by the IDE and you're not really programming. Take advantage of the IDEs tools, but always try to build concepts and develop knowledge.


答: It's been some years since I worked in C#, so I'll give my answer w.r.t. Eclipse and Java.  Completion in Eclipse doesn't reduce my productivity.  The need for completion due to the inconsistent Java API does reduce my productivity considerably.  For example, Java has arrays, lists, sorted sets, and streams.  They are all list-like, and have essentially no methods in common.  It's the same for maps, and HTTP request parameters, and SQL query parameters, and the rows in a SQL result set, and JavaBeans. They are all map-like, but have different APIs, and converting between them is painful.  I do fine without completion in languages where APIs are consistent, where everything that looks like a list is a list, and everything that looks like a map is a map.</p>


答:
The first language productive for me was C#. Though i had fiddled with Foxpro in school time and a bit of C in College. C# is pretty good and very nice starting point for anyone. It follows the general fundamentals of programming like strong typing, encapsulation, inheritance etc which I believe one should always learn, no matter if they use them or not. Later, You can always move to other languages like Python which doesn't follow the standardization of fundamental programming.

The other adding factor which people don't really add to the learning aspect of C# is the availability of best IDE for any language I have seen. Eclipse IDE is good too, but once you used Visual Studio, you will thank microsoft.

C# being enhanced over C, ensures that you don't need to learn other languages beforehand. All the languages over a decade or so has evolved from the nature of C, even the JAVA.

So, the verdict is, C# is a great starting point that renders you the ability to learn other languages fast in future


问:
Choosing between CL and Python for web development
I'm coming from a Java background and after I read this little essay by Paul Graham I started wondering about picking up a new language namely Common Lisp to speed up my work (I'm a web developer).

I'm writing pet projects currently but I have some business plans for the future. Paul speaks about LISP in his essay as a "Secret weapon". I don't know if this statement is true after 10 years but I dipped my toes into a nice CL tutorial and it looks like that LISP may be superior for web development.

Paul also mentions Python as a nice choice which I actually familiar with. My question is: which one should I choose for my future web projects?

What I was thinking about:

I'm not going to develop desktop applications so I can choose whatever language I prefer.

python seems to have a very large community thus a mutch more libraries / frameworks compared to lisp

I found out that lisp has some functionality (like macros) which cannot be found anywhere else

I mostly work alone or with 1-2 other programmers but finding someone with lisp knowledge can be hard

So what do you think?

答:
If you have no time pressure, use Lisp. Learning Lisp will change the way you view Python (and every other language you know), but learning Python won't change the way you view Lisp (if you knew it). Lisp is more than a new tool in the toolbox. It's a new way of thinking.

While you're at it, take a look at Factor or another concatenative language. Concatenative languages are amazing for teaching you how to think in combinators. Learning a concatenative language will change the way you view all other languages.

Finally, exercise your right brain. The formalism of programming languages forces us to over-use our left brain for problem solving. Activate your right brain to access another game-changing paradigm shift.


问:
Group messaging of computers over internet
I want to be able to send messages between computers on the internet network but with minimal functionality

requirement are- 1)computers can join/leave the group (I expect the group size to be a maximum of 5-10) 2)any message generated by any computer will be sent to every other node (this is the main requirement and I have short messages which need to be sent in shortest possible time: suggest network layer protocol to be used here), message wont be resent or ack (except leave)..but I still want to maintain high reliability, can I maintain it without receiving acks?

one problem would be to communicate on the internet I will need some sort of NAT support? how can this be managed without a stun server?

Should I use a p2p library? as I think most of the features they offer wont be needed by me could anyone suggest some here?

I'm working in C++.

答:
You could have a look at ZeroMQ. It's basically a very efficient message queue with support for different transport protocols. Besides others, it implements a Publish-Subscribe model where a node can publish messages that will be received by all subscriber nodes. It is very lightweight and it works on Windows, Linux and Mac. Maybe this is a good starting point...?

Note that there is also a Qt binding (nzmqt) for it (just in case you want to use Qt for your project).


答: Learning C# as a first language is no mistake as long as you sooner or later move on and start learning a second language. That's far more important. Even better if that second language is somewhat different from C# (javascript or ruby would in that respect be better that java). Every language has its pros and cons, and it's the differences that will make you a better programmer in the long run.</p>


问:
git/svn Hooks for PHP/Zend Projects
just because i think we are not using the full potential of all possibilites here yet:
What Pre/Post Commit Hooks (i.e. PHPUnit, PHPDoc) do you people use on your Team Git/SVN Servers?
By now we do use a minification script (sadly only removes unneccessary space and comments and merges files), PHPDoc, PHPUnit and that's it already.

Any good ideas that might be usefull as well?

答:
We use a Jenkins setup that runs Sebastiann Bergman's default template, including pdepend, phploc, phpmd, to analyse style quality, architecture quality and the likes.

http://jenkins-php.org/

We've already greatly improved the quality of our codebase since we started using it a few weeks ago :)

Title: git/svn Hooks for PHP/Zend Projects


答:
The reasons are historical and philosophical, with the history deeply affecting the philosophy.

C++, Perl, and even Python are all older then Java, and because of Moore's law they were developed in an environment where disk and memory were one or two orders of magnitude more expensive. Developers very much wanted to pick and choose which APIs they had on a system because memory and disk were expensive, and networks were slow. Why not let developers exercise their judgment and chose whatever library they thought best?

Java was originally developed for proprietary, embedded software so it HAD to provide all the libraries used at run time. When Java migrated to general purpose computing this turned out to work pretty well for folks doing line-of-business software, but it was also one of the reasons why Java initially got smacked as being slow and bloated.

If you go to a nice restaurant you'll often be given a choice between "prix fixe" and "ala carte".  Each course of the prix fixe meal, and maybe even the wine is chosen by the chef in advance. This is great if you don't know much about the food and trust the chef. If you have very particular tastes or think the chef is a moron, you'll want to order ala carte, where you pick each course to exactly suite your taste.

Title: Java API vs. Other APIs


答:
I don't know a ton about Lisp other than its origins. What I know about Python is this:

5 minutes after the first flying saucer lands, the Python community will have put together something for interfacing with its I/O systems.

Also, coming primarily from JavaScript, I found Python a very natural fit. Perhaps the converse might be true.

Also, Django is pretty much the framework to imitate nowadays.

Title: Choosing between CL and Python for web development

Body:
I'm coming from a Java background and after I read this little essay by Paul Graham I started wondering about picking up a new language namely Common Lisp to speed up my work (I'm a web developer).

I'm writing pet projects currently but I have some business plans for the future. Paul speaks about LISP in his essay as a "Secret weapon". I don't know if this statement is true after 10 years but I dipped my toes into a nice CL tutorial and it looks like that LISP may be superior for web development.

Paul also mentions Python as a nice choice which I actually familiar with. My question is: which one should I choose for my future web projects?

What I was thinking about:

I'm not going to develop desktop applications so I can choose whatever language I prefer.

python seems to have a very large community thus a mutch more libraries / frameworks compared to lisp

I found out that lisp has some functionality (like macros) which cannot be found anywhere else

I mostly work alone or with 1-2 other programmers but finding someone with lisp knowledge can be hard

So what do you think?


问:
What are the most common mistakes and anti-patterns NHibernate user programmers make?
What are the most common mistakes and anti-patterns NHibernate user programmers make? Please explain why those are bad practices or give link to resource for further reading.

For example:

One anti-pattern common for new NHibernate programmers is to use identity/native POID's instead of ORM style onces. Read more here...

答:
My personal "frequently explained" issues:

Anti-Patterns

Messing around with detached objects (SaveOrUpdate or Merge plus some messy code) instead of using DTO's. The more complex the entities are, the messier the code is. (It also means that it works quite well with trivial entities.) Ayende also calls it the Stripper Pattern and explains the encapsulation issue.

Not understanding persistence ignorance and writing NH applications as when using explicit SQL. Symptom of that: calling Update after changing an object, wondering why changes are persisted even if Update had not been called, wondering how to avoid changes to be persisted.

I tried to explain it in this SO answer

Read how flushing works in the reference documentation.

A blog post by kurtharriger who is criticizing exactly what is actually one of
the main features (as a prove that it is a common misconception about NH)

Not understanding transactions and the unit of work pattern. Frequent anti-patterns: implicit transactions, session-per-operation and session-per-application. Some more reading:

Fabio Maulo: Conversation-per-Business-Transaction

On nhforge.org: Effective NHibernate Session management for web apps

Using NH events to put application logic in (eg. change tracking in insert and update triggers)

Create one class per table. Some people don't understand OOD, others don't understand relational design.

Mistakes

use of one-to-one instead of many-to-one. I tried it to explain in this answer.

Using join fetch in combination with SetMaxResult. My latest answers related to that topic:

Why doesnt NHibernate eager fetch my data (with some more notes about side effects in the comments)

Hibernate - How to make associations eager

NHIbernate 1.2 And Lazy Loading

Pagination with Hibernate criteria and FetchMode.JOIN

Writing self changing entities. When an entity doesn't exactly return the value that had been set by NH, it is considered dirty and gets updated in every session. For instance: replacing the NH persistent collection in a property setter.

```<code>  IList<Address> Addresses
  {
    get { return addresses; }
    // will cause the addresses collection to be built up from scratch
    // in the database in every session, even when just reading the entity.
    set { addresses = new List<Address>(value); }
  }

  int Whatever
  {
    // will make the entity dirty after reading negative values from the db.
    // this causes unexpected updates after just reading the entity.
    get { if (whatever < 0) return 0; }
    set { whatever = value; }
  }
</code>```

May be more is following.

OwnerDisplayName: Darius Kucinskas

Body:
My personal "frequently explained" issues:

Anti-Patterns

Messing around with detached objects (SaveOrUpdate or Merge plus some messy code) instead of using DTO's. The more complex the entities are, the messier the code is. (It also means that it works quite well with trivial entities.) Ayende also calls it the Stripper Pattern and explains the encapsulation issue.

Not understanding persistence ignorance and writing NH applications as when using explicit SQL. Symptom of that: calling Update after changing an object, wondering why changes are persisted even if Update had not been called, wondering how to avoid changes to be persisted.

I tried to explain it in this SO answer

Read how flushing works in the reference documentation.

A blog post by kurtharriger who is criticizing exactly what is actually one of
the main features (as a prove that it is a common misconception about NH)

Not understanding transactions and the unit of work pattern. Frequent anti-patterns: implicit transactions, session-per-operation and session-per-application. Some more reading:

Fabio Maulo: Conversation-per-Business-Transaction

On nhforge.org: Effective NHibernate Session management for web apps

Using NH events to put application logic in (eg. change tracking in insert and update triggers)

Create one class per table. Some people don't understand OOD, others don't understand relational design.

Mistakes

use of one-to-one instead of many-to-one. I tried it to explain in this answer.

Using join fetch in combination with SetMaxResult. My latest answers related to that topic:

Why doesnt NHibernate eager fetch my data (with some more notes about side effects in the comments)

Hibernate - How to make associations eager

NHIbernate 1.2 And Lazy Loading

Pagination with Hibernate criteria and FetchMode.JOIN

Writing self changing entities. When an entity doesn't exactly return the value that had been set by NH, it is considered dirty and gets updated in every session. For instance: replacing the NH persistent collection in a property setter.

  IList<Address> Addresses
  {
    get { return addresses; }
    // will cause the addresses collection to be built up from scratch
    // in the database in every session, even when just reading the entity.
    set { addresses = new List<Address>(value); }
  }

  int Whatever
  {
    // will make the entity dirty after reading negative values from the db.
    // this causes unexpected updates after just reading the entity.
    get { if (whatever < 0) return 0; }
    set { whatever = value; }
  }

May be more is following.

OwnerDisplayName: Stefan Steinegger


答:
Too many abstractions

Not using Automappings with FluentNHibernate

Body:
What are the most common mistakes and anti-patterns NHibernate user programmers make? Please explain why those are bad practices or give link to resource for further reading.

For example:

One anti-pattern common for new NHibernate programmers is to use identity/native POID's instead of ORM style onces. Read more here...

OwnerDisplayName: Sly


问:
Price Comparison Database Scema
I have a bunch of data from multiple retailers. Each product that each retailer sells may or may not be sold by another retailer in the database. If multiple retailers sell the same product, then the product can be identified by a SKU. I currently have 1 database for each retailer. I'm having a problem trying to conceptualize an appropriate database schema to identify how many retailers are selling the same product.

Should I have 1 table with all retailers?

答: Yes I would make 1 table with rows for each retailer and a separate table with one row for each product. Then I'd just do another table with rows that have 2 foreign keys: 1 for the retailer and 1 for the product (many-to-many). To find out how many retailers are selling a product just count the number of rows that have the foreign key for a specific product in the many to many table.</p>

Title: Price Comparison Database Scema


答: I have to ask, are you sure you are not re-inventing the wheel?  There are several good in-memory caches out there (JCS, Terracotta, EHCache and many more)</p>

Title: One global HashMap vs. many local HashMaps?

Body:
Which is more efficient; which is faster?  Trade-offs?

Goal is for fast look-ups in a web application.

UUIDs are the keys, so global will work.

Approx 50 million values.

A global cache is definitely more manageable than many smaller ones, even using JMX.  But, I had a hunch that maybe the total overhead of the hashtable's internals would somehow be less with a global hashtable vs many spread out through various classes.  However, I cannot find any evidence of this.

Edit:  Please, you must back-up your claim if it is that the overhead is minimal or even if it is significant.  Maybe this should be moved to the Computer Science forum?


答:
The focus of your question and many of the answers here is on C#. From Wikipedia:

C# language is intended to be a simple, modern, general-purpose,
  object-oriented programming language.

Based on that alone, it seems safe to say that you could learn C# as a first language without doing any long-term damage to your brain. I don't think that Joel was condemning the entire language, though, when he wrote:

Attempts to take a shortcut and go directly to learning the exact
  thing you want to learn right now (like starting with C# and ASP.NET)
  are doomed.

The problem isn't the language, it's taking shortcuts. Too often, people try to take a quick route to their end goal by following step-by-step tutorials or "learn everything in 24 hours" books. You don't have to spend too much time on Stack Overflow before you start noticing that there are a lot of questions along the lines of: "I've never written a line of code in my life, but I'm getting into iPhone programming! Can someone please give me step-by-step instructions for doing exactly what I want to do? Thanks!" I'm not saying that you're taking that approach, but it's something that you have to guard against.

If you want to develop solid programming skills, you should start by learning fundamental skills. If you try to jump straight to OOP and GUI applications and such, you'll probably miss those fundamentals. The books that Joel pointed to are very good indeed. I've only skimmed through the C# Yellow Book (PDF), but looks like it's probably a better intro to programming than most of the C# books I see in stores.


答:
I'd say learning one language and sticking with it is more of a mistake than deciding which language you should start with. There are some languages you can learn that are easier of course, but it's better to try and start learning one that you'll be using a lot (in a school setting the language choice is already made by the school). After you've properly learnt a language and used it actively after some months, you should dabble with another programming language and compare.

In .NET it's easy for you to go with two (sort-of) different programming languages since you can switch between Visual Basic and C#. So you can learn Visual Basic and see what the differences are. At this level you should be proficient with basic procedural coding with the three basic programming structures, if you can be creative with them all (and know how to use variables) then you're on your way to become a great programmer:

Sequence - Code is written in sequence of steps that follow each other in a manner you specify, (defines a "jump", step-by-step and gotos)

Conditional - Code can have decision points, (defines if-statements, switch-case statements)

Looping/Repetition - Code can repeat itself given some decision (which is an extension of both above, defines for-, do-while-loops)

It doesn't matter if your secondary programming language will be your most active or not, just knowing that programming languages (specially if they're following the same paradigm) are very similar to each other and there are small nuances actually goes a long way to get you to understand how software programming works.

From that, at least once a year, try to learn a new programming language that follow another programming paradigm. You don't need to completely keep up with the new language but there are some benefits to know other paradigms. There are several paradigms, and some programming languages intermix between many (note that C# actually has subsets the following three):

Procedural

Object Oriented

Functional

... and many more!

The most important things you should learn that many programming languages follow their own set of idioms and a basic API. So when you learn a new language, try to learn those idioms and API's well and you'll be fine when you build stuff. One good reason is that you'll become better at designing and solving programming problems. Some idiom in one language, may give you some insight on how to solve a problem in your main one.

Also know that there is also another very good reason why you should learn other programming languages, other than the main language you'll be using the most: Your chances on employment is much greater.


问:
The best method to get personal projects done
I have numerous personal projects I've begun and never seem to finish because I get sidetracked with other ideas. I was wondering what the best method to get personal projects done is? Any tricks or tips to it? </p>

<p>The problem is I get a spurt of inspiration on some projects, and I don't wanna lose track of my ideas and right now my method of "saving my ideas" is to just get as much stuff done on the ideas as possible in one night and then store some GitHub issues as to dos. I find that this makes me never get back to older projects tho. </p>

答:
Which one are you sufficiently upset about? Finish that one. Repeat.

These are personal projects: the only person who cares about them right now is you - and if you don't care enough, then you probably already got from them what you needed. Don't beat yourself up about it.


答:
Sometimes I suspect languages of choice have a lot more to do with our personalities and they way we're wired and a lot less to do with practical or academic considerations than we'd like to admit.

That said, learning new stuff is never harmful. You'll know the day you've crossed the threshold towards an evolved or perhaps broken brain (all a matter of perspective I suppose) when you start to realize that everything has a manual. You can ultimately really do anything you want if you've got some talent and are actually interested in the doing rather than the being aspect of a programmer.

At least mess around with Python and JavaScript. It's a definite learning advantage to really be able to just write code and watch it execute immediately in a file I/O accessible console environment like IDLE or a sandbox environment like a browser. What I dislike about C# and Java is that they want everything to be confined to classes even if you're really just writing a simple function with pointless wrappers around it to keep your peers or an overly restrictive compiler happy. The other thing I like about JS and Python is that they really let you set your own paradigm. A little too flexible by a lot of developers preferences. I'm still not sure what to think of the wisdom of overloading basic operators but I'm pretty sure I love Python for allowing the option.

Also don't fall for the cruel lie of choosing the primary language with the most job listings. It's better to be a big fish in medium waters doing what you like than a member of a horde of mostly crappy insufferable fish that turn every job-search into more of a lottery than a matching process.


问:
Is it a code smell if an object knows a lot of its owner?
In our Delphi 2007 application we are using a lot of the following constructs

```<code>FdmBasic:=TdmBasicData(FindOwnerClass(AOwner,TdmBasicData));
</code>```

The FindOwnerClass travels the Owner hierarchy of the current component upwards to find a specific class (in the example TdmBasicData). The resulting object is stored in the Field variable FdmBasic. We use this primarily to pass datamodules along.

Example:
When generating a report, the resulting data is compressed and stored in a Blob field of a table accessed through a datamodule TdmReportBaseData. In a separate module of our application, there is functionality to show the data from the report in a Paged form using ReportBuilder. The main code of this module (TdmRBReport), uses a class TRBTempdatabase to convert the compressed blob data into different tables that are usable in the Reportbuilder runtime reportdesigner.
TdmRBReport has access to TdmReportBaseData for all kinds of report-related data (type of report, report calculationsettings, etc). TRBTempDatabase is constructed in TdmRBReport but has to have access to TdmReportBasedata. So this is now done using the construction above:

```<code>constructor TRBTempDatabase.Create(aOwner: TComponent);
begin
  inherited Create(aOwner);

  FdmReportBaseData := TdmRBReport(FindOwnerClass(Owner, TdmRBReport)).dmReportBaseData;
end;{- .Create }
</code>```

My feeling is that this means that TRBTempDatabase knows a lot of its owner, and I was wondering if this is some sort of code smell or Anti-pattern.

What are your thoughts about this? Is this a code smell? If so, what is a better way?

答:
This kind of looks like a Service Locator Pattern which was first described by Martin Fowler (which has been identified as a common anti-pattern).

Construction based Dependency Injection is preferred over a Service Locator as it promotes visibility of the require parameters and promotes simpler Unit Testing.

http://blog.ploeh.dk/2010/02/03/ServiceLocatorIsAnAntiPattern.aspx

The problem with using a Service Locator isn’t that you take a
  dependency on a particular Service Locator implementation (although
  that may be a problem as well), but that it’s a bona-fide
  anti-pattern. It will give consumers of your API a horrible developer
  experience, and it will make your life as a maintenance developer
  worse because you will need to use considerable amounts of brain power
  to grasp the implications of every change you make.

The compiler can offer both consumers and producers so much help when
  Constructor Injection is used, but none of that assistance is
  available for APIs that rely on Service Locator.

Also most notably it also breaks the Law of Demeter

http://en.wikipedia.org/wiki/Law_of_Demeter

The Law of Demeter (LoD) or Principle of Least Knowledge is a design
  guideline for developing software, particularly object-oriented
  programs. In its general form, the LoD is a specific case of loose
  coupling.

Law of Demeter for functions requires that a method M of an object O
  may only invoke the methods of the following kinds of objects:

O itself

M's parameters

any objects created/instantiated within M

O's direct component objects

a global variable, accessible by O, in the scope of M

In particular, an object should avoid invoking methods of a member
  object returned by another method. For many modern object oriented
  languages that use a dot as field identifier, the law can be stated
  simply as "use only one dot". That is, the code a.b.Method() breaks
  the law where a.Method() does not. As a simple example, when one wants
  to walk a dog, it would be folly to command the dog's legs to walk
  directly; instead one commands the dog and lets it take care of its
  own legs.

The Better Way

Effectively the better way is to remove the service locator call within the class, and pass in the correct owner as a parameter inside it's constructor.  Even if this means that you have a service class which performs an owner look up and then passes that to the class constructor

```<code>constructor TRBTempDatabase.Create(aOwner: TComponent, ownerClass: IComponent);
begin
  inherited Create(aOwner);

  FdmReportBaseData := TdmRBReport(ownerClass).dmReportBaseData;
end;{- .Create }
</code>```

Body:
This kind of looks like a Service Locator Pattern which was first described by Martin Fowler (which has been identified as a common anti-pattern).

Construction based Dependency Injection is preferred over a Service Locator as it promotes visibility of the require parameters and promotes simpler Unit Testing.

http://blog.ploeh.dk/2010/02/03/ServiceLocatorIsAnAntiPattern.aspx

The problem with using a Service Locator isn’t that you take a
  dependency on a particular Service Locator implementation (although
  that may be a problem as well), but that it’s a bona-fide
  anti-pattern. It will give consumers of your API a horrible developer
  experience, and it will make your life as a maintenance developer
  worse because you will need to use considerable amounts of brain power
  to grasp the implications of every change you make.

The compiler can offer both consumers and producers so much help when
  Constructor Injection is used, but none of that assistance is
  available for APIs that rely on Service Locator.

Also most notably it also breaks the Law of Demeter

http://en.wikipedia.org/wiki/Law_of_Demeter

The Law of Demeter (LoD) or Principle of Least Knowledge is a design
  guideline for developing software, particularly object-oriented
  programs. In its general form, the LoD is a specific case of loose
  coupling.

Law of Demeter for functions requires that a method M of an object O
  may only invoke the methods of the following kinds of objects:

O itself

M's parameters

any objects created/instantiated within M

O's direct component objects

a global variable, accessible by O, in the scope of M

In particular, an object should avoid invoking methods of a member
  object returned by another method. For many modern object oriented
  languages that use a dot as field identifier, the law can be stated
  simply as "use only one dot". That is, the code a.b.Method() breaks
  the law where a.Method() does not. As a simple example, when one wants
  to walk a dog, it would be folly to command the dog's legs to walk
  directly; instead one commands the dog and lets it take care of its
  own legs.

The Better Way

Effectively the better way is to remove the service locator call within the class, and pass in the correct owner as a parameter inside it's constructor.  Even if this means that you have a service class which performs an owner look up and then passes that to the class constructor

constructor TRBTempDatabase.Create(aOwner: TComponent, ownerClass: IComponent);
begin
  inherited Create(aOwner);

  FdmReportBaseData := TdmRBReport(ownerClass).dmReportBaseData;
end;{- .Create }


问:
Do you obfuscate your email address in open-source code to prevent spamming?
I've been thinking of releasing a few projects, and most authors in the community leave their email address right in the code, often as is or using commonly used schemes like "meATNOSPAMgmail.com", which sort of gets my paranoia flag up...

When releasing source code publicly, does it often lead to your email address being parsed by spam bots, and if so how do you obfuscate it ?

答:
Obfuscating your email address is great if you are 100% all the time and the spam bots haven't figured out how to parse your particular method yet.  If you mess up once, or the spam bots figure out how to parse it then you can't put the genii back in the bottle.

So live life on the edge, post your email address with little regard for the spam that is sure to follow: jim@mckeeth.org

Chances are they all have your email address anyway, and if they don't they are bound to start guessing.


答:
The question title is "How to pick...", but you seem to be asking "How to complete personal projects?" I think there are (at least) two things going on:

Something that seems like a good idea at the time may turn out to be less important to you after you've thought about it for a while.

The form of your work may make it more difficult to come back to. Sometimes, when you're feeling inspired, you have the sense that you can see the entire project and how all the parts fit together, and you want to write it down before it gets away from you. When you come back to it later, the code you've written may not be so clear, or may not be so well designed as you thought it was at the time. Or maybe you've had some additional ideas on the topic, but they don't really fit in so well with the original concept.

In the first case, not finishing might be the right decision. You've had an idea, it was interesting, and now you're moving on.

In the second case, I think that feeling of seeing everything is your brain playing a trick on on you. You've got an idea and it seems great, and your brain races around filling in the missing pieces to make the idea seem more coherent. One way to deal with that is to slow down and use a better design process. Instead of jumping right into code, write the idea down in prose. Create a high level design, and then start fleshing out the details. If the insight you have relates to implementation, then write that down too, but don't try to code it all up at this stage. This way, you've captured the idea(s) on paper so they won't get away, but you haven't implemented anything, so the design is still pretty flexible. At this point you can come back to it later if you want, and if it still seems like a good idea, improve the design and eventually start implementing in a methodical way. Keep a log of your progress so you can always tell what you've done and what you still need to do.

The last thing is that you have to actually want to finish the project. If you don't want to finish it, then it's just another chore on your to-do list that piles up and makes you feel swamped by a ton of work that you don't actually need to do.

Title: The best method to get personal projects done

Body:
I have numerous personal projects I've begun and never seem to finish because I get sidetracked with other ideas. I was wondering what the best method to get personal projects done is? Any tricks or tips to it? </p>

<p>The problem is I get a spurt of inspiration on some projects, and I don't wanna lose track of my ideas and right now my method of "saving my ideas" is to just get as much stuff done on the ideas as possible in one night and then store some GitHub issues as to dos. I find that this makes me never get back to older projects tho. </p>


问:
What does Google or Microsoft get by hosting JS files on their Content Delivery Networks (CDN)?
As you know Google, Microsoft and jQuery.com offer JS files on their CDN. To do this, they must need to operate significant servers which must come at a cost to them. Why do they do this and what do they get from it?</p>

答:
A number of answers here touch on the technical advantages of Google hosting the files, but they miss the reason as to why this is a benefit to Google. At the end of the day, Google would not choose to do something unless they benefit from it in some way (either directly or indirectly).

Google uses these files extensively across their network, and as such need to host them somewhere. By hosting them from a centralised location, the file will be downloaded once, and then will be cached in the users browser, so it does not have to be downloaded next time the user visits another Google site. By opening this up to other websites, those other websites also benefit from slightly quicker loading times, as the user probably already has them cached. This will come at very little overhead to Google, as in very few cases will the file actually need to be loaded again, but also because their CDN is so large and efficient.

Now, what is the benefit to Google of doing this?

Don't forget Google's primary source of revenue is from web advertising. Therefore, the more people browsing the web, the more money Google can make. As such, it is in Google's interest to make it as easy as possible for people to develop rich web applications and websites, and to make those applications load as fast as possible.

By hosting the file, they make it load faster via caching (as mentioned previously), but also make it easier for developers to access and use. It is now one less step for the developer, they no longer need to copy the file to their server and host it, and can instead just copy code from tutorial websites and have it up and running in seconds.

This makes jQuery very quick, and very easy to use, encouraging more people to use, and contribute to the project. As it is open source, as more people contribute, allowing Google to reduce their input in terms of developer resources.

So by hosting the files, Google has managed to:

Speed up websites

Make websites more feature rich and appealing

Help make jQuery an established technology, which can be maintained by an independent community

All this benefits Google by making the web a more friendly, faster place. All at minimum cost to Google, but significant extra revenue to them.


答:
I'm just a junior, but with all humility and respect for those infinitely more experienced, I have to confess that I don't get this attitude either.

One programmer commented below Joel's answer: "as someone who has had to bang his head on the desk over "programmers" who came highly recommended for their C# abilities, but couldn't do simple things like implement a very well documented base class, find memory leaks in c and c++ programs"...

But why must finding memory leaks in C++ apps be simple for someone who never claimed to know C++? :) I don't understand. It's like criticizing a psychologist for lack of dentist skills. I'm surely not a good programmer, but I feel this is not because I don't know C++ - it's because I don't know well enough the framework and languages which I am using.

"couldn't do simple things like implement a very well documented base class (...) or simply figure out a problem on their own or learn a new idea at even a moderate pace"

OK, but - correlation doesn't mean causation, and what makes us assume that their lack of general programming skills - which I don't doubt - is a result of their language choice?

Or an effect of C# being their first language of choice, for that matter?

I can see other plausible explanations (perhaps C# is just trendy, and hence it attracts a lot of novices... most people for whom C# is the first language have not been programming very long at all, and that is more of a handicap in its own right than never programming in some other language... etc., etc.).


问:
Should we choose Java over C# for a new project?
We have a team of .NET developers (C#) with a range of experience from 2 to 6 years. Over the last few years we have been developing Silverlight, ASP.NET MVC, and WPF applications. However, there is a new two year project which means we will develop a HTML5 application on Linux.

The company I work for would like all developers across their offices to use the same programming language which is Java. Although there is talk of using Mono but using the same language and sharing modules, services, etc. already created in Java is the main reason for moving to Java.

Some of the developers here are upset. How do I find something positive in moving over that will convince the other developers?

There will be a training budget, but the thought of learning to work with Java libraries and a new platform (Linux) will be scaring a lot of the guys.

What should I do?

答:
Firstly, Linux as the new platform is not that big of a problem. Java is based on the JVM which does a pretty good job on hiding the system and the hardware. If you need to dig into the OS, than neither Java nor C# are the language of choice in my opinion. It's much like developing PHP. You can do it with a webserver on both Linux and Windows, and in almost all cases there aren't any differences during runtime due to the system it's deployed on.

When you are developing web applications with Java, especially enterprise web applications, you'll probably use Java EE, so you'll have to use a container for it (JBoss, WebSphere, GlassFish, etc.). These can be run on Windows or Linux, it doesn't matter. Our production systems here use Red Hat Enterprise Linux with JBoss, while most developers have Windows 7 systems and this inhomogeneity never caused any trouble.

Switching to Java from C# isn't really complicated, too. The languages are quite similar in most aspects. You'll really miss some features like Properties and LINQ, but this is really a minor concern.

A much bigger concern are the APIs. Java and J2EE done right differs quite a lot from the .NET (web-)technologies. You should put serious effort into learning JPA and EJB best practices (if you are using Java EE, that is, JPA can also run standalone). I also advice to use EJB 3.0 as the pervious versions are totally overengineered and now have been simplified. Sadly, most Java development these days is still a venture through the XML-Hell. Although convention over configuration has been put into place in the newest releases of most APIs, there's still a lot of XML to write. This is especially true to web-development (JSF for example). Please note that in this context I am talking about configuration issues and not about declarative UI development.

As far as web-technologies are concerned, I'd advice you not to use JSF (which is propagated as a standard), as it is complicated and overengineered. It might get better with the next releases. I'd rather use Apache Wicket or Tapestry, which will save you a lot of headaches, especially if you'll have the need for custom user controls or rich clientside scripts.

As for the interoperability: If the existing services are coded against industry standards (REST/SOAP) then you probably have no problem consuming them with .NET. However, if you'll have to use existing libraries and modules, then it's probably better to use Java, in order to keep reuseability high (DRY) and for the sake of homogeneity.

My advice is to keep the environment of the customer clean. Use Java, the language switch isn't that complicated. Train on the APIs you want to use extensively. I know developers are going to swear, because they'll be missing LINQ, and because they'll be writing a little more boilerplate code, but you can definitely transfer lots of experience (especially on the modelling part) to the new environment.

Edit:
Regarding the APIs of choice, some people (@TMN for example, thanks for pointing it out) suggest to skip EJB altogether and to adopt Spring Framework and Hibernate. Hibernate can also be used as a JPA provider. This is certainly not bad advice.


答:
C# is not as bad as Java by a considerable stretch. They have better support for many concepts like functional programming, generic programming, deterministic destruction and value types, operator overloading, etc. Their support for these features could still use a lot of work, of course, but it's vastly better than Java, even if it is no C++.

Secondly, I think that you're mis-reading what Joel has said. If you can master pointers and recursion, then it doesn't matter what language you're using now. The most important thing would be to use a little unsafe code, get to grips with unsafe quicksort or something, and then go back to the rest of normal C#.

Oh, and get reading :)


答:
My answer is assuming that you are going to move.

I'll add to @Falcon's answer:

The JVM is an amazing platform to run on. If your developers need to the power of another language (for example Scala, which supports LINQ) then they can happily use that language and directly interoperate with Java. It's much more flexible than the CLR. As @Falcon mentions, your developers can also continue developing and testing on Windows until they get  more comfortable in the Linux environment.  I believe that developers should also be comfortable with build, deployment, app servers etc - so I do suggest you get some training in place for that.

Definitely look at the JEE6 stack (EJB 3.0, JPA etc). It's annotation based coding will be fairly close to what C# folks do today (yes you still have to do some XML configuration, but it's not as bad as it used to be, honest). There are a bunhc of free open source application servers that will run the JEE6 code (Jboss, Glassfish, Tomcat and more). There is a particular tool called JRebel, which is a must if you are developing in this environment as it means you don't have to have the expensive stop/start cycle for your application server every time you deploy.

Alternatively if you need to do some rapid prototyping to start with then you can look at SEAM, Spring Roo or Grails, but be prepared to throw away the results afterwards.

The Java ecosystem has a library for everything. This is only a slight exaggeration, it really does have a free, open source library for just about every occasion. If there's a feature that your team misses from C# or some other library they use, there's almost certainly going to be a free, open source Java based equivalent.

Hopefully you can keep the web layer simple, based on AJAX class as opposed to any of the well meaning but flawed Java technologies (JSP, JSF, Wicket , Tapestry etc).

You can point out to your developers that the Java ecosystem is undergoing a massive renaissance at the moment, it has a really passionate community and an environment of developer freedom (you have an endless choice of languages, libraries and platforms).

Title: Should we choose Java over C# for a new project?

Body:
We have a team of .NET developers (C#) with a range of experience from 2 to 6 years. Over the last few years we have been developing Silverlight, ASP.NET MVC, and WPF applications. However, there is a new two year project which means we will develop a HTML5 application on Linux.

The company I work for would like all developers across their offices to use the same programming language which is Java. Although there is talk of using Mono but using the same language and sharing modules, services, etc. already created in Java is the main reason for moving to Java.

Some of the developers here are upset. How do I find something positive in moving over that will convince the other developers?

There will be a training budget, but the thought of learning to work with Java libraries and a new platform (Linux) will be scaring a lot of the guys.

What should I do?


答:
I think the best piece of I've advice I've ever seen when it comes to people asking "What language should I learn?" is simply: a good programmer can work in any language.

There are arguments against that statement I'm sure, but the point is: learn to be a good programmer, instead of a language expert, first. Builders don't specialise in building on exactly one plot of land, they learn the skills of their trade and apply them on whatever plot of land they're required on.


问:
I still can't figure out how to program?
I've read lots of books for various programming languages, Java, Python, C, etc. I understand and know all of the basics of the languages and I understand algorithms and data structures. (Equivalent of say two years of computer science classes)

BUT, I still can't figure how to write a program that does anything useful.

All of the programming books show you how to write the language, but NOT how to use it! The programming examples are all very basic, like build a card catalog for a library or a simple game or use algorithms, etc. They dont't show you how to develop complex programs that actually do anything useful!

I've looked at open-source programs on SourceForge, but they don't make much sense to me. There are hundreds of files in each program and thousands of lines of code. But how do I learn how to do this? There's nothing in any book I can buy on Amazon that will give me the tools to write any of these programs.

How do you go from reading Introduction to Java or Programming Python, or C Programming Language, etc.. to actually being able to say, I have an idea for X program? Is this how I go about developing it?

It seems like there is so much more involved in writing a program than you can learn in a book or from a class. I feel like there is something.

How can I be put on the right track?

答:
Have you played the game of Chess ??. One can teach you the moves, but making them useful is your own concern. You can't learn from a watching a chess game played b/w two individuals instead of playing yourself; Similarly learning from a single USEFUL project as you said, won't help. You need to delve into your own requirements and make a project out of it.

Every project has his own requirements. Seldom, you will find a project using all the features of the language. Therefore, the books focus on the basic features, rather than taking a project and reading out.

To be honest with you, I too searched for a working sample of WPF application when i had to make one few months ago. Found nothing and then read from the books and internet and got things rolling.

And the last thing is that these already made applications or projects make you more confused than ever, because they are made by professionals who have their own styling and tweaks. To get to that level, you need to forget about everything else and just start coding and later on StackOverflow is always there to help you out.

OwnerDisplayName: Mark K.


答:
Why not use Mono?

I have actually been successfully using Mono and .NET 3.5 on linux for commercial software for the past couple of years.  There is only a few things that are not fully supported by Mono.  However our team have generally made the best of it and we're extremely happy with the results.

Switching frameworks is non trivial

I personally know both Java (Spring MVC, J2EE, WebSphere, etc) and C# (3.5, 4.0, Castle MVC, ASP.NET MVC, NHibernate, etc).  The switch between using ASP.NET and Java is anything but trivial.

Pure code yes very similar and easy to switch between Java and C# (no Linq obviously, however there is functional java).

Loosing combined experience in .NET frameworks

However what you loose if you decide to switch is your combined experience with your current frameworks and will need to start from scratch learning a new framework.  Which will cost time and money in slow project velocity as your developers learn a new framework.

Evidence based scheduling just got a lot harder

This is the most non-trivial part of the equation, not only will you no longer be able to successfully calculate project dates as developers will not be able to judge if a portion of the project will work the way they want it to.  So you can expect that when a developer would say "If I was using .NET I would expect it to take X days with an accuracy rate of 80% either way.  But seeing as I'm using an unfamiliar framework perhaps that accuracy rate should be 160%".

Do your developers WANT to learn a new language/framework?

The key here is assuming that your current developers WANT to learn a new framework.  If not they may not give learning Java/J2EE  a good shot and would give up at the first sign of change or resistance to how they know how to do it in .NET.

Developers may decide to leave

If you don't have developer buy in, then you may end up with developers leaving completely.  Its sad, however that maybe the situation you'll be faced with considering that there is a pretty widely used open source alternative in Mono.


答:
I have the same problem

I have found that I have exactly the same problem with my personal projects.  I find that when I have inspiration I'll work diligently to the point of obsession for 2-3 weeks on a personal project and then when I've done quite a bit of work on a project and I hit a wall I'll loose all of that energy and loose interest.

The trick is to cycle through your projects

I find that when I drop a project due to a lack of inspiration or lack of ideas on how to proceed I'll regain inspiration later on (even 6 months on) and then gain another 2-3 week period of getting a lot of stuff done until eventually I get something working.

Wall E - Arduino Project (First Iteration was just getting Servos and soldering)

Wall E - Take 2 (took the Wall E toy apart and made him autonomous)

Wall E - Take 3 (Unfinished - Enable bluetooth to give him commands and switch modes)

Each of the Wall E projects were about 6 months apart, and I still have him sitting on my desk waiting for a bluetooth modem (need to figure out how to get it to fit inside the robot).

Android Projects / XNA Projects / Haskell Projects are pretty much all the same.  I find that if I loose interest and drop a project only to cycle back into it I'll eventually finish the project and gain a lot more than if I had only just dropped it.


问:
When is a loop "non-trivial"?
Is it correct to call a loop that you do not know the limit at compile time "non-trivial"?

If you know that you will be using a value from a class that will be in a range e.g. between 0-1000, is that still non-trivial?

e.g.
Where ISomeInterface.MAX_LIMIT is always between 1-1000:

```<code>public bool someMethod(Type someType, int someId, int someVariable)
{
    bool returnFlag = false;
    int maxLimit = (Activator.CreateInstance(someType) as ISomeInterface).MAX_LIMIT;

    for (int i = 0; i < maxLimit; i++) //is this a non-trivial loop?
    {
        if (_someSerivce.SomeOtherMethod(someType, someId, someVariable, i))
        {
            returnFlag= true;
        }
    }
    return returnFlag;
}
</code>```

Edit:
Was uncertain as to whether this was a meaningful piece of terminology.

I originally read it in one of Jon Skeet's pieces from yoda.arachsys: http://www.yoda.arachsys.com/csharp/stringbuilder.html (see the section headed Rules Of Thumb).

Do you use this as technical terminology at all?

答: I can't be sure, but trivial or non-trivial for loops have nothing to do with the range, but rather the increment. A for loop is "trivial" if it is executed at increments of 1, i.e., i++ in your case. The same loop is "non-trivial" if it is not executed at increments of 1, such as executing at every even iteration, etc.</p>

Title: When is a loop "non-trivial"?


答:
It's not a standard term. Personally, I'd consider a loop trivial if the test condition (2nd part) is a simple comparison of a value that changes only due to the counting expression (3rd part of for loop).

Here, the test condition is i < maxLimit (simple comparison on i) and the counting expression is i++ (same variable i). So, yes, trivial.

Title: When is a loop "non-trivial"?

Body:
Is it correct to call a loop that you do not know the limit at compile time "non-trivial"?

If you know that you will be using a value from a class that will be in a range e.g. between 0-1000, is that still non-trivial?

e.g.
Where ISomeInterface.MAX_LIMIT is always between 1-1000:

```<code>public bool someMethod(Type someType, int someId, int someVariable)
{
    bool returnFlag = false;
    int maxLimit = (Activator.CreateInstance(someType) as ISomeInterface).MAX_LIMIT;

    for (int i = 0; i < maxLimit; i++) //is this a non-trivial loop?
    {
        if (_someSerivce.SomeOtherMethod(someType, someId, someVariable, i))
        {
            returnFlag= true;
        }
    }
    return returnFlag;
}
</code>```

Edit:
Was uncertain as to whether this was a meaningful piece of terminology.

I originally read it in one of Jon Skeet's pieces from yoda.arachsys: http://www.yoda.arachsys.com/csharp/stringbuilder.html (see the section headed Rules Of Thumb).

Do you use this as technical terminology at all?


答: A loop is trivial if executing it takes up a trivial part of your program's execution time.</p>

Title: When is a loop "non-trivial"?


答:
This is coming from a developer who has worked in both the .NET and Java frameworks.

The ones who are getting upset and mad about this situation are either shortsighted, lazy, or just stupid.  Before I get downvoted hear me out, it is not because I feel Java is a superior platform to .NET, actually its quite the opposite.  The C# language is MUCH better and EntityFramework with LINQ is REVOLUTIONARY IMHO.

The reason they should embrace this decision is because having 2+ years of experience in both frameworks has opened up doors for me.  I can't go to the bathroom without head hunters pleading with me to talk to them about the pile of job opportunities that they have lined up.

When the job markets are 45% - Java, 35% - C#/.NET, and 20% - (PHP, Perl, Ruby, etc...) you have essentially qualified for almost 4/5ths of the available job openings at any given time.

And even if money isn't your chief motivator, then not becoming complacent is.  As soon as you start to feel comfortable that's when you NEED to shake things up and try something new.  People who can't bring themselves to step away from their comfort zone are either shortsighted or dominated by fear of the unknown and that isn't what I look for when interviewing developers.

Lets face it, I am working quite happily in Java now -- I am making good money and if this doesn't work out I have the security and peace of mind to know that I have a lot more opportunities then many others I will be competing with.  Do I miss C#? yeah, but in the end I got mouths to feed and am just trying to make my way.


答:
I've personally gone from Java to C# and back again to Java/Clojure so can really sympathise with your team. People naturally resist change, particularly when they fear that their hard-earned skills will become worthless or less valuable.

However there are plenty of positive ways to look at this:

Java and C# are actually, in the grand scheme of things, very similar at a language level. Not particularly surprising when you consider that C# syntax was largely based on Java (with various additions). Skills in one mean that you will become proficient in the other pretty quickly (took me only a couple of weeks to switch either way), and it looks good on your resume not to be seen solely as a "one technology person".

Once you get beyond the minor syntactic differences of the difference comes in using the different frameworks (J2EE vs ASP.NET vs. WPF vs. Swing etc.). However if you're developing a new HTML5-based stack you will probably need to learn new frameworks anyway. So is this really that big of a deal? I'd treat it as an opportunity to learn new ways of doing things that will make you a better programmer in the long run.

The Java platform is great and has a lot going for it. The engineering in the JVM is amazing, there is a fantastic ecosystem of open source libraries, the tooling is excellent (Eclipse, Maven, EGit are the ones I use most), you can write genuinely cross-platform solutions, there's a huge amount of innovation happening (especially in the framework and new-JVM-language space). Sure it's different from the Microsoft stack, but is certainly at least as good overall.

There are plenty of great things on the Java platform for people to get excited about. You're not tied to Java-the-language in the future. Example: Android, Scala, Clojure, are all areas of real innovation and opportunity.

Linux is a great platform to learn and work on. Your team might find it different and unusual at first if they haven't had experience before, but it has a lot of great things going for it. Surely every self-respecting developer can see the value in learning a new technology?

You also don't have to give up Windows - I personally use Windows as my desktop development environment of choice (with the Eclipse IDE for Java), but deploy all my applications with Linux on the server side.

Some advice if you do make the switch:

Keep It Simple and don't go overboard with all the "Enterprisey" Java stuff. It's fine if you're writing a banking system to last 25 years but probably overkill for most situations and will be extremely scary for newcomers. Instead stick to the more modern / simpler / more lightweight solutions. (Things like Vaadin for the UI, for example)

Consider Scala or Clojure rather than Java as the development language. Scala is more OOP, Clojure is more functional but both are a big advance on Java/C#. Both interoperate extremely well with Java (all libraries are compatible, calling to/from Java is very easy, they run in the same process / memory space etc.) so it isn't a problem if you mix this with some development done in Java in your company.

Get a good development environment set-up - the worst thing when making a switch is having a broken development / build system so that you don't know what is going wrong. Whether you use Eclipse or something else, make sure you have a real expert set up a best practice dev. environment so that your team members can be instantly productive / start learning without too much pain.


答:
```<code>for( int i = 0, k = 1, l=things.size(); i < k && l >= 0 ; --l )
{
   if( things[i] == things[k] )
   {
      things.doit();
      ++i;
   }
}
</code>```

This is a non-trivial loop.
It's harder to understand than most common ways to write it.

That said, here it's obviously obfuscated. I don't have real world example at hand.

Title: When is a loop "non-trivial"?

Body:
for( int i = 0, k = 1, l=things.size(); i < k && l >= 0 ; --l )
{
   if( things[i] == things[k] )
   {
      things.doit();
      ++i;
   }
}

This is a non-trivial loop.
It's harder to understand than most common ways to write it.

That said, here it's obviously obfuscated. I don't have real world example at hand.