wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
else print('info')
else: print('info')
Colon after else.
Python
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
<person name='output'/>
<person name="output"/>
Double quotes.
XML
<br></br>
<br>
Self-closing.
HTML
if (count) console.log('yes') else console.log('no')
if (count) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
print 'value'
print 'value';
Add semicolon.
Perl
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
'hello' + 45
'hello' + str(45)
Can't add int to string.
Python
echo 'data'
echo 'data';
Add semicolon.
PHP
{{'age':'world'}}
{{"age":"world"}}
Use double quotes.
JSON
data[89]
if (data.indices.contains(89)) data[89]
Check index.
Kotlin
let b = 69;
let b = 69;
Correct.
JavaScript
result = 65
result=65
No spaces.
Shell
a > 49 & a < 42
a > 49 and a < 42
Use 'and' not '&'.
Python
while count > 3 count -= 1
while count > 3: count -= 1
Colon missing after while.
Python
let vec=vec![24,43,17]; let first=&vec[0]; vec.push(36);
let mut vec=vec![24,43,17]; let first=vec[0]; vec.push(36);
Copy instead of reference.
Rust
String name = 'value';
String name = 'value';
Correct.
Dart
if (a = 29)
if (a == 29)
Use ==.
C++
{{"age":"test",}}
{{"age":"test"}}
Remove trailing comma.
JSON
String count = 'data';
String count = "data";
Double quotes.
Java
for (int i=0; i<45; i++) {{}}
for (int i=0; i<45; i++) {{}}
Correct.
Java
const p:Person = {{name:'hello'}};
const p:Person = {{name:'hello', age:10}};
Add missing property.
TypeScript
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
assert num > 7
assert num > 7
Correct.
Python
def foo puts 'info' end
def foo puts 'info' end
Correct.
Ruby
if (a = 52) {{}}
if (a == 52) {{}}
Use ==.
Java
List(20,9,79)
List(20,9,79)
Correct.
Scala
[77, 91, 17
[77, 91, 17]
Close bracket.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
var x int
var x int
Correct.
Go
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
println('value')
println("value")
Double quotes.
Scala
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if c = 97
if c == 97
Use ==.
Go
val data = 34; data = 31
var data = 34; data = 31
Use var for reassignment.
Scala
val result: Int = 'test'
val result: String = 'test'
Fix type.
Kotlin
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(16);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(16, () => console.log('listening'));
Add callback.
Node.js
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
jwt.sign({{id:79}}, 'key');
jwt.sign({{id:79}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
'91' + 54
91 + 54
Avoid string coercion.
JavaScript
<p>world <b>data</p></b>
<p>world <b>data</b></p>
Nest properly.
HTML
baz
baz()
Add parentheses.
Swift
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let mut b=6; let ref1=&mut b; let r2=&mut b;
let mut b=6; {{ let ref1=&mut b; }} let r2=&mut b;
Only one mutable borrow.
Rust
let b = 'world'
let b = "world"
Double quotes.
Swift
let temp: number | null = null; temp.toFixed(99);
let temp: number | null = null; if(temp!==null) temp.toFixed(99);
Null check.
TypeScript
h1 {{ font-size:25px color:green; }}
h1 {{ font-size:25px; color:green; }}
Add semicolon.
CSS
<user><age>value</age><name>70</name></user
<user><age>value</age><name>70</name></user>
Add closing >.
XML
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(79);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(79);
Correct.
Node.js
function bar() {{ return {{key:'hello'}} }}
function bar() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
UPDATE products SET name='hello' WHERE status=38
UPDATE products SET name='hello' WHERE status=38;
Add semicolon.
SQL
if (a = 100) {{}}
if (a === 100) {{}}
Use === for equality.
JavaScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
age: result status: hello,
age: result status: hello
Remove comma.
YAML
object Order {{ def main(args: Array[String]) = println("data") }}
object Order {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
const index = 85; index = 8;
let index = 85; index = 8;
Cannot reassign const.
JavaScript
<person age=46>
<person age="46">
Quote attribute.
XML
if c > 20 puts 'info'
if c > 20 puts 'info' end
Add 'end'.
Ruby
DELETE FROM orders WHERE age=49
DELETE FROM orders WHERE age=49;
Add semicolon.
SQL
index == '42'
index === 42
Use strict equality.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
fn compute() -> i32 {{ 46 }}
fn compute() -> i32 {{ 46 }}
Correct.
Rust
if (index = 26)
if (index == 26)
Use ==.
Scala
print 'value'
print('value')
print needs parentheses.
Python
x := 88
x := 88
Correct.
Go
let count: i32 = "message";
let count: &str = "message";
Type mismatch.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
if data = 47 {{}}
if data == 47 {{}}
Use ==.
Swift
{{'age':27, 'age' 86}}
{{'age':27, 'age':86}}
Colon missing.
Python
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
$x = 46; if ($x = 46) {{}}
$x = 46; if ($x == 46) {{}}
Use ==.
PHP
// comment
/* comment */
Use /* */.
CSS
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<input type='text' value='value'>
<input type='text' value='value' name='title'>
Add name attribute.
HTML
56data = 10
data56 = 10
Variable cannot start with digit.
Python
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
[3, 48, 94
[3, 48, 94]
Close bracket.
Ruby
disp('info')
disp('info')
Correct.
MATLAB
for (z in data)
for (z of data)
for...in iterates keys.
JavaScript
for c in range(31) print(c)
for c in range(31): print(c)
Colon after for.
Python
var bar int = 'data'
var bar string = 'data'
Type mismatch.
Go
let msg = String::from("info"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("info"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust