Open-source News

BASIC vs. FORTRAN 77: Comparing programming blasts from the past

opensource.com - Wed, 04/05/2023 - 15:00
BASIC vs. FORTRAN 77: Comparing programming blasts from the past Jim Hall Wed, 04/05/2023 - 03:00

If you grew up with computers in the 1970s and 1980s, as I did, you probably learned a common programming language for personal computers called BASIC, or the Beginner's All-purpose Symbolic Instruction Code. You could find BASIC implementations on every personal computer of the era, including the TRS-80, Apple II, and the IBM PC. Back then, I was a self-taught BASIC programmer, experimenting with AppleSoft BASIC on the Apple II before moving to GW-BASIC on the IBM PC and, later, to QuickBASIC on DOS.

But once upon a time, a popular language for scientific programming was FORTRAN, short for FORmula TRANslation. Although since the 1990 specification of the language, the name is more commonly stylized as "Fortran."

When I studied physics as a university undergraduate student in the early 1990s, I leveraged my experience in BASIC to learn FORTRAN 77. That was when I realized that BASIC derived many of its concepts from FORTRAN. To be clear, FORTRAN and BASIC differ in lots of other ways, but I found that knowing a little BASIC helped me to learn FORTRAN programming quickly.

I want to show some similarities between the two languages by writing the same program in both. I'll explore the FOR loop in BASIC and FORTRAN 77 by writing a sample program to add a list of numbers from 1 to 10.

Bywater BASIC

BASIC came in many flavors, depending on your computer, but the overall language remained the same. One version of BASIC that I like is Bywater BASIC, an open source implementation of BASIC available for different platforms, including Linux and DOS.

To use Bywater BASIC on FreeDOS, you must first install the package from the FreeDOS 1.3 Bonus CD. To run it, go into the C: directory and type bwbasic. This command starts the BASIC interpreter. You can enter your program from this prompt:

bwBASIC:

Bywater BASIC uses an older BASIC programming standard that requires you to write every program instruction with a line number. Think of a line number like an index. You can easily refer to any instruction in the program with line numbers. As you type the program into the Bywater BASIC interpreter, add the line number before each instruction:

bwBASIC: 10 print "Add the numbers from 1 to 10 ..." bwBASIC: 20 sum = 0 bwBASIC: 30 for i = 1 to 10 bwBASIC: 40 sum = sum + i bwBASIC: 50 next i bwBASIC: 60 print sum bwBASIC: 70 end

Use the list command to view the program you have entered into the interpreter:

bwBASIC: list 10 print "Add the numbers from 1 to 10 ..." 20 sum = 0 30 for i = 1 to 10 40 sum = sum + i 50 next i 60 print sum 70 end

This short program demonstrates the FOR loop in BASIC. FOR is the most fundamental loop construct in any programming language, allowing you to iterate over a set of values. The general syntax of the FOR loop in Bywater BASIC looks like this:

FOR var = start TO end

In this example program, the instruction for i = 1 to 10 starts a loop that iterates through the values 1 to 10. At each pass through the loop, the variable i is set to the new value.

In BASIC, all instructions up to the next instruction are executed as part of the FOR loop. Because you can put one FOR loop inside another, Bywater BASIC uses the syntax NEXT variable to specify which loop variable to iterate.

Type run at the prompt to execute the program:

bwBASIC: run Add the numbers from 1 to 10 ... 55

Bywater BASIC is called a BASIC interpreter because you can only run the program from inside the Bywater BASIC environment. This means the interpreter does all the hard work of interacting with the operating system, so your program doesn't need to do that on its own, with the trade-off that the program runs a little slower in the interpreted environment than it might if it were a compiled program.

FreeBASIC

Another popular implementation of BASIC is FreeBASIC, an open source BASIC compiler for several platforms, including Linux and DOS. To use FreeBASIC, you'll need to install the FreeBASIC package from the FreeDOS 1.3 Bonus CD, then change into the C: directory where you'll find the FreeBASIC programs.

FreeBASIC is a compiler, so you first create a source file with your program instructions, then run the compiler with the source code to create a program you can run. I wrote a similar version of the "add the numbers from 1 to 10" program as this BASIC file, which I saved as sum.bas:

dim sum as integer dim i as integer print "Add the numbers from 1 to 10 ..." sum = 0 for i = 1 to 10 sum = sum + i next print sum end

If you compare this code to the Bywater BASIC version of the program, you may notice that FreeBASIC doesn't require line numbers. FreeBASIC implements a more modern version of BASIC that makes it easier to write programs without keeping track of line numbers.

Another key difference is that you must define or declare your variables in your source code. Use the DIM instruction to declare a variable in FreeBASIC, such as dim sum as integer, to define an integer variable called sum.

Now you can compile the BASIC program using fbc on the command line:

C:\DEVEL\FBC> fbc sum.bas

