r/programming • • Oct 21 '17

Using Java 9 Modularization to Ship Zero-Dependency Native Apps

https://steveperkins.com/using-java-9-modularization-to-ship-zero-dependency-native-apps#.Wes5IMWbUWE.reddit
310 Upvotes

109 comments sorted by

View all comments

Show parent comments

77

u/SizzlingVortex Oct 21 '17

From the article, I think the author describes native as:

  • Being able to bundle the JVM (versus having the user install Java separately)

  • Not having to embed a web browser like, for example, Electron -- which is called a web-hybrid app in the article

68

u/BadMoonRosin Oct 21 '17 edited Oct 21 '17

Yup... it's a good discussion topic, and I definitely wrestled with the phrasing. Having studied Pascal back in university, and starting out my career as a C++ dev, I too have always thought of "native" as being "a standalone executable".

However, I would run into issues when playing with cross-platform GUI libraries such as wxWidgets, GTK, or Qt. I always wanted to compile my apps down to a statically linked, standalone executable. I didn't want to have to ship a bunch of shared libs, or depend on them being present on the target machines! Yet more knowledgeable developers would calmly try to explain to me that dynamic linking is often technically superior (or with Qt, necessary due to licensing).

Also, last year I went to a Java conference and sat through a few sessions on profiling and JVM tuning. It was a lightbulb moment, that left me considering the possibility that a runtime VM with a JIT compiler really IS a technically superior approach over full AOT compilation.

So anyway, if you're having to ship to tens of megs of dynamically linked libraries with your "native" app... then is it really THAT far removed from an app that's linked to an embedded runtime? I'm not so sure. And I would strongly argue that you have no less claim to the "native" label than Electron has.

43

u/doom_Oo7 Oct 21 '17

Native == the executable you run is a sequence of ASM instructions for your cpu / os without run-time interpretation of algorithms or code necessary for your software's execution.

Also, you can link Qt (and any lgpl stuff actually) statically, as long as you provide object files (not source) upon request.

24

u/[deleted] Oct 21 '17

I would say that is native code.

However we often talk about other aspects of "nativeness" such as having a native looking gui, or working in the appstore, and an end-user might consider those 2 as important.

Although I do agree with you, that I'm unhappy with how the OP has defined native.

4

u/vytah Oct 21 '17

So lemme get it straight: If I ship the following files and only the following files:

myapp.exe
myapp_main.obj
qt5_static.obj
libqt5.dll
makefile.bat
license.txt

(where makefile.bat contains just a single linker invocation)

then everything is fine and dandy?

4

u/wirelyre Oct 22 '17

(I am not a lawyer.) Pretty much. Here's the relevant section from the LGPL version 3:

4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following:

[…]

The conditions are basically:

  • you need to identify that the software contains LGPL'd code; and

  • the user has to be able to modify the LGPL'd portion of the software (just like how you already know through the GPL).

In particular,

4.d) Do one of the following:

4.d)0) Convey the Minimal Corresponding Source […] and the Corresponding Application Code in a form suitable for […] the user to recombine or relink the Application with a modified version.

I took out some important parts. You should read them.

Actually, you should seriously check out the GPL and LGPL texts. They are really lovely pieces of writing, and quite readable.

4

u/doom_Oo7 Oct 22 '17 edited Oct 22 '17

actually you don't even need the libqt5.dll since it's linked statically. And you don't need to ship the .obj's with your app, just to provide them upon request (putting them on your website is fine).

7

u/pron98 Oct 21 '17 edited Oct 21 '17

Native == the executable you run is a sequence of ASM instructions for your cpu / os without run-time interpretation of algorithms or code necessary for your software's execution.

Sure, but the line isn't always so clear cut. A browser executes a lot of Javascript code (not just in web pages, but also in extensions); MS office executes VB code; an OS executes a lot of scripts; games' actual content is usually found in script files interpreted at runtime. Most complex software today must interpret/compile some code as it runs, so while you could decide to draw the line somewhere, the distinction is not always very useful.

3

u/bloody-albatross Oct 21 '17

