bbatsov/clojure-style-guide

Classes in clojurescript should use PascalCase

hlolli opened this issue · 1 comments

To start with, I take it for granted that this clojure-style-guide is used by organizations that write clojurescript, if I'm wrong please close or there's another clojurescript style-guide out there that I'm not aware of, please let me know in comments.

In the wild, I see too often clojurescript developers writing React Classes in kebab-case. This makes code very inconsistent when mixing interops with clojurescript functions.

Say I'm using in react-native the classes View and FlatList

(require '["react-native" :refer (View FlatList)])
(defn root []
  [:> View
   [:> FlatList]])

and I decide to be clever and wrap the class FlatList into a clojurescript function

(require '["react-native" :refer (View) :as rn])
(defn my-flat-list [props]
  [:> rn/FlatList props])
(defn root []
  [:> View
   [my-flat-list {:my "props"}]])

Then I will have a hiccup body of react classes where one class is PascalCase and the other one kebab-case. This I see as a real style inconsistency. Even worse is when I see developers literally writing react classes with kebab-case.

(defn my-class []
  (reagent/create-class
   {:reagnet-render (fn [] [:h1 "Hello World"])}))

when it should be

(defn MyClass []
  (reagent/create-class
   {:reagnet-render (fn [] [:h1 "Hello World"])}))
(defn root []
  [:div [MyClass]])

whereas any js-linter and ts-linter would enforce PascalCase on classes

class HelloWorld extends React.Component {
    render() {
          return (
                  <div>
                    Hello, React!
                  </div>
                )
        }
};
ReactDOM.render(<HelloWorld />, document.getElementById('root'));

My argument for writing this into the style-guide would be, besides enforcing consistency, then in jvm-clojure the same styling applies, java classes are PascalCase, interfaces are PascalCase, same goes for proxy, defprotocol, definterface and deftype.

I would love a discussion around this since most code in the wild does not use PascalCase. I can see the argument, that since this is a symbol generated from a defn, it should be styled accordingly to a function. But that's outside of the intent of the code and just a re-agent implementation.

To start with, I take it for granted that this clojure-style-guide is used by organizations that write clojurescript, if I'm wrong please close or there's another clojurescript style-guide out there that I'm not aware of, please let me know in comments.

Yeah, it's meant to cover ClojureScript as well. I guess we should be more explicit about this in the intro.

In the wild, I see too often clojurescript developers writing React Classes in kebab-case.

kebab-case always makes me laugh so hard! In my mind it's always lisp-case, but maybe that's the right terminology indeed.

I would love a discussion around this since most code in the wild does not use PascalCase. I can see the argument, that since this is a symbol generated from a defn, it should be styled accordingly to a function. But that's outside of the intent of the code and just a re-agent implementation.

Interesting subject! I'm looking forward to hear what people think about it.