Skip to main content
Code Review

Return to Answer

deleted 19 characters in body
Source Link
Borsunho
  • 907
  • 5
  • 8

I started to write a detailed review, but in middle of it I realised that best advise I could give you looking at this code is to pick up some good Ruby book and work through it carefully, paying attention to how examples are formed. You seem to understand basics of how programming works, but your code lacks proper usage of many basic concepts, like arguments, returning, modules etc. Explaining them in detail here seems pointless, it's not a place for Ruby tutorials. You should focus on that basics before you move to object oriented design/conventions.

Still, I'll post what I already wrote as advices for you.


I don't really see any need to use OO structure in this code. It definately could still be written better though.

Indentation

Your way of indenting makes code very hard to read. Compare:

 $pic_names.each do |name|
 print 'ˁ ̊ᴥ ̊ˀ '
 new_name = if pic_number < 10
 "#{$file_name} 0#{pic_number} .CR2"
else
 "#{$file_name} #{pic_number} .CR2"
end
require 'fileutils'
include FileUtils
cp(name, new_name) 
pic_number = pic_number + 1
end

and:

$pic_names.each do |name|
 print 'ˁ ̊ᴥ ̊ˀ '
 new_name = 
 if pic_number < 10
 "#{$file_name} 0#{pic_number} .CR2"
 else
 "#{$file_name} #{pic_number} .CR2"
 end
 require 'fileutils'
 include FileUtils
 cp(name, new_name) 
 pic_number = pic_number + 1
end

Ruby style guide contains some usefull examples on how you should indent your code to make it nice to read. Generally every block means 1 level of indentation (2 spaces).

Require

require 'fileutils'
include FileUtils

You only need to require 'fileutils'fileutils' once, at top of your file. include also doesn't need to be reapated, instead generally it should be at top of a module - will get to that.

Avoid globals

Instead of putting result of your methods in global variables, return from them. I.e:

def folder
 puts "Enter the folder name"
 while folder_name = gets.chomp
 if File.exist?("#{$folder_name}")
 puts "This folder already exists, choose a unique name"
 else
 require 'fileutils'
 FileUtils::mkdir_p "/home/moot/pickaxe/pics/#{$folder_name}"
 return folder_name
 end 
 end
end

And than:

folder_name = folder
Dir.chdir "/home/moot/pickaxe/pics/#{folder_name}"

This is much more flexible.

I started to write a detailed review, but in middle of it I realised that best advise I could give you looking at this code is to pick up some good Ruby book and work through it carefully, paying attention to how examples are formed. You seem to understand basics of how programming works, but your code lacks proper usage of many basic concepts, like arguments, returning, modules etc. Explaining them in detail here seems pointless, it's not a place for Ruby tutorials. You should focus on that basics before you move to object oriented design/conventions.

Still, I'll post what I already wrote as advices for you.


I don't really see any need to use OO structure in this code. It definately could still be written better though.

Indentation

Your way of indenting makes code very hard to read. Compare:

 $pic_names.each do |name|
 print 'ˁ ̊ᴥ ̊ˀ '
 new_name = if pic_number < 10
 "#{$file_name} 0#{pic_number} .CR2"
else
 "#{$file_name} #{pic_number} .CR2"
end
require 'fileutils'
include FileUtils
cp(name, new_name) 
pic_number = pic_number + 1
end

and:

$pic_names.each do |name|
 print 'ˁ ̊ᴥ ̊ˀ '
 new_name = 
 if pic_number < 10
 "#{$file_name} 0#{pic_number} .CR2"
 else
 "#{$file_name} #{pic_number} .CR2"
 end
 require 'fileutils'
 include FileUtils
 cp(name, new_name) 
 pic_number = pic_number + 1
end

Ruby style guide contains some usefull examples on how you should indent your code to make it nice to read. Generally every block means 1 level of indentation (2 spaces).

Require

require 'fileutils'
include FileUtils

You only need to require 'fileutils once, at top of your file. include also doesn't need to be reapated, instead generally it should be at top of a module - will get to that.

Avoid globals

Instead of putting result of your methods in global variables, return from them. I.e:

def folder
 puts "Enter the folder name"
 while folder_name = gets.chomp
 if File.exist?("#{$folder_name}")
 puts "This folder already exists, choose a unique name"
 else
 require 'fileutils'
 FileUtils::mkdir_p "/home/moot/pickaxe/pics/#{$folder_name}"
 return folder_name
 end 
 end
end

And than:

folder_name = folder
Dir.chdir "/home/moot/pickaxe/pics/#{folder_name}"

This is much more flexible.

I started to write a detailed review, but in middle of it I realised that best advise I could give you looking at this code is to pick up some good Ruby book and work through it carefully, paying attention to how examples are formed. You seem to understand basics of how programming works, but your code lacks proper usage of many basic concepts, like arguments, returning, modules etc. Explaining them in detail here seems pointless, it's not a place for Ruby tutorials. You should focus on that basics before you move to object oriented design/conventions.

Still, I'll post what I already wrote as advices for you.


I don't really see any need to use OO structure in this code. It definately could still be written better though.

Indentation

Your way of indenting makes code very hard to read. Compare:

 $pic_names.each do |name|
 print 'ˁ ̊ᴥ ̊ˀ '
 new_name = if pic_number < 10
 "#{$file_name} 0#{pic_number} .CR2"
else
 "#{$file_name} #{pic_number} .CR2"
end
require 'fileutils'
include FileUtils
cp(name, new_name) 
pic_number = pic_number + 1
end

and:

$pic_names.each do |name|
 print 'ˁ ̊ᴥ ̊ˀ '
 new_name = 
 if pic_number < 10
 "#{$file_name} 0#{pic_number} .CR2"
 else
 "#{$file_name} #{pic_number} .CR2"
 end
 require 'fileutils'
 include FileUtils
 cp(name, new_name) 
 pic_number = pic_number + 1
end

Ruby style guide contains some usefull examples on how you should indent your code to make it nice to read. Generally every block means 1 level of indentation (2 spaces).

Require

require 'fileutils'
include FileUtils

You only need to require 'fileutils' once, at top of your file. include also doesn't need to be reapated, instead generally it should be at top of a module.

Avoid globals

Instead of putting result of your methods in global variables, return from them. I.e:

def folder
 puts "Enter the folder name"
 while folder_name = gets.chomp
 if File.exist?("#{$folder_name}")
 puts "This folder already exists, choose a unique name"
 else
 require 'fileutils'
 FileUtils::mkdir_p "/home/moot/pickaxe/pics/#{$folder_name}"
 return folder_name
 end 
 end
end

And than:

folder_name = folder
Dir.chdir "/home/moot/pickaxe/pics/#{folder_name}"

This is much more flexible.

added 630 characters in body
Source Link
Borsunho
  • 907
  • 5
  • 8

I started to write a detailed review, but in middle of it I realised that best advise I could give you looking at this code is to pick up some good Ruby book and work through it carefully, paying attention to how examples are formed. You seem to understand basics of how programming works, but your code lacks proper usage of many basic concepts, like arguments, returning, modules etc. Explaining them in detail here seems pointless, it's not a place for Ruby tutorials. You should focus on that basics before you move to object oriented design/conventions.

Still, I'll post what I already wrote as advices for you.


I don't really see any need to use OO structure in this code. It definately could still be written better though.

Indentation

Your way of indenting makes code very hard to read. Compare:

 $pic_names.each do |name|
 print 'ˁ ̊ᴥ ̊ˀ '
 new_name = if pic_number < 10
 "#{$file_name} 0#{pic_number} .CR2"
else
 "#{$file_name} #{pic_number} .CR2"
end
require 'fileutils'
include FileUtils
cp(name, new_name) 
pic_number = pic_number + 1
end

and:

$pic_names.each do |name|
 print 'ˁ ̊ᴥ ̊ˀ '
 new_name = 
 if pic_number < 10
 "#{$file_name} 0#{pic_number} .CR2"
 else
 "#{$file_name} #{pic_number} .CR2"
 end
 require 'fileutils'
 include FileUtils
 cp(name, new_name) 
 pic_number = pic_number + 1
end

Ruby style guide contains some usefull examples on how you should indent your code to make it nice to read. Generally every block means 1 level of indentation (2 spaces).

Require

require 'fileutils'
include FileUtils

You only need to require 'fileutils once, at top of your file. include also doesn't need to be reapated, instead generally it should be at top of a module - will get to that.

Avoid globals

Instead of putting result of your methods in global variables, return from them. I.e:

def folder
 puts "Enter the folder name"
 while folder_name = gets.chomp
 if File.exist?("#{$folder_name}")
 puts "This folder already exists, choose a unique name"
 else
 require 'fileutils'
 FileUtils::mkdir_p "/home/moot/pickaxe/pics/#{$folder_name}"
 return folder_name
 end 
 end
end

And than:

folder_name = folder
Dir.chdir "/home/moot/pickaxe/pics/#{folder_name}"

This is much more flexible.

I don't really see any need to use OO structure in this code. It definately could still be written better though.

Indentation

Your way of indenting makes code very hard to read. Compare:

 $pic_names.each do |name|
 print 'ˁ ̊ᴥ ̊ˀ '
 new_name = if pic_number < 10
 "#{$file_name} 0#{pic_number} .CR2"
else
 "#{$file_name} #{pic_number} .CR2"
end
require 'fileutils'
include FileUtils
cp(name, new_name) 
pic_number = pic_number + 1
end

and:

$pic_names.each do |name|
 print 'ˁ ̊ᴥ ̊ˀ '
 new_name = 
 if pic_number < 10
 "#{$file_name} 0#{pic_number} .CR2"
 else
 "#{$file_name} #{pic_number} .CR2"
 end
 require 'fileutils'
 include FileUtils
 cp(name, new_name) 
 pic_number = pic_number + 1
