frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

An opinion piece about a definition of consciousness

https://docs.google.com/document/d/1Tmd_3DXbnC2YovDHuMslTs681lN-goSB0NqAv9N3EK0/edit?usp=drivesdk
1•Trenthug•1m ago•1 comments

SiteKit – open-source server management platform

https://www.sitekit.dev/
1•mailnike•2m ago•0 comments

Television Sold the Panama Invasion – Fair (1990)

https://fair.org/extra/how-television-sold-the-panama-invasion/
1•abdelhousni•6m ago•0 comments

KDE Plasma will no longer sleep when your controller is plugged in

https://www.neowin.net/news/good-news-for-gamers-kde-plasma-will-no-longer-sleep-when-your-contro...
2•bundie•17m ago•0 comments

Show HN: Open-source alternative to Cloudflare's Sandbox SDK

https://github.com/system32-ai/sandboxed
1•debarshri•17m ago•1 comments

The Vietnam War: The Press on the Front Lines

https://www.heinzhistorycenter.org/blog/collection-spotlight-vietnam-war-press-on-the-front-lines/
6•georgecmu•24m ago•0 comments

Venezuelan VP: US attack capturing Maduro has 'Zionist overtones'

https://www.jpost.com/diaspora/antisemitism/article-882181
4•pinewurst•24m ago•0 comments

Ask HN: Reading list for being a better engineer?

2•drekipus•26m ago•0 comments

GhostBSD Comes Up with Gershwin, a New Desktop Environment with OS X Like Looks (2025)

https://itsfoss.com/news/ghostbsd-launches-gershwin/
2•alhazrod•27m ago•0 comments

Optimizing Ray Tracing in Haskell (2020)

https://medium.com/@s.nawaz/optimizing-ray-tracing-in-haskell-3dc412fff20a
2•PaulHoule•31m ago•0 comments

Developing a BLAS Library for the AMD AI Engine [pdf]

https://uni.tlaan.nl/thesis/msc_thesis_tristan_laan_aieblas.pdf
3•teleforce•33m ago•0 comments

Prompts Are Engineering Artifacts

https://feipeng.substack.com/p/prompts-are-engineering-artifacts
2•roman10•34m ago•0 comments

Show HN: Why Seamless AI Is a Gaslighting Apparatus

https://github.com/daiki-kadowaki/judgment-transparency-principle
2•daikikadowaki•37m ago•1 comments

MyTorch – Minimalist autograd in 450 lines of Python

https://github.com/obround/mytorch
3•iguana2000•37m ago•0 comments

The Great Gatsby is the most misunderstood novel

https://www.bbc.com/culture/article/20210209-the-worlds-most-misunderstood-novel
3•1659447091•44m ago•1 comments

Show HN: OpenGrad – Self-directed, AI-facilitated graduate programs

https://realadeel.github.io/opengrad/
2•proletarian•48m ago•0 comments

Induction-Based Compass

https://www.youtube.com/watch?v=eiDhbZ8-BZI
3•skogstokig•56m ago•0 comments

SQLNet A social network that looks like Twitter but you write SQL to do anything

https://sqlnet.cc
5•colinbartlett•57m ago•0 comments

Arb – schema-driven CLI generation (Rust example with nested subcommands)

https://github.com/abstractrenderblocks/arb
2•arbopa•1h ago•1 comments

Ask HN: Why Can't We Make Approved Building Plans Reusable?

3•silexia•1h ago•2 comments

Turn your favorite Substack into a printed "newspaper"

https://rawandferal.substack.com/p/substack-print
4•danielleegan•1h ago•1 comments

How the bubble bursts – This time isn't different

https://www.ft.com/content/7987310a-5c90-4976-b730-3559502006e2
6•zerosizedweasle•1h ago•1 comments

The red flags investors should look for in private lending

https://www.ft.com/content/d6b2a25f-7a0d-4f31-96d8-3a0e184af27e
2•zerosizedweasle•1h ago•0 comments

Show HN: Comet MCP – Give Claude Code a browser that can click

https://github.com/hanzili/comet-mcp
4•hanzili•1h ago•0 comments

Interview with Petro Tyschtschenko: Through the Eyes of a Legend

https://www.youtube.com/watch?v=YF4uup4bPjw
1•doener•1h ago•0 comments

Corroded: Illegal Rust

https://github.com/buyukakyuz/corroded
2•csmantle•1h ago•0 comments

Show HN: Shardium – open-source "Dead Man's Switch" for crypto inheritance

https://www.shardium.xyz/
1•maxcomperatore•1h ago•0 comments

Minikv: A little KV store implementation in OCaml to practice DB systems things

https://github.com/alpha-convert/minikv
1•eatonphil•1h ago•0 comments

CSV on the Web

https://csvw.org/
3•cxr•1h ago•0 comments

And This Was My Christmas and New Year Break

https://auteursoftware.substack.com/p/and-this-was-my-christmas-and-new
3•eyeplum•1h ago•0 comments
Open in hackernews

Ask HN: Java why put string in a constant?

1•ramsicandra•7mo 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•7mo 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•7mo 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.