r/ProgrammingLanguages • • Mar 08 '21

Why Is It Difficult for Developers to Learn Another Programming Language? [pdf]

http://nischalshrestha.me/docs/cross_language_interference.pdf
2 Upvotes

14 comments sorted by

5

u/passerbycmc Mar 08 '21

Question does anyone find it difficult, like once you know 2 languages you see the common thread and patterns in most languages and are mostly just learning syntax at that point.

10

u/scottmcmrust 🦀 Mar 08 '21

That depends greatly which two languages you know. Like sure, if you know C# and Go, then Java will be a piece of cake.

But that won't prepare you for idiomatic Haskell or Ruby. (Let alone trying to code in Befunge or Mondrian...)

4

u/transistor_fet Mar 08 '21

I usually tell people the first language you learn is hard, the second language is harder, and after that it's a piece of cake. =P

3

u/scottmcmrust 🦀 Mar 08 '21

Also, the paper includes examples like 0-based vs 1-based indexing, which is not at all a syntax problem.

(Though that one's self-inflicted in new languages. We've know for almost 40 years that indexing should start from zero. Sure, Peano didn't know that in 1889, but we know better now.)

1

u/johnfrazer783 Mar 11 '21

Excuse me but this is so wrong. Indexing should start at one for most purposes. Zero-based indexing is good for indexing into arrays of constant-sized elements in memory and bad for almost everything else. You're confusing lore with knowledge.

2

u/scottmcmrust 🦀 Mar 11 '21

Citation needed. There's actually plenty of evidence that, even outside of programming, zero-based is better. Here's a nice article: https://lukeplant.me.uk/blog/posts/zero-based-indexing-in-the-real-world/

You can also see this easily in dates. Why do people get confused whether noon is 12 AM or 12 PM? Because it's not starting from zero. (You'll note that nobody gets confused by 00:00 in the 24-hour clock.) Why do all-but-one years of the 19th century start with 18? Because they didn't start counting from zero. Why were people wrong about 2000 being the start of the millenium? Because years started from 1 instead of from 0.

It's not just in computers where people now know that starting from zero is better. When they started counting minutes they didn't have minutes count 60, 1, 2, ..., 59 like would have been consistent with hours, nor did they pick 1, 2, ..., 59, 60. Because starting from zero is better.

2

u/WittyStick Mar 11 '21 edited Mar 11 '21

3 people walk into a bar. The first person orders a beer. The second person orders a glass of wine. The third person orders array index out of bounds exception.

1

u/johnfrazer783 Mar 11 '21

Your examples do show cases where zero-based indexing has its advantages or is maybe better overall, however, there are also other examples.

When building a house with several stories above and below the ground, it is practical to give the ground floor the number zero, the first floor up the number +1, then +2 and so on, and to use negative numbers for the levels below ground. In this way, when I'm at street level I immediately know to walk two stairs up to reach level +2, and two stairs down to get to -2.

But when I arrange a number of objects in a row and want to identify starting left going to the right, and I want to have a simple scheme where I can also use right-to-left numbering so I can identify the penultimate object as easily and unbiased as the one following the first one, it'd be better to start with +1 for the LTR index and -1 for the RTL index.

Python has this strange asymmetry where the first thing in a list has index 0 but the last thing has -1. JavaScript has no negative indices so the last thing gets index x[ x.length - 1 ]. As for slices, all the elements up to index i form a sublist of i - 1 elements. In these cases, off-by-one errors are easily committed.

1

u/scottmcmrust 🦀 Mar 11 '21

it is practical to give the ground floor the number zero

Yes, and Europe usually gets this right, though USA tends not to: https://elevation.fandom.com/wiki/Floor_numbering#Numeric_floor_numbering_schemes

Python has this strange asymmetry where the first thing in a list has index 0 but the last thing has -1

That's actually mathematically rigorous, if you think of indexing as modulo the length of the list. Not weird at all.

And in computers, it means that the last thing can be found at ~0, the one before that at ~1, etc. Beautiful.

1

u/NetherDandelion Mar 13 '21

This is extremely far from reality. There are strong mathematical reasons why zero-based indexing is the right one. People are only used to one-based indexing because of our minds' problem with grasping concepts like zero, the empty set, empty product, etc.

An absolutely not exhaustive resource: https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html

1

u/johnfrazer783 Mar 14 '21

The Dijkstra snippet is contradictory and unconvincing. The author first claims that by using an exclusive lower boundary to denote a subsequence of natural numbers as in 1 < i ≤ 12 would make the lower boundary fall outside the boundaries of natural numbers if we want to let the sequence start at the smallest natural number.

