Using IronPython to learn the .NET framework, is this bad? - c#

Because I'm a Python fan, I'd like to learn the .NET framework using IronPython. Would I be missing out on something? Is this in some way not recommended?
EDIT:
I'm pretty knowledgeable of Java ( so learning/using a new language is not a problem for me ). If needed, will I be able to use everything I learned in IronPython ( excluding language featurs ) to write C# code?

No, sounds like a good way to learn to me. You get to stick with a language and syntax that you are familiar with, and learn about the huge range of classes available in the framework, and how the CLR supports your code.
Once you've got to grips with some of the framework and the CLR services you could always pick up C# in the future. By that point it will just be a minor syntax change from what you already know.
Bare in mind that if you are thinking with respect to a career, you won't find many iron python jobs, but like I say, this could be a good way to learn about the framework first, then build on that with C# in a month or twos time.

You can definitely do that to learn the class library, but I'm not sure if it's such a good idea when it comes to fundamental CLR concepts (e.g. delegates and events). You'll need to pay attention and distinguish what is strictly an IronPython feature, and what is CLR feature exposed in IronPython in a way that matches its dynamic semantics better.

If I wanted to just "learn the framework", I would do it in C# or VB for two main reasons:
Intellisense - the framework is huge, and being offered suggestions for function overloads is one of the ways to find new stuff. There's almost no good intellisense for the framework with IronPython at the moment (Michael Foord has done some work on building the appropriate info for Wing, but I haven't tried it myself).
Code samples - pretty much all the educational material that exists about the .NET framework is given with C# or VB. You'll be much more on your own with IronPython.

I find .NET a lot easier to learn with intellisense. If you can get IronPython to work in Visual Studio as a first-class language, go for it. If you try, please document it!
Hmmm: http://www.codeplex.com/IronPythonStudio

Related

Going from C# to VB.NET - Resources?

