Skip to content

Instantly share code, notes, and snippets.

# Bad
class Invitation:
def handle(self) -> None:
# Do something...
message = Invitation()
# handle untuk apa?
message.handle()
# Good
def invitation(user):
# ...
# Bad
def invite_supervisor_lembaga(lists_supervisor_lembaga: List[SupervisorLembaga]):
'''
Filter supervisor lembaga yang aktif dan kirim undangan
'''
for supevisor_lembaga in lists_supervisor_lembaga:
if supervisor_lembaga.active:
# Bad
def create_user_mahasiswa(self, name, username, student_no, telephone_num, gender):
self.name = name
self.username = username
self.student_no = student_no
self.telephone_num = telephone_num
self.gender = gender
# Good
'''
Classic Mine Sweeper Game
'''
# Bad
def getThem():
lists = []
for i in theList:
if i[0] = 4:
lists.add(i)
# Bad (not consistent variable and function name)
@api_view(["GET"])
@permission_classes([IsAuthenticated])
def get_all_mahasiswa(request):
mahasiswa = Mahasiswa.objects.all()
json_mahasiswa = MahasiswaDetailSerializer(mahasiswa, many=True)
return Response(json_mahasiswa.data)
@api_view(["GET"])
@permission_classes([IsAuthenticated])
# Bad
def getPotentialEnergy(mass, height):
return mass * 9.8 * height
# Good
GRAVITATIONAL_CONSTANT = 9.8
def getPotentialEnergy(mass, height):
return mass * GRAVITATIONAL_CONSTANT * height
from rest_framework import serializer
# Bad (if you search "result" maybe the related result more than 100 occurence)
result = serializer.serialize(data_mahasiswa, 100)
# Good
result_json_mahasiswa = serializer.serialize(data_mahasiswa, 100)
from datetime import date
# Bad
x_time = date.now().isoformat()
# Good
currentDate = date.now().isoformat()
...
factory = APIRequestFactory()
request = factory.get('/')
serializer_context = {
'request': Request(request),
}
class LembagaView(RetrieveAPIView):
class LembagaTestViews(APITestCase):
def setUp(self):
user_full = User.objects.create_user(
username="username2",
email="username2@email.com",
password="password",
first_name="User",
last_name="Name"
)