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
public const string FORMAT_JPG = "JPG"; | |
public const string FORMAT_GIF = "GIF"; | |
public const string FORMAT_PNG = "PNG"; | |
// OR | |
public enum ImageFormat | |
{ | |
JPG, | |
GIF, |
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
public const FORMAT_JPG= 1; | |
public const FORMAT_GIF= 2; | |
public const FORMAT_PNG = 3; |
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
<? | |
$sourceFile = 'C:\temp\source.txt'; | |
$destination = 'C:\temp\destination.txt'; | |
$copyWasSuccessful = copy($sourceFile, $destination); // true | |
$destinationFileExists = file_exists($destination); // true | |
$sourceFile = 'C:\temp\source.txt'; | |
$destination = 'C:\temp\destination :txt'; | |
// The filename is simplified |
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
<? | |
$sourceFile = 'C:\temp\source.txt'; | |
$destination = 'C:\temp\destination :txt'; | |
// The filename is simplified | |
// and might come from a programmatic construction | |
$copyWasSuccessful = copy($sourceFile, $destination); | |
if (!$copyWasSuccessful || !$file_exists($destination)) { | |
// Don't trust the function result. Handle the postcondition error |
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 CreditCard { | |
private String number; | |
private MonthOfYear expiryDate; | |
// expiryDate is the role | |
// MonthOfYear is the type | |
} | |
class MonthOfYear { | |
private Month month; | |
private Year year; |
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
const pets = '😺🐶😺'; | |
const justDogs = pets.replaceAll('😺', '🐩'); | |
// Or | |
const justDogs = pets.replace(/😺/g, ''); | |
const catsArePresent = justDogs.includes('😺'); | |
// returns false |
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
const pets = '😺🐶😺'; | |
const justDogs = pets.replace('😺', '🐩'); | |
const catsArePresent = justDogs.includes('😺'); | |
// returns true |
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
import java.util.Date; | |
public class CreditCard { | |
private String cardNumber; | |
private Date expiryDate; | |
public CreditCard(String cardNumber, Date expiryDate) { | |
// Not a complete date | |
this.cardNumber = cardNumber; | |
this.expiryDate = expiryDate; |
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
public class CreditCard { | |
private String cardNumber; | |
private int expiryMonth; | |
private int expiryYear; | |
public CreditCard(String cardNumber, int expiryMonth, int expiryYear) { | |
this.cardNumber = cardNumber; | |
this.expiryMonth = expiryMonth; | |
this.expiryYear = expiryYear; | |
// No validations on number ranges? |
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 calculate(mathOperand, firstArgument, secondArgument): | |
if mathOperand == '+': | |
return firstArgument + secondArgument | |
elif mathOperand == '-': | |
return firstArgument - secondArgument | |
elif mathOperand == '*': | |
return firstArgument * secondArgument | |
elif mathOperand == '/': | |
if secondArgument != 0: | |
return firstArgument / secondArgument |
NewerOlder