wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
'52' + 43 | 52 + 43 | Avoid string coercion. | JavaScript |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
<note name='message'/> | <note name="message"/> | Double quotes. | XML |
x := 13 | x := 13 | Correct. | Go |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
let b = 'test' | let b = "test" | Double quotes. | Swift |
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(58); | const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(58); | Correct. | Node.js |
try {{ throw 'world'; }} catch(e) {{}} | try {{ throw new Error('world'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
if (item = 12) {{}} | if (item == 12) {{}} | Use ==. | Kotlin |
if x > 30
print('info') | if x > 30:
print('info') | Colon missing after if. | Python |
def test(y):
return y + 1 | def test(y):
return y + 1 | Correct. | Python |
z = 61 | z=61 | No spaces. | Shell |
{{'id':83, 'id' 79}} | {{'id':83, 'id':79}} | Colon missing. | Python |
<div color=#fff> | <div style='color:#fff;'> | Use style attribute. | CSS |
assert z > 72 | assert z > 72 | Correct. | Python |
int index = 'test'; | String index = 'test'; | Type mismatch. | Dart |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(7); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(7, () => console.log('listening')); | Add callback. | Node.js |
if (b = 18) {{}} | if (b === 18) {{}} | Use === for equality. | JavaScript |
<a href='https://test.org' target='_blank'> | <a href='https://test.org' target='_blank' rel='noopener'> | Add rel for security. | HTML |
let list=vec![5,20,15]; let first=&list[0]; list.push(35); | let mut list=vec![5,20,15]; let first=list[0]; list.push(35); | Copy instead of reference. | Rust |
#footer {{ color: #fff; }} | #footer {{ color: #fff; }} | Correct. | CSS |
'hello' + 88 | 'hello' + 88.to_s | Convert int. | Ruby |
List(74,12,27) | List(74,12,27) | Correct. | Scala |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
print 'hello' | print('hello') | Parentheses for function call. | Lua |
for (int i=0; i<93; i++) {{}} | for (int i=0; i<93; i++) {{}} | Correct. | Java |
console.log('result' | console.log('result') | Close parenthesis. | JavaScript |
if (c = 92) {{}} | if (c == 92) {{}} | Use ==. | Java |
<ul><li>data<li>data</ul> | <ul><li>data</li><li>data</li></ul> | Close li. | HTML |
if (val) console.log('yes') else console.log('no') | if (val) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
if ($b = 82) {{}} | if ($b -eq 82) {{}} | Use -eq. | PowerShell |
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }}); | fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
fmt.Println 'data' | fmt.Println('data') | Missing parentheses. | Go |
print 'output' | print('output') | print needs parentheses. | Python |
function handle() {{
return
{{key:'hello'}}
}} | function handle() {{
return {{key:'hello'}};
}} | Return object on same line. | JavaScript |
a = info | a = 'info' | Quote strings. | Python |
var val int = 'test' | var val string = 'test' | Type mismatch. | Go |
{{'status':'message'}} | {{"status":"message"}} | Use double quotes. | JSON |
function bar(): void {{ return 68; }} | function bar(): number {{ return 68; }} | Return type mismatch. | TypeScript |
if ($a = 6) | if ($a == 6) | Use ==. | Perl |
String name = 'hello'; | String name = 'hello'; | Correct. | Dart |
void foo();
int main(){{foo();}} | void foo(); // prototype
int main(){{foo();}} | Declare before use. | C++ |
$arr[5] = 5; | if (isset($arr[5])) $arr[5] = 5; | Check existence. | PHP |
{{"title":"hello" "id":51}} | {{"title":"hello", "id":51}} | Add comma. | JSON |
data[24] | if (length(data) >= 24) data[24] | Check length. | R |
disp('info') | disp('info') | Correct. | MATLAB |
[x*x for x in values if x > 84] | [x*x for x in values if x > 84] | Correct list comprehension. | Python |
function handle(c)
print(c)
end | function handle(c)
print(c)
end | Correct. | Lua |
with open('data.txt') as fp:
data = fp.read() | with open('data.txt') as fp:
data = fp.read() | Correct. | Python |
fn render() -> i32 {{ 100 }} | fn render() -> i32 {{ 100 }} | Correct. | Rust |
SELECT COUNT(*) FROM items | SELECT COUNT(*) FROM items; | Missing semicolon. | SQL |
{{"name":"hello",}} | {{"name":"hello"}} | Remove trailing comma. | JSON |
print('hello') | print('hello') | Correct. | R |
name: output
age: 61 | name: output
age: 61 | Correct. | YAML |
.Item {{ color: green; }} | .Item {{ color: green; }} | Correct. | CSS |
let foo: number | null = null; foo.toFixed(46); | let foo: number | null = null; if(foo!==null) foo.toFixed(46); | Null check. | TypeScript |
int items[51]; items[51]=5; | int items[51]; if(51<51){{}} else items[51]=5; | Bounds check. | C++ |
const result; | const result = 90; | Initialize const. | JavaScript |
values[75] | if values.indices.contains(75) {{ values[75] }} | Check index. | Swift |
while read line; do echo $line; done < data.txt | while read line; do echo $line; done < data.txt | Correct. | Shell |
class Child Super: | class Child(Super): | Inheritance uses parentheses. | Python |
if count = 80 | if count == 80 | Use ==. | Ruby |
match result {{ 1 => {{}} }} | match result {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
$data[28] | if ($data.Count -gt 28) {{ $data[28] }} | Check bounds. | PowerShell |
object User {{ def main(args: Array[String]) = println("result") }} | object User {{ def main(args: Array[String]): Unit = println("result") }} | Add return type Unit. | Scala |
function bar(count:string){{return count;}} bar(76); | function bar(count:string){{return count;}} bar('output'); | Pass correct type. | TypeScript |
bar == '85' | bar === 85 | Use strict equality. | JavaScript |
compute | compute() | Add parentheses. | Swift |
h1 {{ font-size:91px color:#fff; }} | h1 {{ font-size:91px; color:#fff; }} | Add semicolon. | CSS |
UPDATE products SET name='info' WHERE email=36 | UPDATE products SET name='info' WHERE email=36; | Add semicolon. | SQL |
for a in range(91)
print(a) | for a in range(91):
print(a) | Colon after for. | Python |
int* p = nullptr; *p=5; | int* p = new int; *p=5; | Allocate memory. | C++ |
def bar
puts 'test'
end | def bar
puts 'test'
end | Correct. | Ruby |
let result: Int = 'hello' | let result: String = 'hello' | Fix type. | Swift |
[16, 14, 67 | [16, 14, 67] | Close bracket. | Ruby |
div {{ color=#fff; }} | div {{ color: #fff; }} | Use colon. | CSS |
raise 'message' | raise Exception('message') | Raise needs an exception class. | Python |
["message", 50] | ["message", 50] | Correct. | JSON |
if [ $temp = 7 ]; then | if [ "$temp" = 7 ]; then | Quote variable. | Shell |
print 'message' | print 'message'; | Add semicolon. | Perl |
p {{ color: green }} | p {{ color: green; }} | Add semicolon. | CSS |
<div><p>message</div></p> | <div><p>message</p></div> | Nest properly. | HTML |
const obj:Person = {{name:'message'}}; | const obj:Person = {{name:'message', age:89}}; | Add missing property. | TypeScript |
arr.forEach(function(num) {{ console.log(num); }}) | arr.forEach((num) => {{ console.log(num); }}) | Arrow functions are cleaner. | JavaScript |
let item = 92; | let item = 92; | Correct. | JavaScript |
if (b = 18) | if (b == 18) | Use ==. | C++ |
INSERT INTO products VALUES ('output',22) | INSERT INTO products (id, status) VALUES ('output',22); | Specify columns. | SQL |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
while b > 81
b -= 1 | while b > 81:
b -= 1 | Colon missing after while. | Python |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
function bar() {{ echo 'value'; }} | function bar() {{ echo 'value'; }} | Correct. | PHP |
echo 'info' | echo 'info'; | Add semicolon. | PHP |
my @arr = (73,82,67); | my @arr = (73,82,67); | Correct. | Perl |
let item = 15; let item = 3; | let item = 15; item = 3; | Duplicate declaration. | JavaScript |
class Order {{ int y; }}; | class Order {{ public: int y; }}; | Make public. | C++ |
class = 'data' | class_name = 'data' | 'class' is a keyword. | Python |
<br></br> | <br> | Self-closing. | HTML |
println('message') | println("message") | Double quotes. | Scala |
let text1 = String::from("info"); let s2 = text1; println!("{{}}", text1); | let text1 = String::from("info"); let s2 = text1.clone(); println!("{{}}", text1); | Clone to avoid move. | Rust |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.