Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] refactor, bug fix, optimization #60

Closed
wants to merge 31 commits into from

Conversation

Rudxain
Copy link
Contributor

@Rudxain Rudxain commented Dec 20, 2022

  • removed some unused vars (IDK if there are more)
  • performance improvements
  • avoids race condition
  • raise clearly understandable Exception if DE is unrecognized
  • etc...

What I mean by "race condition", is because of os.getenv("XDG_CURRENT_DESKTOP"). Each call to os.getenv makes a system call, which is slow by itself, and prevents auto-optimization by CPython. Each system call has enough latency, that if a process mutates XDG_CURRENT_DESKTOP at the right time, it can prevent all conditional branches in the if ... elifs from being executed

@Rudxain
Copy link
Contributor Author

Rudxain commented Dec 22, 2022

I'll convert to draft, because I forgot to fix the color-scheme for non-green themes

@Rudxain Rudxain marked this pull request as draft December 22, 2022 22:03
@Rudxain Rudxain marked this pull request as ready for review December 26, 2022 22:49
@mtwebster
Copy link
Member

Cinnamon was deliberately using a dark theme with a light Gtk theme, but these issues are rendered more or less moot by linuxmint/cinnamon@791ee48, where you'll now be able to quickly choose a light/dark/mixed theme.

It looks like a commit related to that Cinnamon work is blocking this from being merged - if you want to rebase (and leave the Cinnamon theme as is in change_color(), I'll merge the other refactoring/cleanup work.

Thanks

@Rudxain Rudxain changed the title refactor + bug fix refactor, bug fix, optimization Mar 21, 2023
@Rudxain Rudxain marked this pull request as draft March 21, 2023 20:28
@Rudxain
Copy link
Contributor Author

Rudxain commented Mar 21, 2023

I realized there's some more refactoring to do. Please don't merge (yet)

I don't have much time right now, but I'll probably finish it this week (or the next)

@mtwebster
Copy link
Member

I think it's admirable the effort you're putting in here and don't want to be discouraging, but this is completely overboard.

I was ok merging what you had done minus the theme changes, but I don't want the thing rewritten, sorry. It's a simple program that works fine for its intended use, and has the potential to change greatly from one Mint release to the next. All this is doing is increasing the potential for new regressions. I think it's actually making the code more difficult to read as well.

We have a lot of repos and I wouldn't mind seeing more contributions and bugfixes, but before attempting something like a major rewrite, I would suggest opening a discussion about it first.

@mtwebster mtwebster closed this Mar 22, 2023
@Rudxain
Copy link
Contributor Author

Rudxain commented Mar 22, 2023

@mtwebster , ok, so, should I open a discussion now? Which changes were "too much"? I could revert them

@mtwebster
Copy link
Member

You originally were cleaning up repeated calls to get the desktop environment, and other cleanup. That's fine - if you want to pare it down to those again, we can reopen this.

  • we don't need typing. There's not enough going on here for that to matter and I'm not sure it's compatible in LMDE5 (python 3.9).
  • renaming imports - subp_call vs subprocess.call etc..., apt_Cache.. I've never seen this done to such a degree, and I think it harms readability - there's no need to shorten stuff like this.
  • moving strings into constants, enums.. there's not enough code for this to help at all, they're better off at their point of use. When you're working with 1000's of lines of code and re-using strings a lot, it starts to make more sense to do this.

I'm not saying I'm against optimizations, but for nearly all of our gui programs (mintwelcome, mintsources, etc..) readability counts far more than efficiency or making use of python's latest features.

We also have to be careful to maintain compatibility with our debian-based distro - LMDE, which I mentioned only has python 3.9. This is pretty much always going to be the case, as we don't control the parent distros' releases and package versions, so we keep mostly to vanilla code as far as python goes.

Last, smaller PRs are better. They're easier to test - here, you changed so much, I dreaded having to review and test it (and I'd have to do it on all three desktops). Your initial PR was easy to review, as it was focused. It's easy to get carried away (I'm as guilty as anyone). You're also a new contributor and I'm much more careful and critical than with people who've been contributing for months and years.

As for discussion - I guess that's not the right thing to say, you definitely don't need to 'ask' to work on something - doing what's enjoyable for you is the most important thing.

@mtwebster mtwebster reopened this Mar 23, 2023
@Rudxain
Copy link
Contributor Author

Rudxain commented Mar 23, 2023

if you want to pare it down to those again, we can reopen this.

I agree 👍

  • we don't need typing. [...] I'm not sure it's compatible in LMDE5 (python 3.9).

oh... I forgot about that. I'm sorry

  • renaming imports [...] I think it harms readability - there's no need to shorten stuff like this.

Ok, I'll keep the names 1-to-1 (. -> _)

  • moving strings into constants, enums..

