I'd like to define an enum (or something) to give names to possible values of seletedIndex and define the order of destinations in, say, a Flutter NavigationBar in such a way that I only have to go to one place to change the order of the destinations.
The examples I've seen so far always require reordering be done in two places: one in the list of destinations given to the NavigationBar that have an implicit, invisible, unnamed index, and the other is a switch or a subscripting based on selectedIndex to establish the selected page. This seems like a bug magnet. Is there any way to set it up so I only define the order of the destinations in one place and have the list of destinations bound to the correct pages?
It seems to me that NavigationDestination should have a property to handle this binding or a "displayOrder" property, but I don't see this. If there isn't a better way, I guess I could write a function to construct the destination list based on an object (like an enum) that binds the numeric indicies to the corresponding page view, but this seems like a lot of machinery to create for a routine navbar task, especially in this modern OO context -- weird that selecting navbar pages would need a switch in the switchless programming world. Yet the example implementations have switches and two separate areas of the code need to be maintained to do one thing. But, what do I know; obligatory newbie disclaimer follows...
I think my question above was poorly phrased, based on ignorance and seeing some naive examples that suggested page navigation was generally done with an integer like selectedIndex. Once I learned about the Navigator class, and other navigation and List related builders, I saw the OO techniques Flutter provides for putting together hierarchical menus and such without the use of switch statements and integer indicies. So my answer to somebody like me who asks "do I really need to re-invent the navigation wheel" is to learn about Navigation Basics first.
I am reading the code of the Modelica Standard Library. As to the Modelica.Media.Examples.Utilities.ShortPipe, I found that the graphical display didn't agree with the text code.
As the following screenshot shows, I am not sure why there is 1e-05 in the graphical dialogue.
That is just an bad display when looking at parameters from package-browser in that Dymola version, and it will be corrected later (the 1e-5 actually originates in converting between Pascal and bar, and not incorrectly as I first thought in the start-value in the type).
It does not occur when you have dragged in a ShortPipe component to your model (and, of course, you normally should not use that ShortPipe component since it's designed for examples in the media-library).
I am currently trying to learn about GTK from the documentation. However, I am unsure about a slight difference.
G_APPLICATION(app) and
GTK_APPLICATION(app).
or
gtk_application_window_new and g_signal_connect.
So, when is the G used instead of GTK? It's probably a pathetic question but is it to do with GTK being a widget library and adopting a few things?
G_ functions come from GLib, a general-purpose utility library. GTK_ functions come from Gtk+, GUI toolkit based on Glib.
So anything not directly related to GUI (e.g. data structures, signal handling) is part of Glib, whereas GUI bits (windows, buttons etc) are part of Gtk+. Because of that, it's possible to use features provided by Glib outside GUI, for example in console and server applications.
There seems to be some overlap, such as beforementioned GApplication/GtkApplication, but the same rule holds: GApplication forms basis of GtkApplication, where general bits are handled by the former, and GUI-related bits are handled by the latter.
I'm trying to increase my speed of typing code in a Unity project, and finding a big hole in MonoDevelop.
If I have a method like:
void Foo(float x, float y, float, z) {
//
}
When I start typing
Fo
I want it to autofill with:
Foo(x,y,z)
with the x, y, and z, highlighted green.
Currently, it only autofills with
Foo
I would like functionality like what happens when you type for and hit tab twice, where it autofills:
for(int i = 0; i < max; i++) {
}
with max highlighted in green.
I feel like there should be a built in way to do this, but I can't find anything here or on the web. I know for Java in eclipse it has similar functionality to what I want here.
EDIT: Based on a more refined search from the answer below, I was able to confirm that it doesn't seem like you can do this in MonoDevelop. However, this search revealed that Microsoft just released Visual Studio for Mac, which runs super nicely with Unity and has much better code completion features compared to monodevelop. It still doesn't fill in the parameters, but it at least gives you a little popup window guiding you through which ones you need and what type they are. A huge improvement to say the least. After playing around with it for literally 5 minutes, I'm already prepared to scrap MonoDevelop entirely. The nice thing is the interface is basically identical, just seems like a much more polished and modern version.
for+tab+tab is a Code Snippet that has a whole syntax devoted to typing short things and getting long ones. The for syntax is generally unchanged throughout and so it's easy to write a snippet to cover the general use-case.
Methods are not typically in this category of autocompletion, as the number, type, and name of the paramters will change depending on what method is being completed, and so behavior varies by IDE. Eclipse does the best job I've ever seen, even going so far as to make an educated guess as to which variables available in the current scope would be appropriate as parameters! Its not always right (eg. I've gotten something like Translate(xpos, xpos, xpos) before, when Translate(_x, _y, _z) would have been better).
How, and if, you can get Monodevelop to autocomplete method parameters will likely revolve around these snippets. I don't use MD myself so you'll have to dig into the documentation on making your own snippets, but I suspect it won't be possible (based on my own experience reading the snippets docs for Visual Studio).
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
For example, what piece of code is considered better styled? If I show my code to a professional developer and ask if my code is good or not, will using the second style be probably considered as a (minor, but...) minus or a plus to my code quality?
I myself tend to like the second style but would prefer to comply to the most common opinion in this case.
1
val foo : Int = -1
val bar : Int = 1
val yohoho : Double = NaN
2
val foo : Int = -1
val bar : Int = 1
val yohoho : Double = NaN
Did you change your tags? I see several answers referring to Python but the only language tag I see is Scala. If you're interested in Scala I would refer to the unofficial Scala Style Guide. Based on the style guide I would suggest your example should look like this:
val foo = -1
val bar = 1
val yohoho = Double.NaN
The second style will get messed up when variables are renamed using refactoring tools.
It's just my humble opinion, but I personally just hate indentation like the second variant in any programming language. Some claim that "it looks nice" but I find it completely impractical. For example in order to rename the variable yohoho you have to realign all the other variables around (and most editors won't help you with that).
Whatever suits you, you're the coder. The first one just looks funny to me really.
Python's PEP 8 (which is the "Style Guide for Python Code") requests that you don't use whitespace to align code:
Pet Peeves
Avoid extraneous whitespace in the following situations:
....
- More than one space around an assignment (or other) operator to
align it with another.
Yes:
x = 1
y = 2
long_variable = 3
No:
x = 1
y = 2
long_variable = 3
I've tried this with Python, for instance in Django model declarations.
It becomes an OCD inducing pain when you're modifying the code later on. For instance, what if you add a var called yoohoohoey in the 2nd example? You have to go back and add spaces to each line to align it to the new length.
So, I prefer to do things the first way.
Scala doesn't force you to work in either style, but the first is generally preferred because it can really play havoc with diff tools if you have to add a new line and then respace everything else...
On the other hand, if your code/algorithm is much more readable when it's aligned, then align it! Readability trumps all other concerns, as per the agile manifesto:
Individuals and interactions over processes and tools
i.e. It's more important to keep other programmers happy than to keep diff tools happy.
I use the second way, if necessary. Is time consuming to do, but with a bit of time you can configure the auto formatting to make it automatically.
But this is a matter of preference.
The Scala Style Guide is silent on the subject, but I haven't seen vertically align declarations in Scala code, so I'd go with the first choice.
If your goal is to conform to community guidelines, probably the first is more common. But are you looking to fit in -- or to stand out by the quality of your code? Learning what works for you is extremely important.
I suggest you try both styles -- then see how you find working with both. For me, aligning variables is a pain, but it's very helpful when working with larger code files. It's also a nice bit of busy work when I'm stuck on some particular aspect of code and want a little time to let my ideas percolate.
Along this same line of thought, I find that when working with, say, JavaScript, pushing the first line of a function to the far left allows me to scan code very rapidly. That breaks normal indentation rules -- but it's helped me read code far better than nicely indented code.
Whatever suits you is only good enough if you work on your own. If you're part of a group of developers, you should vote and stick to one way. Keep a list of coding standards and enforce it in code reviews.
How often do you have multiple initialized val or var declarations in a Scala file anyway? Top level vals and vars in classes should mostly be primary constructor parameters, if possible. Top level vals in traits will likely be abstract, and thus not initialized. Vals and vars inside methods should absolutely not be padded, as reordering is entirely too likely.
I just searched through a 200 class Scala project, and only found one class where this issue even arises (a "cake pattern" module, where the vals declare the components of my application). It's a non-issue.
Whatever suits you, you're the coder. The second one just looks funny to me really.
Whatever suits you, you're the coder. I find the second one is more of a pain to edit.
I can't speak for Python, but in general you will find both examples across all different languages. In my experience, the first example is more common, but it's a matter of personal taste and I don't believe that another developer would think poorly of you for using either style.
I greatly prefer the first example and agree with others who have commented on the maintainability of the second example. With syntax highlighting available in all IDEs and most quality text editors these days, I don't think the latter style is necessary to keep things readable.
From a usability standpoint while reading, the second is akin to a table layout and it helps you scan it vertically to quickly see that there're two Ints and one Double, but it's also slightly harder to connect the horizontal extremes to see that bar is 1.
The first one makes the individual rows take focus and is easier to scan horizontally to see that bar is 1 but it's harder to quickly see that there're two Ints and one Double.
Expand the example with a lot more lines and it might be easier to "feel" this - but which one to use would be up to which is more important and of course what style is used in the project, team, workplace or best practice for the language in question.
Also, why limit table layouts to only left-aligned columns? ^^
val foo : Int = -1
val bar : Int = 1
val yohoho : Double = NaN
Second style giving headache when you need to search for specific text. When code file grows large sometime you need to seek for specific text, If you coding with custom spaces it is hard to find.
We had bad experience with large XML files holding TSQL scripts, Coders before me using style 2 as in your example, end whenever We added new rule or upgrade old one it is painful to search trough files which is codded with custom spaces.
This kind of indentation is useful when someone reads the code, but it is quite up to you to decide.
My answer is don't use it, you will save some time, and you really want to use it, make some text editor that does it, or maybe do yourself some compiler that interpret printed html code, because it's worthless to do it on a text file, which I'll remind you, is a plain long line of bytes reorganized with tabs, space and return carriages.