Change the Default sketch

When Arduino loads, it opens up a blank sketch. This is highly unhelpful as I can't think of a time when you are not either going to load a saved sketch, or start a new arduino one. In the first case, it opens in a new window so you are still left with the blank one open anyway so it doesn't matter what is in it, and in the second case, you are always as far as I can tell going to need the following lines:

void setup(){
  
}

void loop(){
  
}

So why not have them there by default? Instead you have to either write it out every time, or load the Bare Minimum sketch (which would leave the empty window open anyway!).

Tom
I support this idea.
Best regards
Jantje

Why? You typically have a bunch of stuff that goes before
void setup(){
}

such as adding notes, importing libraries, declaring variables, defining pin names, etc.
Typing in the 25 characters just goes with the coding effort.

If you have a bit of code that you use over and over again, do you write it out each time? No, you put it in a function.

If you have a development environment the use of which uses sketches which all always have to contain the same 25 characters, does it make sense to load a useless blank page and have the user write those characters out over and over again every time, or do you load a blank sketch with those 25 require characters automatically?

Maybe a flawed comparison but the point still stands. If you are going to go to the trouble of having a sketch called BareMinimum, why on earth would you not load it each time?
If you are going to put stuff before it, just have a blank line before void setup(), that way you can easily add extra stuff.

I can understand the lines not being there when you open up an extra tab, as those tabs are usually either header files or extra cpp files, but the main sketch must have setup and loop. It never doesn't. It won't compile if it doesn't. So give one good reason why they shouldn't be there by default.

This is easy to implement and useful. Maybe even you can add some comments like // Project // Author:

So why not have them there by default?

There are times that I wish to do a simple paste of a complete sketch that I might have seen and copied on a posting here, so a blank screen is appropriate for that case. Preferences are highly subjective and subject to a wide range of personal opinions and tastes, I think having the IDE start with a blank edit page is not a totally bad choice.

I have called up the bare minimum sketch at times, then close the blank window and then do a 'save as' before moving on with the new sketch under it's now new name, not that hard or slow a procedure to perform.

Lefty

Maybe it could be an option in the preferences then.

retrolefty:
There are times that I wish to do a simple paste of a complete sketch that I might have seen and copied on a posting here, so a blank screen is appropriate for that case.

In this case you do a simple select all (ctrl a) before pasting (ctrl c). This is less work than typing 25 characters (plus comments).
Most development environments have the skeleton in one way or another.
I think it is also easier for a newbie to see the sketch structure.
Best regards
Jantje

PS for those interested:My eclipse plugin does this.

Jantje:
(ctrl a) before pasting (ctrl c).

Yup, thats what I do when helping out, I have one instance open and just ctrl-a/ctrl-v in the next persons code.

I never use the examples & stuff in the IDE, I just start typing. Maybe its a hardware guy thing.
I have also never written a function. Just put the code inline where I want it to happen, no bouncing back & forth popping things off the stack & whatever. Let the compiler take care of it.
I think this is making too much of a trivial thing.

CrossRoads:
I never use the examples & stuff in the IDE, I just start typing. Maybe its a hardware guy thing.
I have also never written a function. Just put the code inline where I want it to happen, no bouncing back & forth popping things off the stack & whatever. Let the compiler take care of it.
I think this is making too much of a trivial thing.

Well as you might know, I'm a hardware guy also. But I try and always write related logical code sections into reusable functions for future use with other sketches, especially functions that work with external chips like external A/D or D/A chips. I don't do the whole library thing yet, but do try and put common functions into tabbed windows that are easy to copy into other sketches. Standalone functions along with good comments almost let you throw the external device datasheets away once you prove out the basic commands for them.

Lefty

CrossRoads

CrossRoads:
I have also never written a function. Just put the code inline where I want it to happen, no bouncing back & forth popping things off the stack & whatever. Let the compiler take care of it.

I'm a software guy.
In my current project I have 43 self written files. As I use header files I'm willing to say 21.
That is a lot of code to use inline only. I also extensively use classes which are easier to maintain when in separate code files.
I don't understand your following remark:

popping things off the stack & whatever. Let the compiler take care of it.

As far as I know the compiler takes care of this. (Are you not mixing the heap and stack? I avoid using the heap not the stack.)
If you only use inline code I think you miss a great wealth of functionality.
I think that the Arduino ide does not invite the user to take the code development path. Even worse: the design decisions taken to make it simple for the "beginner" make it hard to get past the beginner coding experience. I'm thinking about: No support for library development, the keywords files needed for libraries, No support for multiple folders, All files open in a folder, no source code control integration ....
That is why I started to build my eclipse plugin.

