861
top 18 comments
sorted by: hot top controversial new old
[-] Xeelee@kbin.social 71 points 1 year ago

Luckily, we have an endless supply of virgins to sacrifice. Nobody said they have to be female, right?

[-] NegativeLookBehind@kbin.social 25 points 1 year ago

But then, who will maintain the code?

[-] Xeelee@kbin.social 19 points 1 year ago

We'll outsource it to India.

[-] PelicanPersuader@beehaw.org 9 points 1 year ago

Better to use China, they've got plenty of excess virgins

[-] bear_with_a_hammer@lemm.ee 2 points 1 year ago

Nah, let's start from US -> Virgin Islands

[-] xuxebiko@kbin.social 20 points 1 year ago

Think maybe the project manager will fall for it?

Satan has created a library that runs as efficiently as possible and covers every possible use case, and all we need to do to get access is sacrifice 1000 virgins. Do it for the cause.

[-] BaldProphet@kbin.social 16 points 1 year ago

Sacrifice 1000 programmers, got it

[-] GitProphet@lemmy.sdf.org 9 points 1 year ago

5 interdependent modules? how sweet...

[-] russjr08@outpost.zeuslink.net 7 points 1 year ago

5? Those are rookie numbers, gotta pump up those dependency graphs!

[-] xuxebiko@kbin.social 6 points 1 year ago
[-] HeavyRust@lemm.ee 3 points 1 year ago* (last edited 1 year ago)

Pentagram for demon summoning ⛤

[-] jungekatz@lemmy.world 3 points 1 year ago

Well i fell for it already and now there is no going back 😨

[-] Korne127@lemmy.world -5 points 1 year ago

This is the one thing where my opinion might be highly unpopular, but I don't see circular dependencies as something bad. If you write really structured modularised code, and just use the APIs of the different modules, it is completely fine to have different modules all depend on each other. At least in object oriented programming, using this approach that's almost guaranteed to happen.
E.g. imagine a configuration module: Other modules need access to the configuration module to get the different entry values, but the configuration module needs access to other modules to change specific stuff if you change a configuration entry. Of course you could separate that module into one data part and one action part changing the data and doing stuff in other modules, but if you use many modules like that, this will just become even more complicated and lead to duplicated structures (e.g. a specific data tree plus the exact same tree for actions) which would be cleaner if it was directly in the same module.
Or a different example: An (e.g. discord) bot which is connected in one module, and both messages to the bot can lead to the module getting informations from other modules and actions in other modules can trigger the bot, leading to them depending on each other.

[-] eth0p@iusearchlinux.fyi 11 points 1 year ago

Circular dependencies can be removed in almost every case by splitting out a large module into smaller ones and adding an interface or two.

In your bot example, you have a circular dependency where (for example) the bot needs to read messages, then run a command from a module, which then needs to send messages back.

    v-----------\
  bot    command_foo
    \-----------^

This can be solved by making a command conform to an interface, and shifting the responsibility of registering commands to the code that creates the bot instance.

    main <---
    ^        \
    |          \
    bot ---> command_foo

The bot module would expose the Bot class and a Command instance. The command_foo module would import Bot and export a class implementing Command.

The main function would import Bot and CommandFoo, and create an instance of the bot with CommandFoo registered:

// bot module
export interface Command {
    onRegister(bot: Bot, command: string);
    onCommand(user: User, message: string);
}

// command_foo module
import {Bot, Command} from "bot";
export class CommandFoo implements Command {
    private bot: Bot;

    onRegister(bot: Bot, command: string) {
        this.bot = bot;
    }

    onCommand(user: User, message: string) {
        this.bot.replyTo(user, "Bar.");
    }
}

// main
import {Bot} from "bot";
import {CommandFoo} from "command_foo";

let bot = new Bot();
bot.registerCommand("/foo", new CommandFoo());
bot.start();

It's a few more lines of code, but it has no circular dependencies, reduced coupling, and more flexibility. It's easier to write unit tests for, and users are free to extend it with whatever commands they want, without needing to modify the bot module to add them.

[-] Elderos@sh.itjust.works 5 points 1 year ago

It does not get more complicated to split your example. What gets more complicated is giving all sort of unrelated responsabilities to a single class, simply because it is the path of least resistance.

In your example, all you need is an extra module listening for configuration changes and reacting to it. This way you leave your context-specific logic out of your data model, no need for cyclic dependency. There are so many downsides to cyclic dependency, to justify it because splitting your logic is "too complicated" really isn't a strong argument.

[-] Korne127@lemmy.world -1 points 1 year ago

I honestly don't see a single downside, as long as it's modularised, maintainable and with clean APIs. And e.g. with a configuration module: The place where I've experienced this was a place where bigger parts of the configuration module were classes to build specific custom tree configurations. And if one module would just save what should happen at the change of each entry (and not save that with that entry), it would need to duplicate the whole structure and map it to the entries, which is ugly. It just makes sense to put those strongly related configurational things into one configuration module which provides an easy API (one method for changing and one for retrieving a config element after constructing it and adding other modules).

[-] Elderos@sh.itjust.works 5 points 1 year ago* (last edited 1 year ago)

What you seem to be describing is one big class with lots of responsabilities, and not circular dependency. Personally, I don't think it is ideal, and I don't know about your specific case so I could be wrong, but I have never seen a legit case for bloated classes. That being said, making a big class is still much better than splitting it into inter-dependant classes. Classes that know each other are so cohesive that they might as well be the same class anyway.

To add onto the circular dependency problem, it is not just about readability and cognitive load (though there is some of that), but cyclic dependencies actively break things, and make it much harder to manage the lifecycle of a program. No dependency injection, poor memory management, long compile times. It is a huge hack, and I understand that you think it can be the proper solution sometime, but it is really just a bad thing to do, and it will bite you some day. And I am assuming here that you're using a language that is friendly, in some languages you won't even compile past a certain point, and good luck cleaning up that mess.

load more comments
view more: next ›
this post was submitted on 20 Jul 2023
861 points (99.1% liked)

Programmer Humor

32495 readers
507 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS