16
Orek
6y

Just published vscode extension to auto transform object accessors to nullable / safer accessors (&& chain).

search for “vscode-oat” in marketplace.

Looking for feedbacks :)

Comments
  • 2
    Whats the background?

    I don't like this kind of checking, especially when there are function calls involved that execute a numerous times just to get a part of the last call.
  • 2
    JavaScript doesn’t have “safe navigation”, the ?. operator https://en.m.wikipedia.org/wiki/... ? Looks like CoffeeScript does, I wonder how they unroll it then....
  • 2
    @bkwilliams nope no safe navigation in vanilla JS. You most likely end up doing what op's extension does.

    One could also use lodash's get method.
  • 2
    @Commodore when C# got it it changed my coding style completely, much more readable.
  • 0
    @010001111 In the company I’m currently working we dont have access to source, to be able to use default functionalities / data we must wait for it to arrive first. So this is the way we are dealing with exceptions. && operator is the most optimized solution found so far.
  • 0
    @bkwilliams custom accessor functions are very slow in comparison to try catch or && operators
  • 1
    @Commodore its very slow, you can check plugin’s page I published tests with few methods, && seems to be most optimized way so far
  • 0
    @bkwilliams for js there is a stage 3 proposal for elvis like accessor but it may take ages to see it in browsers
  • 1
    @Orek yes it is. Don't get me wrong, I'm not arguing the usefulness of your extension. Checking every property is a pain. Although I tend to try avoid such problems by either flattening my data structure or using variables.
  • 1
    @Commodore && chain is much faster than _get and you don’t need to import a library to your project by this extension :)) I understand and appreciate your comment. Yes in cases where you can influence the object you are going to use that totally makes sense
Add Comment