# Redundant declarations in interface PConstants

**URL:** <https://discourse.processing.org/t/redundant-declarations-in-interface-pconstants/8602>\
**Category:** Processing\
**Created:** [February 21, 2019, 5:38pm UTC](https://discourse.processing.org/t/redundant-declarations-in-interface-pconstants/8602 "2019-02-21T17:38:39Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [February 21, 2019, 5:38pm UTC](https://discourse.processing.org/t/redundant-declarations-in-interface-pconstants/8602/1 "2019-02-21T17:38:39Z")

</div>

Speaking of which, when are the Processing’s devs gonna remove those 3 redundant declarations for the fields inside the `interface` PConstants? 😛

> <https://github.com/processing/processing/blob/processing-0269-3.5.3/core/src/processing/core/PConstants.java#L40>

---

<div class="post-metadata">

**Author:** ![needfulthing](https://avatars.discourse-cdn.com/v4/letter/n/ee7513/32.png) [@needfulthing](https://discourse.processing.org/u/needfulthing)\
**Post date:** [February 21, 2019, 6:17pm UTC](https://discourse.processing.org/t/redundant-declarations-in-interface-pconstants/8602/2 "2019-02-21T18:17:09Z")

</div>

Sorry, I meant properties, but I’m not even sure if that works in Java. I’m not a Java geek 🙂

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [February 21, 2019, 6:17pm UTC](https://discourse.processing.org/t/redundant-declarations-in-interface-pconstants/8602/3 "2019-02-21T18:17:42Z")

</div>

> [@Multiple classes in an (undefined) ArrayList?](https://discourse.processing.org/t/multiple-classes-in-an-undefined-arraylist/8291/12):
>
> gonna remove those 3 redundant declarations

Maybe just submit a pull request removing them?

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [February 21, 2019, 6:45pm UTC](https://discourse.processing.org/t/redundant-declarations-in-interface-pconstants/8602/4 "2019-02-21T18:45:08Z")

</div>

> [@Multiple classes in an (undefined) ArrayList?](https://discourse.processing.org/t/multiple-classes-in-an-undefined-arraylist/8291/12):
>
> those 3 redundant declarations

This a bit of-topic but as you raised it.

PApplet implements PConstants so the constants X, Y and Z are available to the sketch creator. Thus the following sketch will run without problem.

```auto
println(X,Y,Z);

```

it will output `0 1 2`

Removing them would any sketches that used them 🤓

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [February 21, 2019, 6:48pm UTC](https://discourse.processing.org/t/redundant-declarations-in-interface-pconstants/8602/5 "2019-02-21T18:48:30Z")

</div>

> [@Multiple classes in an (undefined) ArrayList?](https://discourse.processing.org/t/multiple-classes-in-an-undefined-arraylist/8291/13):
>
> I’m not a Java geek. 🙂

Well, this tutorial explains the types of variables in Java: ☕

> **[Declaring Member Variables (The Java™ Tutorials \>        
           ...](https://docs.oracle.com/javase/tutorial/java/javaOO/variables.html)**
>
> This beginner Java tutorial describes fundamentals of programming in the Java programming language

> [@Multiple classes in an (undefined) ArrayList?](https://discourse.processing.org/t/multiple-classes-in-an-undefined-arraylist/8291/15):
>
> This a bit off-topic but as you raised it.

That’s why I’ve opened it w/: “Speaking of which…” 😅

> [@Multiple classes in an (undefined) ArrayList?](https://discourse.processing.org/t/multiple-classes-in-an-undefined-arraylist/8291/14):
>
> Maybe just submit a pull request removing them?

If I do that, it’s a sure way it’s never gonna happen! 🤐

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [February 21, 2019, 6:55pm UTC](https://discourse.processing.org/t/redundant-declarations-in-interface-pconstants/8602/6 "2019-02-21T18:55:03Z")

</div>

I said it was off-topic because the fact that they have not been removed from PConstants has **_nothing_** to do with the topic under discussion. What has happened is that this discussion has been hijacked and as a moderator you should be trying to stop this. I would be happy if all the replies related to PConstants including mine to be deleted.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [February 21, 2019, 7:01pm UTC](https://discourse.processing.org/t/redundant-declarations-in-interface-pconstants/8602/7 "2019-02-21T19:01:47Z")

</div>

Moved this to a new thread.

It seems to me like the key issues here are:

1. should this be changed at all?
2. if it should, what – concretely – would that proposed change look like?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [February 21, 2019, 7:07pm UTC](https://discourse.processing.org/t/redundant-declarations-in-interface-pconstants/8602/8 "2019-02-21T19:07:21Z")

</div>

> [@quark](#):
>
> … has _ **nothing** _ to do with the topic under discussion.

But it has EVERYTHING to do as a sideline followup of my previous warning:

> [@Multiple classes in an (undefined) ArrayList?](https://discourse.processing.org/t/multiple-classes-in-an-undefined-arraylist/8291/11):
>
> Not the fields. Actually, any fields declared in an interface are implicitly public, static & final! no_mouth

IMO, a mere sideline comment isn’t enough to make a discussion to become hijacked as you had stated.

This split action was completely over-the-top. But whatever… 🤷‍♂️

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [February 21, 2019, 7:15pm UTC](https://discourse.processing.org/t/redundant-declarations-in-interface-pconstants/8602/9 "2019-02-21T19:15:12Z")

</div>

Sorry if you didn’t want it split, @GoToLoop. For me I thought there was a conversation that was worth hashing out if there was going to be a proposed change to PConstants that should be submitted as a pull.

If the answer is “no” then we can just let this thread end here – or hide it, if you prefer.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [February 21, 2019, 8:16pm UTC](https://discourse.processing.org/t/redundant-declarations-in-interface-pconstants/8602/10 "2019-02-21T20:16:41Z")

</div>

It was merely a followup anti-example about using redundant modifiers on an ìnterface`.

My “request” on that was just rhetoric. I know pretty well there’s no chance for that to happen.

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [February 21, 2019, 10:31pm UTC](https://discourse.processing.org/t/redundant-declarations-in-interface-pconstants/8602/11 "2019-02-21T22:31:37Z")

</div>

You can’t remove constants without breaking compatibility. Maybe suggest for v4?

> [@GoToLoop](#):
>
> It was merely a followup anti-example about using redundant modifiers on an ìnterface`.

I’d argue for always having the redundant modifiers for consistency. This is not an anti-pattern, particularly now with things like private methods on interfaces.

On the other hand, ironically, interfaces for the purpose of providing constants is an anti-pattern. A good candidate for replacing with import static (again in v4+)

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [February 21, 2019, 10:53pm UTC](https://discourse.processing.org/t/redundant-declarations-in-interface-pconstants/8602/12 "2019-02-21T22:53:38Z")

</div>

> [@neilcsmith](#):
>
> I’d argue for always having the redundant modifiers for consistency.

Although most constants within “PConstants.java” are modified w/ `static final`, there are also `static public final` & `public final static` in some! 🤪

That’s not what I’d call “consistency”, but crazy & useless boilerplate! 🤡

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [February 21, 2019, 11:10pm UTC](https://discourse.processing.org/t/redundant-declarations-in-interface-pconstants/8602/13 "2019-02-21T23:10:47Z")

</div>

Well, they should all be `public static final`. But that’s all a really minor issue vs getting rid of PConstants as an interface, which is the real anti pattern! Having type safe constants would also be a massive improvement.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [February 21, 2019, 11:17pm UTC](https://discourse.processing.org/t/redundant-declarations-in-interface-pconstants/8602/14 "2019-02-21T23:17:53Z")

</div>

> [@neilcsmith](#):
>
> … vs getting rid of PConstants as an `interface`,

I hope you’re aware that would make 99.9% of sketches to stop working, right? 👷‍♂️

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [February 21, 2019, 11:24pm UTC](https://discourse.processing.org/t/redundant-declarations-in-interface-pconstants/8602/15 "2019-02-21T23:24:17Z")

</div>

It would be source compatible actually. In fact, I’ve already done that and type safe constants (which might break source compatibility very rarely, but are _really_ worth it). But it’s not binary compatible so would have to be done in a future major version and libraries recompiled.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [February 21, 2019, 11:30pm UTC](https://discourse.processing.org/t/redundant-declarations-in-interface-pconstants/8602/16 "2019-02-21T23:30:54Z")

</div>

> [@neilcsmith](#):
>
> In fact, I’ve already done that …

Meaning you’ve convert `interface` PConstants into an `enum`, is that so?

In order for sketches to directly use such constants, I believe they’d need:  
`import static processing.core.PConstants.*;`

However, the whole Processing library would need to change its API to accept `enum` PConstants in place of each type of the current `interface` PConstants!

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [February 22, 2019, 12:06pm UTC](https://discourse.processing.org/t/redundant-declarations-in-interface-pconstants/8602/17 "2019-02-22T12:06:08Z")

</div>

> [@GoToLoop](#):
>
> Meaning you’ve convert `interface` PConstants into an `enum` , is that so?
> 
> In order for sketches to directly use such constants, I believe they’d need:  
> `import static processing.core.PConstants.*;`

Those two things are orthogonal. You could use `PConstants` as it is now with `import static`, and something the preprocessor could add to the default imports, and thus be source compatible.

_An_ `enum` doesn’t solve the issue of type safety. You need an `enum` (or in a couple of edge cases an interface) for each constant grouping. That way, all the methods that accept a constant show the allowed options in code completion and refuse to compile with an invalid constant. Picking up errors at compile time is much more beginner / user friendly. And still source code compatible, except in rare cases people want to store constants in another field.

My wrapper is at [Constants.java](https://github.com/praxis-live/praxis/blob/master/praxis.video.pgl.code/src/org/praxislive/video/pgl/code/userapi/Constants.java) for reference.
