www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Porting C# code

reply Brien <reply tolist.com> writes:


Are there any tools that can help me do this?
Jan 06 2010
parent reply BCS <none anon.com> writes:
Hello Brien,


 
 Are there any tools that can help me do this?
 
I've got a tool that will handle some of the porting but it has a number of limitations. For one, it only handles a very limited set of .NET (exactly Zero GUI, mosly only bits of the File I/O, regex and other "back end" kind of stuff) and it has some somewhat arbitrary formatting limitations. It would take me a bit but I could prob'ly dig out the code.
Jan 06 2010
parent reply Brien <reply tolist.com> writes:
Hi BCS,

I'd really appreciate it.  I'm looking to port over a network server
application so the GUI stuff shouldn't be a problem.  I've also kept my source


Did you write your own parser or base it on ANTLR or some other
parsing/compiling library?

I wonder if it is possible to fully automate the conversion process- if you



public class Foo {
    public /*  shared */ int bar;
}

which could get translated as a shared variable.


port to D where I would be able to use native techniques on critical areas of
the code.

-Brien
Jan 07 2010
next sibling parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Thu, 07 Jan 2010 09:23:47 -0500, Brien <reply tolist.com> wrote:

 Hi BCS,

 I'd really appreciate it.  I'm looking to port over a network server  
 application so the GUI stuff shouldn't be a problem.  I've also kept my  


 Did you write your own parser or base it on ANTLR or some other  
 parsing/compiling library?

 I wonder if it is possible to fully automate the conversion process- if  




 public class Foo {
     public /*  shared */ int bar;
 }

 which could get translated as a shared variable.


 optimized port to D where I would be able to use native techniques on  
 critical areas of the code.
Note there is a D compiler for .NET, which may allow you to avoid porting parts of it. I've never used it, but it has been announced here somewhere. -Steve
Jan 07 2010
parent reply Brien <reply tolist.com> writes:
 Note there is a D compiler for .NET, which may allow you to avoid porting  
 parts of it.  I've never used it, but it has been announced here somewhere.
 
 -Steve
I saw that, but my goal is to get off of .NET. I'm assuming I will be able to get better performance out of optimized D running on Linux versus optimized .NET on Windows or Mono. Is that a safe assumption?
Jan 07 2010
parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Thu, 07 Jan 2010 09:53:32 -0500, Brien <reply tolist.com> wrote:

 Note there is a D compiler for .NET, which may allow you to avoid  
 porting
 parts of it.  I've never used it, but it has been announced here  
 somewhere.

 -Steve
I saw that, but my goal is to get off of .NET. I'm assuming I will be able to get better performance out of optimized D running on Linux versus optimized .NET on Windows or Mono. Is that a safe assumption?
It depends on what you are doing. If you rely heavily on the GC, .NET's GC is much more mature than D's, and probably performs better. -Steve
Jan 07 2010
parent Brien <reply tolist.com> writes:
Steven Schveighoffer Wrote:
 It depends on what you are doing.  If you rely heavily on the GC, .NET's  
 GC is much more mature than D's, and probably performs better.
For performance reasons, I've taken great pains to avoid steady state memory allocations. I've got a lot of mid-life crisis type allocations so I'm forced to avoid the GC which would spend all day doing Gen2 collections. I'm looking at D as a way to gain a speed boost and allow me to get off of Windows for my production runtime.
Jan 07 2010
prev sibling parent reply BCS <none anon.com> writes:
Hello Brien,

 Hi BCS,
 
 I'd really appreciate it.  I'm looking to port over a network server
 application so the GUI stuff shouldn't be a problem.  I've also kept

 
 Did you write your own parser or base it on ANTLR or some other
 parsing/compiling library?
I took the cheap solution of a state machine and per-line regex.
 
 I wonder if it is possible to fully automate the conversion process-



 
 public class Foo {
 public /*  shared */ int bar;
 }
 which could get translated as a shared variable.
 
The output is D 1.0

 optimized port to D where I would be able to use native techniques on
 critical areas of the code.
That might be viable but the system was never intended for speed (its intent was as a way to escape needing Mono on a non Windows system) so you would I'll look into digging it out.
Jan 07 2010
parent reply Brien <reply tolist.com> writes:
BCS Wrote:
 That might be viable but the system was never intended for speed (its intent 
 was as a way to escape needing Mono on a non Windows system) so you would 

Ok, that's good to know. I assumed because D billed itself as a "systems" programming language that performance would be paramount. I'm sure I'm the millionth person to ask this, but- is there a language out there that is bare metal like C/C++ with the friendlier syntax and developer
Jan 07 2010
next sibling parent reply Don <nospam nospam.com> writes:
Brien wrote:
 BCS Wrote:
 That might be viable but the system was never intended for speed (its intent 
 was as a way to escape needing Mono on a non Windows system) so you would 

Ok, that's good to know. I assumed because D billed itself as a "systems" programming language that performance would be paramount.
He's talking about his converter program, not about D!
 I'm sure I'm the millionth person to ask this, but- is there a language out
there that is bare metal like C/C++ with the friendlier syntax and developer

D is trying to be exactly that. We don't have the infrastructure yet, though. So the productivity gains are a bit theoretical at present...
Jan 07 2010
parent reply Brien <reply tolist.com> writes:
Don Wrote:

 Ok, that's good to know.  I assumed because D billed itself as a "systems"
programming language that performance would be paramount.
He's talking about his converter program, not about D!
Oops, sorry about the misinterpretation.
 I'm sure I'm the millionth person to ask this, but- is there a language out
there that is bare metal like C/C++ with the friendlier syntax and developer

D is trying to be exactly that. We don't have the infrastructure yet, though. So the productivity gains are a bit theoretical at present...
Cool. That being the case, I'm not sure I can give up my addiction to Jetbrains about library support- I can reimplement whatever I need, just the language itself. Also, is the threading support and memory model of D1.0 solid and performant? I'm a little unclear about how synchronization is achieved. I see the synchronized keyword and I've seen some references to using mutexes, but I don't really have a clear picture. Thanks
Jan 07 2010
parent reply Lutger <lutger.blijdestijn gmail.com> writes:
On 01/07/2010 10:50 PM, Brien wrote:
 Don Wrote:

 Ok, that's good to know.  I assumed because D billed itself as a "systems"
programming language that performance would be paramount.
He's talking about his converter program, not about D!
Oops, sorry about the misinterpretation.
 I'm sure I'm the millionth person to ask this, but- is there a language out
there that is bare metal like C/C++ with the friendlier syntax and developer

D is trying to be exactly that. We don't have the infrastructure yet, though. So the productivity gains are a bit theoretical at present...
Cool. That being the case, I'm not sure I can give up my addiction to Jetbrains about library support- I can reimplement whatever I need, just the language itself. Also, is the threading support and memory model of D1.0 solid and performant? I'm a little unclear about how synchronization is achieved. I see the synchronized keyword and I've seen some references to using mutexes, but I don't really have a clear picture. Thanks
Wouldn't it be more efficient for you and the code to implement the easily do extern(C) so it's not much work, much less probably than massaging an automated port. If you go with D1 take a look at the ldc compiler and the tango documentation for class libraries (these should contain a fair bit of information): www.dsource.org/projects/tango www.dsource.org/projects/ldc
Jan 07 2010
next sibling parent Lutger <lutger.blijdestijn gmail.com> writes:
On 01/07/2010 11:59 PM, Lutger wrote:
 On 01/07/2010 10:50 PM, Brien wrote:
 Don Wrote:

 Ok, that's good to know. I assumed because D billed itself as a
 "systems" programming language that performance would be paramount.
He's talking about his converter program, not about D!
Oops, sorry about the misinterpretation.
 I'm sure I'm the millionth person to ask this, but- is there a
 language out there that is bare metal like C/C++ with the friendlier

D is trying to be exactly that. We don't have the infrastructure yet, though. So the productivity gains are a bit theoretical at present...
Cool. That being the case, I'm not sure I can give up my addiction to Jetbrains Resharper. Do you think a fully automated translation from tools? I'm not too worried about library support- I can reimplement whatever I need, just the language itself. Also, is the threading support and memory model of D1.0 solid and performant? I'm a little unclear about how synchronization is achieved. I see the synchronized keyword and I've seen some references to using mutexes, but I don't really have a clear picture. Thanks
Wouldn't it be more efficient for you and the code to implement the easily do extern(C) so it's not much work, much less probably than massaging an automated port. If you go with D1 take a look at the ldc compiler and the tango documentation for class libraries (these should contain a fair bit of information): www.dsource.org/projects/tango www.dsource.org/projects/ldc
it. Seems like it hasn't been updated for 2 years: http://www.dsource.org/projects/nanu
Jan 07 2010
prev sibling parent reply BCS <none anon.com> writes:
Hello Lutger,

 On 01/07/2010 10:50 PM, Brien wrote:
 
 Don Wrote:
 
 Ok, that's good to know.  I assumed because D billed itself as a
 "systems" programming language that performance would be paramount.
 
