[ home / overboard ] [ soy / qa / raid / r ] [ craft ] [ int / pol ] [ a / an / asp / biz / mtv / r9k / tech / v / sude / x ] [ q / news / chive / rules / pass / bans / status ] [ wiki / booru / irc ]

A banner for soyjak.party

/tech/ - Soyence and Technology

Download more RAM for your Mac here
Catalog
Email
Subject
Comment
File
Password (For file deletion.)

File: 1770713289362n.png 📥︎ (1.84 MB, 765x1024) ImgOps

 28956[Quote]

Learning C++ atm
I have never used OOP or the original C. Only Python.
Any advice to learn C++ because I hear it can be quite tricky.

 28959[Quote]

Just use AI

 28980[Quote]

>>28978
Nice—coming from Python actually gives you a big advantage conceptually (especially if you've used NumPy), but Fortran will feel very different at first. The difficulty people talk about usually comes from its rigid structure, explicit memory allocation, and the confusing mix of ancient legacy code versus modern standards.

Here’s how to approach it without getting overwhelmed:

🧠 Shift your mindset first
Python hides a lot of complexity and lets you play loose with data. Fortran demands precision.
You’ll need to start thinking about:
* Types and declarations everywhere (no dynamic typing safety net).
* Memory layout (how arrays are stored physically matters for speed).
* Compilation (errors happen before running, not during).
That’s normal—don’t rush it.

🪜 Learn in this order (very important)

1. Core basics & The Golden Rule
Start with basic syntax.
* The Golden Rule: *Always* start every program and module with `implicit none`. (Without it, Fortran tries to implicitly guess variable types based on their first letter, which is a nightmare for debugging).
* Focus on:
* Variables (`integer`, `real`, `logical`, `character`).
* Control flow (`if`, `do` loops—Fortran's version of `for` loops).

2. Procedures and Intents
Fortran handles code blocks differently than Python's single `def`.
* Learn the difference between Functions (return a single value, used in expressions) and Subroutines (can modify multiple arguments, called explicitly with `call`).
* Master Intents: When passing variables, you explicitly declare if they are `intent(in)`, `intent(out)`, or `intent(inout)`. This makes your code incredibly safe and easy to read.

3. Arrays (The Fortran Superpower)
This is where Fortran shines and will feel a bit like NumPy.
* 1-based indexing: By default, arrays start at 1, not 0 like Python. (Though you can actually set custom bounds like `-5:5`).
* Dynamic allocation: Learn how to use `allocatable` arrays instead of fixed-size ones.
* Array slicing and intrinsics: Learn built-in math functions (`matmul`, `dot_product`, `sum`, `maxval`). You can do operations on whole arrays without writing loops.

4. Modules (Code Organization)
Don't write one massive script.
* Use `module` to group related variables, subroutines, and functions.
* Use `use` to import them into your main program (this is Fortran's equivalent of Python's `import`).

5. Modern Features (Derived Types)
Skip the archaic 1970s features and learn modern style:
* Derived Types (`type`): Fortran's version of `structs` or basic classes.
* Type-bound procedures: How Fortran handles Object-Oriented Programming.
* `elemental` and `pure` procedures (functions that guarantee no side effects).

⚠️ Common beginner traps

Getting trapped in Fortran 77 (Fixed Format)
If you see code where everything is IN ALL CAPS, stops exactly at column 72, and relies heavily on `GO TO` statements, run. You want to learn "Modern Fortran" (Fortran 90 and later), which uses "free format" and looks much cleaner.

Row-Major vs. Column-Major Memory
* Python/C stores 2D arrays row-by-row.
* Fortran stores them column-by-column.
If you write a nested loop that iterates over rows first in Fortran, your program will run incredibly slow. Always iterate over the innermost memory contiguous index (the first dimension).

0-based indexing confusion
Remember, your loops and array slices start at 1 now. A standard loop is `do i = 1, n`, not `for i in range(n)`.

🛠️ Tools to make life easier

* Compiler: `gfortran` (part of GCC) or Intel Fortran (`ifort`/`ifx`).
* Build System: fpm (Fortran Package Manager). This is a massive game-changer for modern Fortran—it acts a lot like `pip` and `cargo`, handling dependencies and building your project automatically.
* Use compiler flags:
`-Wall -Wextra -std=f2008` (Forces you to write clean, standard code).

🧩 Practice ideas (from Python → Fortran)

Translate Python/NumPy scripts:
* Matrix multiplication / Linear Algebra solver.
* A numerical integrator (like the Euler method or Runge-Kutta).
* File I/O: Read a `.csv` or `.dat` file, perform statistics on the columns, and write the output to a new file.

🔁 Biggest tip

Fortran isn’t just one language—it’s a historical timeline. You will inevitably search for help online and find solutions from 1985 mixed with solutions from 2018. Focus entirely on Modern Fortran (Free Format). Use `implicit none`, bundle your code in `modules`, and rely heavily on Fortran's built-in array operations.

 28983[Quote]

File: 1771587706850u.jpg 📥︎ (48.79 KB, 736x813) ImgOps

>>28959
>>28978
>>28980
you are all worthless niggers. Get out.
<
C++ is one Frankenstein of a language because while it's technically fully compitable with C, it borrows a lot of features and programming paradigms from other languages that came after it. So there are classes with constructors and accessibility fields, stream append operators and things like hash maps, iotas and vectors (linked lists)
<
for example the first thing you learn in any language is Hello World, in C++ it looks like this:

std::cout << "Hello World!" << endl;

this is retarded and no other language does it like that. Even in basic C you just write

printf("Hello world!");

looks more familiar to python right? Because it's a right approach. In C++, you use << operator to append a string to a output stream COUT in the namespace STD (which is supposed to house every basic shit you need but also not), which will call a function to print these lines on the screen. This is convoluted and retarded. Bjorn Strausswhatever is an idiot.
In any other language you just call the print function. In any other language you don't NEED namespaces in headers like iostream.
>OOP
If you want OOP use C#. It's nicer and more friendly.
>low level shit
if you want to learn things like pointers and addresses learn C. It's a basic and beautiful language.

 29039[Quote]

>>28956 (OP)
Don't learn it unless you need to work on a codebase with it. Use a better language like C or C#, like the person above me said.

 29041[Quote]

>>28983
>>29039
Unless you want a job (which is impossible to get btw), don't learn cpp tbh

 29117[Quote]

>>28983
>std::cout << "Hello World!" << endl;
>this is retarded and no other language does it like that. Even in basic C you just write
>printf("Hello world!");
holy retard has never heard of std::println
>if you want to learn things like pointers and addresses learn C. It's a basic and beautiful language.
c is nigger aids nigga

 29121[Quote]

File: ClipboardImage.png 📥︎ (139.82 KB, 320x334) ImgOps

Use AI, it's better

 29325[Quote]

Ill recommend you to learn c# firstly, after this yeah you can try to learn c++

 29463[Quote]

>>28983
> std::cout << "Hello World!" << endl;
> which will call a function
> in basic C you just write printf("Hello world!");
assuming this is accurate wouldn't it make more sense for this to be the other way around
appending to the buffer in c instead of in c++ since c is supposed to be lower level
why is that

 29464[Quote]

>>29463
Op here, so what I understand about C++ now that I am learning it is that it was made to work with anything, so they make it complex enough to work with every case.

 29515[Quote]

>>28956 (OP)
dont be a dumb nigger, dont give up and you will be fine



[Return][Catalog][Go to top][Post a Reply]
Delete Post [ ]
[ home / overboard ] [ soy / qa / raid / r ] [ craft ] [ int / pol ] [ a / an / asp / biz / mtv / r9k / tech / v / sude / x ] [ q / news / chive / rules / pass / bans / status ] [ wiki / booru / irc ]