Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use enhanced enums #80

Closed
5 of 6 tasks
JosefWN opened this issue Apr 19, 2022 · 13 comments
Closed
5 of 6 tasks

Use enhanced enums #80

JosefWN opened this issue Apr 19, 2022 · 13 comments

Comments

@JosefWN
Copy link
Contributor

JosefWN commented Apr 19, 2022

When Dart 2.17 is released, enhanced enums will simplify our code a bit: dart-lang/sdk#47849

Examples:

  • Block option SZX could be an int enum
  • CoapCode could be broken down into int enums
  • CoapMediaType could be int enum
  • CoapMessageType could be int enum
  • Request.observe could be int enum?
  • CoapDefinedAddress could be string enum?
@JKRhb
Copy link
Contributor

JKRhb commented May 11, 2022

Dart 2.17 has just been released by the way :) https://medium.com/dartlang/dart-2-17-b216bfc80c5d

@shamblett
Copy link
Owner

Yes, got it, FFI updates and experimental RISCV support are good news for me with my IOT hat on.

@JKRhb
Copy link
Contributor

JKRhb commented May 15, 2022

I just noticed that the option type numbers might also be an interesting place where the enhanced enums could be used. I'll try to come up with a PR for that soon.

@JKRhb
Copy link
Contributor

JKRhb commented Jun 17, 2022

I started working on refactoring the CoapCodes using enhanced enums by the way :)

@JosefWN
Copy link
Contributor Author

JosefWN commented Jun 20, 2022

A couple of minor things I noticed, which will likely resolve themselves with the re-write, but mentioning just in case. Not all codes are represented in codeToString (at least continues is missing), and the fallback doesn't show the code:

    if (isValid(code)) {
      if (isRequest(code)) {
        return 'Unknown Request [code {0}]'; // `$code` rather than `{0}`?
      // ...

Somewhat related: I suppose toString in CoapMessage could also use a typeString getter (like codeString) for type. Then we would get: Type: NON rather than Type: 1 in the printouts.

@JKRhb
Copy link
Contributor

JKRhb commented Aug 7, 2022

  • Block option SZX could be an int enum
  • CoapCode could be broken down into int enums
  • CoapMediaType could be int enum
  • CoapMessageType could be int enum
  • Request.observe could be int enum?
  • CoapDefinedAddress could be string enum?

I think from this list, we could mark CoapCode, CoapMediaType, and CoapMessageType as resolved now :) Should we maybe turn this issue into a task list for tracking the remaining candidates for enhanced enums?

@JosefWN
Copy link
Contributor Author

JosefWN commented Aug 7, 2022

Done! :)

@shamblett
Copy link
Owner

Package re released at version 5.0.0.

@JKRhb
Copy link
Contributor

JKRhb commented Aug 12, 2022

Thank you for releasing the new version, @shamblett! I think we could reopen this issue, though, as there are still a couple of places where enhanced enums could be used (see the task list above).

@shamblett
Copy link
Owner

Yes no.problem a bit overly aggressive with my tidy up.

@shamblett shamblett reopened this Aug 12, 2022
@JKRhb
Copy link
Contributor

JKRhb commented Oct 16, 2022

Block option SZX could be an int enum

This is now also addressed by #122 and can be checked once the PR has been merged :)

@JKRhb
Copy link
Contributor

JKRhb commented Oct 27, 2022

I think with #136 and #122 we have covered all checkboxes in @JosefWN's initial comment :) Do you see any more potential for refactoring with enhanced enums?

@JosefWN
Copy link
Contributor Author

JosefWN commented Oct 31, 2022

LGTM!

@JosefWN JosefWN closed this as completed Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants