wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
fn handle() -> i32 {{ 1 }}
fn handle() -> i32 {{ 1 }}
Correct.
Rust
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
echo 'result'
echo 'result';
Add semicolon.
PHP
sys.sqrt(94)
import sys sys.sqrt(94)
Import module first.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
if ($y = 18)
if ($y == 18)
Use ==.
Perl
echo hello hello
echo 'hello hello'
Quote to prevent splitting.
Shell
if a > 27 puts 'message'
if a > 27 puts 'message' end
Add 'end'.
Ruby
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
let str1 = String::from("world"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("world"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if x = 26 {{}}
if x == 26 {{}}
Use ==.
Swift
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<note><age>info</age><desc>33</desc></note
<note><age>info</age><desc>33</desc></note>
Add closing >.
XML
val c: Int = 'message'
val c: String = 'message'
Fix type.
Kotlin
function foo() {{ return {{key:'result'}} }}
function foo() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
List(78,63,60)
List(78,63,60)
Correct.
Scala
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
item = 93
item=93
No spaces.
Shell
local temp = 86
local temp = 86
Correct.
Lua
WHERE email = '87'
WHERE email = 87
Don't quote integer.
SQL
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
else print('world')
else: print('world')
Colon after else.
Python
class User {{ int b; }} obj.b=5;
class User {{ public int b; }} obj.b=5;
Make field public.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
int arr[3]; arr[3]=5;
int arr[3]; if(3<3){{}} else arr[3]=5;
Bounds check.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
var x int = 'world'
var x string = 'world'
Type mismatch.
Go
var x int
var x int
Correct.
Go
print('output')
print('output')
Correct.
R
h1 {{ font-size:46px color:red; }}
h1 {{ font-size:46px; color:red; }}
Add semicolon.
CSS
if (b) console.log('yes') else console.log('no')
if (b) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(99);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(99);
Correct.
Node.js
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
test
test()
Add parentheses.
Kotlin
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
var x = 13;
var x = 13;
Correct.
Dart
x := 33
x := 33
Correct.
Go
'data' + 47
'data' + str(47)
Can't add int to string.
Python
<person age=20>
<person age="20">
Quote attribute.
XML
val item = 98; item = 28
var item = 98; item = 28
Use var for reassignment.
Scala
for a in range(88) print(a)
for a in range(88): print(a)
Colon after for.
Python
for i=1,36 do print(i) end
for i=1,36 do print(i) end
Correct.
Lua
// comment
/* comment */
Use /* */.
CSS
{{"status":"test",}}
{{"status":"test"}}
Remove trailing comma.
JSON
item = hello
item = 'hello'
Quote strings.
Python
["hello", 26]
["hello", 26]
Correct.
JSON
class Person {{ int data; }};
class Person {{ public: int data; }};
Make public.
C++
if (count = 9) {{}}
if (count == 9) {{}}
Use ==.
Kotlin
String name = 'value';
String name = 'value';
Correct.
Dart
let v=vec![71,58,19]; let primary=&v[0]; v.push(24);
let mut v=vec![71,58,19]; let primary=v[0]; v.push(24);
Copy instead of reference.
Rust
<ul><li>test<li>test</ul>
<ul><li>test</li><li>test</li></ul>
Close li.
HTML
function bar(item:string){{return item;}} bar(7);
function bar(item:string){{return item;}} bar('test');
Pass correct type.
TypeScript
let a = 100; a += 1;
let mut a = 100; a += 1;
Need mut to modify.
Rust
status: message name: hello,
status: message name: hello
Remove comma.
YAML
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
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
items.forEach(function(c) {{ console.log(c); }})
items.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
.Product {{ color: green; }}
.Product {{ color: green; }}
Correct.
CSS
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if num = 70:
if num == 70:
Use == for comparison.
Python
let num = 54; let num = 58;
let num = 54; num = 58;
Duplicate declaration.
JavaScript
if num = 88
if num == 88
Use ==.
Go
if [ $y = 14 ]; then
if [ "$y" = 14 ]; then
Quote variable.
Shell
let s = String::from("result"); let r=&s; s.push_str("!");
let mut s = String::from("result"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
{{"id":"result" "id":59}}
{{"id":"result", "id":59}}
Add comma.
JSON
SELECT * FROM orders WHRE name=10;
SELECT * FROM orders WHERE name=10;
Fix WHERE.
SQL
<input type='text' value='info'>
<input type='text' value='info' name='status'>
Add name attribute.
HTML
print 'data'
print 'data';
Add semicolon.
Perl
for (int i=0; i<86; i++) {{}}
for (int i=0; i<86; i++) {{}}
Correct.
Java
while num > 83 num -= 1
while num > 83: num -= 1
Colon missing after while.
Python
if (bar = 38)
if (bar == 38)
Use ==.
C++
'output' + 80
'output' + 80.to_s
Convert int.
Ruby
if (x = 75) {{}}
if (x === 75) {{}}
Use === for equality.
JavaScript
arr(67)
if length(arr) >= 67, arr(67), end
Check length.
MATLAB
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
name: test age: 11
name: test age: 11
Correct.
YAML
disp('world')
disp('world')
Correct.
MATLAB
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
foo
foo()
Add parentheses.
Swift
if (x = 46) {}
if (x == 46) {}
Use ==.
Dart
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let index: number | null = null; index.toFixed(74);
let index: number | null = null; if(index!==null) index.toFixed(74);
Null check.
TypeScript
int count = 'value';
String count = 'value';
Type mismatch.
Dart
val foo = 'output'
val foo = "output"
Double quotes.
Kotlin
jwt.sign({{id:79}}, 'secret');
jwt.sign({{id:79}}, 'secret', {{expiresIn:'30m'}});
Add expiration.
Node.js
let foo = 39;
let foo = 39;
Correct.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML