Pages: [1] 2   Go Down
Author Topic: Change the Default sketch  (Read 2042 times)
0 Members and 1 Guest are viewing this topic.
Leeds, UK
Offline Offline
Edison Member
*
Karma: 80
Posts: 1729
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Code:
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!).
Logged

~Tom~

Belgium
Offline Offline
Edison Member
*
Karma: 68
Posts: 1926
Arduino rocks; but with my plugin it can fly rocking the world ;-)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Tom
I support this idea.
Best regards
Jantje
Logged

Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27357
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Leeds, UK
Offline Offline
Edison Member
*
Karma: 80
Posts: 1729
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: August 10, 2012, 02:14:36 pm by Tom Carpenter » Logged

~Tom~

Chile
Offline Offline
Edison Member
*
Karma: 35
Posts: 1251
Arduino rocks?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

My website: http://ried.cl

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17301
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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
Logged

Leeds, UK
Offline Offline
Edison Member
*
Karma: 80
Posts: 1729
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe it could be an option in the preferences then.
Logged

~Tom~

Belgium
Offline Offline
Edison Member
*
Karma: 68
Posts: 1926
Arduino rocks; but with my plugin it can fly rocking the world ;-)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Leeds, UK
Offline Offline
Edison Member
*
Karma: 80
Posts: 1729
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

(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.
Logged

~Tom~

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27357
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17301
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Belgium
Offline Offline
Edison Member
*
Karma: 68
Posts: 1926
Arduino rocks; but with my plugin it can fly rocking the world ;-)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Quote
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
Logged

Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27357
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17301
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

« Last Edit: August 11, 2012, 05:34:34 pm by retrolefty » Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27357
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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 smiley
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.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1] 2   Go Up
Jump to: