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.
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.
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!
*u stinky*
Offline
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
Offline
Simple is better than complex.
sometimes complex is better to make it work
thanks hg for making this much better and ty for my avatar aswell
Offline
XxAtillaxX wrote:Simple is better than complex.
sometimes complex is better to make it work
Have you tried to program?
Offline
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 )
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
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
i like this one too
suddenly random sig change
Offline
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();
}
}
}
Offline
is this actual code or?
Offline
is this actual code or?
▼CONTENT WARNING
I literally have no idea at all how you could bring "hepatitis" to a clearly programming-related topic.
Offline
soniiiety wrote:is this actual code or?
▼CONTENT WARNINGhttps://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.
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.
Offline
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
Offline
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.
Offline
[ Started around 1734519178.0556 - Generated in 0.069 seconds, 13 queries executed - Memory usage: 1.69 MiB (Peak: 1.92 MiB) ]