this post was submitted on
26 points (100% like it)
26 up votes 0 down votes
all 51 comments

[–]kintar1900 24 points25 points ago

Hello, is-serp. I found myself in the same kind of situation about four years ago. If you're proficient in Java, the transition will probably be spent frantically trying to learn the new package layout (they call them Namespaces in C#), and familiarizing yourself with msdn.microsoft.com.

As far as frameworks go, here are the analogs I found for my favorite enterprise-y Java libs:

  • For me, Spring has been replaced with Ninject. It's stupid simple to configure with a fluent API instead of the XML nightmare that is Spring (or at least, that Spring became for me). If you're doing any AOP with Spring, Ninject can handle that, but be sure you understand the way C# and the .NET CLR handle virtual members. (Everything's virtual by default in Java. NOTHING is virtual by default in .NET)
  • If you don't like Ninject, StructureMap is very powerful and very popular, and also has a Fluent API.
  • Hibernate has a sibling project in the .NET ecosystem called NHibernate. It started as a direct port, and works almost exactly the same. I highly recommend the FluentNHibernate project for configuration, though. It dumps all of the XML files and replaced it with a type-safe fluent API. (Are you sensing a pattern yet? LOL)
  • If you consume web services, PLEASE, for the love of all that's holy, learn how to use the ChannelFactory and ClientBase classes directly. DON'T use VisualStudio's "Add Service Reference" wizard unless all else fails. It'll be a pain in the ass to begin with, but you'll save yourself hours of configuration misery in the long term.
  • If you expose web services, WCF is great, but a little fiddly to learn how to use unless you're hosting it inside IIS. I can provide more links on that topic if it's relevant.
  • If you're using Ant for your Java builds, NAnt is a direct port. Honestly, though, I'd recommend investigating another build system. There are a few good ones out there. UppercuT is my current favorite, although it can be a little binary-heavy depending on how you use it. If you're comfortable with Ruby, the Rake build system works well with MSBuild and .NET in general.

Last but not least, NuGet.org is a godsend. It's a library package and dependency management system that just came about within the past two years. It does for .NET everything that Maven and Ivy were supposed to do for Java, but in an elegant, reliable, so-simple-a-chimp-can-do-it manner.

Good luck! I was a Java developer for eight years before my forced switch. I've been in the .NET world for a little over three years now, and I actually wince when I have to look back at Java code. My last piece of advice: Learn C#'s lambda syntax early, and read up on the LINQ extensions to the collection classes. Between those two pieces of syntactic sugar, you'll probably get addicted. :)

[–]kintar1900 18 points19 points ago

Oh, one last thing: The Global Assembly Cache (GAC) is evil incarnate. DO NOT USE IT until you understand it thoroughly, and have a sincere desire to drive yourself mad. Keep packaging your libraries yourself in the project directory. Just...trust me on this. :)

[–]joshlrogers 7 points8 points ago

As a career .Net developer, I concur...

[–]John_Fx 5 points6 points ago

The sole purpose of GAC is to appease people who are nostalgic for DLL Hell.

[–]darkpaladin 3 points4 points ago

Haha, I have a professional rule I follow regarding the GAC. If you think you need it, you don't.

[–]jerkimball 1 point2 points ago

Lol...I'm actually rolling in a pre commit hook to try and detect/prevent references from the gac....

[–]doomchild 0 points1 point ago

Ye GODS is that the truth. I've never been able to find a good answer as to why the GAC was created in the first place.

[–]grauenwolf 0 points1 point ago

It's a good place to put OS-level dlls like System.Drawing.

[–]tpa 2 points3 points ago

Other popular (code only) dependency injection frameworks: Autofac and StructureMap.

You don't need Fluent NHibernate anymore if you want to use code only mapping. NHibernate 3.2 has built-in support. Syntax isn't as good and documentation is lacking but otherwise it works.

I wouldn't recommend using plain WCF if you need to offer tru RESTfull interfaces. Luckily there is WCF Web API which is really good at that. All the power without any of the hassle (configuration, proxies, bindings).

[–]darkpaladin 1 point2 points ago

