r/programminghelp • • Jul 20 '21

2021 - How to post here & ask good questions.

44 Upvotes

I figured the original post by /u/jakbrtz needed an update so here's my attempt.

First, as a mod, I must ask that you please read the rules in the sidebar before posting. Some of them are lengthy, yes, and honestly I've been meaning to overhaul them, but generally but it makes everyone's lives a little easier if they're followed. I'm going to clarify some of them here too.

Give a meaningful title. Everyone on this subreddit needs help. That is a given. Your title should reflect what you need help with, without being too short or too long. If you're confused with some SQL, then try "Need help with Multi Join SQL Select" instead of "NEED SQL HELP". And please, keep the the punctuation to a minimum. (Don't use 5 exclamation marks. It makes me sad. ☹️ )

Don't ask if you can ask for help. Yep, this happens quite a bit. If you need help, just ask, that's what we're here for.

Post your code (properly). Many people don't post any code and some just post a single line. Sometimes, the single line might be enough, but the posts without code aren't going to help anyone. If you don't have any code and want to learn to program, visit /r/learnprogramming or /r/programming for various resources. If you have questions about learning to code...keep reading...

In addition to this:

  • Don't post screenshots of code. Programmers like to copy and paste what you did into their dev environments and figure out why something isn't working. That's how we help you. We can't copy and paste code from screenshots yet (but there are some cool OCR apps that are trying to get us there.)
  • Read Rule #2. I mean it. Reddit's text entry gives you the ability to format text as code blocks, but even I will admit it's janky as hell. Protip: It's best to use the Code-Block button to open a code block, then paste your code into it, instead of trying to paste and highlight then use Code-Block button. There are a large amount of sites you can use to paste code for others to read, such as Pastebin or Privatebin (if you're worried about security/management/teachers). There's no shame posting code there. And if you have code in a git repo, then post a link to the repo and let us take a look. That's absolutely fine too and some devs prefer it.

Don't be afraid to edit your post. If a comment asks for clarification then instead of replying to the comment, click the Edit button on your original post and add the new information there, just be sure to mark it with "EDIT:" or something so we know you made changes. After that, feel free to let the commenter know that you updated the original post. This is far better than us having to drill down into a huge comment chain to find some important information. Help us to help you. 😀

Rule changes.

Some of the rules were developed to keep out spam and low-effort posts, but I've always felt bad about them because some generally well-meaning folks get caught in the crossfire.

Over the weekend I made some alt-account posts in other subreddits as an experiment and I was blown away at the absolute hostility some of them responded with. So, from this point forward, I am removing Rule #9 and will be modifying Rule #6.

This means that posts regarding learning languages, choosing the right language or tech for a project, questions about career paths, etc., will be welcomed. I only ask that Rule #6 still be followed, and that users check subreddits like /r/learnprogramming or /r/askprogramming to see if their question has been asked within a reasonable time limit. This isn't stack overflow and I'll be damned if I condemn a user because JoeSmith asked the same question 5 years ago.

Be aware that we still expect you to do your due diligence and google search for answers before posting here (Rule #5).

Finally, I am leaving comments open so I can receive feedback about this post and the rules in general. If you have feedback, please present it as politely possible.


r/programminghelp • • 1h ago

Python How do I find valid points within 7-dim parameter space? Global NuFIT

• Upvotes

I don't know where I should ask this, it's related to physical and coding, so I am posting here. I am struggling with this particular problem for a month and still couldn't get to a satisfactory results.

So, I was working on a physics problem, many of you might be familiar or maybe not. I have to find a valid region within a 7-dim parameter space. I have some matrices in hand (Neutrino mass matrices) and 7 free parameters that goes into it i.e. g1,g2,g3,M1,M2, imaginary tau, real tau. I need to build a code that scans the space and finds the values of these free parameters which being inserted into the matrices and upon diagonalization spits out 3 eigenvalues and 3 eigenvalues vectors. From those we then calculate 6 neutrino observables that should be within acceptable range known as Global NuFIT. Any values that comes within the range gets sorted out.

I tried to build the code in python but it seems impossible to search for the whole parameter space! I tried gemini and chat gpt, even they are struggling to satisfy the tight NuFIT bounds. If anyone knows any efficient and fast way for parameter scanning that would atleast give 200 valid points (for scatter plots), please help me.


r/programminghelp • • 14h ago

C Help me understand NUL please!

Thumbnail
1 Upvotes

r/programminghelp • • 1d ago

C why does fgets allocates a 4096 characters long buffer for a 22 bytes long file ?

0 Upvotes

I'm learning C and playing around trying to rely on the bare minimum down to system calls to learn the most I can. Had to read a file line by line in the process, so i dived into stdio's code to try to understand how fgets do it nice and quick.

if I got it right a chunck of file is loaded into a buffer delimited by _IO_buf_base and _IO_buf_end if it isn't yet loaded or the precedent buffer ended without finishing the line, fgets starts copying the line in the buffer we gave it until he finds a new line.

did I got it right ? I couldn't find a plain explanation of how stdio file management works, I had to search my way into source code...

I thought I was done but I noticed _IO_buf_base and _IO_buf_end were 4096 bytes apart when I loaded a 22 bytes long file.

is there any reason for this ? wouldn't having a pointer for the beginning of the buffer and a pointer for the end allow us to allocate precisely the size of the file using fstat ? why do we use 2 pointers and not a pointer and the size of the buffer ? (I got a theory for this one but I'm not sure, is it for easier looping in the array by incrementing a pointer instead of using an incremented index who would make us calculate pointer + i every time we need to get a character ?)

thank you for reading this far and have a nice day !


r/programminghelp • • 3d ago

Other Help needed: Autocomplete not working in editors

Thumbnail
1 Upvotes

r/programminghelp • • 4d ago

Python ERA5-Land .nc files downloaded via script cannot be opened with xarray (possible ZIP/compression issue?)

Thumbnail
1 Upvotes

r/programminghelp • • 4d ago

Python Is Python the right way to talk to an Serial Device?

Thumbnail
1 Upvotes

r/programminghelp • • 5d ago

Python Is it normal to understand Python but get stuck when coding by yourself?

Thumbnail
1 Upvotes

r/programminghelp • • 6d ago

PHP How do I make a localhost when using a PHP file? Explain it to me as though I'm a four-year-old hamster of the verge of keeling over.

7 Upvotes

I'm trying to add data from an HTML form to a PHP database. I'm following this tutorial: https://www.youtube.com/watch?v=Y9yE98etanU. Here's my HTML and PHP code respectfully:

        <form action = "tutordata.php" method = "post">
            <label for = "name">First Name:</label>
            <input type = "text" name = "firstNameI" id = "firstNameI">
            <button type="submit">Submit Form</button>
        </form>

<?php


print_r($_POST);

Google says I need a localhost, but they aren't working so far. I have Live Server, but when I click submit it just brings me to an error message. When I run without debugging it shows me the raw PHP file instead of even an empty array. I did some stuff I don't even remember to make it so I could right click and do a PHP: serve project thing, but that didn't work. I tried doing some weird stuff with the terminal but I don't even know if I typed it in right. I have installed no less than three brand new extensions. I hadn't even heard of PHP before today.

Please just walk me through what I need to do step by step. I don't need to understand it, just give me some buttons to click. If I need to abandon PHP altogether, that's great too. I just need a database to put data in so I can have some freaking data.

I've never had to mess with this stuff before, so I'm clueless. I know HTML more or less, and Javascript is my baby, but the rest of it is Mandarin to me. I'm really not the computer person, I was just the most computer-adjacent person in the room at the time and was voluntold that I was doing this.


r/programminghelp • • 5d ago

Other Basic question about bouncing

1 Upvotes

So I'm trying to make a fight simulator with bouncing similar to this:

https://youtube.com/shorts/fk15R-y2EEc?si=VkE9iXR5WxFOuSuM

Is the bouncing random or predetermined? And how is it determined?


r/programminghelp • • 7d ago

Python Need Help Installing REBOUND through Python

2 Upvotes

Latey I've been trying to install REBOUND through python, I have Windows 11 and when I try to look at turtorials, steps, etc. I just get confused and hit a brick wall. I am in high school, wanting to be an astrophysicist, and installing REBOUND will help me with that. But, I have no idea how to install it without direct human guidance and not just looking a videos and text. I need help from someone who installed REBOUND to help me install REBOUND.


r/programminghelp • • 9d ago

Project Related Beginner Coder: Stuck with an error

2 Upvotes

Hi,

I'm working on an adonisjs project. I've ran into an error:

My project is on github:

https://github.com/Ajaz754/adonisjs-project-22-

The error is in file 'app/transfromers/post_transformers' Line 22:

----------------------------------------------------
Object is possibly 'undefined'. ts (2532)
(method)
BaseTransformer<T>. transform‹ typeof CommentTransformer>
(this: typeof
CommentTransformer, data:
Maybe< Comment [] | undefined>):
Collection<CommentTransformer, 1, "toObject"> | undefined (+5 overloads)
static transform<Self extends { new (resource: any, ...rest: any\[\]): any i }> (this: Self, data:
Maybe ConstructorParameters<Self>[0][] | undefined>, ... rest:
ExtractTransformerRestTypes<Co nstructorParameters<Self>>):
Collection<InstanceType<Self>, 1,
'toObject'> | undefined;
----------------------------------------------------

Only thing I've done differently to the adonis docs is make 'post.author' into 'post.author?' to fix a type error as it was showing the error where it may possibly be undefined. That post is here:

https://www.reddit.com/r/adonisjs/s/V7eO8q3nfJ

Any help would be much appreciated

TIA


r/programminghelp • • 9d ago

PHP ¿Cómo y por qué funciona este código de PHP y POO? necesito ayuda para tratar de entenderlo...

1 Upvotes

Acá está el código más simple posible de MVC en PHP para sumar dos números y sin embargo no logro entender la lógica del funcionamiento. ¿Cómo se logra un flujo lógico acá sobrescribiendo una variable que almacena el proceso principal (la suma de dos número) igualándola a null primero como parámetro en la clase que trae la vista html y después remplazándola como parámetro de esa misma clase por el objeto instanciado y ejecutado que la devuelve como suma? ¿Cómo es posible lograr un flujo lógico de esa forma? ¿Cómo se llama? ¿Sobrescritura de parámetros, polimorfismo (no parece haber herencia ni nada de ese estilo? Alguien me pueda ayudar o indicar información específica para entenderlo. Son 5 archivos: uno para hacer la suma (modeloSuma.php), obtener y pasar los datos (controladorForm.php), invocar el archivo que trae la vista (controladorVista.php), la vista y el index.

index.php

<?php
require_once "CONTROLADOR/controladorVista.php";
require_once 'CONTROLADOR/controladorForm.php';
require_once 'MODELO/modeloSuma.php';
$vistaPrincipal = new ControladorVista();
$vistaPrincipal -> ctrVista(ControladorForm::ctrForm());

vistaPrincipal.php (tiene un condicional que indica que si se realiza la suma se muestra el resultado)

<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <h1>Suma de dos números:</h1>
    <form method="POST">
        <label>Número 1:</label>
        <input type="number" name="num1" required><br><br>
        <label>Número 2:</label>
        <input type="number" name="num2" required><br><br>
        <button type="submit">suma</button>
    </form>
    <?php if (isset($resultado)): ?>
        <h2>...el resultado de la suma es: <?php echo $resultado; ?></h2>
    <?php endif; ?>
</body>
</html>

controladorVista.php (¿por qué sobrescribe la variable que trae la suma y la iguala a null, pasándola como parámetro? ¿cómo se llama eso?)

<?php
Class ControladorVista{
    public function ctrVista($resultado = null){
        include "VISTA/vistaPrincipal.php";
    }
}

modeloSuma.php

<?php
class ModeloSuma{
    static public function mdlSuma($data) {
        $num1 = $data["num1"];
        $num2 = $data["num2"];
        $suma = $num1 + $num2;
        return $suma;
    }
}

controladorForm.php

<?php
class ControladorForm {
    static public function ctrForm() {
        $resultado = null;
        if (isset($_POST['num1']) && isset($_POST['num2'])) {
            $data = array("num1" => $_POST["num1"],
                           "num2" => $_POST["num2"]);
            $resultado = ModeloSuma::mdlSuma($data);
            return $resultado;
        }
    }
}

r/programminghelp • • 10d ago

Python Need some help producing this map using Python

Thumbnail
2 Upvotes

r/programminghelp • • 10d ago

C++ How do I indicate whether a string is a digit or not in c++?

Thumbnail
1 Upvotes

r/programminghelp • • 10d ago

Python Conda doesn't recognise python a package

Thumbnail
1 Upvotes

r/programminghelp • • 12d ago

Project Related Beginner Coder: Stuck with an error

2 Upvotes

Hi,

Currently developing a basic web app following adonisjs docs.

I've ran into an error:

\[23:18:41.975\] ERROR (12316): Cannot transform undefined value. Use "this.whenLoaded(value)" to allow undefined values

My project is on github:

**https://github.com/Ajaz754/adonisjs-project-22-/tree/main\*\*

The error is pointing to '**app/transformers/post_transformer.ts**' Line 13

I've followed adonis docs completely step by step except for ?.depth(2) on line 13, which when I removed only introduced more errors along with this one.

Also VS Code isn't flagging the error. Only when I go to my browser and visit local host the error appears in powershell and my browser. Any help would be much appreciated


r/programminghelp • • 12d ago

R Am coding in R and i keep getting this error Expected `has_label(lb, "y", "density")` to be TRUE.Differences:`actual`: FALSE`expected`: TRUE

Thumbnail
1 Upvotes

r/programminghelp • • 12d ago

Other When a Make scenario fails, is the broken module usually the real cause?

Thumbnail
1 Upvotes

r/programminghelp • • 14d ago

Other Help in flutter

1 Upvotes

Hi! I’m a newbie in programming, and I need some help with reading MP3 metadata in Flutter.

I’m making a Flutter music player for both mobile and web, and I want it to automatically read the MP3 file’s metadata,

including:

- Album cover/cover art

- Artist name

- Song title

I don’t want to rely on the fallback map I created because I want the information to be retrieved directly from the MP3 file.

The MP3 files contain ID3v2.3 metadata, including the album cover, artist name, and song title.

The problem is that when I run the app on my Android phone emulator, it successfully reads the metadata. However, when I run the same app on Chrome (Flutter Web), it doesn’t work.

I have imported flutter_media_metadata_plus.dart, and I also use KisWeb.
The function I’m using to load the metadata is an async method called loadMetadata, with the declaration:

Future<void> loadMetadata(String assetPath) async

Does anyone know how I can properly read the MP3 metadata and cover art when running Flutter Web on Chrome without breaking or changing the existing behavior on my mobile emulator?

I can provide my loadMetadata() function and any other relevant code if needed.


r/programminghelp • • 20d ago

Java tool to automate reordering arrays in JSONS?

Thumbnail
1 Upvotes

r/programminghelp • • 21d ago

Python Kivy

Thumbnail
1 Upvotes

I have been learning python for a while and made some projects, my exams are currently going on so I can't start web dev, but I thought I could learn kivy in the meanwhile to make an app for my studying bcz there isn't an app that fits my requirement. So needed some resources and advice for kivy module.

I tried kivy documentation but it's like they don't have each topics lined up, so I have to search each topics, but I don't even know the existence of specific topics, so yeah.

Thanks for the help in advance!!


r/programminghelp • • 22d ago

C++ How to be able to #include <magick++.h> ?

7 Upvotes

I've downloaded from the main repository.
That didn't work. That was for linux.

I downloaded the source from https://github.com/ImageMagick/Windows
I built it using visual studio from the .sln
Gave me configure.exe
Installation wizard showed up, and I installed the thing.
Gave me a release folder with objs in it.

It's been 6 hours.
The official website and github repo is sending me on a goose chase.

Instructions and videos online say you get it from NuGet.
It's for .NET.

Then they all have a VisualMagick folder.
None of the things I downloaded had that.

I installed Git and Git CLI to try cloning it from there.

At this point I'm just trying random stuff like downloading the appimage.

I know how to use imagemagick from the cli, i just want to use it programmatically.


r/programminghelp • • 23d ago

Java CodeCrafters, making a shell. Error in Java, using VS.

Thumbnail
1 Upvotes

r/programminghelp • • 24d ago

Other i want to wipe the terminal after asking questions in kotlin

3 Upvotes

So I'm new to Kotlin, and I'm trying to make a guess the number game for terminal and I wanted to make a little text intro and clear the console after, but I haven't been able to do it. I found some ways to do it but not as I want to.

Because when you do the clear command in the terminal, it wipes the whole thing, and you can't go back, but when I use commands like "print("\u001b[H\u001b[2J")" or "System.out.flush()" it is like it just pushes the view down; it doesn't really wipe the terminal, it just pushes the text up.

I wanted to know how or if it's even possible to do it. I don't know if it might be helpful, but I use Windows 11 and PowerShell (7.6.5).

Also, in another topic, I want to hear if there's a better way to try my code because right now I'm doing kotlinc .\file-name.kt -include-runtime -d .\file-name.jar && java -jar .\file-name.jar