Also, to a user it is quite irrelevant what language is used. They define native app differently. If your app uses the native GUI toolkit and behaves natively, then it's a native application from the user point of view. So then not even C++ and Qt is truly native, but a C# application can be (under Windows).

→ More replies (17)

4

u/xandoid Oct 21 '17

My definition of native is an app that does not replace anything the OS supplies with cross-platform alternatives.

So a Java app using JavaFX to paint its own widgets is not a native app just because it happens to be AOT compiled down to a PE binary on Windows.

8

u/doom_Oo7 Oct 21 '17

My definition of native is an app that does not replace anything the OS supplies with cross-platform alternatives.

I don't think that's a good definition: a lot of OSes provide nothing in the GUI department per se. VxWorks, GenodeOS, Linux... does this mean there can't be native apps in them ?

5

u/bloody-albatross Oct 21 '17

Under Linux its more fine grained. E.g. those Gtk applications don't feel native under my KDE desktop (god I hate the Gtk file chooser).

2

u/The_Jare Oct 21 '17

Strictly speaking, if the OS does not provide it then you are not replacing it, so it doesn't count against the nativeness. :)

1

u/xandoid Oct 22 '17

You're absolutely right. That is exactly what my definition means.

→ More replies (4)

1

u/xandoid Oct 22 '17 edited Oct 22 '17

That is a complete non sequitur. I said "replace", not add something the OS doesn't provide.

1

u/NostalgicCloud Oct 21 '17

Except its not replacing the GUI. It provides it's own widgets that reply on the native api's

1

u/Poddster Oct 22 '17

So if a game has a lua interpreter in it, the entire game is non native?

→ More replies (1)

4

u/Gravitationsfeld Oct 21 '17

It's really not. In theory that sounds great, but in practice a JITC never has the time to do the code gen of an offline compiler which has two to three magnitudes more time before people start complaining.

2

u/[deleted] Oct 21 '17

I think we should specify the type of nativeness such as "native code" or "native appstore integration" etc.

These days we do so much in the browser that electron might count for native UI. As for native code, I would expect you to emit ASM. You certainly have a native installation experience with a single double-clickable file.

2

u/SizzlingVortex Oct 21 '17 edited Oct 21 '17

Yup... it's a good discussion topic, and I definitely wrestled with the phrasing.

I agree with calling it native. In today's world it's pretty much embedded web browser (web-hybrid) apps vs everything else. I realize I'm speaking "generally" here, but I'm specifically comparing embedded web browser apps vs non-embedded web browser apps. For example, IntelliJ IDEA (which requires the JDK -- be it the bundled one or one that already exists on your computer), I think most users would call this IDE "native" when compared to Electron. However, if I was comparing IntelliJ against an app that compiled down to native code, that didn't need a runtime environment, then I would make the distinction that the app that doesn't require a runtime is the "native" app.

Edit: To the downvoter(s), I'm interested in knowing what you disagree with.

11

u/meschbach Oct 21 '17

I didn't down vote but I was tempted too. As an experienced Java developer when I read the term "native" it initially lead me to believe the program was in object code of the target processor, not in byte code. Not a a pure Java application. The article makes it sound as though a native executable has byte code embedded within the image.

1

u/zanotam Oct 22 '17

Eh, I read a good argument elsewhere in this thread that basically came down to reviewing the standard definition using the concept of S-expressions. If code is data then you can't distinguish between the 'obvious' example of code interpreting data structures and code interpreting other code.

12

u/Drarok Oct 21 '17

I use a lot of JetBrains’ products, but I would never call them native. They’re terrible platform citizens on macOS, and the default keymap often clashes with system-wide keyboard shortcuts. Even the cursor movement keys are wrong.

Fantastic feature sets, but I merely tolerate them being java.

→ More replies (3)
→ More replies (1)

4

u/ApatheticBeardo Oct 21 '17

So not native at all.

Ok.

1

u/donalmacc Oct 23 '17

That description sounds like bundling a JVM instead of bundling a web browser. I fail to see how that’s any more native...