Careeroza
Real World Example
Comments in a Production Codebase
In companies, code is read far more often than it is written. A typical Java service at a fintech like Razorpay or PhonePe documents public methods with Javadoc and uses short comments for business rules that are not obvious.
Example
/**
* Calculates convenience fees for a ticket booking.
*/
public class Main {
/**
* Returns the convenience fee for one booking.
* @param ticketPrice price of the ticket in rupees
* @return fee in rupees
*/
static double convenienceFee(double ticketPrice) {
// Business rule (Finance team, 2024): 2% fee, minimum Rs. 10, maximum Rs. 50
double fee = ticketPrice * 0.02;
if (fee < 10) fee = 10;
if (fee > 50) fee = 50;
return fee;
}
public static void main(String[] args) {
System.out.println(convenienceFee(200)); // small ticket -> minimum fee
System.out.println(convenienceFee(1500)); // 2% of 1500
System.out.println(convenienceFee(9000)); // capped at maximum
}
}Output
10.0 30.0 50.0