DEV Community

Discussion on: Is there any difference between struct embedding and defining a field with the struct you want to embed?

Collapse
 
baenencalin profile image
Calin Baenen

I know, but shouldn't this be okay as method names, like in a language like Java, or JS (where it's already defines as a keyword)?
Is it okay to use this if I keep my methods grouped in the same general area (file, and location) as the method's host-type?

Collapse
 
moose profile image
moose

There isn't anything technically wrong with it, and you can certainly do that if that is the most prudent naming convention for you. You'd likely run into null pointer exception in java and scoping issues in js it though. You'd also probably catch some heat in any code review should you choose that kind of convention.

The problem with using a lot of objects with vague naming conventions is readability and maintainability. If you ever had to come back after a while and add a feature its dollars to donuts you won't be 100% on what is exactly executing and why in the file and you would be more prone to make errors where there once was none. And thats an everyone thing, we all do it/did it before and set ourselves up for failure later on.

So with that in mind: once you start progressing to more advanced topics and when what you write starts becoming more complex than the example I saw earlier you will run into spaghetti moments no doubt. Even Rob Pike takes notes. If you added any kind of complex logic to your file and tried running it in multiple thread, you would have vague errors everywhere pointing to "this" and it would be a nightmare.

No private marking for class inits, no kind of scoping thats obvious, no real type hints without reflection tools making things harder to maintain in the future because you'll forget stuff (we all do) and coming back to any kind of complex code with no set up documents of meaningful purpose.

Being young like you are, you'd be ahead of the pack starting to enforce good habits surround your development chops. If you still have reservations about it: I recommend in earnest, you find a medium size Opensource Project, clone it and just attempt to reverse engineer it. It would be a good exercise for you to experience to see what an actual onboarding is like.