question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Color type is now a `class` instead of `struct`

See original GitHub issue

I have been back and forth on this one, but it is still a large breaking change that will affect users. Maybe. I am not sure exactly how this affects all the code when recompiled, but it is different.

This will matter though when there are new null ref exceptions popping up, but hopefully tooling can aid with that.

Most frameworks are structs - except for iOS - and this may be unexpected.

@jonlipsky did mention that he noticed some perf improvements with TouchDraw, but this might need a check on say Android with the GC. It may be that it is fine and the GC is OK and that copying structs is more expensive.

@Clancey mentions a nicer reading:

var foo = color?.ToNative() ?? defaultColor
// vs
var foo = color == Color.Default ? defaultColor : color.ToNative()

This is true, but it is also the same with Color? as a nullable.

This also relates to #57 where there is no longer a Default “color” and null is used.

Relates to parent issue: #58

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
hartezcommented, Apr 10, 2021

Even with nullable structs, the code won’t be clean. You still need to check if it is default value. So the nullable struct is even uglier.

That’s only if we decide to use a struct AND keep a Color.Default. If we remove Color.Default, make Color a struct, and go with the convention that cross-platform colors default to null, then we end up with your cleaner-looking code. E.g., if my cross-platform property is

public Color? MyColor { get; set; }

Then my translation to a native color looks something like

var color = Element.MyColor?.ToNative() ?? GetNativeDefaultColor();

Where GetNativeDefaultColor is doing the work of determining what “default” means given the control type, usage, current theme, etc.

2reactions
charlesroddiecommented, Apr 10, 2021

+1 should be a struct

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting error when trying to use pointer with struct
You're creating a series of pointers to struct Color , but you're not initializing any of them, so because they're defined at file...
Read more >
Difference between Class and Structure in C# - ...
In C#, both classes and structures are used to define custom data types, but there are some differences between them. Inheritance: A class...
Read more >
Class vs Struct in C#: Making Informed Choices
Structs are lighter than Classes. The difference is that classes are reference types while structs are value type. This drastically impacts ...
Read more >
C# Struct VS Class: Key Differences
Structs are value types, meaning they are copied when passed around or assigned to variables, while classes are reference types, meaning they ...
Read more >
When should structs be used instead of classes in C++?
There are two answers to this question 1. Struct and class are pretty much the same, except that the members of a struct...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found