Related
I am thinking of writing a DSL to be run in the .Net environment. I am most likely to implement this in C#, though I am flexible on this.
Is there a recommended online resources that show the main steps involved in writing a DSL for the .Net platform?
Ideally, I would like a resource that would provide at least an overview on the following:
'Spec'ing a DSL
How to map the specs to the .Net framework
Preferably a helloworld example of a trivial DSL implemented in a .Net language
[Edit]
Actually, I have just seen this article - but it is slightly dated. Does anyone have a view on whether the article is a good starting point or not (the .Net framework and C# seem to evolve at a very rapid pace)
If you are willing to buy a book on the topic, I highly recommend "DSLs in Boo: Domain Specific Languages in .NET" by Ayende Rahien. Very informative and gently takes you through the process of writing a DSL. The author uses a lightweight .NET language called Boo to serve as basis for the DSL's syntax.
Also you can look into VS2012 corner:
Microsoft Visual Studio 2012 Visualization & Modeling SDK
Microsoft Visual Studio 2010 Visualization & Modeling SDK
There's a bunch of different solutions you could use, including the article you linked, but some other examples from MS...
FsLex/FsYacc - Ports of the popular Lex and Yacc lexer/parsers for F#, but don't be turned off right away. If you've not used it before, F# has a feature called "pattern matching", which allows you to match very complex constructs (such as walking a tree), without an extensive amount of if/else/or blocks all over. This is perfectly suited to language compiling - because almost all DSL solutions you will find will work by parsing the language into an AST (Abstract syntax tree). In this F# solution, you get a strongly typed tree to work with. You can grab the F# Parsed Language Started to get you going. (There's plenty of existing grammars for Lex/Yacc that can help you out too).
SQL Server Modeling Tools (formerly "Oslo") - Contains a language called M, formerly broken into several parts, one being MGrammar. It's quite an advanced parser and can save you plenty of time over other grammars - code patterns (or generic grammar rules) and precedence are built in and easy to use. I would perhaps recommend this if you're starting out with parsing, because it comes with a visual tool - Intellipad, which has a 3-panel DSL mode, where you type in your language and some example code - and it'll show you the output AST as you type - it's quite productive to use. The generated AST is a valid M language constructor (MGraph), which can be used with services like SQL and XML. A downside to MGrammar IMO, is that walking the AST from C# or elsewhere is a tiresome process. There's nothing strongly typed, and you're working with objects and searching with strings - awkward and easy to make mistakes. There's some samples on msdn, and some vids on channel9 which can help you get started like this lengthy overview
The Visualization and Modeling SDK - An entire solution built into VS, which focuses largely on building your with Visual Studio's design tools over code. It comes with a minimum language starter template to help you. Haven't any experience with this to recommend it.
There's plenty of other non-MS solutions, like the one you've mentioned, C# targets for ANTLR etc. These are particularly useful if you're re-using existing grammars - because there's dozens already out there.
You could try JetBrains' MPS. It is a very rich and robust ecosystem for generating DSLs. I've never used it myself, so caveat emptor, but it's free so I guess it can't hurt (much) to give it a go.
Check out my open source project meta#. It sounds like what you are looking for.
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 12 years ago.
I know it is a kind of broad question but any answer are appreciated.
All:
Require some form of runtime on your system (JVM/.net/Python runtime)
All can probably be compiled to executables without the runtime (this is iffy and situational, none of them are designed to work this way)
Are good languages
All have specific areas where they are much more appropriate than the other two
Java:
Tries very hard to be Cross Platform--generally succeeds
Little access to platform features that are not in the SDK
Slowest of the three to change and does not contain features common to the other two such as closures
Very backwards compatible (partly because of the previous point)
FAST (about 2x slower than C, quite a few x faster than python)
Probably has the most library support of the three
Strong multi-platform server systems already deployed using J2EE
Scales down to embedded (I've worked on 2 different embedded java projects--coming soon to a cable box near you)
Static
C#
Quicker to add new features
Windows only--Mono is cross platform but does not have the library support.
Started very similar to Java but has many more language features now.
Much better access to windows APIs
Not sure about speed--I think it's similar to Java.
Very good library support
The only one of the three that you have to pay for (it's free for "entry level")
Static
Python
Language is cross platform. Not sure about non-language platform access (such as drag-and-drop)--anyone know?
Probably an easier language to learn
The only one of the three that does not use c-like syntax
Slowest of the three, but still pretty darn fast compared to other dynamic languages.
Dynamic
This link is also interesting
Python is a dynamic language where Java and C# are really not. It is totally different than the other two. There are ways to accomplishing things in Python that do not translate well to the others and vice versa.
Java and C# look the same, but they have differences between the two under the sheets. Being an expert in one, does not make you an expert in the other by any stretch of the imagination. The syntax is similar and libraries are too, so it would be easier to get up to speed in one or the other, but there are subtleties that can trip you up.
C# and Java have almost identical syntax and very similar libraries. There are differences that you have to be aware of (Type Erasure in Java, for example).
Python is a completely different animal. It is a dynamic language (where the other two aren't). Python winds up being closer in style to something like Ruby.
Java and C# are statically typed languages, while Python is a dynamically typed language. That's a huge difference.
The syntax of Java and C# is similar (but I would not call it "almost identical" as Justin Niessner says).
Java and c# are pretty similar in terms of syntax and are mostly strongly typed (C# is getting more dynamic with every version), Python is a dynamic language
Java and C# are very similar and are syntactically similar to C/C++. They also use braces to mark code blocks.
Python is completely different. Although imperative like Java and C#, Python uses indentation to define blocks of code.
Java and C# are also compiled languages, whereas Python is interpreted and dynamic.
Python, Ruby, and Groovy are somewhat similar languages.
C# and Java are easy to move between, although I don't know many people who are experts in both. C#'s syntax is based off of Java, so they read very, very similarly. They both run cross-platform; Java on the JVM, C# on .NET or Mono. They're both OOP, and widely used for web development. I'd use whichever the team was more familiar with.
Python's off to the side there. It's also used frequently as a scripting language. It can use classes and object orientation, but isn't forced to. It's not as well supported for web work. I'd use this for a different set of tasks than C#/Java.
C# and Java are the two languages you listed that are most similar. Python has a very different syntax, and uses a slightly different programming model. Both C# and Java are Object Oriented languages at their core, with increasing nods to Dynamic Typing. Python began as a Dynamically Typed scripting language and has been picking up more and more Object Oriented features over the years.
The C# class library (.NET Framework) is theoretically multi-platform, though it's heavily weighted towards the Windows platform, and any other OS compatibility is largely an afterthought. The .NET framework currently has two "official" frameworks for building windowed applications (Windows Forms, and WPF) and two "official" frameworks for building web applications (ASP.NET, and ASP.NET MVC). Windows Forms is similar to Java Swing, but the other four frameworks are very different from much of what is found in the Java or Python worlds. There are many language features in C# that are different or lacking in Java, such as Delegates.
The Java class library is pretty solidly multi-platform. It's officially supported desktop and web frameworks (Swing and J2EE) are generally regarded as slow, and difficult to use. However, there is a very lively open source community which has built several competing frameworks that are very powerful and versatile. Java as a language is very slow to introduce new language features, though it is runtime-compatible with several other languages that run on the Java platform (Groovy, Jython, Scala, etc..). Java is the language which has has the most run-time optimizations put into it, so an application written in Java is almost certainly going to be faster than an application written in C# or Python.
Python is an interpreted language (in general), and is pretty solidly multi-platform. Python has no "official" desktop or web frameworks, though desktop applications can be written using GTK or Qt support, both of which are multi-platform. Django has become a de-facto standard for Python web development, and is regarded as a very powerful and expressive framework. Python is at this point fully Object Oriented, and is notable for it's powerful tools for working with collections/arrays/lists. As an interpreted language, Python will be significantly slower than either C# or Java.
Python was made to be simpler, more readable, flexible and object oriented than what existed before - i.e. Java, Perl etc. It's actually closer to Java than it is to Ruby. Ruby is more like Smalltalk. Think of Python as Java without the stuff that mostly gets in your way, makes things awkward to do, slows you down or clutters the essence of your logic. So no semi-colons, curly braces for scoping. No static variable declaration or variables at all really they're identifiers that point to objects instead.
There's also a standard style guide for Python unlike other languages. Indentation is used to indicate scope and inconsistent indentation is a syntax error.
It also includes some often used things built into the language: lists, dictionaries, sets, generators etc.
Java is nice for those familiar with C / C++ syntax and are set in their ways, like that syntax and find it readable. Ruby and Python are for those that preferred Pascal or Smalltalk to C, like Lisp etc.
They are not similar at ALL. They all take widely different approaches to OOP, syntax, and static/dynamic typing.
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?
I currently use Python for most of my programming projects (mainly rapid development of small programs and prototypes). I'd like to invest time in learning a language that gives me the flexibility to use various Microsoft tools and APIs whenever the opportunity arises. I'm trying to decide between IronPython and C#. Since Python is my favorite programming language (mainly because of its conciseness and clean syntax), IronPython sounds like the ideal option. Yet after reading about it a little bit I have several questions.
For those of you who have used IronPython, does it ever become unclear where classic Python ends and .NET begins? For example, there appears to be significant overlap in functionality between the .NET libraries and the Python standard library, so when I need to do string operations or parse XML, I'm unclear which library I'm supposed to use. Also, I'm unclear when I'm supposed to use Python versus .NET data types in my code. For example, which of the following would I be using in my code?
d = {}
or
d = System.Collections.Hashtable()
(By the way, it seems that if I do a lot of things like the latter I might lose some of the conciseness, which is why I favor Python in the first place.)
Another issue is that a number of Microsoft's developer tools, such as .NET CF and Xbox XNA, are not available in IronPython. Are there more situations where IronPython wouldn't give me the full reach of C#?
I've built a large-scale application in IronPython bound with C#.
It's almost completely seamless. The only things missing in IronPython from the true "python" feel are the C-based libraries (gotta use .NET for those) and IDLE.
The language interacts with other .NET languages like a dream... Specifically if you embed the interpreter and bind variables by reference.
By the way, a hash in IronPython is declared:
d = {}
Just be aware that it's actually an IronPython.Dict object, and not a C# dictionary. That said, the conversions often work invisibly if you pass it to a .NET class, and if you need to convert explicitly, there are built-ins that do it just fine.
All in all, an awesome language to use with .NET, if you have reason to.
Just a word of advice: Avoid the Visual Studio IronPython IDE like the plague. I found the automatic line completions screwed up on indentation, between spaces and tabs. Now -that- is a difficult-to-trace bug inserted into code.
I'd suggest taking a look at Boo [http://boo.codehaus.org/], a .NET-based language with a syntax inspired by Python, but which provides the full range of .NET 3.5 functionality.
IronPython is great for using .NET-centric libraries -- but it isn't well-suited to creating them due to underlying differences in how the languages do typing. As Boo does inference-based typing at compile time except where duck typing is explicitly requested (or a specific type is given by the user), it lets you build .NET-centric libraries easily usable from C# (and other languages') code, which IronPython isn't suitable for; also, as it has to do less introspection at runtime, Boo compiles to faster code.
For example, in Java there is Functional Java and Higher-Order Java. Both essentially give a small API for manipulating higher-order, curried functions, and perhaps a few new data types (tuples, immutable lists).
LanguageExt looks very promising for making functional style programming in C# easier.
https://github.com/louthy/language-ext
have you looked into F#?
Also a neat blog post would be here that talks about how to use the new generic / lambda expressions built into c# 3.0.
If you just add using System.Linq to the top of your source file there are a LOT of nice new functions added to working with collections such as folding / filtering / etc.
Assuming you can't use F# for whatever reason, and just want to use functional paradigms and idioms in your C# code to improve quality & reliability:
Functional style pattern matching for C#
Monad library for C#/.Net
There is also 'elevate' which has some functional things like option types (maybes) etc.
I think you want F#
Also, the more recent versions of C# have a lot of functional concepts included in the base langauge.
There may be such a library for C#, but you should probably consider just using F# http://research.microsoft.com/fsharp/fsharp.aspx and http://msdn.microsoft.com/en-us/fsharp/default.aspx.
Microsoft plans to make F# a first-class language in Visual Studio so there should be little risk in using one of the CTPs to build your initial stuff.
If you're looking for something that extends C# then no, but there is F# which is a .NET based functional language. From the "About F#" page:
F# is a typed functional programming language for the .NET Framework. It combines the succinctness, expressivity, and compositionality of typed functional programming with the runtime support, libraries, interoperability, tools and object model of .NET. F# stems from the ML family of languages and has a core language compatible with that of OCaml, though also draws from C# and Haskell. F# was designed from the ground up to be a first-class citizen on .NET, giving smooth interoperability with other .NET languages. For example, C# and F# can call each other directly. This means that F# has immediate access to all the .NET Framework APIs, including, for example, Windows Presentation Foundation and DirectX. Similarly, libraries developed in F# may be used from other .NET languages.
Since F# and OCaml share a similar core language, some OCaml libraries and applications can cross-compile either directly or with minor conditionally-compiled changes. This provides a path to cross-compile and/or port existing OCaml code to .NET, and also allows programmers to transfer skills between these languages. A major focus of the project has been to extend the reach of OCaml-like languages into arenas where they have not traditionally been used. Throughout the project the designers of F# are grateful for the support and encouragement of Xavier Leroy and others in the OCaml community.
Not a shrink-wrapped library per se, but Luca Bolognese of Microsoft has a series of blog posts where he builds a C# library for functional programming with types like tuples, records, type unions and so on:
Also Linq is basically a library for functional programming with syntactial support in C#.
Check out http://code.msdn.microsoft.com/FunctionalCSharp for some samples.
F#, there's a CTP release available from microsoft.
One more option to consider is FuncSharp. It's not so heavy as LanguageExt and it does cover the most important patterns/aspects.