Giter Site home page Giter Site logo

Comments (4)

charlierudolph avatar charlierudolph commented on July 26, 2024

Sounds good to me. Based on your comments in #64, might need to be flexible with the file names though.

foo_controller.coffee
foo-controller.coffee
FooController.coffee

each is the foo controller

Basically take the filename, camelCase it, and remove Controller.

from exprestive.

alexdavid avatar alexdavid commented on July 26, 2024

When I was first designing exprestive I debated whether to use classes or just export an object. I chose classes for a few reasons, and still think that was the right decision.

Here are a few reasons I think classes make sense

  • Dependency injection - In every project I've used exprestive, I've found the dependencies feature incredibly useful. Basically you can specify dependencies from the server that are available in the constructor of every controller. This is useful if your app has services that are initialized in the server but need to be accessed by your controllers.
  • Loss of name attribute - Named functions in javascript (like coffeescript/livescript classes) automatically get a name attribute which we use to reference from the routes file. Using file names to resolve this, as you suggest seems brittle, and introduces a lot more edge cases. This name is also used automatically in error reporting when a controller method raises an error. Finally, it permanently prevents node apps using exprestive from being compiled down to a single file, while this is not something we do, it is a practice I've seen app developers do and our architecture should be flexible enough to not care how you structure your app.
  • Extend a base controller - Extending common functionality in controllers comes free in coffeescript/livescript. This is useful functionality if you have a lot of CRUD routes. Using a base class you could do some magic to automatically wire up the RESTful verbs (index, show, etc...). Exprestive also provides an optional base controller that offers some helper methods.
  • Classes have less magic - We could implement a lot of the issues I've documented here by using methods, but it would require significant more magic. Javascript developers are familiar with classes, they know how to create private helper methods, extend base classes, and how to call these methods from their controller methods. If I didn't know how to use exprestive and I came across an app that was using it and I saw your syntax, I would not intuitively know if I could just create private helper methods and reference them with this from my controller methods.
  • What are we actually saving by changing this - In coffeescript/livescript you're saving 4 characters: class. For simple apps an object of methods is a good fit, but using a class isn't any more difficult, but provides much more flexibility. I'm ok with breaking changes, but only if there is a real advantage for doing so. I'd rather not have major breaking changes for the sake of having breaking changes.

from exprestive.

charlierudolph avatar charlierudolph commented on July 26, 2024

Forgot about dependencies and extending the base controller. Those are far easier with classes then introducing some new syntax.

from exprestive.

kevgo avatar kevgo commented on July 26, 2024

Okay, sounds good. Thanks!

from exprestive.

Related Issues (12)

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.