News for hackers. Stuff that matters.
Re:Writing Gnome Apps with Swift by diggan on Thursday March 28, 2024 @05:42AM (#39849198)
> Isn't it good that now there is an alternative to C?

It's not exactly the first alternative, GJS (Gnome JavaScript) have existed for a long time and is also a C-like language, so doesn't seem this would give too much value compared to just using GJS, unless you know Swift a lot better than JavaScript but the languages are similar enough that even that doesn't provide much value.

AFAIK, GJS is an official Gnome project too, so there will be a vast difference in ecosystem support compared to Gnome apps written in Swift, which I'm not sure is so popular outside of Apple circles.

Re:Writing Gnome Apps with Swift by codedokode on Thursday March 28, 2024 @05:48AM (#39849229)
JavaScript is non static-typed and you'll spend time fixing bugs that can be prevented by static typing. Also, GJS is not well documented, as far as I remember.
Re:Writing Gnome Apps with Swift by diggan on Thursday March 28, 2024 @05:52AM (#39849256)
> JavaScript is non static-typed and you'll spend time fixing bugs that can be prevented by static typing.

Use TypeScript if types are so important for you. Others find their own way of handling those issues without getting tripped up on it. Hardly a reason to completely switch between two languages in my mind, but of course it's alright if it's reason enough for you. Luckily there are acceptable workarounds for both groups of people :)

> Also, GJS is not well documented, as far as I remember.

What exactly is missing here? There are guides for the basics, API reference exists and there is a ton of apps you can look into for inspiration and/or figure out specific implementations.

Is that really worse than what exists for writing Gnome apps with Swift? Seems like a really weak argument for using Swift instead of GJS.

Re:Writing Gnome Apps with Swift by codedokode on Thursday March 28, 2024 @05:57AM (#39849287)
Swift is compiled, static-typed language and without tons of legacy like JS (for example, it has real objects, not dictionaries). Doesn't require an interpreter. It seems to be better than JS in every aspect.
Re:Writing Gnome Apps with Swift by diggan on Thursday March 28, 2024 @06:04AM (#39849337)
One mans gold is another mans trash :) Static typing seems to be a neat addition for lots of people, that's great! Doesn't mean it's a silver bullet that improves development for everyone, and that's OK.

I still don't see how a language (GJS) with an already existing ecosystem of writing Gnome apps, lots of examples, API references and more is worse for writing Gnome apps than Swift, that seems to have been launched just some days ago?

Edit: I realize now that the "Adwaita for Swift" this blogpost is about isn't even an official Swift project, is the output of a student interested in Swift and Gnome.

Re:Writing Gnome Apps with Swift by sph on Thursday March 28, 2024 @08:17AM (#39850297)
I think you are vastly overestimating how good and current the GJS documentation and examples are. Without touching the fact that it is NOT a stable API and breaking changes are very common.

Even the gold standard of GTK coding in C is still very undocumented outside of the happy path and confusing due to the Gtk 3->4 migration, and the only approach to learning it is by reading what other Gtk apps do.

Re:Writing Gnome Apps with Swift by Betelgeuse90 on Thursday March 28, 2024 @07:08AM (#39849709)
Honestly I used to think the same way about JS, because not having types allowed for very concise code sometimes. But the more I used Swift I realized how powerful type inference can be, and the difference in conciseness shrunk to basically nothing.
Re:Writing Gnome Apps with Swift by diggan on Thursday March 28, 2024 @07:17AM (#39849760)
Heh, yeah, everyone's journey is different :) I started out being a big fan of static typing but eventually found that I'm usually hit by different issues than "this was a int but I expected a string" that were more important to be solved, so I'm mostly using dynamic languages nowadays.

But that's what so great with programming languages, there are so many that work so differently, so there is at least one language for everyone, no matter how different your brain works :)

By the way, if you're a fan of "conciseness" you should give a lisp-type languages a try if you haven't before, will show you a completely different level of conciseness! Clojure is a great introduction to lisps. And if you still need validation of data somehow, clojure.spec et al works great and will introduce you to some cool new things you probably haven't come across before :)

Re:Writing Gnome Apps with Swift by knallfrosch on Thursday March 28, 2024 @09:22AM (#39851036)
Doesn't TypeScript – as mentioned above – solve all JavaScript type problems? I have, in 6 years, never encountered a single type error originating from a TS file.
Re:Writing Gnome Apps with Swift by jwells89 on Thursday March 28, 2024 @12:14PM (#39853478)
Biggest problems with TypeScript IMO are that it’s a layer rather than a language proper and that untyped JS problems can too easily worm their way in if you’re using any libraries at all. Also depending on the group of developers involved, the ease at which one can pull the escape hatch and opt out of TS is a liability and can render much of its benefit moot.
Re:Writing Gnome Apps with Swift by SkiFire13 on Thursday March 28, 2024 @07:27AM (#39849813)
> I still don't see how a language (GJS) with an already existing ecosystem of writing Gnome apps, lots of examples, API references and more is worse for writing Gnome apps than Swift, that seems to have been launched just some days ago?

I mean, you said it yourself:

> One mans gold is another mans trash :) Static typing seems to be a neat addition for lots of people, that's great!

For those people it is definitely better than GJS!

Re:Writing Gnome Apps with Swift by diggan on Thursday March 28, 2024 @07:53AM (#39850060)
Well, I mean if the difference was only about static typing, I definitively see what you're talking about. But the difference between GJS and Swift for Gnome app development is greater than that, so personally just that one "feature" wouldn't push me towards Swift.

But yeah, probably for some it's worth it, so that's pretty cool :)

Re:Writing Gnome Apps with Swift by azangru on Thursday March 28, 2024 @07:08AM (#39849703)
> legacy like JS (for example, it has real objects, not dictionaries)

Could you explain the nature of problems that occur due to javascrript's treatment of objects? What makes it a big and important issue?

Re:Writing Gnome Apps with Swift by codedokode on Thursday March 28, 2024 @11:21AM (#39852680)
In JS you can delete properties, assign anything to them (no typing), cannot add comments to them, cannot restrict access from outside. Also you can access non-existing properties and no error will be thrown.