I have inherited a really awful webforms application that is all kinds of bad--an untestable hairy mess of datasets and Page_Load events. Object oriented? N-tier? Unit tests? source control? All academic niceties to the team that built this mess.
It started life as an asp classic app, got mostly ported to VB.NET. Management denied my request to "nuke the entire site from orbit" and start over.
[Insert discourse on how ASP.NET MVC is absolutely, positively the only sane way to to .net websites anymore]
I know we might be able to interoperate between the legacy webforms and mvc. The question is, can we leave the legacy code in VB and build the new stuff in C#? I want to force the conversion to C# so the team doesn't fall back into bad habits.
Is there an MVC 2 Areas strategy that we could use here?
I'm not surprised the idea of a total rewrite was shot down. In general that is a recipe for delay and more bugs, regardless of how buggy the current project.
As far as I know it depends on the kind of project. If the existing project is a web application then no you can not. You could reference external libraries built in C# due to the CLR, however, you will not be able to bake C# code right into the project. This is done all the time and is mostly acceptable.
If the existing project is a web site project then I would have to say yes you can. However, you should not willingly do this unless there is an absolute need to do so. This is just asking for a difficult to maintain project and essentially requires you to do a lot of management in the web.config. I would strongly advise against doing this.
site reference: http://timheuer.com/blog/archive/2007/02/28/14002.aspx
I think you should be able to put this method together with those from the Google search mentioned by an earlier poster. Its going to take a bit of work though.
Additionally, coding practices are pretty much entirely unrelated to the language and from my experience working with mostly web forms and a little MVC, both have their time and place. I would look at laying down a set of practices that must be followed and enforce them using code reviews. Any new code you write would be kept clean and tight while you can also update old code to use standards.
I'm intrigued by your implication that the team's bad habits are caused by use of VB. There are plenty of bad habits in any language: the trick is not to switch language, but to learn good habits.
Anyone's post about this kind of thing is going to be opinion - and in my opinion you'd be better off teaching them to program properly in VB than making them learn a new language that they may struggle with. I've seen great, stable, maintainable VB code and I've seen horrendous, messy C# code. Try not associate a programming language with the quality of output of a team that happens to be using it.
(For the record, I develop in both VB and C# and would always choose C# given the choice - but not because I think I write better code in C#.)
It is possible, essentially by making all the views, etc. in the MVC project embeddable, adding it as a reference to the VB.Net project and then registering the routes.
It's a bit more complicated that that, Matt Honeycutt has a series of posts roughly outlining how he did it here:
http://trycatchfail.com/blog/post/ASPNET-MVC-3-Razor-C-and-VBNET-WebForms-A-Tale-of-Black-Magic-Voodoo.aspx
Related
I am trying to refactor my code by migrating a "Web User Control" which has become quite complex into a separate standalone "Server Control" project. Moreover, the control also has some javascript logic inside it.
So, I would like to get some advice on :
How and where to put (migrate) the existing javascript logic from the Web User Control?
How to logically and cleanly separate existing javascript for ASP.net pages? Any directory structure suggestion will be highly appreciated.
Please bear with me because I am a very beginner.
Kind Regrads
The answer to this question is long, complicated, and varies from case to case. Still, having worked on codebases like this, here are a few things I learned:
write tests: essential to any legacy codebase. you must write tests before changing your code. If it's as tightly coupled as you say then not writing tests will give you hell 2 months into the project when small side effects of your changes begin to creep into production.
make javascript Unobtrusive: put all javascript into .js files, away from the server and away from the structure. this way you'll have one less thing to worry about when writing your server side code.
divide and conquer: this is probably the best tip anyone can give you. I once worked on a project that had 5000 code line files, with html, javascript and visual basic all mixed in one ugly mess. There I learned that by extracting these mega classes into 100-line files, I could better understand the intent of each block and easily find dupes.
have a BA handy: sometimes a whole web page / class is so mangled that rewriting portions of it is the only way to bring it back to a maintainable state. Having someone who can explain the business logic is really important especially under these circumstances since they can tell you what a class is supposed to do, why it does it, and what parts are obsolete. In this same project I was talking about, we started rewriting certain pages. Having a BA there with us allowed us to remove around 30% of the code, since it was obsolete. having 30% work to do on a 250 thousand line codebase is really useful, especially when a deadline is looming.
don't use web controls, use html / jquery and handlers: asp.net web controls don't play nice with web standards. They don't play nice with ajax and the don't play nice with SPA oriented approaches. If you're refactoring towards this, replace web controls with their html input equivalents, then use javascript (jQuery, ext/sencha, dojo, etc) to add the desired behaviour. on the server you can then write handlers that can be called with AJAX.
you shouldn't do it alone: you should be part of a team that has an architect that sets the roadmap and patterns to use; a frontend developer that knows javascript, html, and some .Net; a backend developer that knows c# and .Net, aswell as SQL Server or the database technology and a designer that knows html5 and css, so he can propose better ways of structuring the documents.
you probably shouldn't be doing this at all: if you're a beginner like you say you are you should be working on properly made web projects and learning how to write correct code. I certainly don't mean to insult you, but this is a monumental task, with lots of complexities and tons of pitfalls. These projects are normally apps developed by VB6 programmers getting onto the web bandwagon as quickly as possible in the beginning of the past decade, and as a result have lots of procedural code copied and pasted into multiple classes and quirky ways to do things, as if the coder knew not much about OOP (and let's face it, most VB devs don't or didn't at least when ASP.net first came around). The person in charge should be a seasoned ASP.Net developer with solid understanding of modern web technologies and desirably experience in bringing a legacy project up to speed with the latest industry standards.
Probably sounds a bit stupid but I'm getting confused moving from Classic ASP to ASP.net.
After looking at the two different variants of the language, VB or C#, I have decided to go with C#. I was reading another StackOverflow answer that explained moving from VBScript to C# was easier to learn coming from VBScript.
So, I thought I'd hit W3schools to learn some basics on C# but got confused when I was given the options; Web Pages, MVC or Web Forms. Would somebody please explain the differences and which one would suit me best?
I have been coding in classic ASP/VBScript for many years, building all kinds of web application, some big, some small, and I do not want to use any software like Visual Studio, I just want to write code. I currently use Dreamweaver just for coding.
For a move from classic ASP to a .NET web platform, I would suggest going with ASP.NET/MVC.
WebForms are an abstraction that was created to make VB6 programmers comfortable with working on the web and it is a very leaky abstraction. It uses an event model and an idea of PostBacks that simply is not part of how the web really works. It has limitations that will not be familiar or make much sense at first (you can only have one form on a page, for example). As such MVC will be much more familiar.
I suggest that you watch this video by asp.net official developers as well as other relevant videos at the migrating section
Here's another good video produced to help programmers to choose the programming model (webforms, webpages or mvc, tools, etc)
Although w3schools has several good examples, it has several inconsistencies as well as incorrect information. Good alternatives for w3schools include MDN and IE Reference API (as the name implies, it's aimed to IE, and it's a good reference for when something works in other browsers but not in IE)
First, let me ask you to consider this as a real question, and not a subjective one.
That out of the way, here's my situation: We are looking to port our existing classic ASP application to .NET, but we're unsure of what language to use for the new app.
I personally would 'prefer' C#, as I'm more familiar and comfortable with that languages way of doing things, but, the original code is VBScript, so it would possibly be easier to port to VB.NET ... One possible situation I fear would be that, because the code is so similar between the two variants of VB, that we might end up getting stuck on something that is not similar between the two, even though it looks like it would work. A shift to a wholly different language might avoid that kind of situation.
Does anyone have any practical examples of this kind of situation? Insights to illuminate the issue with? Do the potential benefits of a complete paradigm shift outweigh the gains from a high degree of 'copy-and-paste-ability' ?
I have used C#.NET and just recently learned VB.NET and I have to say that once you get around the small syntactical differences, VB is also a very good language. So for you, this is a win win.
That being said, I think a syntax change will help protect the project from any careless copy pastes from the old dirty code base. I believe a fresh start with a fresh language is your best bet for a top notch re-write.
There are 10X as many questions re: C# as there are VB.NET on StackOverflow. That seems to indicate there are more developers using C#, or perhaps a more thriving community (or maybe it just means C# is harder or C# developers don't know as much).
Any gains made due to the similarity of VBScript to VB.NET are far outweighed by the fact that you need to learn the new data types, .NET namespaces, and a new style of web development using webforms or MVC (my preference).
For this reason I think the choice of language should be made independently of what was used before.
3 years ago I had to make this same decision. My preference would have been C# but we ultimately went with VB.Net because that was the closest language available to the developer base we had. All of the developers had experience with VBScript, so learning VB.Net was easier for them. While the framework is the framework and the rest is just syntax and best practices, you'd be surprised the difference in learning curve just by adding a few curly braces for VB developers (the reverse seems to be exactly the same for C# developers going the other way with an itchy semi-colon finger, learning new keywords and relearning event syntax).
You should look at your developer pool and consider what is the easiest for your team to perform development and maintenance. If this is not a serious criteria (because the developers are proficient equally in both), then I would recommend a C# approach. The primary reason is that the VBScript will be relying on outdated methodologies, but converting to VB.Net will not necessarily throw exceptions for these methods whereas C# will. It will also force you to touch every aspect of your application, which (while tedious) will provide your team an opportunity to evaluate how older methods may be refactored into more efficient processes.
Just keep in mind - the "easiest" seeming solution seldom is.
When moving to ASP.NET, I believe that less focus needs to be on the page itself, and more on how you're going to write the business logic. This is a subjective question because different units will have different results.
That said, always play to your strengths. If your team is more familiar with C# than VB.NET, use C#. If they're more familiar with VB.NET, use VB.NET. If they have no real .NET Experience, then you probably want to set up some sample projects with which they can play to see which will be easier to learn. You want the most bang-for-your-buck, and that means making sure the team is as comfortable as possible.
Further, I wouldn't worry too much about copy & paste code, as there are enough differences that any professional developer (as in one who acts professional, not just one who gets paid) will see how much he/she is changing and go back through the rest of the code to ensure it is working properly.
The difference between an ASP.NET and Classic ASP application is already so big, that it will not be an easy copy/paste port anyway.
So I think you should go for the language that you feel most comfortable with (and as another answer suggests, there is a much larger community using C# than VB.Net).
Why are you rewriting the application? What are the short and long term objectives you hope to achieve through this change?
At a high level there is not much to choose between VB and C# - both are extremely functionally rich labguages that compile to teh same IL code.
Personally I moved to C# a few years ago because the vast majority of code examples found on the net are in C#, and the programmer's best friend is the internet where you may just find that nugget of useful information that save you hours of head scratching.
In your situation, by fircing yourself to rewrite the code in a different language will force you to possible rething the implementation and therefore review carefully the code and functionality required - if yuo have the time and budget. If you are up against tight deadlines then VB would be the natural choice, but may negate the benefiots if the rewrite.
I have been in exactly this position, and I urge you not to translate the app in two ways at once--from VB to C# and from classic ASP to ASP.NET.
You have chunks of business logic in your code that will not need to change much, so why change it? You are guaranteed to introduce new bugs in the translation.
I can't count how many times I thought, "this looks exactly the same, why isn't it working?"
Just adapting your code to the new codebehind pattern will be challenging enough. A vast and worthwhile improvement, of course, but not trivial.
VB.NET and C# are so incredibly similar that technically the choice is almost irrelevant. Each language has some minor things they excel in, but overall, the two are practically identical, just with wildly different syntax.
With that said, I highly recommend going with C#, just because it's the language the .NET community really got behind. It will have the most books, websites, blogs, forums, you name it. Not having to translate the oodles of examples out there on the net into VB.NET alone makes C# a better choice. I think in my 10 years of being a .NET developer, I could count the number of people I've ran into that genuinely chose VB.NET on one hand. Most people that are using VB.NET are using it in a "stop gap" fashion, with the intention of ultimately going to C#.
Many people go for C# because they think that VB.Net and C# is only syntactically different which is just not true. VB.Net has better features for handling interactions with COM components for example, like optional parameters (these are now available in C# 4.0). But there are catches too in a line by line conversion of VB to VB.net. A very simple example is the array index. If I'm not mistaken array indexes start from 1 in vb and in vb.net it starts from 0 which causes horrible bugs. Overall, I'd definitely consider going for VB.Net even though I work basically in C#.
I think I'm leaning toward C# and .net as a concentration language for learning web development. I would like to learn good programming fundamentals and I've looked at pretty much everything else. The four I've narrowed it down to have been C#, Python, Ruby and PHP. Is there a reason to stay away from C# (and I don't think the cost issue would really apply to my solo-developer situation but I could be totally wrong). Any thoughts?
I realize that these are all great languages so I'm not trying to ask which is the best overall. However, would Ruby be a viable alternative for a first language or does it have too much "magic under the hood" coupled with Rails, and unorthodox methodologies? I do like what I've seen with the language.
This is likely to result in a flamewar but I think C# is a pretty good language to start with for Web Development.
It is a full featured object oriented language and is statically typed and compiled. It's very well documented and has a huge developer community.
If you absolutely have to run on Linux/Apache and do not want to use Mono, that would be a reason not to use C#. Other than that, I don't think there is a compelling reason not to, particularly with ASP.NET MVC, which lets you move away from the WebForms model.
This is not to say that WebForms is necessarily bad but some might object to WebForms as it introduces abstractions that are not inherent in other web development platforms.
If you go with C# for web development, depending on your experience with web technology, I'd heartily recommend starting with ASP.NET MVC before ASP.NET Web Forms.
ASP.NET Web Forms is the original style of building ASP.NET applications, and tries to abstract a lot of the details. It allows you to build applications without realising what's happening under the hood (post data, state management). In my opinion, these abstractions although making things easy at first begin to "leak" when you get into more complicated scenarios (as this tutorial proves).
ASP.NET MVC on the other hand makes it easier to build web sites that are a lot "closer to the metal" while still keeping you productive. If you want absolute control over the resulting HTML and aren't afraid of things like cookies, form tags, post and query string data, then you might enjoy ASP.NET MVC a lot more.
Of course it would be beneficial to know both. But if I was starting now, I'd probably start with MVC and move to Forms (then realise how bad it is and move back :)).
There are no "best language over all". You use one tool for the purpose it has been made, that's why there are several tools.
Since your question is "why not learn C#", I'd say :
If you plan to work with other OS then Windows (Mono cannot compare).
If work in an env or with people not .net friendly (e.g : bank, scientists)
If you work in an env or with people that are expert in another good tech (never underestimate the use of a good master).
If you think Free Software matters so much that using a MS product is not worth it.
If you don't like MS Visual Studio (working in c# without a good IDE is a pain).
If You plan to program something that .net is not suited for (e.g embedded devices, scripting, real-time, fault tolerant system, AI, etc).
If you are a web dev and can't afford a Windows Server Licence.
If you want to learn programming with the very basics, including simple functions and quick and dirty scripts.
Now, I program in Php, Python, Java and C#. Python is my language of choice, but c# is really the first MS programming tool that seduced me : it's clean and efficient. Really, it's about what you want to do, not a question of religion.
Make YOUR choice.
That's said, C# sucks and Python rocks.
I agree C# is a pretty complete language, it's syntax is clean and extensible. There's a huge amount of web resource already available, but and it's a big but, it effectively ties you to windows as your platform. For web especially that's an important consideration. On the desktop windows is king, but for web servers the market it isn't nearly so dominant.
Another side issue, if you're looking at rich media on the web you have to consider Flash and/or Silverlight. If you go C# then you're someway to using Silverlight without learning a different language.
Don't worry about the cost. The compiler is free to use, along with the rest of the Fx SDK, and you can even download Visual Studio for free.
The disadvantage to learning C# is that it ties you to a proprietary platform and software stack. Now, there is Mono, which does a good job of implementing much of C# and .Net, but the primary and most complete implementation is Microsoft's which is non-free.
I have not used C# enough to debate it's technical merits with respect to Ruby or Python. I can say, however, that learning to use and even contribute back to free software can be quite educational, in addition to the other benefits (discussed in length elsewhere) that free software provides.
c# is a good language to start with because:
It is a very good and very clean language
It has an excellent library (.NET framework). This is one of the most important things to consider when choosing a language.
It is very popular, you'll always be able to find the answer you are looking for from the community.
If you know c#, you pretty much know VB.NET.
c# is syntactically similar to Java. Learning c# won't teach you Java's libraries, but it will significantly reduce the learning curve if you want to enter the Java camp.
c# is syntactically similar to c++. Again, it uses a different library and unlike c++ you get memory management; but the learning curve should be somewhat reduced if you decide to play with c++.
As for the web...
ASP.NET webforms does a lot of magic for you. ASP.NET MVC (just released) does almost no magic for you. For learning, MVC is the better choice.
C# is a great language to use. And since you are using it via the web and not desktop applications for example, you don't have to worry about being multi-platform since the code is run on your server and the output delivered to the clients. With that said, you will have to find Windows hosting (which can sometimes be a bit more expensive) or use mono (which isn't exactly the most updated software out there). The downsides are minimal though, grab a copy of the express edition and go for it!
I think the cost of deployment might be a different thing, i.e. if your project needs to scale horizontally, and add more servers to load balance or even for geographically distributed servers. Usually the windows hosting will run a bit more than linux (without even considering the flame wars reasons).
C# is fine for starting if you are doing web development. However, I recommend that you don't start programming with web development. Web development is hard to get right. Way harder than little command line things. I recommend that you get some good experience programming for the command line, and then move up to GUI, and then move on to the web. The web has a whole bunch of things you have to worry about. You have to know 3 languages (HTML, JS, C#(or insert your server side language here)). Plus you have to worry about all the browser quirks and stuff. And that's without even getting into databases. Which is usually used in most web applications, but opens up a whole other can of worms.
Considering all the answers so far, I thought I'd look at all four languages mentioned.
While I've done a lot of development in PHP, and sadly continue to do so, I think PHP was never a great language (though it had a few great elements) and these days there's not much point picking it up. It remains extremely easy to get into but I think in general, PHP is a "bad habit".
Python is a great language, but to me, Ruby is all that Python is and a bit more. Personally I would go for Ruby.
C# is also a great language, but while I haven't used C# enough to say anything with confidence, I feel that Ruby is a better choice.
No reason in particular to stay away from C#. It's as good a language as any. Stackoverflow uses it for example, so it works on a successful website, and you can get jobs programming in it.
The proprietary thing would be a consideration if you were programming as a hobby or off your own limited budget, or you wanted to contribute to the development of the compiler/language. I'm guessing neither of these are the case. (Edit: as others have pointed out, open source environments for C# exist.)
It depends on a couple of things. C# and .Net is populate and th tools are really very easy (complared to Java! Java developer talking here...) but Windows Hosting is expensive vs LAMP (which include Ruby, Python and PHP).
For me it all depends on the tool that you want to use. For web services etc I would use C# but for a simple website PHP since its easy.
It also depends on the job market of your location... here in South Africa you get alot more C# jobs and not much PHP etc. Off course if your a freelance you will struggle to find work.
For me Ruby again is good for my own person stuff but you don't get any Ruby jobs here.
My advice? Learn the differences for yourself. Play around with both of them. If you have a project in mind, write a prototype for it in them. You'll always be at the mercy of other peoples' biases otherwise.
ASP.net (C#) and Ruby on Rails are used in high-profile sites, so you can't go too wrong with either one. Might I also suggest that you try out Python programming with django? It's what I tend to prefer for web programming.
I'm a C# .Net developer and I think it's great, but I'll highlight a danger in the Asp.Net WebForms. It is unlike the majority of other web frameworks and does A LOT of magic under the covers. As others have said ASP.Net MVC is probably more inline with other web frameworks (Rails for example). Web Forms abstracts a lot of the nuts and bolts of webdev away which If you want to be web developer you'll end up needing to know. So yes C# is great but I'd start with MVC and then look at web forms possibly. Also looking at other languages and frameworks is highly encouraged there's always stuff to learn.
Commercially I am a C# developer. I love C#. C# is a great strongly typed language. With Resharper installed I can build my ideas in code rapidly and flex it to my will.
When I go home each evening I use Ruby. Even though I have no refactoring support (snif.) I find I am much more productive in Ruby than in C#.
I worked writing a large ASP.Net application for a couple of years. We implemented MVC to try to detangle the view from the model. It always felt like I was fighting the framework, not working with it. The latest .Net frameworks for doing web application are based on Rails... just a couple of years behind. I love the language. I love the CLR. I'm not too keen on .Net.
I find the ruby community to be friendly and vibrant. The rails open source community produces loads of tutorials and plugins that make getting up to speed easy and putting your application together simple.
Another thing to consider (as far as choosing a language to learn) is that ruby is an Object Oriented language. Even classes are objects. C# is a Class Oriented language, ie. it provides you one way to create objects.. define a class first. (not totally true.. you can generate assemblies in memory using codedom.. but that is by no means easy).
This may seem like a subtle point, but there is a difference.. and until you get experience with an OO language like ruby or smalltalk it's not obvious what that is. Once you have felt the freedom of building objects by mixing in functionality at runtime etc. you find that all the 'work-around's you had to do in C# disappear. Not having the safety net of interfaces does seems scary at first.
In all, I'd learn ruby..
If you are new to programming (totally) I'd start with http://pine.fm/LearnToProgram/
Then I would learn BDD (RSpec) and get test infected as soon as possible.
Then I'd consume rails tutorials and screen casts until my eyes popped
The only problem is .. if you start with ruby then later go to C# you'll find yourself going "Aaaaagh! This would be so much easier to do in ruby" all the time. I know I do.
It really depends on what you are trying to achieve. I program in both and to be brutally honest, if you are trying to make a career out of programming, I get paid twice as much for .NET programming. The types of clients that I do PHP dev work for are not the types that pay a lot (PHP is often chosen based on saving some $$$). .NET seems to be much more entrenched in larger corporations.
Just my observation...
No disadvantages really except that you will be unwelcome in those social groups (and even geographical regions) that pose themselves against the "evil Microsoft".
The language (better .NET platform) is quite good. One important thing is that it is being very actively developed causing some people trouble keeping up. But I'd rather have rapid development compared to year-long stagnation.
You might consider checking what employers in your area prefer as a technology stack.
Considering licensing costs you can consider the following: If it is a small site you can use Visual Studio Express/SQL Server Express for free and it will be sufficient. If you come up with some major heavy trafficked project you will likely to find a way to make revenues and cover licensing costs.
Learning C# is great in 2009.
Way back in the day, when I entered the professional world, the language landscape was very different. I coded professionally in C and Modula 3 (Pascal replacement language).
My point is that I would plan for the technical landscape to change over time, and plan for that in your professional career development.
Learning multiple platforms is a great way to accomplish this. For example, you could have C#/.NET as your primary skill, but also work with JAVA. When a new platform emerges, you could add it as your transition or backup skillset.
I have been a web developer for my entire development career. Nearly 100% microsoft focused the entire time. I have been using .Net, both C# and VB.Net, since beta. I now find myself in a position to where I have the opportunity to start doing some WinForms development in C# using the 3.5 framework. As with anything new, I am excited about the learning opportunity in front of me.
I am curious if anyone has any suggested books, articles, feedback, etc on the topic of transitioning from web development to winforms in the .Net world.
I think it goes without saying that the paradigms are very different. I really enjoy C# because of how easy it is to write great windows software.
Start by getting into the IDE and creating a real but small project. One of my first C# projects was a light weight budget program. That took me into many areas of C#, from XML handling to custom windows controls, to debugging, and more.
Experience is the best teacher. Take time to look at the function lists, and peruse the documentation. Get a feel for what is in the thousands of classes that make up .NET.
Reading books can be nice, but getting your hands dirty (in conjunction with a good book) is far more effective.
Set a goal and go for it, you will have no problem learning all about it. Don't be afraid to try things and take risks -- it helps you learn the system.
If you are moving from Web to Windows, there is a some significant differences between the two enviroments. Some good and some are bad. If your .Net based and moving to 3.5 look into WPF since it is the best of both worlds for Web developers converting right now.
I do know of some common mistakes made by web developers making the crossover. They would include:
Opening database connections on every form and every database calls. (In Windows Bad)
There is no ViewState concept or Stateless concept in Windows
I am sure there is a few more that can be added but right now I can't think of an exact list.
I do agree with gahooa, look at doing a small project and read as much as possible on the subject. Approach it as if you never developed before, and the skills you gained over the years will automatically kick in when needed.