News for hackers. Stuff that matters.
Re:Fortran is easy to learn by hpcjoe on Friday January 07, 2022 @10:44PM (#29848416)
Agreed. I'm a (very) long time Fortran user, and a more recent C, Python, and Julia user. I'd agree that scanf is a pain. The chomping/parsing bit can be, in all cases, hidden behind a convenience function, which if you like, you can name "read".

FWIW, I've been using Fortran since the mid 1980s, C from the mid 90s, Python from the mid 00s, and Julia since 2012 or so. All of these languages are fine for the example provided, and all are understandable. Each of these languages require some minimal boilerplate around the core algorithm to make it work. Specifics of input and output mechanisms would be language/dialect specific.

Really, each of them is fine for this trivial example. Its when you start getting into serious translation of the underlying math into something the language will understand, that the real difference stand out.

That's when both Fortran and Julia stand out. Both are designed to make this process as painless as possible. Fortran was designed and built almost 70 years ago. IO was very painful then, and while the language itself is very simple and easy to understand, the IO system is still quite similar to the early days.

The "(,)" notation combines units (file descriptors), and formatting. It is not different in intent than the scanf and other functions.

Why Fortran and Julia are so easy to use comes from the expressiveness of the language, the simple mechanism of writing code that looks close to the formulae in question. There is no fiddling with array indexing that doesn't start where the formula indicates. No allocating arrays of arrays to build matrices.

That is, it is simple to go from conception to working code very quickly. In a manner that really does look like the way you would do it on paper.

That's why Fortran is still in use, and growing. And why Julia is catching on quickly.

Re:Fortran is easy to learn by flubflub on Saturday January 08, 2022 @06:27AM (#29850666)
I don't think 1 based indexing is that useful. A lot of mathematics formulae start from 0 too and 1-indexing makes that more awkward.

Although I agree that some languages like Julia and say MATLAB feel more fluent to express mathematics.

Re:Fortran is easy to learn by xmcqdpt2 on Saturday January 08, 2022 @12:47PM (#29854114)
Luckily, Fortran allows easily changing from one to the other. You simply define arrays as A(1:10) or A(0:9) and they will index from 1 or 0.

You can even do arbitrary indexing: fixed like A(-3:3) or dynamically like B(n1:n2). This may sounds useless but it's actually an excellent feature when writing eg convolution kernels.

I don't know of any other languages beyond Fortran and Julia that have arbitrary array indexing as a core feature (you can fake it in C in two lines I guess).

Re:Fortran is easy to learn by flubflub on Saturday January 08, 2022 @03:46PM (#29856019)
Wow that's incredible and really changes my opinion on Julia's indexing.

It is small but really makes things more elegant. I should definitely try Julia. I've spent a lot of time calculating awkward array index conversion formulae in my head and this could make things a lot more simple especially for weird cases.

I was under the impression that Fortran's only redeeming benefit was that it compiled well for numeric computing routines.

Re:Fortran is easy to learn by TheRealKing on Saturday January 08, 2022 @05:55PM (#29857428)
Again, to be clear, Julia does not have arbitrary indexing as in Fortran. It has an external package that can mimic arbitrary indexing of Fortran.
Re:Fortran is easy to learn by adgjlsfhk1 on Saturday January 08, 2022 @10:55PM (#29859888)
That's not a meaningful distinction. Julia is a powerful enough language that OffsetArrays don't need to be built in to work perfectly. Good languages don't need everything built in.
Re:Fortran is easy to learn by TheRealKing on Sunday January 09, 2022 @04:56PM (#29867718)
The comment above states: "...Julia that have arbitrary array indexing as a core feature...". Is an external package written in Julia considered a "core" feature of the Julia language? Why does the Julia community always twist the facts? Why cannot they accept the facts as they are? It would not reduce the value of their efforts, I guarantee you—decency and honesty always prevail.
Re:Fortran is easy to learn by fault1 on Sunday January 09, 2022 @09:34PM (#29869924)
Julia's docs say that it supports "Julia supports arrays with arbitrary indices": https://docs.julialang.org/en/v1/devdocs/offset-arrays/

So let's break that down.

The base standard library and "idiomatic" Julia are both largely written without the assumption of 1-based indexing, instead dispatching to what you think about as an array-oriented dsl, which is this interface: https://docs.julialang.org/en/v1/manual/interfaces/#man-inte...

It is very normal in Julia to implement such interfaces to do what you want. Julia uses these types of internal interfaces with multimethods in lieu of a lot of compiler intrinsics.

So I would say Julia and Fortran have different implementations of arbitrary indexing.

They are both oriented around core design features of each respective language.

Re:Fortran is easy to learn by shele on Monday January 10, 2022 @05:55AM (#29872966)
Yes, Julia does support arbitrary indexing because base functions are written in terms of `firstindex`, `eachindex` and `lastindex` etc.

One can see it in the implementation of `filter!` for example https://github.com/JuliaLang/julia/blob/ab4e036b9209967b4273... :

Re:Fortran is easy to learn by adgjlsfhk1 on Sunday January 09, 2022 @11:40PM (#29870729)
External Julia packages can impliment core features. For another example, look at StaticArrays. Fortran is a brittle old language where everything supported must be built into the language. Julia isn't.
Re:Fortran is easy to learn by TheRealKing on Monday January 10, 2022 @01:47AM (#29871401)
Again, twisting facts by some Julia novice about a topic they have no familiarity with. Fortran does not require features to be built-in. Look at all the intrinsic Fortran modules. But array-based indexing IS built-in to the language. Unlike Julia, you do not have to rely on an external package for it. Perhaps the Julia community's relatively young age has made it so arrogant, Machiavellian, and fact-twisting about other languages to prove their presence here and there. Other programming communities are old enough to put decency and honesty in their core values.
Re:Fortran is easy to learn by adgjlsfhk1 on Monday January 10, 2022 @08:07AM (#29874180)
I also find it interesting that you assume I'm a Julia novice. I use Julia for my job, and have a few dozen commits to Julia (and several to packages)
Re:Fortran is easy to learn by ChrisRackauckas on Monday January 10, 2022 @04:15AM (#29872221)
Julia's compiler is made to be extendable. GPUCompiler.jl which adds the .ptx compilation output for example is a package (https://github.com/JuliaGPU/GPUCompiler.jl). The package manager of Julia itself... is an external package (https://github.com/JuliaLang/Pkg.jl). The built in SuiteSparse usage? That's a package too (https://github.com/JuliaLang/SuiteSparse.jl). It's fairly arbitrary what is "external" and "internal" in a language that allows that kind of extendability. Literally the only thing that makes these packages a standard library is that they are built into and shipped with the standard system image. Do you want to make your own distribution of Julia that changes what the "internal" packages are? Here's a tutorial that shows how to add plotting to the system image (https://julialang.github.io/PackageCompiler.jl/dev/examples/...). You could setup a binary server for that and now the first time to plot is 0.4 seconds.

Julia's arrays system is built so that most arrays that are used are not the simple Base.Array. Instead Julia has an AbstractArray interface definition (https://docs.julialang.org/en/v1/manual/interfaces/#man-inte...) which the Base.Array conforms to, and many effectively standard library packages like StaticArrays.jl, OffsetArrays.jl, etc. conform to, and thus they can be used in any other Julia package, like the differential equation solvers, solving nonlinear systems, optimization libraries, etc. There is a higher chance that packages depend on these packages then that they do not. They are only not part of the Julia distribution because the core idea is to move everything possible out to packages. There's not only a plan to make SuiteSparse and sparse matrix support be a package in 2.0, but also ideas about making the rest of linear algebra and arrays themselves into packages where Julia just defines memory buffer intrinsic (with likely the Arrays.jl package still shipped with the default image). At that point, are arrays not built into the language? I can understand using such a narrow definition for systems like Fortran or C where the standard library is essentially a fixed concept, but that just does not make sense with Julia. It's inherently fuzzy.

Re:Fortran is easy to learn by xmcqdpt2 on Sunday January 09, 2022 @12:56PM (#29865672)
I wasn't sure. I googled it and it was in the Julia docs but I didn't look at the details to see if it is first-class.

The fortran version is super neat, especially in conjunction with stack allocated multidimensional variable length arrays.

Re:Fortran is easy to learn by hpcjoe on Sunday January 09, 2022 @02:16PM (#29866412)
Much of Julia language is written in Julia. So the 'external package' is just an extension you install/use if you wish. A distinction without a difference.
Re:Fortran is easy to learn by Jtsummers on Saturday January 08, 2022 @09:45PM (#29859418)
Ada and many BASICs also permit using arbitrary ranges. Ada even takes it further, any range over a discrete type can work including characters and arbitrary enumerations.
Re:Fortran is easy to learn by pjmlp on Sunday January 09, 2022 @12:00PM (#29865054)
Ada has adopted it from Modula-2/Pascal.
Re:Fortran is easy to learn by ogogmad on Saturday January 08, 2022 @07:09AM (#29850904)
A lot of formulae start from 1 too. And in linear algebra, most of them do.

It's like driving on the left side of the road instead of the right side of the road. Inconsistency is what makes it painful.

Re:Fortran is easy to learn by noobermin on Saturday January 08, 2022 @07:18AM (#29850974)
I am convinced a good fraction of the off by one errors in C like languages comes from 0 indexing. The ith element is found after traversing i+1 elements and that fact leads to mistakes all the time. With 1 indexing the numbers line up.
Re:Fortran is easy to learn by hpcjoe on Sunday January 09, 2022 @02:24PM (#29866488)
I agree. There's far less of a cognitive load for developers associated with representing an expression as written, if you don't need to mess with indices, in order to accommodate the language and its vagaries.

One should not need to adjust the way one expresses an algorithm, because of opinionated language design decisions. Put another way, languages designed for scientific/engineering computing won't have a hard/fixed opinion about things that shouldn't be worried about.

Re:Fortran is easy to learn by Koshkin on Saturday January 08, 2022 @07:22AM (#29851001)
Indeed, polynomials, for instance, start with a power of zero. At the same time, there is a reason why the natural numbers begin with 1, and, in practical terms, there is a certain convenience in the count (size) being the same as the last index.
Re:Fortran is easy to learn by ogogmad on Saturday January 08, 2022 @07:30AM (#29851046)
The natural numbers don't start with 1... The convention is inconsistent, but for many mathematicians, especially including logicians, they start with 0. It is best not to use the term "natural numbers" at all.

By the way, your point about polynomials works in favour of the convention that 0 is a natural number.

Re:Fortran is easy to learn by Koshkin on Saturday January 08, 2022 @09:27AM (#29851925)
Try thinking of being the zeroth person in a line. Or your child being in the zeroth year of her life.
Re:Fortran is easy to learn by ogogmad on Saturday January 08, 2022 @09:38AM (#29852041)
How many lions are in my room at the moment? Hopefully zero.
Re:Fortran is easy to learn by Koshkin on Saturday January 08, 2022 @10:41AM (#29852671)
But zero sheep is not a flock.

(Besides, there's uncountably many things you have zero of in you room.)

Re:Fortran is easy to learn by ogogmad on Saturday January 08, 2022 @11:01AM (#29852880)
> But zero sheep is not a flock.

So one isn't a natural number?

> (Besides, there's uncountably many things you have zero of in you room.)

;) Exactly. Zero is the most natural number.

Re:Fortran is easy to learn by Koshkin on Saturday January 08, 2022 @12:55PM (#29854201)
So, on your scale, which is the first natural number?
Re:Fortran is easy to learn by wilbdhm on Saturday January 08, 2022 @02:15AM (#29849406)
> Why Fortran and Julia are so easy to use comes from the expressiveness of the language, the simple mechanism of writing code that looks close to the formulae in question

Why would it not in any other languages?

Re:Fortran is easy to learn by kergonath on Saturday January 08, 2022 @04:14AM (#29849985)
Some other languages have attempts to emulate it (like some matrix classes in c++ and numpy), but it is not that great. You can make it look close in some places at the cost of more complexity elsewhere. It also feels bolted on with more or less opaque data structures manipulated by ad hoc functions. There always are strange edge cases where the library fights against the language. The TKR (type, kind, rank) concepts are at the very core of the variable model in Fortran, and n-dimensional matrices are first class variables just like scalars, and are much more natural to use. Elemental functions are very useful and trivial to implement in Fortran. Coupled with the great array syntax and easy user-defined operators, it makes writing complex numerical expressions very satisfying and elegant. Granted, some other parts of Fortran are far from elegant.

I am not saying it makes other languages unusable (I use numpy arrays quite frequently; Python and Fortran are very complementary), but definitely less natural and elegant.

Re:Fortran is easy to learn by ogogmad on Saturday January 08, 2022 @07:08AM (#29850896)
With Python+Numpy, my issues are or were:

  1. The matrix multiplication syntax used to be bad. But it became possible at some point to write A @ B for the product of A with B. And that seems fine to me.

  2. The code seems more natural when you write `sin(array([1,2,3]))` instead of `np.sin(np.array([1,2,3]))` -- which you can achieve by running `from numpy import *`, but doing this is discouraged by a lot of people.

  3. The convention in Linear Algebra is that indexing starts from 1, not 0. This sometimes makes translating from a language which follows the more usual convention difficult.
Overall though, I think only 3 is unfixable, but this is usually a minor problem. Usually, Python+Numpy doesn't seem any worse than Matlab syntax-wise.

I find the experience of using Pandas to be much worse. Sympy also feels abrasive because of needing to write `m12 = var('v12')`.