Swift is a general-purpose programming language built using a modern approach to safety, performance, and software design patterns. It aims to be the best language for a variety of programming projects, ranging from systems programming to desktop applications and scaling up to cloud services. Read more about it and how to try it out in Fedora.

Safe, Fast, Expressive

Like many modern programming languages, Swift was designed to be safer than C-based languages. For example, variables are always initialized before they can be used. Arrays and integers are checked for overflow. Memory is automatically managed.

Swift puts intent right in the syntax. To declare a variable, use the var keyword. To declare a constant, use let.

Swift also guarantees that objects can never be nil; in fact, trying to use an object known to be nil will cause a compile-time error. When using a nil value is appropriate, it supports a mechanism called optionals. An optional may contain nil, but is safely unwrapped using the ? operator.

Some additional features include:

Closures unified with function pointers

Tuples and multiple return values

Generics

Fast and concise iteration over a range or collection

Structs that support methods, extensions, and protocols

Functional programming patterns, e.g., map and filter

Powerful error handling built-in

Advanced control flow with do, guard, defer, and repeat keywords

Try Swift out

Swift is available in Fedora 28 under then package name swift-lang. Once installed, run swift and the REPL console starts up.

Swift has a growing community, and in particular, a work group dedicated to making it an efficient and effective server-side programming language. Be sure to visit its home page for more ways to get involved.

Cris

What are the benefits of Swift over Julia? It was a rhetorical question. I understand that it’s good to have alternatives but I don’t see this expanding beyond the Apple ecosystem. Just another FireWire®

Tpk

Ray Scott

I don’t think Apple have ever had the intention of porting their frameworks to Linux. I believe Swift support on Linux is intended to be used for writing backend services, but even that’s not possible I imagine without Apple’s Foundation module.

Ron Olson

Ron Olson

My use of Swift on Linux has been to test out code, algorithms, etc.; I can log into a powerful 16-core Linux box and use multithreaded Swift code without dealing with my much older, and much slower, Mac.

M Leslie Satenstein

As far as I know from what I read about recent C compilers, uninitialized pointers and arrays are Nulled. Numbers (int, a char, float, are set to zero at function prologue.
My gcc C compiler tells me about a variable’s first use before being set.
If not C, I would still use C. The human brain knows better how to manage memory allocations.

No, I don’t NEED autocompletion and in-place documentation to code, but it makes my life so much more pleasant. I gave Rust a try, and it’s pretty much fulfilling the Swift promise, on Linux. Rust’s “Racer” code intelligence app compiles fine.

I’d love to give Swift a real shot on Fedora, but without IDE/editor support, we don’t get the full benefits.

Robb

Thanks, yep – that’s the path I followed, which led me to the SourceKittenDaemon dependency. If I’m right, that’s the piece which actually does the heavy lifting for the Swift plugins in VSC, Emacs, etc.

Ray

I tried that this afternoon, but the plugin complained about a missing SourceKit dependency. I think the VSCode plugins are only expected to work on macOS, and won’t work on Linux until the SourceKit related issues are resolved.

ANDRE GOMPEL

For assertive programming, from C, to Erlang, Julia, Go, Rust, Swift (and more), so many “me too languages” who do almost the same thing as C (C99) !

For system low level, the differences are so minor, that rather than a yet another language (YAL), I would much prefer as “a pragma statement” at the beginning of the source file, a choice for “YAFC” (yet another flavor of C).
So in most case (I know it is not always easy) theses file could be linked together.
In most cases it is doable.
Noe that many years ago, DEC (Digital Equipment Corporation) almost achieved the same goal on VAX/VMS.

I am not sure thought, that a language adequate for system low level, which include device drivers, scheduler, semaphores, access to memory, and I/O mapped, embedded system (without an OS)…) will be the same for “a great application level” programming language, which in most cases run on top of an O/S and all its resources.

I see a danger for the Open Source, to leave the control wide open to a large corporation (Microsoft) for the much appreciated “Visual Studio”, for which there seem to be no great “pure open source” equivalent.

GTK+ and Qt provide decent GUI frameworks. (Not KDE, bloated, never finished). Wondering if it ever will be a great FOSS, IDE build with either one?

Frederik

For C++, the combination of Gnome builder and glade works pretty well. You’re buying into the entire glib ecosystem which is a no-go for some — personally that was the case, but I’ve realize that you simply can’t get anything real done without buying into one ecosystem or another. I personally like how glib does things, more than I like how Qt does things (lot of legacy cruft that hasn’t been dumped). I use the C-API of Glib, not the C++ API, which loses a lot of values over the C API on it’s insistence on using classes.

Gnome builder lacks a few integrations out of the box. I’d love to see a glade plugin that will at least allow me to launch glade from the IDE; at the moment I have to open my UI files from somewhere outside of Gnome builder. The git plugin seems to be hidden somewhere on the internet, that I can’t find (please provide a link if you know where to find it).

Given it’s dependency on meson (which is awesome), I would love to see a better integration with the Gnome builder.

Michael J. Ryan

FYI: Visual Studio Code is completely Open-Source with an MIT license [1]. Not to be confused with the Visual Studio IDE. It’s quickly become one of the best developer environments on the planet imho. I use it on Windows, Linux and Mac regularly, as I tend to prefer the same tools everywhere as much as possible.

Elmmur

Give KDevelop a chance.

GomeBuilder is deeply tied to gnome projects. They even pin gnome projects at the front page, which will be wholey dowloaded if you click on them. That actually holds me back from it. But yeah maybe that’s why it’s called Gnome Builder. Anyway, KDevelop looks more like a general purpouse IDE to me.

Thomas An

Ron Olson

You can interact with native libraries/headers, etc. Take a look at this (now old) project I wrote to learn how to do this very thing: https://github.com/tachoknight/Crazy8sBot. You could just as well work with any other library via the ‘unsafe’ bindings.

steve

I downloaded and tried it. sorry to be so selective but there is no gui? modern programming languages have good editors, gui and graphical design of the screens. this looks like it runs in vi and is terminal based only. useless in today’s world. Unless i am doing something wrong in which case please tell me what it is.

Ron Olson

Turning it around, good editors know about languages; gcc does not come with its own editor, but most (all?) Linux-based editors know how to highlight C/C++ code (though sometimes there’s a disconnect between the editor highlighting and the language features cough C++20 experimental features).

Ron Olson

I mentioned this elsewhere, but in case you didn’t see it, you can use Visual Studio Code, Microsoft’s free editor, on Linux with Swift syntax highlighting. Because it has a built-in terminal, you can use the Swift REPL in the editor whilst writing Swift code; I do this all the time.

Subscribe to Fedora Magazine via Email

Contribute

The opinions expressed on this website are those of each author,
not of the author's employer or of Red Hat. Fedora Magazine aspires to
publish all content under a Creative Commons license but may not be able
to do so in all cases. You are responsible for ensuring that you have the
necessary permission to reuse any work on this site. The Fedora logo is a
trademark of Red Hat, Inc. Terms and Conditions