Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

As Unity is very .Net based could it adopt the F# and Visual Basic Languages?

Discussion in 'General Discussion' started by Arowx, Sep 16, 2018.

Thread Status:
Not open for further replies.
  1. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    This example isn't correct though. The non linq code is needlessly verbose.

    You can do non linq version as follows:
    Code (csharp):
    1.  
    2. var sorted = currentlyHoveringOver.sort( ... // priority then distance as tie breaker );
    3. return sorted[0];
    4.  
    This is actually clearer than your linq example.

    If you really need the performance, you can write a "get max" function.

    Code (csharp):
    1.  
    2.     public static T GetMax<T>( this IList<T> list, Func<T, float> converter){
    3.       float m;
    4.       return GetMax( list, converter, out m );
    5.     }
    6.     public static T GetMax<T>( this IList<T> list, Func<T, float> converter, out float max_value ){
    7.       max_value = float.MinValue;
    8.       T c_min_item = default (T);
    9.       for( int i = 0 ; i < list.Count ; i++ ){
    10.         float v = converter( list[i] );
    11.         if( v <= max_value ) continue;
    12.         max_value = v; c_min_item = list[i];
    13.       }
    14.  
    15.       return c_min_item;
    16.     }
    17.  
    Here you can use GetMax( ... priority then distance ) and achieve the same performance as your verbose example while retaining clarity.

    You don't need a library of built in methods to write clear code. You can do it yourself if you think about the problem.
     
  2. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    I didnt do sort as it adds a complexity, though you cant hover more than lets say 10 items if you really shovel in alot of items on a close space so I guess its a bit of a sub optimization. Mine is only o(n) hard to beat that
     
  3. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    your linq example has orderby and then a thenby. This will be slower than in place sort.

    Edit: sorry misread. The sort example is a simplification of your linq. The GetMax example is a simplification of your verbose example. Both should be approx the same (or better) performance than the examples you gave.
     
    Last edited: Sep 21, 2018
  4. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    No my first example is o(n) if you first sort it you get an additional o(log n) or worse

    In terms of complexity Linq does not perform worse than a normal list Sort, OrdeyBy and thenby will be executed together so it's still o(log n)
     
  5. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    Sorting (linq or in place) isn't o(log n) it's o(n log n). That's a very big difference.

    GetMax is o(n) from my example as well as your "verbose" example. They're the same. But instead of 40 lines of code, you can do it in 1 using the getmax function i pasted.
     
  6. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    Getmax can't be used as far as I can see it and get o(n) you need to get the one with highest prio then closest and it's pickup command need to be active
     
  7. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    You can do this by writing a good summation that includes weighting and tiebreaker. A "GetMin" example would be:

    score = (priority * -10000) + (sqrMagnitude) + (Pickup ? +1000000 : 0 );

    Or something along those lines, depending on the scale of values being used. Admittedly, I'd pre filter the pickupables.

    It's worth noting that I wouldn't worry about micro performance in this example, since this is executing one time per frame (correct me if I'm wrong). So I'd just pre-filter.
     
  8. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    You think that is more readable than my first or second example? :)

    If yes we have different ideas about clean code :) not that my first example I would much rather use my Linq example if performance wasn't an issue
     
  9. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    Honestly, I do. It may depend on your familiarity and comfort level with stuff like scoring functions. I find them very easy to read and very clear since I tend to use them often. You can format it nicely to help.

    Code (csharp):
    1. var closest = currentlyHoveringOver
    2.     .OrderByDescending(h => h.Key.PickupPriority)
    3.     .ThenBy(h => (this.Model.PickupPoint.position - h.Key.ColliderParent.transform.position).sqrMagnitude)
    4.     .FirstOrDefault(h => GetPickupCommandState(h.Key.ItemType) == ButtonAction.PressDown)?.Key;
    This simply has too many letters, symbols and function calls for my eyes.

    Code (csharp):
    1. var closest = currentlyHoveringOver.GetMin(
    2.    h =>
    3.      (h.Key.PickupPriority * -10000)
    4.      + (this.Model.PickupPoint.position - h.key.ColliderParent.transform.Position).sqrMagnitude
    5.      + h.GetPickupCommand.. ? +1000000 : 0 ) )
    I think the second is way, way easier to read personally.
     
  10. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    It's what's so nice with fluent syntax, you often don't even need to read the lambda, it's often enough to quickly have a look at the flow, ok first we order on something then on something else and finally we take the one which has its pickup command activated.
     
  11. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    "you often don't even need to read the lambda"

    I think that may be where I disagree with you fundamentally.

    "we order on something then on something else..."

    Understanding the "flow" is far less of a concern for me in most of my work than understanding the data and logic itself. I am more concerned with the exact criteria you're sorting by than the sorting itself.

    I've discussed code with programmer friends of mine and have found this to be one of the differences I've found after working exclusively with game code for a long time. My enterprise friends tend to really focus on the flow and logic above the data itself.

    I think this might be due to the process of working in an enterprise environment, where often the exact formulas and stuff are codified in business logic that's embedded in requirements. In game code, often the calculations themselves are much more of a focus than the logic containing them.

    At least in my experience.
     
  12. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    669
    I like Linq for client-side REST responses (especially if they're infrequent enough) but I'll always prefer an optimized utility or hand-rolled loop for perf critical stuff.

    The underside of things like Linq are not only are that it allocates in-place (and lacks the ability to reason about a lot of the method chains involved, although I'm sure you could write an IL weaver that could optimize some cases), but it has copious hidden function calls and delegate invocations. The hidden function calls can create additional cache misses, as we have less ability to control where code is stored than even our data and the code must still be fetched from RAM or one of the CPU caches.

    The delegate invocations are some of the slowest function calls possible next to interface calls, although your mileage may vary on that. And those delegates are often the operator that gets run on entire sequences of temp-allocated working buffers.

    What I'm saying is, if you look at the real costs of what your doing in terms of hardware, sometimes just doing it manually costs less actual code, as abstraction frameworks in general tend to cloud the real cost of things.

    Even with the
    Sort()
    call @frosted mentioned, there may be any number of sort functions and helper functions implemented there. Decompile a lot of the Linq and .NET framework collection utility functions, and they often call into helpers which call into helpers which call into helpers. Most of these also have redundant checks on the collection reference types since they can't assume where they're getting called from nor the validity of the data being given to them. This is sensible given they're core framework functions and cannot break as they're depended on by a lot of general code.

    But in game development, sometimes it really does make sense to just write a data-specific version of an algorithm, as it's often not that more complicated on the surface level code than a chain of algorithims and it'll perform a heck of a lot faster since you can optimize for assumptions about how your data is used.
     
  13. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,492
    All I want is to get rid of {} and ; anyway :D I have no clue how and when to use linq
    /2cts from non programming side
     
  14. I changed my mind!

    I think Unity should consider to introduce a new scripting language. And they should add the white-space.
    It would be the perfect scripting language for game development, because it helps to keep the flow, since does not overwhelm the developers with useless and verbose syntax. Also it does not use {} neither ;. :D
     
  15. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,492
    Top programmer humor always I see :p
    Still hate programming and its ugly ass interface
    I shall destroy your beloved practice with best designer redesign
    so that the code will be forever accessible
    and you shall feel the pain of newb using comic sans equivalent in programming
    (though you already suffer it, it will be even more hell)
    /Revealing EVIL Machiavellian Keikaku

    Pro tip {} and ; are stuff for compiler, you don't need them ... ever ... just build better ide interface, we are not DOS anymore
     
  16. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,081
    I find that they're really handy for delineating what code is operating on what level, especially when loops or other conditionals are a factor.
     
    angrypenguin likes this.
  17. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,492
    I use too think that, but then whitespace™ does the same and it actually make the work looks more compact so you don't have to aimlessly scroll to read and understand the logic in one go.

    Now instead of doing:

    Code (CSharp):
    1. LoopKeyword(parameter){
    2.     logic;
    3. }
    or
    Code (CSharp):
    1. LoopKeyword(parameter)
    2. {
    3.     logic;
    4. }
    I do
    Code (CSharp):
    1. LoopKeyword(parameter){
    2.     logic ;}
    Which make thing much easier to read, and was counter intuitive to me because I use the second style to help me find scope too.

    But that's not the point, it's not about the style, the point is that we have better visual way to represent scope by not using text and having a visual representation of the scope, like an actual visual box (and we wouldn't need to manage indent then). I mean ide already push some dotted line to tells you the scope, we haven't needed that in english text either, we use bullet point, and bullet point have the visual weight to be neatly be sorted and not just clutter by being the same visual weight as any other character.

    I mean if we took all those ide hacks, like collapsing brackets, and turning them into actual visual interfaces, that would be great. In fact we could still use brackets and semi colon as input shortcut, the system would just use them to open and close a new scope, without having to mess with them during typing; semi colon would signal to start a expression line, keep enter as the signal to a new line inside the same expression. That would already make things way cleaner.

    The point is that we can push this to the ide (I mean it can render it into usual code text if it want, that's just a tag to parse, that's its literal role), and that's one minor pet peeves among many (we need to rethink that auto complete thing, can we get highlight of syntax that actually help with the logic? I can tell string is a type, no need to bold it, I would prefer to use styling to tell me the basic type of a variable when its far from declaration without having to hover it), the idea is to reduce syntax error and let the designer deal with the logic. Simpler language syntax is not the key, cleaner and less busy works is the goal.
     
    Deeeds likes this.
  18. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,081
    Honestly, I feel like this might come down to a personal preference thing, which is why I think maybe IDEs could maybe have built in "code style theming" that would allow people to define syntax rules that the IDE could completely handle. Maybe even have that progress towards a sort of natural language overlay that could really ease beginners into research.

    Hell, while I'm dreaming, maybe one of the easier to read styles could be SO easy to read that it ultimately replaces the concept of psuedocode.
     
    angrypenguin likes this.
  19. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,614
    You want to draw a big box around things. I want to draw a { before it and a } after it. How is that not a style thing? It's the same information either way.

    And both of those are visual representations. The difference is that visually I want to mark the start and the end, you want to draw a box around the whole thing.

    I'm with @Murgilod, this is very much a personal preferences thing.

    We still need to manage scope, though. If we take away {} and we avoid managing indentation, we now need some other way to determine scope, or where your box is drawn. Ignoring how we represent it on screen, we need to either indicate where scopes begin and end or we need to indicate what things belong to what scope.

    In your mind, what user input results in your scope box being drawn on screen? What user input is used to modify that scope box?

    Also note that viewing code as text isn't just done when we're working on the code. Non-text representations of things are going to have implications throughout our tool chains - diff/merge tools, task tracking systems, and so on. Basically, under the hood they need to get represented as characters in a text file anyway, and people will need to be able to understand and work with those characters.

    That said, I do agree that if programming were re-imagined from the ground up, rather than step-by-step over decades starting from nothing, we may well end up with something quite different and more efficient. No argument there... but I think it would have to be from the ground up, rather than cherrypicking, because if it could be cherrypicked I'm pretty sure it would already be done.

    Styling of what?
     
    Lurking-Ninja and Ryiah like this.
  20. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    669
    Lurking-Ninja likes this.
  21. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,943
    None of these solve the problem for artists though. We still need a visual language. How about Befunge? :p
     
    Lurking-Ninja likes this.
  22. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    I dont mess with gfx, artist shouldnt mess with code :D
     
  23. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,943
    It's intended for level designers so programmers don't have to waste their time with trivial stuff like doors, levers, etc. :p
     
    hippocoder likes this.
  24. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    Slapping some components coded by programmers on gameobjects I think we can allow. :)
     
    Last edited: Sep 22, 2018
    xVergilx likes this.
  25. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,492
    I'm sorry you all don't know how to read and focus too much on style, it's like the forest vs the tree. :rolleyes:

    I think there is already tools for this, it automatically turn tour code into proper indentation and can replace tab vs space at any moment, so you can render your code to whatever code style to share with people you are working and not care about their coding standard too much. That wasn't really the point! quoting myself again:


    Yeah thanks you that's what I said.

    The point is that you can't erase them by typo, that's one stupid mistake away, but that was just an illustration for a broader philosophy. Think of dos vs windows, dos is teh worse UI/UX version of windows, but windows as the same functionality, and it's more information dense because you can constantly switch to appropriate "view" on data. It minimize basic syntax error by using itemization, so you can use one click on the presented item, instead of separating view and command (typing cd vs path), and using a non linear presentation (item aligned on a grid surface vs scrolling text). OH and if you want the power of command line you can still type them in the adresse bar.

    Windows is not just a styling on top of DOS.

    Yeah thank you that's what I said, so you are agreeing? :rolleyes:
    BTW even spaghetti node language bake their noodliness into actual text code.
    But then code bake into IL text in unity which is then bake ultimately into binary, and you can parse any of them.

    You know that ide has some styling already to supposedly help you?


    It use colors, italics, squiggly, boldness and underline to communicate with you, that's style, you can even customize their colors to increase readability. I'm arguing they often focus on the wrong thing.

    They could be highlighting hidden data. I know var is a reserved keyword, thank you but that doesn't tell me anything about the logic (ironically it's there to remind beginner), but what if once a variable was define by a type, well it was colored by the code color of that type (just an example, I'm not saying it's optimal design choice).

    For example let say we have the bad (on purpose) naming convention (for illustration remember) below:

    String name
    Class Name
    name = "george the crocodile"
    Name = new Name()

    Usually you would have ide do

    String name
    Class Name
    name = "george the crocodile"
    Name = new Name()

    When

    string name
    class Name
    name = "george the crocodile"
    Name = new Name()

    Is much better given the task at hand, you don't highlight useless information, it's written string, I know it's a string, it's before an identifier I know it's a type by grammar rules, why bold it again and put a lipstick color on it? I don't have any information. But once declared the identifier type is hidden, so it's a much better information to keep around.

    Similarly, we could have function declaration be floating dockable windows, which can then invoke at the place of use to compare code. By itemizing the block of code you could also add extra info and make comment specific and relevant, and also help with refactoring. And comment would be great if we could apply to them the whole text manipulation thing like bold, italic, etc instead of the hack presentation we are still using ... and we can still use them because it's not an abolition!

    But the point isn't pretty color and simplification, it's a whole philosophy of moving pointless thing away, and presentation is one part of it. Ie present the right information at the right time by minimizing pointless manipulation.

    Jokes land better when they don't miss the point, unfortunately. ;) OINK!
     
  26. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    We are using C# !

    void Whatever(){
    }

    Is personal style only that evolved from outdated learning materials that wanted to save screen and print space (not an issue nowadays). Data shows that it's worse for more programmers and introduces more bugs and thus Unity and MS default to:

    void Whatever()
    {
    }

    And this is now reflected in the default scripts created in 2018.3 onward as well as Visual Studio defaults.
    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/inside-a-program/coding-conventions
    • be verbose
    • be clear
    Squashing crap together, using single-letter variables (or non-verbose) is purely a personal preference and hasn't got any logic to it other than making it more fun for the person who wrote it. I also see these bad practises that neither microsoft nor Unity recommend, sprinkled liberally in this thread's code.

    Squishing code and being less verbose does not make the program easier to understand nor does it make it quicker to code, because most of the time spent coding is spent on maintenance and this is a proven fact. So making it harder to maintain by squishing it all together, using obscure solutions that aren't faster but require more specialised knowledge and using non verbose variables are all things that really are just in the long term, making everything waste money: https://www.zdnet.com/article/developers-despair-half-your-time-is-wasted-on-bad-code/

    Tut tut! Such sloppy naughty filthy hobbitses with habitses.
     
  27. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    90 procent of Unity Devs are probably hobbyists. So offocurse you will see unmaintainable code on this forums.
     
  28. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,492
    @hippocoder
    I hope this isn't a response to me, because that's not what I was saying o_O I mean this is concerning by now ... lol
    I guess as long as I don't commit to a proof of concept misunderstanding will abound. But I feel nobody is adressing the main point.

    But speaking for myself, I have sub HD screen, teh style I mentionned help me because I wish I had a large screen like before. But then the squishing problem is created by the presence of unnecessary bracket to begin with, so it does make the point that styling bracket IS a distraction. In fact I'm not squishing them as much as making them as out of my way as possible. In fact dangling bracket allow me to know which code I'm working very quickly and the "squish" one signify code I have done testing and is working, which help me scan the code as it remain a huge problem 20years after I first tryed to code. Seems like not everybody evolve to leet hacker after many years.
     
    hippocoder likes this.
  29. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    No silly. I would never harm my precious torvald ways reading any text from artists! ;)
     
  30. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    Pretty likely I'm the guilty one here since I posted some single letter variable name code.

    In my defense, I think there are times when single letter variables make sense. We've all used them by convention, and do it frequently.

    Code (csharp):
    1. for( int i=0 ; i < ... ; i++ ){ /** does renaming i "index" make this code clearer? **/ }
    Although yes, abusing single letter variables is bad form (it's one of my main complaints with formal mathematics), I think that there are plenty of cases where it's defensible.

    Code (csharp):
    1. var v = GenericFuncParameter();
    Here for example, I use "v" as an abbreviation for "value". Mostly because "value" doesn't actually give any additional information on what the code is doing. You could also use "thing" and it would present nearly equal information.

    Code (csharp):
    1. // would naming this "value" really communicate more here than a veneer of professionalism?
    2. var thing = GenericFuncParameter();
    In some cases, where you are using a bunch of generics to just make a reusable loop or something, variable names are generally going to be so obtuse as to be meaningless.

    There's a handful of single letter variables I use in convention: v (value). when dealing with sequences I will use p, n, c (previous, next, current), when dealing with mega abstract functions that use Object I will use o.

    In terms of my personal code style, my single biggest regret in practice is using _ word separators for local variables. like_this_is_awful. The underscores add so much visual noise to the code making it harder to differentiate between operations, function calls, and variable names.

    That lower_case_underscore style is something that I picked up a long, long time ago from a coding standards doc at a job long ago. Really regret sticking with it.
     
    Last edited: Sep 22, 2018
    Deeeds likes this.
  31. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Yeah the holy ikj and friends are fine for indexers as they're established really, among most programmers. What I refer to is the compression of LINQ code using these - microsoft warns against that practise.
     
  32. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    You really think one letter is bad in lambda?

    Code (csharp):
    1.  var list = Where( x => x.IsValid() );
    I'm def guilty of that. One of my many crimes against coding standards :p
     
    hippocoder likes this.
  33. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I don't think it's bad, microsoft does :p

    I don't use LINQ or other query shortcuts not because I've judged them, but because I prefer to remain neutral as possible in code, so the code can port easily, be understood by everyone without training and so on. I use as few language-specific features as possible as a rule (in C#'s case I include .net in this).

    This has for me, translated to better performance, easy maintenance and less time spent trying to shoehorn something oddball into a pattern the current language supports but nothing else does. ECS is simple and brute force enough to still fit within this methodology.

    In LINQ's case, people want to use it, but find they have to build a lot of structure around it to use it efficiently. Then they find there's still cases where it can't be used due to performance. Why bother? :D
     
  34. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,614
    I was making observations and asking questions for the sake of further discussion. No need for a condescending eye roll.

    Yeah, that was actually specifically what I was thinking about, and precisely why I asked what you were proposing be styled.

    There's a really important distinction between what you're showing there from an existing solution and what you're proposing. With the existing solution I do not need to know or remember anything that I did not already know. With your solution, I need to learn and remember a bunch of arbitrary style-to-type mappings.

    The first time I used an IDE with syntax highlighting I didn't need to learn anything. I opened my same old code files they were just easier to read. I didn't need to know that function calls are blue italics. By looking at any funciton call, all other function calls just jumped out at me because they were all style thed same way. It is immediately self explanatory. It is free productivity.

    With your proposed system I need to learn and remember arbitrary stuff like "green non-italic text is a string variable", and somewhere around a dozen other such mappings for basic variables alone. It doesn't account for custom types. See the screenie you posted, would this help at all there? I also see it being confusing for those who move between tools / styles / IDEs / languages. (I mean, sure, if we all somehow find and implement a universally acceptable style... but we still argue about where our curly braces go, so that's never going to happen.)

    My point isn't that things shouldn't change. Reducing the time doing even simple brain work means increasing the time we get to spend on the harder stuff that matters more. That's a good thing, no arguments there. My point is that for this to work I strongly suspect that whatever is done needs to be self-descriptive, as opposed to relying on coders learning even more stuff.

    I haven't put enough time into thinking about this to propose a solution that does that.

    In part it still has "the same functionality" because it still has a command prompt. Command prompts allow you to do stuff that you can't do in a GUI'd environment, because you can do anything you can write a command for, rather than being limited to what a designer prepared for in advance.

    This I agree with, but - as a programmer - I personally see immense value in presenting things in a way that mirrors how they are used by the computer. While this varies from language to language, a part of the reason that I like C-style code is that it's a reasonable facsimile of what the CPU is doing under the hood. I like seeing my code as a sequence of instructions because that helps me think through them similarly to how my CPU will do so.

    Which, again, isn't to say that this can't be augmented or improved. Just that different people will have different ideas of what "the right information at the right time" means.
     
    Ryiah and Lurking-Ninja like this.
  35. ceebeee

    ceebeee

    Joined:
    Mar 7, 2017
    Posts:
    395
    And F# is any different? Any language can be 'used wrong'.
     
    Ryiah likes this.
  36. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,492
    @angrypenguin
    first I need to put that:
    The example given are not meant to be solution, they are meant to be illustration, else I would have solve the issue. Anyway:

    But the question asked was already answered? why ask the question is the answer was already given? I don't understand what you were trying to achieve, I wasn't trying to be condescending, just display confusion. lol

    Well it's an illustration, just I hasn't stress in that post of mine enough, but I have been hammering it since the beginning, it's a way to show potential thing we could thing more but then:
    - You already have to learn an even more arbitrary mapping between random name and type, you must remember all the type of all the variable and there is zero distinction. There has been attempt to fix that aspect with naming convention like US8 (unsigned short) prefix or suffix, using noun or verbs, etc ...
    - You don't have to know the mapping anymore because of above, but you have the relative advantage of knowing that you are trying to pipe incompatible variables together, which happen enough that there is many thread of people having problem on the forum because they don't know why piping their string into int don't work.
    - where curly brace go is a problem of separating the presentation and the content, curly brace is not content, in fact a proper parsing like I propose would just leave the code intact and each people would have a personalized view they can shift around depending on what they want to focus on (like automatically appending the type on each variable identifier instance as a view). No fight over style as you can simply change it to match the problem at hand, as a single view don't solve all problem. Pushing presentation responsability to the programmer is distraction at best. Using advance itemization, we would solve that. IN fact some debugging happen just like that, your code is shown relative to the compiled version, your code is the presentation, the asm is the content, you open a view to see how stuff goes under the hood, it's not permanent.
    Yeah that's the point I was making, it doesn't substract. Though you are still limited by whatever commend a designer gave to you even in DOS, dos don't let you fully program for example. Designer isn't bout making pretty thing, they are about functionality, and functionality isn't just text command. When I propose color, I'm proposing a functionality, ie to discriminate type visually, ie to increase the information bandwidth by using untapped communication channel, or using them appropriately.
     
  37. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,614
    I think this largely comes down to us wanting to think at different levels of abstraction.

    I often want to think at a level of "I am giving instructions to a CPU about how to manipulate the contents of its memory". As such, knowing what data types are available and how they work isn't "arbitrary" to me. They're fundamdental tools of the trade. I could not be a competent coder without knowing that, and if I didn't know that then my IDE couldn't help me short of doing the coding itself.

    I do see your point about making it clear when you're making incompatible assignments before you make them, and that this doesn't require that people know the style mappings. I can't say I've had an issue with that in a long time, so it simply never occured to me to be something that needs solving.

    I understand and agree with the philosophy. Otherwise I'd still code in a plain ol' text editor with a command line window open.

    I'm trying to step past the concept of this particular example and figure out how it would actually work, in practice. In my mind I can't figure out how to make it work. It sounds to me like we would have code files that look like patchwork quilts, and that the extra information channel is going to be unwieldy to use to the point that I'd end up mousing over elements to see their pop-up info anyway, because bandwidth isn't free. And then it falls apart as soon as I use a class anyway. At the same time, I'd lose the existing syntax highlighting that I do find to be useful, either because it's absorbed into the noise or it's actually gone.

    The reason I asked about what would be styled is that I wasn't sure you meant the text itself. One of my first thoughts in this area was to somehow "decorate" elements of the code to give you additional information. For example, maybe sets of icons to indicate data types, scope, and other commonly important things. You could then have a hotkey to make them visible so they're not cluttering up the screen (ie: they take up bandwidth) except when they're wanted, without requiring hands to move away from the keyboard. It still has problems, such as still not handling custom data types well, but this isn't taking up bandwidth when it's not used, would still be faster than the existing mouse-over-each-element thing, and if the decorations are designed well it'll be self explanatory.

    In the context of my usual level of abstraction they're certainly content.

    The vast majority of the time curly braces are used along with some other element - class declaration, branch statement, etc. - that could be taken to imply the existence of a block. But blocks can also be created independently of these things, and some programmers choose to do so to limit the scope of variables (similar to controlling stack frames) or organise things into chunks.
     
  38. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,943
    They're content in the same sense that commas and periods are content in a sentence. I have to admit I've always found it interesting that people can struggle with symbols in programming languages while having no trouble using them in written languages.
     
    bobisgod234 likes this.
  39. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    Writing code is like the least-difficult part of software development in general. I know being a programmer I probably can't "see" it the same way that non-programmers do, but yeah, I don't get the issue with curly brackets.
     
    angrypenguin likes this.
  40. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    I agree but also you should not downplay the importance of it either, its why C# still get new nifty features like expression-bodied members etc.
     
  41. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,492
    I'm going to question that, as you not only you have the cute curly dangling bits, but you have indent that give you the exact same information, as seen by language who don't use it like python, and language that don't need it but programmer use it anyway, like basic. They are redundant, they are only content for the parser so it can know how the logic are structured. Which mean it's an opportunity to hide them in a view, or replace them with more efficient presentation.

    That's just a pet peeves anyway. So let's move to the true meat:
    It's no surprise that using a tools for so long, you get in sync with tools, which mean any deviation can be seen as uncomfortable.

    That's why artist who started and got expert on a soft, have it difficult to change to another one, even though they are equivalent. Or why it's so hard to get rid of of qwerty/azerty and any traditional layout even after provingly superior layout (or shifting from wasd to esdf :p ). Having a mother who is infographist, I had also witness the battle with traditionalist doing everything by hand and those who made everything on computer, of course the traditionalist had more control, they were more experienced with their tools, and the one using the new tools were both less experience in the new tools and in compositing, so it looks like the traditionalist is right, up until the new tools and people catch up in experience and has as much power if not more.

    What I want to say is that I understand where you come from.

    As a designer, I see programmer having a set goal to solve, that is to represent a problem into specs and solving it with code, it's very directed and focused. You generally have a set of very definitive metrics (like cpu cycle, memory cost, etc ...). You take high level concept and translate them in te appropriate low level machine concept. hence why cultural thing like bracket style get taken seriously, it's viewed with the same mindset than typical implementation, but they haven't clear cut metrics.

    I see designer as making up the problem in the first place, especially design of cultural thing. It's about figuring out the specs to begin with, and not only the specs but to which metrics it must be evaluated. The goals start vague and can actually shift with realization, it's like looking at a blur image becoming sharper and the number of interpretation of what it could be decrease over time.

    Of course I'm looking to design code for more designer mindset.

    Don't be too hung up on that example, it's DESIGN to be an illustration, not a solution, it does falls appart on custom type as it's a throwaway idea, not a thesis on solving that particular problem. If I had solved te problem I woudl talk about how we need to solve it in the first place.

    Which mean the actual solution could be very different.

    I was showing on another thread on visual programming that people like the noddly monster because they can see data flow more easily, while text emphasized command flow, and both had their shortcoming and benefit in solving class of problem. In some way I imported and translated to text command programming, concept use in visual node system, they are the one having color coded type for box, slots and link.

    At the same time, I have been pointing that IDE already are christmas tree of extra information, and they have a lot of redundancy! I'm reposting that image:

    Look at item.Tags.forEach(....)
    below item there is a vertical line to indicate scope, on top of curly brace, on top of indentation! That's like how many layer of redundant information? I thought curly was to help seeing the scope!

    I'm saying we can reorganize that into a cleaner presentation
    and getting rid of common syntax error that stole precious second. I watch people programming on youtube (hello craig perko) and they all have moment where they compile code, it takes a few second, it throws error and they have to correct a typo and recompile. It's done without a second thought, I doubt any programmer remember these events unless the compiling time exceed one minutes, in which they blame the compiling soft and not the small typo.

    One of the direction I'm proposing, is what I can itemization. It's partially done by IDE, and done too strongly by noob trap, like rpg maker or stencyl, so we loose flexibility. Basically code are a collection of strictly define objects. When you declare a variable, it has a set number of property, you just align them syntactically. What if once declare it is turned into an item, to which you could attach many meta data that will be usable for many view and presentation (like commentary so they are not floating or plain text name on top of an identifier). You could still type in the old school way, but every validation turn the declaration or expression into a proper item you can manipulate if you need it. To edit them you would do it like you already, just left click on them.

    IDE kinda do it half way, you do have lit of all member and method on the side that allows you to jump to any declaration, it's ugly and clunky. A lot of that uglyness is that everything is build on top of a notepad presentation overblown with floating metadata like intellisense, vertical scope line, etc ... maybe it(s time we officialize all these and made them not mess up things?

    I mean #region can be better that the unwieldy stuff we have, and seeing a function definition in a pop up showing partial code and overlapping useful code, only to disappear when the mice go away, okay i can to the declaration but have hard time jumping back to where I was ... I would just have the itemized windows of a function declaration pop up, which I can scroll, tab or dock for comparison (function definition can be put anywhere after another, so if order isn't important, we can as much detach them from the linear presentation).
     
  42. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    You admit you have limited experience with programming, then speak at length about how { } is supposedly redundant. How can you speak with such authority about something you don't really use much?

    Here are some thoughts:

    You code better with well defined blocks. When you have a large program you do not want any kind of guesswork going on. With the majority of braces languages you can do this...

    With braces:
    Code (CSharp):
    1.  
    2. if (thing)
    3. {
    4.     DoSomething();
    5.     DoSomethingElse();
    6. }
    7.  
    Without...
    Code (CSharp):
    1.  
    2. if (thing)
    3.     DoSomething();
    4.     DoSomethingElse();
    5.  
    Both examples compile into valid C# code. But they both don't have the same outcome.

    There are a number of other language features where { } is pretty much mandatory and you won't be able to describe the code without them, but these are for syntax sugar. Typically without the sugar, you can still express them so { } are technically redundant. I said technically.

    Because { } describes block, and when you are looking through thousands of lines of code, { } is going to reduce ambiguous meanings for the reader. Python by contrast will cause a lot of problems, as the block is defined by the indentation.

    With C# you're able to split particularly long and verbose things up on several lines yet not get confused. Try that with python at your peril. Or should I say Perl? In any case, Python got where it was by filling a need, and we have somewhat different needs in game development. Some parts (modding, DCC etc) are well served by python syntax. Other parts (critical scope, complexity) are better served by strict scope.

    At the end of the day, the time spent programming is not going to be about the syntax, but about how long it takes to think about a problem, refactoring existing code and generally managing the code.

    It's never about how long it takes to type. Never.
     
    Rotary-Heart and angrypenguin like this.
  43. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    I am in the anti brace camp. I really want anything that reduces the amount of visual noise on screen.

    { as a character has literally too much going on. The point at the center of the mid point of the curve is visually taxing.

    [ ] would be better characters.
    () are much better characters.
    o is the best letter.
    " " are uneven, unbalanced and noisy (too top heavy).

    In general, roman characters are extremely well designed. They tend to be balanced horizontally and vertically, have simple smooth form, etc.

    Punctuation is more of a mixed bag. Core operators: + = / * <> tend to be visually solid. $@^{}&# are pretty bad. $ is probably the worst, languages that use $@ as special characters are generally disapproved of stylistically.

    In general, I want a low amount of punctuation outside of ()'s []'s and base operators: = + / * > <

    I also want my eyes to be able to see those operators clearly. Almost everything else is noise.
     
  44. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    For early exits I omit the braces like

    Code (CSharp):
    1. if(PleaseExitEarly) return;
    foreach loops that only have one line i omit

    Code (CSharp):
    1.  
    2. foreach(var item in items)
    3.    item.DoSomething();
    4.  
    One line if blocks too, though I'm a bit inconsistent on this one for some reason, sometimes I use braces. Maybe my six sense is telling me I will be adding more code to the block :p

    Then offcourse you should use var and all the other modern language tools that can reduce noise
     
  45. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,492
    No I never said that :confused:
    I have 20 years of hobbyist programming, the last 8 years on unity C# alone. I also frequently read code and about code.

    The truth is that I'm a designer and kinda hate programming (I do care a lot), I commit to it because result is more important.

    I'm not sating to JUST get rid,in fact you can even keep them as tags in the raw file, I'm just saying to replace them with something more efficient in the presentation.

    I agree, that's why I want syntax OUT OF THE WAY :p it's literal busyworks. It's not about how long you type, but how long you manage the code, make it readable, etc ...logic is mediated by the presentation, it's especially critical when you are looking at another code you didn't produce.

    Yeah I know c# rely on curly braces, if keyword execute the expression right after the check when it's true (unless you use the neverwinter night scripting language).

    Which mean indent is just visual feedback to the programmer for ease of readability, when they scan the code. Which is why we scream at forum noob to put the code tag up, when they share their code. Which mean that stated use of the bracket doesn't hold up, as you supply the bracket with non compilable visual element. if bracket where visually useful to scan the code, the indent wouldn't be necessary, and we wouldn't scream at forum noob.

    So when you argue python is bad because it doesn't allow you to control the style of the logic block, like breaking statement into multiple line (which is control by the ; in c# not the bracket) you are arguing about style, and you say this argument is important, therefore you have demonstrated that programmer care a lot about style, because that's the only merit between that specific comparison between python and c#.

    I mean, when you say,
    Python is technically strictly scope too (well they don't "strictly" enforce private member, but we are all adult right?), just that there is confusion between the visual feedback, the presentation flexibility and programmer's ease. That's literally style issues.

    My proposition stem from this basic observation:

    What if style and logic get separated and manipulated separately?

    We wouldn't have the shortcoming of both python and c#
     
  46. Owen-Reynolds

    Owen-Reynolds

    Joined:
    Feb 15, 2012
    Posts:
    1,992
    Back in the 1960's, we thought code blocks should use words. Sometimes BEGIN and END. Sometimes there was no begin because IF's and WHILE's automatically started blocks, but you were required to write ENDWHILE or ENDIF, depending. Take a look at even Pascal code from the late 70's. We tried lots of things.

    C, I think, was the first to say "hey, we already indent, why not use a single short begin/end symbol which looks like grouping, maybe {}? And use it consistently for every code block?" People liked it more. That's why Java kept it (but C# didn't really have a choice, since a design goal was to look like C++ and Java). People knew about Python's required indents with no need for an end symbol, and said "nah."
     
    hippocoder likes this.
  47. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,492
    It's a tales that read as saltiness to me:
     
  48. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,943
    This. There are people on both sides of the fence when it comes to using whitespace. One problem with whitespace is that there isn't just one single symbol for each aspect of it. You have both spaces and tabs which while you can choose the one you want you can't mix them. I don't know how newlines are handled but I imagine it's a similar problem.
     
    Last edited: Sep 25, 2018
    frosted likes this.
  49. ceebeee

    ceebeee

    Joined:
    Mar 7, 2017
    Posts:
    395
    yeah I mean I think the forced indent and lack of braces is dumb. but I learned Python and become proficient at it anyway because it's so ubiquitous. You can't let personal feelings get in the way of knowledge.
     
    angrypenguin likes this.
Thread Status:
Not open for further replies.