frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Is AI a bicycle for the mind, or a car?

https://twitter.com/kouhxp/status/2123096768996892959
1•mrkn1•54s ago•0 comments

Show HN: TypingCompiler – Practice typing with real code snippets

https://www.typingcompiler.com/test?title=Rust%3A%20Custom%20Fibonacci%20Iterator
1•girouetten21•1m ago•0 comments

Show HN: Mastra Factory, the open-source software factory we use to build Mastra

1•codekarate•1m ago•0 comments

Building collaborative editing in EmDash CMS

https://emdashcms.com/blog/how-we-built-collaborative-editing
1•noah_pham•1m ago•0 comments

Shwcs – A reviewed catalog of B2B software, agencies and services

https://shwcs.site/en
1•andrevallee•2m ago•0 comments

Pikuma: Fundamentals of Computer Science and Mathematics

https://pikuma.com/
1•gurjeet•2m ago•0 comments

William Shatner "Sings" 'Rocket Man' (1978) [video]

https://www.youtube.com/watch?v=8wI4jMxveyI
1•Anon84•3m ago•0 comments

Julia 1.13 brings REPL improvements and more

https://lwn.net/Articles/1108153/
1•leephillips•3m ago•0 comments

Tuios

https://tuios.dev
1•vnzvrt•4m ago•0 comments

PyBot message board – the largest open dataset of swarm dynamics

https://huggingface.co/spaces/HuggingFaceSwarms/pybot-msgboard
1•lewtun•5m ago•0 comments

Cyber Attacks/ Network Outages have become a norm now

https://www.csis.org/programs/strategic-technologies-program/significant-cyber-incidents
1•mastaanshaik•6m ago•2 comments

Historical sociology of neural network research (1991)

https://era.ed.ac.uk/items/db7c1acb-a8a5-4b14-8874-f1138e6751b8
1•theanonymousone•6m ago•0 comments

Evening Atlas

https://willjobs.com/evening-atlas/
2•NickDouglas•7m ago•0 comments

The Cognitive Case for Play in Technical Work

https://www.joekarlsson.com/blog/cognitive-case-for-play-in-technical-work/
1•joekarlsson•7m ago•0 comments

Everything After Code, as Code

https://www.pulumi.com/blog/everything-after-code-as-code/
1•cnunciato•8m ago•0 comments

Wayfinder: Frontier-Level Code Search at a Fraction of the Cost

https://blog.voyageai.com/2026/11/18/wayfinder-code-search/
2•emschwartz•9m ago•0 comments

Principles of good design (Dieter Rams)

https://designmanifestos.org/dieter-rams-ten-principles-for-good-design/
3•mrkn1•11m ago•2 comments

M.C. Escher's Art Creates Mathematical Worlds

https://www.quantamagazine.org/how-m-c-eschers-art-creates-bizarre-mathematical-worlds-20261118/
3•baruchel•12m ago•0 comments

"Anthropic Is Not a Safe AI Company" – Coalition Challenges Anthropic Safety

https://www.businesswire.com/news/home/20261118974464/en/Anthropic-is-Not-a-Safe-AI-Company---Bro...
3•sshah03•13m ago•1 comments

Show HN: Can an AI Agent Bypass Your Website Security?

https://assess.poh.org/
3•timshell•13m ago•0 comments

Cerebras Systems Inc. (CBRS): Hot Garbage [pdf]

https://culperresearch.com/wp-content/uploads/2026/10/Culper_CBRS_10-28-2026.pdf
2•Betelbuddy•15m ago•0 comments

Jensen Huang Tweets

https://daringfireball.net/linked/2026/11/18/huang-tweets
2•chmaynard•15m ago•0 comments

We're Giving AI Agents the Keys to Our Computers. That's a Security Nightmare

https://soargram.io/content/273880860
2•levicanskij•17m ago•0 comments

Microsoft rejected Rockstar's pitch to put GTA3 on the original Xbox (2021)

https://www.eurogamer.net/microsoft-recalls-time-it-rejected-rockstars-pitch-to-put-gta3-on-the-o...
2•TMWNN•18m ago•1 comments

Dealing with LLMs in IETF Discussions

https://datatracker.ietf.org/doc/draft-fengfar-led/
2•mooreds•19m ago•0 comments

Contexting vs. Context

https://cutlefish.substack.com/p/tbm-452-contexting-vs-context
1•mooreds•19m ago•0 comments

High school disables AI detector after it kept mistaking everyday items for guns

https://www.techspot.com/news/114607-pennsylvania-high-school-disables-ai-weapons-detector-after....
1•healsdata•20m ago•0 comments

Why a "stable" labor market feels so bad [video]

https://www.youtube.com/watch?v=rY9s0tMzfM8
1•mooreds•20m ago•0 comments

SetShot macOS app – snapshot and diff macOS settings changes

https://github.com/adamengst/setshot-app
2•amichail•20m ago•0 comments

ElevenLabs Down

https://status.elevenlabs.io/united-states
2•cheapcheerful•22m ago•0 comments
Open in hackernews

Ask HN: Java why put string in a constant?

1•ramsicandra•1y ago
I'm relatively new to Java. I often notice a pattern where there is a list of constant which value are equal to the name.

  class Constant {
    public static final String ALBUM = "album";
    public static final String NAME = "_name";
    public static final String DISPLAY_NAME = "display-name";
    public static final String SERVICE_NAME_METRIC_NAME_PREFIX = "service_name.metric_name";
  }

Here is a public example of this practice I could find: https://developer.android.com/reference/android/provider/MediaStore.MediaColumns

I could understand that this might help in 2 ways refactoring and typo. This reduces chance of typo because you'll get compile error instead of run-time error if you typo a constant. This might also help in refactoring if you ever wants to change the value. but if may use this android public API example, I don't think it's wise to change a field name ever. If it's decommissioned, it's good to keep it so we don't re-use the field. If it's a new better field available, I think it should have a different name. I maybe making a straw man argument here. Let me know. If it's an internal API where such refactoring might make sense -- I still kind of think internal API should also be backward compatible, replacing a string are not a complicated operation in my opinion.

I see that this practice has a cost. One being that in every class that use this API. You need to add an import. It's also often the const is only used once from my experience.

  import static com.example.MediaFields.NAME;
  import static com.example.MediaFields.DISPLAY_NAME;

  String value = json.getString(NAME);
  String value2 = json.getString(DISPLAY_NAME);
vs

  String value = json.getString("name");
  String value2 = json.getString("display_name");
You write 1 line for declaration plus 2 lines for each class using this API. This is not a big deal in terms of LoC and I'm not an LoC police. However, my sense is the cost outweigh the benefit.

What do you think?

Comments

lanna•1y ago
You just made TWO typos: "display-name" vs "display_name" and "_name" vs "name", automatically counter-argumenting your point.

It is also for documentation. With the declared constants, we know all possible values. With plain strings, how am I supposed to know which values to use?

The benefits far outweigh the marginal cost.

ramsicandra•1y ago
The -, _, and leading _ are just variations of white space / separator I have encountered. I think it's possible to document all the allowable values in the Javadoc section of the function that takes in string as their argument.

In the specific android example, I would put it here. Under projection params where it takes in all the Images.Media.* string consts.

https://developer.android.com/reference/android/content/Cont...

Though, if it's a practice of Java Engineer to document allowable enum like string as a constant, then I can say that's a valid argument.