How to organize F# and C# side by side [closed] - c#

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
The project I am working on will have to be migrated from C# to F# based on what brings food on the table tomorrow - in other words, the two languages have to live side by side in this project for years to come.
The problem I am faced with repeatedly is how I should organize projects in the solution to meet this need.
I translate pieces from C# to F# all the time, because it frequently shortens the development time and increases the quality. But I end up with C# code that wants to use F# code, and F# code that want to use C# code, in the same layer, or at boundaries between layers or modules. I find myself putting code in the wrong projects just to avoid creating yet another project in some layer.
The situation is not bad now, but I worry that I will paint myself into a corner at some point, unless I can come up with a pattern or a structure, or simply understand the problem better.
Is there some modification to a normal F# architecture - a pattern, a substructure or a superstructure - that is well suited to such a mixed solution?
Are there patterns that are known to be especially helpful in solving this particular challenge?

Use an interface to communicate between the two languages.
Typically when porting, f# is the lower-level dll and C# can call f# as usual.
Now for f# to call c# define an interface in the f# dll (e.g. IClibApi) that is implemented in c# (e.g. ConcreteClibApi extends IClibApi). Create an instance of ConcreteClibApi and pass it to f#. Now f# can call c# thru IClibApi.
Later you can start porting ConcreteClibApi :)

Related

Dynamically creation some code during runtime [duplicate]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I work in a code base that is quite large and today I found a project that was emitting IL code inside a normal class.
The project containing the IL code being emitted was a implementation of a Service Locator MSDN Desctiption.
What are the advantages of doing this and why would this be done as apposed to using the C# language?
Typically this is done to circumvent the overhead of using reflection, using information only available at runtime.
You would then use reflection, which can be slow depending on what you do, to build a new piece of code that works directly with the data given to it, without using reflection.
Advantages:
Performance
Disadvantages:
Hard to debug
Hard to get right
Hard to read code afterwards
Steep learning curve
So you need to ensure it's really worth the price before embarking on this.
Note that this is a general answer. In the specific case you came across, there is no way to answer why this was done nor which particular advantages (or disadvantages) you would have without actually seeing the code.
There are many uses for this.
One of the more often used scenario is for changing/injecting code on the fly:
.NET CLR Injection: Modify IL Code during Run-time
A good tutorial that help me to understand a good use for it is:
Dynamic... But Fast: The Tale of Three Monkeys, A Wolf and the DynamicMethod and ILGenerator Classes
Good luck

Using deep learning models from TensorFlow in other language environments [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a decent amount of experience with TensorFlow, and I am about to embark on a project which will ultimately culminate in using a TensorFlow trained model in a C# production environment. Essentially, I will have live data which will come into the C# environment, and I will ultimately need to output decisions / take certain actions based on the output of my model in TensorFlow. This is basically just a constraint of the existing infrastructure.
I can think of a couple of potentially bad ways to implement this, such as writing the data to disk and then calling the Python part of the application and then finally reading the result output by the Python application and taking some action based on it. This is slow, however.
Are there faster ways to accomplish this same integrated relationship between C# and the Python-based Tensorflow. I see that there appear to be some ways to do this with C++ and TensorFlow, but what about C#?
This is a prime use case for TensorFlow Serving, which lets you create a C++ process that can run inference on a trained TensorFlow model, and serves inference requests over gRPC. You can write client code in any language that gRPC supports. Take a look at the MNIST tutorial: C++ server and Python client components.

Real time use of abstract, sealed and static class [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
If I've some common functionality that I've to keep in a class, so will I go for static, sealed or abstract class...Does all these types of classes serve the purpose of keeping the common functionality together...where actually the difference lies when I've to go for one
abstract, sealed, static has nothing to do with real time development. It has to do with bring structure within your software, so that the functionality implemented in classes can and should be used in the right way.
After some comments i think this:
I think you can only learn this, by doing it. There isn't a book or epub that will explain you how to do programming. They will show the syntax and some examples. It will be trial and error. Every day you'll face a new challenge.
You'll have to practice it. The best advise is, look what others already created and try to imagine why did they wrote/solve it that way.
I can explain what a static/sealed/abstract class is/does, but it doesn't learn you when to use it.
Back to the question: Define 'real time'.. I think that static/abstract/sealed should NOT be decisive on how you write your 'real-time' software. If you are 'scared' about performance on this level, C# should not be your choise. I would write c++ or if you want a real challenge, try to beat the compilers with asm ;-)
I think you won't measure the 'overhead'
So, use abstract/static/sealed in a right way, so your future collega's/you can read/maintain it.
I use C# for communication (tcp/ip) between a windows computer and a PLC (with delta robots). But it's far from realtime. It's fast enough to keep many robot working with > 100 messages per second.

Is there anything that I can do with Perl/Python but C# would not do? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have done some development in C# and I love the language and the environment. I am taking a Perl class, and yes it sounds like easy learning curve, but there are some questions which I think need to be asked essentially as a server-side developer.
So far, if I want to create a stripped-down program which runs on a Windows machine then I can create a console application. C# + .NET are good enough that I can achieve most of the functionality.
Now, when scripting languages come into picture, I agree that they are easy to use and easy to write. The languages have super-rich functional libraries. But is is just a choice that we make to use a scripting language as opposed to a fully-fledged framework like .NET? Or are there some things that only scripting languages can do, and would be very difficult to achieve from languages like C# and Java?
C# is Turing-complete, so the answer to your question is "no".
.NET has nothing to do with your question; other languages have their own "full fledged framework"s (or more than one).

Porting a Visual C++ project to C# [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I got my hands on some well documented C++ code that's about 1KLOC. It would take me a significant amount of time to port this line by line and debug the results, so I'm wondering if there are tools or ways to do it faster, and I have questions in case I have to do it fully manually.
Specific questions:
Does C# also support overriding operators like * and +?
What to do with the C++ memory management code like alloc() and free()?
How to identify functions used from <stdio.h>, <conio.h> and <math.h>?
How to find replacements to such system functions?
Does C# have any special/open source libraries that provide such functions?
No graphics libraries have been used, its purely command line based.
You might want to try this tool and see if that works out for you. There is a demo where you translate up to a 100 lines of code at a time:
http://tangiblesoftwaresolutions.com/Product_Details/CPlusPlus_to_CSharp_Converter_Details.html
Try it out and let us know. But it would prolly be more beneficial to port this yourself in c# so you can get a handle of the features that c# comes with.
You will need to do it manually, and 1KLOC isn't much.
However, you will need to learn C#.
To answer your questions:
Yes
Depending on what you're doing, probably List<T>
I don't know what you're asking
Look in the .Net Framework class library on MSDN
Yes
1 - C# also support operator overloading see : http://msdn.microsoft.com/en-us/library/aa288467(VS.71).aspx (it looks very much to c++ operator overriding)
2 - C# is garbage collected so you only need "new" instead of alloc. free is done by the garbage collector
3 - I have no idea , but when porting code you would have to find in standard c# library the equivalents
4 - In MSDN there is a lot of information.
5 - ( http://code2code.net/ ) ??? but better to do it at hand
More information on coding standards : http://msdn.microsoft.com/en-us/library/xzf533w0.aspx
ie naming: http://msdn.microsoft.com/en-us/library/x2dbyw72.aspx

Categories

Resources