Hacker News new | past | comments | ask | show | jobs | submit | nayuki's comments login

Java SE 11 (Sep 2018) introduced the ability to run source files directly. So instead of the old `javac Main.java && java Main`, you can do `java Main.java`. https://openjdk.org/projects/jdk/11/ , https://openjdk.org/jeps/330

Furthermore, there's ongoing work ([0] and related JEPs) to allow running single Java files without an enclosing class and the static main method:

  void main() {
      System.out.println("Hello, World!");
  }

This is currently (as of JDK 24) under preview, so such a file needs to be run with "--enable-preview". E.g.

  $ java --enable-preview HelloWorld.java
  Hello, World!
[0] https://openjdk.org/jeps/445

With the latest EA release (EA 24) of JDK 25 [1], you no longer need the `--enable-preview`. You can also simplify the println to:

  void main() {
      IO.println("Hello, World!");
  }

JEP 445 has been followed by JEP 512 which contained minor improvements and finalizes the feature [2].

If you want to use 3rd-party libraries, I highly recommend trying JBang [3].

[1] https://jdk.java.net/25/release-notes

[2] https://openjdk.org/jeps/512

[3] https://www.jbang.dev


Hmmm... Disappointing that the static methods are no longer imported as of JEP 512. I thought that was the whole point of the new IO class. If we can't write "println" we might as well just write "System.out.println".

> The EU is also looking into creating a digital euro

It's weird to call it a "digital euro" because the euro is already digitized by traditional banks! At an existing traditional bank, your balance is already a discrete number. Money can be sent and received electronically on communications networks without using physical media like coins and bills and cheques.


> the shared reference analogy describes what happens in a computer. Nothing is truly parallel when accessing a shared resource. We need to take turns reading the pages. The hardware does this quickly by means of cached copies.

This exists, but it's uncommon: https://en.wikipedia.org/wiki/Dual-ported_RAM , https://en.wikipedia.org/wiki/Dual-ported_video_RAM


I recall from maybe 5~10 years ago where someone filmed a laser show on a camera and the sensor got damaged with lines stuck in the on state. The lasers were moving very quickly so they wouldn't hit any spot for a long time, but apparently it was enough to damage the camera. e.g. https://www.youtube.com/watch?v=8bpyMST7eCA [2015-12-02] (not the first video that I ever saw)

This is one of those cases where marketing is correct.

Oh tell me, if your CPU processes 1 byte in 1 cycle, and it runs at 800 MHz, how many bytes does it process in 1 second?

The answer is 800 million bytes, or 800 (real) megabytes. It cannot be 800 mebibytes. (Equal to 763 mebibytes.)

Similarly, let's say we have a 1-bit Boolean attribute for each person in the world, and the world population is 8 062 000 000 billion people. How many bits do we need in our database? It's 8.062 gigabits, not 8.062 gibibits. (Equal to 7.508 gibibits.)

The telecom industry has always used power-of-1000 prefixes on bits and bits per second. You have a gigabit Ethernet LAN, and assume no protocol overhead. How long does it take to transmit a 4.7 GB (real gigabytes) DVD image? Multiply by 8 to convert from bytes to bits, so that's 37.6 Gb, so that will take 37.6 seconds to transmit. But how long does it take to transmit a "700 MB" (actually MiB) CD image? Well, it's 734 MB (real megabytes), so 5872 Mb, which is 5.872 seconds.

The problem with the abusively overloaded definition that 1 kilobyte = 1024 bytes, 1 megabyte = 1048576 bytes, etc. is that it fails to align with the rest of the metric system, or even how we group decimal numbers into thousands and millions. The computer industry is wrong here.

And now you have the problem that you can't fit a memory dump of "16 GB" of RAM onto a "16 GB" flash memory card, because the former is actually GiB but the latter is real GB.


> Oh tell me, if your CPU processes 1 byte in 1 cycle, and it runs at 800 MHz, how many bytes does it process in 1 second?

An interesting metric, used by noone in the Universe except you for the sake of this discussion. But let's entertain this: if the actual CPU speed is 838,860,800Hz, how many bytes does it process in 1 second?

> Similarly, let's say we have a 1-bit Boolean attribute for each person in the world

I have no problem with definition of bits.

> And now you have the problem that you can't fit a memory dump of "16 GB" of RAM onto a "16 GB" flash memory card, because the former is actually GiB but the latter is real GB.

Remarkable circular reasoning, since the Marketing Kilobyte was defined in the 1990s precisely to inflate actual storage sizes without getting class action suits.

> it fails to align with the rest of the metric system

Look, byte is not derived from fundamental units. It is thus not a part of metric system so SI has zero business regulating information storage. On the other hand you can't buy a computer that does not address memory in anything other than powers of two. Nor you could ever buy a 1000 million bytes RAM chip, because they don't ever exist for basic reason that binary computers use 2^n addressable space.


> An interesting metric, used by noone in the Universe except you for the sake of this discussion.

The speed of cryptographic function such as ciphers and hashes are quoted in cycles per byte. This is because in the pure numeric code, without worrying about memory transfer speed, the speed of the crypto algorithm is directly proportional to the CPU clock speed. https://en.wikipedia.org/wiki/Encryption_software#Performanc... . Random example: https://bench.cr.yp.to/results-hash/amd64-hertz.html

> if the actual CPU speed is 838,860,800Hz, how many bytes does it process in 1 second?

If the CPU is 800 MiHz (never heard of that term, lol), then it processes 800 MiB in 1 second. Stated differently, 839 MHz --> 839 MB.

> Remarkable circular reasoning

No, I'm pointed out that the industry has already splintered into two. Your "16 GB" of RAM is a different measure than "16 GB" of HDD or SSD.

> It is thus not a part of metric system so SI has zero business regulating information storage.

If a byte is not derived from fundamental SI units, then it should not take on SI prefixes.

Otherwise, if it takes on prefixes, it should respect the SI definition and not abusively have its own contradictory definition.

> On the other hand you can't buy a computer that does not address memory in anything other than powers of two.

So what? I can use that same logic to argue that all RAM sizes should be quoted in base-2, so I'm buying 1_0000_0000_0000_0000 (base-2) bytes of RAM, right? Clearly base-10 notation is a poor fit, so why not go all the way to base-2?

> Nor you could ever buy a 1000 million bytes RAM chip

It is certainly feasible. You can just cut a bunch of rows at the end. I know how binary decoder gates work.

Also, if you have a computer and put in a 4 GiB stick of RAM and a 2 GiB stick, then you have 6 GiB of addressable memory, which is clearly not a power of 2.


> The speed of cryptographic function such as ciphers and hashes are quoted in cycles per byte.

That's called throughput, and denomination for it absolutely doesn't matter. You can measure it in megabytes as well as in MarketingMegabytes.

> If the CPU is 800 MiHz (never heard of that term, lol), then it processes 800 MiB in 1 second.

Plot twist, your 800MHz CPU oscillator would never run at 800,000,000Hz sharp for any substantial stretch of time. And clock specs are typically rounded numbers. That's why this whole example is ridiculous.

> No, I'm pointed out that the industry has already splintered into two.

No shit it did. My point is that it did it for no advantage at all. You could measure storage megabytes in same normal sane megabytes as before, just couldn't lie about it to the customers.

> If a byte is not derived from fundamental SI units, then it should not take on SI prefixes.

Kilo is a Greek prefix, not SI prefix. You can split hairs that it should mean sharp thosuand but it does not exist in terms of computer architecture. Kibi however is completely made up shit used by noone else and it sounds like a wannabe cartoon character.

> It is certainly feasible.

It is not feasible, that's why they aren't ever gonna be made.

> Also, if you have a computer and put in a 4 GiB stick of RAM and a 2 GiB stick, then you have 6 GiB of addressable memory, which is clearly not a power of 2.

It is not a power of 10 either, you should really think this through.


For frequency, a decade is a ratio of 10, akin to a bel. And in photography, a stop or an EV is a factor of 2, akin to an octave. https://en.wikipedia.org/wiki/Logarithmic_scale#Common_uses

There is a solution for you - log points! https://en.wikipedia.org/wiki/Relative_change#Logarithmic_ch... , http://a-loonie-saved.blogspot.com/2008/08/log-points.html

An example of deceptive arithmetic: A mutual fund's 5-year history of annual returns is −70%, +30%, +50%, +20%, +40%. Naively, the total return for the 5-year period looks like +70%. But in fact it's −1.72%, because the reciprocal function makes the −70% very “heavyweight” compared to the positive changes.

Using log points instead, the 5-year sequence is approximately −120.4, +26.2, +40.5, +18.2, +33.6. The sum of these rounded numbers is −1.9 (nowhere near +60.0), which agrees well with the correct result of about −1.735 log points (i.e. −1.72%).



> I do wish we would have metriced around base 12

Please clarify what you mean by this. Let me call your system altmetric for clarity.

Surely, you want altmetric to use prefixes that are powers of 12 - okay, fair enough. I see the analogy with the fact that 1 foot = 12 inches, and how base-60 is used in minutes and seconds (also arcminutes and arcseconds). (But why no thirds and fourths?)

