TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Signed Integers Considered Stupid (Like This Title)

3 点作者 blackhole超过 13 年前

1 comment

sixtofour超过 13 年前
"The places where this become stupid are things like using an integer for height and width, or returning a signed integer count. Why on earth would you want to return a negative count?"<p>Manipulating values that don't seem, at first cursory glance, to need negative values using unsigned integers can be thought of as over specification. The difference between two heights can be negative, and adding the differences in and out of measurements would be much more convenient if negative values were allowed. Altitude above sea level can quite easily be negative if we add in ocean depth. It depends on the context, and a blanket prescription is overly restrictive.<p>Even in your for loop example, it could make sense to use a signed integer. Requirements could change, and you might later need to start or end at less than 0. If you had prematurely specified unsigned, then you have to change and double check all code when you eventually need to change your loop. Again, it depends more on context than a blanket prescription.<p>"This is retarded."<p>This kind of language greatly reduces the desire to read the rest of your argument.<p>"I can only attribute the vast overuse of int to programmer laziness. unsigned int is just too long to write. Of course, that's what typedef's are for,"<p>There are other non-lazy reasons to use int. And I don't believe obscuring a primitive type is the best use of typedef, but that's my opinion.