This file contains hidden or 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 Article { | |
final DateTime publishDate; | |
final String title; | |
final String content; | |
Article({ | |
required this.publishDate, | |
required this.title, | |
required this.content, | |
}); |
This file contains hidden or 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 Article { | |
final DateTime date; | |
final String title; | |
final String content; | |
Article({ | |
required this.date, | |
required this.title, | |
required this.content, | |
}); |
This file contains hidden or 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
<?php | |
// Header-based API versioning example | |
// GET /api/primes?limit=12 HTTP/1.1 | |
// Host: eratostenes.com | |
// Accept: application/vnd.myapi.v2+json | |
// NOTICE THE HEADER V2 | |
$acceptHeader = $_SERVER['HTTP_ACCEPT'] ?? ''; |
This file contains hidden or 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
<?php | |
// https://eratostenes.com/api/v2/primes?limit=10 | |
// NOTICE /V2/ | |
// Version 2 is faster! | |
$requestUri = $_SERVER['REQUEST_URI']; | |
if (preg_match('#^/v([0-9]+)/#', $requestUri, $matches)) { | |
$version = $matches[1]; | |
} else { |
This file contains hidden or 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
<?php | |
// Misusing query parameters for versioning | |
// https://eratostenes.com/api/primes?limit=10&version=2 | |
// Version 2 is faster! | |
$version = $_GET['version'] ?? '1'; | |
if ($version === '1') { | |
echo json_encode(['data' => 'Response from API v1']); |
This file contains hidden or 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
<?php | |
class UserService { | |
// Step 1: Identified annotations | |
// (@author, @version, @description, | |
// Step 2: Evaluated their purpose | |
// (metadata, deprecated, todo notes) | |
// Step 3: Removed unnecessary annotations (no value added) | |
// Step 4: Replaced critical annotations | |
// with explicit code (none needed) | |
This file contains hidden or 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
<?php | |
// @author John Wick | |
// @version 3.14 | |
// @description Service for user operations | |
class UserService { | |
/** | |
* @deprecated | |
* @param int $id | |
* @return string | |
*/ |
This file contains hidden or 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 User { | |
public email; | |
private name; | |
// Step 1: Choose consistent indentation (2 spaces) | |
// Step 4: Public methods before private ones | |
constructor(name, email) { | |
this.name = name; | |
this.email = email; | |
} |
This file contains hidden or 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 User{ | |
private name; | |
public email; | |
constructor(name,email) { | |
this.name=name; | |
this.email = email; | |
} | |
private validateEmail() { |
This file contains hidden or 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
interface QueryResult { | |
void display(); | |
} | |
class SelectResult implements QueryResult { | |
public void display() { | |
System.out.println("Fetched rows"); | |
} | |
} |
NewerOlder