Though I have worked with Visual Basic in the past (VB 4, 5, and 6), ever since the .NET framework was first released I have been working in C#. For an upcoming project I am being asked to work in VB.NET so I am trying to come up to speed with VB.NET. Can anyone recommend any resources (books, articles, etc ..) targeted towards C# developers who are looking to quickly become familiar with VB.NET?
EDIT: I feel I should emphasize, due to certain comments, that I am not trying to compare the various worth of each language (C# vs. VB.NET). Such a comparison wold be subjective in so many ways. Rather, I am saying I myself am not that versed in VB.NET and am looking for resources that would enable me to learn VB.NET considering my experience is with C#.
Never, ever forget this when you're doing boolean logic:
AndAlso instead of And
OrElse instead of Or
Just dive in. Seriously, that is the best way to learn. Functionally, they are mostly the same these days.
For me, the major differences are
lack of support for iterators (yield return) in VB.Net (coming in the next version)
XML literals in VB.Net are not available in C#. As a C# developer, many times I prefer VB when working with XML these days...
linq query syntax behaves differently in VB (richer at first sight in VB, but much more consistent in C#)
Other than that, it's mostly just syntax
Oh, and don't forget to put Option Strict and Option Infer on... If you need dynamic, you can 'sort of' get the same by turning off Option Strict (I recommend doing this at the file level).
Here is a link that compares the two languages: http://www.harding.edu/fmccown/vbnet_csharp_comparison.html
In truth with .Net 4.0 they are pretty much the same. The syntax is different (obviously), but their functionality is nearly identical. This is now by design, Microsoft plans on co-evolving them from now on, so new features will be added to both.
I work with both, if you know C# and know VB6 syntax, it'll be easy to pick up (I started with C# since I have more of a C++ background, but I also had some VB6 so it was very easy to start working on VB.Net as well).
There's a few things you'll have to look up every now and then but as Kevin says, they're more or less the same language. And anyway, the languages themselves aren't that big so aren't very difficult to learn, it's learning the .Net Framework that takes a lot of time, so you know what's already written and where to find it, and your knowledge of that transfers across.
go to msdn Visual Basic Developer Ceneter , you'll find tons of information there
http://msdn.microsoft.com/en-us/vbasic/default
here is a learning guide
http://searchwindevelopment.techtarget.com/tutorial/Choosing-VBNET-or-C-Learning-Guide
Google is good for checking syntax differences (search "C# keyword equivalent in vb.net"). MSDN is good about having code examples in both VB and C# too.
This online conversion tool can often be helpful too.
Besides the short circuit operators, one thing that can trip you up is not initializing your variables. It seems like you don't have to, but if you are in a loop you actually do have to.

Should C# and Java incorporate each others syntax?

I've been jumping from C# to Java an awful lot and the "differences" between the two are a bit of an annoyance.
Would it be possible to write a set of extentions/plugins that would merge the two languages syntaxes.
I'm talking about adding either IDE support or using language constructs that would for example:
treat these two lines equivalently:
System.out.println("Blah");
Console.out.writeline("Blah");
Automatically notice that when you type in string you mean String
Recognise common API calls and translate them in the background.
The end goal being to be able to write a java/C# program and to pick at compile time which VM/Runtime you are targeting.
If you could do this would it be a good idea?
If not why not?
The two languages are so similar it's painful in some aspects but in other aspects they are really different.
I've seen Code that will translate a C# project into Java and I'm assuming there is probably the reverse, what I am proposing is a middle ground, so we can all just "get along".
No, absolutely not. Certainly not in the languages themselves (as implied by the title) and preferably (IMO) not in the IDEs (as requested in the body).
They are different languages. The idioms and conventions are subtly different. I don't want to be thinking in Java when I'm writing C# or vice versa. I believe developers should be actively encouraged to separate their thinking. It's not too hard to switch between the two, but that switch should be present, IMO.
While I totally agree with Jon Skeet, if you must have this why not create your own library of Java API so you can create System.out namespace which has a method call printLn which calls Console.Writeline()?
That gets you close to what you want.
Just because Java and C# share some similar syntax you need to see past this and think in terms of Java Platform and .NET Platform. The two are distinctly different, so my answer is definitely not.
There actually already is a Java language for the .NET framework, developed by microsoft: J#
This way you get the java-syntax but you are still developing with the .NET framework.
But i am not recommending anyone to use it.
I knew Java before i knew C# so i tried out J# because i thought it would be an easier transition. At first I liked it but after I tried C# I'm never going back. First of all, nobody uses J# so it's kinda hard to find examples and tutorials. Second, C# has (IMO) much more convenient syntax, specially for events, properties, lambda, anonymus methods and alot of other things, it's also being updated every now and then with even more syntax sugar which i don't think J# is.
Maybe if you often write Java and sometimes have to write a .net app it might be a good option.
I think no. I also switch from java to c#. But if the syntax is identical was is to stop someone from trying to compile c# in a Java compiler, or vice-versa.
Visual Studio actually ships with a Java to C# converter, which tries to do some of the things you mention. Unfortunately it fails miserably (1) for anything beyond the simple hello world application.
Despite being very similar on the surface, there are many significant differences between Java and C#, so you would achieve very little by doing what you suggest imo.
(1) To be fair, it actually does a fairly good job if you consider the limitations given for such a task, but in practice the resulting code is of limited use and you have to do a lot of clean up after the conversion.
Firstly what you are describing is not a difference in language syntax but a differences in class libraries. Both languages are relatively simple in terms of keywords and features but understanding or knowing the libraries and how they operate requires considerable learning.
The mistakes you are describing are things that the developer should not be making to begin with - the IDE should not be guessing. There are going to be many cases where you can't easily / trivially translate between java or dotnet. In the end a skilled developer learns and knows when and which class libraries to use.
Actually in the beginning there was no dotnet - microsoft was behind java. They however proceeded to change java in ways not compatible with the java plstform standard. To paraphrase sun sued microsoft and won I'm court. Following that ms proceeded to create dotnet and particularly c# which became microsofts VM platform. Of course along the way a whole stack of things got changed. Microsoft introduced many things which broke Javas run anywhere etc. They have done the same thing with dotnet which have cause problems for the mono team to be able to faithfully reimplemwnt everything for other non windows platforms.
• String vs string.
• lowercase method names (java) v uppercase method names(dotnet).
• Giving java keywords new names - "package".
In the end dotnet was microsoft response so they can control the platform and do their own thing instead of following a standar

How do I convert VB5 project to a c# project

I have a VB5 (non .net) project that I would like to upgrade to a c# project. Has anyone have any suggestions on methods or free tools that are avalible to help me with this.
Thanks
Brad
You are better off with a straight rewrite.
What I would suggest is first convert the project to VB6. It'll be much easier to go forward from there. There are a number of tools to help you do this. There is VBMigration Partner and there is vbto. I've not tried either so YMMV.
If costs are a constraint you could try this: there is a wizard in Visual Studio that will attempt to upgrade VB6 to VB.NET. It's not 100% accurate and you WILL have to write code for things VB.NET does not support such as control arrays, etc. Once the code is in VB.NET you can use a tool like SharpDevelop to convert the VB.NET to C#. It'll be a bit tedious but i suppose all roads, no matter how convoluted, lead to Rome.
In case you were able to migrate it to VB6 you can use the code advisor to see how you can fix your project to be compatible to vb.net, then you can migrate to vb.net, in case it success, you can use this tool to convert it to c# or the Reflector.
I give it a chance of 1x10^(-100)% to work.
Good luck.
If you're about to convert VB5 to .NET (whether it's C# or even VB.NET) the fastest way is to restart from 0 your implementation so you can take full advantage of .NET Framework classes. I don't know if there are tools to do this conversion automatically.
It's rarely a good idea to do a strict conversion from one language to another, particularly when they are as different as VB5 and C#.
Theoretically, you could convert VB5 to VB6 and then VB6 to VB.NET and then VB.NET to C#, but that just sounds crazy to me as I type it.
C# is so much more powerful than VB5 that you wouldn't want to covert the code anyway. After all, it likely has a poor design due to VB's weak OO capabilities.
I'd instead recommend re-implementing the functionality you need in C# (or whatever other language you want to use).
I know there exist a conversion tools, not sure though if there are some for vb5.
However, i'd recommend performing a redesign of the project, taking advantage of the .net features unavaiable in vb5. Specially it would be good redesigning for a OO language.
Migrating VB5 to C# just to have .NET is never a good reason. I would prefer to have a good look at the assumptions and design decisions I made in the VB5 version, rethink them all, add new ideas, sketch the UI and improve it to look closer to a modern one.
Then it's a new project, I wouldn't even call it a rewrite, because so much would have changed.
I've migrated a small 1-tier VB6 application to C# and I will never do it again.
There are applications out there that do a rather good job migrating from VB6 to VB.Net.
//Magnus
I’ve done it in the past but don’t recommend it. Getting the project to work correctly after the ‘auto-migration’ was not worth the effort. I ended up rewriting the program and was better off because of it.
Having done this myself I talk about the issues involved here.
Basically as ocdecio you are looking at least a partial rewrite. You will likely need to refactor your forms to move as much code out of them as possible. You will also need to refactor any VB6 specific features to work behind a interface that you can reimplement in .NET. Notably the Graphics commands, and the Printer functions. Migration Tools are usually worthless for any serious project.

How do I move from Java to C#?

I know Java well. Which caveats and resources will help me cross to the other side (C#) as painlessly as possible.
Biggest tip: go with the .NET naming conventions from the word go. That way you'll constantly be reminded about which language you're in. (Sounds silly, but it really is helpful.) Embrace the idioms of the language as far as possible.
There are various books specifically for folks in your situation - search for "C# for Java" in Amazon and you'll get plenty of hits. It's worth reading carefully to make sure you don't assume that things will work the same in C# as in Java. (For instance, in C# instance variable initializers are executed before the base class constructor body; in Java they happen after. Subtle things like this can take a while to learn, and are easy to miss if you're skimming.)
If you're going to be using C# 3, I'd get a book which definitely covers that - everything in C# 3 will be new to you. Gratuitous plug: my own book (C# in Depth) covers C# 2 and 3, but assumes you already know C# 1. (In other words, it won't be enough on its own, but you may want it as a "second" book.)
See this great article on C# from a Java Developer's Perspective. It has several insights on the things that can be done in both sides to avoid minimum overhead. Having example in both the language you know and the language you want to learn eases the learning curve quite a bit.
Install Visual Studio 2008 and Resharper with IntelliJ IDEA key bindings. This gives you things like prompting you to include namespaces if you start using them.
Start a new project and start writing Java code, when you run into something that doesn't work properly or it's unable to find the class you're trying to use Google "PrintLn in c#".
Write tests or code snippets for sanity checks, like you may want to check if == works for strings (it does)
realize that c# alias Data Types (int is an alias for System.Int32, string for System.String)
look at other peoples code I recommend JP Boodhoos Google code
Take a job in C#, there's lots of jobs requiring both Java and C# especially in support.
Know your libraries, most Java libraries have been ported and most of the time the name is either like (Hibernate => NHibernate) or (Xstream => Xstream.Net). Not every library has an obvious name so just start looking into random ones you hear about here. ie (Rhino.Mocks,HTMLAgilityPack,MBUnit,Rhino.Commons,Castle Project)
Go to usergroup meetings look for a DNUG (Dot Net User Group) they'll be helpful and you can get some good advice.
There's a cheat-sheet from Microsoft for Java developers using C# :)
I know that a good answer has already been accepted. However, I'd like to make an addition...
I find that learning a new language typically involves learning subtle syntactic differences....especially when dealing with the difference between languages in the C/C++/Java/C# family.
In addition to a nice thick reference book I recommend getting a pocket reference like C# 3 Pocket Reference from O'Reilly. It won't help you with the design patterns etc...but will provide a very quick reference about the specific differences of the language you are using.
Here's a quick blurb about this book from that site:
C# 3.0 Pocket Reference includes plenty of illustrations and code examples to explain:
Features new to C# 3.0, such as lambda expressions, anonymous types, automatic properties, and more
All aspects of C# syntax, predefined types, expressions, and operators
Creating classes, structs, delegates and events, enums, generics and constraints, exception handling, and iterators
The subtleties of boxing, operating overloading, delegate covariance, extension method resolution, interface reimplementation, nullable types, and operating lifting
LINQ, starting with the principles of sequences, deferred execution and standard query operators, and finishing with a complete reference to query syntax-including multiple generators, joining, grouping, and query continuations
Consuming, writing, and reflecting on custom attributes
I used this book (well the original) to help me go from being a Java to a C# developer. While I was learning, I kept it by my desk at all times and it really helped.
I made the transition pretty easily by using C# at work, but one of the most important things to do is familiarize yourself with the .NET API and some of the powerful techniques available in C#.
After I learned the .net library I relied on it a lot more than I used to, so learning about the things it can do for you is very helpful. After that, if you work with db code at all, learn LINQ, and also techniques lambas, anonymous types and delegates are also a useful to pick up.
The language syntax is vary similar, so I should only read a small reference of the C# syntax. Like a simple book (for experienced programmers) or maybe wikipedia (http://en.wikipedia.org/wiki/Comparison_of_Java_and_C_Sharp) will tell enough.
The biggest difference is the library: Asp.Net websites are totally different from java servlets.
Don't read much, just start programming!
Here's a link that has syntax comparison between Java and C# (even though it's almost identical, there are a few differences).
http://www.harding.edu/fmccown/java1_5_csharp_comparison.html
Use Sharpen to convert your Java programs to C# and see the differences.

How should I convert Java code to C# code?

I'm porting a Java library to C#. I'm using Visual Studio 2008, so I don't have the discontinued Microsoft Java Language Conversion Assistant program (JLCA).
My approach is to create a new solution with a similar project structure to the Java library, and to then copy the java code into a c# file and convert it to valid c# line-by-line. Considering that I find Java easy to read, the subtle differences in the two languages have surprised me.
Some things are easy to port (namespaces, inheritance etc.) but some things have been unexpectedly different, such as visibility of private members in nested classes, overriding virtual methods and the behaviour of built-in types. I don't fully understand these things and I'm sure there are lots of other differences I haven't seen yet.
I've got a long way to go on this project. What rules-of-thumb I can apply during this conversion to manage the language differences correctly?
Your doing it in the only sane way you can...the biggest help will be this document from Dare Obasanjo that lists the differences between the two languages:
http://www.25hoursaday.com/CsharpVsJava.html
BTW, change all getter and setter methods into properties...No need to have the C# library function just the same as the java library unless you are going for perfect interface compatibility.
Couple other options worth noting:
J# is Microsoft's Java language
implementation on .NET. You can
access Java libraries (up to version
1.4*, anyways).
*actually Java 1.1.4 for java.io/lang,
and 1.2 for java.util + keep in mind that J# end of
life is ~ 2015-2017 for J# 2.0 redist
Mono's IKVM also runs Java on
the CLR, with access to other .NET
programs.
Microsoft Visual Studio 2005 comes
with a "Java language conversion
assistant" that converts Java
programs to C# programs
automatically for you.
One more quick-and-dirty idea: you could use IKVM to convert the Java jar to a .NET assembly, then use Reflector--combined with the FileDisassembler Add-in--to disassemble it into a Visual C# project.
(By the way, I haven't actually used IKVM--anyone care to vouch that this process would work?)
If you have a small amount of code then a line by line conversion is probably the most efficient.
If you have a large amount of code I would consider:
Looking for a product that does the conversation for you.
Writing a script (Ruby or Perl might be a good candidate) to do the conversion for you - at least the monotonous stuff! It could be a simple search/replace for keyword differences and renaming of files. Gives you more time/fingers to concentrate on the harder stuff.
I'm not sure if it is really the best way to convert the code line by line especially if the obstacles become overwhelming. Of course the Java code gives you a guideline and the basic structure but I think at the end the most important thing is that the library does provide the same functionality like it does in Java.

Categories