But do you want altmetric to require all numbers to be expressed in base-12? If no, then your system does not allow easy conversion. In real metric, the fact that 1.234 kg = 1234 g is a trivial conversion, and it turns a calculation problem into a mere syntactical transformation. If yes and you require base-12, then you've basically alienated everyone. It would be about as weird as telling construction workers and doctors and drivers to use hexadecimal. But at least it makes unit conversions as trivial as base-10 metric.

Let's say you have your altmetric utopia with prefixes based on powers of 12, regardless of whether you require numbers to be expressed in base-12 or not. What do you do about the rest of the world which uses base-10?

You're the head chef for a cruise ship, and the upcoming voyage has 572 people for 14 days. (Imaginary) guidelines say that to keep people happy, you need to provision an average of 800 g of food per person per day. In metric: 572×14×800 g = 6406400 g ≈ 6406 kg ≈ 6.4 Mg (tonne), a simple calculation.

In altmetric, you still get 6406400 g, but now you need to start dividing by 12 repeatedly to form larger groups. Let's just say alpha = 12^3 and beta = 12^6. So 6406400 g ≈ 3707 alphagrams ≈ 2.15 betagrams. That doesn't make life any easier.

Or let's take a somewhat different example. When buying stocks on the market, you specify how many shares you want to buy and the price you want to buy at. But you can't say "I have $X, buy as many shares as possible without exceeding $X". So say you just received a $30000 bonus (after tax) and your favorite stock has an asking price of $68.49 per share for an unlimited quantity. In decimal math, this is easy to figure out - $30000/($68.49/share) = 438.02 shares, so you round down to 438 shares and place your order.

But suppose you're in some F'd up world where you have to specify your stock order in stones, pounds, and shares ("ounces"), where 1 stone = 14 pounds, 1 pound = 16 shares. So your order of 438 shares becomes 1 stone + 13 pounds + 6 shares. You had to do an excessive amount of busywork just to fit into that non-decimal system. And along the way, you might have to think about things like the fact that it's also $15341.76/stone, $1095.84/pound.

You're not the first person I've come across who wants measurements to be grouped/divided into units by some factor other than 10, usually 12. I did a lot of thinking about this, and my conclusion is that if you make an altmetric system where prefixes are not powers of 10, then you lose a huge benefit of the metric system. (The other huge benefit is coherent derived units, like 1 joule = 1 newton × 1 metre.)

> I take back what I said about the mile.

It looks like the derivation of the English statute mile is this: 1 mile = 8 furlongs, 1 furlong = 10 chains, 1 chain = 4 rods, 1 rod = 5.5 yards, 1 yard = 3 feet. You can confirm that 8 × 10 × 4 × 5.5 × 3 = 5280.

https://en.wikipedia.org/wiki/Mile#Statute , https://en.wikipedia.org/wiki/Furlong , https://en.wikipedia.org/wiki/Chain_(unit) , https://en.wikipedia.org/wiki/Rod_(unit)


This mythical altMetric utopia requires everyone to actually count in base C (to use dc notation) as well. the main advantage is that thirds and quarters(the useful fractions) tend toward whole numbers. In base 10 all you get are halfs and fifths(and nobody wants to use fifths)

everything would still be metric, the calculations would be as simple, every one would learn their baseC times tables and how to do baseC long division.

$3000 / $(68.49/share) = 54.59B1 shares 54 shares = total cost of $2B88.B6 take your remaining 33.07 and have a nice lunch

1000 Cgrams(1728Agrams) = 1kiloCgram 1000kiloCgrams = 1 Cton

but going smaller a third of a Cgram is 0.4 Cgrams a quarter is 0.3 Cgrams

Does this actually makes any ones life better... Probably not. but it has every advantage of using baseA and the minor(very minor) advantage that thirds and quarters are easier.

But this assumes that baseC won over baseA 1500 years ago, and if there is one truly global success story it is baseA, many languages, cultures, writing systems, but everyone(statisticly) uses baseA with arabic style numbers

footnote: I am using the slightly obnoxious prose of using baseA and baseC to avoid the confusing ambiguity that saying base 10 in base twelve means there are twelve numbers in a digit(where the word digit, coming from the way we count on fingers would also mean twelve.)


> Sure, and 10db means "10x more power". But: 1. 10x more power than what? It changes, and you Just Have to Know.

That gives me an idea - explicitly state the basis and multiply. So the current notation "3 dBm" should instead be "1 mW × 3 dB".

Furthermore, any addition in the logarithmic domain must be grouped, like: "3 dBm + 5 dB" --> "1 mW × (3 dB + 5 dB)".


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: