104
Vote

Generics support for MF

description

Provide support for generics types for .NET MF.
This support is particularly necessary when porting small projects or libraries from the desktop, where re-working the code is not prohibitive but re-testing is delicate.
Having generics would allow to skip most of the testing altogether thus allowing true interoperability.
Furthermore a source code could be shared by adding an existing desktop source using "add as a link" in Visual Studio. The directives #define/#if can adjust the differences between MicroFramework and desktop implementations.
 
Real use case example: exchanging data between a balance and the MF device
  • write the source code for the desktop using the serial port
  • the collected data from the balance will use for example List<T> to provide more robustness
  • test the protocol implementation on the desktop
  • create a new library MF project
  • "add as link" the desktop source code in the MF project
  • add required #define and #if/#endif as required (for example to fix "using" namespaces definitions)

comments

staceyw wrote Mar 30, 2011 at 3:06 PM

+1. Doing things like simple ports for things like Rx or Linq ports loose of a lot of luster when having to resort to Object.

rogihee wrote Apr 14, 2011 at 7:35 PM

+1. I recently ported a project from desktop USB automotive device to embedded FEZ Cobra where I created a new micro project with "add as link" for the core "model". Not having generics for simple things as list<type> was the biggest hurdle to overcome.

juliusfriedman wrote Apr 20, 2012 at 1:02 PM

Also I just realized that similar to how you can use IL to allow mathematica operations across double and integer types by modifying the DLL after compilation you can probably utilize reflection and or some type of indirection to perform the same operations in the MF.

http://www.codeproject.com/Articles/33617/Arithmetic-in-Generic-Classes-in-C

http://stackoverflow.com/questions/1251507/is-it-possible-to-call-value-type-operators-via-reflection

If we can't have generics then possibly also the addition of the Dynamic Type would be helpful for these types of scenarios inter alia.

juliusfriedman wrote Apr 16, 2013 at 12:25 AM

This might be applicable for a way of thinking about generics if you know what your doing.

If we had use of the Emit class this would be almost implementable here on the Micro Fx.

http://www.codeproject.com/Articles/578116/Complete-Managed-Media-Aggregation-Part-III-Quantu

raffaeler wrote Apr 16, 2013 at 12:14 PM

The main point for my request is to ease porting code.
I can also write a code generator on desktop which starts from generic classes and create all the possible variants of the untyped classes, but it's tedious and not easy to mantain.

We are now in 2013 and the market offers Raspberry PI for ridiculous prices with a full OS. Microframework can still make sense but the support should absolutely be first-class, otherwise there is no story.

TomSpilman wrote Apr 21, 2013 at 8:37 PM

What is the status of this? I know that some work has happened to support generics, what happened to that?

dthorpe wrote Oct 13, 2013 at 10:45 AM

Need generics.

The sub-300kb MF system memory budget was admirable 5 years ago, but with $80 mainboards now shipping with 16MB of RAM the memory budget argument against generics no longer holds water. It's time to move the platform forward.

mikeorb wrote Oct 3 at 12:01 AM

Generics please! I have very large API with generics throughout, beyond collections. Using generics in base classes, for example. I cannot use NETMF because of this limitation.

raffaeler wrote Oct 3 at 8:28 AM

mikeorb, I suggest you to use Mono on Raspberry Pi.
It's a very cheap hardware where mono give you full support of the .NET Framework 4.5 ... even the asynchronous task management and the full asp.net/owin stack where you can host a full-featured self-hosted WebApi service.

juliusfriedman wrote Oct 4 at 2:44 PM

Its not that difficult to add generics, or something like emit.

I would volunteer to add it but im working on a media library full time, after that I would be happy to improve regex and implement generics and possibly something like emit.

raffaeler wrote Oct 4 at 3:22 PM

Let's face to reality and compare the hw price and power, then .net language and library completeness, ... there is no competition.
Nowdays the gap is huge.

juliusfriedman wrote Oct 4 at 3:39 PM

Depends on where your coming from or going to, there is always competition especially when you consider the form factor and requirements for the platform.

More power isn't always the solution especially when it has to fit in something like a watch.

raffaeler wrote Oct 4 at 4:14 PM

I don't get your point.
Smartwatches already run super-powered CPUs with full featured operating systems.
For example Moto360 use ARM A8 (TI based chipset > 600MHz) with Linux/Android.

I loved Microframework. I wrote the first article on the microframework blog and opened this thread.
But let's face to reality, that time has gone. Hardware is better in price and power.
Small microcontrollers (like PIC, Atmel and Arduino) still make sense because you have the power of real-time processing over the microsecond but higher abstractions can use exactly the same resources of a PC with the big advantage of portability, testing and faster prototyping.

JanKucera wrote Oct 4 at 7:47 PM

Is anybody after the generics benefits actually? Because everybody so far seems to be concerned about code compatibility/reusability, in which case generics by syntactic sugar would do.