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.

Ask HN: What are some examples of truly idiomatic code?

1 pointsby jason_sover 7 years ago
I&#x27;ve heard the expression &quot;idiomatic XYZ&quot; used a lot, where XYZ is the name of some computer language. For example, &quot;for element in iterable: do_something(element)&quot; in Python rather than the traditional C-like loop that uses an index. But a lot of these examples aren&#x27;t really idioms -- they are just more natural constructs that are well-known and defined in the language. There&#x27;s no need for a compiler or interpreter to figure out &quot;what you&#x27;re really trying to do&quot; in order to implement it well.<p>So I&#x27;m looking for examples of truly idiomatic code in computer languages --- something where a fluent programmer would easily understand what is going on at a high level, but you&#x27;d have to program a compiler or interpreter to &quot;recognize&quot; the construct in order to treat it more efficiently than the language definition would imply.<p>The only one I can think of, off the top of my head, is Array.prototype.slice.call(arguments) in Javascript (e.g. https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;7056925&#x2F;how-does-array-prototype-slice-call-work) which makes a real Array object out of a function&#x27;s arguments, which are not an Array.

no comments

no comments