Don't get me wrong. I do feel the Arduino IDE is the place to start. And if I had to design a IDE for beginners -for whom the IDE is designed- I would probably take the same decisions and come to a very similar result.

I would like to compare it to learning the people to ride a bicycle (assume nobody knows bicycles). If you design a cheap and cheerful bicycle to learn people to ride a bicycle you will probably create a three wheeler.
If you only know a three wheeler it is not obvious to think of a two wheeler( Another learning curve and opportunities to fail).
But if you know motorbikes a three wheeler is very limiting.
For all clarity: The three wheeler is the Arduino IDE; The motorbike is a professional "software development environment".
Not being a hardware guy I would think it is the same discussion as "why use shields" among the hardware guys.
Just my 5 cents

Best regards
Jantje

There's probably some truth in the beginner vs pro description.
Some of what I do may end up working like a function - I set some variables as flags, if another part of the code sees that flag set it does something & clears the flag to show its done; such as updating a display.
Right now I am writing some code with 3 or 4 modes. Each mode is its own tab. So loop runs, checks a flag, jumps to that tab, that tab finishes, falls thru & updates the display if the mode did something.
So sort of function like, even if not called that.
One could argue its style too.
Heap, stack, whatever. I declare all variables before void setup, they get used uniquely within the tabs, a few are shared & updated among all. Haven't gotten myself into trouble yet ( fingers crossed ... )
I don't have any shields either. If I need something, I just build it up. I do have some different audio & video things to play with, haven't built them into any project yet tho. Really just a matter of finding a project to put them in.

CrossRoads:
There's probably some truth in the beginner vs pro description.
Some of what I do may end up working like a function - I set some variables as flags, if another part of the code sees that flag set it does something & clears the flag to show its done; such as updating a display.
Right now I am writing some code with 3 or 4 modes. Each mode is its own tab. So loop runs, checks a flag, jumps to that tab, that tab finishes, falls thru & updates the display if the mode did something.
So sort of function like, even if not called that.

Well then you are using user defined functions, as the whole tab thing is pre-compiled time construct. Once the whole sketch is compiled it's all one single program where the loop function is calling your user written functions that return to main loop.

One could argue its style too.
Heap, stack, whatever. I declare all variables before void setup, they get used uniquely within the tabs, a few are shared & updated among all. Haven't gotten myself into trouble yet ( fingers crossed ... )

That is another way of saying you use mostly global variables. I do too, especially on smaller sketches, but that is considered poor practice by most pro type programmers that will or might say that all variables should be local only unless there is a strong reason they must be global. This is one of the hallmarks (proper scope of variables) of a good structured programming language. But again I tend to use global because it just seems to work better for me on small projects, as I'm a write, test, run, debug, rewrite, test again type of guy. I rarely try and write a complete working sketch in one operation. Kind of like building electronic projects on circuit/section at a time and testing as you go rather then building the complete project from the start before testing.

I don't have any shields either. If I need something, I just build it up. I do have some different audio & video things to play with, haven't built them into any project yet tho. Really just a matter of finding a project to put them in.

I use hardwired (soldered wirewrap wire) proto-board shields for projects that I want to keep long term, but will test them first on solderless bread board. I haven't had the desire yet to learn to make my own PCB, but that's mostly laziness on my part, it is a better method with the software and other tools available to hobbyist today.
Lefty

Well then you are using user defined functions, as the whole tab thing is pre-compiled time construct.

Well, yes and no and perhaps both :slight_smile:
Yes, as this time around I have several distinct modes that will run, selected during void setup. Have to reset to change modes.
No, in that I am using tabs because I got tired of scrolling up down this huge page.
Perhaps user defined with the display code, where it reads a flag and acts on global variables.

XD I changed the default sketch and published it as a mod:
http://arduino.cc/forum/index.php/topic,118440.0.html

Is it just a modified class file like before? If so could you just post that class file as I don't need all the other stuff and this 50MB download is taking forever (its not my internet access as usually I get about 20Mb/s)

Yes but I don't remember 100% if is only this file, this time was harder to add via 'hack', I used an old string I found inside the class (something about "Sunshine- go to take a walk", when the sketches of the day are more than N number hahah). (Attached)

Base.class (37.8 KB)

Thanks, that worked great. Just renamed pde.jar in the /lib/ folder to a zip, replaced the class file, and renamed it back. Worked a treat!

I modified that class a tiny bit - I just replaced a couple of the characters in the default sketch for the same amount of different ones, so that it is now this:

void setup()
{
  // This code will only run once, after each powerup or reset of board
  
}

void loop()
{
  // This code loops consecutively 
  
}

Having the new lines is helpful. Yeah I know, I am too lazy to just press Enter, LOL!

I think I can live without the weird string about taking a walk!

Base.class (37.8 KB)