Skip Navigation
User banner
Learn Programming
Learn Programming
Members 1.6K
Posts 98
Active Today 2
  • Please read: community rules

    0
  • Any alternative for libevdev for controller handling on Linux?

    I know stuff like SDL and RayLib exists, but I already have my own X11 and Windows API stuff working, and otherwise those libraries like to obscure things from the user in the name of "ease of use", sometimes even missing features (force feedback and proper XInput are the ones that are often skimped out on for whatever reasons, and only SDL has them to my knowledge). While I'll implement libevdev eventually, it has the issue of needing access to the devices.

    While I found some reference to game inputs in X11's input extensions, I cannot find any user guide on them, since they're instead pointing me to SDL and co.

    1
  • Where can I find OpenGL tutorials that are known to be not generated by AI?

    I not only have hard time finding tutorials, but even if I do, I have a hard time getting them to not crash, let alone working. I don't know what's the reason, but I have a suspicion that some of these are now AI generated, hence the issues of them not working or outright crashing.

    I know newer APIs exist. They're way too complicated for my usecase.

    I've heard about WebGPU, but I don't want to touch it with a 10 meter long pole, due to its name. I'll have a lot of time convincing people that WASM isn't a web-only thing, and me using it for scripting won't mean my game engine is either Web-based, nor that it has any Web-capability, and I only stayed with it due to my inability of finding a well-supported scripting VM without "Web" in its name.

    If you ask: My game engine is currently using CPU rendering, and used to use SDL2 for displaying the output. I decided to move away from them. Managed to find some basic OpenGL tutorials when I first write my replacement for the SDL2 window handling. The Windows API is well documented on that regard, I even was able to find X11 documentations (this one even required me to find code already implementing such things, since documentation on some features was scarce). However, it somehow became increasingly difficult to find them.

    3
  • What is wrong with my shaders?

    Vertex:

    ```glsl #version 120

    void main() { gl_TexCoord[0] = gl_MultiTexCoord0; gl_Position = ftransform(); } ```

    Fragment:

    ```glsl #version 120

    uniform sampler2D tex;

    void main(){ vec4 texSlmp = texture2D(tex, gl_TexCoord[0].st); gl_FragColor = vec4(texSlmp.r, texSlmp.g, texSlmp.b, 1.0); } ```

    All I get with this is a black screen.

    I cannot seem to get tutorials for anything older than OpenGL 3.3, and for my usecase, I could go lower, except everyone tells me "OpenGL is obsolete, try Vulkan instead".

    gl_TexCoord[0] seem to be all zeros if I modify the fragment shader to try to output gl_TexCoord[0].st, so its content would be displayed as color information, which I did for a different test. Also I can't find anything on how do I "pass" textures (or other values) to the shaders in the official docs, nor any of the tutorials I could find explains how that actually works.

    EDIT: Target version is OpenGL 2.1/GLSL 1.20

    EDIT2: I updated the shaders to GLSL 3.30, but then my DuckDuckGo search results suddenly turned bad about the subject, and in/out still doesn't work between vertex and fragment shaders (values taken from the vertex shader is all zero).

    6
  • Is it better to check if a file exists before trying to load it, or to try to load it, and catch the error and move on?

    For context, I am trying to do a save system for a game.

    16
  • Why Go Interfaces Are the Remarkable Secret to Clean Code Mastery

    2
  • Unlock the Secrets of Web Storage APIs in JavaScript

    Learn about Local Storage, Session Storage, Cookies, and IndexedDB with working code examples

    0
  • What are some easy-to-solve errors you spent awhile fixing?

    I just spent an hour searching for how I could have gotten an

    > Uncaught TypeError: Cannot set properties of null

    javascript. I checked the spelling of the element whose property I was trying to set and knew that element wasn't null because the spelling was the same in the code as in the HTML. I also knew my element was loading, so it wasn't that either.

    Turns out no, the element was null. I was trying to set " NameHere" when the element's actual name was "NameHere".

    Off by a single space. No wonder I thought the spelling was the sameβ€”because all the non-whitespace was identical. (No, the quotation marks slanting in the second NameHere and being totally vertical in the first NameHere wasn't a part of the error, I am typing them all vertical and either Lemmy or my instance is "correcting" them to slanted for the second NameHere. But that is also another tricky-to-spot text difference to watch out for!)

    And what did not help is that everywhere I specifically typed things out, I had it correct with no extra spaces. Trying to set " NameHere" was the result of modifying a bunch of correct strings, remembering to account for a comma I put between them, but not remembering to account for the space I added after the comma. In short, I only ever got to see " NameHere" written out in the debugger (which is how I caught it after like 30 repeats of running with the debugger), because everywhere I had any strings written out in the code or the HTML it was always written "NameHere".

    I figured I'd post about it here in case I can help anyone else going crazy over an error they did not expect and cannot figure out. Next time I get a similar error I will not just check spelling, I'll check everything in the name carefully, especially whitespace at the beginning and end, or things one space apart being written with two spaces instead. Anyone else have a similar story to save the rest of us some time?

    17
  • github.com GitHub - free-news-api/news-api: Top Free News API Comparison

    Top Free News API Comparison. Contribute to free-news-api/news-api development by creating an account on GitHub.

    GitHub - free-news-api/news-api: Top Free News API Comparison
    0
  • I don't grok repositories and services and where's the cut-off point for them

    I understand the basic principle but I have trouble determining what is the hard line separating responsibilities of a Repository or a Service. I'm mostly thinking in terms of c# .NET in the following example but I think the design pattern is kinda universal.

    Let's say I have tables "Movie" and "Genre". A movie might have multiple genres associated with it. I have a MovieController with the usual CRUD operations. The controller talks to a MovieService and calls the CreateMovie method for example.

    The MovieService should do the basic business checks like verifying that the movie doesn't already exist in the database before creating, if all the mandatory fields are properly filled in and create it with the given Genres associated to it. The Repository should provide access to the database to the service.

    It all sounds simple so far, but I am not sure about the following:

    • which layer should be responsible for column filtering? if my Dto return object only returns 3 out of 10 Movie fields, should the mapping into the return Dto be done on the repository or service layer?

    • if I need to create a new Genre entity while creating a new movie, and I want it to all happen in a single transaction, how do I do that if I have to go through MovieRepository and GenreRepository instead of doing it in the MovieService in which i don't have direct access to the dbcontext (and therefore can't make a transaction)?

    • let's say I want to filter entries specifically to the currently logged in user (every user makes his own movie and genre lists) - should I filter by user ID in the MovieService or should I implement this condition in the repository itself?

    • is the EF DbContext a repository already and maybe i shouldn't make wrappers around it in the first place?

    Any help is appreciated. I know I can get it working one way or another but I'd like to improve my understanding of modern coding practices and use these patterns properly and efficiently rather than feeling like I'm just creating arbitrary abstraction layers for no purpose.

    Alternatively if you can point me to a good open source projects that's easy to read and has examples of a complex app with these layers that are well organized, I can take a look at it too.

    10
  • How to go from writing code that works to writing efficient, clean code and following good practices?

    Besides some of the very, very obvious (don't copy/paste 100 lines of code, make it a function! Write comments for your future self who has forgotten this codebase 3 years from now!), I'm not sure how to write clean, efficient code that follows good practices.

    In other words, I'm always privating my repos because I'm not sure if I'm doing some horrible beginner inefficiency/bad practice where I should be embarrassed for having written it, let alone for letting other people see it. Aside from https://refactoring.guru, where should I be learning and what should I be learning?

    28
  • Classes and objects. Just started learning, working in python.

    So I have struggled with classes and objects but think I'm starting to get it...? As part of a short online class I made a program that asked a few multiple choice questions and returns a score. To do this there are a few parts.

    1. Define some inputs as lists of strings ((q, a), (q2, a2),...). The lists contain the questions and answers. This will be used as input and allows an easy way to change questions, add them, whatever.

    2. Create a class that takes in the list and creates objects - the objects are a question and it's answer.

    3. Create a new list that uses that class to store the objects.

    4. Define a function that iterates over the list full of question/answer objects, and then asks the user the questions and tallies the score.

    Number 2 is really what I am wondering about, is that generally what a class and object are? I would use an analogy of a factory being a class. It takes in raw materials (or pre-made parts) and builds them into standard objects. Is this a reasonable analogy of what a class is?

    4
  • withcodeexample.com Top Javascript Coding Round Questions For Beginners - 1

    Top JavaScript coding round questions for beginners: Reverse a string, check palindrome, find largest number in array, and calculate factorial.

    Top Javascript Coding Round Questions For Beginners - 1
    0
  • Making a database identifier unique per user?

    Let's say I am making an app that has table Category and table User. Each user has their own set of categories they created for themselves. Category has its own Id identity that is auto-incremented in an sqlite db.

    Now I was thinking, since this is the ID that users will be seeing in their url when editing a category for example, shouldn't it be an ID specific only to them? If the user makes 5 categories they should see IDs from 1 to 5, not start with 14223 or whichever was the next internal ID in the database. After all when querying the data I will only be showing them their own categories so I will always be filtering on UserId anyway.

    So let's say I add a new column called "UserSpecificCategoryId" or something like that - how do I make sure it is autogenerated in a safe way and stays unique per user? Do I have to do it manually in the code (which sounds annoying), use some sort of db trigger (we hate triggers, right?) or is this something I shouldn't even be bothering with in the first place?

    18
  • Just started learning python - question about types of statements.

    Just started as in, I'm about an hour into a 4 hour intro video. Seeing two basic ways of manipulating things and don't understand the difference.

    If I want to know the length of a string and I just guess at how to do it I would try one of these two things,

    1. Len(string)
    2. string.len()

    What is the difference between these types of statements? How do I think about this to know which one I should expect to work?

    20
  • Struggling with learning testing

    I am really struggling to include proper testing practices into my code and would appreciate any advice on how to get going. I work in web dev so my I am interested in how to properly implement a suite of tests for websites and incorporate into it a CI/CD pipeline.

    I find a lot of tutorials teach the most basic types of unit tests, 90% of the time most instructors teach how to write a test to sum two numbers, but when it comes to writing real unit test I find it hard to know what I should be testing. I learnt some cypress and have gotten better at including end-to-end testing because that makes more sense to me, but I still feel I am way short of where I should be.

    How can I move forward? Did anyone else find themselves in my situation and find good resources to help them learn? Thx

    6
  • People often say they can't think of any ideas to practice coding. Maybe try this suggestion for some inspiration.

    I asked some LLM chatbots to give me some silly ideas to try. Below are a few of my favorite responses.

    ---

    From Perplexity.ai

    > Six Degrees of Wikipedia: Creating a program that finds the shortest path between two random Wikipedia articles using graph traversal algorithms. This applies graph theory concepts to explore connections in a large knowledge base.

    > Emoji Encryption: Using hash tables and cryptographic algorithms to create an encryption system that converts text to emojis. This could be an interesting way to explore cryptography concepts in a fun, visual way. ---

    From Gemini.google.com

    > Procrastination Station: This website creates increasingly elaborate and ridiculous tasks to distract you from what you actually need to do. Dishes? Nah, fold your socks into origami cranes!

    > Dramatic Password Validator: Forget boring error messages. This program rejects weak passwords with Shakespearean insults or movie villain monologues. ---

    From Chatgpt.com

    > 3. Time Travel Email Service: Build a data structure that allows you to send emails to yourself in the past, with time complexity considerations that are totally ignored because it’s time travel.

    > 4. Mood-Driven Random Number Generator: Implement an algorithm that generates random numbers based on the mood of the user, using sentiment analysis on real-time facial expressions.

    3
  • Cleanest way to manage unique objects in C++?

    Hello, I would like to store these http headers in classes:

    Host: developer.mozilla.org User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:50.0) Gecko/20100101 Firefox/50.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate, br Referer: https://developer.mozilla.org/testpage.html Connection: keep-alive Upgrade-Insecure-Requests: 1 If-Modified-Since: Mon, 18 Jul 2016 02:36:04 GMT If-None-Match: "c561c68d0ba92bbeb8b0fff2a9199f722e3a621a" Cache-Control: max-age=0

    As you can see, many have unique data (numbers, strings, list of strings). I would like to:

    • store a header name
    • store list of possible options for that header (or store if it's a number)
    • read an input header and store and return the found option / list of options / number
    • make adding new types of headers as easy as possible

    Is making hard coded classes for every type of header viable? How would this be done in the cleanest way possible?

    9
  • visualstudiomagazine.com Open Source 'Eclipse Theia IDE' Exits Beta to Challenge Visual Studio Code -- Visual Studio Magazine

    Some seven years in the making, the Eclipse Foundation's Theia IDE project is now generally available, emerging from beta to challenge Microsoft's similar Visual Studio Code editor, with which it shares much tech.

    Open Source 'Eclipse Theia IDE' Exits Beta to Challenge Visual Studio Code -- Visual Studio Magazine

    The project home page.

    The Github

    Looks just like VS Code and I think it's still built on electron so take that as you will.

    7
  • How do I learn to optimize my code better?

    I'm trying to make minesweeper using rust and bevy, but it feels that my code is bloated (a lot of for loops, segments that seem to be repeating themselves, etc.)

    When I look at other people's code, they are using functions that I don't really understand (map, zip, etc.) that seem to make their code faster and cleaner.

    I know that I should look up the functions that I don't understand, but I was wondering where you would learn stuff like that in the first place. I want to learn how to find functions that would be useful for optimizing my code.

    19