GDScript with braces
It's much better without it. Just give it a try.
Megalomaniak No, I just tried it, I didn't like it, You have to build, the code is a bit different, I want it to be the same but with braces. The Java public private mess, and less cleaner code, GD Script looks cleaner, I can't tell what makes it that but it feels unclean maybe the public private thing
It looks clean because there are no braces...
cybereality No, I don't like the more verbose-y parts like Public, Private etc, The indents look good when you have small amounts of code but not if you have a lot and have mental pressure from debugging.
Let's compare:
public partial class CharacterBody2D : Godot.CharacterBody2D
{
public const float Speed = 300.0f;
public const float JumpVelocity = -400.0f;
// Get the gravity from the project settings to be synced with RigidBody nodes.
public float gravity = ProjectSettings.GetSetting("physics/2d/default_gravity").AsSingle();
public override void _PhysicsProcess(double delta)
{
Vector2 velocity = Velocity;
// Add the gravity.
if (!IsOnFloor())
velocity.Y += gravity * (float)delta;
// Handle Jump.
if (Input.IsActionJustPressed("ui_accept") && IsOnFloor())
velocity.Y = JumpVelocity;
// Get the input direction and handle the movement/deceleration.
// As good practice, you should replace UI actions with custom gameplay actions.
Vector2 direction = Input.GetVector("ui_left", "ui_right", "ui_up", "ui_down");
if (direction != Vector2.Zero)
{
velocity.X = direction.X * Speed;
}
else
{
velocity.X = Mathf.MoveToward(Velocity.X, 0, Speed);
}
Velocity = velocity;
MoveAndSlide();
}
}
extends CharacterBody2D
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y += gravity * delta
# Handle Jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction = Input.get_axis("ui_left", "ui_right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
extends CharacterBody2D
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
func _physics_process(delta) {
# Add the gravity.
if not is_on_floor() {
velocity.y += gravity * delta
}
# Handle Jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor() {
velocity.y = JUMP_VELOCITY
}
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction = Input.get_axis("ui_left", "ui_right")
if direction {
velocity.x = direction * SPEED
}
else {
velocity.x = move_toward(velocity.x, 0, SPEED)
}
move_and_slide()
}
Focus in the middle of the code and at the top then. In GDScript you get lost. In C# and my version (last) you don't, If you look at the above with all the variables, you get lost in the public mess for C# but not in GD and mine. I want JavaScript style code. I have had no problems with that in readability.
GDScript looks 100% better and easier to read to me. I don't know, you might just have to get used to it.
- Edited
If you want to pursue this, there are two ways:
Submit a proposal:
https://github.com/godotengine/godot-proposalsImplement it yourself, and submit a PR (pull request):
https://github.com/godotengine/godot/pulls
Personally, I don't think the idea will get far. Most of my programming experience is with languages that use braces (e.g. Pascal, C, C++, C#, Perl, PHP) and I have no objection to that approach, but GDScript is different and most users like that.
I've got an alternative solution.
Learn some BASH scripting and regular expressions.
I can't say I have ever complained about syntax ever since I realized even this isn't verbose enough for a lot of cases when all you want is to parse an email address in a little bash script.
"^[A-Za-z0-9](([a-zA-Z0-9,=\.!\-#|\$%\^&\*\+/\?_`\{\}~]+)*)@(?:[0-9a-zA-Z-]+\.)+[a-zA-Z]{2,9}$"
For real though, brackets look cool. I'd be down to see it as an option.
- Edited
packrat I've got an alternative solution.
Learn some BASH scripting and regular expressions.
I can't say I have ever complained about syntax ever since I realized even this isn't verbose enough for a lot of cases when all you want is to parse an email address in a little bash script.
That actually reminds me, someone ages ago did make a tutorial for creating your own scripting language for godot 2.x.
Didn't find the one I was thinking of with a quick search but did come across one for godot 3.x:
Audio quality is a bit lacking tho.
- Edited
Megalomaniak You know I've been thinking of doing something like that for a while, but I haven't had time (or energy) to do that kind of thing. The classic education time hog has claimed me too, and it's a really a crying shame.
Since we're just about to enter the twilight zone here I'm trying to imagine how might it work the other way around - a c++ or java variant that uses strictly whitespace for code blocks. Now that would be... something! X-)
Here's the code that got us to the moon. I don't see any braces:
https://github.com/chrislgarry/Apollo-11
The thing is, if you want to be a successful programmer, you have to be flexible. Meaning, learning new APIs, new languages, new IDEs and software, etc.
I have probably programmed in 20 languages at least, and I can pick up a new language in like 2 days. It's important to learn the tools and not assume everything will be the same or what you are used to.
The language daScript supports both styles (although you can't mix them within a function).
White space based flow control has always turned me off of languages. I'm fine with brace based (like C++) or keyword based (like Lua) blocks.
Kojack White space based flow control has always turned me off of languages.
I think it forces people to avoid the "I wrote a whole operating system in 1 line of code!!!!!!!!!!!".
I submit that spending some quality time with vanilla Python can cure most of one's curly brace addiction
Btw I didn't know the Apollo code was done in all assembly. I was hoping at least for some Algol for easier code management. On the second thought, they probably wanted to squeeze maximum performance out of the platform.
- Edited
xyz they probably wanted to squeeze maximum performance out of the platform.
I worked on embedded systems in the 80's/90's. Even then, I had to use assembly language for code that had to run very fast, for example, processing radar data in real time.
The more time I spend in Python, the more glad I am that Ruby exists.
It's been a while since I've done any assembly. Maybe I should pick up a new one, perhaps ATmega328 assembly for Arduinos. That could be interesting.
I touched python once, but I stuck with bash.
It's 4 decade old nightmare of outdated, "historically friendly" syntax, but it reminds me of this really old 24 year old cat i met once.
Even though it's so old it can barely stand, and you're pretty sure if you touch it wrong, it'll snap like a glowstick, you love it anyway.