
This is an app designed for Students for quick access to Unit Conversion Formulas. Milli Absorbance to Absorbance Conversion Pressure in kg/square cm to Head in Meter Temperature Conversion based on the Rankine

Temperature Conversion based on the Kelvin Temperature Conversion based on the Fahrenheit Temperature Conversion based on the Newton Its very useful for student to save valuable time. You have both: ans = c*1.The app lists all the important Unit Conversion formulas. Prefer spaces between operations (and be consistent). In this situation, we structure our input capturing into intuitive grouping that the user might expect - therefore, it's not arbitrary. But I think it's a good thing to be aware of no matter what level the programmer. This may seem overkill for a post like this, but hey, I just finished reading the book and want to help reinforce the concepts. If a structure appears arbitrary, others will feel empowered to change it. Have a reason for the way you structure your code, and make sure that reason is communi- cated by the structure of the code. The essential idea is that when things are consistent, they are more easily read and understood when they're not, things tend to stick out, distract us, and interrupt the flow of whatever we're trying to do.ĭon't be arbitrary is an idea I recently read from Clean Code, a popular book about writing.
#FREE TEMPERATURE CONVERSION APP CODE#
This might not seem like a big deal and it really isn't here but I think it illustrates a couple of important ideas of writing clean code to be mindful of: consistency and don't be arbitrary.Ĭonsistency is often mentioned related to various aspects of writing good code it's especially important when many people are touching the same software. I would have expected 5 to come right after 1.

One thing I noticed when looking at: **1) Convert Celsius to Fahrenheit**Įvery other combination of starting temperature seems sensibly grouped together but 1 & 5 unexpectedly are split up. Methods are self documenting and make code more readable. A key idea here is that you want to be using methods often. These are rough ideas to get you going and of course you'd have to set up the logic appropriately (looping, etc). This would be a good exercise in OOP by refactoring once you get more comfortable. It is preferable to use an object-oriented class based solution rather than conditionals I get the sense that you might not have learned OOP yet. Valid (K, C, F)."ĭo note that this is not an ideal solution. Raise ArgumentError, "Unit: # is invalid. Rather than having 6 methods handling each conversion, you could cut it in half by writing functions such as this: def convert_to_fahrenheit(start_unit, temp) One way you might shorten things up and dynamicize is as follows: Note that conventional Ruby style uses 2 spaces rather then tabs for indentation - I recommend adopting this. You followed reasonably good formatting and style guidelines. Your program appears to correctly convert between temperatures. Ruby especially encourages small methods it's common to see them be as short as a single line.

With your conversion related methods, you've achieved this - nice job. Methods should be short and have a single responsibility. Print "would you like to run again? (Y/N)" Puts "Thank you for using, Temperature Converter!" Please select an option from the following menu: # A simple program to convert either from C to F, or F to C depending on the user's choice. # My project: temperature converter (temp_conv.rb) Any ideas on how I could shorten this up and make it a little more dynamic would really be appreciated! #!/usr/bin/ruby Looking back at it, it's pretty much just a bunch of boilerplate code. I'm learning Ruby and as an exercise I decided to build this little temperature converter app (C to F, F to C, F to K, etc).
