Is Swift 6 a good first language?

It super duper does not, because your computer isn't a fast PDP-11.

12 Likes

That's a great article, I especially liked this quote from it:

“A programming language is low level when its programs require attention to the irrelevant.”

but we usually call C a lower-level language, of course it's not the lowest, especially not on modern processors that themselves have additional abstraction layers inside them.

However, just being exposed to the idea of a pointer, manual memory management or the fact that the processor can't concatenate your strings already teaches a lot and makes you appreciate and understand better what the higher-level languages are doing, and most importantly how they are doing it.

So to bring us back to the original topic, Swift is probably not a great first programming language for someone who wants to make engineering their primary trade, they definitely need to start from C, then move on to some higher-level static languages (in fact Swift would probably be a great second language), then even higher to some dynamic languages.

1 Like

I would rephrase that anyone would need to learn C at some point. It is really good at teaching some lower level things, like memory management, that can be useful to understand much greater variety of code, plus C is kinda universal language (historically) for interop. But I wouldn’t say that one should start with it - start with the language you want to use everyday.

7 Likes

Exactly.

And let's not forget the ascii stuff. :slight_smile:

How would you explain to someone, with no previous exposure to ascii, that we had to have the unicode encoding because ascii could not handle the encoding of the other world languages.

How would you explain to someone the concept of this or self and why we need them? Or virtual functions or dynamic dispatch for that matter if they never had exposure to stuff like this:

#include <stdlib.h>
#include <stdio.h>

typedef struct Complex Complex;

struct Complex {
   double x;
   double y;
   void      (*print) (const Complex *);
   Complex * (*add) (const Complex *, const Complex *);
};

static void      Complex_print (const Complex *);
static Complex * Complex_add   (const Complex *, const Complex *);

 Complex * Complex_init (double x, double y) {
   Complex * self = (Complex *) malloc (sizeof (Complex));
   self->x = x;
   self->y = y;
   self->print = Complex_print;
   self->add   = Complex_add;
   return self;
}

static void Complex_print (const Complex * self) {
   printf ("%f + j%f\n", self->x, self->y);
}

static Complex * Complex_add (const Complex * self, const Complex * other) {
   return Complex_init (self->x + other->x, self->y + other->y);
}

int main () {
   Complex * f = Complex_init (3, 7);
   f->print (f);

   Complex * g = f->add (f, f);
   g->print (g);

   return 0;
}
1 Like

I think most people learn object oriented programming with some variation of the “message passing” metaphor. It’s certainly possible to have a solid mental model for this stuff without understanding the details of the lowering. And of course vtables and function pointers are just one possible implementation of the concept.

8 Likes

That’s just silly. I personally started out by tinkering with HyperCard, TeX, HTML (not even Turing complete you say), QBASIC, and then Java. All of those (Java to a lesser extent) had the property that you can just put stuff in a file and see the results right away, and it didn’t take a lot of specialized knowledge to make something interesting appear on the screen.

When I tried to learn Mac Toolbox programming with C early on, I recall having to type several pages of sample code from the book to display a window with a couple of controls and run an event loop, and getting discouraged because I kept making typos and couldn’t get it to work. If that was the only way to learn programming available to me I would not have enjoyed it.

It wasn’t until much later that I learned about machine organization, how data structures are actually implemented, etc and of course that made me a better programmer, but there’s no valid reason to start with that.

25 Likes

Python was my first language, C was my second, and Swift was my third. although Python exposes some concepts (like self) that are mirrored in Swift, i felt that learning C before Swift made it a lot easier to learn Swift than if i had skipped straight from Python to Swift.

C teaches you to obsess over a lot of details - especially around optimization - that can be counterproductive when using Swift. but overall i think it teaches a lot of important concepts that wouldn’t be as easy to grasp without the C background.

3 Likes

Yeah, I learned by writing scheme programs in a notebook and simulating execution by hand; it was a couple years between when I learned to program and when I had regular access to a computer, and even then I mostly wrote games for calculators instead. Plenty of good programmers started with C, but many had radically different introductions to programming and turned out just fine. Plenty of long-time C programmers have absolutely no idea how computers “really work.”

