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
general remarks #1
Comments
that was fast |
i'm a well-known hater, so I gotta hate, right? |
Just gonna mention that the main reason this was open sourced was to get feedback/improvements on the pp algorithm itself. |
I know next to nothing about maths, sorry :). |
That's fine, and your contribution is definitely valuable. Just wanted to state our focus here in case it takes a bit of time to have these kinds of things addressed. |
Hi there, yup, most of the code has been written years ago and I did not bother getting it up to speed, since it "worked". There are some good finds and suggestions in your remarks as well, thanks a lot for your effort! Even if you are worried, feel free to make a PR with these changes. We/I won't pull it in without verifying it works. :) |
To go into your feedback in more detail. I agree with all points I do not explicitly mention. General:
Src/Shared/Config: Super old code, needs a rewrite anyway. I agree with your comments
Src/Shared/Core/Logger: Again, old code, needs to be refurbished. :)
Src/Shared/Core/StringUtil: Returning the non-const ref is done so that these function calls can be chained, rather than be performed in sequence. Looks more elegant to me, although, I admit, it does involve some (negligible) unnecessary overhead. Are there any serious ways this could break, which are not present when returning void? Src/Shared/Core/Threading:
Src/Shared/Network/DatabaseConnection: Again, horribly old code. Needs a rewrite or serious refactoring (on top of what it already received). Src/Shared/Network/QueryResult: Same as above. They belong together. |
My advice would rather be "replace
Okay, fair. Not sure why you're using brace initializers at time (i.e. there), though.
You can safely use
Really, it's up to you. Both have pros and cons (SEH exceptions are very much a WAT).
I don't think
Right. Sticking with the "take by value and move" is usually the 'simplest' thing to do. Only use
The non-confusing way to do this... Would be to take the strings by value :). Since a call is a rvalue, the compiler will do the move by himself (and often even optimize it out). Here's an example. I don't think it makes that much sense to take a mutable reference – just take by value and return a temporary. Also, the value version would allow |
Brace initializers were introduced with C++11, not 14, that's why I am using them. The rest of what you've written makes sense. I'd be more than happy to accept pull requests addressing this stuff. Otherwise, I'll probably do it myself eventually when I have a larger amount of free time somewhere in the future. Thanks again. |
There's no real reason to not use NB: It's only possible for |
When I say that "I don't feel confident enough", it mostly stems from the fact I have no Windows dev env. to work on, so... :P.
I gathered as much – I just mean "since you're not using the |
When talking about runtime complexity I was talking about the cost for each element, which indeed is O(1) in the case of reserve. (You allocate N elements in O(N) time.) The worst case you are describing (copying existing elements) still results in an amortized O(1) allocation cost per element due to a smart strategy about when and how to re-allocate. Note the "amortized". Even when taking into account copying of all existing elements! Fancy maths. ;) So yeah, complexity-wise |
As I said, it's just fine "not to care", and I don't know how big that vector is supposed to be :). I just wanted to make it explicit that the cost of |
The cost of moves / copys is included. See this. |
|
griwes: Did you even read what I wrote after the text you quoted? You are not providing a counterargument at all. |
@Tom94: I'm just pointing out, again, why you are spewing nonsense. |
Also lol, there's no tests - that makes refactoring impossible. |
@griwes the |
I'm going to post this comment here instead of opening a new issue because it is kinda general. I'm seeing a lot of arbitrary float values placed everywhere in the calculations of things. E.G. from Src/Processor/User.cpp lines 55-56
I know every one of the values in the source have been changed a lot in testing and are very precise, but having oodles of numbers without names makes it difficult to maintain, especially if you're unfamiliar with the code base. Using the example above, IMHO, it would be much easier to read if it simply was refactored to something like this:
I'm of the opinion that there should never be a naked number in your code, and I'm wondering if there was a specific reason for all these numbers aside from "never got around to it"? If there wasn't a reason, the next question would be: would you be comfortable letting us propose a naming system for these numbers to more easily balance the numbers in the future? |
i'm okay with adding named constants wherever possible. if you remove the WEIRD prefix you could probably post a PR and we'd be able to merge it in. you have to understand that while we did open source this, it wasn't originally written to be the "perfect" code base. you are welcome to help make it that way, but it isn't something we had the man hours allocated towards :). |
Awesome! Yeah that silly name was just to make a point. I would make something a bit more serious with the PR. Do you guys have an IRC or something set up so I can ask questions about specific numbers that I'm confused about when naming these constants? |
You can join us on slack https://osu.ppy.sh/p/slack |
I don't think named constants for every formula used in the calculations make sense. The example you gave is completely fine (except that I'd move the comment above the actual values being defined, since it does directly reference them, and that I'd define the values right before they are actually used, rather than at the top of the function). In the case of, for instance, Furthermore, it kind of obfuscates the volatile nature of the entire function. When balancing you don't necessarily just want to tweak constants. Usually you want to change the function itself. |
I guess that's a valid point. I'll just kinda keep making changes where it looks like it'll make sense and if it's too obfuscating then the PR can be revised. And perhaps the better solution to some of these formulas is just to add a descriptive comment about what each part of the formula does. |
Just pointing out that if you're using named constants be sure to use Also I have a opinion ( though probably not shared ) that all caps should only be used on preprocessor-related stuff and therefore even constants shouldn't be all caps ( because I hate all caps )
|
I'm not sure you're not overcomplicating things just for the sake of it here... |
Ignore the latter half if you will but really, |
It doesn't serve any purpose here. None of that is useful as a compile-time values. The whole "move values to constants" seems pretty moot to me |
Is that not a thing anymore?
|
they moved to discord |
oh, gotta change fast I guess. |
Actually, you're already using
I got to see that when I opened the file into vim ( So I ended up refactoring stuff pretty conservatively (I didn't touch the 2 parts that had windows line endings, say). |
I don't feel confident enough in writing a PR since there are no tests for me to run & check if I broke stuff.
Src/Shared/Config
configVariables.h
(don'tifndef
there)..inl
is a widely-used extensionclass A { ~A() = default; };
)fopen/fseek/ftell
/etc, but maybe that's for performance reasons? (Even then, you should try to use some other construct to get RAIIfclose
)return;
after athrow;
std::isspace
std::strchr
, i.e.:std::strchr("aeiouy", c) != nullptr
NULL
. usenullptr
.strcmp
. Usestd::string
.delete[]
).sizeof(char)
is 1, as per standard (sizeof
returns the number of chars you can stuff in one type... so it's always gonna be 1 for char)Src/Shared/Core/Active
std::make_unique
, use it (no big deal anyways).foo == false
is better expressed as!foo
.catch (...)
and assigning the exception, inside of using your destructor withstd::uncaught_exception(s)
(the behavior of either is very different, and the second one is C++17 only)? The problem is that this is dangerous... on windows, you can catch a lot more than you might first except if SEH exceptions are enabled - that includes access violations...NULL
; usenullptr
std::rethrow_exception
is dead code /!\Src/Shared/Core/Exception
Src/Shared/Core/Logger
std::string&&
to forward it. Either do that, andstd::move
, or just do it the "simple" way: take it by value (and then move it).CLog::Log
takes the text by rvalue reference, but then copies the value inside the lambda. If you enabled C++14, take it by value and use[Text=std::move(Text)]() { ... }
to move it inside the lambda.auto a = std::string{};
really is juststd::string a;
sizeof(char)
is 1.Src/Shared/Core/StringUtil
Src/Shared/Core/Threading
L N M
makes it pretty hard (for me) to reason through it. I'm not sure you couldn't use some C++11/C++14/Boost mutex type? (C++17 and Boost both have a shared mutex impl (i.e. multi reader, only one writer))..reserve
enough space.unique_ptr
in "StartThreads" since RAII works LIFO (last in, first out).Src/Shared/Network/DatabaseConnection.
new MYSQL
, use aunique_ptr
with a custom deleter (that's gonna bemysql_close
). You can remove all the delete this way (and use.reset()
where needed).nullptr
instead ofNULL
.while (a != 0)
iswhile (a)
Src/Shared/Network/QueryResult
nullptr
instead ofNULL
.That's pretty much all I saw for Src/Shared. I'll try to look at other files tomorrow :)
The text was updated successfully, but these errors were encountered: