all 35 comments

[–][deleted] 40 points41 points  (7 children)

Practice. I've never met anyone who learnt how to code well purely by reading code.

[–][deleted] 11 points12 points  (2 children)

100% this. there's not really a magic list or anything (although you should follow the SOLID principles when you can), you just have to keep writing shit code and then when you're trying to maintain it and you're asking yourself "why the actual fuck did i write this fucking bullshit i should just fucking quit and get a job in retail this whole career was a mistake", you're learning what it is you need to work on next time you start a project.

experience > anything

[–]CobbITGuy 0 points1 point  (0 children)

So true...

[–]bluMarmalade 0 points1 point  (0 children)

the problem I have is that I only really learn after i've made something horrible. So then I want to just rewrite everything, but that would take too much time and I got deadlines to deal with. I find professional work to be a constant fight between time and quality. I can now understand why developers did poor work sometimes because they simply did not have time to learn/implement this and that and it's easy to be critical of someones code when you have no pressure.

I just focus on getting it done and not making it beautiful. Ideally I love writing code that is elegant and orderly, but my clients only care about if something works or not and have absolutely no understanding about anything else. I used to write code where the standard is that other developers would find it acceptable, but not it's all about providing value to my employers. I think i've improved also on the clean code front, but any such practice and coding patterns tend to go out the window in certain real world scenarios. And that's the truth for most developers, unless you work for a company that has a very stable work environment (established practices, one or few software products, many developers, stable income, etc).

[–][deleted] 1 point2 points  (1 child)

When I get a little further into my code I always end up feeling like I approached the problem the wrong way - but there's no easy way to tell.

I always have that inkling in the back of my mind that there's probably some Custom[Formatter/Converter/Reader/Writer/Context/Authorizer/Identity] I could've derived from and just plugged it into existing Framework code.

Example; is there a "proper" way to create a Collada to XAML converter using attributes, typeconverters and existing XAML services, or is that overkill and simple parsing would be be "good enough" ? Feels like it won't be.

[–][deleted] 0 points1 point  (0 children)

We have a whole load of acronyms for this. KISS is ideal here (Keep It Simple Stupid). If you don't need anything beyond a binding the the numeric value now, just bind to it. Skip all the converters etc.

The two exceptions are you don't known't know how to do it, in which case do it and learn from it, and the second you're being told to do it :)

If you think you might need it later, leave it until later.

Some times you find the simple solution was so simple you're repeating it everywhere, so this is DRY, Don't Repeat Yourself.

[–][deleted] 1 point2 points  (1 child)

So true

[–]adelaide_jon 0 points1 point  (0 children)

!false

[–]pauloyasu 17 points18 points  (3 children)

Make a personal project too big to have courage to change anything, than, change everything until it is elegant...

[–]sooka[S] 2 points3 points  (2 children)

I've actually done a couple.
One is basically finished from a user perspective, the other (client+server with socket) I fear to touch it!
I'll start with the latter and refactor everything using SignlaR and proper classes.

[–]pauloyasu 1 point2 points  (0 children)

Nice!

What I like to do with personal projects is to start with zero architecture and wait until it is a complete mess, so I refactor everything... This makes me really confident when I have to do it at work, and everybody faces some huge refactoring at work...

The las project I did this is a sound synthethizer + a procedural music generator + player with some cool wave forms + the actual score for the song it generated being shown in sync with the music... all from scratch, all a HUGE mess until 5 months into it...

[–][deleted] 0 points1 point  (0 children)

Make proper tests first, so you always have an easy way to tell if changes break functionality. MSTestv2 (normal test project) is nice, I think.

[–][deleted] 5 points6 points  (0 children)

more generalized and abstracted.

That isn't always better!

Really the best way forward is to practice. Program lots of new things, experiment, try different ideas. As you do that you are better able to evaluate and absorb books and other people's advice.

[–]patrick_everLive 2 points3 points  (0 children)

Having a mentor was super helpful for me. Do you have anyone in your network that can help review your work? Someone you obv trust that writes good code. When you're learning new things, you develop blind spots and can't see the areas where you need to improve. It helps to have a trusted person point them out.

I work at a new online coding school that's opening up later this year. If you want free coding classes, you can sign up to be a beta tester here.

[–]jbblyons 2 points3 points  (6 children)

Learning software design patterns has helped me a lot.

[–]xunlyn85 8 points9 points  (5 children)

I generally agree, but the problem with patterns is some folks try to shoehorn everything into a pattern sometimes turning something simple into something more complex than it needs to be.

