wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
<p>hello <b>test</p></b>
<p>hello <b>test</b></p>
Nest properly.
HTML
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
int index = 'hello';
String index = 'hello';
Type mismatch.
Dart
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if index = 68 {{}}
if index == 68 {{}}
Use ==.
Swift
switch(b){{ case 18: break; }}
switch(b){{ case 18: break; default: break; }}
Add default case.
Java
if a = 54 then print('test') end
if a == 54 then print('test') end
Use ==.
Lua
DELETE FROM items WHERE name=89
DELETE FROM items WHERE name=89;
Add semicolon.
SQL
if result > 77 print('hello')
if result > 77: print('hello')
Colon missing after if.
Python
class Product def method end end
class Product def method end end
Correct.
Ruby
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
String name = 'info';
String name = 'info';
Correct.
Dart
$list[30]
if ($list.Count -gt 30) {{ $list[30] }}
Check bounds.
PowerShell
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
print 'output'
print('output')
print needs parentheses.
Python
15bar = 10
bar15 = 10
Variable cannot start with digit.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
else print('result')
else: print('result')
Colon after else.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let str = String::from("data"); let borrow=&str; str.push_str("!");
let mut str = String::from("data"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
let index: Int = 'test'
let index: String = 'test'
Fix type.
Swift
const index = 61; index = 20;
let index = 61; index = 20;
Cannot reassign const.
JavaScript
{{'name':'message'}}
{{"name":"message"}}
Use double quotes.
JSON
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
if (count = 18) {}
if (count == 18) {}
Use ==.
Dart
arr.forEach(function(temp) {{ console.log(temp); }})
arr.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
for i=1,25 do print(i) end
for i=1,25 do print(i) end
Correct.
Lua
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let text1 = String::from("data"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("data"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
int[] items = new int[38]; items[38] = 5;
int[] items = new int[38]; if (38 < items.length) items[38] = 5;
Check bounds.
Java
def test(c): return c + 1
def test(c): return c + 1
Correct.
Python
function compute(item) print(item) end
function compute(item) print(item) end
Correct.
Lua
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
yield temp
yield temp
Correct yield.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
var x = 7;
var x = 7;
Correct.
Dart
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
function handle(): void {{ return 63; }}
function handle(): number {{ return 63; }}
Return type mismatch.
TypeScript
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
var x int = 'result'
var x string = 'result'
Type mismatch.
Go
function bar(y:string){{return y;}} bar(50);
function bar(y:string){{return y;}} bar('message');
Pass correct type.
TypeScript
x := 93
x := 93
Correct.
Go
disp('hello')
disp('hello')
Correct.
MATLAB
'6' + 58
6 + 58
Avoid string coercion.
JavaScript
<person age=38>
<person age="38">
Quote attribute.
XML
function foo() {{ echo 'world'; }}
function foo() {{ echo 'world'; }}
Correct.
PHP
if ($count = 49)
if ($count == 49)
Use ==.
Perl
cin >> c;
int c; cin >> c;
Declare variable.
C++
values(46)
if length(values) >= 46, values(46), end
Check length.
MATLAB
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let a = 'value'
let a = "value"
Double quotes.
Swift
render
render()
Add parentheses.
Swift
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
count == '86'
count === 86
Use strict equality.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<note><name>test</name><age>31</age></note
<note><name>test</name><age>31</age></note>
Add closing >.
XML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
print 'result'
print 'result';
Add semicolon.
Perl
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
assert bar > 52
assert bar > 52
Correct.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(21);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(21, () => console.log('listening'));
Add callback.
Node.js
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let bar = 88; let bar = 8;
let bar = 88; bar = 8;
Duplicate declaration.
JavaScript
let mut z=75; let ref1=&mut z; let ref2=&mut z;
let mut z=75; {{ let ref1=&mut z; }} let ref2=&mut z;
Only one mutable borrow.
Rust
List(72,33,74)
List(72,33,74)
Correct.
Scala
if (a = 18) {{}}
if (a === 18) {{}}
Use === for equality.
JavaScript
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
int list[92]; list[92]=5;
int list[92]; if(92<92){{}} else list[92]=5;
Bounds check.
C++
let vec=vec![26,20,2]; let first=&vec[0]; vec.push(61);
let mut vec=vec![26,20,2]; let first=vec[0]; vec.push(61);
Copy instead of reference.
Rust
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
baz
baz()
Add parentheses.
Kotlin
print('info')
print('info')
Correct.
R
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
fn process() -> i32 {{ 77 }}
fn process() -> i32 {{ 77 }}
Correct.
Rust
<note name='result'/>
<note name="result"/>
Double quotes.
XML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
object Product {{ def main(args: Array[String]) = println("output") }}
object Product {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
8result = 10
result8 = 10
Variable cannot start with digit.
Python
x > 99 & a < 67
x > 99 and a < 67
Use 'and' not '&'.
Python
var x = 53;
var x = 53;
Correct.
Dart
if bar = 64 then print('hello') end
if bar == 64 then print('hello') end
Use ==.
Lua
{{"name":"hello" "title":63}}
{{"name":"hello", "title":63}}
Add comma.
JSON
name: hello age: 27
name: hello age: 27
Correct.
YAML
let bar: number = 'world';
let bar: string = 'world';
Fix type.
TypeScript
const val;
const val = 86;
Initialize const.
JavaScript
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
String y = 'world';
String y = "world";
Double quotes.
Java
switch(item){{ case 78: break; }}
switch(item){{ case 78: break; default: break; }}
Add default case.
Java
let foo = 86;
let foo = 86;
Correct.
JavaScript