/r/learnprogramming

Photograph via snooOG

A subreddit for all questions related to programming in any language.

Welcome to LearnProgramming!


New? READ ME FIRST!

Posting guidelines

Frequently asked questions

Subreddit rules

Message the moderators


Asking debugging questions

If you need help debugging, you must include:

  1. A concise but descriptive title.
  2. A good description of the problem.
  3. A minimal, easily runnable, and well-formatted program that illustrates your problem.
  4. The output you expected, and what you got instead. If you got an error, include the full error message.

See debugging question guidelines for more info.

Asking conceptual questions

Many conceptual questions have already been asked and answered. Read our FAQ and search old posts before asking your question. If your question is similar to one in the FAQ, explain how it's different.

See conceptual questions guidelines for more info.

Other guidelines and links

  1. Frequently asked questions
  2. Asking homework questions
  3. Asking for code review
  4. Answering questions
  5. Learning resources
  6. Other communities

Subreddit rules

1. No unprofessional/derogatory speech

  • Follow reddiquette: behave professionally and civilly at all times. Communicate to others the same way you would at your workplace. Disagreement and technical critiques are ok, but personal attacks are not.

Abusive, racist, or derogatory comments are absolutely not tolerated.

See our policies on acceptable speech and conduct for more details.

2. No spam or tasteless self-promotion

In short, your posting history should not be predominantly self-promotional and your resource should be high-quality and complete. Your post should not "feel spammy".

Distinguishing between tasteless and tasteful self-promotion is inherently subjective. When in doubt, message the mods and ask them to review your post.

Self promotion from first time posters without prior participation in the subreddit is explicitly forbidden.

3. No off-topic posts

  • Do not post questions that are completely unrelated to programming, software engineering, and related fields. Tech support and hardware recommendation questions count as "completely unrelated".

Questions that straddle the line between learning programming and learning other tech topics are ok: we don't expect beginners to know how exactly to categorize their question.

See our policies on allowed topics for more details.

4. Do not ask exact duplicates of FAQ questions

  • Do not post questions that are an exact duplicate of something already answered in the FAQ.

If your question is similar to an existing FAQ question, you MUST cite which part of the FAQ you looked at and what exactly you want clarification on.

5. Do not delete posts

  • Do not delete your post! Your problem may be solved, but others who have similar problems in the future could benefit from the solution/discussion in the thread.

Use the "solved" flair instead.

6. No app/website review requests or showcases

  • Do not request reviews for, promote, or showcase some app or website you've written. This is a subreddit for learning programming, not a "critique my project" or "advertise my project" subreddit.

Asking for code reviews is ok as long as you follow the relevant policies. In short, link to only your code and be specific about what you want feedback on. Do not include a link to a final product or to a demo in your post.

7. No rewards

  • You may not ask for or offer payment of any kind (monetary or otherwise) when giving or receiving help.

In particular, it is not appropriate to offer a reward, bounty, or bribe to try and expedite answers to your question, nor is it appropriate to offer to pay somebody to do your work or homework for you.

8. No indirect links

  • All links must link directly to the destination page. Do not use URL shorteners, referral links or click-trackers. Do not link to some intermediary page that contains mostly only a link to the actual page and no additional value.

For example, linking to some tweet or some half-hearted blog post which links to the page is not ok; but linking to a tweet with interesting replies or to a blog post that does some extra analysis is.

Udemy coupon links are ok: the discount adds "additional value".

9. Do not promote illegal or unethical practices

  • Do not ask for help doing anything illegal or unethical. Do not suggest or help somebody do something illegal or unethical.

This includes piracy: asking for or posting links to pirated material is strictly forbidden and can result in an instant and permanent ban.

Trying to circumvent the terms of services of a website also counts as unethical behavior.

10. No complete solutions

  • Do not ask for or post a complete solution to a problem.

When working on a problem, try solving it on your own first and ask for help on specific parts you're stuck with.

If you're helping someone, focus on helping OP make forward progress: link to docs, unblock misconceptions, give examples, teach general techniques, ask leading questions, give hints, but no direct solutions.

See our guidelines on offering help for more details.

11. Don't ask to ask.

  • Ask your questions right here in the open subreddit. Show what you have tried and tell us exactly where you got stuck.

We want to keep all discussion inside the open subreddit so that more people can chime in and help as well as benefit from the help given.

We also do not encourage help via DM for the same reasons - that more people can benefit

12. Low Effort Questions

  • Do not ask easily googleable questions or questions that are covered in the documentation.

This subreddit is not a proxy for documentation or google.

We do require effort and demonstration of effort.

This includes "how do I?" questions

13. No AI (chatGPT etc.) generated messages/comments. No questions about chatGPT/AI generated code.

  • Such posts/comments will be removed without warning and the poster of ai generated content will be instantly banned.

/r/learnprogramming

4,080,645 Subscribers

1

Is a user's displayName a reliable way to store usernames when using Firebase?

I'm currently creating a simple social media platform. Each user in the application will have a unique username, which will be stored in a MySQL database. I'm just stuck choosing between two options:

  1. I can create a React Redux slice to store the current user, and whenever I need to display the username anywhere, I can simply use the username that I recieve from React Redux.

  2. I can take the displayName from the Firebase authenticated user, and display that name as the username.

The only difference between these 2 options really is that the React Redux method just adds a little bit more complexity. Obviously whenever the user creates a post or comment, I will be searching the database for their username, but just for user's frontend, is it a viable method to use displayName? Is the user able to change this property?

1 Comment
2024/04/08
04:29 UTC

1

Need a leetcode buddy , Lang : java

Hey, i'm preparing for my interviews/jobs and graduating this may. Like a leetcode session 2hours/day.
we can discuss some interesting problems and can get good at cp and programming. If interested dm me.
Lets connect.
Thanks

1 Comment
2024/04/08
04:08 UTC

1

MVC architecture for a music application

Hi, I'm making a music website for a college project, and currently I'm drawing class diagram for MVC and I have some questions. I have read that one controller can have multiple views, so I was thinking of having a UserController to handle views like SignUp, LogIn, ChangeProfile, etc. When I look at the Internet on how to implement this, most of the time I would only see the example where they use 1 controller - 1 view. So my questions are, for example in the view for SignUp, giving that the attributes are username, password, email, verificationCode, what should the methods in this view class be? Since controller have many views, how would it know what views it is dealing with, how would view know which controller it sending user input to? And how would controller update the view after that. I'm asking these questions because I haven't really built real application using MVC architecture before and some obvious things may not seem plausible to me. Thank you for you guys help.

1 Comment
2024/04/08
04:08 UTC

1

I need some help converting the following C code into MIPS code.

The following is the code I need to translate.

void swap(int v[], int k) {

int temp;

temp = v[k];

v[k] = v[k+1];

v[k+1] = temp;

}

void sort (int v[], int n) {

int i, j;

for (i = 0; i < n; i += 1) {

for (j = i – 1; j >= 0 && v[j] > v[j + 1]; j--) {

swap(v,j);

}

}

}

int main() {

int A[10] = {7, 42, 0, 27, 16, 8, 4, 15, 31, 45};

sort(A, 10);

return 0;

}

2 Comments
2024/04/08
04:04 UTC

1

how do i get into software engineer?

how do i get into software engineer?

seriously, i just graduated with bachelor in Tourism, and i wanted to be software engineer

do i need another bachelor? i'm willing to put in the hours and effort

5 Comments
2024/04/08
03:54 UTC

1

Help on what direction to go?

Hi there, I’ve recently started to learn how to code on my own and I enjoy it, however, I am quite lost on what direction to go!

Does anyone have any advice on what path to go down? As in web dev/app dev/what languages to learn/etc.

I truly appreciate anyone’s help and am open to trying different paths, I’d just like some input from more experienced people.

Thank you!

1 Comment
2024/04/08
03:49 UTC

5

In Python, what is the difference between a method and a function?

Title. I’m having a hard time understanding the differences.

12 Comments
2024/04/08
03:25 UTC

0

Free way of sharing program with other people?

