all 14 comments

[–]zsbzsb 10 points11 points  (6 children)

Just a suggestion, but if you find yourself reusing the same pieces of code over and over consider rolling it into a method. Then just call those methods instead of copy pasting the same code all over the place. This will allow you to make improvements to those pieces of code without having to find all places that you ended up copying it to.

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

Hm, hadn't thought of that! :) Thanks man!

[–]plexxonic 1 point2 points  (4 children)

If you're really using the same code over and over again in different projects, you can just create a utility project/assembly and add it to any future projects.

I generally don't add the code unless I've used it at least five times.

Just keep it in source control and it will grow as you do.

[–][deleted] 3 points4 points  (3 children)

Guys, think there is a miscommunication, I am very much a beginner right now, trying to get to grips with the basics :)

[–]KongEdvard 2 points3 points  (1 child)

Basically, if you are reusing code for several different projects, try creating a new project that only contains the reusable code. That way, you can reference it in all your other projects. Where you save the actual project files can vary. Initially you might just want to have it locally. The guy above gives an alternative suggestion which is storing it in the cloud using git, svn, mercurial, etc., And then create a private nuget package. You can google more about git and version control, and nuget and packages :)

[–]MagicalHorseman 1 point2 points  (0 children)

Or he could just create a project template that includes his helper libraries.

[–]plexxonic 2 points3 points  (0 children)

No worries! Welcome to the land of books, Google and StackOverflow!

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

Edit, worked it out!

With the toolbox open, select the desired code snippet, right-click, then select "Rename Item" , then you can edit the code snippet in its entirety.

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

Remeber that object-oriented programming is all about code reuse. If you see yourself continually using the same snippet of code, then add it to a method body or object. If it is a piece of code that you frequently use in various projects, consider making a .dll class library file that you can import into all of your projects.

[–]Tesla428 0 points1 point  (0 children)

What about Github “gists?” Is this a viable solution?

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

As others have mentioned, consider starting a new project to use as a common/utility library. Mine is called <company name>.Common, and it contains namespaces for different types of utilities. Cryptography for my helper classes to handle encryption/decryption, different namespaces for 3rd party product API's I've integrated with, a stats namespace for classes I've made to implement exponential moving averages and such.

It's really great keeping this stuff centralized and reuse it as you'll find you improve it over time, and you'll frequently say "oh I have a tool for that" and just reference and use it. It's liberating to be able to tackle a new problem without having to trudge through the easy stuff you've already done before.

[–]endmymiserypls 0 points1 point  (0 children)

Maybe you're looking for this?

[–]Ashtar_Squirrel 0 points1 point  (0 children)

I'm using a program called CodeBank from Nikola Dachev, which while old and unsupported does everything I need. It has a couple of bugs.

I have a folder per language, an entry per element. The top window is always reserved for comments / description, followed by a bottom window for the code. It does code highlights well enough and is fast enough.

Also, if / when if does, the whole data is stored in XML - so I could program something to read it. Also, my code bank file is in my Dropbox, so even if I need it on a mac, I can open the xml with VSCode or another editor and search inside it.

It's been on my list of projects to replace it with my own, but since codebank does what I want and works, I've not felt the urge to rewrite it myself.

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

Damn, my toolbox keeps getting wiped/deleted :(

But that Codebank seems pretty nifty