You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally posted by robacarp October 11, 2024
I'm normally in favor of a strictly typed interface, especially at the boundary layer of a shard. But I wonder if the expressiveness here might actually benefit from loosening it up a bit where content is passed into a tag renderer.
For example this method declaration has a strict argument type signature of String where it's not actually needed:
privatedefplain(content : String) : Nil
append_to_buffer(content)
end
That results in needing to explicitly .to_s a number, where that's unlikely to be actually necessary:
# explicit cast of data to string, because the compiler will complain without it
plain query.count.to_s
What do you think about adding an overload method which calls .to_s on the content?
privatedefplain(content) : Nil
append_to_buffer(content.to_s)
end
The .to_s is naïve, but it'll result in not needing to manually call .to_s on every non-string which has a reasonable .to_s implementation. Consider this:
h2 do
plain "Showing "
plain query.current_range.begin.to_s
plain " to "
plain query.current_range.end.to_s
plain " of "
plain query.total_hits.to_s
plain " results"
end
This type of desired result is the worst case for this style of html templating engine like blueprint or luckytemplate -- it requires a lot of overhead to compile a simple string, and in this case each data point being injected requires an explicit .to_s as well.
The text was updated successfully, but these errors were encountered:
Discussed in #76
Originally posted by robacarp October 11, 2024
I'm normally in favor of a strictly typed interface, especially at the boundary layer of a shard. But I wonder if the expressiveness here might actually benefit from loosening it up a bit where content is passed into a tag renderer.
For example this method declaration has a strict argument type signature of
String
where it's not actually needed:That results in needing to explicitly
.to_s
a number, where that's unlikely to be actually necessary:# explicit cast of data to string, because the compiler will complain without it plain query.count.to_s
What do you think about adding an overload method which calls .to_s on the
content
?The
.to_s
is naïve, but it'll result in not needing to manually call.to_s
on every non-string which has a reasonable .to_s implementation. Consider this:This type of desired result is the worst case for this style of html templating engine like blueprint or luckytemplate -- it requires a lot of overhead to compile a simple string, and in this case each data point being injected requires an explicit
.to_s
as well.The text was updated successfully, but these errors were encountered: