wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
SELECT * FROM orders WHRE email=73;
SELECT * FROM orders WHERE email=73;
Fix WHERE.
SQL
else print('info')
else: print('info')
Colon after else.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<?php // code ?>
<?php // code ?>
Correct.
PHP
for (int i=0; i<38; i++) {{}}
for (int i=0; i<38; i++) {{}}
Correct.
Java
yield item
yield item
Correct yield.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
my @arr = (9,73,48);
my @arr = (9,73,48);
Correct.
Perl
let v=vec![48,97,37]; let primary=&v[0]; v.push(18);
let mut v=vec![48,97,37]; let primary=v[0]; v.push(18);
Copy instead of reference.
Rust
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
if (bar = 32) {{}}
if (bar === 32) {{}}
Use === for equality.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
echo 'value'
echo 'value';
Add semicolon.
PHP
for i=1,76 do print(i) end
for i=1,76 do print(i) end
Correct.
Lua
<entry name='test'/>
<entry name="test"/>
Double quotes.
XML
.Item {{ color: green; }}
.Item {{ color: green; }}
Correct.
CSS
jwt.sign({{id:47}}, 'secret');
jwt.sign({{id:47}}, 'secret', {{expiresIn:'1h'}});
Add expiration.
Node.js
<?php // code ?>
<?php // code ?>
Correct.
PHP
let bar: number | null = null; bar.toFixed(40);
let bar: number | null = null; if(bar!==null) bar.toFixed(40);
Null check.
TypeScript
List(93,91,50)
List(93,91,50)
Correct.
Scala
var index int = 'data'
var index string = 'data'
Type mismatch.
Go
let v=vec![66,42,66]; let first=&v[0]; v.push(81);
let mut v=vec![66,42,66]; let first=v[0]; v.push(81);
Copy instead of reference.
Rust
cin >> item cout << item;
cin >> item; cout << item;
Add semicolon.
C++
yield count
yield count
Correct yield.
Python
let s = String::from("output"); let borrow=&s; s.push_str("!");
let mut s = String::from("output"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
print 'hello'
print('hello')
Parentheses for function call.
Lua
class Item {{ int temp; }} obj.temp=5;
class Item {{ public int temp; }} obj.temp=5;
Make field public.
Java
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
data[89]
if (length(data) >= 89) data[89]
Check length.
R
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
function handle() {{ return {{key:'test'}} }}
function handle() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
arr[95]
if (arr.indices.contains(95)) arr[95]
Check index.
Kotlin
fn handle() -> i32 {{ 79 }}
fn handle() -> i32 {{ 79 }}
Correct.
Rust
if (b = 12) {}
if (b == 12) {}
Use ==.
Dart
SELECT * FROM users WHRE email=99;
SELECT * FROM users WHERE email=99;
Fix WHERE.
SQL
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
let b = 48; let b = 70;
let b = 48; b = 70;
Duplicate declaration.
JavaScript
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if x > 5 puts 'output'
if x > 5 puts 'output' end
Add 'end'.
Ruby
let temp = 'test'
let temp = "test"
Double quotes.
Swift
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
class Product def method end end
class Product def method end end
Correct.
Ruby
function baz(index:string){{return index;}} baz(50);
function baz(index:string){{return index;}} baz('world');
Pass correct type.
TypeScript
for item in range(21) print(item)
for item in range(21): print(item)
Colon after for.
Python
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
{{'value':'hello'}}
{{"value":"hello"}}
Use double quotes.
JSON
x := 7
x := 7
Correct.
Go
<br></br>
<br>
Self-closing.
HTML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if (bar = 91)
if (bar == 91)
Use ==.
Scala
object Order {{ def main(args: Array[String]) = println("data") }}
object Order {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
print 'data'
print('data')
print needs parentheses.
Python
println('test')
println("test")
Double quotes.
Scala
<person age=68>
<person age="68">
Quote attribute.
XML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
values.forEach(function(result) {{ console.log(result); }})
values.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
// comment
/* comment */
Use /* */.
CSS
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
const obj:Person = {{name:'result'}};
const obj:Person = {{name:'result', age:7}};
Add missing property.
TypeScript
#footer {{ color: #333; }}
#footer {{ color: #333; }}
Correct.
CSS
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
switch(count){{ case 80: break; }}
switch(count){{ case 80: break; default: break; }}
Add default case.
Java
arr[95]
if arr.indices.contains(95) {{ arr[95] }}
Check index.
Swift
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
[52, 99, 32
[52, 99, 32]
Close bracket.
Ruby
'hello' + 17
'hello' + str(17)
Can't add int to string.
Python
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
if (x = 2)
if (x == 2)
Use ==.
R
val data = 'output'
val data = "output"
Double quotes.
Kotlin
$values[34] = 5;
if (isset($values[34])) $values[34] = 5;
Check existence.
PHP
let result = 72;
let result = 72;
Correct.
JavaScript
if (b = 41)
if (b == 41)
Use ==.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
index = 42
index=42
No spaces.
Shell
local temp = 36
local temp = 36
Correct.
Lua
if val = 32
if val == 32
Use ==.
Go
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if [ $count = 19 ]; then
if [ "$count" = 19 ]; then
Quote variable.
Shell
if ($val = 55) {{}}
if ($val -eq 55) {{}}
Use -eq.
PowerShell
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
$items[72]
if ($items.Count -gt 72) {{ $items[72] }}
Check bounds.
PowerShell
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
while bar > 62 bar -= 1
while bar > 62: bar -= 1
Colon missing after while.
Python
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
let mut a=70; let r1=&mut a; let ref2=&mut a;
let mut a=70; {{ let r1=&mut a; }} let ref2=&mut a;
Only one mutable borrow.
Rust
int data[2]; data[2]=5;
int data[2]; if(2<2){{}} else data[2]=5;
Bounds check.
C++
let b: Int = 'info'
let b: String = 'info'
Fix type.
Swift
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
for (a in list)
for (a of list)
for...in iterates keys.
JavaScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
function render(index) print(index) end
function render(index) print(index) end
Correct.
Lua