Sea of Tranquility

I like talking about sci-fi, space, robotics, linux, anti-fascism and democratic socialism. 🇩🇪☮️

(SeaOfTranquility on libera.chat or hackint.org or lemmy.world)

  • 0 Posts
  • 3 Comments
Joined 1 year ago
cake
Cake day: June 14th, 2023

help-circle

  • I’ve heard that a lot of people have trouble with updating and maintaining nextcloud but I personally never had those issues and my instance is running for over 5 years now. I would agree with other people here, that something like docker makes everything easier if you want to selfhost. I personally followed this guide with a custom dockerfile that looks something like this. Once you have a functional docker image and a docker-compose file, updating your instance is as easy as typing:

    docker compose stop
    docker compose rm -f
    docker compose build --pull
    docker compose up -d
    

    If you chose to go down that route as well, you might want to change the config files in your docker image since some of the values might not suit your instance. I, for example, have added the following for the PHP config:

    RUN sed -i "s/\(opcache\.interned_strings_buffer*=*\).*/\148/" /usr/local/etc/php/conf.d/opcache-recommended.ini
    RUN sed -i "s/\(opcache\.memory_consumption*=*\).*/\1256/" /usr/local/etc/php/conf.d/opcache-recommended.ini
    

  • There are a many approaches to implementing OOP in C. Since C doesn’t give you any language constructs to implement this out of the box, it’s up to you to do it in a consistent and understandable manner. Since there is no definite way to do it, let me just give you an example of how I would translate a Python file, and you can decide how you implement it from there:

    --------------
    class Parent:
        def __init__(self, param1: str, param2: int):
            self.__param1 = param1
            self.__param2 = param2
        def __private_method(self):
            print("private method")
        def public_method(self):
            print("public method")
        @staticmethod
        def static_method():
            print("static method")
        @property
        def param1(self):
            return self.__param1
    
    class Child(Parent):
        def __init__(self):
            super().__init__("param1", 2)
    --------------
    

    I would split the C code for this into header and source files:

    (header.h)

    --------------
    #pragma once
    
    /// Parent Class ///
    typedef struct Parent_obj {
        char* param1
        unsigned int param1_len
        int param2
    } Parent_obj_t;
    void Parent_init(Parent_obj_t* self, char* param1, unsigned int param1_len, int param2);
    void Parent_public_method(Parent_obj_t* self);
    void Parent_static_method();
    void Parent_param1(Parent_obj_t* self, char* out, unsigned int max_len); // property method with upper bound string length
    void Parent_del(Parent_obj_t* self); // destruct object (similar to __del__() in python)
    
    /// Child Class ///
    typedef struct Child_obj {
        Parent_hidden_state_t* super
        char* param
        unsigned int param_len
    } Child_obj_t
    void Child_init(Child_obj_t* self, Parent_obj_t* super);
    void Child_del(Child_obj_t* self);
    --------------
    

    (source.c)

    --------------
    #include "header.h"
    
    /// Parent Class ///
    // private methods
    void Parent_private_method(Parent_obj){...}
    // public methods
    void Parent_init(Parent_obj_t* self, char* param1, unsigned int param1_len, int param2){...}
    void Parent_public_method(Parent_obj_t* self){...}
    void Parent_static_method(){...}
    void Parent_param1(Parent_obj_t* self, char* out, unsigned int max_len){...}
    void Parent_del(Parent_obj_t* self){...}
    
    /// Child Class ///
    // public methods
    void Child_init(Child_obj_t* self, Parent_obj_t* super){...}
    void Child_del(Child_obj_t* self){...}
    --------------
    

    Modules and namespaces can be modeled using folders and prefixing your structs and functions.