#how could i improve my code

1 messages · Page 1 of 1 (latest)

glacial fox
livid escarp
#

Renaming your variables better , having constants

#

capitalize global variables

glacial fox
rain prism
#

make more things

glacial fox
rain prism
#

no you dont

#

physically impossible to perfect it before moving on because later on you might need it to do things you didn't originally plan on needing it to do; meaning you may need to throw it out and start again to get it to do what you wanted. meaning all that time you spent perfecting and optimizing it? wasted.

#

s1 is expected to know this

rain prism
#

[Scripter 2 - Intermediate] Key Expectation: Novel problem solving at scale with intent

Meaning:

In addition to the scaling problem, you, or another scripter, often may need to go back to your scripts at a later time to fix a problem ("Maintainability"), change or add new behavior ("Robustness"), or produce new content with it ("Versatility"), so it is a major priority for marketplace employers that their codebase stays clean, organized, and manageable as its scale increases so that any person or team working with your scripts, yourself a year from now included, are able to look upon your work and understand what it is doing in order to build upon it with minimal time and effort; this is the problem of collaboration.

What this looks like in a script:

Get "Ultimate bGuide to Software Freelancing" - a FREE roadmap for a very, very lucrative career. CLICK HERE: https://iamdev.net/free

Really simple - abstraction is hiding stuff!

▶ Play video
rain prism
#

coz if i can look at your code and say "this section sucks but all i have to do is change the body of the function and nothing else" it is excellent code 👌

rain prism
#

the inputs and outputs are 'decoupled' from the implementation

glacial fox
glacial fox
#

i asked how i could improve my code

#

and youre edgiiing it

glacial fox
#

trust me i did my research

glacial fox
#

im like high s1

#

im tryna get low-mid s2

rain prism
rain prism
rain prism
rain prism
rain prism
glacial fox
rain prism
glacial fox
#

at least i think so

rain prism
rain prism
glacial fox
rain prism
#

that's the best way to improve.

#

it's really not that deep.

#

it really, really is that simple.

glacial fox
#

i dont think im asking for much

rain prism
glacial fox
#

which is mainly what i care about

glacial fox
rain prism
#

and i'm saying dont bother; just roll with what you have

rain prism
glacial fox
rain prism
glacial fox
#

cuz i plan on adding more to this system

rain prism
#

add more stuff first and then scale it

#

not the other way around, that is premature optimization

glacial fox
rain prism
rain prism
#

it's impossible to know in advance how flexible you need your systems to be .. until you actually use your system to do those flexible things

glacial fox
rain prism
#

coz you can plan all you like, it won't matter when it comes to actually making the things you want to make

#

9 times out of 10 you'll hit something that you weren't expecting. you simply cannot account for that short of just making stuff, finding all those boundaries, scale up, and keep going. rinse repeat

rain prism
glacial fox
rain prism
#

the more stuff you create, the more accustomed to making stuff you'll be, and the more consistent your code will become because you simply know the patterns you're using better, which will in turn make it more readable because your code is more consistent

rain prism
#

you need it to make systems flexible

#

and do more stuff

glacial fox
rain prism
#

same same

#

they're roughly the same thing

glacial fox
#

or is abstraction more than that

rain prism
#

how to put it simply

#

"do more with less"

#

i.e every time you go to use an animation you usually don't care how it is loaded or anything, so you abstract away those responsibilities to some abstraction layer that handles loading and playing back animations

#

then wherever you need an animation you call into that abstraction since you only care about actually playing an animation at that point, how it gets loaded or where the id comes from is irrelevant

#

coupling is the specific functions and interfaces you depend on

#

the specific kinds of inputs the abstraction needs

#

there is always some coupling

#

i.e animationsystem:PlayAnimation(name_or_id)

#

your system could take a named animation, or it could take a flat id, or maybe it can take both!

rain prism
#

but the :PlayAnimation() function is a dependency now - the function must always have that name and do exactly that job, you can't change it because anything that depends on it must also change. this is coupling.

rain prism
# glacial fox could it take an object?

and this is why abstraction so good. if you later decide you want to pass in animation objects directly, you can do that without changing anything else coupled to it

glacial fox
rain prism
glacial fox
rain prism
#

if you want to remove capability such as removing the ability to pass in a pure id, then yes you would need to change all the scripts that use a pure id to use the new technique instead

#

naturally, doing that without making those changes first is going to break a lot of things

#

this is the purpose of Deprecation.

glacial fox
rain prism
#

so your system might still be capable of taking a pure id - but you would consider it "deprecated" and slowly phase out anywhere you still use a pure id, and never use it for future works. this is why you should absolutely care when roblox deprecates something because it is exactly the same as this

glacial fox
#

or even a function in general

rain prism
#

the goal is backwards compatability; code that hasn't been updated to use new methods still need to function

#

otherwise your game breaks

#

this stuff isn't hard to research btw

rain prism
#

and should be glaringly obvious

#

like well duh if you remove something that other parts of your game relies on, it's going to break your game

#

I didn't need to tell you that, you already knew that

glacial fox
rain prism
#

the only part you probably didn't realize is yes code really is that stupid

