An introduction to the Julia language, part 1
An introduction to the Julia language, part 1
Posted Aug 30, 2018 9:53 UTC (Thu) by danielpf (guest, #4723)In reply to: An introduction to the Julia language, part 1 by jem
Parent article: An introduction to the Julia language, part 1
This is a legend, because the +1 bug occurs in any language. For example in 0-based indexing you loop from 0 to N-1, so you must not forget the -1. I have programmed scientific applications in many languages overs decades and found that both kinds of indexing offer advantages and disadvantages in different contexts. In both indexing ways the +1 bug is lurking.
Posted Aug 31, 2018 6:19 UTC (Fri)
by epa (subscriber, #39769)
[Link] (1 responses)
for (int i = 0; i < N; i++)
So N-1 isn’t usually needed.
A neat helper, too, is Python’s half-closed range for list slices, a[n:m] giving m-n elements. This is more convenient than a .. inclusive range for many programming tasks.
Posted Sep 6, 2018 6:43 UTC (Thu)
by Wol (subscriber, #4433)
[Link]
Which is a trap for the unwary, or noob.
All languages have idioms. I once wrote a piece of code - in a class for C beginners - that effectively did
count = 0
to find out how many threes were in the hand. I just could not get the lecturer to write the addition line correctly on the board until I told him to write it down, character by character, as I spelt it out. To me, that idiom is second nature, to him it was totally alien.
And yet, it SHOULD be completely natural to users of any language (like C) where the language defines the result "true" as being represented by the integer "1". (Note I said "result" not "value" ...)
and you'll find plenty of C programmers to whom the "<" idiom is alien, until they've been programming in C for quite a while and had it rammed in to them.
Cheers,
An introduction to the Julia language, part 1
An introduction to the Julia language, part 1
for i = 1 to 13
count += (cardvalue == 3)
next
Wol
