Hi John,
Thank you for writing this important book.
One idea that particularly resonates with me is the role of functions not just as units of behavior, but as a way of creating a language for the code. For example, a call like
add_null(attribute);
can read more naturally and convey intent more clearly than something like
data.put(attribute, null);
—even though the function itself may be considered shallow.
I’d be very curious to hear your take on this perspective.
Thank you,
Meir
add_null(attribute);can read more naturally and convey intent more clearly than something like
data.put(attribute, null);
--
You received this message because you are subscribed to the Google Groups "software-design-book" group.
To unsubscribe from this group and stop receiving emails from it, send an email to software-design-...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/software-design-book/CAP1Du3XhhUt4cx6yVfC6bnWwG34w9j7G7s7aEwox6d121je72g%40mail.gmail.com.
Hi Justin,
Thank you for the detailed reply — it helped clarify the risks much better than I could articulate.
I understand that languages like Lisp explicitly support language growth. But when working in a language like Python, do you ever treat “this introduces necessary vocabulary” as a deciding factor for defining a function?
Best,
Meir
...in a language like Python, do you ever treat “this introduces necessary vocabulary” as a deciding factor for defining a function?
To view this discussion visit https://groups.google.com/d/msgid/software-design-book/CADJ-BO0Y2VW0ALa0rQqCDfqT5ryuL9rsqbgW7E_ERE00G8Z6ZA%40mail.gmail.com.
Thank you for the follow-up. Let me give another example to clarify what I mean.
Consider computing the area of a triangle with side lengths stored in variables a, b, and c using Heron’s formula. That formula is expressed in terms of the half-perimeter of the triangle.
Reading triangle_perimeter(a, b, c) / 2 requires less mental effort than reading (a + b + c) / 2, because the former explicitly states the geometric meaning of that sum—it introduces vocabulary specific to the application domain.
Hi Justin,
Thank you very much for the insight.
To clarify your position, suppose I have a Triangle class with accessors (e.g., @property in Python) for its three sides—setting aside the question of whether exposing them directly is a good design choice.
In that context, would you still see no reason to define a perimeter method?
Thank you,
Meir
Hi Justin,
So, the free function triangle_perimeter(a, b, c) does not add clarity beyond perimeter = a + b + c. But when the same computation is exposed as
triangle.perimeter(), it may add value beyond perimeter = t.a + t.b + t.c. What is it about attaching the name to the object that makes it worthwhile?Thank you,
Meir
Hi Justin,
So, the free function triangle_perimeter(a, b, c) does not add clarity beyond perimeter = a + b + c. But when the same computation is exposed as triangle.perimeter(), it may add value beyond perimeter = t.a + t.b + t.c. What is it about attaching the name to the object that makes it worthwhile?
Thank you,
Meir
Thank you all.
Would defining a free function like triangle_perimeter(a, b, c) be also considered a violation of the principle from Chapter 7, “Different Layer, Different Abstraction”?
Thank you,
Meir
To view this discussion visit https://groups.google.com/d/msgid/software-design-book/CAEoi9W4qOjYGVcVkhRz1KXfwg5f-pSUyniDiOWxDga-G9fmh7g%40mail.gmail.com.