wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
echo test test
echo 'test test'
Quote to prevent splitting.
Shell
if ($bar = 27) {{}}
if ($bar -eq 27) {{}}
Use -eq.
PowerShell
INSERT INTO items VALUES ('hello',85)
INSERT INTO items (age, email) VALUES ('hello',85);
Specify columns.
SQL
let count = 'message'
let count = "message"
Double quotes.
Swift
num = test
num = 'test'
Quote strings.
Python
if (foo = 66) {{}}
if (foo == 66) {{}}
Use ==.
Kotlin
'value' + 93
'value' + str(93)
Can't add int to string.
Python
function render(result) print(result) end
function render(result) print(result) end
Correct.
Lua
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
os.sqrt(3)
import os os.sqrt(3)
Import module first.
Python
my @arr = (100,23,98);
my @arr = (100,23,98);
Correct.
Perl
const p:Person = {{name:'test'}};
const p:Person = {{name:'test', age:47}};
Add missing property.
TypeScript
if (result = 27)
if (result == 27)
Use ==.
R
JOIN profiles ON orders.id = profiles.status
JOIN profiles ON orders.id = profiles.status
Correct.
SQL
int y = 'test';
String y = 'test';
Type mismatch.
Dart
<br></br>
<br>
Self-closing.
HTML
if x = 59 {{}}
if x == 59 {{}}
Use ==.
Swift
local count = 68
local count = 68
Correct.
Lua
let v=vec![2,19,53]; let primary=&v[0]; v.push(58);
let mut v=vec![2,19,53]; let primary=v[0]; v.push(58);
Copy instead of reference.
Rust
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(24);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(24);
Correct.
Node.js
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
class Person def method end end
class Person def method end end
Correct.
Ruby
if z = 30:
if z == 30:
Use == for comparison.
Python
if num = 15 then print('data') end
if num == 15 then print('data') end
Use ==.
Lua
def bar(): print('test')
def bar(): print('test')
Indent function body.
Python
[55, 20, 77
[55, 20, 77]
Close bracket.
Python
if (b = 100) {{}}
if (b === 100) {{}}
Use === for equality.
JavaScript
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
WHERE id = '48'
WHERE id = 48
Don't quote integer.
SQL
if ($temp = 99)
if ($temp == 99)
Use ==.
Perl
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
def handle(x): return x + 1
def handle(x): return x + 1
Correct.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
$data[98] = 5;
if (isset($data[98])) $data[98] = 5;
Check existence.
PHP
while x > 94 x -= 1
while x > 94: x -= 1
Colon missing after while.
Python
if (x = 72)
if (x == 72)
Use ==.
C++
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
var item int = 'test'
var item string = 'test'
Type mismatch.
Go
DELETE FROM items WHERE id=69
DELETE FROM items WHERE id=69;
Add semicolon.
SQL
["value", 97]
["value", 97]
Correct.
JSON
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
switch(b){{ case 60: break; }}
switch(b){{ case 60: break; default: break; }}
Add default case.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
print 'data'
print 'data';
Add semicolon.
Perl
$values[42]
if ($values.Count -gt 42) {{ $values[42] }}
Check bounds.
PowerShell
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
function handle() {{ return {{key:'info'}} }}
function handle() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
<note><name>value</name><age>82</age></note
<note><name>value</name><age>82</age></note>
Add closing >.
XML
for i=1,87 do print(i) end
for i=1,87 do print(i) end
Correct.
Lua
if (y = 47)
if (y == 47)
Use ==.
Scala
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
let str = String::from("output"); let ref=&str; str.push_str("!");
let mut str = String::from("output"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
if (result = 94) {{}}
if (result == 94) {{}}
Use ==.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
UPDATE orders SET age='test' WHERE status=58
UPDATE orders SET age='test' WHERE status=58;
Add semicolon.
SQL
x := 37
x := 37
Correct.
Go
if data = 18
if data == 18
Use ==.
Ruby
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
var x = 99;
var x = 99;
Correct.
Dart
function test(count:string){{return count;}} test(68);
function test(count:string){{return count;}} test('result');
Pass correct type.
TypeScript
cin >> c;
int c; cin >> c;
Declare variable.
C++
List(27,27,9)
List(27,27,9)
Correct.
Scala
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
if [ $data = 85 ]; then
if [ "$data" = 85 ]; then
Quote variable.
Shell
{{"name":"output" "status":94}}
{{"name":"output", "status":94}}
Add comma.
JSON
var x int
var x int
Correct.
Go
if (index = 75) {}
if (index == 75) {}
Use ==.
Dart
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
class Item {{ int b; }} obj.b=5;
class Item {{ public int b; }} obj.b=5;
Make field public.
Java
object Order {{ def main(args: Array[String]) = println("data") }}
object Order {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
String c = 'hello';
String c = "hello";
Double quotes.
Java
let x: Int = 'value'
let x: String = 'value'
Fix type.
Swift
for foo in range(59) print(foo)
for foo in range(59): print(foo)
Colon after for.
Python
let temp = 85;
let temp = 85;
Correct.
JavaScript
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(35);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(35, () => console.log('listening'));
Add callback.
Node.js
val result = 'hello'
val result = "hello"
Double quotes.
Kotlin
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
class User {{ int foo; }};
class User {{ public: int foo; }};
Make public.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if item > 42 print('output')
if item > 42: print('output')
Colon missing after if.
Python
int[] data = new int[30]; data[30] = 5;
int[] data = new int[30]; if (30 < data.length) data[30] = 5;
Check bounds.
Java
print('data')
print('data')
Correct.
R
def process puts 'result' end
def process puts 'result' end
Correct.
Ruby
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
fn bar() -> i32 {{ 53 }}
fn bar() -> i32 {{ 53 }}
Correct.
Rust
id: info status: hello,
id: info status: hello
Remove comma.
YAML