views:

230

answers:

8

I've been jumping from C# to Java an aweful 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 syntaxs.

I'm talking about adding either IDE support or using language constructs that would for example:

  1. treat these two lines equivelently:

    System.out.println("Blah");

    Console.out.writeline("Blah");

  2. Automatically notice that when you type in string you mean String

  3. 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 targetting.

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".

+16  A: 

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.

Jon Skeet
I absolutely agree! They're two different languages!
Ray Hidayat
+2  A: 

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.

JoshBerke
Yup, do it all in the language.
Hamish Grubijan
+1  A: 

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.

Kev
A: 

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.

A: 

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.

A: 

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.

Brian Rasmussen
A: 

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.

mP
A: 

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

mP