Page 1 of 1

LC App design theory?

Posted: Tue Mar 07, 2017 9:53 pm
by monki
I was wondering if there are there any resources, links, for LiveCode app design? Where to place scripts in a stack, best practices, things to avoid, and so on?
Thanks

Re: LC App design theory?

Posted: Tue Mar 07, 2017 10:49 pm
by dunbarx
Are you completely new to LC? If so, welcome.

But you need basic knowledge to be able to appreciate any answer you might get here.

Once you get the hang of LC, and can drive comfortably, even if not at breakneck speed, do ask that question again. It will not take too long.

Check out the scripting conferences: http://www.hyperactivesw.com/revscriptc ... ences.html
and http://livecode.byu.edu

There are other fine sites as well, written and maintained by LC advocates.

As well as the user guide, dictionary and lessons, all available in the "help" menu.

If you are a bit more experienced, please ask more specific questions.

Craig Newman

Re: LC App design theory?

Posted: Wed Mar 08, 2017 12:52 am
by shaosean
Avoid using global variables..

Re: LC App design theory?

Posted: Wed Mar 08, 2017 9:18 am
by AndyP
Hi shaosean,

I was wondering why you advise against using global vars?

Are you advocating the use of custom properties instead?

I use global vars all the time and do not encounter any problems as long as you remember to add the deceleration at the top of each card etc. In fact doing so, I find reinforces in my memory that the global exists.

Re: LC App design theory?

Posted: Wed Mar 08, 2017 4:02 pm
by dunbarx
Globals are a matter of style. I prefer custom props, but now and then use them. Context seems to favor one over the other...

But that is a tiny issue with respect to the original question. Or is it?

Craig

Re: LC App design theory?

Posted: Wed Mar 08, 2017 6:45 pm
by monki
Thanks for the answers.

Let me clarify a bit. I've built a few apps for my personal use, and have taught myself along the way. So, not completely new but self-taught and mostly feeling around in the dark.

I've also read a bit about smalltalk, looked at some of the books online. One thing that is both a pro and a con of that environment is that you get a lot of design theory right at the start: How long a method should probably be, how it should be named, what, generally, it should do, and moves into the fine details.

There were some books that kind of touched on this for hypercard, I have an old Goodman book where he talks about naming related objects the same thing if they reference each other: button "timeCode", field "timeCode", group "timeCode". That way a mouseUp on group, card or stack level can reference (field (short name of target)) and get the correct field. So I don't have to code a bunch of different mouseUps that do the same thing but reference different objects: buttons, fields, graphics, etc.

I was wondering if there were any updated material that dig into this kind of thing that was created after the 90s?

So questions like: Is it a good idea to name fields, buttons, groups the same thing? Should object names "haveNoSpaces" or be easier to use "with some spaces"? I can see how the later naming convention would be better. A script could easily shift between objects if objects were named "my field 6" by just adjusting word 3 of (short name of target).

So this kind of general ideas about app building was what I was wondering about. I understand that different people will have different approaches but learning what approaches people use would be insightful. :)

So, a more abstract question about style than solving a particular problem.

Thanks.

Re: LC App design theory?

Posted: Wed Mar 08, 2017 8:14 pm
by dunbarx
OK.

I generally assign related controls with related names. For example, in a project I am working on, I have multiple groups of fields, three fields high and twelve long. That is, groups of 36, like a row of connected three story buildings. I name the fields in the "top floor" of the first group "top,1,1", top,1,2", etc. The "middle" floor would be "middle,1,1", "middle,1,2", etc.

In this way if the user clicks on fld "bottom,4,8" I know all about its neighbors, especially those in the same "building". I could for example, put new data into fld "top,4,8", that field being the one two above the target by simply (pseudo):

Code: Select all

put newData into fld "top" & "," & item 2 of the short name of the target & ",' & item 3 of the short name of the target
A single mouseUp handler in the card script does just that. Anyway, that sort of thing.

Craig

Re: LC App design theory?

Posted: Wed Mar 08, 2017 8:54 pm
by FourthWorld
Hi monki -

There's a lot of dogma about global variables, among users of many languages. But most languages still provide them, so there must be some value in using them. Shao Sean's guidance is appropriate, avoiding absolutes to suggest mindfulness instead. Here's my own take on globals, and the practical considerations of their alternatives:
http://forums.livecode.com/viewtopic.ph ... 57#p129457

As for more general questions of structure and naming, how much of the User Guide have you read? With more than 650 pages it's pretty beefy and almost no one reads the whole thing, but you may find the chapter "Programming a User Interace" worth a skim, esp. the section in it titled "Referring to Objects".

Re: LC App design theory?

Posted: Wed Mar 08, 2017 10:06 pm
by monki
dunbarx wrote:OK.

I generally assign related controls with related names. For example, in a project I am working on, I have multiple groups of fields, three fields high and twelve long. That is, groups of 36, like a row of connected three story buildings. I name the fields in the "top floor" of the first group "top,1,1", top,1,2", etc. The "middle" floor would be "middle,1,1", "middle,1,2", etc.

In this way if the user clicks on fld "bottom,4,8" I know all about its neighbors, especially those in the same "building". I could for example, put new data into fld "top,4,8", that field being the one two above the target by simply (pseudo):

Code: Select all

put newData into fld "top" & "," & item 2 of the short name of the target & ",' & item 3 of the short name of the target
A single mouseUp handler in the card script does just that. Anyway, that sort of thing.

Craig
Great, Thanks.
I see that you're using itemized object names, interesting idea. Never thought of doing that, might start though.

Re: LC App design theory?

Posted: Wed Mar 08, 2017 10:27 pm
by monki
FourthWorld wrote:Hi monki -

There's a lot of dogma about global variables, among users of many languages. But most languages still provide them, so there must be some value in using them. Shao Sean's guidance is appropriate, avoiding absolutes to suggest mindfulness instead. Here's my own take on globals, and the practical considerations of their alternatives:
http://forums.livecode.com/viewtopic.ph ... 57#p129457

As for more general questions of structure and naming, how much of the User Guide have you read? With more than 650 pages it's pretty beefy and almost no one reads the whole thing, but you may find the chapter "Programming a User Interace" worth a skim, esp. the section in it titled "Referring to Objects".
I usually use custom properties at the stack level for any global variables, then use commands and functions for set, and get. That's worked well for me. Think I got the idea from the newsletter article you linked in the post. It's a great idea, I use it all the time. I didn't know about the lockMessages issue, so that's something to keep in mind. But so far it hasn't come up.

I don't think globals are evil, just dangerous. However, I have thought about using a global or two to create my own version of the "it" variable, but it would only be set by me. As long as its use is compartmentalized into small handlers, I don't think it shouldn't be a problem. I declare all my variables using "local", but there are times when I just want to do a little thing. I could use "it" for that. But it could be safer to have something that the environment doesn't use. I guess a script variable would work better for that.

I've read parts of the User Guide, but no, I haven't read all of it. I will take a look at that section again though.

Thanks.

Re: LC App design theory?

Posted: Wed Mar 08, 2017 11:34 pm
by dunbarx
I see that you're using itemized object names,
It is just a way to parse and create references "internally". Anything would do.

Be careful with "it", and even more so with "the result". They have a habit of changing on you. Store them somewhere immediately unless you really are sure...

But it sounds like you are well ahead of the level of questions you are asking. This forum is for just that sort of thing, of course, and others will likely be interested. I would just say that as you use LC more, you will find your own comfort level.

Craig

Re: LC App design theory?

Posted: Thu Mar 09, 2017 11:16 pm
by shaosean
AndyP wrote:Hi shaosean,

I was wondering why you advise against using global vars?

Are you advocating the use of custom properties instead?

I use global vars all the time and do not encounter any problems as long as you remember to add the deceleration at the top of each card etc. In fact doing so, I find reinforces in my memory that the global exists.
More a matter of preference I guess.. I personally prefer a library stack with a nicely defined API to have access to the data.. So many different ideas about programming styles, just find one that works for you and go for it, but for new coders, I would recommend against globals as it may end up causing them some wondering about why something does/doesn't work..

Re: LC App design theory?

Posted: Fri Mar 10, 2017 12:23 am
by FourthWorld
shaosean wrote:So many different ideas about programming styles...
There is only one immutable truith: no dangling "then"s.

This:

Code: Select all

if Something() then
   SomethingElse
end if
...is readable and pleasing, but this:

Code: Select all

if Something()
then
    SomethingElse
end if
...is the work of the devil.

:)

#TheStruggleIsReal