|
45 | 45 | "oldApproach": "String Concatenation", |
46 | 46 | "modernApproach": "Text Blocks", |
47 | 47 | "oldCode": "String json = \"{\\n\" +\n \" \\\"name\\\": \\\"Duke\\\",\\n\" +\n \" \\\"age\\\": 30\\n\" +\n \"}\";", |
48 | | - "modernCode": "String json = \"\"\"\n {\n \"name\": \"Duke\",\n \"age\": 30\n }\n \"\"\";", |
| 48 | + "modernCode": "String json = \"\"\"\n {\n \"name\": \"Duke\",\n \"age\": 30\n }\"\"\";", |
49 | 49 | "summary": "Write multiline strings naturally with triple-quote text blocks.", |
50 | 50 | "explanation": "Text blocks let you write multiline strings exactly as they appear. No more escaping quotes or adding \\n. The compiler strips incidental indentation automatically.", |
51 | 51 | "whyModernWins": [ |
|
1133 | 1133 | "oldApproach": "Escaped Strings", |
1134 | 1134 | "modernApproach": "Text Blocks", |
1135 | 1135 | "oldCode": "String sql =\n \"SELECT u.name, u.email\\n\" +\n \"FROM users u\\n\" +\n \"WHERE u.active = true\\n\" +\n \"ORDER BY u.name\";", |
1136 | | - "modernCode": "String sql = \"\"\"\n SELECT u.name, u.email\n FROM users u\n WHERE u.active = true\n ORDER BY u.name\n \"\"\";", |
| 1136 | + "modernCode": "String sql = \"\"\"\n SELECT u.name, u.email\n FROM users u\n WHERE u.active = true\n ORDER BY u.name\"\"\";", |
1137 | 1137 | "summary": "Write SQL, JSON, and HTML as they actually look.", |
1138 | 1138 | "explanation": "Text blocks make embedded languages readable. Copy SQL from your database tool and paste it directly. The closing delimiter position controls indentation stripping.", |
1139 | 1139 | "whyModernWins": [ |
|
2425 | 2425 | "oldApproach": "SimpleDateFormat", |
2426 | 2426 | "modernApproach": "DateTimeFormatter", |
2427 | 2427 | "oldCode": "// Not thread-safe!\nSimpleDateFormat sdf =\n new SimpleDateFormat(\"yyyy-MM-dd\");\nString formatted = sdf.format(date);\n// Must synchronize for concurrent use", |
2428 | | - "modernCode": "DateTimeFormatter fmt =\n DateTimeFormatter.ofPattern(\n \"yyyy-MM-dd\");\nString formatted =\n LocalDate.now().format(fmt);\n// Thread-safe, immutable", |
| 2428 | + "modernCode": "DateTimeFormatter fmt =\n DateTimeFormatter.ofPattern(\n \"uuuu-MM-dd\");\nString formatted =\n LocalDate.now().format(fmt);\n// Thread-safe, immutable", |
2429 | 2429 | "summary": "Format dates with thread-safe, immutable DateTimeFormatter.", |
2430 | 2430 | "explanation": "DateTimeFormatter is immutable and thread-safe, unlike SimpleDateFormat. It can be stored as a constant and shared. Predefined formatters like ISO_LOCAL_DATE are available for common formats.", |
2431 | 2431 | "whyModernWins": [ |
|
0 commit comments