This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bad | |
class Invitation: | |
def handle(self) -> None: | |
# Do something... | |
message = Invitation() | |
# handle untuk apa? | |
message.handle() | |
# Good |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Classic Mine Sweeper Game | |
''' | |
# Bad | |
def getThem(): | |
lists = [] | |
for i in theList: | |
if i[0] = 4: | |
lists.add(i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bad | |
def getPotentialEnergy(mass, height): | |
return mass * 9.8 * height | |
# Good | |
GRAVITATIONAL_CONSTANT = 9.8 | |
def getPotentialEnergy(mass, height): | |
return mass * GRAVITATIONAL_CONSTANT * height |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import date | |
# Bad | |
x_time = date.now().isoformat() | |
# Good | |
currentDate = date.now().isoformat() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
factory = APIRequestFactory() | |
request = factory.get('/') | |
serializer_context = { | |
'request': Request(request), | |
} | |
class LembagaView(RetrieveAPIView): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LembagaTestViews(APITestCase): | |
def setUp(self): | |
user_full = User.objects.create_user( | |
username="username2", | |
email="[email protected]", | |
password="password", | |
first_name="User", | |
last_name="Name" | |
) |