I prefer MVC endpoints for web services these days. Unity and Castle Windsor are solid IOC Containers that have a DI side to them.

[–]captainjeanlucpicard 0 points1 point ago

Www.servicestack.net for REST > WCF any day.

[–][deleted] ago

[deleted]

[–]tpa 0 points1 point ago

Errrr? I linked to WCF Web API and you mention the WCF Web API that comes with ASP.NET MVC4. They are exactly the same thing. They are actually merging those projects so that once ASP.NET MVC4 is released it will contain the WCF Web Api out of the box.

[–]MondoHawkins 2 points3 points ago

This just about sums it up. I'd only add that there are .net ports of many popular Java libraries. They almost always have an "N" at the start or their name. (eg. NUnit = JUnit, NHibernate = Hibernate, etc...)

[–]vplatt 2 points3 points ago*

Wow... so a lot of this depends on the environment one is using and the architecture/solution architect. The recommendations above are good, but they really scream "trying to be a Java architect in a .NET environment".

In my experiences, the core technologies and tools you're going to want to use besides Visual Studio aren't like that. In particular, if you have the choice, I would look into the following:

  • Microsoft MVC (as opposed to Web Forms in ASP.NET) & jQuery
  • Entity Framework (or another great ORM tool such as Telerik's, EntitySpaces, etc.)
  • LINQ (in conjunction with EF/database access and otherwise)
  • WCF
  • Team Foundation Server (especially for source control) - you could always use Subversion or maybe even git (which I haven't tried), but if your shop is moving whole-hog on to .NET, then it's a good option

Besides that though, you haven't really given us enough information. Are you the architect for this and will you have a choice between frameworks? If not, do you know what frameworks you'll be using? Hell, you could be doing .NET on Linux with Mono for all we know.

[–]kintar1900 0 points1 point ago

Just a couple of rebuttal points:

  • Entity Framework : One of the downsides to EF is that you can't use plain old CLR objects (POCOs) as your domain models. You're tied into the classes that EF generates for you. With NHibernate and other OSS-based ORM solutions, your domain models can be retroactively wired into a database without any changes except a liberal sprinkling of "virtual" keywords to support dynamic proxying. In addition, changes to the database or business logic are exceedingly easy to manage since you don't have to re-generate DAO classes every time you turn around.
  • TFS : Why would anyone ever use a for-pay source control and CI system when there are so many proven OSS alternatives? (Unless your company is paying for a fully hosted and managed solution, that is. If that's the case, more power to you!) Git or Mercurial are both free and awesome DVCS systems, and I've never met a developer worth hiring who didn't have at least some exposure to SVN. If you're after it for continuous integration, I highly recommend looking at TeamCity or CruiseControl.NET. They're both well supported by the community, and have hooks into every major version control system.

[–]LHCGreg 1 point2 points ago

Newer versions of EF (4.1?) support POCOs.

[–]vplatt 0 points1 point ago

Re: EF - That criticism would have been fair a version ago. But you miss out on other low hanging fruit you could criticize instead, so ... I guess we'll leave it at that. EF is hardly the worst one could do where an ORM / DAL is concerned.

Re: TFS - As far as pure VCS concerns go, I agree. However.... TFS provides many more capabilities than just that. You certainly can get to CI with products on type of FOSS solutions but.... most shops won't. It's just that simple. 80% or more them just won't in my experience. If you're living in FOSS nirvana and have never used TFS, and have never felt the lack, then my hats off to you - but it will be the exception by far.

[–]48klocs 1 point2 points ago

AutoFac is another popular DI framework.

For data access, Entity Framework is the current hotness. I say "current" because Microsoft can't make its fucking mind up about data access strategies. Well, for more than a couple of years at a time.

[–]brangles 1 point2 points ago

That article is over 10 years old and still relevant tiday.

[–]48klocs 1 point2 points ago

For the concept of fire in motion in business strategies as well as the "best practice" data strategies that Microsoft would rather you forget about like so many used condoms.

Rest in peace, ADO.Net and Linq to SQL. Entity Framework, your clock is running.

[–]xTRUMANx 2 points3 points ago

Sometimes I feel I'm the only guy left writing ADO.net code and not hating it.

[–]jared84lsu 0 points1 point ago

I'm right there with you; I've got some Linq sprinkled in there now and then, but I'm not a big E-F guy yet.

[–]xTRUMANx 0 points1 point ago

YAY! I'm not the only one.

I've been thinking of showing off a little SqlClient helper library I wrote which allows me to write code like the following:

public Branch GetBranch(string id)
{
  using (var connection = new SqlConnection(ConnectionString))
  using (var command = new SqlCommand(connection)
  {
    command.CommandText = "SELECT * FROM Branches WHERE BranchId = @id";
    command.Parameters.AddWithValue("@id", id);

    var branch = SqlClientHelpers.GetItemFromReader(command, readerToBranchMapper);

    return branch;
  }
}

public List<User> SearchBranches(string searchText)
{
  using (var connection = new SqlConnection(ConnectionString))
  using (var command = new SqlCommand(connection)
  {
    command.CommandText = "SELECT * FROM Users WHERE Name LIKE @searchText + '%'";
    command.Parameters.AddWithValue("@searchText", searchText);

    var users= SqlClientHelpers.GetListOfItemFromReader(command, readerToUserMapper);

    return users;
  }
}

The library would start a try-catch block, open the command's connection, execute the query, fill any type of object with the data in the SqlDataReader based on the mapper which is a Func<SqlDataReader, T>. Here's an example mapper:

Func<SqlDataReader, Branch> readerToBranchMapper = reader =>
{
  var branch = new Branch();
  branch.BranchId = reader["BranchId"] as string;
  branch.CreditLimit = reader["CreditLimit"] as int?;

  return branch;
}

The cool thing is with this approach is that I've found myself filling in the same type of object in several methods at times so extracting out the mapping from SqlDataReader to my domain object really reduced the line count of my repository not to mention that I've also extracted out the rest of the boilerplate like the try-catch block, connection opening and command executing which I would have had to written in every method in my repository.

The only thing one needs to do is fill in the catch with whatever exception handling you need. Personally, I don't have a catch in the library itself and instead to choose to handle it elsewhere in my application.

There's also a SqlClientHelpers.ExecuteNonQuery(command) helper which lets you execute a stored procedure in one line rather than the 6-10 lines it would have taken with the necessary safety procedures (try, open connection, execute sproc, catch, exception handling, finally, close connection).

Doesn't any of this of any interest to you at all?

[–]captainjeanlucpicard 0 points1 point ago

No.

[–]filterspam 1 point2 points ago

ADO.net is under everything.

[–]xTRUMANx 0 points1 point ago

If you consume web services, PLEASE, for the love of all that's holy, learn how to use the ChannelFactory and ClientBase classes directly. DON'T use VisualStudio's "Add Service Reference" wizard unless all else fails. It'll be a pain in the ass to begin with, but you'll save yourself hours of configuration misery in the long term.

Can you expand more on this point? I recently had to use the "Add Service Reference" menu on a project cause my manager felt it was the simplest way to get two of our apps to communicate. I've since removed it since I kept encountering exceptions due to having a some max file size config value too low. Although, I'd like to have some better more solid reasons to give him next time he asks me to "infect" my projects with service references.

[–]kintar1900 2 points3 points ago

Using the WCF framework typically is the easiest way to get two .NET apps to communicate for any non-trivial exchange of data. My issue is with the boatload of XML the wizard adds to your app.config file.

Whenever you use "Add Service Reference", all of the configuration data is written into a section of the app.config. The configuration is exceedingly verbose and, since it's in XML, can't be altered at run-time by your application. In practice, you can typically replace the 10-15 lines of XML the wizard generates with 3-6 lines of C# code.

And for the error you were hitting...was it something about an array length quota? To configure those, there's an XMLQuotas property on the binding object. For internal apps where I don't have to worry (as much) about malicious users hitting the service, I typically set it to int.MaxValue. ;)

[–]grauenwolf 0 points1 point ago

I use it as a stepping stone. After I generate the proxies for the first time I manually strip out all of the garbage.

[–]Aljavar 0 points1 point ago

Ah.... Exactly.

[–]hoppersoft 7 points8 points ago

I recommend Jeffrey Richter's CLR via C# and John Robbins' Debugging Microsoft .NET Applications (says 2.0, but it's all applicable to 3.X/4.0 as well)

[–]myevillaugh 2 points3 points ago*

I highly recommend CLR via C#. That will give you an in-depth understanding unrivaled by any other book. Effective C# will help steer you around the gotchas.

[–][deleted] 1 point2 points ago

Came here to say this. CLR via C# is a bible of sorts, and Richter is a windows god.

[–]Dullbert 6 points7 points ago

Whatever book you read, once you have any questions ask them on StackOverflow.com . It's a very helpful community with an awesome platform. It's easier to post your questions there, and most .NET related stuff is answered within a few minutes (if it isn't answered already). MSDN is ok too, but I only bother going there if StackOverflow can't help me for some reason.

[–]ElGuaco 5 points6 points ago

Use generic collections and learn to use LINQ pronto.

Read Jon Skeet's book called "C# in Depth".

[–]grauenwolf 3 points4 points ago

A must read is .NET Framework Design Guidelines. This explains the theoretical basis behind how the APIs are constructed and how you should write your code.

[–]N7-Legion 4 points5 points ago

Lots of great things in this thread. One thing I would say is that don't get stuck using MS-provided tools and libraries. A lot of them are good but there are, in some cases better, alternatives. The problem is that most of the samples/documentation that you will see will be based on MS technologies since that is what most people use.

Here are a couple suggestions:

  • Web Framework - Definitely go with ASP.NET MVC. There are alternatives like OpenRasta, Nancy, ServiceStack as well.

  • ORM - Personally I am not a big fan of Entity Framework but it's good enough for most uses. I would look into Micro-ORMs such as Massive, PetaPoco and Dapper though if your needs are simpler or performace is critical.

  • Unit Testing - MSTest sucks. Use mbUnit or xunit.

  • IoC/DI - Autofac, Munq are both pretty good (and fast)

There are a bunch of other tools (MSpec, ELMAH, Moq, etc.) as well but the bigger point is that the .NET ecosystem is not just MS-centric. Unfortunately too many people don't know this and just use whatever tools that come out of MS without doing any research. Don't be one of those guys.

[–]N7-Legion 2 points3 points ago

Oh and bookmark these blogs. These guys basically put togehter a daily digest of sorts.

[–]kintar1900 1 point2 points ago

Unit Testing - MSTest sucks.

It's actually pretty good if you use ReSharper, but that's an expensive tool. My preferences are NUnit and MSpec.

...but the bigger point is that the .NET ecosystem is not just MS-centric. Unfortunately too many people don't know this and just use whatever tools that come out of MS without doing any research. Don't be one of those guys.

This. A thousand times this. Microsoft has come a long way, especially in the past two years, and they make some excellent tools. But .NET developers who limit themselves to Microsoft tools and frameworks are basically joining a footrace while wearing a potato sack. :)

[–]Randolpho 2 points3 points ago

There's little I can add that kintar1900 hasn't mentioned; I can't recommend many good books because books on the subject of languages and platforms are so invariably behind the times that they're worth very little, IMO. Online resources -- particularly asking good questions on StackOverflow -- are more likely to be your friend.

Start with MSDN and hit blogs on the subject from folks like Scott Guthrie, Phil Haack, and the folks at DotNetSlackers or DotNetKicks. Good luck with that.

But as an enterprise architect myself, and even though I'm a huge fan of the .NET stack, I have to heavily question the decision to switch platforms. If I were you I'd fight back on that decision -- you're not going to replace your system in "a couple of months" unless it's a really, really simple system.

I obviously don't know your architecture or your company's political culture, but I'm betting (heh) that you could probably swing a gradual shift, tier by tier.

[–]BrianScott1980 1 point2 points ago

Totally, Scott Guthrie is Mr .Net and one of the main reasons that many of the highlighted frameworks are so well adopted in the .Net ecosystem.

[–]zingbat 1 point2 points ago*

Download this free book by Rob Miles - Its a great starter book that covers .net and C#. Including things like generics and LINQ.

http://www.robmiles.com/c-yellow-book/Rob%20Miles%20CSharp%20Yellow%20Book%202009.pdf

EDIT: He also has a free book for Java developers switching to C#

http://www.robmiles.com/c-yellow-book/C%20Sharp%20from%20Java%20Orange%20Book%202009.pdf

[–]xTRUMANx 0 points1 point ago

That link goes to the 2009 pdf. If I'm not mistaken, there's also a 2011 version of the book.

[–]zingbat 1 point2 points ago

Sorry about that. You are right..there is a 2011 book

I had the 2009 one still bookmarked.

[–]xTRUMANx 1 point2 points ago

Kinda off-topic but what would you recommend to a .net developer trying to get to know a little more about Java?

[–]kintar1900 1 point2 points ago

Not to be pithy, but pretty much the reverse of what we've recommended to the OP, I think. :)

What kind of .NET developer are you? Web apps? Desktop/WPF? Core services? The OP said he/she was a system architect, so that gave us a little information on what kind of frameworks could be recommended. Give us a little info about your interests and job experience, and I'm sure someone around here can throw out a few good suggestions.

[–]xTRUMANx 0 points1 point ago

I mostly build asp.net mvc websites and windows forms applications.

Let's say my goal is to build a simple GUI crud application in Java. I don't really care about the app I'm building, I just want to experience developing Java apps in an IDE.

[–]is-serp[S] 1 point2 points ago

If you want to build GUI applications in Java, well don't :)

If you want to do the same as what you're doing at the moment (i.e. MVC applications) I would recommend learning Spring MVC. Documentation is pretty good.

If you want to learn Java from scratch I would recommend the Oracle Java tutorials, these book for learning Java from scratch Core Java Vol. 1 & 2, and then this book to learn how to use Java properly Effective Java. Once you get familiar with the different java technologies (so you know what's happening under the hood once you get to the more high level stuff) such as Servlets, JMX, JDBC, etc. I would recommend you start getting familiar with Spring Framework, either through their documentation or else this book Spring in Action. For CRUD operations, my suggestion would be to learn JPA 2 (maybe this book) and use that in your code (so you don't really depend on a specific library), and then choose an implementation such as Hibernate or Oracle JPA.

Other stuff that you should look at are the Google Guava library, and most of this Apache Foundation Java projects.

If you have more specific questions, feel free to ask, either via PM or here :)

[–]xTRUMANx 0 points1 point ago

Thanks for the info.

Back in university, I hated programming and I account that for a lecturer who taught us to build swing apps on notepad. I have no idea how I passed those classes.

The only reason I suggested a gui crud app because I wanted something simple where I could experience typical java development like creating classes, using some 3rd party packages, connecting to a database and let's not forget the factory factories.

I've already built some simple console apps on a text editor and tried out the basic programming idioms found in every oo language. Do you think it's best for someone like me to skip to Spring?

By the way, I read a while back that Heroku supported Java. Can a Spring app run on Heroku? Their example tutorial uses servlets and xml and maven and it's all going over my head.

[–]is-serp[S] 0 points1 point ago

I don't know about going directly to Spring. Although I use Java and will switch to C#, I am a low-level guy at heart so am much more comfortable knowing how stuff works under the hood so I can debug when I have problems. I guess it's up to you and your level of expertise and what you want to achieve. You can maybe grab the Spring in Action book I mentioned above follow the example application to get some hands on experience.

The good thing about Spring is that it encourages good software practices such as low coupling etc. so you should be good.

I would assume that a Spring app will be able to run on Heroku since it's just a standard app with an IoC (and more) container set up.

[–]alphabeat 1 point2 points ago

It's handy writing Android apps that's for sure.

[–][deleted] 0 points1 point ago

Dunno if you're a fan of Minecraft, but decompiling it and messing around with the sources is a great way to play with Java, while getting instant gratification from your experimentation.