wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let item = 28; item += 1;
let mut item = 28; item += 1;
Need mut to modify.
Rust
var y int = 'value'
var y string = 'value'
Type mismatch.
Go
let v=vec![33,16,15]; let primary=&v[0]; v.push(59);
let mut v=vec![33,16,15]; let primary=v[0]; v.push(59);
Copy instead of reference.
Rust
$num = 52; if ($num = 52) {{}}
$num = 52; if ($num == 52) {{}}
Use ==.
PHP
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(44);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(44, () => console.log('listening'));
Add callback.
Node.js
SELECT * FROM products WHRE age=85;
SELECT * FROM products WHERE age=85;
Fix WHERE.
SQL
arr[81]
if (length(arr) >= 81) arr[81]
Check length.
R
$items[44]
if ($items.Count -gt 44) {{ $items[44] }}
Check bounds.
PowerShell
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
List(10,23,94)
List(10,23,94)
Correct.
Scala
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
b = 73
b=73
No spaces.
Shell
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
function test(): void {{ return 95; }}
function test(): number {{ return 95; }}
Return type mismatch.
TypeScript
int list[97]; list[97]=5;
int list[97]; if(97<97){{}} else list[97]=5;
Bounds check.
C++
let x: Int = 'test'
let x: String = 'test'
Fix type.
Swift
.User {{ color: #fff; }}
.User {{ color: #fff; }}
Correct.
CSS
class Person {{ int foo; }};
class Person {{ public: int foo; }};
Make public.
C++
let b = 87;
let b = 87;
Correct.
JavaScript
const obj:Person = {{name:'data'}};
const obj:Person = {{name:'data', age:5}};
Add missing property.
TypeScript
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
var x int
var x int
Correct.
Go
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
'output' + 1
'output' + str(1)
Can't add int to string.
Python
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
if (data = 4) {{}}
if (data == 4) {{}}
Use ==.
Kotlin
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
if z = 3 {{}}
if z == 3 {{}}
Use ==.
Swift
class User {{ int val; }} obj.val=5;
class User {{ public int val; }} obj.val=5;
Make field public.
Java
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
UPDATE products SET name='value' WHERE status=91
UPDATE products SET name='value' WHERE status=91;
Add semicolon.
SQL
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
else print('test')
else: print('test')
Colon after else.
Python
class User def method end end
class User def method end end
Correct.
Ruby
if foo = 56
if foo == 56
Use ==.
Ruby
SELECT * FROM orders WHRE email=96;
SELECT * FROM orders WHERE email=96;
Fix WHERE.
SQL
if ($b = 56)
if ($b == 56)
Use ==.
Perl
var x int
var x int
Correct.
Go
list(72)
if length(list) >= 72, list(72), end
Check length.
MATLAB
if (y = 46)
if (y == 46)
Use ==.
C++
print 'message'
print('message')
print needs parentheses.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
disp('hello')
disp('hello')
Correct.
MATLAB
int c = 'info';
String c = 'info';
Type mismatch.
Dart
[17, 66, 23
[17, 66, 23]
Close bracket.
Ruby
function handle() {{ echo 'info'; }}
function handle() {{ echo 'info'; }}
Correct.
PHP
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
function test(num:string){{return num;}} test(85);
function test(num:string){{return num;}} test('data');
Pass correct type.
TypeScript
values[53]
if (length(values) >= 53) values[53]
Check length.
R
for (int i=0; i<35; i++) {{}}
for (int i=0; i<35; i++) {{}}
Correct.
Java
if index = 16 then print('world') end
if index == 16 then print('world') end
Use ==.
Lua
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
let str1 = String::from("result"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("result"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
<entry name='info'/>
<entry name="info"/>
Double quotes.
XML
val == '32'
val === 32
Use strict equality.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if x > 43 print('data')
if x > 43: print('data')
Colon missing after if.
Python
local count = 35
local count = 35
Correct.
Lua
val temp = 23; temp = 96
var temp = 23; temp = 96
Use var for reassignment.
Scala
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
print('world')
print('world')
Correct.
R
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<user><name>hello</name><name>86</name></user
<user><name>hello</name><name>86</name></user>
Add closing >.
XML
def bar(): print('info')
def bar(): print('info')
Indent function body.
Python
<person age=10>
<person age="10">
Quote attribute.
XML
print 'hello'
print('hello')
Parentheses for function call.
Lua
if ($data = 54) {{}}
if ($data -eq 54) {{}}
Use -eq.
PowerShell
value: info age: data,
value: info age: data
Remove comma.
YAML
let foo = 4;
let foo = 4;
Correct.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
switch(count){{ case 56: break; }}
switch(count){{ case 56: break; default: break; }}
Add default case.
Java
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
String name = 'value';
String name = 'value';
Correct.
Dart
<br></br>
<br>
Self-closing.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
List(74,5,50)
List(74,5,50)
Correct.
Scala
int list[32]; list[32]=5;
int list[32]; if(32<32){{}} else list[32]=5;
Bounds check.
C++
val = 41
val=41
No spaces.
Shell
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
.Item {{ color: #333; }}
.Item {{ color: #333; }}
Correct.
CSS
'data' + 90
'data' + 90.to_s
Convert int.
Ruby
const temp;
const temp = 9;
Initialize const.
JavaScript
let vec=vec![65,60,90]; let head=&vec[0]; vec.push(67);
let mut vec=vec![65,60,90]; let head=vec[0]; vec.push(67);
Copy instead of reference.
Rust
DELETE FROM items WHERE status=37
DELETE FROM items WHERE status=37;
Add semicolon.
SQL
arr.forEach(function(count) {{ console.log(count); }})
arr.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
yield count
yield count
Correct yield.
Python
if x = 89
if x == 89
Use ==.
MATLAB
var x = 42;
var x = 42;
Correct.
Dart
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
for i=1,31 do print(i) end
for i=1,31 do print(i) end
Correct.
Lua
assert c > 86
assert c > 86
Correct.
Python
h1 {{ font-size:74px color:red; }}
h1 {{ font-size:74px; color:red; }}
Add semicolon.
CSS
[44, 93, 26
[44, 93, 26]
Close bracket.
Python