If your code doesn't have any errors in it, the compiler generates a program that you can run. For example, my program is now called sum. Running my program adds up the numbers from 1 to 10:

C:\DEVEL\FBC> sum Add the numbers from 1 to 10 ... 55FORTRAN 77

The FORTRAN programming language is like a hybrid between old-style and modern BASIC. FORTRAN came before BASIC, and BASIC clearly took inspiration from FORTRAN, just as later versions of FORTRAN took cues from BASIC. You write FORTRAN programs as source code in a file but you don't use line numbers everywhere. However, FORTRAN 77 does use line numbers (called labels) for certain instructions, including the FOR loop. Although in FORTRAN 77, the FOR is actually called a DO loop, it does the same thing and has almost the same usage.

In FORTRAN 77, the DO loop syntax looks like this:

DO label var = start, end

This situation is one of the instances where you need a line number to indicate where the DO loop ends. You used a NEXT instruction in BASIC, but FORTRAN requires a line label instead. Typically, that line is a CONTINUE instruction.

Look at this sample FORTRAN program to see how to use DO to loop over a set of numbers. I saved this source file as sum.f:

PROGRAM MAIN INTEGER SUM,I PRINT *, 'ADD THE NUMBERS FROM 1 TO 10 ...' SUM = 0 DO 10 I = 1, 10 SUM = SUM + I 10 CONTINUE PRINT *, SUM END

 

In FORTRAN, every program needs to start with the PROGRAM instruction, with a name for the program. You might name this program SUM, but then you cannot use the variable SUM later in the program. When I learned FORTRAN, I borrowed from C programming and started all of my FORTRAN programs with PROGRAM MAIN, like the main() function in C programs, because I was unlikely to use a variable called MAIN.

The DO loop in FORTRAN is similar to the FOR loop in BASIC. It iterates over values from 1 to 10. The variable I gets the new value at each pass over the loop. This allows you to add each number from 1 to 10 and print the sum when you're done.

You can find FORTRAN compilers for every platform, including Linux and DOS. FreeDOS 1.3 includes the OpenWatcom FORTRAN compiler on the Bonus CD. On Linux, you may need to install a package to install GNU Fortran support in the GNU Compiler Collection (GCC). On Fedora Linux, you use the following command to add GNU Fortran support:

$ sudo dnf install gcc-gfortran

Then you can compile sum.f and run the program with these commands:

$ gfortran -o sum sum.f $ ./sum ADD THE NUMBERS FROM 1 TO 10 ... 55A few differences

I find that FORTRAN and BASIC are very similar, but with some differences. The core languages are different, but if you know a little of BASIC, you can learn FORTRAN. And if you know some FORTRAN, you can learn BASIC.

If you want to explore both of these languages, here are a few things to keep in mind:

  • FORTRAN 77 uses all uppercase, but later versions of FORTRAN allow mixed cases as long as you use the same capitalization for variables, functions, and subroutines. Most implementations of BASIC are case-insensitive, meaning you can freely mix uppercase and lowercase letters.

  • There are many different versions of BASIC, but they usually do the same thing. If you learn one BASIC implementation, you can easily learn how to use a different one. Watch for warnings or error messages from the BASIC interpreter or compiler, and explore the manual to find the differences.

  • Some BASIC implementations require line numbers, such as Bywater BASIC and GW-BASIC. More modern BASIC versions allow you to write programs without line numbers. FreeBASIC requires the -lang deprecated option to compile programs with line numbers.

I explore the FOR loop in BASIC and FORTRAN 77 by writing a sample program to add a list of numbers from 1 to 10.

Image by:

Opensource.com

Programming What to read next This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License. Register or Login to post a comment.

Our favorite fonts for the Linux terminal

opensource.com - Wed, 04/05/2023 - 15:00
Our favorite fonts for the Linux terminal Jim Hall Wed, 04/05/2023 - 03:00

Terminal emulators came up as a topic for me recently, and it got me thinking: What's everyone's favorite terminal font?

So I asked Opensource.com contributors to share what font they like to use. Here are their answers.

VT323

I like to use a different font (VT323) in my GNOME Terminal than the font I use (Source Code Pro) in my programming editors or other apps that use a monospace font. I just like the look of the classic VT-style font.

Sometimes, I switch to the original IBM EGA font, because to my eye it looks really nice. But I associate EGA with DOS, and I associate VT323 with classic Unix terminals, so I use VT323 most of the time. Here's my screenshot of GNOME Terminal using VT323 as the monospace font:

Image by:

(Jim Hall CC BY-SA 4.0)

I set up the terminal using VT323 at 24 pt, which gives a nice big window. If I'm going to bring up a terminal window, I want to really use it to do real work, not just do one thing and exit. I'm probably going to stay in that terminal window for a while, so it should be big and easy to see. I also prefer 80x25, because I'm an old DOS command line guy and 25 lines looks "right" to my eyes:

Image by:

(Jim Hall CC BY-SA 4.0)

Jim Hall

Monospaced fonts

I don't know that I have a specific font that I use. I usually use either DejaVu or Liberation Mono. I like monospaced fonts because they're easier to read. Even then, I don't want the letters to be too close together. The main thing is being able to tell a small "L" from the number 1, Q from O, and so on. It's also nice to have all special characters stand out clearly.

I also like a good contrast between the font and background, so I set the background to black and characters to white.

Greg Pittman

Hack

I like to use monospaced fonts, particularly for the terminal and coding because they're easier to read. I've been using the Hack font family for years. It provides a nice monospace font combined with additional glyphs and Powerline characters that I can use to display status on the command line.

Image by:

(Ricardo Gerardi CC BY-SA 4.0)

Here's the font preview generated with Fontpreview tool.

Image by:

(Ricardo Gerardi CC BY-SA 4.0)

Ricardo Gerardi

Victor Mono

I've been using Victor Mono for both my terminal and IDE for a few years. It's perhaps a bit of an acquired taste, because the italic characters are in a monospace cursive script. I like this because code comments have a distinct look that's noticeably different from the rest of the code. Here's what it looks like in a terminal:

Image by:

(Chris Reynolds CC BY-SA 4.0)

I also use the Solarized Dark color scheme for both my IDE and the terminal. If I could, anything work or code related would all use the same color scheme, and the same fonts, so it all looks uniform. I've gone through various fonts over the years, but I always try to use the same thing in my terminal as in my IDE.

Chris Reynolds

Monaco

At the moment, Monaco regular at 16 pt (so much better than 12 or 14 pt fonts).

Jenny Panighetti

Keeping it pretty in pink

This reminds me of the time I pranked the other devs on my team by making all of their terminals pink (I was the only woman). It was like a baby pink background with hot pink text.

I like to make my personal terminals pretty, but for work I leave it white on black and just make the font around 16 pt because I appreciate the larger font size.

I just leave my terminal set to SF Mono font, but I make it bolder and bump it up a few points so I can see it better. My favorite colors to use are pink or a nice aqua blue color. I also like the default style the terminal has, called "Novel".

Image by:

(RachieVee CC BY-SA 4.0)

RachieVee

Let's ask ChatGPT

For the heck of it, I decided to ask ChatGPT. Here was its response:

As a language model, I do not have personal preferences or the ability to have a favorite font. However, some popular terminal fonts include Monospace, Consolas, and Inconsolata. These fonts are popular because they are easy to read, have clear distinctions between different characters, and are highly legible even at small font sizes. Additionally, they are designed to work well with a variety of different operating systems and terminals, making them versatile choices for developers and users alike.

I generated this text in part with GPT-3, OpenAI's large-scale language-generation model. Upon generating draft language, the author reviewed, edited, and revised the language to my own liking and takes ultimate responsibility for the content of this publication.

Stephanie Brinley

Fantasque Sans Mono $ grep font ~/.Xdefaults URxvt*font: xft:FantasqueSansMono-Regular:pixelsize=12:antialias=true

I don't remember when I settled on Fantasque Sans Mono, but I guess it's been my default for the past 8 years now, both in Rxvt and Konsole. I don't know what font I'm using in my GNOME terminal. Probably whatever the default is on GNOME.

Seth Kenlon

Jetbrains Mono

Lately, I have Tilix set as my default terminal. My Tilix config has similar settings to what Jim Hall uses. The few differences are:

  • Cursor shape is underline instead of a block
  • Font is Jetbrains Mono Nerd Font Mono Medium 14
Image by:

(Alan Formy-Duval CC BY-SA 4.0)

 —Alan Formy-Duval

Here is an entirely subjective list of some fun fonts for your Linux console.

Image by:

Jamie Cox. Modified by Opensource.com. CC BY 2.0.

Linux Opensource.com community What to read next This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License. 29648 points New Zealand (South Island)

Seth Kenlon is a UNIX geek, free culture advocate, independent multimedia artist, and D&D nerd. He has worked in the film and computing industry, often at the same time. He is one of the maintainers of the Slackware-based multimedia production project Slackermedia.

User Attributes Team Open Source Super Star Moderator's Choice Award 2011 Best Interview Award 2017 Author 100+ Contributions Club Columnist Contributor Club 4602 points United States

Alan has 20 years of IT experience, mostly in the Government and Financial sectors. He started as a Value Added Reseller before moving into Systems Engineering. Alan's background is in high-availability clustered apps. He wrote the 'Users and Groups' and 'Apache and the Web Stack' chapters in the Oracle Press/McGraw Hill 'Oracle Solaris 11 System Administration' book. He earned his Master of Science in Information Systems from George Mason University. Alan is a long-time proponent of Open Source Software.