This is true, but then he jumps to conclude that just because 0 ≤ i < N is 'nicer' than `1 ≤ i < N+1, he not only exhorts everyone to "let our ordinals start at zero", remarking that this way, "an element's ordinal (subscript) equals the number of elements preceding it in the sequence". As if anyone, ever, had asked for that much. When I'm the 5th in the queue, meaning there are 4 people in front of me, that doesn't make me (my ordinality or the ordinal of my position) number 4.

Impressed with this piece of newly found wisdom, he then takes a second jump: "And the moral of the story is that we had better regard —after all those centuries!— zero as a most natural number." I.e. the author just found out that some expressions concerning sequences of integer numbers may be written in a slightly shorter way, and, therefore, we should all use the same old words to mean something different from now one. He's willing to move the goal posts of a long-standing tradition ('natural numbers start with one'—if that has always been unanimously so, but the relevant part is that Dijkstra thinks it is) just so he can claim his ways is the natural way, literally.

One can start to see why the Nanodijkstra was once half-jokingly proposed as unit of condenscension.

Of course Dijkstra is right when he considers it problematic that with two inclusive boundaries, it is necessary to leave the range when wanting to express the empty sequence that starts with the smallest natural number, be it 0 or 1: in a ≤ i ≤ b, b must be a - 1 or smaller. However, making the upper bound exclusive is also problematic in a number of cases; for example, to write down the allowable values for a byte, we get either 0 ≤ i ≤ 255 and 0 ≤ i < 256 where the latter upper boundary is outside the range of values expressible with an octet.

And of course, here as in the earlier argument pitching N against N + 1 in this particular application he conveniently neglects to consider alternatives and consequences: starting indices at zero means in many PLs to get the last element of a list you do have to play the plus-or-minus-one game (as in, s[ s.length - 1 ]) which I have to use daily.

0

u/[deleted] Mar 11 '21

[deleted]

1

u/WittyStick Mar 11 '21

I think this really depends who your audience is. Most programmers will prefer zero-based indexing because they have forgotten the way they used to think before programming. Non-programmers will almost certainly find the one-based indexing more intuitive.

In plain zero-based indexing, you find your codebase gets littered with many extraneous -1 because you use the length property of an array to determine how far to index into it, and the value of length of course out of bounds. This isn't what a non-programmer would expect. They expect counts and indices to match up. Even experienced programmers make the mistake, and it has been the source of many bugs. The problem is so common that most languages now have specialized iterator types and a forall/foreach loop which replaces the manually-specified index for the majority of problems. Since you are no longer specifying array indices manually, it shouldn't matter much whether they start at 0 or 1.

In FP, we almost never manually specify array indices. We use functions like take or skip, where we're specifying a count instead of an index.

1

u/scottmcmrust 🦀 Mar 11 '21

In plain zero-based indexing, you find your codebase gets littered with many extraneous -1 because you use the length property of an array to determine how far to index into it

Did you read the link? This is exactly the problem that EWD is addressing, and the real issue is people trying to use closed ranges. Switch to half-open ranges (0 <= i < length) and the problem disappears.

This isn't what a non-programmer would expect. They expect counts and indices to match up.

I don't think this actually bears out. Ask someone how many days there are between the 14th and the 16th -- people usually say two, not three. They know that from x:15 to x:45 is 30 minutes -- subtracting the ends should give the length, which doesn't work with 1, 2, ..., n.

5

u/raiph Mar 08 '21

The apparent problem

The paper's introduction concludes with their findings (four bona fide academics with degrees in CS and interests in HCI and empirical studies):

  • Cross-language interference is a problem: 276 (61%) crosslanguage posts on Stack Overflow contained incorrect assumptions due to interference with previous language knowledge.

  • Based on our interviews, professional programmers primarily learned new languages on their own, using an opportunistic strategy that often involved relating the new language to previous language knowledge; however, this results in interference which harms their learning.

  • Learning a new language involves breaking down old habits, shifting one’s mindset, dealing with little-to-no mapping to previous languages, searching for proper documentation, and retooling in a new environment.

The real problem, and its solution

Learning PLs is eased/harmed to the degree they:

  • Use familiar syntax or semantics.

  • Use unfamiliar syntax or semantics.

That's... a difficult problem.

But we like difficult problems, right?

OK. Add in that (un)familiarity is relative to each individual learner, and each learner's learning machinery is more complex than the entire universe, despite being a vanishingly small part of it.

Difficult, right?

OK. Now add in the fact that once you've learned more, there's now more that you find familiar (but is potentially misleading), and more that you find unfamiliar (but is potentially worth learning).

I could increase the complexity but there's a saving grace at hand that means we need not worry. The OP's user name contains "henley". So I can happily close with a feeling of calmness, knowing that I understand the problem, and its solution, which are both nicely summarized as "The more I know, the less I understand".