This repository has been archived by the owner on Sep 24, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Code Style
William Oldham edited this page Mar 10, 2019
·
3 revisions
This project follows a set code style across all of the projects. In general, we adhere to the Google code style for Java but in some cases we have our own additions or modifications.
- All files have a copyright statement at the top:
If you use IntelliJ, you can setup a copyright template using the placeholder
/* * Copyright (c) {year} CascadeBot. All rights reserved. * Licensed under the MIT license. */
$today.year
for the year. This will automatically preface new files with the right copyright notice. - In contrast to 4.1.1, we allow the use of single line
if
statements as long as they are not part of a multi-block statement. If the statement consists of multipleif
branches or anelse
block then braces are used. - We're not savages so, for that reason, we use four spaces instead of two. In reference to 4.2.
- As per 2.3.3, we use unicode escapes coupled with a explanatory comment.
- We add an additional blank line after the class header for clarity i.e. a line after
public class ClassName {
. - We also add a blank line before the closing brace of a class.
- As per 3.1.1, wildcard imports are not used.
- While we adhere to 4.1.3, empty blocks are not to be used without good reason. With any empty block, an appropriate comment explaining why the block is empty is required.
- In contrast to 4.4, we do not have a mandatory line limit. We ask that code-writers use their common sense to determine when a line is too long. Lines over 120-130 characters long should be reviewed to see if they can be line-wrapped. As stated before however, this is not required.
- Use the guidelines at 4.5 to determine how to line-wrap.
- Variables, fields and parameters should all be given explanatory names. Having nonsensical names is not allowed!
/*
* Copyright (c) 2019 CascadeBot. All rights reserved.
* Licensed under the MIT license.
*/
package com.cascadebot.cascadebot.commands.developer;
import com.cascadebot.cascadebot.commandmeta.CommandContext;
import com.cascadebot.cascadebot.commandmeta.ICommandRestricted;
import com.cascadebot.cascadebot.commandmeta.Module;
import net.dv8tion.jda.core.entities.Member;
import java.util.Arrays;
public class TestCommand implements ICommandRestricted {
@Override
public void onCommand(Member sender, CommandContext context) {
// Command content
}
@Override
public String command() {
return "test";
}
@Override
public String description() {
return "Command that developers change when testing stuff";
}
@Override
public Module getModule() {
return Module.DEVELOPER;
}
}
package com.cascadebot.cascadebot.commands.developer;
import com.cascadebot.cascadebot.commandmeta.*;
import net.dv8tion.jda.core.entities.Member;
import java.util.Arrays;
public class testcommand implements ICommandRestricted {
public void onCommand(Member s,CommandContext c)
{
//Command content
}
public String command( )
{
return "test";
}
public String description( )
{
return "Command that developers change when testing stuff";
}
public Module getModule( )
{
return Module.DEVELOPER;
}
}