| Follow AlanFormy_Duval User Attributes Correspondent Open Source Sensei People's Choice Award Author Comment Gardener Correspondent Apache DevOps Gamer Linux SysAdmin Geek Java Contributor Club 46 points

I’m a WordPress developer who has a keen interest in accessibility. #a11y I’m also a technical writer and I share my WordPress and coding experiences on my blog.

| Follow rachelrvasquez Open Enthusiast 1173 points Toronto

Ricardo Gerardi is Technical Community Advocate for Enable Sysadmin and Enable Architect. He was previously a principal consultant at Red Hat Canada, where he specialized in IT automation with Ansible and OpenShift.

He has been a Linux and open source enthusiast and contributor for over 20 years. He is currently interested in hacking stuff using the Go programming language, and he's the author of the book Powerful Command-Line Applications in Go. Ricardo also writes regularly about Linux, Vim, and command line tools for the community publications Opensource.com and Enable Sysadmin.

Ricardo enjoys spending time with his daughters, reading science fiction books, and playing video games.

| Follow ricardogerardi | Connect ricardogerardi Open Source Champion People's Choice Award Awesome Article Award 2019 Author DevOps Linux Developer Docker Fedora Geek Contributor Club 4595 points Louisville, KY

Greg is a retired neurologist in Louisville, Kentucky, with a long-standing interest in computers and programming, beginning with Fortran IV in the 1960s. When Linux and open source software came along, it kindled a commitment to learning more, and eventually contributing. He is a member of the Scribus Team.

Open Source Sensei Emerging Contributor Award 2017 Awesome Article Award 2019 Author Python Contributor Club 17 points Salt Lake City

I am a Software Engineer for Pantheon. I’ve been building things with WordPress since around 2007. Before that, I played with various other open source platforms and the first incarnation of my blog was written entirely in HTML. Originally a designer, I graduated from the University of Redlands, Johnston Center, with a self-made degree titled Creative Arts in the Digital Revolution, which combined my loves for music, visual art, film and writing using computers as a medium for all of them.

I have worked as a freelance designer and developer, for a premium WordPress plugin developer, as well as in development agencies like WebDevStudios and Human Made. I've also authored many WordPress training courses (now retired) on the online learning platform, Pluralsight.

When I'm not working, I'm probably playing, planning or reading about Dungeons & Dragons and tabletop role-playing games.

| Follow jazzs3quence | Connect chrissreynolds Community Member 17 points Community Member 1 Comment Register or Login to post a comment. Fábio Emilio Costa | April 5, 2023 Register or Login to like

I'm partial on Victor Mono and Fantasque Sans Mono

Chrome 112 Released With WASM Garbage Collection Trial, CSS Nesting

Phoronix - Wed, 04/05/2023 - 05:20
Google today promoted the Chrome 112 web browser to their stable channel on all supported platforms...

RADV Lands Shader Caching For Graphics Pipeline Libraries

Phoronix - Wed, 04/05/2023 - 04:55
Ahead of hopefully enabling the RADV Vulkan Graphics Pipeline Libraries "GPL" support by default for this quarter's Mesa 23.1 release, the RADV driver has now landed on-disk shader caching support for GPL libraries...

CentOS Hyperscale SIG Now Has An Intel-Optimized Repository

Phoronix - Wed, 04/05/2023 - 02:00
The CentOS Hyperscale special interest group that is focused on providing new packages and features atop CentOS Stream for use by hyperscalers like Meta and Twitter have now established a "hyperscale-intel" repository for Intel-optimized packages...

System76 Teases Their "Virgo" In-House Manufactured Laptop

Phoronix - Tue, 04/04/2023 - 23:35
While for a number of years now System76 has manufactured their own Thelio desktop line of Linux PCs from their facility in Denver, Colorado (and their Launch Keyboard), they have long talked up ambitions for eventually manufacturing their own Linux laptops rather relying on other white-label manufacturers as they currently do. Today a first glimpse of their in-house laptop prototyping was shared,..

Intel Posts Xe DRM Scheduler Patches For Review

Phoronix - Tue, 04/04/2023 - 21:30
As part of the process for getting Intel's new Xe DRM kernel driver upstreamed as the eventual replacement to the existing i915 driver for Gen12 graphics hardware and newer, Intel engineers on Monday posted the initial Xe DRM scheduler patches that have been separated out to get review on them, figure out what can be common/shared among drivers, and get those bits upstreamed...

Updated NVIDIA Turing Firmware Published For Open-Source Nouveau Driver

Phoronix - Tue, 04/04/2023 - 20:33
NVIDIA has published updated NVIDIA TU10x /TU11x "Turing" GPU firmware to support newer RTX 20 hardware revisions and fix outstanding issues affecting the open-source Nouveau driver...

Pages