Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#1 2018-09-12 18:38:28

Anatoly
Guest

What do you consider "good code" and what "spaghetti code"?

Please tell me what you consider a good code and what you consider a bad code. I still have to learn much before I can say "I can code" and dance before my friend. But for it may you tell me what you consider good- and bad code?
Like do structure of code matter for you, or the simple writing of the code?

Thanks in advance.

#2 2018-09-12 18:41:09

XxAtillaxX
Member
Joined: 2015-11-28
Posts: 4,202

Re: What do you consider "good code" and what "spaghetti code"?

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!


signature.png
*u stinky*

Offline

#3 2018-09-12 19:06:45, last edited by TaskManager (2018-09-12 19:07:01)

TaskManager
Formerly maxi123
From: i really should update this
Joined: 2015-03-01
Posts: 9,460

Re: What do you consider "good code" and what "spaghetti code"?

good code is when your variables and functions are named a b c and entire code blocks are put into a single line and your code utilises tricky not-obvious features to show off that you know X programming language really well! also each function that you write has to do a very specific thing because if your function does more various things its more POWERFUL
take a read on this article, ive found it while trying to learn JS but it generally applies to any language. that article abuses sarcasm/irony HEAVILY but since you end your forum posts with "/s" rather often, you'll understand //forums.everybodyedits.com/img/smilies/cool


i8SwC8p.png
signature by HG, profile picture by bluecloud, thank!!
previous signature by drstereos

Offline

#4 2018-09-12 19:08:19

peace
Member
From: admin land
Joined: 2015-08-10
Posts: 9,226

Re: What do you consider "good code" and what "spaghetti code"?

XxAtillaxX wrote:

Simple is better than complex.

sometimes complex is better to make it work


peace.png

thanks hg for making this much better and ty for my avatar aswell

Offline

#5 2018-09-12 19:57:20

drunkbnu
Formerly HG
Joined: 2017-08-16
Posts: 2,306

Re: What do you consider "good code" and what "spaghetti code"?

peace wrote:
XxAtillaxX wrote:

Simple is better than complex.

sometimes complex is better to make it work

Have you tried to program?

Offline

#6 2018-09-12 20:30:31, last edited by RageQuits (2018-09-12 20:31:57)

RageQuits
Member
From: Belgium (Dutch)
Joined: 2018-08-26
Posts: 29
Website

Re: What do you consider "good code" and what "spaghetti code"?

Here are some basic-basic things i keep track of (keep in mind i just made this very fast without paying attention, so some things can be done easier / shorter / might not make sence);
Also, all these examples are made in Java.

1) Don't just ignore an exception.

Don't

try {
    File inputFile = new File(baseDir, "config.yml");
    if(!inputFile.exists()) inputFile.createNewFile();
    FileUtils.readFileToString(inputFile, Charset.defaultCharset());
} catch (IOException e) {

}

Do

try {
    File inputFile = new File(baseDir, "config.yml");
    if(!inputFile.exists()) inputFile.createNewFile();
    FileUtils.readFileToString(new File("Config"), Charset.defaultCharset());
} catch (IOException e) {
    LogManager.getLogger().log(Level.ERROR, String.format("Failed loading configuration file (%s)", e.getMessage(), e));
}

2) Advoid duplicated code. Work with methods.
IntelliJ (Java IDE) is very nice with this and can detect these parts with ease.

(Dumb example but idc //forums.everybodyedits.com/img/smilies/tongue)

Don't

double double1 = 3.13,
       double2 = 3.15;

System.out.println(double1 > Math.PI);
System.out.println(double2 > Math.PI);

Do

public static void main(String[] args) {
    double double1 = 3.13,
           double2 = 3.15;
    someMethod(double1);
    someMethod(double2);
}

private static void someMethod(double in) {
    System.out.println(in > Math.PI);
}

3) Work object-oriented, don't always use statics.
I don't really have to explain this. I guess you know what i mean

4) Use lambda's. It always saves space.

Don't

Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
    @Override
    public void run() {
        stop();
    }
}));

Do

Runtime.getRuntime().addShutdownHook(new Thread(this::stop));

There's a whole lot but i only said these ones because i made these mistakes a whole lot of the time.