end

Ruby style guide contains some usefull examples on how you should indent your code to make it nice to read. Generally every block means 1 level of indentation (2 spaces).

Require

require 'fileutils'
include FileUtils

You only need to require 'fileutils once, at top of your file. include also doesn't need to be reapated, instead generally it should be at top of a module - will get to that.

Avoid globals

Instead of putting result of your methods in global variables, return from them. I.e:

def folder
 puts "Enter the folder name"
 while folder_name = gets.chomp
 if File.exist?("#{$folder_name}")
 puts "This folder already exists, choose a unique name"
 else
 require 'fileutils'
 FileUtils::mkdir_p "/home/moot/pickaxe/pics/#{$folder_name}"
 return folder_name
 end 
 end
end

And than:

folder_name = folder
Dir.chdir "/home/moot/pickaxe/pics/#{folder_name}"

This is much more flexible.

I started to write a detailed review, but in middle of it I realised that best advise I could give you looking at this code is to pick up some good Ruby book and work through it carefully, paying attention to how examples are formed. You seem to understand basics of how programming works, but your code lacks proper usage of many basic concepts, like arguments, returning, modules etc. Explaining them in detail here seems pointless, it's not a place for Ruby tutorials. You should focus on that basics before you move to object oriented design/conventions.

Still, I'll post what I already wrote as advices for you.


I don't really see any need to use OO structure in this code. It definately could still be written better though.

Indentation

Your way of indenting makes code very hard to read. Compare:

 $pic_names.each do |name|
 print 'ˁ ̊ᴥ ̊ˀ '
 new_name = if pic_number < 10
 "#{$file_name} 0#{pic_number} .CR2"
else
 "#{$file_name} #{pic_number} .CR2"
end
require 'fileutils'
include FileUtils
cp(name, new_name) 
pic_number = pic_number + 1
end

and:

$pic_names.each do |name|
 print 'ˁ ̊ᴥ ̊ˀ '
 new_name = 
 if pic_number < 10
 "#{$file_name} 0#{pic_number} .CR2"
 else
 "#{$file_name} #{pic_number} .CR2"
 end
 require 'fileutils'
 include FileUtils
 cp(name, new_name) 
 pic_number = pic_number + 1
end

Ruby style guide contains some usefull examples on how you should indent your code to make it nice to read. Generally every block means 1 level of indentation (2 spaces).

Require

require 'fileutils'
include FileUtils

You only need to require 'fileutils once, at top of your file. include also doesn't need to be reapated, instead generally it should be at top of a module - will get to that.

Avoid globals

Instead of putting result of your methods in global variables, return from them. I.e:

def folder
 puts "Enter the folder name"
 while folder_name = gets.chomp
 if File.exist?("#{$folder_name}")
 puts "This folder already exists, choose a unique name"
 else
 require 'fileutils'
 FileUtils::mkdir_p "/home/moot/pickaxe/pics/#{$folder_name}"
 return folder_name
 end 
 end
end

And than:

folder_name = folder
Dir.chdir "/home/moot/pickaxe/pics/#{folder_name}"

This is much more flexible.

Source Link
Borsunho
  • 907
  • 5
  • 8

I don't really see any need to use OO structure in this code. It definately could still be written better though.

Indentation

Your way of indenting makes code very hard to read. Compare:

 $pic_names.each do |name|
 print 'ˁ ̊ᴥ ̊ˀ '
 new_name = if pic_number < 10
 "#{$file_name} 0#{pic_number} .CR2"
else
 "#{$file_name} #{pic_number} .CR2"
end
require 'fileutils'
include FileUtils
cp(name, new_name) 
pic_number = pic_number + 1
end

and:

$pic_names.each do |name|
 print 'ˁ ̊ᴥ ̊ˀ '
 new_name = 
 if pic_number < 10
 "#{$file_name} 0#{pic_number} .CR2"
 else
 "#{$file_name} #{pic_number} .CR2"
 end
 require 'fileutils'
 include FileUtils
 cp(name, new_name) 
 pic_number = pic_number + 1
end

Ruby style guide contains some usefull examples on how you should indent your code to make it nice to read. Generally every block means 1 level of indentation (2 spaces).

Require

require 'fileutils'
include FileUtils

You only need to require 'fileutils once, at top of your file. include also doesn't need to be reapated, instead generally it should be at top of a module - will get to that.

Avoid globals

Instead of putting result of your methods in global variables, return from them. I.e:

def folder
 puts "Enter the folder name"
 while folder_name = gets.chomp
 if File.exist?("#{$folder_name}")
 puts "This folder already exists, choose a unique name"
 else
 require 'fileutils'
 FileUtils::mkdir_p "/home/moot/pickaxe/pics/#{$folder_name}"
 return folder_name
 end 
 end
end

And than:

folder_name = folder
Dir.chdir "/home/moot/pickaxe/pics/#{folder_name}"

This is much more flexible.

lang-rb

AltStyle によって変換されたページ (->オリジナル) /