Git Product home page Git Product logo

Comments (10)

probablycorey avatar probablycorey commented on September 18, 2024

/cc @nathansobo @benogle

from api.

kevinsawicki avatar kevinsawicki commented on September 18, 2024

Can you give an example of what you mean by "helper method"?

from api.

probablycorey avatar probablycorey commented on September 18, 2024

Config is a good example to explain helper methods and other examples of things
I would like to fix.

Here is the current API for config with usage stats

Config                                                       called packages atom packages
--
::get(keyPath)                                               732    250      21
::observe(keyPath, options, callback)                        149    80       10
::set(keyPath, value)                                        70     30       4
::unobserve(keyPath)                                         38     26       0
::toggle(keyPath)                                            9      4        2
::getSettings()                                              8      6        1
::getDefault(keyPath)                                        5      3        1
::getPositiveInt(keyPath, defaultValue)                      4      4        2
::getInt(keyPath)                                            2      2        0
::getUserConfigPath()                                        1      1        0
::pushAtKeyPath(keyPath, value)                              0      0        0
::unshiftAtKeyPath(keyPath, value)                           0      0        0
::removeAtKeyPath(keyPath, value)                            0      0        0
::isDefault(keyPath)                                         0      0        1
::restoreDefault(keyPath)                                    0      0        0

Here is what I would like Config to look:

Config                                                         called packages atom packages
--
::get(keyPath)                                               732    250      21
::observe(keyPath, options, callback)                        149    80       10
::set(keyPath, value)                                        70     30       4

Helper Methods

I'm defining helper methods as a method that can be recreated using other API
methods. They exist for convenience and can be recreated with a few lines of
code. I consider getPositiveInt, getInt, toggle, pushAtKeyPath and
removeAtKeyPath all helper methods.

Misused methods

  • getSettings

    This method should be renamed because it is confusing to mix settings and
    config. SettingsView is the only package that uses this method correctly. All
    other packages use it like this:

    var config = atom.config.getSettings()['atom-beautify'];

    Clearly they should be using Config::get instead of getSettings

  • getDefault

    SettingsView is the only package that uses this method correctly. All other
    packages use it like this:

    value = atom.config.get 'sublime-tabs.' + "#{key}"
    value ?= atom.config.getDefault 'sublime-tabs.' + "#{key}"
    

    when all they need to do is call

    value = atom.config.get 'sublime-tabs.' + "#{key}"
    

from api.

nathansobo avatar nathansobo commented on September 18, 2024

How can ::pushAtKeyPath be replicated in terms of the other methods?

from api.

probablycorey avatar probablycorey commented on September 18, 2024

Wouldn't this work?

array = atom.config.get(keyPath) ? []
array.push(value)
atom.config.set(keyPath, array)

from api.

nathansobo avatar nathansobo commented on September 18, 2024

Yep. 😿

from api.

probablycorey avatar probablycorey commented on September 18, 2024

Based on meetings we've had, I think I can safely say the Atom team disagree with most of this philosophy. But I'd still like to read an overview of the rest of the team's API philosophy.

from api.

joefitzgerald avatar joefitzgerald commented on September 18, 2024

the Atom team disagree with most of this philosophy

@probablycorey can you add more context to this statement? Do you mean the team disagrees with the issue as stated at the top? Or something else?

from api.

nathansobo avatar nathansobo commented on September 18, 2024

I think we actually do agree with most of it, but we did not agree on removing a significant portion of the existing public API, including some methods you could describe as "helper methods". As a compromise, we've decided to segment the API into "essential" and "extended". New users can start with the essential API as a more digestable introduction to programming Atom, while more advanced methods used in packages remain in the scope of the public contract via the extended API.

from api.

joefitzgerald avatar joefitzgerald commented on September 18, 2024

👍

from api.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.