Skip to content

[Enhancement] Keep Native Platform API with the same name convention as it is in Native Platform #522

Closed

Description

@redradist

Summary

I have lots of experience in Xamarin.Forms and Xamarin in general and one of the issues in this framework is that when I copy platform example to .NET project it is not working without renaming the whole API !!

API Changes

I think it would be helpful to have the same API name conversion as in Native Platform or at least to provide the same API in two variants:

// C# naming conversion
var toast = Toast.MakeText(context, text, duration);
toast.Show();

// Android naming conversion
var toast = Toast.makeText(context, text, duration);
toast.show();

As all Native Platform API Bindings generated by external tool, it means that we could generate two functions instead of one:

class Toast
{
  Toast MakeText(...)
  {
    ...
  }
  Toast makeText(...)
  {
    return MakeText(...);
  }
}

There are lots of frameworks that support Native Platform API as it is: NativeScript, Tensorflow.NET, and it seems very useful

Intended Use Case

Intended to be easier to learn platform API

Activity

  1. GalaxiaGuy commented on Mar 17, 2021

    @GalaxiaGuy
    Contributor

    The bindings to the native platform are maintained in https://github.com/xamarin/xamarin-android and https://github.com/xamarin/xamarin-macios for Android and iOS respectively, and so those repose would be the better places to bring this up.

    However, I doubt you will get much support as the advantages seem minimal. You say that you have to rename the whole API when copying platform examples - in my experience much more has to change when copying native Android code and just changing case is a small part. This will only increase as more is written in Kotlin.

  2. redradist commented on Mar 17, 2021

    @redradist
    Author

    The bindings to the native platform are maintained in https://github.com/xamarin/xamarin-android and https://github.com/xamarin/xamarin-macios for Android and iOS respectively, and so those repose would be the better places to bring this up.

    However, I doubt you will get much support as the advantages seem minimal. You say that you have to rename the whole API when copying platform examples - in my experience much more has to change when copying native Android code and just changing case is a small part. This will only increase as more is written in Kotlin.

    @GalaxiaGuy I agree that it is maintained by separate projects, but only guys that develop MAUI can decide to request this feature for next major framework as MAUI otherwise guys in that project will just reject this request

    And regarding the Kotlin, Android documentation provides examples for both Java and Kotlin languages ;)

  3. changed the title [-][Enhancement] Keep Native Platform API with the same name convension as it is in Native Platform[/-] [+][Enhancement] Keep Native Platform API with the same name convention as it is in Native Platform[/+] on Mar 19, 2021
  4. hartez commented on Mar 19, 2021

    @hartez
    Contributor

    This would be a breaking change for all existing Xamarin.Android and Xamarin.iOS code, and cause a similar problem for anyone porting existing Xamarin.Forms code to MAUI. Plus those names would violate the C# and .NET naming conventions; since MAUI is part of .NET, we need to remain consistent with those naming conventions.

    That said, there may be some demand for a Visual Studio extension which can automatically convert pasted Java examples into C# by fixing names and casing. Maybe someone in the community can take a stab at that.

  5. redradist commented on Aug 31, 2021

    @redradist
    Author

    @hartez

    This would be a breaking change for all existing Xamarin.Android and Xamarin.iOS code, and cause a similar problem for anyone porting existing Xamarin.Forms code to MAUI. Plus those names would violate the C# and .NET naming conventions; since MAUI is part of .NET, we need to remain consistent with those naming conventions.

    That said, there may be some demand for a Visual Studio extension which can automatically convert pasted Java examples into C# by fixing names and casing. Maybe someone in the community can take a stab at that.

    Oh ... Some of Microsoft guys think differently as I mentioned in dotnet/machinelearning#5918
    (they will support Python naming convention)

    Also I do not ask to break existing code, I ask to generate method with two names ...
    Also it can be generate in separate namespace like Microsoft.Maui.Android.Native without breaking of Microsoft.Maui.Android symbols

  6. ghost locked as resolved and limited conversation to collaborators on Feb 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposal/opent/enhancement ☀️

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions