I am wrapping calls to an API and most of my methods have in their first lines:
if ( !Gree.Authorizer.IsAuthorized() )
{
return;
}
In python I would decorate those methods with something like #login_required.
What would you use to refactor that type of logic in c#?
You are looking for a subset of a more general programming methodology called Aspect Oriented Programming.
C# seems to support it through several libraries, and one can also roll out his own, thanks to some of the CLR features. See Aspect Oriented Programming using .NET which covers its basic principles (I am linking the part of the article talking about the specifics of C#, but the rest is equally interesting if you are looking for ready-made solutions like PostSharp, as mentioned in another answer).
You can use any AOP tool for C# such as this one.
With PostSharp, software developers can encapsulate implementation
patterns into classes called aspects, and apply these aspects to their
code using custom attributes.
I'm not familiar with python but it seems you are looking for "attributes" (MSDN), (which are pretty similar to Java annotations).
In particular, .NET provides the "AuthorizeAttribute", which does exactly what you want (and maybe a little more). While you are not under .NET, this may still shed some light in the implementatino you are trying to achieve.
I've decided to try and create a game before I finish studies. Searching around the net, I decided to create the basic game logic in python (for simplicity and quicker development time), and the actual I/O engine in c# (for better performance. specifically, I'm using Mono with the SFML library).
After coming to grips with both languages and IDEs, I've gotten stuck on integrating the two, which leads me to three questions (the most important one is the second):
a. which module should encapsulate the other? should the python game logic call the c# I/O for input and then update it for output, or should it be the other way around?
b. whatever the answer is, how can I do it? I haven't found any specific instructions on porting or integrating scripts or binaries in either language.
c. Will the calls between modules be significantly harmful for performance? If they will, should I just develop everything in in one language?
Thanks!
Sincerely, I would say C# is today gives you a lot of goods from Python. To quote Jon Skeet:
Do you know what I really like about dynamic languages such as Python, Ruby, and
Groovy? They suck away fluff from your code, leaving just the essence of it—the bits
that really do something. Tedious formality gives way to features such as generators,
lambda expressions, and list comprehensions.
The interesting thing is that few of the features that tend to give dynamic lan-
guages their lightweight feel have anything to do with being dynamic. Some do, of
course—duck typing, and some of the magic used in Active Record, for example—
but statically typed languages don't have to be clumsy and heavyweight.
And you can have dynamic typing too. That's a new project, I would use just C# here.
Have you considered IronPython? It's trivial to integrate and since it's working directly with .net the integration works very well.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
C# has a good momentum at the moment. What are the features that you would need to have in order to switch (or return) to Java?
It would also be quite useful if people posted workarounds for these for the current Java versions, e.g. Nullables being wrapped around custom classes, to make this a much more interesting wiki.
As a .NET/C# developer here are the missing features that annoy me. This list in no particular order - just as thoughts come to mind:
The Java library is too small. For common things I have to choose between 5 competing open source products because the base library is lacking in so many ways.
This is an Object Oriented programming language right? Why in the heck do primitive types not inherit from "object"?
Pointers
Lambdas
Closures
Partial Classes and to a lesser extent partial Methods
Real support for Generics
Using statements and Dispose - this was a real WTF for me. You really have to explicitly close connections in try/catch blocks. Poor Java guys!
Yield return would be nice
Unsigned integers - again WTF? I have to use number types larger than I need for what purpose again?
In Java you can return from final blocks of try/catch. A co-worker confused the hell out of me for hours by introducing a bug this way. This behavior should be prohibited as in C#.
I rarely have to use Java and when I do, I have all sorts of WTF moments.
Edit: I Removed for-each comment based on the fact it is no longer a missing Java feature since 1.5.
In my experience, Java vs. .Net is more of a business decision than a technical one. Shops with MS experience trend towards .Net and shops with Java experience trend towards Java & OSS. I've seen little evidence of people switching based upon language features. On the other hand, I've seen shops heavily tilt towards one platform b/c of one or two key employees they wanted to hire being knowledgeable in that area.
in no particular order:
function pointers (delegates); the whole passing interfaces around thing is stupid
real generics; what's the point of having type safe generics if the compiler can't even hold the meta data through a unit's compilation?
ui speed; all the self-drawing ui libraries are very slow compared to native controls wrapped in "managed" libraries, not to mention that microsoft's self-drawn ui is hardware accelerated through direct3d
an yield return construct; c# is so user friendly in this it's crazy
operator overloading
linq; just cuz its so addicting
properties; more synctatic sugar you get addicted to
better interop with native code; c#'s p/invoke and native com support makes interop so easy compared to jni -.-
first class value types; this goes hand in hand with real generics, having generic lists that never box/unbox in c# is part of why c# is faster than java.
and i'd say this is the most important one:
a responsive, informative debugger; nothing can even come close to visual studio right now
Just going off the cuff, I think the biggest thing Java 7 needs that everyone is lamenting the lack of is closures.
I'm a C# programmer and about one year ago I had to participate in the development of an application in Java. What I missed the most was:
Visual Studio (Eclipse is nice, but
VS is VS, especially Team Edition)
Comparing strings with ==
Properties
Basic types as first-class objects
(e.g. not "int" type vs "Integer"
class)
Anonymous methods (a workaround can
be made by using anonymous classes
but it is not the same)
LINQ
And there was one single Java feature that I missed when I went back to C#: explicit exception declaration in method signatures.
DISCLAIMER: I am speaking about a somewhat old project, I don't know if some of these features are present in current versions of Java.
Less heinous XML parsing and manipulation tools. Doing anything with XML in Java sucks.
I'll also give one answer the other way around. C# needs an enumeration implementation like Java has. Java's enumerations rock!
Let me add anonymous overrides to this list also. Sorry to go off topic, but C# needs the ability to anonymously override methods. I have been switching back and forth between Java and C#, and I have to say for unit testing legacy code, there is nothing better than anonymous class overriding.
I would need function pointers of some sort. The ability to use delegates in C# is so useful. There are so many times in Java where I want to create a map of delegates or function pointers as the solution, but I can't. I know you can simulate a similar thing in Java, but having the abstraction as part of the language is a huge plus!
Momentum. I have done a lot of development on both platforms. I'm enjoying the .NET side more because of the way the C# language is evolving. Java's evolution seems to be more a reaction to C# than an actual vision. So I think the best thing for Java to do is ignore .NET and create something new of its own.
Another one I would like is some equivalent to LINQ. I noticed how much I actually depend on the ability to use LINQ when I tried to do a top coder competition and realized they only support .NET 2.0. Once you get used to using LINQ to solve problem and make it part of your regular programming vocabulary it is very difficult to not see problems in that light. It is akin to using generics and then not being able to use generic.
I think, choice between Java and C# is not a question of language features, but a question of platform and ecosystem choice.
So, I doubt that any new syntactic sugar in Java or C# can lead to a significant amount of switchers between the platforms.
After all, JVM world has Scala and many language-sensitive developers are using it in some way.
I think, you should consider swithcing this holywar from "Java vs C#" to "JVM vs CLR", because JVM is (in the last years — mostly) not only Java, but also Scala, Groovy, Clojure, JRuby, Jython, and dozen of JVM-languages.
Properties!
Anonymous objects are nice too
Continuations, like Scala (on top of the rest) would be good too, for agents development.
Support to run over CLR (and vice versa perhaps for JVM) without IKVM and other such layers.
Let's be clear that we need to distinguish between Java and the JVM. I actually switched from C# to Java, but I admit it was not because of Java's amazing language features! In my very humble opinion, C# is the better language, and CLR is the perhaps a more elegant VM. However, even with Mono, you're not writing applications that run everywhere!
I think the greatest argument for Java is the amazing community it has. This is where the cutting edge technology is being developed, not at Sun (now Oracle). The Java community has consistently been the leader in developing Enterprise technologies. For instance, how long did it take Microsoft to provide a DI Framework? Where's AOP in .NET? When I start a .NET project, my foundation is Spring.NET, a Java port. When I need ORM, it's NHibernate. Need a testing framework? NUnit. I realize there are other OSS projects for the .NET platform, but their numbers and support from Microsoft are laughable compared to the Java community.
on the other side, has .net got enterprise open projects like Terracotta (semi commerical), Infinispan, Compass ? no. ncache (commerical), lucene.net are far behind them. Especially Terracotta is unique, it can improve some of your app x100, it's simply perfect and free (partitioning is commerical). If we implement a high load app in both .net with anything and java with terracotta + hibernate + terracotta-hibernate-integration, java app will probably far more performant than .net one. Ther're some ports to .net like nhibernate, log4net, lucene.net, but all of them are trying to catch java versions. And entity framework is a disaster, they have to start with nhibernate as the base or get some lessons from them.
.net is only working on windows (mono is far from enterprise, there isn't any enterprises using it), how much money does myspace.com spent for their 4000 windows web server licences ? 1 million ?
You can't install a simple plugin to VS (and can't do some other things) if don't buy professional edition,
Some windows instance types in amazon web services are nearly x2 price of the linux ones.
if you look at ohloh.net open source java project counts (with language comparison tools), you'll see that java has x5 more volume than c#.
also Java has %20 share on worldwide while c# has %4.x (source:tiobe.com)
Look at the top web sites; only microsoft and myspace are using .net. google, amazon, ebay, linkedin, alibaba, twitter (switched to scala from rails)... many of them are using java and many others are using php, ruby (facebook, yahoo,..)
As a language Java is far behind c#, but Scala (runs on jvm) is as good as c# and it's performance is nearly same as java and also it can use all jdk and other java code as his library.
I'm not saying java is better, but I'm saying java is as valuable as .net, too.
A native 'decimal' type for Java replacing the BigDecimal class would be nice. But Java thread-safe collections are nice.
Perhaps the question is not so much what Java 7 needs to persuade developers to use it, but more a case of what makes developers want to move from Enterprise/server-side java language to a different C# desktop Windows-only oriented world?
For most developers, the language isn't difficult to pick up be it Java or C#. I develop in Java, but Linq didn't take long to understand and use.
I think the choice of Java or C# depends on what motivates you personally -perhaps money? in which case either language will do whether they have certain features or not.
Ste
They should start by fixing the Calendar/Date related classes, even that seems too much to ask.
A simple way to map values in your model to the UI (like bind in Java/FX)
I think it depends on bussiness decisions, not the languages themselves.
But I really really really love C# lambdas and curry :D :D
http://mikeomatic.net/?p=82
a map({codeblock}) which runs over anything iterable would be nice. And filter too. And being able to return multiple values easily from a method.
(a,b,c) = getThreeValues();
(would assign the individual variables a, b and c).
Actually I just think they should have Haskell as a supported scripting language on the JVM :D
linq, lambda, anonymous types
I don't see any point in "luring" anyone anywhere. They solve different problems and you should use whichever one suits you.
Java has less "Language" and less structures to trip up new people, it's platform independent and it doesn't change too fast allowing old code to stick around for a LONG time (Good for some large companies).
C# has tight desktop integration and a slew of nice features that make it more fun to program. It has .net integration. It has pointers, closures, etc which make it harder for n00bs (a valid language target, hence Basic) but more fun for experienced programmers--I haven't convinced myself that these features make you more productive, but in some situations they can make your code a lot nicer! Also if you need pointers, you need pointers.
I don't see a whole lot of overlap in target audiences. Why change a language to attract programmers when it's healthier for the entire industry to have two healthy languages each targeted at solving different problems attracting different developers?
Boo seems like a very cool language. Is it 100% C# compatible? I mean: can I use any C# DLL/class? Could I make use of the XNA framework?
As far as I know, Boo has an implementation on top of the .NET CLR - which implies that it should be able to both consume, and be consumed by C# code. The syntax may not always be pretty when consuming Boo from C# - but the opposite should be quite elegant, given Boo's syntax.
Also, all of the classes in the .NET BCL should be available to you in Boo.
Yes Boo is easily consumed by C# and vice versa. Most of the best features of Boo don't carry over to C#, such as syntactic macros, for obvious reasons, but you can create Macros in C# and consume them in Boo. Additionally Boo has the nice feature of being able to create Modules, which is something you can't do in C#.
They both can create extension methods. Boo has 'duck' typing while C# now has the "dynamic" keyword. While they're both functionally equivalent you might end up seeing the two merge eventually.
Boo currently has known issues with generics, but the feature will be completely supported once they are all ironed out. I suspect there will have to be some extra work done to support the new Co/Contra-variance features in .NET 4 as well.
It would be no different than using VB.NET with C#. Currently the only big different between the two (functionally) is Boo does not have pointers... but there are ways to handle that.
PS: Boo IS a wonderful language.
IIRC, any language which compiles into IL (Intermediate Language, .NET's version of Java's bytecode) can work with any other language which does the same. So you can mix C#, F#, ASP.NET, VB.NET, and if Boo does the same, you should be able to use with with C# as well.