frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Code Review Is Dead

https://www.jlchnc.com/essays/code-review-is-dead
1•pizzuh•1m ago•0 comments

The US army veteran and the mystery Boeings flying Sudan's war routes

https://www.reuters.com/investigations/us-contractor-mystery-boeings-operating-sudan-paramilitary...
1•Teever•1m ago•0 comments

A different approach to aim training for FPS games

https://www.pramit.gg/post/i-made-an-aim-trainer
1•pmazumder•1m ago•1 comments

An Elite NYC Public School Admitted 777 Students. Only 3 Were Black

https://www.nytimes.com/2026/07/14/nyregion/nyc-specialized-schools-black-hispanic.html
1•apparent•2m ago•0 comments

White House Teleprompter Operator Probed over Alleged Bets on Trump Speeches

https://www.wsj.com/politics/policy/white-house-teleprompter-operator-investigated-for-alleged-be...
1•qlte•2m ago•0 comments

Bootstrapping Trust: From Isolated Build Machines to Enclaved CI Pipelines

https://www.youtube.com/watch?v=V411Vadty38
1•benldrmn•3m ago•0 comments

Earth Is Dimming

https://www.economist.com/interactive/science-and-technology/2026/07/15/earth-is-dimming
1•Brajeshwar•4m ago•0 comments

Starship's Thirteenth Flight Test

https://www.spacex.com/launches/starship-flight-13
2•janpot•5m ago•0 comments

Scientists unravel the fast-moving 'butterfly effect' of the deep ocean

https://www.cam.ac.uk/research/news/scientists-unravel-the-fast-moving-butterfly-effect-of-the-de...
1•gmays•6m ago•0 comments

Hiring - Software Engineer (AI-Native WMS) Bilingual (ENG.KOR) Carson, CA

https://app.notion.com/p/wooltari/Software-Engineer-AI-native-WMS-372c2cf4d496805b8080c067d616183...
1•wooltarihr•7m ago•1 comments

ClickFix operator's blockchain C2 off the public ledger: 4 months, ~127 hosts

https://meltedinhex.com/posts/clickfix-errtraffic-blockchain-c2/
1•sdkhere•10m ago•0 comments

Kimi K3 full benchmarks and model details

1•benjiro29•10m ago•1 comments

Cyber Letters of Marque and Reprisal – Digital Privateers to Combat Cyber Crime

https://www.scribd.com/document/1062415707/Cyber-Letters-of-Marque-and-Reprisal
1•Vaslo•14m ago•0 comments

L3 Simulator: agent orchestrator over GH issues

https://github.com/czarandy/l3-simulator
1•czarandy•16m ago•0 comments

Google Gemini Launch Delayed as Tech Falls Short of Internal Goals

https://www.bloomberg.com/news/articles/2026-07-16/google-gemini-launch-delayed-as-tech-falls-sho...
7•mfiguiere•17m ago•1 comments

California authorizes its DMV to join a national ID database

https://papersplease.org/wp/2026/07/16/gov-newsom-signs-law-to-upload-california-data-to-national...
2•logickkk1•17m ago•0 comments

JD Vance: Jeffrey Epstein had clear connection to Mossad

https://www.ynetnews.com/article/sjyjztremg
3•root-parent•20m ago•0 comments

Airbus migrating 70 critical apps from AWS to France's Scaleway

https://www.theregister.com/paas-and-iaas/2026/07/16/airbus-migrating-70-critical-apps-from-aws-t...
3•rwmj•20m ago•1 comments

AI disruption in private credit: exposure to software firms in BDCs (BIS)

https://www.bis.org/publ/bisbull128.htm
1•aanet•21m ago•1 comments

NASA Dragonfly - a rotorcraft to explore Saturn's moon Titan

https://science.nasa.gov/mission/dragonfly/
2•thinkingemote•22m ago•0 comments

Connect more of your apps to Search

https://blog.google/products-and-platforms/products/search/connected-apps/
1•thm•22m ago•0 comments

Linus Torvalds rebukes anti-AI stances in the Linux kernel code review process

https://www.tomshardware.com/software/linux/linus-torvalds-rebukes-anti-ai-stances-in-the-linux-k...
3•vanburen•22m ago•0 comments

Nintendo Switch Joy-Con Removable Battery Replacement Procedure

https://www.nintendo.com/en-gb/Support/Troubleshooting/Battery-replacement/Joy-Con-L-HAC-015-01-B...
1•haunter•24m ago•0 comments

Please Stop Making Me Opt Out of AI

https://www.wired.com/story/please-stop-making-me-opt-out-of-ai/
3•Brajeshwar•25m ago•0 comments

MergeStat: Query your Git repo with SQL

https://www.mergestat.com/
1•nvahalik•25m ago•0 comments

Young Drivers Are Going 'Psycho' on the Road–and Filming It

https://www.wsj.com/tech/personal-tech/dash-cams-drivers-tiktok-3101b404
1•bookofjoe•26m ago•1 comments

CLR: Checker of Lifetimes and other Refinement types for Zig

https://github.com/ityonemo/clr/
2•lioeters•26m ago•0 comments

SPCX is now Wall Street's most shorted new stock

https://invezz.com/news/2026/07/16/the-worlds-most-valuable-ipo-spcx-is-now-wall-streets-most-sho...
20•lbrito•26m ago•10 comments

Minefield Quiz: Countries of the World with No Borders

https://brilliantmaps.com/world-minefield-game/
1•Kaibeezy•28m ago•0 comments

Pricklypear: Vibeslop Interpreted Lisp with Postgres AST, Written in OCaml

https://pricklypear.rocks/welcome
1•sroerick•33m ago•1 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.