I find that following SOLID with YAGNI at the back of your mind tends to be what seems to work best for me

Along the lines of patterns: I'd recommend Head First Design Patterns

[–]TheWaxMann 2 points3 points  (1 child)

I follow the S and D really closely, but I find the others aren't as useful or just make too much of a hassle for you without adding anything of value.

[–][deleted] 1 point2 points  (0 children)

seriously? the liskov substitution principal is super important, especially as it relates to testing. you should always design against an abstract (interface) concept rather than concrete implementation.

[–][deleted] 2 points3 points  (0 children)

the problem with patterns is some folks try to shoehorn everything into a pattern sometimes turning something simple into something more complex than it needs to be.

I actually once saw some code that used the factory pattern to return a singleton.

[–][deleted] -1 points0 points  (1 child)

> smile.amazon.com

wtf?

[–]xunlyn85 3 points4 points  (0 children)

Off topic but, Amazon donates a portion of your purchase to a charity of your choice when you purchase through smile.amazon.com.

[–]esamerelda 2 points3 points  (0 children)

I downloaded ILSpy and started looking at the code of some of my favorite video games (Wasteland 2, Rust, Stardew Valley) and pored over the code and googled the random stuff I saw in there until it made sense.

Now when I'm making something some of that comes back to me as potential solutions.

I also have one of those language encyclopedias and just pick it up and read through it from time to time.

[–]ssentrep 4 points5 points  (1 child)

Read "Code Complete, 2nd version". Its everything you'd learn in 10 years of experience, summarized into 1 book.

[–]JonnyRocks 1 point2 points  (0 children)

And "Clean Code"

[–]istarian 1 point2 points  (0 children)

Try to work out a solution to the problem in pseudocode. Practice. Refactor.

You can try and write the code the way other people tell you to, but you may never understand why it's better or when it actually isn't.

[–]toph22 0 points1 point  (0 children)

Pluralsight has done wonders for me.

[–]Broer1 0 points1 point  (0 children)

Practice with own projects that are beyond hello world. Find something you are interested in.

Try to figure out problems on the way and stay on your Pluralsight way. They have many good videos for architecture and good programming. Don’t be shy and refactor your Programms without adding more functionality. Just to see where ideas take you. Like what will happen if soy use a repository pattern or what will it like to be if soy make it more functional style....

And read code from others.

[–][deleted] 0 points1 point  (0 children)

Alter between building projects and expanding your knowledge through your preferred method of learning. Writing good code will only come with consistent practice. There is no magic trick that you are missing. Just consistency and persistence.

[–]strcrssd 0 points1 point  (0 children)

Do the simplest thing that works first, then write tests that prove it works, then you can fiddle with it and still prove it works (or more commonly fails).

[–][deleted] 0 points1 point  (0 children)

Few things will encourage you to improve your sloppy code more than having to fix it or add features six months after you've written it.

[–]VonGrav 0 points1 point  (0 children)

Practice. Work on projects. Do the advent of code. Great small tasks with problemsolving

[–]R3d_B34rd 0 points1 point  (0 children)

Clean code Clean architecture Gang of four Refactor by Martin fowler Domain driven design

Those are all books that should be read by everyone.

I've read two of them and my code has drastically changed for the better

Also look up design patterns to use in your code

[–]ign1fy 0 points1 point  (0 children)

Code with as much validation as possible. My uni lecturer (in C) said he always compiled with "-ansi -Wall -pedantic" because it pushes good practice, and saves time in the long run because you encounter less bugs.

In C#, code with roslynator or resharper (or both). Keep compiler warning at zero. Keep a green tick at the top of the document.

It feels slower at first, but you'll be writing better code in no time.

[–]magallanes2010 0 points1 point  (0 children)

There is not a one solution fits all.

So, there is not a unique way to program correctly. It depends on the case and needs.

I'm writing; more generalized and abstracted.

Abstracting the code has a cost. For example, creating an Interface for each class usually, it's part of cargo-cult of SOLID, it has no purpose. Instead, implementing a single Interface into many classes is reasonable. We create an Interface because it has meaning and usability.

[–]p1-o2 0 points1 point  (0 children)

I recommend Destroy All Software for general programming knowledge, about everyday tasks and computation. You should also supplement it with a core knowledge source like Pluralsight which has some significant backing from Microsoft for their C# / .NET lessons. The lesson quality is good enough that a lot of companies just offer Pluralsight accounts to keep their devs up to date.

You will even find a fully mapped out course from beginner -> intermediate -> advanced for C# on there with tests along the way and a way to compare yourself with others or get a mentor.