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.

Reconstant: Share constant definitions between programming languages

33 pointsby nyellinabout 4 years ago

6 comments

tempodoxabout 4 years ago
String constant generation for C is wrong. It should be<p><pre><code> const char X[] = &quot;This string cannot be reassigned.&quot;; </code></pre> instead of<p><pre><code> const char *X = &quot;This string CAN be reassigned&quot;; </code></pre> In the second case, you can do<p><pre><code> X = &quot;Another value&quot;; </code></pre> X wouldn&#x27;t be constant, but only the value it points to. Also, it costs sizeof(char *) more memory than the actual string contents.
评论 #26376303 未加载
评论 #26385314 未加载
s_gourichonabout 4 years ago
This might make sense for &quot;big&quot; projects, with already several languages and an important need. Else it&#x27;s not obvious if the burden of having yet another dependency has a favorable benefit-cost result.<p>In other words, the danger of &quot;now you have two problems&quot; should be considered. <a href="http:&#x2F;&#x2F;regex.info&#x2F;blog&#x2F;2006-09-15&#x2F;247" rel="nofollow">http:&#x2F;&#x2F;regex.info&#x2F;blog&#x2F;2006-09-15&#x2F;247</a>
评论 #26375304 未加载
yoav-laviabout 4 years ago
Interesting idea, I would suggest looking into TypeScript enum support as well as it is a different syntax than the JS object based variant (the const string definition can be shared)<p><a href="https:&#x2F;&#x2F;www.typescriptlang.org&#x2F;docs&#x2F;handbook&#x2F;enums.html" rel="nofollow">https:&#x2F;&#x2F;www.typescriptlang.org&#x2F;docs&#x2F;handbook&#x2F;enums.html</a><p>Edit: from the image it looks like you&#x27;re using some non standard formatting for the JS output, using Prettier may be more standard - <a href="https:&#x2F;&#x2F;prettier.io" rel="nofollow">https:&#x2F;&#x2F;prettier.io</a>
评论 #26376312 未加载
zffrabout 4 years ago
To the OP, I’m just curious what was the problem you were facing that inspired this project?<p>I haven’t run into a scenario where I would use something like this before
评论 #26376325 未加载
whateveracctabout 4 years ago
i just use Nix for this! define the constants in Nix, and generate the programming language files with simple Nix string programming.
domanoabout 4 years ago
Environment variables do the job already, where is the benefit?
评论 #26375186 未加载
评论 #26375292 未加载
评论 #26375255 未加载