Yep, I think the enums were unnecessary.

there's not enough code for this to help at all, they're better off at their point of use.

For most vars, yes. But stuff like DEFAULT_COLOR is very useful if we want to replace "green" with "aqua"/"blue" in the future. Imagine using find&replace, or worse, manual writing, to replace just 1 color.

It also helps with semantics. Instead of being a hardcoded "green", it's whatever DEFAULT_COLOR contains.

When you're working with 1000's of lines of code and re-using strings a lot, it starts to make more sense to do this.

That's what I did with the var I mentioned. But I agree that other vars (such as MMC) should be inlined.

I'm not saying I'm against optimizations, but for nearly all of our gui programs (mintwelcome, mintsources, etc..) readability counts far more than efficiency or making use of python's latest features.

ok, I'll try to maximize readability

smaller PRs are better. They're easier to test

I agree and "resonate" with this, lol. I understand

here, you changed so much, I dreaded having to review and test it (and I'd have to do it on all three desktops).

I'm sorry (again)

You're also a new contributor and I'm much more careful and critical than with people who've been contributing for months and years.

That's reasonable

As for discussion - I guess that's not the right thing to say, you definitely don't need to 'ask' to work on something - doing what's enjoyable for you is the most important thing.

ok, thanks

Rudxain added 7 commits March 23, 2023 19:58
I currently don't have access to my IDE. I'll revert all other changes later
`apt_Cache` seems readable enough. IDK what to do about it
`Final` is no longer an impediment, but this may increase cognitive load
Comment on lines +2 to +3
from os import path as os_path, getenv as os_get_env, system as os_system
from subprocess import call as subprocess_call, check_output as subprocess_check_output, Popen as subprocess_Popen
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like I said, I do not want imports renamed - how is os_get_env an improvement over os.getenv?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did that for 2 reasons:

  • Importing a specific module, rather than a collection of modules is (usually) good practice
  • The prefix is useful to remember the "parent module" (I'm not sure if this is the correct terminology)

Should I import the parent module (original), or remove the prefix (no as rename)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Importing a specific module, rather than a collection of modules is (usually) good practice

This is meant to discourage using something like from foo import *, so you don't up with unexpected global namespace collisions. It's not intended to be used the way you're using it.

There's no reason to use 'os_get_env' over 'os.getenv', or anything in the os module, for that matter. I'll do it if I'm using just a single function from ridiculously_long_module_name, or if I'm repeatedly using math.pi, it looks cleaner to maybe from math import pi as PI.

You should just import modules and use them normally for the most part.

A bit of info:
https://google.github.io/styleguide/pyguide.html#22-imports
https://peps.python.org/pep-0008/#imports

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is meant to discourage using something like from foo import *, so you don't up with unexpected global namespace collisions. It's not intended to be used the way you're using it.

There's no reason to use 'os_get_env' over 'os.getenv', or anything in the os module, for that matter. I'll do it if I'm using just a single function from ridiculously_long_module_name, or if I'm repeatedly using math.pi, it looks cleaner to maybe from math import pi as PI.

You should just import modules and use them normally for the most part.

Fair enough 👍. Since readability is more important than performance, and the Py runtime is very likely to optimize it, and importing 1 parent module pollutes less the global namespace than multiple modules, then it's safe to conclude that it's better not to use my "prefix approach".

A bit of info: https://google.github.io/styleguide/pyguide.html#22-imports https://peps.python.org/pep-0008/#imports

Thanks for the links! I'll read them later. I'm busy IRL

Comment on lines +5 to +6
from gettext import install as get_text_install
from gi import require_version as gi_require_version
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same - we're using these methods once, why rename them?

locale.bindtextdomain("mintwelcome", "/usr/share/linuxmint/locale")
locale.textdomain("mintwelcome")
get_text_install("mintwelcome", "/usr/share/linuxmint/locale")
from locale import gettext as _, bindtextdomain as locale_bind_text_domain, textdomain as locale_text_domain
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same...

Comment on lines +49 to +50
from platform import machine as platform_machine
from apt import Cache as apt_Cache
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

@clefebvre clefebvre changed the title refactor, bug fix, optimization [WIP] refactor, bug fix, optimization Nov 27, 2023
@Rudxain
Copy link
Contributor Author

Rudxain commented Feb 7, 2024

Closing as stale.

My temporal bandwidth is very thin now. And I'm no longer a Mint user since many months ago. So I no longer have personal motivation to contribute to these projects. I'm sorry for letting the community down :(

I hope other people continue contributing to these projects, since LM is a decent OS, NGL

@Rudxain Rudxain closed this Feb 7, 2024
@Rudxain Rudxain deleted the patch-2 branch February 7, 2024 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants