exercism-analysis's People
exercism-analysis's Issues
Not triggering "indentation/inconsistent_spacing" rule
I saw the following submission today, which didn't trigger the inconsistent indentation rule. Notice how the indentation is variously 1, 2, and 4 spaces.
class Hamming
def self.compute(first_sequence, second_sequence)
hamming_counter = 0
unless first_sequence.length != second_sequence.length
split_first_sequence = first_sequence.split('')
split_second_sequence = second_sequence.split('')
split_first_sequence.select.with_index do |first_sequence_base,index|
hamming_counter += 1 if first_sequence_base != split_second_sequence[index]
end
hamming_counter
end
end
end
Here's the curl call:
curl -XPOST 'http://analysseur.exercism.io/analyze/ruby' --data '{"code":"class Hamming\n def self.compute(first_sequence, second_sequence)\n hamming_counter = 0\n unless first_sequence.length != second_sequence.length\n split_first_sequence = first_sequence.split(\"\")\n split_second_sequence = second_sequence.split(\"\")\n split_first_sequence.select.with_index do |first_sequence_base,index|\n hamming_counter += 1 if first_sequence_base != split_second_sequence[index]\n end\n hamming_counter\n\n end"}' -H "Content-Type: application/json"
"inconsistent indentation" is greedy
I've run a bunch of tests locally against the indentation
analyzer, and I get a huge number of false positives for inconsistent indentation.
For example:
class Hamming
def self.compute (x,y)
a = 0;
min = [x.length,y.length].min
for i in 0...min
if x[i]!=y[i]
a += 1
end
end
return a
end
end
I don't think this one has inconsistent indentation, it uses tabs consistently... unless it's looking at spacing around binary operators and after commas, etc. If so, I need to update the feedback text to reflect that.
Another one that gets inconsistent indentation is this one:
class Hamming
def self.compute(strand1, strand2)
min = [strand1.length, strand2.length].min
(0...min).count do |i|
strand1[i] != strand2[i]
end
end
end
This one consistently uses two spaces for indentation.
I've got almost 200 examples all taken from Hamming in Ruby, so just let me know what kind of data would be useful for figuring out what to do with this.
?rule - mix tabs and spaces
We may want to let people know specifically that mixing tabs and spaces is a bad idea.
question about indentation-tab rule
Does the tab rule kick in also if people use exactly four spaces (consistently) for indentation?
If not, can we make it so?
?rule - shebang
A fair amount of people add a #!/usr/bin/env ruby
statement to the beginning of their class.
We may want to add a nitpick for this.
Not triggering 'two spaces' rule
Here's a bit of code that seems like it should have triggered the indentation/two spaces rule:
class Hamming
def self.compute dna1, dna2
#compute Hamming distance of 2 DNA strings
prep1 = self.prepare dna1
prep2 = self.prepare dna2
self.calculate prep1, prep2
end
def self.prepare(dna)
#preparation steps
dna_hash = Hash.new
dna.split(//).each_with_index do |index, key|
dna_hash[key] = index
end
dna_hash
end
def self.calculate(dna1, dna2)
#if values for the same index are not the same, increase distance
distance = 0
dna1.each do |key, value|
unless dna2[key] == value then distance+=1 end
end
distance
end
end
"class Hamming\r\n def self.compute dna1, dna2\r\n #compute Hamming distance of 2 DNA strings \r\n prep1 = self.prepare dna1 \r\n prep2 = self.prepare dna2 \r\n\r\n self.calculate prep1, prep2\r\n end\r\n\r\n def self.prepare(dna)\r\n #preparation steps\r\n dna_hash = Hash.new \r\n dna.split(//).each_with_index do |index, key|\r\n dna_hash[key] = index \r\n end\r\n dna_hash\r\n end \r\n\r\n def self.calculate(dna1, dna2)\r\n #if values for the same index are not the same, increase distance \r\n distance = 0\r\n dna1.each do |key, value| \r\n unless dna2[key] == value then distance+=1 end\r\n end\r\n distance\r\n end\r\nend"
Ruby: Shebang rule for tests
Right now when you submit your code file example.rb and you choose to also submit your test file, example_test.rb, Rikki will pick on that shebang.
Skipping that check for test files I believe is a good behaviour.
@kotp mentioned that there is a low-priority task for that.
I'd like to give this a try if no one else is working on it and if it's worth while.
What do you think?
Cheers
Defining inconsistent indentation
I've been looking at the exercises that triggered the rule "inconsistent indentation". Out of 1500 samples analyzed, over 700 triggered the rule.
It seems like there are a few things that could trigger it that probably shouldn't. (I don't actually know what triggers it, I'm just making some guesses here.
private - There are three more-or-less common (acceptable) indentation strategies for the private keyword:
#1 - class/private/end aligned
class Thing
def stuff
# ...
end
private
def mine
# ...
end
end
#2 - class/end + def/end/private/def/end
class Thing
def stuff
# ...
end
private
def mine
# ...
end
end
#3 - class/end + def/end/private + def/end
class Thing
def stuff
# ...
end
private
def mine
# ...
end
end
trailing whitespace on blank lines - While I hate trailing whitespace, it's not obviously inconsistent.
chaining methods - This should probably be allowed, but I have no idea if it's possible to detect it.
def count_differences(seqs)
short, long = *seqs
short.chars.zip(long.chars)
.map{ |char1, char2| char1 == char2 ? 0 : 1 }
.reduce(&:+)
end
... and by "fine" I'm totally not talking about the ternary nested inside the map :^)
macros - well, not really technically macros, but things like attr_reader
declarations and stuff like module_function
, extend Thingy
, include Whatever
. E.g.
module Hamming
module_function
def compute(first_strand, second_strand)
length = [first_strand, second_strand].map(&:size).min
pairs = first_strand.each_char.zip(second_strand.each_char).take(length)
pairs.count { |a, b| a != b }
end
end
mystery - some look perfectly good to me, but still trigger the inconsistent indentation rule. E.g.
class Hamming
def self.compute(s1, s2)
iterations = s1.length < s2.length ? s1.length : s2.length
hd = 0
for i in 0...iterations
hd += 1 if s1[i] != s2[i]
end
hd
end
end
When you've got a moment, let's talk about the criteria for this rule.
Common pattern: conditional within loop
Very often I see people use an enumerable method, and then stick an if/else or ternary statement or a postfix if inside of it. I generally point them to the list of enumerable methods and say that often there will be one that can do more of the heavy lifting.
Is this something that would be fairly low-cost to implement an analyzer for?
Separate Analyzers for each rule?
Hi Jacob,
Can we have a separate analyzer for each rule that is defined, even if they are within the same category?
Right now I've got this:
RubyAnalyzers = [
Exercism::Analyzers::ControlFlow,
Exercism::Analyzers::Indentation,
Exercism::Analyzers::ForLoop
]
And I want to see what the data looks like if I turn off just the inconsistent indentation rule. I've verified the tab
rule, and it works really well, so I don't want to turn that one off.
How hard is this?
New rule: `puts`
Every once in a while people use puts
inside of the exercism solutions. puts
is great, but pretty inappropriate. I think it would be nice to have an automated response for this one.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.