Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Classes in clojurescript should use PascalCase #176

Open
hlolli opened this issue Jun 20, 2019 · 1 comment
Open

Classes in clojurescript should use PascalCase #176

hlolli opened this issue Jun 20, 2019 · 1 comment

Comments

@hlolli
Copy link

hlolli commented Jun 20, 2019

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.

@bbatsov
Copy link
Owner

bbatsov commented Jun 20, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants