Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Clojure Polymorphism

You're reading from   Clojure Polymorphism Leverage Clojure's polymorphic tools to develop your applications

Arrow left icon
Product type Paperback
Published in Nov 2019
Publisher
ISBN-13 9781838982362
Length 56 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Paul Stadig Paul Stadig
Author Profile Icon Paul Stadig
Paul Stadig
Arrow right icon
View More author details
Toc

Summary

From this exercise, I would draw the following principles:

  • If you have an actual, factual performance concern, then avoid multimethods in favor of a plain function or protocol functions.
  • You should never extend a multimethod or protocol that you do not own to a type that you do not own.
  • If you are designing a library that requires some abstraction, you do not want to define a multimethod or protocol; you want to allow a user to pass in a function.
  • If you are extending an abstraction to types or something that can reasonably be modeled as types, then protocol functions will provide the best balance between flexibility and performance.
  • If you are more concerned about writing cross-platform code and less about flexibility or performance, then using a plain function with a cond and cross-platform predicates for dispatch would be best.
  • If you need very general dispatch and are fine with the performance penalty, then use multimethods.
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime