As soon as you know which parts of your code can work as distinct components, then you can start splitting it (your first refactoring step). It's true you can start a game prototype as a single messy script, but after some time it's good to start organizing stuff, if you know you are going to work more on it.
In Godot, splitting stuff is done through different ways:
Usually, scenes are made of more than one node, and some of them can have a script dedicated to do one task. I usually use the root node as the "master" script, and other specific tasks get delegated to child nodes (particles, sound, animations... even debugging).
You can put only one script per node, but you can still use a simple
Node and add it as a child to use it as modular component. Finally, communication is done through signals (equivalent of events that you can connect to listeners), functions, groups, or the tree itself (get_parent() or iteration on children for example).
Scripts don't have to be on a node, they can also be standalone, and used as classes.
For example, you can create a
thing.gd and use it as a class in another script, like that:
const Thing = preload("thing.gd")
var thing = Thing.new()
# Do stuff with it...
Scripts can also have static methods, so you can put helper functions in them:
var i = Thing.calculate_stuff(5)
In Godot, global variables don't exist. Instead, what you can do is put a script in the "auto-load" section of your project: http://docs.godotengine.org/en/stable/tutorials/step_by_step/singletons_autoload.html
When given names, these scripts will act like nodes that are accessible from anywhere, and stay alive even if the scene tree is reloaded or the scene changes. IMO this is only useful for storing information that is persistent across scenes for the whole game. Be careful with them because something accessible from anywhere can be messed up more easily on the long term.
Finally, it's also possible to declare classes within a script. It's not like inner classes of Java, though (they don't have access to the parent instance through
var name = ""
name = n
var thing = Thing.new("Hello")