[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip / qa] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


Why is fortran so comfy?
>>
>>103213209
because it's like MS Excel but in code
>>
File: cobol.png (132 KB, 1541x920)
132 KB
132 KB PNG
>>103213209
nah, COBOL master race
>>
>>103213209
lack of syntax vomit
if you open up a c++ or rust file it's just random symbols like ++'"><<><?>/.::'[][][{}{} on every line hundreds of times for no reason
>>
>>103213209
Because it's designed and optimised for exactly one thing: numerical algorithms.
It is made for exactly one job and does that one job exceptionally well. It's minimal, easy to learn, and is so thoroughly embedded in nearly every single piece of scientific and numerical software that it will never ever go away.
>>
>>103213421
int i=2;while(i --> 0){puts(i&1?"\x1b[1myou wouldn't\x1b[0m":"\x1b[1mget it...\x1b[0m");}
>>
>>103213209
I enjoy writing Fortran from time to time, for small terminal based programs.
When I hate to use libpng, Vulkan, OpenGL, XCB or something, then ANSI C.
>>103213466
Fortran lacks good graphical libraries, and it has wierd parts of syntax tho.
I don't want to write _and_, modulo, advance, no, C is saner in some ways...
--
Many people aren't aware that most Fortran code is faster than most C code.
Before someone calls this fact false, read about it, it's 60 minutes from knowing the truth.
>>
>>103213634
on benchmarks i keep seeing C and fortran as equal
link me
>>
>>103213663
>>103213634
I think most people who code in Fortran are aware of this. The compiler doesn't allow aliasing, for example.
It's also false if you do anything besides numerical work (but then again why would you use Fortran for anything else?). It's just that the compiler is made from decades of people wondering how they can squeeze every bit of performance out of your code for numerical programs.
But strictly speaking in a real high performance environment you see C and Fortran both being used and getting pretty much the same performance.
>>
>>103213678
>The compiler doesn't allow aliasing, for example.
I meant to say Fortran doesn't allow aliasing, so the compiler can make assumptions for optimisation it can't make in C (unless you use restrict etc)
>>
>>103213209
>Fortrannies
>>
>>103213663
>>103213682
Exactly, keyword 'restrict' was added to C (standard from 1999) only 27 years after C was created. By the way, as far as I know, C++ still doesn't have that keyword.
My brain makes a shortcut in Fortran, assuming that I use 'restrict' always, on every passed "pointer". There's also copy-by-value convention, if I remember well. Writing this without double-checking.
One more advantage of most Fortran code is optimization of do-while loops by default, when it can, and it mostly can, optimizing loops in C is more involved from compilers point of view.
--
However, I'm not pretending that I care much about performance, my 13 years old laptop (my main machine) works well with BunsenLabs and shitty programs I write...
Fortran has backwards compability issues, in a sense that it needs to cut-off old flesh, forbid implicit declarations by default, fix parts of the syntax, Ada is the example how to do it.
And I personally dislike modules in Fortran, or that interoperability requires me to pass compiler flags to 'gfortran' in order not to mangle external ELF64 symbols, and few more things...
>>
>>103213209
no jobs, like at all
>>
>>103213754
makes sense
is it worth writing new heavy numerical computation stuff in fortran?
or should i stick with C and be careful about `restrict`?
would my project tank in readability? how 1:1 is C to fortran?
>>
>>103213759
jobs are for data peasants, i'm a computing aristocrat
>>
>>103213780
I do numerical work. Actually, the difference isn't important. Much of it is written in C++ nowadays, but it doesn't matter.
For example most of your linear algebra stuff was written in C, not Fortran. When you really, really need to squeeze out every bit of speed, which is usually the case with heavy duty numerical work, often you'll actually want to do stuff like write the bottlenecks in assembly, although this depends on just how heavy duty your work is.
For some scientific applications you won't be able to avoid Fortran, because so much is written in it it's never going to go away. So you should know Fortran at least.
>would my project tank in readability
Only if you suck. Fortran is a very very simple language. Modern Fortran is especially easy to read. Most people who bitch about Fortran are complaining about Fortran77 or something of the like where you still had computed gotos being spammed by idiots and spaghetti code was the result. Fortran nowadays is nothing like that.
>>
>>103213836
understood
my only understanding of fortran came from my dads fortran book, which had punched card diagrams...
so in general it can do everything C can do without being annoying?
>>
>>103213634
To myself, I meant "have", not "hate"...
>>103213780
> is it worth writing new heavy numerical computation stuff in fortran?
Definitely, but first you'd have to learn Fortran, it's strengths and weaknesses, what to do, when to do it, and vice versa, what NOT to do, when NOT to do it.
Language is just a tool, just like an axe and a shovel. You can dig a hole with an axe, but it'd be faster with a shovel. You can cut a tree with a shovel, but it'd be faster with an axe...
> or should i stick with C and be careful about `restrict`?
Well, I don't want my answer to sound like a double-edged sword... If you know C already and want a finished project, use C, if you want to learn an old good language, use Fortran.
If you don't ragequit like FFA player in Instagib match in Quake Live, then the project will be completed anyway, but development time will vary on your current knowledge of those tools.
> would my project tank in readability? how 1:1 is C to fortran?
They're very different in syntax, even more in "way of thinking when writing the program", but I believe that it'll be much more readable than your average C code. Again, I say this as Ada fag.
>>103213466
Again, this Anon knows it, symbol spam is very annoying in most languages, C++, Pust and Haskell are notorious for it. I can write C++, but I can't read other persons code.
No, a program shouldn't be like a "well written prose" or like a "haiku song", fuck those fags. Also fuck Clean Code (tm) fags and negros. It should be understandable and simple.
>>103213808
Based.
>>
>>103213871
No, C can do more. Fortran can do numerical stuff well. It isn't really designed for anything else and I've never heard of anyone even seriously trying to do anything else with it.
>>103213903
>I believe that it'll be much more readable than your average C code
I agree if for no other reason than Fortran supporting multidimensional arrays explicitly.
Also coarrays are worth mentioning as (imo) a really nice idea which C doesn't have.
>>
>>103213634
>*adds `restrict` to every pointer in every math kernel*
wow that was hard
>>
>>103214058
It's beyond that, I mentioned (in later post) do-while loops and how Fortran compilers can optimize them better, out of the box, you can write them in C too, but it's less convenient.
The real performance benefits come from SIMD and no LOCK (0x0f) prefix, and vectorization usually gets done in loops, but not all loops, you'd have to read more I'm afraid...
Best case scenario for a loop is: from n to 0, assembled loop body is less than 128 bytes long, you're modifying array elements, elements are small (byte, word or at worst IEEE754 dword).
--
We can talk about this in real-time if you join #/g/chad IRC channel on Rizon, I'm not going to join Matrix, Pisscord or anything else. I'm writing some documentation, don't check this thread regularly.
--
> tl;dr: It's not that simple...
>>
>>103213421
lack of Troons taking over the language
>>
>>103213919
>No, C can do more. Fortran can do numerical stuff well. It isn't really designed for anything else and I've never heard of anyone even seriously trying to do anything else with it.
With direct access I/O + async I/O libraries, I've done full IT applications in Fortran. But, this was 40 years ago.
>>
>>103213634
What's the point of the tab arrows? I've seen quite a few people using them, some of them pretty damn good programmers but to me it's just absolute visual noise, like programming with a VHS filter on
>>
>>103213209
>>103213405
>>103213634
Prolog is where its at
>>
>>103213209
Do you guys have favourite programs in Fortran?
I think LAPACK is probably cheating.
>>
>>103215507
Well, I used to visualize all ASCII characters (invisible (0-31) and invisible (32-126) in my IDE (back when I used Kate on KDE), including stuff like:
-- '\n' as returning arrow
-- '\t' as arrow
-- various invisible characters as blocks with names like NUL, DC1, EOF, etc.
Then I went to Emacs, then switched between Mousepad and nano, then started using Geany, and I like to visually separate between tabs and spaces.
That way, I know where I align the code with spaces, and where I indent the code with tabs. When I open some other guy's file, sometimes I see they mix tabs and spaces...
I don't want to derail the thread, but use tabs for indentation and spaces for alignment. That way, I can set tab width to 8, and RMS can set it to 2, and we're all happy.
--
Let me say it like this: Never, ever, indent code with spaces. You're hardcoding your prefered indentation width into the file, and bloating the file size for no reason.
>>
Any other old niche languages that are worth learning, in order to overcharge companies?
>>
>>103215711
>Let me say it like this: Never, ever, indent code with spaces. You're hardcoding your prefered indentation width into the file, and bloating the file size for no reason.
I don't indent code at all, Rider does it for me. I have no idea what it's doing internally but it just works all the time
>>
>>103215951
I'm a caveman who indents his own code manually. Below, for other interested Anons, some basic Fortran syntax:
--
! This is single line comment in Fortran.
! Ifs
if (X) then
...
else
...
end if
! Switches
[name:] select case (X)
case A
...
case B
...
case default
...
end select [name]
! Loops
do i = start, stop [,step]
...
end do
! Functions
function name (arguments)
...
end function [name]

I'm not here to shill it, but I think it's readable, it reminds me of assembly in some ways, and of Python in other ways.
Also, I suggest everyone interested to use 'gfortran' compiler, not 'flang' (LLVM Fortran) compiler.
Also, I hope no one here will buy proprietary Fortran compiler... Intel and AMD have major ones, other companies minor ones.
--
Fortran might be the only language that was exclusively used by white men, no spooks, goons, pajeets or tr*nnies.
>>
>>103216046
>Fortran might be the only language that was exclusively used by white men, no spooks, goons,
>who is Kazushige Goto
>>
>>103216065
I find it interesting that someone on this sewing forum knows about Goto.
However, he's known for hand-optimized assembly and machine code.
>>
>>103216181
Yes, but to optimise libraries which extensively used Fortran, meaning he most likely had to know it well/
>>
>>103213663
>on benchmarks i keep seeing C and fortran as equal
>link me
Actually your average fortran is faster than your average C

what I mean is, it has to do with pointer referencing. C operates under the assumption that any given memory region has multiple pointers (you can't predict what is pointing where at runtime). So it has to hit memory and lose memory i/o latency whenever it references a pointer. FORTRAN doesn't really operate that way so it can be optimized here. So if our code is crunching large numerical data, C will get nerfed on memory i/o

I say your "average C" because of course the strong C programmers here know of the workaround, to use "restrict" pointers, but here the programmer is taking on the handling of knowing about multiple pointers at runtime
>>
I made a small console game in Fortran a while back, it was awful.
Mostly because I either shat myself or it's the way of doing it, but you have to declare your structures each time you use it in a function.
Please, tell me I shat myself and that Fortran is not that retarded...
>>
>>103217663
> Please, tell me I shat myself and that Fortran is not that retarded...
That's what modules are for.
--
Bigger problem with Fortran in my opinion is interoperability with C, if you want to use OpenGL in Fortran, it requires a lot of boilerplate.
Lets be real, most of useful libraries are written in C. As one Anon above said tho, a lot of science boilerplate programs are in Fortran...
--
I'm documenting IA32e and working on small x86-64 assembler, when I finish it, I'll look into auto-generator of C headers to Fortran modules.
I don't know if it was done before, probably was, but I don't know of it. Simple concepts should be easy, ELF symbol mangling will be harder.
>>
Where do I look for Fortran job offers?
>>
Freeform Fortran 2018 unironically looks pretty comfy. Too bad you have to go way out of your way to get a compiler that supports it.
>>
>>103213209
Because you haven't done anything meaningful in it
>>
>boomer thread
kinda comfy ngl
>>
>>103215711
>You're hardcoding your prefered indentation width into the file, and bloating the file size for no reason.

Given today's storage availability, file size isn't a concern. Tabs are inconsistent across different editors. It's better to use spaces. If you're working with a team, your code styling should be standardized anyway. Non-standardized styling is a sign of a disorganized team.
>>
someone post some Fortran projects they like...
>>
>>103222243
I don't like shilling stuff like this is some shitty webdev thread...
If you really want that, google "github fortran" or something else...
If you really expect people to show you something new for 80yo language:
> https://github.com/fortran-lang/stdlib
> https://github.com/fortran-lang/fpm
They were started around 2020 as modernization projects for Fortran.



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.