Poll of the Day > I spent 4 hours rewriting code

Topic List
Page List: 1
Yellow
02/03/21 3:00:12 AM
#1:


Because I thought it was sloppy and repetitive only to find out the new version is 10 times slower and doesn't fix the problem, so I reverted the whole thing.

I'm actually just happier that I got it right the first time. The original was sloppy in an efficient way. To me that's just a sign that it's done well.

---
why am I even here
... Copied to Clipboard!
shadowsword87
02/03/21 3:07:34 AM
#2:


Why not spend those 4 hours hacking together a new thing?
Feature creep your ass off.
... Copied to Clipboard!
Yellow
02/03/21 4:00:49 AM
#3:


shadowsword87 posted...
Why not spend those 4 hours hacking together a new thing?
Feature creep your ass off.
Because bugs need to be fixed. Sometimes you have a bug you can't find. If you can't find it, it's either because your code is optimized and is well designed to the point that it isn't easily understood, or isn't comprehensive and is badly designed, so instead of finding it and fixing it it's sometimes better just to rewrite it and hope you don't make the same mistake twice. Basically nuke your rat's nest from orbit.

However it turned out that the code worked just fine and was fast as well, which reaffirms that my code is done well. I also know the specific method the real bug is and how to fix it.

Also feature creep means new bugs, and sometimes bugs disguise themselves as other bugs, so when you leave old bugs in there you may dig around in places it doesn't exist.

---
why am I even here
... Copied to Clipboard!
Nightwind
02/03/21 6:19:01 AM
#4:


Did you document it this time, so the next person who looks at the "sloppy" code understands how good it is?

Sometimes a kludge needs to be praised.

---
Nightwind
"the wind has no destination"
... Copied to Clipboard!
Sahuagin
02/03/21 6:23:44 AM
#5:


