Multilanguage development - c#

I would like to develop an application with two languages.
Actually, the goal is to generate two differents application, one with a language (Java), the other on in another language (C#).
I would like to use makefiles to help me generate one application or the other one, thanks to targets definition.
I don't know where to begin.
Have you ever try to develop like this ?
Is it possible to use one makefile to call java compiler or c# compiler using different targets ?
Thanks in advance for your help.

Sure, you can use a make file to compile (and link) source files for different languages. There's no limitation. All you need is a compiler (linker) that can be called by a shell / from a command line.
Alternatives: ant can do both Java and C#. If you don't need to build both applications with a single build file, you still can use separate files and write a batch/shell script to call both builders.

Yes it is possible to override a Makefile variable to point to either javac or the .NET compiler.
You will, however, most likely not benefit from this as it is very hard to write a program that is valid in both languages.
You may want to look into http://www.ikvm.net/ which provides a Java emulation environment under .NET, so if you have a Java program it can run under .NET.

There is also the Fantom project, which claims to do that, but I have strong doubts regarding cross-platform support (how can you abstract all side-effects of all APIs?).
But I don't know the project, maybe they do a fine job.
http://fantom.org/

my idea is pretty dumb but i guess you could try this:
step 1: make a bat file
step 2: make the 2 script files
step 3: make it so it executes both of them!
#echo off
start yourfile.script
start yourfile.script
this idea is gonna fail

Related

Does c# support any scripting language

I need my superusers to write some basic expressions like (getting today, or getting first day of last month, or just returning a default int value like 40), that I can later execute and get the result. It will be used for basic scripting that will provide an optional default value for a report parameter. It would be nice if it did not require any additional installation
So does c-sharp support any scripting languages that it can happily execute and evaluate?
thanks in advance,
It's an ASP.Net application and .Net Framework 4.5
LUA is a scripting language that is able to be used from C#, take a look at LuaInterface
You can use NLua (http://nlua.org/ https://www.nuget.org/packages/NLua/)
Super easy to integrate, and work on any platform.
I recently used IronPython to provide "scripting" to a program. You can embed the IronPython runtime in your program and let it execute scripts passed as a string. Look here for some examples.
You can also execute C# code compiled on the fly. See here.
Short answer, yes.
There are a lot of different possible script engines for pretty much any possible scripting language.
Personally, i like to use C# for scripts too.
Then make the program load the script file and compile it runtime.

C# SDK for non-IDE Java developer

I've been playing with Java for years as a means of developing quick and easy tools for repetitive tasks. I am not a true "developer" in the traditional sense, but I have lots of experience creating a wide assortment of tools and PoCs.
Unfortunately for me, I have noticed many shops are specifically looking for experience with C#, and not so many for Java. Even here on SO, there are more questions and more followers to C# related issues than Java. My preference will always be Java over C# simply for the cross-platform compatibility, but since the languages are so similar, I believe it would be beneficial for me to cross-train. I have already dabbled in other languages and scripts (VB and other BASIC flavors, Javascript, VBScript, ASP, JSP, PHP, etc.) so adding another isn't out of the question.
My current Java environment simply consists of a text editor (primarily jEdit for its plugins and layout) and homemade scripts to compile/jar my projects. I don't like to use IDEs because I want full control over my code and don't want a program writing code for me. (I also prefer to write my own code as opposed to using any sort of external library/package, if feasible. It helps me learn and greatly reduces unnecessary code.)
Therefore, what are my options for a non-IDE C# SDK? Libraries are obviously not that important to me. I've heard of Mono, which appears to separate the functions, but haven't tried it yet. What other SDKs exist that are similar to a simple Java SDK combined with a text editor?
Using an IDE doesn't have to mean anything writing code for you. I'm not generally keen on designer-generated code, but unless you decide to use a designer (or snippets etc), Visual Studio won't be writing code for you. Of course it will create a skeleton class for you when you create one, add the appropriate method signatures when you implement an interface etc - but is that boilerplate really something you want to write yourself?
I'd also suggest that your policy of not using external libraries is a bad one. I agree that it's useful for educational purposes to sometimes reimplement something, but it means that the code quality is likely to end up being worse... why would you not want to use code that has already been used and improved by many other people? Yes, you need to be careful about what libraries you use - but you really don't want to do everything yourself... not if you want to be productive, anyway.
I often use a text editor and command line myself for simple test code (e.g. for Stack Overflow questions) but I wouldn't dream of doing that for "real" code that I plan to keep.
Honestly, a lot of C# and .NET is about learning the tools; Visual Studio gives you a lot that you wouldn't be able to do with a text editor. There's a free version, and I highly suggest you check it out! People hiring will want to know that you're familiar with the tools they'll most likely be using.
You can just start with Notepad and csc.exe, the the command-line C# compiler that ships with the .NET SDK.
However, IDE is not necessarily synonym for code generator. I would download Visual Studio Express and start with empty Console projects.
Have fun!
Don't forget you can build/assemble C# projects using MSBuild and a .sln file if you really want. But the IDEs will make life a lot easier.
The IDE will not write code for you, it will help you writing code. Using libraries will help you concentrate on what you really want to program, not the things that already have been done.
Check into AvalonEdit, the text editor component of SharpDevelop. It is an open source text editor that has classes that could implement features such as intellisense and syntax highlighting. You would only have to use as much of it as you wanted and you could embed it anywhere you would use a text box control.
If you are familiar with Ant from Java then you could also check out NAnt to do your compile phase.
As far as I know, with Visual Studio you also get a command line C# compiler, csc. You could use a text editor and manually compile your C# code with that on the command line if you really want - that wouldn't be very practical however when your project contains more than a handful of source files.
If your project becomes bigger, you could use a tool like NAnt, which is a .NET version of the popular Java build tool Ant.
I agree with Jon Skeet about that your way of working is not very practical. If you are really looking for a software development job, you'd better learn to use the tools that other developers use. An employer will also not accept the fact that you'd want to write all the code yourself instead of using libraries. By using libraries instead of writing it all yourself you save lots of time, you are reusing well-tested code and your code will be much easier to maintain by other developers.

Can I execute a single C# statement as a script?

I have seen online how C# allows you to compile code on the fly and I think that is a really awesome thing. I need to use this functionality for my project. But here is the problem. I'm not trying to compile a whole function or new program dynamically. I just need to call a single statement to create or delete stuff on the fly.
Is there a way C# can compile and/or run a single code statement and allow that statement to act on variables and objects in the current program's scope?
Thanks
You could compile C# using Microsoft.CSharp.CSharpCodeProvider, but that gets really complicated if you want to do it correctly, since you need to load your code in a separate App Domain to prevent memory leaks.
I'd suggest using IronPython or some other DLR language: http://www.codeplex.com/wikipage?ProjectName=IronPython
Some sample here, not sure how up-to-date it is but the idea's pretty much the same: http://www.voidspace.org.uk/ironpython/dlr_hosting.shtml
To give you an alternative rather than using C# as a scripting language, have a look at Conscript [1].
Conscript is a compiled scripting language for .NET.
[1]: http://www.codeproject.com/KB/cs/Conscript.aspx
"I just need to call a single statement to create or delete stuff on the fly." Statements like these make me shudder down to my bones. What are you trying to accomplish here, really? You want to have your user write C# statements and have your program execute them within its AppDomain? Not only is this an immense security risk, it is also a terrible user experience.
Furthermore, C# is not a scripting language. If you try to shoehorn it into being one, You're Gonna Have A Bad Time (TM).
You can, while using the debugger. At a breakpoint, just type some code into the Immediate Window in VS, and viola.
One of the best debugging features there are!
Scripting static languages comes trade-offs. There are scope and security concerns to consider, but they can be controlled.
If you're looking to execute static code (i.e. C#) from within a managed run time, I'd recommend starting with Mono. The Mono team has made strides creating a safe environment to compile JIT code into native code at run time.
Start with their official post on the subject.
It depends on what you are trying to do ... if you are looking to use it as an embedded scripting language within another application, then my answer doesn't apply, but if you just want to execute random C# statements (or programs if you like) and save them as scripts, LinqPad is awesome for that.

How to support linux for my C# project

I have a project that is an open source application for a specific type of scientific calculation that uses c++ for the backend, and C# for the front end. I'm not doing anything windows specific in the c++ portion, so I'm hoping for a relatively small learning curve there. I have a few specific questions, and I would appreciate any advice in general about this type of transition. Please keep in mind that I know absolutely nothing about Linux, but I am willing to learn.
Is there an IDE that is similar to Visual Studio? Ideally, I would like to set it up in a similar fashion to what I have now, with 2 C# solutions and a couple of c++ dlls. I really don't want to use a text editor alone and link with a command line
Is there some tool to give me an idea about problems I might have in the transition?
Is there anyway to translate my Visual Studio options to gcc options?
I know that I don't need to support Linux technically, as almost everyone in my field uses Windows, or has easy access to a Windows box, but I thought this might be interesting from a technical standpoint.
There is a IDE you can use for C# on linux - it is Mono Develop. The current version will open visual studio project and solution files, so zero knowledge is needed to migrate to it.
It uses the Mono project, which is an implementation of C# for linux.
They have created a migration tool (MoMa) so you can test your C# code and see if it will work on linux - it will provide you with hints and explanations of what isn't portable and why.
I know this isn't the c++ route you are asking about, but it is probably going to be the easiest and quickest way to make your application platform independent.
The answer to nr 1 is: MonoDevelop. Which also comes with Mono, the .NET version that's platform independent. It's a must-use when you do this transition. It runs also on Windows, which makes the learning curve less steep.
The answer to nr 2 is: I don't know..., but running your program compiled for Mono should give you a fair idea of platform specific issues you have in your code.
The answer to nr 3 is: try that as a specific question, that will give that rather complex issue the right attention and support.
The answer to nr X is: use an automatic build (NAnt or similar) to automatically build your code for several target platforms. However, it is possible that your .NET code runs unmodified for either platform (ideally it should) and only your C++ part needs special attention.
Everyone else has already mentioned MonoDevelope. But there is also MoMA which can scan a .NET application and look for commands like pInvoke that will not be portable.

How can I embed a Perl interpreter in my C# program using Mono on Linux?

Does anyone know if it's possible to call a Perl sub from Mono in C#? This is on a Linux machine.
Maybe DllImport? We want to avoid loading perl every time if possible, as well.
Interop works fine with Mono under Linux to call C-Code.
Thus I would consider that you look at perlembed.
Instead of a C-program you need to create a shared C-library.
For Interop there are several good guides - a potential pitfall are sizes of datatypes, because you get really plaform/CPU dependent.
Let me know if you need anywhere more detailed information.
This thread on PerlMonks might help.

Categories