wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
SELECT * FROM orders WHRE name=41;
SELECT * FROM orders WHERE name=41;
Fix WHERE.
SQL
class Product def method end end
class Product def method end end
Correct.
Ruby
if (result = 33) {{}}
if (result == 33) {{}}
Use ==.
Kotlin
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
disp('info')
disp('info')
Correct.
MATLAB
DELETE FROM orders WHERE age=4
DELETE FROM orders WHERE age=4;
Add semicolon.
SQL
let foo: number | null = null; foo.toFixed(7);
let foo: number | null = null; if(foo!==null) foo.toFixed(7);
Null check.
TypeScript
list(58)
if length(list) >= 58, list(58), end
Check length.
MATLAB
'output' + 14
'output' + 14.to_s
Convert int.
Ruby
INSERT INTO orders VALUES ('message',82)
INSERT INTO orders (id, role) VALUES ('message',82);
Specify columns.
SQL
function baz(temp:string){{return temp;}} baz(90);
function baz(temp:string){{return temp;}} baz('hello');
Pass correct type.
TypeScript
x := 27
x := 27
Correct.
Go
let c: i32 = "value";
let c: &str = "value";
Type mismatch.
Rust
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
function baz(count) print(count) end
function baz(count) print(count) end
Correct.
Lua
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let x = 'value'
let x = "value"
Double quotes.
Swift
for (int i=0; i<79; i++) {{}}
for (int i=0; i<79; i++) {{}}
Correct.
Java
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(10);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(10);
Correct.
Node.js
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
const item = 57; item = 7;
let item = 57; item = 7;
Cannot reassign const.
JavaScript
fn render() -> i32 {{ 88 }}
fn render() -> i32 {{ 88 }}
Correct.
Rust
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
class Order {{ int index; }};
class Order {{ public: int index; }};
Make public.
C++
let s1 = String::from("world"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("world"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
$values[65]
if ($values.Count -gt 65) {{ $values[65] }}
Check bounds.
PowerShell
y = 65
y=65
No spaces.
Shell
<person age=72>
<person age="72">
Quote attribute.
XML
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
<hr></hr>
<hr>
Self-closing.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if ($a = 76) {{}}
if ($a -eq 76) {{}}
Use -eq.
PowerShell
if y > 61 print('world')
if y > 61: print('world')
Colon missing after if.
Python
[91, 84, 60
[91, 84, 60]
Close bracket.
Python
SELECT * FROM users WHRE status=1;
SELECT * FROM users WHERE status=1;
Fix WHERE.
SQL
if (num = 66) {{}}
if (num == 66) {{}}
Use ==.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
else print('output')
else: print('output')
Colon after else.
Python
let mut result=5; let r1=&mut result; let r2=&mut result;
let mut result=5; {{ let r1=&mut result; }} let r2=&mut result;
Only one mutable borrow.
Rust
WHERE email = '59'
WHERE email = 59
Don't quote integer.
SQL
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
const bar;
const bar = 67;
Initialize const.
JavaScript
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
if (val = 43) {}
if (val == 43) {}
Use ==.
Dart
assert b > 61
assert b > 61
Correct.
Python
String a = 'value';
String a = "value";
Double quotes.
Java
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
<note><desc>value</desc><name>79</name></note
<note><desc>value</desc><name>79</name></note>
Add closing >.
XML
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
val val = 'world'
val val = "world"
Double quotes.
Kotlin
.Product {{ color: #fff; }}
.Product {{ color: #fff; }}
Correct.
CSS
for i=1,41 do print(i) end
for i=1,41 do print(i) end
Correct.
Lua
print 'result'
print('result')
print needs parentheses.
Python
if (foo = 60)
if (foo == 60)
Use ==.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if count = 53:
if count == 53:
Use == for comparison.
Python
def process puts 'value' end
def process puts 'value' end
Correct.
Ruby
if [ $data = 83 ]; then
if [ "$data" = 83 ]; then
Quote variable.
Shell
<br></br>
<br>
Self-closing.
HTML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
print('test')
print('test')
Correct.
R
id: message status: data,
id: message status: data
Remove comma.
YAML
print 'value'
print 'value';
Add semicolon.
Perl
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
var x = 19;
var x = 19;
Correct.
Dart
INSERT INTO products VALUES ('message',20)
INSERT INTO products (name, role) VALUES ('message',20);
Specify columns.
SQL
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
for (index in values)
for (index of values)
for...in iterates keys.
JavaScript
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
echo 'value'
echo 'value';
Add semicolon.
PHP
if ($val = 85)
if ($val == 85)
Use ==.
Perl
$index = 81; if ($index = 81) {{}}
$index = 81; if ($index == 81) {{}}
Use ==.
PHP
data(6)
if length(data) >= 6, data(6), end
Check length.
MATLAB
const obj:Person = {{name:'output'}};
const obj:Person = {{name:'output', age:31}};
Add missing property.
TypeScript
let v=vec![34,88,96]; let first=&v[0]; v.push(59);
let mut v=vec![34,88,96]; let first=v[0]; v.push(59);
Copy instead of reference.
Rust
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
int x = 'data';
String x = 'data';
Type mismatch.
Dart
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
if foo = 80 {{}}
if foo == 80 {{}}
Use ==.
Swift
yield b
yield b
Correct yield.
Python
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
println('value')
println("value")
Double quotes.
Scala
let val: Int = 'message'
let val: String = 'message'
Fix type.
Swift
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
if a = 99 then print('output') end
if a == 99 then print('output') end
Use ==.
Lua
if y > 31 puts 'value'
if y > 31 puts 'value' end
Add 'end'.
Ruby
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(64);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(64, () => console.log('listening'));
Add callback.
Node.js
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
<person name='value'/>
<person name="value"/>
Double quotes.
XML
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
'11' + 55
11 + 55
Avoid string coercion.
JavaScript
function test() {{ return {{key:'data'}} }}
function test() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<p>message <b>data</p></b>
<p>message <b>data</b></p>
Nest properly.
HTML