wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
val num = 75; num = 3
var num = 75; num = 3
Use var for reassignment.
Scala
if foo = 22
if foo == 22
Use ==.
MATLAB
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (count = 81) {}
if (count == 81) {}
Use ==.
Dart
$bar = 8; if ($bar = 8) {{}}
$bar = 8; if ($bar == 8) {{}}
Use ==.
PHP
items[25]
if items.indices.contains(25) {{ items[25] }}
Check index.
Swift
print 'test'
print('test')
print needs parentheses.
Python
if temp = 79 {{}}
if temp == 79 {{}}
Use ==.
Swift
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
String num = 'world';
String num = "world";
Double quotes.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
<hr></hr>
<hr>
Self-closing.
HTML
const num = 74; num = 26;
let num = 74; num = 26;
Cannot reassign const.
JavaScript
UPDATE products SET email='data' WHERE role=54
UPDATE products SET email='data' WHERE role=54;
Add semicolon.
SQL
if (foo = 44)
if (foo == 44)
Use ==.
C++
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(69);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(69);
Correct.
Node.js
if (result = 66)
if (result == 66)
Use ==.
Scala
local z = 71
local z = 71
Correct.
Lua
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
a > 49 & b < 70
a > 49 and b < 70
Use 'and' not '&'.
Python
val item = 'hello'
val item = "hello"
Double quotes.
Kotlin
x := 59
x := 59
Correct.
Go
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
<user><age>hello</age><age>24</age></user
<user><age>hello</age><age>24</age></user>
Add closing >.
XML
int[] list = new int[50]; list[50] = 5;
int[] list = new int[50]; if (50 < list.length) list[50] = 5;
Check bounds.
Java
if foo = 41 then print('data') end
if foo == 41 then print('data') end
Use ==.
Lua
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
let vec=vec![41,48,29]; let head=&vec[0]; vec.push(1);
let mut vec=vec![41,48,29]; let head=vec[0]; vec.push(1);
Copy instead of reference.
Rust
def bar(): print('output')
def bar(): print('output')
Indent function body.
Python
if (temp = 28)
if (temp == 28)
Use ==.
R
index = result
index = 'result'
Quote strings.
Python
const person:Person = {{name:'hello'}};
const person:Person = {{name:'hello', age:72}};
Add missing property.
TypeScript
int list[61]; list[61]=5;
int list[61]; if(61<61){{}} else list[61]=5;
Bounds check.
C++
SELECT id role FROM users;
SELECT id, role FROM users;
Add comma.
SQL
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
print('result')
print('result')
Correct.
R
let count: i32 = "world";
let count: &str = "world";
Type mismatch.
Rust
jwt.sign({{id:50}}, 'key');
jwt.sign({{id:50}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
.Person {{ color: #333; }}
.Person {{ color: #333; }}
Correct.
CSS
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
if data = 81
if data == 81
Use ==.
Go
let val: number | null = null; val.toFixed(53);
let val: number | null = null; if(val!==null) val.toFixed(53);
Null check.
TypeScript
data(79)
if length(data) >= 79, data(79), end
Check length.
MATLAB
<person age=20>
<person age="20">
Quote attribute.
XML
{{"status":"info",}}
{{"status":"info"}}
Remove trailing comma.
JSON
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let data = 52; let data = 39;
let data = 52; data = 39;
Duplicate declaration.
JavaScript
cin >> a;
int a; cin >> a;
Declare variable.
C++
yield index
yield index
Correct yield.
Python
INSERT INTO orders VALUES ('info',12)
INSERT INTO orders (id, email) VALUES ('info',12);
Specify columns.
SQL
$data[2]
if ($data.Count -gt 2) {{ $data[2] }}
Check bounds.
PowerShell
if (result) console.log('yes') else console.log('no')
if (result) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let str1 = String::from("test"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("test"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
status: test name: hello,
status: test name: hello
Remove comma.
YAML
30item = 10
item30 = 10
Variable cannot start with digit.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
[9, 86, 19
[9, 86, 19]
Close bracket.
Ruby
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
const num;
const num = 9;
Initialize const.
JavaScript
["world", 2]
["world", 2]
Correct.
JSON
// comment
/* comment */
Use /* */.
CSS
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
result = 9
result=9
No spaces.
Shell
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
if x = 88
if x == 88
Use ==.
Ruby
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
if c > 70 print('value')
if c > 70: print('value')
Colon missing after if.
Python
def process(x): return x + 1
def process(x): return x + 1
Correct.
Python
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
fn foo() -> i32 {{ 47 }}
fn foo() -> i32 {{ 47 }}
Correct.
Rust
<br></br>
<br>
Self-closing.
HTML
function render(): void {{ return 33; }}
function render(): number {{ return 33; }}
Return type mismatch.
TypeScript
class Person {{ int b; }} obj.b=5;
class Person {{ public int b; }} obj.b=5;
Make field public.
Java
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
let count = 56; count += 1;
let mut count = 56; count += 1;
Need mut to modify.
Rust
print 'info'
print 'info';
Add semicolon.
Perl
'value' + 83
'value' + 83.to_s
Convert int.
Ruby
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
for z in range(49) print(z)
for z in range(49): print(z)
Colon after for.
Python
let x: number = 'info';
let x: string = 'info';
Fix type.
TypeScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
h1 {{ font-size:93px color:red; }}
h1 {{ font-size:93px; color:red; }}
Add semicolon.
CSS
function foo() {{ echo 'world'; }}
function foo() {{ echo 'world'; }}
Correct.
PHP
my @arr = (58,74,82);
my @arr = (58,74,82);
Correct.
Perl
if ($b = 32) {{}}
if ($b -eq 32) {{}}
Use -eq.
PowerShell
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
function test() {{ return {{key:'message'}} }}
function test() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP