minimize code

Go To Last Post
21 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hello,

 

atmel studio 7

i'm making a bigger program (any way..for me wink). and i'm struggle a litle bit whit the length of the code.

when i'm programming  some new lines on the bottom, and i have to go to the top, to check something for example, i have to scroll a lot.

thats not comfortable to do, and there is a big risk to lose the overview of the program.

now is there on the left side of the program field a light grey line over the total length of the code. on the line you find some squares with a - or + inside.

when you click on one of these squares a part off the program is fold in or out. that whil make the code shorter en more readable.

the question: is there a way to control the position of these squares, and is there something where you can control the length what is fold in/out ?

 

ore are there better ways to managed my problem ?

 

thanks in advance.

Last Edited: Sun. Dec 22, 2019 - 07:32 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

One of the things you can do to shorten the visual length of the code is to collapse loops, if() statements, functions, and such. 

 

To see how it works, find a function and note the first line of that function. At the left edge of the window is a little symbol (don't remember its shape). Clicking that symbol collapses the entire function. Clicking again expands it. Now that you know what that symbol is, you will see it other places in front of if(), while(), for() and similar statements. Try it out and see if that helps.

 

There MAY also be split screen (don't remember, I mostly use a third-party editor that DOES have it). If there is, you can split the window into two parts have the beginning in one half and the part you are working on in the other half.  When there is a screen splitter, the splitter icon is usually just above the vertical scroll bar, or close to that area.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

Last Edited: Sun. Dec 22, 2019 - 08:07 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i think you mean whit "that symbol with that shape" the square whit the - or + where i was talking about.

 

i don't want to split the screen in to two parts, the parts gives a smaller field to program in. and i find that is to small already smiley 

Last Edited: Sun. Dec 22, 2019 - 08:26 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Click the symbol and observe what happens.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yes a part of the code wil fold ln and out.

only i can't control the position of that symbol and:

i can not control the length of the code wat is fold in or out.

it looks random to me.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not at all random.

 

You fold entire functions (and everything in it) when the symbol is on the first line of a function.

 

You fold an entire  for() or while() operation, and everything in it, when the symbol is in front of a for() or while() statement

 

You fold an entire if() up to the next else if() or else that is at the same level as the original if(). Each of those, if(), else if (), else is treated as a separate foldable unit.

 

Ditto, select() and case statements. Lke if() in may fold in multiple units.

 

You just need to try it and learn how it  operates. This is one of the reasons for breaking up large code blocks into smaller .c and .h file units. Check out:

 

https://www.avrfreaks.net/forum/...

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

Last Edited: Sun. Dec 22, 2019 - 08:45 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks for your help.

 

i'm gonna study tomorrow the link.

if i take a close look to the thin light grey line (put on my reading glasses wink) i find some small thin light grey lines right-angled on the long light grey line.

that looks to me the and of a part wich is folding in.

but not every if has a folding symbol. i still don't see the structure of it.

i prefer that i can place them on a place where i like.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Folding only makes physical sense where there is a block that has a well defined beginning and end. Trying to fold at an arbitrary location could bring all kinds of difficulties.

 

Folding is also not the universal solution to your problem. If there are many folded blocks between the two points that you want to observe, you may never be able to see both. That is just the nature of code. 

 

Then, again, breaking a project into .c and .h files is not a universal solution, either. That is why grep was invented. As soon as you figure out how to break your program into several files, you will discover the need for grep (will search across multiple files, among other things). The AS7 editor may have that capability in its Find - CodeWrangler, the third-party editor I use, DOES have it. With it, I can load 100 files and search through all with a single command. That editor also has code folding (do not used it very much) and window splitting (used just 3 or 4 times in 10 years).

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


 

 

Ultraedit allows you to select any amount of text you want & hide/unhide it.  Maybe some other editors allow this too.  You might want to ask yourself why the code is so long; maybe it needs broken down into more functions, which can be collapsed in most editors.

 

https://www.ultraedit.com/wiki/Hide/show_selection    

 

Also, maybe get one of those monitors that you can rotate vertically...I have a few & sometimes that is handy, I use a VP2770 monitor, though I really don't rotate it as much as I used to.  Since it is discontinued, you might get one cheeeep

Here is the newer vp2771, which supports rotation, like the vp2770

https://www.ebay.com/itm/ViewSonic-VP2771-Professional-27-1440p-WQHD-Monitor-2560-x-1440-IPS-Panel/153762333005?hash=item23ccf3014d:g:3HQAAOSwNbZd9Zfw:sc:FedExHomeDelivery!45040!US!-1

 

What ViewSonic monitors can support Auto Pivot function?

Created by: Jeff Kuo

Modified on: Tue, 27 Mar, 2018 at 12:35 PM


Only the following models can support Auto Pivot function.

VP2468/VP2771/VP2775/VP3268-4K/VP2785-4K

 

 

 

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Mon. Dec 23, 2019 - 09:30 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

avrcandies wrote:

You might want to ask yourself why the code is so long; maybe it needs broken down into more functions, which can be collapsed in most editors.

 

Indeed. Many people advocate that each function should be no more than 50-100 lines long, ideally no longer than what you can see on one printed page or one screen.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ka7ehk wrote:
... (will search across multiple files, among other things).

...

That editor also has code folding (do not used it very much) and window splitting (used just 3 or 4 times in 10 years).

In Visual Studio Code, Minimap and horizontal/vertical splits plus a search view.

Minimap | Visual Studio Code User Interface

Side by side editing | Visual Studio Code User Interface

Views | Visual Studio Code User Interface

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

You urgently need to Google the term "cyclomatic complexity". If you are writing functions so long you get lost scrolling through them - you have drastically failed to understand the concept of modularity!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If I remember correctly it will only fold unfold if(), while(), etc. If they have corresponding {} brackets.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

no,....i don't think that is thru.

 

i have 2 screens, 1 is the laptop screen, and the second one is a wide screen (is that the correct therm ?) that i rotate 90 degrees, and then from the top to the bottom programming field......its ideal smiley 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am totally with CLawson on this one.  If your C code is too long to fit on a moderate 1080 to 1600 pixel high monitor you have a problem with your code/programming style not a problem with your IDE or display.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you are doing a lot of assembler code, having the taller lcd might be nice, but for most C code it isn't needed nearly as much.  Occasionally, it's nice to have the extra vertical room so you can "see it all" at one time, when you're scratching your head, trying to mentally put it all together.  Then you appreciate the extra headroom.   But even then, why not use some diagramming tools?

 

The bothersome issue is, laptop screens seem to have gotten smaller the last decade (where are all the 18+ inch laptops?) & I'm not gonna switch to a smaller font!

 

 

 

 

    

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Cognitive complexity is an alternative to cyclomatic complexity.

May one grok the code ... well, may be more "fun" to "Rock the Casbah".

 

C: Cognitive Complexity of functions should not be too high via https://www.avrfreaks.net/forum/jacks-top-ten-reasons-project-failures#comment-2760396

Rock the Casbah - Wikipedia

Rock the Kasbah (2015) - IMDb

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:
(where are all the 18+ inch laptops?)
Too heavy for the backpack; a solution is the forthcoming Microsoft Surface Neo (655g) and Windows 10X (0g)

Surface Neo: Everything we know so far | Windows Central

via https://www.avrfreaks.net/forum/another-win10-rant-frustration-part-3?page=2#comment-2789081

 

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"Dare to be naïve." - Buckminster Fuller

Last Edited: Thu. Dec 26, 2019 - 04:14 PM