11 Likes

I'm sorry but I find that using a personal anecdote as an argument against "C should be the first language" is pretty weak. My chain of languages is even worse: Fortran -> Turbo Pascal -> Turbo C, then C++, then a dozen of other languages that are considered mainstream today. Swift was probably number 12. However I do recommend C as the first language based on my personal experience, so quite the opposite of what you are saying.

"Beware of bugs in the above code; I have only proved it correct, not tried it” - Knuth

8 Likes

I'm sorry, but I find that using a personal anecdote as an argument for "C should be the first language" is pretty weak :slightly_smiling_face:

7 Likes

You stole my point :slight_smile: That was my point.

Folks, we are not in the C forums and the question was not „what’s a good first language to learn“, could we get back to the topic or close the thread please?

I think Swift is still a good first language to learn, and having warnings for e.g. Globals already at the beginning of the journey, while new learners might not understand it exactly, prevent bad practices from developing early.

In any case, being facetious aside, C was my first language and I have to say that it equally forced me to struggle through a lot that was completely irrelevant to my learning experience at the time (and for many years afterwards!) — I think Slava captured it well:

When learning, and teaching others, a quick feedback loop of typing something → getting something onto the screen, and as far as the magic incantations for getting that feedback loop started, I'd consider Swift to require quite a bit less than many other languages. Ruby and Python, for me, are similar in that respect, with different advantages and disadvantages.

I think with experience comes forgetting just how much later in the process a lot of the complaints in this thread appear. So much of early programming just revolves around sticking readLine() in a file and doing something funny with the output, and that type of experimentation is a lot easier in Swift than many other compiled languages.

8 Likes

Getting back to the original question, IMHO the question itself isn’t quite correct in the way that almost any language can be a good first language, depending on goals and other circumstances.

So discussing if Swift fits depends on all these details as well, or otherwise discussion is doomed to go to another languages and personal experiences (which I don’t see as a bad thing as well).

2 Likes

Swift has strayed from its origins as a novel alternative to Objective-C and has become more of a "secret handshake" type of language, where its foists arcane, nonobvious syntax on the programmer which has to be explained and reexplained. It's similar to C++ in that sense. I would recommend Python as a starting language and get the kid a Raspberry Pi 5 to run it on, since Linux experience is always helpful. After Python, they should learn C and ideally, assembly.

2 Likes

Who said they should? Why not Haskell and monads? :upside_down_face:

2 Likes

Have a feeling, that everyone just biased by their own experience, and term good first language should be defined before discussing.
In my humble opinion basics are not C, Python and etc., but imperative programming, functional, objective, network model, memory and etc. It's easier for kids to start with imperative approach, and many languages will work here, Swift included.

4 Likes

i think we should focus on what would make Swift a better first language.

to me at least, it seems there is broad consensus that Swift’s handling of top-level code could be improved. top level code should be exempt from (most) concurrency checking, and throwing from top level code should not send the script into backtrace collection mode.

i get the sense that some folks regard top level code as “here be dragons” and something to get people away from ASAP. this is not incorrect wrt to the current state of top level code in Swift. but i don’t think that’s a very beginner-friendly mindset.

11 Likes

OP made it pretty clear that they wanted to discuss the impact of data-race safety on progressive disclosure:

This discussion has veered very far off course. A "what is the best first language" debate might be fun to some of you, but it's inherently a very personal choice based on your goals, and debating this is not constructive for these forums.

We also should not make broad statements about the path that people who are "serious about becoming a programmer" should take; there are many different ways to become a programmer, and these sweeping statements can come off as discouraging to programmers who are on a different path. There is no single blessed path for learning programming. It's okay to discuss what would have helped you in your journey. It is not okay to insinuate that someone who didn't learn a particular language or programming concept is not serious about programming or is not a "competent" programmer. The Swift community welcomes all programmers at any point in their journey, regardless of the path they took to get there and what concepts they have and have not yet learned.

If you all would like to continue this discussion, please get back to the original topic of improving progressive disclosure in the Swift 6 language mode.

26 Likes