I created a simple program that I want to share with other people for use, but the thing is that whenever I upload the files for the program on Google Drive or anywhere else, either the browser or antiviruses will detect the exe file as a virus and will refuse to download. From what I've been seeing online, I would need to do code signing for the program, but it would cost money to do so. I don't plan on charging people for the program, so I don't want to do that. Is there a way I could have the program up for use for people with no coding experience, whether it be online or whatnot? I would try to use Replit as a way to share the program, but the thing is that the program is meant to allow the user to copy and paste text into a text file so the program can read it to make calculations. On Replit, it doesn't allow the user to edit any files, even the txt file.

5 Comments
2024/04/08
03:20 UTC

1

Help getting started with IDE’s?

For context, I’m a CS student in my first year of CS classes. I’ve dabbled with scratch, swift playgrounds, and python but about half way in to my python bootcamp I decided it would probably be better to spend that time and effort getting the piece of paper while I was at it, because I genuinely enjoy it. I was hoping things like the ins and outs of IDE’s would be covered in my fundamentals class, but they aren’t. The class uses Java with an online and interactive textbook that’s great for teaching you Java and writing logic, but then for projects you’re just sent to download JDK, Netbeans, and given .jar and .java files to open and edit. Which is fine enough, I just feel like it would benefit me to know how to open and start a new project from scratch, how and where is the best way to save that file so I can open it on both my desktop & laptop, etc. Are there any resources anyone could point me toward to get a better grasp on things like that, rather than logic exercises?

8 Comments
2024/04/08
02:58 UTC

1

Education Advice

As you guys may know from my other posts, I have been self teaching myself python and basically programming. I’m currently in the middle of a hard dilemma.

S, im a 3rd year university student in japan currently majoring in environmental science (i know its nothing related to cs etc). However I started losing interest in my major and picked up programming early this year and I figured out that I wanted to be a software dev or any tech sector jobs in the future (after I finished my uni).

So basically the dilemma is that should I change uni and get a CS degree or shud i just finish my study in my current uni, while learning programming on my own, get the degree and hopefully got an intern and a job.

Any advice will be appreciated! Cuz im really lost on what to do. TIA

TL;DR Studying a different major in a japanese uni, but wanting to have a tech job in the future. Shud i change uni to get a CS degree or just muscle it through with self learning.

6 Comments
2024/04/08
01:00 UTC

3

Programming games

I want to tryout some programming games, so i can chill and play something which is still productive. The difficulty could be easy since I’m not even coding for a year.

Does anyone have some recommendations, and pls let it be something i can play on mac. And i’m not interested in CSS and HTML.

15 Comments
2024/04/08
00:44 UTC

13

What exactly do I need to make to get a job?

I've been learning how to code for about a year now, give or take. I'm learned JS and I know quite a bit about React from what I watch in tutorials but outside of this, I have no road since I don't go to college to learn programming and I have no idea as to what projects I'm supposed to do or how I would even go about getting a job. What projects are employers looking for? Or what technologies are the most relevant so I can build something using those. Do I need to go all out and learn MERN because I've heard people say that learning MERN isn't necessary if you're going in as a junior developer. If that's the case, I could theoretically already get a job, I just need to know what projects to build. Also, what is a portfolio? Is it just a site that links to all of my projects? Where do I apply? Just to LinkedIn? I have so many questions since I'm doing this all on my own and I don't know anyone who does coding. You can post below what projects you built to get your first job. Thanks in advance

30 Comments
2024/04/08
00:33 UTC

1

How to make the color of my Windows Title Bar independent of the Windows OS?

e.g. Windows OS has accents and Dark and Light Mode. I want to independently skin my window from the Operating System. How do?

Let's say this is mostly language agnostic, apart from interfacing with the Windows API, which begs the real question - is there an A PI to control this?

3 Comments
2024/04/08
00:29 UTC

1

Would love some constructive feedback!

I am working on an interactive website to act as a "portfolio" for my projects now and into the future. All done in CodeSpaces using HTML/JS/CSS. Would love to know what bad habits you may see, bad choices etc.

Website - Here is the link

Repo - Here is the link

I have been working on this for about 2-3 days now and have never touched HTML, CSS, or Javascript so please go easy on me. I would very much like constructive feedback.
Right off the bat I know that:

  1. Formatting is horrendous - different screen sizes alter the experience and needs to be fixed

  2. Formatting in general - weird spacings where there shouldn't be (again dependent on screen size)

  3. More depth and "cleanliness" on the different pages (and keep consistency)

  4. I know my code is messy and working on being more tidy in this area is a must (learned a few days in it is best to have separate files for separate pages and tasks. I started having everything on one and realized how bad and silly that was.

I know there may be too many elements going on at once. Each one is to try and demonstrate a different level of complexity (ie. the shapes when you hover over move, the Works page ideally those would be cards rotating of different projects etc.)

Again, I am new. I am still forming habits and developing skills so I know this first go is going to be garbage... but it's my garbage and I intend to improve it over time. :)

1 Comment
2024/04/08
00:21 UTC

1

personal project ideas for the community

Hello! I wanted to do a personal project that involves programming and circuitry (like Arduino) and will help like a group of people.

I am currently a high schooler so I don’t have access to a lot of expensive resources but I would like to learn more ways to apply my coding and circuitry knowledge to physical projects that are catered to a community (like high schoolers, elderly people, or even like a smaller group).

I am not sure if this is the right sub to ask for ideas but I hope to learn/do more! Thank you! :)

2 Comments
2024/04/07
23:55 UTC

2

Anyone want to review blog posts about cool algorithms?

I've written blog posts about Linear Congruential Generators and Lazy Cartesian Products. It's hard for me to know if they are understandable and readable for myself. If anyone DMs me, I'll send you the links and you can learn about some really cool algorithms. I think that if you've taken a couple of Python courses, you'll probably be able to follow them but also learn something.

3 Comments
2024/04/07
23:41 UTC

1

how to count the number of a specific string in 1 column of a csv where every column has a list?

It's a Series object like this, it's obtained from a csv file but [x,y] is just a string, not a list

0    [x]
1    [x,y]
2    [x,z]

I want the number of x,y,z. In this case it would be x=3, y=1, z=1

My end goal is to make a box plot with x,y,z as the categories and have my y axis display the count of how frequently each of x,y,z occurs, something like this

plt.bar(['x','y','z'], [#instert the count of x,y,z])

for anyone wondering, the solution was

df.str.split(',').explode().tolist()
3 Comments
2024/04/07
23:31 UTC

1

Analysing human to AI calls - sentiment analysis/other ML?

Hi,
If a customer is talking to an AI chatbot over the phone, I want to be able to pass them onto a human if they seem to be distressed or are struggling with communicating with the AI. I'm currently looking into 2 options:

  1. Sentiment analysis on raw text picked up through speech-to-text
  2. Non-verbal elements (volume, tone, talking speed etc...)

I don't know much about this stuff and unfortunately have no idea how to go about using non verbal elements.

Does anyone have any suggestions on what resources exist for implementing these?

Any help would be appreciated!
Thanks

2 Comments
2024/04/07
22:33 UTC

1

stuck on assembly language project

program should take integer inputs from user and once a 0 has been entered read back the lowest number entered besides 0.
I can't figure out whats wrong with my code

.data

prompt: .asciiz "Enter an integer : "

output: .asciiz "The smallest number is "

smallest: .word

.text

loop:

#get user input

la $a0, prompt

li $v0, 4

syscall

#store user input

li $v0, 5

syscall

move $t2, $v0

beqz $t2, exit

slt $t5, $t0, $t2

movz $t0, $t2, $t5

j loop

exit:

sw $t2, smallest # put $t1 into the label smallest

la $a0, output

li $v0, 4

syscall

lw $a0, smallest

li $v0, 1

syscall

#end program

li $v0,10

syscall

1 Comment
2024/04/07
22:09 UTC

2

Where can I ask a lot of questions?

I'm a beginner to web dev and I keep finding out random things while trying to make my own websites that don't make sense to me. I also feel that the things are so obvious that there is little info on the topic, and what I don't understand is kind of hard to describe when searching on google. Is there a website specifically for simple dumb questions or should I just get a coding teacher?

11 Comments
2024/04/07
22:00 UTC

4

How do I push my a github commit to a DIFFERENT branch in pycharm?

I am working in pycharm and have linked my github. I am fairly new to this particular set up, and I am working with others and so I don't want to mess it up.

  • I have a branch, B, that I am currently working on.
  • There is a branch, A, that is our main "dev" branch.

I want overwrite A with what I am currently doing in B.

What exactly do I do? I see all these different features but this is all a bit confusing.

6 Comments
2024/04/07
21:55 UTC

1

What services to use to create a shared session between users?

Hello,

I'm trying to build out a project by using C# / .NET Core + Vue for learning purposes. My idea is to create a .NET Web API to handle a shared session type of project where users can click create your own session to host or join someone's session.

When someone creates their own session, I can then generate a type of password or session ID that others can join in and they can see whos in the same session with them by displaying their name or user ID. I'm also learning Vue for the front end. My question is what kind of services provide what I'm looking for?

My best guess was maybe Firebase / Supabase for authentication but I guess I'm not entirely sure what to even google.
Thank you for your advice and tips, I appreciate it!

2 Comments
2024/04/07
21:49 UTC

2

Best way to deploy a simple python script to web?

So I have a python script that does web scraping using selenium then some simple processing, my idea is to you the web mobile app clips and to create a simple website that runs the python script on the backend. I would be the only one using this so i want to try and keep it free if possible, any services you guys can vouch for to allow me to do this?

3 Comments
2024/04/07
21:45 UTC

2

Help with a data extraction

Hello guys!

I've got a challenge at my university to build a model that extracts products from. 500+ furniture stores.

Here are the guidelines:"## Guidelines
A good approach that works well with such extraction problems is to create a NER (Named Entity Recognition) model and train it to find your entities (you have one entity, ‘PRODUCT’).
- In order to create such a model you need training data, you can also extract that from the input pages.
- Crawl ~100 pages from the list above & extract the text from it.
- Find a way to tag some sample products from these texts.
- Train a new model from the examples you just made.
- Use it to extract product names from some new, unseen pages.
Please use any programming language, toolset or libraries you're comfortable with or find necessary, especially if you know it will be better or more interesting.
We recommend using the Transformer architecture from the [**sparknlp**]874df20d1d77) library or the huggingface [**transformers**](  library."

I have little experience with web crawling. I`m not that scared about the NER part, rather then crawling the ~100 pages in order to train my model. I have tried to scrape with beautifulsoup but I don't know how to make it so I don't have to input manually the site selectors in order to get the correct product name.

If you have any suggestions, please let me know <3

1 Comment
2024/04/07
21:20 UTC

4

How to improve my problem solving?

I have noticed that a lot of mistakes that I make when working on programming problems just stems from me either over complicating the problem (example: adding a for loop when its actually not needed when dealing with arrays, or just something else silly).

The most of the time when I struggle so badly on a problem that I end up looking up the solution I just feel dumb because the solution was so much simpler than what I was trying to do.
How do I go about to improving this?

3 Comments
2024/04/07
21:01 UTC

1

Stuck with VSCodium, who can't find my libraries

I've been on this for an entire afternoon and am so done. idk if anyone can help me but idk what else to do. I truly have checked everywhere, including looking info both on vscode and codium, asking chatGPT, countless forums... the problem is just too specific, and codium too little used an supported. But I also simply don't want to use vscode, plain and simple, so I'm very stuck.

Here's the situation: I'm coding C++, Pop_OS 22.04, and am trying to use GTKmm for the first time. The way I currently have vsc set up is that I use the clangd extension for syntax editing and catching errors, and then i simply have custom build tasks that run "make" on my current folder to compile and link my project. Everything is in one folder and the project itself isn't very big, consisting of about 7 modules. But I do need GTKmm and that's my current problem: it's properly installed on my system and everything works perfectly if I run make from the project directory in the terminal. But if I try to run make on that same directory from vscodium, whether it's through my task or through a terminal, it gives an an error, bc it can't find GTKmm4:

project.cc:1:10: fatal error: gtkmm.h: No such file or directory 1 | #include <gtkmm.h> | ^~~~~~~~~ compilation terminated. make: *** [Makefile:14: simple.o] Error 1

Similarly, clangd is now rendered useless as it also cannot find the gtk header, and thus is constantely signaling errors where there are none. How can I solve this? I've gone as far as creating a copy of all the necessary .pc files and added them to a different pkgconfig folder (because VSCodium kept telling me it was unable to find the ones my terminal accesses just fine), as well as making sure to include the folder containing gtkmm's header under c_cpp_properties.json (tho i can't imagine this does anything, seeing as all I'm doing is running make?)

I simply don't know what else to do. It seems like vscodium just doesn't "see" (for lack of a better word) the folders that my terminal's makefile does. How can this be?

4 Comments
2024/04/07
20:26 UTC

2

Help with returning the results of a Swagger API on MS Visual Studio

I am trying to call an API from Swagger on Microsoft Visual Studio, but I am getting nothing returned. The API is called CityReview, and it takes City as an input to run a stored procedure on MS SQL Server. I am attempting to run the API by going to /AToday?City=Chicago but nothing is returning. HTML

@ page
@ model RateMyAsthma.Pages.ATodayModel
@{
    var City = HttpContext.Request.Query["City"];
}
<head>
//...
</head>
<body>

            <h1>Today reviews for:</h1>
            <h2 id="cityName" style="visibility: hidden;"></h2>
            <div id="cityRating" style="visibility: hidden;"></div>
            <script type="module">
                displayCityReviews(@City);
            </script>

</body>

JavaScript

async function displayCityReviews(City) {
    const response = await fetch(`https://localhost:7070/api/CityReview/${City}`)
    const data = await response.json();
    document.getElementById('cityName').innerHTML = data[0].city;   
    document.getElementById('cityName').style.visbility = "visbile";
    document.getElementById('cityRating').innerHTML = data[0].rating;
    document.getElementById('cityRating').style.visbility = "visible";
}
1 Comment
2024/04/07
20:27 UTC

1

Suggestions?

Hi people, I want to learn SFML. Any suggestions?

1 Comment
2024/04/07
20:26 UTC

1

Problems with image in customtkinter

I have problems opening an image from binary data and displaying it in a CTk window. I recieve "pyimage3 doesnt exist" error.

def flags():

global gamew

global play

global capital_entry

global button

global started

started=0

play=True

gamew=ctk.CTk()

gamew.protocol("WM_DELETE_WINDOW",close_game)

gamew.title("Flags")

gamew.geometry("450x450")

label=ctk.CTkLabel(gamew,text="Flags",text_color="white",corner_radius=10,height=10,width=400)

label.configure(font=("TkDefaultFont", 50))

label.pack()

button = ctk.CTkButton(gamew, text="Start",command=enter_flags,width=200,height=40)

button.pack(pady=30)

gamew.mainloop()

def b_recv():

len=my_socket.recv(10).decode()

return my_socket.recv(int(len))

def enter_flags():

global gamew

global s_button

global started

global label

global ans

global image

global photo

started += 1

if started == 1:

button.destroy()

send("flags")

binary_data = b_recv()

try:

# Create the PhotoImage object

image = Image.open(BytesIO(binary_data))

photo = ImageTk.PhotoImage(image)

# Create a label and display the image

label = ctk.CTkLabel(gamew, image=photo)

label.image_ref = photo # Keep a reference to prevent garbage collection

label.pack()

except Exception as e:

print("Error loading image:", e)

3 Comments
2024/04/07
20:18 UTC

3

Swift PlayGrounds - Append Item to Array Help

Keep getting the “Type ‘()’ cannot conform to ‘View’” error at ’numbers.append(4).’ What am I doing wrong here?

import SwiftUI
struct ContentView: View { var body: some View {
    var numbers = [1, 2, 3]
    numbers.append(4)

    VStack {
        if numbers.count == 3 {
            Text("Happy birthday!")
        } else {
            Text("Not Happy Birthday 😔")
        }
    }
}

}

6 Comments
2024/04/07
20:00 UTC

Back To Top