xtapa

joined 1 year ago
[–] [email protected] 2 points 3 months ago* (last edited 3 months ago)

I personally try to avoid deeply nested if/else. Or else in general, because I think it makes code more readable. Especially when one of the branches is just an exit condition.

if exitCondition {
    return false
}
// long ass code execution

is way more readable than

if !exitCondition {
    // long ass code execution
} else {
   return false
}

In a loop, you can just return the value instead of passing it to a "retVal" variable.

With those in mind, you could refactor HasPermissions to

func (r *RBAC) HasPermission(assignedRoles []string, requiredPermission string, visited map[string]bool) bool {
	for _, assigned := range assignedRoles {
		if visited[assigned] {
			continue
		}
		role, ok := r.Roles[assigned]
		if !ok {
			//role does not exist, so skip it
			continue
		}
		for _, permission := range role.Permissions {
			if permission.String() == requiredPermission {
				//Permission has been found! Set permitted to true and bust out of the loop
				return true
			}
		}
		//check inherited roles
		if permitted := r.HasPermission(role.Inherits, requiredPermission, visited); permitted {
			return true
		}
	}
	return false
}

The same could be applied to LoadJSONFile and I think that really would approve the readability and maintainability of your code.

edit: This refactor is not tested

[–] [email protected] 5 points 4 months ago

Your "statistics" are fantasy numbers, not statistics. And statistics or probabilities, no matter how low or high, are not proof.

[–] [email protected] 5 points 4 months ago

Habe von AfD nichts weiter erwartet.

[–] [email protected] 7 points 5 months ago

Add Shape shifting and you're Ranma.

[–] [email protected] 4 points 5 months ago (1 children)

I like the question.

I had to think of two songs immediately:

Coldplay - Magic. I really feel the lyrics but the "of course I do" at the end always leaves me in tears.

Daft Punk - Touch. I always interpret the song as a robot struggling to become sentient, but it also reminds me of my process of leaving behind my angry and frustrated teen and early twenties self because I realized that it made me unhappy.

[–] [email protected] 1 points 5 months ago

The firmware update did it :)

[–] [email protected] 3 points 6 months ago (2 children)

That wouldn't exclude Cyberpunk for example.

[–] [email protected] 2 points 6 months ago (1 children)

Oh, updating firmware sounds reasonable. Thanks!

[–] [email protected] 2 points 6 months ago

They usually were not pointy and heavier than regular swords which made it easier to chop off body parts.

[–] [email protected] 2 points 6 months ago

Mein Bruder hat sich ein Bett aus Konstruktionsholz gebaut (bzw von einem Freund bauen lassen und mitgeholfen). Das Teil ist ziemlich stabil und nix knarzt. Die Anleitung war aus dem Internet. Kann man dann den eigenen Bedürfnissen anpassen ob mit Füßen oder lieber geschlossener Kasten, in der Höhe etc.

[–] [email protected] 2 points 6 months ago (1 children)

Just get a Bakfiets.

view more: ‹ prev next ›