2

Which way you prefer to write code?

1.
server.addHandler(...)
server.addSerializer(...)
server.addCompressor(...)
...

2.
server.add("handler",...)
server.add("serializer",...)
server.add("compressor",...)
...

3. Both. (as per mood) :p

Comments
  • 3
    For low-level languages: 1
    For high-level languages: 2
  • 3
    The benefit of first style is IDE intelligence.

    The benefit of second style is less methods to learn.
  • 0
    @2lazy2debug never!!

    constructors are to get necessary data requires to construct the object.
  • 0
    Whatever I learnt first.
  • 0
    @blueprint.route("/die")
  • 0
    // adds handler to server
    Server.addHandler(new StringBuffer(„Handler“).toString());

    So the next one who touches my code as to use his brain...
  • 0
    Second all the way. That’s functional.

    To be honest, I prefer the special, greatest way on terms of conceptions:

    add(server, “compressor”)
  • 1
    server+=myHandler
    as in C#
  • 0
    Handlers are the modules handle request, response. Consider them as servlet, if you're Java user.

    handlers, serializers, compressors,and other need to be added dynamically.
  • 0
    @uyouthe server is a 3rd party library who knows how to add any components to them.

    The way you suggested can be possible when user can modify server's code which is not recommended.
  • 0
    @amitgupta we do it in Clojure exactly the way I told you about
  • 0
    @uyouthe I'm implementing the server in JavaScript or rather node.js.. no idea above Clojure
  • 1
  • 2
    depends on the language. langs like elixir where you pattern matching in definition exist, i do 2, but more statically typed langs like rust, 1.
  • 0
    Finally I've added both options so user can choose whichever way they prefer.

    I've also added directory scanning to add them automatically so both options can be avoided.

    2 lines to build a server...
Add Comment