Comments on: Making APIs Easier to Use and Understand https://simpleprogrammer.com/use-default-parameters-enumerations-make-apis-easier-use/ Thu, 12 Apr 2018 05:19:26 +0000 hourly 1 https://wordpress.org/?v=7.0 By: Introduction to Hapi.Js - Simple Programmer https://simpleprogrammer.com/use-default-parameters-enumerations-make-apis-easier-use/#comment-2638 Wed, 10 Jan 2018 23:05:59 +0000 https://simpleprogrammer.com/?p=11357#comment-2638 […] (REST) APIs because it provides you with routing, input, output validation, and caching. You can build an API that serves all kinds of clients that need mobile and single-page […]

]]>
By: What Is Back-End Development? – scribdbook https://simpleprogrammer.com/use-default-parameters-enumerations-make-apis-easier-use/#comment-2637 Thu, 15 Dec 2016 04:47:07 +0000 https://simpleprogrammer.com/?p=11357#comment-2637 […] produces a user interface. This could encompass back-end web development, but it might also involve writing APIs, creating libraries, or working with components of systems that don’t have user interfaces or […]

]]>
By: What is back end development?? – Tech connect world https://simpleprogrammer.com/use-default-parameters-enumerations-make-apis-easier-use/#comment-2636 Wed, 14 Dec 2016 05:40:41 +0000 https://simpleprogrammer.com/?p=11357#comment-2636 […] a user interface. This could encompass back-end web development, but it might also involve writing APIs, creating libraries, or working with components of systems that don’t have user interfaces or […]

]]>
By: CaRDiaK https://simpleprogrammer.com/use-default-parameters-enumerations-make-apis-easier-use/#comment-2634 Wed, 17 Feb 2016 08:00:00 +0000 https://simpleprogrammer.com/?p=11357#comment-2634 In reply to Thorbs.

Shifting complexity? Really? Let’s say that login method has 500 references. So you need to add lastLoggedIn. That’s 500 changes. Then they need another parameter. That’s another 500 changes. Need to change a parameter type? Wow, another 500 changes please. Or you could just put it on a class implementation and be done with it, make the 500 changes once and once only. If you can’t change the signature then you could use the adapter pattern or wrap the method. If you used an ILoginInfo interface as a parameter, better still, you’ve now go a seam that you can leverage to test any implementation of the interface against that method. All this is even before we talk about code reuse. You could tell in literally seconds the effects of a change on a system. Think DRY. How is that shifting complexity? If anything, it reduces it. It’s this primitive obsession adds needless complexity. What can you do with those primitive types? Add if statements everywhere? Put the logic where it needs to go, which 99% of the time is on the implementation!

]]>
By: JT Turner https://simpleprogrammer.com/use-default-parameters-enumerations-make-apis-easier-use/#comment-2635 Wed, 17 Feb 2016 03:11:00 +0000 https://simpleprogrammer.com/?p=11357#comment-2635 A few other tips:

1. Follow a standard like JSON API (http://jsonapi.org/) or HAL (http://stateless.co/hal_specification.html).
2. Build a Swagger Specification and generate code libraries using it (http://swagger.io/).
3. Think about building a GraphQL version as well. If you build the controllers correctly you could share much of the same logic between the REST API and GraphQL.

FYI I would love to do a guest blog post about this if you are game showing a simple one in Node.js.

]]>
By: Dave Rael https://simpleprogrammer.com/use-default-parameters-enumerations-make-apis-easier-use/#comment-2633 Tue, 03 Feb 2015 02:28:00 +0000 https://simpleprogrammer.com/?p=11357#comment-2633 In reply to Thorbs.

yes – i’ve also been guilty of being the overly “clever” guy and had it bite me and my teams.

]]>
By: Thorbs https://simpleprogrammer.com/use-default-parameters-enumerations-make-apis-easier-use/#comment-2632 Mon, 02 Feb 2015 22:38:00 +0000 https://simpleprogrammer.com/?p=11357#comment-2632 In reply to Dave Rael.

p.s, Judging by the end of your reply, I assume you have also came across over engineered solutions in your time with the rationale of the lead engineer trying to be too clever for everyone.

]]>
By: Thorbs https://simpleprogrammer.com/use-default-parameters-enumerations-make-apis-easier-use/#comment-2631 Mon, 02 Feb 2015 22:35:00 +0000 https://simpleprogrammer.com/?p=11357#comment-2631 In reply to Dave Rael.

I hear ya… design is all about trade off’s and I agree using a class to encapsulate the parameter will just be shifting the complexity from one area to another. Preaching to the converted.

]]>
By: Dave Rael https://simpleprogrammer.com/use-default-parameters-enumerations-make-apis-easier-use/#comment-2630 Mon, 02 Feb 2015 14:45:00 +0000 https://simpleprogrammer.com/?p=11357#comment-2630 In reply to Thorbs.

Sure, it’s always a balance and there is not one prescriptive answer for something being always better. Not changing your method signature for a new parameter can be helpful, but it can also hide new complexity where using your method is easier if that is explicit. If any consumer of your method needs to change because the new parameter is required, you haven’t really gained anything in not changing the signature (you actually have changed the signature, you’ve just hidden the change). Use your head and do what makes sense in a situation and always consider what makes you API most straightforward to understand and abide by the principle of least surprise.

]]>
By: Thorbs https://simpleprogrammer.com/use-default-parameters-enumerations-make-apis-easier-use/#comment-2629 Sun, 01 Feb 2015 17:51:00 +0000 https://simpleprogrammer.com/?p=11357#comment-2629 In reply to David Rael.

Fair points but is there not also the advantage that if you need more parameters in the future it can be encapsulated and handled in the object.

]]>