#

most beginners tend to overthink it

glacial fox
rain prism
#

like omg deprecated big word such complex

#

no.. it just means you don't break your game when you go to remove something

#

everything in scripting is like this

#

all of it

#

in fact the more ooga booga caveman smallbrain you are about it, the better.

#

in fact, you may find me asking really stupid questions, or posting really dumb or obvious answers to people's questions

plucky coveBOT
#

studio** You are now Level 56! **studio

glacial fox
rain prism
glacial fox
rain prism
#

i make more things all the time

#

last week i made gui particles

#

this week i made a bytenet replacement

glacial fox
rain prism
#

today and tomorrow i'll be working on the player session sync thing, basically networking/remotes wrapper so i can share data

glacial fox
rain prism
#

you're overthinking it

rain prism
rain prism
#

that's simple but not very dumb

#

kinda dumb tho

#

it's actually because beginners don't know how to use that stuff whereas i do

rain prism
#

a beginner, who does not understand remotes in the first place, does not need something that makes their remotes harder to use

glacial fox
#

i now know when and how to use buffers

#

praise me

rain prism
#

the skill level of the person i am speaking to matters a lot

glacial fox
rain prism
#

it's only worth using when you have good reason to use it

#

and know why you would use it instead of not use it

glacial fox
#

cuz remote events are unavoidable in most cases

rain prism
#

bytenet is pure compression into buffers (and tbh doesn't do a very good job of it)

glacial fox
glacial fox
#

im pretty sure buffers should be used for very very frequent calls with many parameters

rain prism
glacial fox
rain prism
#

buffers are only useful if you can beat roblox

glacial fox
#

are buffers not meant to be used in expensive situations

rain prism
# glacial fox ???

do you really think roblox doesn't already compress a lot of its network traffic?

#

if you can't do better than that, there's no point to using buffers with remotes

glacial fox
rain prism
#

it doesn't show meaningful compression because real data is much more random and unsorted

#

most of the time, people are not going to be sending so much data that any of this actually matters

#

I am in a position where i do expect to be sending a lot of data

#

hence i need proper networking systems

#

-- i also know how to build them

glacial fox
#

or are they just not useful

rain prism
# rain prism make more things

and i only know that coz i've already made so much stuff. when I say make more things, i'm not suggesting you do anything I have not already done myself.

#

I have already done all that work. you have not

rain prism
#

like as in without doing something dum like an infinite loop or insane memory leak - in the normal course of operation the game maxes out servers. i've hit limits like that before

rain prism
glacial fox
#

i would benchmark but i cant realy simulate a real game

rain prism
#

you'd get better gains by sending a number instead of a string

#

coz i see that a lot

#

:FireServer("SomeAbility")

glacial fox
rain prism
#

and then they go ermagherd bytenet uber compress ByteNet:FireServer("SomeAbility")

#

..... send a number not a string would've been better in both cases, bytenet didn't help

rain prism
#

in fact with roblox the definition of an entity isn't as clear-cut as it is in other games

#

but i'm not going to go into that right now

glacial fox
plucky coveBOT
#

studio** You are now Level 20! **studio

glacial fox
rain prism
# rain prism make more things

anyway, bottom line is that i'm not kidding, exaggerating, gatekeeping, or "edgiiing" when i say, just make more things. I genuinely mean it.

#

coz while you're still trying to perfect one little tiny piece of code, someone else, such as myself, has made leaps and bounds of progress in making systems and content - they aren't perfect, but the job absolutely gets done to a reasonable degree, and in substantially larger volumes.

#

it's like

#

you can spend a year making one thing that doesn't end up doing what you want after a week of adding content to it

#

or you can spend a year making and releasing a thousand things that may not be perfect but they function and people can play with what you make.

#

it's really up to you, i'm not your mom

glacial fox
rain prism
# glacial fox the self glaze 💔 😭

well yeah i've just spent an hour explaining to you that you should be focusing on making stuff not perfecting it when i could've spent that time making my own stuff

#

we've both lost productivity in your pursuit of unnecessary perfection.

glacial fox
#

its the principle

rain prism
#

but

#

well

glacial fox
rain prism
#

you can forge your own path and i won't stop you if you really want to do that, at least you are now informed that it is a bad idea and why it is a bad idea.

#

is about all i can give you - can lead a horse to water but can't make it drink.

glacial fox
#

Cuz at the end of the day commissioners barely care about back end

#

Only how it looks

#

And if it works

rain prism
#

you will know when it needs improving when your code doesnt do what you need it to do or is lagging your game

glacial fox
rain prism
#

readability is just dont make it confusing to read or follow on a later read

#

aka use descriptive variable and function names, don't nest too heavily

#

don't using confusing weird ass logic where it doesn't belong

#

"bEcAuSe OpTiMiZaTiOn" is not a good excuse to make your code impossible to follow

#

and your datastore code shouldn't have any animations in it

#

that is - keep related stuff together

#

don't put unrelated stuff together

#

avoid globals and magic variables etc

glacial fox
#

I meant just making my code readable

nova basin
#

Hmm

glacial fox
#

So I think your hatred for dod is unjustified