Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] Lines of Code
#11
I ain't reading everything in this thread but my two cents is that LOC is the Least Of my Concerns. Get the product working and get it working well. Who gives a shit how long the source is.
The noticing will continue
Reply
#12
Yep, go to China Town and ask for Who.... because Who gives a shit!

Oh and Steve. The only way you get a Volkswagen Bug up to 200 is to blow it the **** up. It's fun to watch, and you also get credit for performing a valuable public service.

Pete Big Grin

- Deport Now. Ask Me How!
Reply
#13
When a bit older, I really want to be able to understand my code from a couple of years ago

Sometimes I intentionally put all statements on separate lines to show all separate steps that are done and give them a bit more 'weight' in the sub or function:
Code: (Select All)
if order% = _TRUE then
  Input "What do you want to order? ", food$
Else
  Print "Goodbye"
End If
Sometimes I put statements on the same line to show they belong together and do some small housekeeping:
Code: (Select All)
if groupsize% < 10 then groupsize% = groupsize% + 1 Else groups% = groups% + 1: groupsize% = 0
45y and 2M lines of MBASIC>BASICA>QBASIC>QBX>QB64 experience
Reply
#14
Code: (Select All)
groupsize = groupsize + 1   'Increase the size of the group by 1
groups = groups + groupsize \ 10  'the there's 10 or more, break them into new groups
groupsize = groupsuze mod 10 'the groupsize of the empty group is now the leftovers

And ^ there's an example where multiple lines are better than that single line of code.  No if to deal with, so no decision making or comparison involved.  Just basic one step maths, with room beside each statement to remark what it's doing and explain the thought process behind it.  It's going to me more efficient than the single line statement, and it even works if large additions were to suddenly pop up such as 23 new people getting off a bus all at once, making it more flexible and easy to expand if the code usage needs an upgrade in the future.

It's more lines of code, but it's BETTER code in many ways, and that's the point I've been trying to make all along.  Few lines of code seldom makes more efficient or better programs.  It just makes more work.  Smile
Reply
#15
Your code is more efficient and better in what it does.

Still (fully depending on functional view of the code at that place) I would put them on 1 line if managing groups & groupsizes is not the main focus of the function it is in; it might be some less important housekeeping.
Then I would prefer to only occupy one line on my screen

If this was in a function with the main responsibility of managing groups & groupsizes, I would put them on 3 separate lines
45y and 2M lines of MBASIC>BASICA>QBASIC>QBX>QB64 experience
Reply
#16
Minimizing lines is good in only a couple of ways, for me:

Code: (Select All)
Dim As Long a: a = 5

You don't need two lines for that. The above crudely emulates how other languages allow you to assign a value during the definition.


Code: (Select All)
If thing = 1 Then DoThing()

Rather than:
Code: (Select All)
If thing = 1 Then
DoThing()
End If
The noticing will continue
Reply
#17
I'm with Spriggsy on the use of IF/THEN blocks. I use them if multiple statements are part of the condition, not just a single statement. I also look at the statement(s) length on the line. Frankly, I'd rather be able to read everything without lateral scrolling. Any good chiropractor will tell you doing it that way is better than developing a bad case of SCROLLIOSIS.

Wait... Ah, Steve. Who was it you asked me to pun to death, yesterday?

Pete
Reply




Users browsing this thread: Stuart, 7 Guest(s)