TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

The missing harm of manual dispatch in Julia

102 pointsby amkkmaover 4 years ago

7 comments

nur0nover 4 years ago
I love how easy it is to view the machine code for a function. Julia actually ships with a handful of these introspection macros: <a href="https:&#x2F;&#x2F;docs.julialang.org&#x2F;en&#x2F;v1&#x2F;devdocs&#x2F;reflection&#x2F;#Intermediate-and-compiled-representations" rel="nofollow">https:&#x2F;&#x2F;docs.julialang.org&#x2F;en&#x2F;v1&#x2F;devdocs&#x2F;reflection&#x2F;#Interme...</a>. They are invaluable when it comes to optimization.
评论 #24581889 未加载
评论 #24582509 未加载
doublesCsover 4 years ago
I keep saying that Julia is the future. No more tinkering with Cython and other hacks.
评论 #24582041 未加载
评论 #24588164 未加载
评论 #24583182 未加载
ddragonover 4 years ago
This reminds me of these slides on the Julia compiler and Zygote [1] that really impressed me at the time. Not only the compiler is incredibly smart, it also gives the programmer to a lot of tools to talk with it (the introspection macros, IR Tools, macros on AST, macros on IR - generated functions).<p>And maybe a little related, while traits are not a feature on the language, you can use this kind of compile-time optimizations to implement trait dispatch that the compiler will completely erase from the generated code, the so called holy traits [2].<p>[1] <a href="https:&#x2F;&#x2F;docs.google.com&#x2F;presentation&#x2F;d&#x2F;1IiBLVU5Pj-48vzEMnuYEr9WQy9u2oi6Yk_8F3sgGkvQ&#x2F;preview#slide=id.p" rel="nofollow">https:&#x2F;&#x2F;docs.google.com&#x2F;presentation&#x2F;d&#x2F;1IiBLVU5Pj-48vzEMnuYE...</a><p>[2] <a href="https:&#x2F;&#x2F;invenia.github.io&#x2F;blog&#x2F;2019&#x2F;11&#x2F;06&#x2F;julialang-features-part-2&#x2F;" rel="nofollow">https:&#x2F;&#x2F;invenia.github.io&#x2F;blog&#x2F;2019&#x2F;11&#x2F;06&#x2F;julialang-features...</a>
pdeffebachover 4 years ago
This is a good feature! Sometimes, you want to use `if` `else` based on type information, say if your function is very large and the different behavior based off of type is only a small piece of the process you want to convey.<p>It&#x27;s great to have the flexibility.
评论 #24581962 未加载
marcuspoloover 4 years ago
I am not a Julia user, can the compiler optimize away the run-time type checking when `foo`&#x27;s argument is not easily known at compile time?<p>e.g.,<p><pre><code> foo(function_which_returns_dynamic_type())</code></pre>
评论 #24582073 未加载
评论 #24583634 未加载
评论 #24585658 未加载
compressedgasover 4 years ago
This only shows that it can do method type specialization to get rid of type dispatch.<p>Can you add a new multimethod clause to an existing if-then-else type dispatch method? For example add:<p><pre><code> foo(x::Baz) = x.foo </code></pre> Or is harm still done because the method is not open for extension when written like that?
评论 #24581880 未加载
carabinerover 4 years ago
Missing harm considered harmful.