removing duplication is almost always a good thing. (though, that's duplication of logic, not duplication of structure.)

if there are performance issues, use a profiler. sometimes things are slow for a reason you would never have guessed. a profiler will tell you the exact place(s) in your code that are taking the most time to execute. (if this is graphics related though it may not be so straight forward as that.)

---
... Copied to Clipboard!
Yellow
02/03/21 4:50:53 PM
#6:


Sahuagin posted...
removing duplication is almost always a good thing. (though, that's duplication of logic, not duplication of structure.)

if there are performance issues, use a profiler. sometimes things are slow for a reason you would never have guessed. a profiler will tell you the exact place(s) in your code that are taking the most time to execute. (if this is graphics related though it may not be so straight forward as that.)
I do love my profilers. They helped me cut down my CPU usage from 20% to 3%.

I often optimize as I go.

Nightwind posted...
Did you document it this time, so the next person who looks at the "sloppy" code understands how good it is?

Sometimes a kludge needs to be praised.
The method is InternalAlign. This is a class that handles a UI element in a grid while the element is being resized by the user. It's triggered when any "widget" within the grid is resized for any reason (though it prevents infinite loops by disabling itself while modifying the areas)

If a widget is made wider, it will resize the column to the right to accommodate it.

I had "cleaned" up this code to move the repetitive parts into an easily accessed method, but it was horribly slow because it had to re-create several lists that were in the bigger uglier one many times a frame.

Idk if anyone will work on this, it's sort of my own for fun project. I comment my old code when I'm too lazy/tired to do real coding.

https://github.com/jamieyello/DownUnder-UI/blob/master/UI/Widgets/Behaviors/Format/GridFormat.cs

---
why am I even here
... Copied to Clipboard!
Sahuagin
02/03/21 7:00:20 PM
#7:


how do you build it if the solution is only a single shared project?

---
... Copied to Clipboard!
Yellow
02/03/21 8:15:08 PM
#8:


Sahuagin posted...
how do you build it if the solution is only a single shared project?

you must have a driver project of some kind that is not part of the repo.
I have a tutorial that is out of date. If you wanted to look at it, the easiest way for me to do that would be to put the UI Editor up on GitHub. You could probably get the gist of how it works at Game1.LoadContent().

https://github.com/jamieyello/DownUnder-UI-Editor

This needs the other project as a shared project reference. Idk how Visual Studio will handle that, if there are any automatic imports. Probably not, probably just a bunch of errors before you add the reference.

The shared project runs with a modified version of the MonoGame framework template. It's a shared project instead of a packaged dll because of how the Monogame framework loads assets, which is something I really don't like. I sort of frankenstien'd a game framework into a re-distributable by making it a shared project.

I still 100% do not want to make my own framework. It is intended to be used alongside a refined and popular game framework, and I do not want to handle any kind of engine porting or usability issues. No one would use it if I came up with it on my own.

Anyway, I am so burnt out on this dumb Grid behavior. So complicated, so many bugs. I wish I would be done with it already.

I made some good writeups on where I am on currently Discord
https://discord.gg/bEZPvQE

---
why am I even here
... Copied to Clipboard!
Sahuagin
02/03/21 8:47:23 PM
#9:


tempted to go through this and clean it up a bunch. not used to programming with others though, so there would instantly be the issue of conventions.

my conventions that conflict would be:
I use size 3 tabs, but you have 4 (forgot about tabs versus spaces; I use 3 spaces, you use 4 spaces)
I use (dunno the name but looks like it's 1TBS) style (ie: braces on same line), this is all K&R style (braces on separate line, vertically aligned)
I use var when possible but it seems like you avoid it intentionally?

can I use 3 spaces for indents, or should I stick with 4 spaces?
can I use 1TBS style, or should I stick with K&R?
can I use var?

(I guess not to imply that you *have* to take my changes or anything; but either way, there should be agreement on conventions)

---
... Copied to Clipboard!
Yellow
02/04/21 12:31:07 AM
#10:


Sahuagin posted...
can I use 3 spaces for indents, or should I stick with 4 spaces?
can I use 1TBS style, or should I stick with K&R?
can I use var?
Sure, those seem like reasonable changes. I just couldn't get VS to switch indenting style when you suggested it earlier but I agree it saves space.

I haven't been using var under the (false) assumption that it somehow slowed down the compiler. I just Googled and that's wrong.

Sahuagin posted...
(I guess not to imply that you *have* to take my changes or anything; but either way, there should be agreement on conventions)
Oh yeah, that sounds interesting, I've never accepted a commit. I take it you got it to build despite my lack of instructions?

---
why am I even here
... Copied to Clipboard!
Sahuagin
02/04/21 1:31:37 AM
#11:


Yellow posted...
Oh yeah, that sounds interesting, I've never accepted a commit. I take it you got it to build despite my lack of instructions?
I'm maybe/probably going to try doing a pass over all the code files, I just wanted to make sure we're on the same page first before I start changing things.

I'm not sure about the indents. I feel like I shouldn't change it all to 3 spaces just because I like it. the braces at least I think would be an improvement in a lot of places but the tab size is a bit more personal preference. and reading it sounds like 4 is standard in a lot of places. so I might keep it at 4.

---
... Copied to Clipboard!
magemaximus
02/04/21 1:50:03 AM
#12:


i think i have spent 12 hours writing code. was making a game for one of my computer science classes. using c++. talking about 12 hours straight. but i spent like 48 out of 72 hours writing the code because my dumbass likes to do things when they are close to being due instead of using the 3 or 4 months that i was given.

---
You can't persuade fanboys. You'd be better off trying to convince a wall. ~CodeNamePlasmaSnake~
... Copied to Clipboard!
Yellow
02/04/21 3:17:49 AM
#13:


So my workflow atm is basically change the what the DisplayWidget is in LoadContent(), usually to some static Widget method.

Doing that will basically change the program to whatever UI you define. I usually change it to some test Widget I make to test features that I develop, then I go back to the UI editor to implement the features that I've been working on. Recently I've been working on a right click context menu that will be useful for copy, paste, and "go to slot", which is going to eventually add a slot in your WidgetCode source file. I make heavy use of the WidgetBehavior class, which is the base of my ECS, that adds functionality to Widgets. (BlurBackground, DrawOutline, DrawText)

The future workflow for the framework is to make it so all user code goes in a class that inherits WidgetCode, which is the equivalent of a Form in Windows forms. It automatically connects "slots" to methods it finds. When I get the UI editor functional I can completely abandon the old way of doing it. People have complained when they tested it out that doing UI manually gets very messy very quickly.

When creating an object that inherits from WidgetCode, it will deserialize an XML file that defines the "Widget". There is also a partial class that is generated alongside the WidgetCode class that helps the user navigate the Widget they created using the UI editor. This is the same exact thing Windows Forms does.

---
why am I even here
... Copied to Clipboard!
Yellow
02/04/21 3:18:53 AM
#14:


magemaximus posted...
i think i have spent 12 hours writing code. was making a game for one of my computer science classes. using c++. talking about 12 hours straight. but i spent like 48 out of 72 hours writing the code because my dumbass likes to do things when they are close to being due instead of using the 3 or 4 months that i was given.
Hope you've gotten better about that. I like to think I wouldn't do the same thing, but I feel like I'd let myself down the same way. :)

---
why am I even here
... Copied to Clipboard!
magemaximus
02/04/21 3:42:58 AM
#15:


oh yeah i changed my major from cs to math. i don't regret. intense coding isn't for me.

---
You can't persuade fanboys. You'd be better off trying to convince a wall. ~CodeNamePlasmaSnake~
... Copied to Clipboard!
Sahuagin
02/04/21 7:59:07 PM
#16:


I did some basic cleaning, but gonna try to take this slow, whereas my instinct would normally be to just change everything I see whenever I see it

before I go over everything I think I need to change the structure a bit

here's what I want to do, but it's up to you:

- the shared library should just be for the content, not all of your code. I will split it apart and make a class library for the code part of it (and later probably splitting that apart based on dependency.)

- the solution is not buildable unless I add the editor project, but that project is not in the repo. I will add the editor project to the UI repo so that that solution will build. (may try merging the repo in with git, but I'm not a git expert and I don't want to make a mess.)

let me know if I'm being too intrusive

---
... Copied to Clipboard!
Sahuagin
02/04/21 8:20:38 PM
#17:


ok I have to figure out this git stuff

looks like I need to clone a fork rather than clone your repo directly, which makes sense

reading your docs it sounds like I should try to figure out how to get it working without restructuring, at least for now

---
... Copied to Clipboard!
Yellow
02/04/21 9:12:06 PM
#18:


Sahuagin posted...
- the shared library should just be for the content, not all of your code. I will split it apart and make a class library for the code part of it (and later probably splitting that apart based on dependency.)
I had thought of doing that.

The upside is that yes, shared project formats are waaay too new and experimental for me to prefer using. And I assume you have a good reason for doing it.

The only downside is that I think it's kind of cool that the source code is not only sitting right there, but the commit button is also sitting right there, encouraging users to get familiar with the framework and commit. Just by using it you are already in an environment to contribute. There's something very powerful about that, I think it may more than double the amount of people who commit. They may find a bug, source it back to the framework, and be able to fix it without even opening a browser. Alternatively with a class library, a user may find a workaround and not fix the problem, and instead complain on a forum or open an issue on github (I find people who open issues on GitHub to be the most technically inclined who would probably fix it if it was sitting right in front of them). For a small project that might keep people feeling very engaged.

In being forced to use the horrible shared project format, I think I now see the purpose of its existence, and find it kind of hard to part with. Is this necessary for other steps you want to take?

Sahuagin posted...
- the solution is not buildable unless I add the editor project, but that project is not in the repo. I will add the editor project to the UI repo so that that solution will build. (may try merging the repo in with git, but I'm not a git expert and I don't want to make a mess.)
Yeah good idea lol.

Edit, adding the "DownUnder UI Editor" to "DownUnder UI", wouldn't that copy over the UI editor to the user's project? Alternatively, keep an entire copy of "DownUnder UI" in "DownUnder UI Editor"

This is more of an issue with shared projects in general, there's no good way to reference them. Tragically very hard to share.

---
why am I even here
... Copied to Clipboard!
Sahuagin
02/04/21 9:15:30 PM
#19:


well, I started over since I hadn't forked. I have things building and running with almost zero changes (just a matter of matching your directory structure) and now will try a minimal pull request.

---
... Copied to Clipboard!
Yellow
02/04/21 9:25:31 PM
#20:


Neat.

---
why am I even here
... Copied to Clipboard!
Sahuagin
02/04/21 9:55:18 PM
#21:


A normal C# project compiles to a .dll file, and the dll is copied to projects that reference that project. A long standing problem with VS is that other "content" files do not get copied. So you can't reference a project to gain access to its files, it only gets a copy of the output dll. This means that you can't reference things like XNA content, or web related files (.js/.html/.css etc.).

You can sort of work around this with linked files, but it's hard to maintain and would sometimes conflict. You can also write your own pre/post-build copy commands to move files, but that's also hard to maintain.

So a new solution to this problem are "shared projects" which basically end up just merging right into projects that reference them, as if it was a part of that project. You then get copies of the files in that project as if they were a part of your project, allowing you to push non-C# files into one reusable place, add references, and make use of them in many places. (And yeah, as usual with MS, it's sort of a hack fix o a problem that could really use a way better solution.)

Anyway

Now that I have things in the right place, I'm not as eager to make those two changes, though I do feel like that's the right direction to go architecturally (but it's definitely a soft suggestion at most; I don't want to mess up your project)

I'm not sure what you mean about the shared project. The main difference is that a shared project sort of bakes right into a project that references it as if those code files were a part of the referencing project, rather than a class library where the code compiles to a dll (assembly) and then is loaded at runtime. (I suppose a practical difference there would be that a shared project reference increases the size of the referencing projects output file, and a class library reference splits it into a separate dll, which then has to be loaded.)

for the second point, I think ideally there should be one repo that lets you get up and running. an end user can reference any of the projects they want from a new separate solution, but the repo itself should (theoretically/IMO) have a single solution that builds and runs (or even contains multiple executable projects).

I don't want to stomp all over your design though; I'm going to try to be extremely cautious. the point for me is the learning experience of working on someone else's code and particularly doing so without causing any problems for them.

---
... Copied to Clipboard!
Yellow
02/04/21 10:36:41 PM
#22:


Sahuagin posted...
for the second point, I think ideally there should be one repo that lets you get up and running. an end user can reference any of the projects they want from a new separate solution, but the repo itself should (theoretically/IMO) have a single solution that builds and runs (or even contains multiple executable projects).
I guess in order to simplify things I should do as you say. I'm not as attached to the shared project thing as I made myself out to be. Despite it sounding like a big deal, it's really not imo. :)

I agree that the "DownUnder UI Editor" solution should be moved to the "DownUnder UI" repo, the main repo should be moved to a class library, and that the content portion of said solution should be the only thing left in a shared project. I understand how that will make things easier.

Sometimes the project kind of escapes my scope and it's hard to tell exactly how easy it is to use.

---
why am I even here
... Copied to Clipboard!
Yellow
02/04/21 10:51:37 PM
#23:


But yes the maintainability of the code is more important than doing something unusual and gimmicky for some perceived benefit that may be near sighted.

---
why am I even here
... Copied to Clipboard!
Yellow
02/05/21 4:43:19 PM
#24:


I will be doing the restructuring later today, let me know if you have a commit to make, it might be tricky trying to commit to files that have been moved around.

---
why am I even here
... Copied to Clipboard!
Sahuagin
02/05/21 5:23:01 PM
#25:


k I submitted my most recent changes.

I will wait I guess and then I think I'll fork and clone from scratch afterward.

---
... Copied to Clipboard!
grimhilde00
02/05/21 6:03:45 PM
#26:


I spent all week designing a remodel at work and was questioning my life

That said I actually do think I figured out a good way and a way that makes me think this is a meaningful/useful change

Halfway through the week I was just like....why am I doing this...

---
aka kriemhilde00
... Copied to Clipboard!
Yellow
02/05/21 7:23:20 PM
#27:


Sahuagin posted...
k I submitted my most recent changes.

I will wait I guess and then I think I'll fork and clone from scratch afterward.
All done, one big project.

Edit nvm some funky stuff happened and I fixed it? It doesn't build yet

Edit now the core does build. UI Editor throws a weird error.

Edit now the UI Editor builds. Hooray.

---
why am I even here
... Copied to Clipboard!
Far-Queue
02/05/21 7:33:44 PM
#28:


I was the feature creep in my high school

---
https://imgur.com/ZwO4qO2
"Far-Queue is probably one of the least troll-like of the posters here." - LinkPizza
... Copied to Clipboard!
Yellow
02/05/21 7:56:02 PM
#29:


Also maybe we should move this over to Discord/Community monogame forums, not sure if PotD cares

Far-Queue posted...
I was the feature creep in my high school
You are a feature creep.

grimhilde00 posted...
I spent all week designing a remodel at work and was questioning my life

That said I actually do think I figured out a good way and a way that makes me think this is a meaningful/useful change

Halfway through the week I was just like....why am I doing this...
That sounds fun. Possibly more fun than whatever you were doing before.

---
why am I even here
... Copied to Clipboard!
grimhilde00
02/05/21 8:01:04 PM
#30:


Yellow posted...
That sounds fun. Possibly more fun than whatever you were doing before.

No

---
aka kriemhilde00
... Copied to Clipboard!
Yellow
02/05/21 8:01:44 PM
#31:


grimhilde00 posted...
No
But what's more fun than remodeling a building?

We're different people.

---
why am I even here
... Copied to Clipboard!
grimhilde00
02/05/21 8:05:31 PM
#32:


Yellow posted...
But what's more fun than remodeling a building?

We're different people.

A building? I was talking about code remodeling

---
aka kriemhilde00
... Copied to Clipboard!
grimhilde00
02/05/21 8:06:50 PM
#33:


I thought this being a coding topic was context enough my bad

---
aka kriemhilde00
... Copied to Clipboard!
Yellow
02/05/21 8:08:54 PM
#34:


grimhilde00 posted...
A building? I was talking about code remodeling
Oh. See I've never actually had a coding job, so I've never been able to do a company's endless porting. Never heard of remodeling.

I'd rather remodel a building.

---
why am I even here
... Copied to Clipboard!
Yellow
02/05/21 8:15:42 PM
#35:


grimhilde00 posted...
I thought this being a coding topic was context enough my bad
No but seriously I've never heard of code remodeling

What do you do? Is that all you do?

---
why am I even here
... Copied to Clipboard!
grimhilde00
02/05/21 8:24:34 PM
#36:


Yellow posted...
No but seriously I've never heard of code remodeling

What do you do? Is that all you do?

No... That's not all I do. Just we have a certain model and it's proving problematic with scaling and new things and it needed rework like a few months ago

---
aka kriemhilde00
... Copied to Clipboard!
grimhilde00
02/05/21 8:27:30 PM
#37:


Basically there's a concept with certain underlying assumptions that are no longer correct and things have just been tacking onto it badly so it's becoming a frankenstein and it needed to be rethought and need to rework all the systems in place for that

So was looking into how to do that with a new approach that was more future proof and flexible but still clean and narrow

---
aka kriemhilde00
... Copied to Clipboard!
Yellow
02/05/21 8:35:35 PM
#38:


That sounds very very corporate. So now you're trying to come up with some kind of plug in system so people stop fucking up the code?

---
why am I even here
... Copied to Clipboard!
grimhilde00
02/05/21 8:41:58 PM
#39:


No. It's a startup. It's just people built things without thinking things through and now it needs to support more things and there's growing edge cases being put everywhere that's getting ugly.

And it's slowing down adding new things because people have to have all this knowledge about all these different places that work inconsistently.

So it just needs to be made cleaner.

---
aka kriemhilde00
... Copied to Clipboard!
Yellow
02/05/21 8:52:19 PM
#40:


Huh

I could basically interview you like this until you get annoyed, I'm very curious as to what doing it as a job is like. Maybe if I spent more than two days applying I would.

---
why am I even here
... Copied to Clipboard!
grimhilde00
02/05/21 9:04:59 PM
#41:


I'm just trying to be vague lol

---
aka kriemhilde00
... Copied to Clipboard!
Topic List
Page List: 1