2021-03-01 20:37:44

so I was messing around with flutter on my school computer and I tried to edit the code. For fun, I don’t know much yet but I’m learning. After I tried to compile it, it gave me a bunch of errors about missing parentheses and all of that. How do you guys keep track, visual studio code seems to help a lot with this but there’s one thing it doesn’t help with. There are sometimes where you need to put a comma or a semicolon And I never know where I need to put them. How do you people keep track of this?

2021-03-01 20:46:51

Practice.  Nothing but practice.  Keep at it and it gets easier.

For semicolon, comma, etc. those are just rules of the language.  For parens, brackets, braces, etc. eventually you learn to keep a count in your head when reading, even if you don't move character-by-character.

If you don't understand the rules in the first place, spend time on that.  If you do, but it's still a problem, slow yourself down and think about it as you write code, rather than writing as fast as possible and letting the compiler complain.

Finally, note that the compiler won't always complain.  In some languages with some libraries, foo(bar(1), 2) and foo(bar(1, 2)) can both be valid code, but with very different meanings.  This is especially true when you're talking about vector math libs, but in lots of other places as well, for instance in Python with libraries that use default parameters a lot.

My Blog
Twitter: @ajhicks1992

2021-03-01 21:09:55

when I write code blocks, I put the brackets first, then I write the content of the block. i.e. first, I write:
if(choice==1)
{

}
then I write the content between the braces. This helps in not forgetting them.

2021-03-02 03:20:41

@3, I personally prefer putting the brace on the same line as the declaration, just because it filters out unnecessary things and is easier to read for me. But that's my preference.
As for the question itself, I've seen some authors do this in their code -- it may help:

while (cond) {
if (cond) {
// lots of opening braces here
} // if
} // if
} // while
} // for
// ...

This might help you know when things begin and end. In languages like Ada, things like this are required, e.g.:

procedure foo is
begin
if condition then
-- block
end if;
end foo;
"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2021-03-02 03:27:47

Indentation

End of Post!
Leos signing off.
CFN ID: LeosKhai. (Always looking to fight people)
Discord: leos_khai

2021-03-02 21:47:38

@4, I think this is common in java and js. I work with c#, and the convention, at least in my company,  is to put the brace on a single line, so I don't have a choice. It is not so bad though, since I can diferentiate one line if statements from the beginning, without scanning for the end brace.

2021-03-03 14:11:04

Emacspeak will by default announce matching brackets and other delimiters when you type or move over the closing one. For instance, if you have a line like the following:

foo(bar(

Typing a closing parenthesis will make it announce "matches foo(bar(", and for a second one it will announce "matches foo(".

Though I don't necessarily advocate that everyone should be using Emacspeak, I do think this is perhaps a feature that could be added to the accessibility support of VSCode and other editors.

2021-03-03 16:45:18

Opening braces on a line by themselves is a style I've only ever seen used in C, and never before my current job.  Take that as you will.

It's out there, but it's really not the dominant style anymore.

It's also worth adding that if you nest *anything* beyond 3 or 4 levels without a really damned good reason, it's probably bad code.  If your expression is going that deep with the parens, pull part of it out to a variable; if you're going that deep with braces, pull part of it out to a function.

My Blog
Twitter: @ajhicks1992

2021-03-03 17:15:39

@8
Dart (at least what I seen of it) uses a lot of nesting, in flutter for example. You have your class, your material app for example, the homepage, the app bar, The body, the child widget, the child of that child widget and so on and so forth

2021-03-03 18:08:52

@9
It's possible.  I haven't looked closely at dart.  But you can attach things after the fact I think, and there's always variables.  This is entirely pseudocode, but you could do:

sidebar = [
    button { name = "save" },
    button { name = "load" },
]

main_panel = [
    button { name = "back" },
    button { name = "forward" },
    textField: { label = "input some text" },
]

app =  [
    sidebar,
    main_panel
];

Dart uses normal language constructs for UI.  This means you can build up fragments, return fragments from functions, build fragments in loops, and so on.  In this context, deeper nesting is feasible, but look how I laid out the above.  You can indent the levels and let the indentation count it off, and put only a small bit of the nesting on each line.

I think the actual problem here isn't that you can't handle nesting, it's that you haven't actually learned dart properly.

My Blog
Twitter: @ajhicks1992

2021-03-08 06:35:24

Whenever I write an opening, I write the closing right afterwards. So I first type if(), then go arrow left and write the condition, then arrow right to exit paren and type {}, then go back and write everything inside the block. This way I cannot forget to close them. After some time of practice it became really automatic for me.