He's talking about his converter program, not about D!
Oops, sorry about the misinterpretation.
 I'm sure I'm the millionth person to ask this, but- is there a
 language out there that is bare metal like C/C++ with the

 
D is trying to be exactly that. We don't have the infrastructure yet, though. So the productivity gains are a bit theoretical at present...
Cool. That being the case, I'm not sure I can give up my addiction to Jetbrains Resharper. Do you think a fully automated translation from tools? I'm not too worried about library support- I can reimplement whatever I need, just the language itself. Also, is the threading support and memory model of D1.0 solid and performant? I'm a little unclear about how synchronization is achieved. I see the synchronized keyword and I've seen some references to using mutexes, but I don't really have a clear picture. Thanks
Wouldn't it be more efficient for you and the code to implement the easily do extern(C) so it's not much work, much less probably than massaging an automated port.
IIRC managed<->un-managed calls are insanely expensive. If you do this,profile the Snot out of it to be sure you actually get a gain out of it.
Jan 07 2010
next sibling parent Brien <reply tolist.com> writes:
BCS Wrote:
 IIRC managed<->un-managed calls are insanely expensive. If you do this,profile 
 the Snot out of it to be sure you actually get a gain out of it.
I can confirm that. The thunk layer is pretty heavy weight and tends to code gen doesn't seem to deal with that very efficiently. And lastly, it does really poorly optimizing value type structs so the builtin features that could theoretically get you closer to the metal don't in reality.
Jan 08 2010
prev sibling parent reply Iivari Mokelainen <iivari mokelainen.com> writes:
BCS wrote:
 Hello Lutger,
 
 On 01/07/2010 10:50 PM, Brien wrote:

 Don Wrote:

 Ok, that's good to know.  I assumed because D billed itself as a
 "systems" programming language that performance would be paramount.
He's talking about his converter program, not about D!
Oops, sorry about the misinterpretation.
 I'm sure I'm the millionth person to ask this, but- is there a
 language out there that is bare metal like C/C++ with the

D is trying to be exactly that. We don't have the infrastructure yet, though. So the productivity gains are a bit theoretical at present...
Cool. That being the case, I'm not sure I can give up my addiction to Jetbrains Resharper. Do you think a fully automated translation from tools? I'm not too worried about library support- I can reimplement whatever I need, just the language itself. Also, is the threading support and memory model of D1.0 solid and performant? I'm a little unclear about how synchronization is achieved. I see the synchronized keyword and I've seen some references to using mutexes, but I don't really have a clear picture. Thanks
Wouldn't it be more efficient for you and the code to implement the easily do extern(C) so it's not much work, much less probably than massaging an automated port.
IIRC managed<->un-managed calls are insanely expensive. If you do this,profile the Snot out of it to be sure you actually get a gain out of it.
Every managed->unmanaged call is checked somehow, and there was an attribute which lets you do pinvoke calls extremely fast but unsafe. printf perfomance was pretty much the same as in C++ with that attribute. Its used internally to do OS calls very fast, iirc it was undocumented. Try some disassemblers on .net framework, mainly parts that do OS calls. Good Luck - data
Jan 08 2010
parent Brien <reply tolist.com> writes:
Iivari Mokelainen Wrote:
 Every managed->unmanaged call is checked somehow, and there was an 
 attribute which lets you do pinvoke calls extremely fast but unsafe. 
 printf perfomance was pretty much the same as in C++ with that 
 attribute. Its used internally to do OS calls very fast, iirc it was 
 undocumented. Try some disassemblers on .net framework, mainly parts 
 that do OS calls.
 
 Good Luck
 
 - data
Pinvoke is no good for functions that are fast and invoked a lot. Here's some good proof http://community.opennetcf.com/articles/cf/archive/2008/01/31/performance-implications-of-crossing-the-p-invoke-boundary.aspx -Brien
Jan 08 2010
prev sibling parent BCS <none anon.com> writes:
Hello Brien,

 BCS Wrote:
 
 That might be viable but the system was never intended for speed (its
 intent was as a way to escape needing Mono on a non Windows system)

 
Ok, that's good to know. I assumed because D billed itself as a "systems" programming language that performance would be paramount. I'm sure I'm the millionth person to ask this, but- is there a language out there that is bare metal like C/C++ with the friendlier
(Ignoraing IDE/tool chain issues) Yes, D. won't be getting some of the available speed advantages that D can give you. You end up with the union of the problems and the intersect of the advantages.
Jan 07 2010