0 points
Submitted by mrdavidispikachu
almost 9 years

What's the point of an implicit return?

In other words, besides the fact that you don’t have to type return to return something, what else can you do with this capability?

Answer 51346e3973d3903c35006142

4 votes

Permalink

It saves you a few keystrokes (typing “return”), that’s all :)

Some people say that implicit returns are faster, but the difference is too tiny to really matter.

points
Submitted by Alex J
almost 9 years

7 comments

johantheolive almost 9 years

As someone who is relatively new to ruby, it seems to go against the ‘ruby way’ of readability to make it less apparent what is being returned, but then again it is dependent on the coder’s choice. Just an observation, thanks for your answers to all these questions.

Cvu over 8 years

So why would anyone use “return” then?

Trumble about 8 years

If you’re code is likely to be read by another I would think best practice would be to use return, since programmer two may be unfamiliar with ruby.

red serpent about 8 years

Am new to programming. My understanding is that good programers document. Would it not be documented anyways if so what is the voice of experienced programers say about saving 6 key strokes. There has to be a smart practical answer to this. Otherwise why built it?

Trumble about 8 years

You’d be best off using explicit, for the sake of the humans reading it. Person 2 may not be familiar with Ruby if they are looking at your code.

You would see a benefit for implicit, over millions/billions/trillions of pieces of data, there would be a time saving that is beneficial and you would favour the implicit over explicit. BUT if saving time is important, you’ve probably picked the wrong language.

It really depends on what you’re building, if you’re building something to monitor the stock market (and you had to use Ruby) you would use implicit, because it’s time sensitive data, where fractions of a second do matter. TLDR; Time = money friend.

red serpent about 8 years

What good coding habit should i develop? implicit/explicit? Why “Build”/allow implicit returns In Ruby while other languages don’t, especially when speed was not the intended purpose as you wrote. We all know time is money, there are many ways of making it. If web development is Ruby’s forte then what is it about web development that requires saving 6 strokes meaningful when documenting it will take more strokes? OK the execution time will be faster by 2/1000 of sec. in 10,000 iterations and one may build a stock market app that crunches numbers …what type of web apps are we talking about OR is it that this feature plays its true part in Rails?

Trumble about 8 years

If we’re talking you’re looking to get a job, I would say explicit would be better. I mean it could be a question on the job as a preference to what others use. I can’t offer you a better answer, sorry.

Answer 5331f05a7c82cadbd6001710

2 votes

Permalink

It would be a good idea that you read this first. It would help us …help you. Once you have read it . Ask us again please, accordingly. We shall be glad to “Help”. Article from Matt Gemell “What have you tried” http://mattgemmell.com/what-have-you-tried/

points
Submitted by red serpent
almost 8 years

Answer 5330d27d282ae3846a0007bb

-1 votes

Permalink

I am having trouble with this excersize can someone give me the code please thanks

points
Submitted by Add your name
almost 8 years

1 comments

just delete return