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 abject failure of weak typing

61 pointsby zoomerangalmost 11 years ago

7 comments

dllthomasalmost 11 years ago
I'd like to stress the point about wrapper types, which can even be usefully employed in C. Note that - in C - this is not typedef (which is mostly cosmetic), but rather wrapping primitives in otherwise empty structs. This has no runtime cost and has the tremendous benefit that you won't mix up the arguments to place_order(price_t, quantity_t) where you might to place_order(int price, int quantity).
slashnullalmost 11 years ago
I think what this planet needs is a comprehensive study of how different typing techniques and schools of thought would solve different classes of problems, because what I notice is that<p>1) definitions are hard, and don&#x27;t mean much<p>2) there are many equivalences, and some idioms are conceptually very similar across different type systems, and are just not implemented the same way. For example, a it&#x27;s a common hobby among FP weenies to show how most of the GoF design patterns are one-liners in their languages of choice.<p>3) the scope of many typing disciplines is not the same; for example, unityped languages work great for tasks of limited scope with lots of user interface components, functional is historically used to write nice algorithms, and OOP is an attempt at giving a distinct shape to software of very large scope (and it happens to be a pain in the ass when the scope isn&#x27;t that large)
EvenThisAcronymalmost 11 years ago
<p><pre><code> def compare(a: Int, b: Int): Int This one has not only 232 possible results, but an incalculable (232)264 possible implementations. Even if we are generous and only allow the inputs to be 0 or 1, we still have 2128 implementations. If the only meaningful return values are -1, 0 and 1, indicating “less than”, “equal” or “greater than”, then why would we embed them like specks of dust in a big desert of undefined behaviour? </code></pre> I don&#x27;t agree with this. This is not a &quot;big desert of undefined behaviour&quot;. The behaviour is defined along the entire spectrum of Integer values. &quot;Less than&quot; maps to all values &lt;= -1, &quot;equal&quot; maps to 0, and &quot;greater than&quot; maps to all values &gt;= 1. There&#x27;s no undefined behaviour here.
sitkackalmost 11 years ago
Implicitness as a source of error (in general) seems to raise its ugly head over and over again.
jxfalmost 11 years ago
This entire post seems to conflate &quot;weak typing&quot; with &quot;dynamic typing&quot;. Both are terms that seem to have a lot of common definitions, but they&#x27;re nevertheless distinct.<p>Weak typing usually implies a system where types get coerced easily:<p><pre><code> php -r &quot;echo &#x27;4&#x27; + 4;&quot; 8 </code></pre> Dynamic typing, though, generally means that the type is associated with runtime values. It doesn&#x27;t mean that the typing is necessarily weak:<p><pre><code> ruby -e &quot;&#x27;4&#x27; + 4&quot; -e:1:in `+&#x27;: no implicit conversion of Fixnum into String (TypeError) from -e:1:in `&lt;main&gt;&#x27;</code></pre>
评论 #7812035 未加载
评论 #7813537 未加载
评论 #7811688 未加载
manicdeealmost 11 years ago
It&#x27;s a well written version of, &quot;our software design was sloppy and our programmers took shortcuts. Therefore language feature X is to blame.&quot;<p><pre><code> def findAddress(userId: String): String What does it do? Are you sure? Now lets look at another: def blah(foo: UserId): Address </code></pre> What about<p><pre><code> def find_address_of_user( UserID ) </code></pre> or even better<p><pre><code> class User(Model): … address = our_models.AddressModel( … ) </code></pre> So you can use &#x27;x = user.address&#x27; with no need to explicitly map between users and addresses because the mapping is part of your data structure?<p>In some scenarios, Hungarian notation might make sense:<p><pre><code> def user_address(user): </code></pre> In Hungarian notation you explicitly state what kind of data is expected, so that you can easily determine if mistakes are being made in the code:<p><pre><code> billing_vcard = contact_vcard(customer.billing_contact) </code></pre> as opposed to:<p><pre><code> display_vcard = contact_email(customer.billing_contact) </code></pre> Of course, cue the irrational knee-jerk reaction to &quot;Hungarian notation&quot; by people who don&#x27;t understand what it actually is.<p><pre><code> OO lore has it that pattern matching is evil, and that subtype-polymorphism is the answer to all questions. </code></pre> Not the OOD that I&#x27;ve been taught. Polymorphism is a tool, and it is as much the answer to all questions as a screwdriver is the answer to all construction projects.<p>That the author of this piece has found various languages educational in presenting new ways of solving problems (with code smells, data model smells, or sloppy architecture) is the biggest take-home message for me: don&#x27;t be a &quot;Perl programmer&quot; or a &quot;Scala programmer&quot;. Be a software engineer, and make sure you are aware of all the available architecture rules, modelling guides and design patterns that have been developed over the years to make your job easier.<p>Perhaps I&#x27;m missing something due to having read through the article too quickly. Please educate me.
评论 #7809194 未加载
评论 #7809154 未加载
评论 #7809179 未加载
评论 #7812215 未加载
tiquorsjalmost 11 years ago
News flash!! Strong typing has benefits!