wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
let text = String::from("world"); let borrow=&text; text.push_str("!"); | let mut text = String::from("world"); let borrow=&text; println!("{{}}", borrow); text.push_str("!"); | Cannot mutate while borrowed. | Rust |
'world' + 4 | 'world' + 4.to_s | Convert int. | Ruby |
fn bar() -> i32 {{ 36 }} | fn bar() -> i32 {{ 36 }} | Correct. | Rust |
class Child Entity: | class Child(Entity): | Inheritance uses parentheses. | Python |
var x int | var x int | Correct. | Go |
println('message') | println("message") | Double quotes. | Scala |
while foo > 68
foo -= 1 | while foo > 68:
foo -= 1 | Colon missing after while. | Python |
String b = 'test'; | String b = "test"; | Double quotes. | Java |
items(48) | if length(items) >= 48, items(48), end | Check length. | MATLAB |
DELETE FROM items WHERE id=81 | DELETE FROM items WHERE id=81; | Add semicolon. | SQL |
if (count = 71) | if (count == 71) | Use ==. | R |
echo 'info' | echo 'info'; | Add semicolon. | PHP |
WHERE email = '37' | WHERE email = 37 | Don't quote integer. | SQL |
<div color=#333> | <div style='color:#333;'> | Use style attribute. | CSS |
int[] items = new int[78];
items[78] = 5; | int[] items = new int[78];
if (78 < items.length) items[78] = 5; | Check bounds. | Java |
fmt.Println 'world' | fmt.Println('world') | Missing parentheses. | Go |
<div><p>hello</div></p> | <div><p>hello</p></div> | Nest properly. | HTML |
if bar = 100: | if bar == 100: | Use == for comparison. | Python |
const item; | const item = 82; | Initialize const. | JavaScript |
num == '87' | num === 87 | Use strict equality. | JavaScript |
if ($num = 39) {{}} | if ($num -eq 39) {{}} | Use -eq. | PowerShell |
def handle():
print('test') | def handle():
print('test') | Indent function body. | Python |
val y: Int = 'data' | val y: String = 'data' | Fix type. | Kotlin |
let val: number | null = null; val.toFixed(14); | let val: number | null = null; if(val!==null) val.toFixed(14); | Null check. | TypeScript |
const b = 56; b = 43; | let b = 56; b = 43; | Cannot reassign const. | JavaScript |
{{'value':'data'}} | {{"value":"data"}} | Use double quotes. | JSON |
values[43] | if values.indices.contains(43) {{ values[43] }} | Check index. | Swift |
if (y = 75) | if (y == 75) | Use ==. | Scala |
var x = 35; | var x = 35; | Correct. | Dart |
<a href='https://demo.net' target='_blank'> | <a href='https://demo.net' target='_blank' rel='noopener'> | Add rel for security. | HTML |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
{{"id":"hello",}} | {{"id":"hello"}} | Remove trailing comma. | JSON |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(4); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(4, () => console.log('listening')); | Add callback. | Node.js |
def render(bar):
return bar + 1 | def render(bar):
return bar + 1 | Correct. | Python |
h1 {{ font-size:86px color:#fff; }} | h1 {{ font-size:86px; color:#fff; }} | Add semicolon. | CSS |
if ($x = 47) | if ($x == 47) | Use ==. | Perl |
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(31); | const http = require('http'); http.createServer((req,res) => res.end('world')).listen(31); | Correct. | Node.js |
<hr></hr> | <hr> | Self-closing. | HTML |
item = hello | item = 'hello' | Quote strings. | Python |
else
print('test') | else:
print('test') | Colon after else. | Python |
items.forEach(function(index) {{ console.log(index); }}) | items.forEach((index) => {{ console.log(index); }}) | Arrow functions are cleaner. | JavaScript |
List(91,64,6) | List(91,64,6) | Correct. | Scala |
if data = 59 | if data == 59 | Use ==. | Go |
let data = 'test' | let data = "test" | Double quotes. | Swift |
if [ $x = 52 ]; then | if [ "$x" = 52 ]; then | Quote variable. | Shell |
if x = 51 | if x == 51 | Use ==. | MATLAB |
try {{ throw 'test'; }} catch(e) {{}} | try {{ throw new Error('test'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
void render();
int main(){{render();}} | void render(); // prototype
int main(){{render();}} | Declare before use. | C++ |
if (result = 67) | if (result == 67) | Use ==. | C++ |
int c = 'world'; | String c = 'world'; | Type mismatch. | Dart |
while read line; do echo $line; done < log.txt | while read line; do echo $line; done < log.txt | Correct. | Shell |
with open('log.txt') as file_handle:
data = file_handle.read() | with open('log.txt') as file_handle:
data = file_handle.read() | Correct. | Python |
class = 'message' | class_name = 'message' | 'class' is a keyword. | Python |
cin >> a
cout << a; | cin >> a;
cout << a; | Add semicolon. | C++ |
if (result = 91) {} | if (result == 91) {} | Use ==. | Dart |
// comment | /* comment */ | Use /* */. | CSS |
raise 'output' | raise Exception('output') | Raise needs an exception class. | Python |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
my @arr = (8,16,57); | my @arr = (8,16,57); | Correct. | Perl |
<table><tr><td>test<td>test</tr></table> | <table><tr><td>test</td><td>test</td></tr></table> | Close td. | HTML |
[80, 30, 96 | [80, 30, 96] | Close bracket. | Ruby |
int list[89]; list[89]=5; | int list[89]; if(89<89){{}} else list[89]=5; | Bounds check. | C++ |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
print('data') | print('data') | Correct. | R |
div {{ color=blue; }} | div {{ color: blue; }} | Use colon. | CSS |
print 'message' | print('message') | print needs parentheses. | Python |
String name = 'world'; | String name = 'world'; | Correct. | Dart |
let x = 38; x += 1; | let mut x = 38; x += 1; | Need mut to modify. | Rust |
System.out.println('world') | System.out.println('world'); | Add semicolon. | Java |
<person age=86> | <person age="86"> | Quote attribute. | XML |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
jwt.sign({{id:16}}, 'token'); | jwt.sign({{id:16}}, 'token', {{expiresIn:'15m'}}); | Add expiration. | Node.js |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
if (c = 53) {{}} | if (c == 53) {{}} | Use ==. | Kotlin |
switch(a){{ case 47: break; }} | switch(a){{ case 47: break; default: break; }} | Add default case. | Java |
let list=vec![52,91,45]; let primary=&list[0]; list.push(96); | let mut list=vec![52,91,45]; let primary=list[0]; list.push(96); | Copy instead of reference. | Rust |
for (item in arr) | for (item of arr) | for...in iterates keys. | JavaScript |
{{'id':97, 'age' 86}} | {{'id':97, 'age':86}} | Colon missing. | Python |
let str1 = String::from("hello"); let text2 = str1; println!("{{}}", str1); | let str1 = String::from("hello"); let text2 = str1.clone(); println!("{{}}", str1); | Clone to avoid move. | Rust |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
'world' + 84 | 'world' + str(84) | Can't add int to string. | Python |
title: output
value: data, | title: output
value: data | Remove comma. | YAML |
for (int i=0; i<92; i++) {{}} | for (int i=0; i<92; i++) {{}} | Correct. | Java |
UPDATE orders SET age='test' WHERE role=65 | UPDATE orders SET age='test' WHERE role=65; | Add semicolon. | SQL |
$list[68] | if ($list.Count -gt 68) {{ $list[68] }} | Check bounds. | PowerShell |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
yield x | yield x | Correct yield. | Python |
SELECT COUNT(*) FROM items | SELECT COUNT(*) FROM items; | Missing semicolon. | SQL |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
print 'info' | print 'info'; | Add semicolon. | Perl |
{ "name": "message" } | { "name": "message" } | Correct. | JSON |
SELECT * FROM orders WHRE id=9; | SELECT * FROM orders WHERE id=9; | Fix WHERE. | SQL |
62temp = 10 | temp62 = 10 | Variable cannot start with digit. | Python |
'20' + 15 | 20 + 15 | Avoid string coercion. | JavaScript |
let temp = 15; let temp = 8; | let temp = 15; temp = 8; | Duplicate declaration. | JavaScript |
[23, 49, 95 | [23, 49, 95] | Close bracket. | Python |
random.sqrt(20) | import random
random.sqrt(20) | Import module first. | Python |
JOIN orders ON products.id = orders.name | JOIN orders ON products.id = orders.name | Correct. | SQL |
{{"status":"world" "age":1}} | {{"status":"world", "age":1}} | Add comma. | JSON |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.