-
-
Notifications
You must be signed in to change notification settings - Fork 88
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
Set and enforce a consistent code style #41
Comments
Except for structs! |
Hey ero ! :) Thanks for pointing this out, i could actually need every help i can get with this.
Thats really something i use quite frequently. I actually did that since in some cases fields are actually being faster compared to properties. Especially when the propertys get is not being marked inline. So the question here is actually what to prefer, however such cases are pretty rare.
Understandable, how would you decide whether its necessary or not ? Unfortunately we can not test the performance effect on every single method. I think atleast query related methods should keep that since it lowers the cache miss in such cases. I already benchmarked this months ago and it was the case for such scenarios. However the effect on other methods is still unknown, based on experience methods marked with inline always performed better which is kinda important for this lib. So probably we should just ignore that inline is being spammed everywhere, you can see similar decisions in other ECS libs like "Default.ECS".
Why is that ? I can understand that it might make the code harder to understand at first, however its way more convenient to use. Probably we should focus on ensuring that the code is readable so that everyone automatically understands what type the var is e.g. : I agree on the rest however and could need some help here. Thanks for the editorconfig, just saw that. Im gonna use it :)
|
The big issue here is really the Properties' getters and setters can be marked inline just like any other method: public int Foo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)] get;
[MethodImpl(MethodImplOptions.AggressiveInlining)] set;
}
This is all very difficult to test. Slapping the attribute on every method you feel like can actually have negative effects. Think about it this way: if you inline a method which is on a path that's hit rarely, then the code generated is going to be bloated with unnecessary instructions that don't get executed.
All of these were merely suggestions. I like being explicit personally. If you'd like to keep using |
Well ref fields are great for various purposes, for example to reduce copies... or to return a var references = entity.Get<Position, Velocity>(); // Returns public struct References{ ref Position t0, ref Velocity t1 }, one single operation...
references.t0.X += references.t1.X;
references.t0.Y += references.t1.Y;
alternative
ref var pos = ref entity.Get<Position>();
ref var velocity = ref entity.Get<Velocity>();
// 2 Operations to receive a ref to the structs we wanna modify... two lookups instead of 1 = bad for hotspots It might violate several code conventions, but is extremely usefull and more performant since it basically batches operations ^^
Thanks, im gonna take a look at that... most methods are actually being used in hotspots (e.g. all |
Properties are just syntax sugar of: |
I support this, structure fields should not be touched or converted to properties. I also suggest that they stay public, this depends on the struct itself. However there a lot of usecases for properties inside classes. |
Do you have some branch you're using to work on this? |
Yep, its still local however ^^ Unfortunately I'm not home today, but any other branch will also do the trick. |
I've been doing some work over on just-ero/Arch#experimental-code-style. Here's a summary of what I did:
|
Took a quick look at it, looks promising :) Thanks ! Just a small side note, The Since this is mostly low-level and high-performance, we often need to decide between efficiency and code conventions... in this case we should always focus efficiency. |
Sooo looks great :) Thanks ! I also moved the properties directly behind the constructor. Somehow they were not moved. |
Archetype now also received documentation... i also made some fields private and moved them above the constructor to make them follow the order :) |
Documentation is finished and was merged with 7f2b07c :) Now I'm gonna work on the notes and other mentioned code style issues. |
Arch
is currently using unconventional code styles in a lot of places. I would like to propose some more consistent styles, as well as some other things to potentially look at. Enforcing a consistent code style allows for a better overall coding and reading experience.Major things this project needs to tackle:
in
modifier.MethodImpl
attribute.Below, I've listed some conventions this project can enforce. These are up for discussion though. I'm happy to help implementing this.
The below can also be found here as an
.editorconfig
file.Naming Conventions and Accessibility Modifiers
private
,protected
,private protected
, andprotected internal
fields should be_camelCase
. The same applies when they'restatic
.internal
andpublic
properties should bePascalCase
. The same applies when they'restatic
.const
locals and fields should bePascalCase
.camelCase
.PascalCase
.TPascalCase
.IPascalCase
.Fields should never be
internal
orpublic
. Properties should never beprivate
,protected
,private protected
, orprotected internal
.Accessibility modifiers should be required at all times.
readonly
should be added whenever possible.var
Preferencesvar
anywhere..NET Conventions
System
using directives should always be sorted first..this
qualification should never be used.int
) should always be used over framework types (Int32
).a + (b * c)
a || (b && c)
(a < b) == (c > d)
Expressions
default
expression.?:
) overif
with assignments and returns.new
).Pattern Matching and
null
Checkingthrow
-expression (obj ?? throw new ArgumentNullException(nameof(obj));
).null
propagation.is null
overReferenceEquals
or== null
.New Line and Braces Preferences
if
,else
,case
blocks.The text was updated successfully, but these errors were encountered: