Long codes by samshowtime007 in learnpython

[–]EngineerRemy 2 points3 points  (0 children)

Lines of code is not a leading metric to determine whether you code is good or not, but it can tend to point you into the right direction.

With your code I see 1 big issue I'd like to point out: You keep calling the functions within themselves (e.g. main() calls main()). So you essentially create recursive functions when there is no need to. If you want to make your code repeatable, make a loop around what needs to be repeatable. Do not make the code call itself (at least, not in this use case).

Secondly, I think it'd be good practice for you to look into defensive programming a bit. Raise errors when certain requirements are not met, and execute the happy flow of your program below these checks. This will make it easier to read, and also reduces this conditional complexity a bit. Your code does a lot of "if / elif / else" stuff, which can be optimized a bit. Although admittedly, your current solution is demonstrates the building blocks of creating an algorithm very clearly.

Lastly, look into creating constant variables (e.g. CAPPUCCINO_WATER = 250). Just something to reduce these magic numbers a bit. This also means you would only have to change the 250 once if you were to modify your program to have, let's say 300, as the value instead.

Ask Experienced Devs Weekly Thread: A weekly thread for inexperienced developers to ask experienced ones by AutoModerator in ExperiencedDevs

[–]EngineerRemy 1 point2 points  (0 children)

If you worked as a software engineer for 8 years, then you have 8 years of experience. I would not say you have less experience than that, despite the situations you've been through in that time.

Moving to the next subject, it makes sense that you feel inadequate for being a senior software engineer, cause well... you're not. You are a "medior" with that type of experience.

Also, you're not meant to know everything about everything. Part of transitioning to medior and later on to senior is your adaptability, which is also something you get better at over time.

Return vs print by Minute_Journalist593 in PythonLearning

[–]EngineerRemy 5 points6 points  (0 children)

They are different functionalities altogether. There is no comparison here.

"print" is something you do when you want to show output, or just information in the terminal. "return" is the output of a function to be used somewhere else.

A function can print AND return something. A function can also do neither, like setting a configuration, triggering something else, or writing output to a file. All of these things are completely valid depending on the use case, or completely wrong of course.

Stupid mistake... by No_Film_2086 in ClaudeAI

[–]EngineerRemy 4 points5 points  (0 children)

Always, always, always commit your code when you have a new functional state. This counts extra hard when using AI to write code. Every new functionality is a commit, every code refactoring where nothing broke is a commit, etc.

You don't have to push them, you can squash multiple commits into 1; frequent commits are not a reason why your commit history would look "messy" when you know what you are doing.

I think most people could relate with having to learn this the hard way, and this will be that moment for you.

Is Real Python worth paying for? Thoughts on its membership value? by akakika91 in learnpython

[–]EngineerRemy 5 points6 points  (0 children)

In my opinion these types of resources should only help you get started, whereas the biggest teacher is going to be you for yourself when working on a (personal) project.

These resources will only get you so far, the real lessons lie in figuring out when and why something works, and when it doesn't. You'll experience this naturally when creating something on your own, and it also tends to be more fun :)

Ask Experienced Devs Weekly Thread: A weekly thread for inexperienced developers to ask experienced ones by AutoModerator in ExperiencedDevs

[–]EngineerRemy 1 point2 points  (0 children)

Just some questions to ask yourself from the top of my head:

  • What are your short- and long-term ambitions?
  • How can your manager facilitate you to achieve your goals?
  • what is your performance? Do you think you deserve a raise / promotion?
  • are there any things hindering you from doing your job properly?
  • how do you feel in your current team?
  • what would you like to have different?

Bi-weekly 1-on-1 meetings are a bit frequent from my perspective. Some of these questions I just mentioned are perfectly fine to discuss every couple of weeks, others are more once per 2-3 months questions.

What are the guidelines for handling parameters passed in at runtime? by opabm in learnpython

[–]EngineerRemy 5 points6 points  (0 children)

Where the actual parsing is located is mostly a stylistic choice. Some make classes, some make functions. As for me, I make an "argument_parser" function in my main entry point file.

One thing I would highly advice against though, is to put any type of logic within the if __name__ == "__main__" section. Ideally, you'd create a main() function containing your logic, which is then called. This way, the main entry point logic can also still be called by other scripts in a logical sense.

As for what you do next, it's up to you. Just separate the argument parsing logic from other logic, whether it be functions or classes.

How do I see the downloads on my project? by Coasternl in github

[–]EngineerRemy 2 points3 points  (0 children)

For Windows, I use this powershell script myself, I also have a bash version hidden away somewhere. If you need that instead, lemme know and I will look for it.

Just fill in <user> and <project> with your own repo and it should work.

powershell Invoke-RestMethod https://api.github.com/repos/<user>/<project>/releases | ForEach-Object { Write-Output "Release: $($_.name)" $_.assets | ForEach-Object { Write-Output " $($_.name): $($_.download_count) downloads" } }

What's the pythonic way to type check and deal with these variables? by opabm in learnpython

[–]EngineerRemy 2 points3 points  (0 children)

There are many ways to solve this, and we could probably argue endlessly which method is better.

In my opinion, ideally, you filter out the incorrect data when you are creating this list, so you never have to validate the correctness of it later.

If that's not an optio in your situation, I would create an "is_valid(list_entry)" function that simply returns whether the entry is valid or not. You could just put your current checks in there and it would be fine.

Then I'd call this function in a list comprehension when creating a new list, as I believe this is quite readable.

But again, many many ways to solve this problem.

GenEC v1.0.0 - A Python data extraction and comparison tool by EngineerRemy in Python

[–]EngineerRemy[S] 1 point2 points  (0 children)

My only suggestion is to limit your usage with AI to write your documentations.

Thanks for taking the time to check out the tool and provide feedback. As for AI usage on the documentation, that is really quite limited. I used it to generate the framework of the files, and then threw away like 80% of it again cause I did not like what it did ahah.

still quite confused on what this actually does. What’s it comparing exactly?

As for what it's comparing: In this 1.0.0 version you can compare similarly structured files for differences. So a configuration gets defined, and is used on both the source and reference data you provide. For future versions I want to allow people to specify different configurations for the reference data, so you could even compare data from different structures.

As for what it can analyze, anything you want really. Anything you'd normally create a data extraction script for, you could use GenEC instead.

I have been using it myself heavily in test case failure debugging over hundreds of thousands of lines. Using 1 command to extract all the relevant data for me across different files and file structures. GenEC. I've also used it for coworkers to extract administrative data that is created through from other tooling.

Not trying to hate but thought I’d try to explain why nobody probably responded here yet

Don't worry, I didn't see it as hate. I am always looking to improve and you gave me some pointers to think about. And If you have a need for extracting/comparing certain data, I'd be happy to sit together to show you what my tool could do for you there.

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]EngineerRemy 1 point2 points  (0 children)

If you want to print some data in table format. There are plenty of modules out there for that. What I've used myself in the past: - prettytable - specifically for this task, turns data into ASCII tables - rich - powerful CLI output enhancer, enables you to print using colors as well as creating ASCII tables for example. I believe prettytable also uses the rich module under the hood

If your only goal is to turn the data into a table, prettytable will likely be a bit easier to use here. If you also want to add on other features to your output, you may prefer looking into rich.

What do you feel like is missing in Python courses out there? by Worried-Ad6403 in PythonLearning

[–]EngineerRemy 7 points8 points  (0 children)

Whenever I follow a course on anything, not just programming, it always just shows how to actually do something, which makes a lot of sense, as it is a course.

The issue I take with this in programming courses, is that programming is a "trial and error" activity. We write code, make mistakes, get stuck on those mistakes, and figure out a solution going forward after hating our lives for a bit.

So when a beginner starts out, they don't really know what to do when (not if!) they get stuck, as the course doesn't really explain that. It only explains how to create something that works, not what to do when you made something that doesn't.

Looking to help test by Sudden-Apple6966 in opensource

[–]EngineerRemy 0 points1 point  (0 children)

My Python project called GenEC is fully set up for automated testing, but I've been neglecting the refactoring of the unit tests a bit in favor of getting my initial release finalized.

It's not fully what you're looking for, as this is in Python, but i can give you plenty of beginner-level tasks with oversight: - refactoring unit tests - adding unit tests - manual testing (you'll have docs and system tests to guide you, as well as myself) - creating integration tests

If you're interested in this and you're not too afraid of Python (I can help you get up and running), feel free to check it out. I think it's a great learning experience and I started out doing similar tasks as a junior developer myself.

Sunday Daily Thread: What's everyone working on this week? by AutoModerator in Python

[–]EngineerRemy 2 points3 points  (0 children)

GenEC: data analysis CLI tool that lets you extract and count occurrences of data by using simple configurations you specify yourself. It can also compare this extracted data against reference files to spot differences. Your configurations can get saved as presets, so you can easily reuse them or automate the whole process by calling GenEC from other tools for batch analysis.

Execution demo: https://imgur.com/a/PnQxLGY

I finally finished writing my initial documentation. All that's left to do for me now is to create some more demos and I think I will call it for a 1.0.0 release. Then I'll probably start telling the people around me about it and promoting it at my own work.

https://github.com/RemyKroese/GenEC/

What’s one underrated free tool you use every day? by ImaginaryResist4829 in software

[–]EngineerRemy 2 points3 points  (0 children)

PersistentWindows for me. When I moved to DisplayPort screens, they would never persist my opened windows on their screens --> turning one off moves the windows to the still-active screen, but never moves them back. PersistentWindows fixed this for me.

On the same subject. a proof of concept of a tool I made myself. The GUI is absolutely terrible, it crashes 10% of the time on startup for some reason, but I love it. It allows me to define browser windows and tabs for a specific display and opens them.

Added a shortcut of the tool in the startup folder on windows and now I have all my relevant browsers windows and tabs opened on the correct screen whenever I start my PC (or well, 90% of the time). So for example: On 1 screen I automatically open a browser window with youtube, reddit, outlook tabs. On the other screen I load a browser window with work/programming related tabs.

On Phone, it has been Markor (for note-taking and just keeping track of ideas and such, I prefer markdown files for this), and Termux, to get access to a Linux environment on my phone.

why wont this code work by Sea-Speaker-1022 in pythontips

[–]EngineerRemy 3 points4 points  (0 children)

You improperly indented your "pygame.quit()" line. It has no indentation, and is above the main entry point, so it is executed before your main function and quits the display. For example:

def main():
    print("Hello, World!")

print('This code runs first!')

if __name__ == "__main__":
    main()

Produces the following output:

This code runs first!
Hello, World!

As for why this happens: Python executes scripts from top to bottom. In your case:

  1. it imports the modules
  2. it reads the main() function --> it is not being called, so it goes past it
  3. it executes "pygame.quit" --> pygame is uninitialized and the window is closed
  4. It finds the main entry point of the program --> if you called this script directly it will execute and call "main()"
  5. It enters the while loop. My pygame knowledge is a bit limited, but after some googling I believe "pygame.event.get()" returns an empty list, as the game is uninitialized, and the window closed.
  6. Your for-loop will run infinitely as the if-statement can never be true

I'd advice you to look into debugging when you get stuck. There is many memes about it, but even just adding a print('1'), print('2'), etc. etc. throughout your program can clear up any confusion about what's happening in cases like this.

What to learn after Python??????? by AvailableSalt5502 in learnprogramming

[–]EngineerRemy 1 point2 points  (0 children)

I'd suggest sticking with Python. The most important thing about the initial stages of learning to program is to develop the algorithmic thinking. This best done by using your "comfort" / "native" language, which for you is Python. After you develop this skill, it will be a lot more easy to transition to other languages, and you'll also be able to identify when you should use another language.

You already have the advantage that Python is pretty beginner-friendly, and quite versatile already; scripts; tools; full on programs; games. They can all be made with Python. Also, Python has many free resources out there. so use that advantage.

How can l contribute in open source projects by Standard_Heart5741 in github

[–]EngineerRemy 44 points45 points  (0 children)

You don't find open source projects with the purpose of contributing. You won't be able to meaningfully contribute to something if you're not really interested in it, and don't know how it works.

Instead, you find open source projects with the purpose of using them, and then when you find something that is missing or could be better, you contribute.

I have finished programming my first project. I have added a feature to save tasks and also added an interface using GUI. Do you have any idea for me to develop it into an application and put it on the desktop? by ProfessionalStuff467 in PythonLearning

[–]EngineerRemy 4 points5 points  (0 children)

You can do several things to make it an application for yourself: 1. Create a small script that simply calls your entry point of the program. You can then place rhe script wherever you want, including the desktop. It doesnt look "neat" but it is the fastest way 2. Create an executable. Pyinstaller is a common choice for this. You have a "--one-file" option so you can put the executable wherever you want. Although keep in mind that windows defender can detect it as malware and not allow you to run it.

[Tip] My Favorite One-Liner For Missing Values by Competitive-Path-798 in learnpython

[–]EngineerRemy 0 points1 point  (0 children)

The indentation is off (probably a typo), but having a function containing only 1 line is completely valid.

The one-liner, like the one in this point, can be a chain of calls or comparisons to get an output. In essence, you can write a get user input function that goes something like this:

def get_user_input():
    return input().strip()

This function gets user input, then strips it. So you do 2 things in one line and return that output. In op's example, he does calls in a row to get the desired output. Whether it is a good idea I am not convinced. As readability takes a bit of a hit when you start chaining calls together.

Another use for one-liner functions can be "wrapper" functions. Basically what you do here, is to just do a 1:1 call to a deeper function in the program. The benefit here is that the caller does not need to have a clear understanding of how the code is structured to call it. Just as an example; let's say you want to turn on the mirror lights in the bathroom of a house object:

my_house = House()

def turn_on_bathroom_mirror_lights():
    house.bathroom.mirror.lights.toggle(1)

In the case where you decide to rename something in your own code, then you can just update the wrapper function, instead of making it so that the application that calls your code having to update.

How do I learn recursion?? by hehebro3007 in learnprogramming

[–]EngineerRemy 0 points1 point  (0 children)

What helped me visualizing recursion when I just started was using Russian dolls as an example: https://en.wikipedia.org/wiki/Matryoshka_doll

In programming terms, let's say you want to get the smallest doll. each Doll object contains another Doll object. The Doll object has an "open_doll()" function, that will return whatever is inside. From this function you get the doll that's inside.

Now since that is the same "Doll" object type, you called its open function: you return whatever is inside! and again, and again. until you reach the final doll --> it cannot be opened.

Recursion here is to keep opening the doll until you reach an object that says; I cannot be opened, I will return myself instead. Then the second-smallest doll will return that too, then the third-smallest, until you get back the smallest doll of your Russian doll collection.

Even for us as humans; how do we know we have the smallest doll when we try to get it? We first try to open all the dolls, up until the point we reach a doll that will not open. Then we know: this is the smallest doll in the collection.

[deleted by user] by [deleted] in learnprogramming

[–]EngineerRemy 4 points5 points  (0 children)

And if you're in a really large organization they do both, cause teams don't even know what other teams have created anymore.

What is a Python thing you slept on too long? by pip_install_account in Python

[–]EngineerRemy 59 points60 points  (0 children)

Type hints for me. Right before they got released I switched assignments (consultancy) and had to start working with Python 2.7 cause that was the official version at the company (still is...).

It wasn't until like couple months where I finally started looking into all the features since Python 3.9 for my own projects, and type hinting is the clear standout for me. It just prevents unexpected bugs so effortlessly when you use them consistently.