# On Kaleidoscope.use() and .setup()

**URL:** <https://community.keyboard.io/t/on-kaleidoscope-use-and-setup/1433>\
**Category:** Kaleidoscope Internals\
**Created:** [April 28, 2018, 2:45pm UTC](https://community.keyboard.io/t/on-kaleidoscope-use-and-setup/1433 "2018-04-28T14:45:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![noseglasses](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/noseglasses/32/429_2.png) [@noseglasses](https://community.keyboard.io/u/noseglasses)\
**Post date:** [April 28, 2018, 2:45pm UTC](https://community.keyboard.io/t/on-kaleidoscope-use-and-setup/1433/1 "2018-04-28T14:45:16Z")

</div>

> [@Productivity macros, what do you use?](https://community.keyboard.io/t/productivity-macros-what-do-you-use/954/15):
>
> Nope, the order of Kaleidoscope.setup() and Kaleidoscope.use() should not matter. If it does, I’d consider that a bug.

Strictly speaking, the Kaleidoscope-Leader plugin has a bug. Its [README.md](https://github.com/keyboardio/Kaleidoscope-Leader/blob/master/README.md) says:

> Note that we need to use the Leader object before any other that adds or changes key behaviour! Failing to do so may result in unpredictable behaviour.

---

<div class="post-metadata">

**Author:** ![noseglasses](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/noseglasses/32/429_2.png) [@noseglasses](https://community.keyboard.io/u/noseglasses)\
**Post date:** [April 28, 2018, 2:48pm UTC](https://community.keyboard.io/t/on-kaleidoscope-use-and-setup/1433/2 "2018-04-28T14:48:55Z")

</div>

And Qukeys and Kaleidoscope-Papageno have bugs as well because they also like to be `.use(...)`d first. I don’t see a way to avoid this.

I think such special requirements should be acceptable behavior, and not a bug, as long as they are well documented.

---

<div class="post-metadata">

**Author:** ![Llamalland](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/llamalland/32/832_2.png) [@Llamalland](https://community.keyboard.io/u/Llamalland)\
**Post date:** [April 28, 2018, 3:41pm UTC](https://community.keyboard.io/t/on-kaleidoscope-use-and-setup/1433/3 "2018-04-28T15:41:11Z")

</div>

You might be misunderstanding what I meant when I asked that question. I was confused why a lot of examples for plugins listed kaleidoscope.setup() after kaleidoscope.use (list of plugins) where the default firmware lists them the other way around. I didn’t take what @Algernon said to mean that it would be a bug if the order of the list of plugins was important, just that if the order of .setup() and .use() in relation to each other were important, that would be a bug.

---

<div class="post-metadata">

**Author:** ![noseglasses](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/noseglasses/32/429_2.png) [@noseglasses](https://community.keyboard.io/u/noseglasses)\
**Post date:** [April 28, 2018, 6:54pm UTC](https://community.keyboard.io/t/on-kaleidoscope-use-and-setup/1433/4 "2018-04-28T18:54:53Z")

</div>

Yeah, you are right. I misread that.

Now, that we are speaking about it, why isn’t `Kaleidoscope.setup()` called automatically by `Kaleidoscope.use(...)`?

---

<div class="post-metadata">

**Author:** ![algernon](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/algernon/32/4404_2.png) [@algernon](https://community.keyboard.io/u/algernon)\
**Post date:** [April 28, 2018, 7:51pm UTC](https://community.keyboard.io/t/on-kaleidoscope-use-and-setup/1433/5 "2018-04-28T19:51:02Z")

</div>

Because `Kaleidoscope.use()` is optional. We could document that one needs to call either of the two, but it’s a lot easier if we just use both, always. Makes copy & pasting the factory firmware easier too.

We could also teach `Kaleidoscope.loop()` to check if `.setup()` was called, and run it once if it hasn’t, but that’d be a bit of an ugly hack for very little gain, in my opinion.

---

<div class="post-metadata">

**Author:** ![noseglasses](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/noseglasses/32/429_2.png) [@noseglasses](https://community.keyboard.io/u/noseglasses)\
**Post date:** [April 28, 2018, 8:00pm UTC](https://community.keyboard.io/t/on-kaleidoscope-use-and-setup/1433/6 "2018-04-28T20:00:39Z")

</div>

> [@Productivity macros, what do you use?](https://community.keyboard.io/t/productivity-macros-what-do-you-use/954/21):
>
> We could also teach Kaleidoscope.loop() to check if .setup() was called, and run it once if it hasn’t, but that’d be a bit of an ugly hack for very little gain, in my opinion.

Not sure. It would be extremely cheap (1 byte of RAM, few bytes of PROGMEM, few cycles for the noop function calls every loop) and completely backwards compatible.

```cpp
void
Kaleidoscope_::setup(void) {
   static bool alreadyCalled = false;
   if(alreadyCalled) { return; }
   alreadyCalled = true;
   ...
}

void
Kaleidoscope_::loop(void) {
   this->setup();
   ...
}

```

---

<div class="post-metadata">

**Author:** ![algernon](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/algernon/32/4404_2.png) [@algernon](https://community.keyboard.io/u/algernon)\
**Post date:** [April 28, 2018, 8:09pm UTC](https://community.keyboard.io/t/on-kaleidoscope-use-and-setup/1433/7 "2018-04-28T20:09:31Z")

</div>

Not saying it is expensive in any sense, my thinking is that this is not needed right now. With `loop()` calling setup, we’d save one line in the user sketch, a line noone up to this point found either confusing, complicated or anything like it. In return, we add 3 more elsewhere.

It’s a small thing either way, but not something I feel there is a _need_ for. 🙂

And with `.use()` likely to go away at some point, and us moving towards a more… declarative way of specifying what plugins to use, `setup()` will end up being a few property settings and `Kaleidoscope.setup()`… in this setup, I feel it makes more sense to have an explicit call to it. On the other hand, this is just a feeling, or my own aesthetic preference if you like.

---

<div class="post-metadata">

**Author:** ![noseglasses](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/noseglasses/32/429_2.png) [@noseglasses](https://community.keyboard.io/u/noseglasses)\
**Post date:** [April 28, 2018, 8:17pm UTC](https://community.keyboard.io/t/on-kaleidoscope-use-and-setup/1433/8 "2018-04-28T20:17:30Z")

</div>

Every line you spare the user of an interface to write is worth several lines in the interface’s implementation.

> [@algernon](#):
>
> a line noone up to this point found either confusing

Yep, but only up to this point…  
I suppose there are many people being confused about a lot of things, but only few of them actually write about it.

> [@Productivity macros, what do you use?](https://community.keyboard.io/t/productivity-macros-what-do-you-use/954/14):
>
> So this may have been enough, I certainly got it to compile based on what was in there. Few noob questions, and if it’d be easier just to see my sketch, I’ll upload it: To compile, in the line defining Key\_Redial, I had to remove “(key)” as it said ‘key’ was not declared in this scope" So I interpreted (key) intended more as a comment, like “put your key name here” or something. Have I just compiled gobbledygook? Also a couple of noob questions not really related to Redial in particular: …