Offline

#7 2018-09-15 04:00:59

Slabdrill
Formerly 12345678908642
From: canada
Joined: 2015-08-15
Posts: 3,402
Website

Re: What do you consider "good code" and what "spaghetti code"?

TaskManager wrote:

good code is when your variables and functions are named a b c and entire code blocks are put into a single line and your code utilises tricky not-obvious features to show off that you know X programming language really well! also each function that you write has to do a very specific thing because if your function does more various things its more POWERFUL
take a read on this article, ive found it while trying to learn JS but it generally applies to any language. that article abuses sarcasm/irony HEAVILY but since you end your forum posts with "/s" rather often, you'll understand //forums.everybodyedits.com/img/smilies/cool

i like this one too


suddenly random sig change

Offline

Wooted by:

#8 2018-09-15 10:44:15, last edited by daneeko (2018-09-15 10:50:36)

daneeko
Member
From: EE Universe
Joined: 2015-02-20
Posts: 2,245

Re: What do you consider "good code" and what "spaghetti code"?

just starting to learn c# with sololearn and i made a lil calculator

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Please assign a value to x");
            int x = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Please assign a value to y");
            int y = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("You got the sum of {0}", x+y);
            Console.WriteLine("Press enter to exit.");
            Console.ReadLine();
        }
    }
}

UzI5nBc.png

Offline

#9 2018-09-15 11:54:21

soniiiety
Member
From: peaceful dojo
Joined: 2016-02-10
Posts: 1,747

Re: What do you consider "good code" and what "spaghetti code"?

is this actual code or?

CONTENT WARNING

Offline

Wooted by: (3)

#10 2018-09-15 15:47:51, last edited by drunkbnu (2018-09-15 15:50:32)

drunkbnu
Formerly HG
Joined: 2017-08-16
Posts: 2,306

Re: What do you consider "good code" and what "spaghetti code"?

soniiiety wrote:

is this actual code or?

CONTENT WARNING

128100fb0b658d993dffffca20273ed6.png

I literally have no idea at all how you could bring "hepatitis" to a clearly programming-related topic.

Offline

#11 2018-09-15 16:57:38

Anatoly
Guest

Re: What do you consider "good code" and what "spaghetti code"?

HG wrote:
soniiiety wrote:

is this actual code or?

CONTENT WARNING

https://cdn.discordapp.com/attachments/ … 273ed6.png

I literally have no idea at all how you could bring "hepatitis" to a clearly programming-related topic.

I see you love hitting your face.

Wooted by:

#12 2018-09-15 17:09:44

Vitalijus
Member
From: Lithuania
Joined: 2015-02-15
Posts: 1,384
Website

Re: What do you consider "good code" and what "spaghetti code"?

Good code should have capital letters, numbers, lowercase letters and various symbols. Bad / spaghetti code is something out of numbers only, 1111 for example, because that's very easy to guess. //forums.everybodyedits.com/img/smilies/smile


wn7I7Oa.png

Offline

#13 2018-09-15 18:55:40

TaskManager
Formerly maxi123
From: i really should update this
Joined: 2015-03-01
Posts: 9,460

Re: What do you consider "good code" and what "spaghetti code"?

Vitalijus wrote:

Bad / spaghetti code is something out of numbers only, 1111 for example

That isn't bad code, that was literally the only way to code back in 1950s


i8SwC8p.png
signature by HG, profile picture by bluecloud, thank!!
previous signature by drstereos

Offline

#14 2018-09-15 19:49:58

Vitalijus
Member
From: Lithuania
Joined: 2015-02-15
Posts: 1,384
Website

Re: What do you consider "good code" and what "spaghetti code"?

TaskManager wrote:
Vitalijus wrote:

Bad / spaghetti code is something out of numbers only, 1111 for example

That isn't bad code, that was literally the only way to code back in 1950s

I remember putting code as VITALIJUS back before the WWII and Pipec's appearance into EE.


wn7I7Oa.png

Offline

Vitalijus1537037398724696

Board footer

Powered by FluxBB

[ Started around 1713507916.5782 - Generated in 0.075 seconds, 10 queries executed - Memory usage: 1.67 MiB (Peak: 1.89 MiB) ]