What is your biggest fear with the current A.I. revolution?

One thing that I have learned , is to acknowledge my fears in order to see if I can do anything about them. I would love to read yours fears about this A.I. revolution.

I have chosen to participate in this weave with what ever resources my small company has , because I know that this is a deeply transformative technology in my field (for example we will lunch a products chatbot in some of our clients eShops apps , maybe I will write a separate post about that experience). But of course there many things that I fear, except that A.I. will rule (or even kill) us all.

I believe that this current A.I. frenzy state , is a hype but one that would not go away. As the web bubble burst in early 2000 I believe that something similar will happen with all these "not really" A.I. companies. But the affects will be there. And as the web changed anything , this A.I. wave will do , once again.

My biggest fear is that this revolution is chaotic and driven by near future profits , or / and by near future egos boosting , ignoring the big picture. Some years ago I had the opinion that A.I. will "leak" to the real world piece by piece and that will be barely noticed. Now it makes sounds that are recognized more as explosions.

The consequences of those explosions are not clear , or even what the word will look like after. I know for example that our clients have started to ask things that even in the most futuristic Star Trek movies would look crazy. I know that when we launch an A.I. related product our clients expectations have nothing to do with reality and merge supernatural with tech. The expectations are wild and not founded in any truth or technology.

As Sam said in the topic "what Illia show ?" , my biggest fear is that this all thing has exploded in an awful way. What we will do when we don't hire new programmers because the low end jobs can be done by A.I. ? Will they ever become high end programmers with no experience at all ?

How will this all economy cycle work if you take parts of it off and you have no idea of how will be replaced ? It is a messy transition , ... so more dystopian than I could ever think.

AlmaLinux vs Rocky Linux for a new server

I watched both grow , from their early beginnings , because our current servers are on CentOS and of course I am not happy with where CentOS has gone.
Because the CentOS lesson , I have been really caution and I am a little bit too worried from witch one from those to select. If you have build in a server in top of an OS a tons of others systems you CAN'T just change the OS. You just migrate to a new server with whatever that means (it is not just the cost , consider the burden to the Sales & Demand dpt. to make all users to use a new serve in their outlook or what ever their are using)
I will not list the advertised pros for each one of them in relation to the other ( to be fair an LLM can summarize pretty well press releases even if you ask one vs the other). And notice that I am leaning to AlmaLinux.

But ... If you imagine AlmaLinux as an entity , then that entity is living out of resources from CloudLinux. There is nothing bad about that , it is not their's (CloudLinux) property nor can they can influence the AlmaLinux future path (I hope). But if CloudLinux bankrupts , or just stops supporting AlmaLinux what happens ? Will AlmaLinux still be there ?

And there there is Rocky Linux , witch seems great. And the sales point is that the human that is under CentOS is also under Rocky. And exactly this is the reason I am not leaning towards Rocky. Why couldn't the same play that happened with CentOS repeat with Rocky ? Some entity (big company or a crazy billionaire) buys it out and make your version non upgradable as it is, except of course if you pay a stream something and be a forever customer that they can bill you as match as they like.

What is your view in this dilemma ?

Google is promoting reddit in an arrogant way

I don't love Reddit , in fact before Google started to slap it on my face few months ago , I had many years to been there for a simple reason I didn't liked their format nor their way of "building" a programmers community.
Now everything I search in Google in the top 5 result there should be a Reddit post. Even if it is rather irrelevant with my search and only in the outer match of the embeddings of my query, even so ... there it is.
I understand that Google NEEDS human created content (as all the AI "lets gain some bucks now, before they get what we are doing" folks) but is it logical to invest so much users expectation in a specific site and to promote it so ruthlessly in search results , that makes those Google results look silly ?

What do you think ?

How do you use LLM AI tools in your daily programming workflow ?

I am curious how other programmers that I have no interaction with in this subject , are using LLM AI tools in their daily programming workflow.

Although I use them I have an issue recommending them to others in my company because I believe you have to have a certain amount of experience to understand the B..S.. parts from the real useful ones. The coding hallucinations are starting to become so great that you can't tell if a library that the code uses doesn't exist (and never existed) because the usage and references are plausible. When you ask general programming questions you usually get answers that are common misconceptions and far from the truth. e.g. Some moments ago Gemini told me that when it replied that Memory tables are not faster than MyIssam or InnoDb it meant that most servers have less RAM than the table size !!! (maybe that was accurate 15 years ago ... but again ... not even then ... )

But... I realize that more and more ChatGPT and maybe even more Gemini , are part of my starting point when I search something related to programming.

What is your experience so far ?

C++ How bad is to implement class methods in a hpp file and on its cpp ?

Hello , I always had a distant relationship with C++ (writing in it small programs (or libs for other languages) only when performance really matters) but I have found myself writing more and more C++ bots. I learned that you need to separate the definition of the class (interface in c++ ) in a hpp file with its implementation in a cpp file , but as i write more I got tired of that and now I implement my methods in the header hpp file .
I have tried to understand why this is not the way to do it but I still don't get it. Of course implementing the methods in a cpp file could give you the option to implement some of them in one file and some of them in another in the future but that would be a mess in my opinion.
Have I got this all wrong ?

Shared Web Worker with Dedicated Web Worker as failover – Lazy Load Example

I wanted to post something in Daniweb for a while but I didn't had anything new. Recently I decided to write a new implementation for websocket connections client side using Shared Web Workers. Shared Web Workers are supported today by most browsers for desktop but few for mobile devices , so it had to have a fallover mechanism to Dedicated Web Workers. I searched but I didn't found an example , so I am posting it here. Moreover since we will have a worker not in main thread it would be great to have the option for callback functions for other uses than WebSockets. I implemented these without any framework to keep it as simple as possible and here it is an example of this for something common and useful , lazy loading images . It needs to be modified if you are going to use it to be adjusted to your needs and to add error handling and arguments checking at least.

We are going to user five files in a folder. Two images: one imageExample.jpg that is going to be the image to lazy load and a transparent1x1.png that is a transparent image 1px x 1px that we will use as placeholder src for the image before is loaded.

Lets start with the index.php (I am using PHP here but you can use any language)

<?php
/*
getting the root URL of the project is beyond the scope of this ,
but here is a quick implementation  
 */
$v = $_SERVER["SERVER_PROTOCOL"] ; 
$v = mb_strtolower(mb_substr($v, 0 , mb_strrpos($v, "/")));
if(isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on")
{
    $v .= "s";
}
$root = $v."://".$_SERVER['HTTP_HOST']; 
$v = $_SERVER["PHP_SELF"];
$v = mb_substr($v, 0 , mb_strrpos($v, "/"));
$root .= $v;
?>
<html>
<head>
    <title>
        JavaScript Shared Web Worker with Dedicated Web Worker as failover 
        - Lazy Loading Images example
    </title>
    <style>
        /* IntersectionObserver works better with blocking elements to determine if are 
            intersected with the viewport */
        picture,img
        {
            display: inline-block;
            vertical-align: middle;
        }
    </style>
</head>
<body>
    <!-- all the img tags inside picture elements will be loaded with the 
        src of the noscript img tag when they appear on screen   -->
    <picture>
        <noscript>
            <img src="<?=$root?>/imageExample.jpg" alt="example image" width="800" height="500" />
        </noscript>
        <img src="<?=$root?>/transparent1x1.png" alt="example image" width="800" height="500" />
    </picture>
    <script type="text/javascript">
        /*
            load the example.js after DOMContentLoaded or if that doesn't fired on window.onload 
            and then call the init of the example object that instantiated there 
        */
        var _fncl=false;
        _fnc=function()
        {
            _fncl=true;
            var s = document.createElement("script");
            s.async=true;
            s.src="<?=$root?>/example.js?"+<?=date("U")?>;
            s.addEventListener("load", function(e)
            {
                    _.init("<?=$root?>");
            }, false);
            document.body.appendChild(s);
        };
        window.addEventListener("DOMContentLoaded", _fnc);
        window.onload=function(){if(!_fncl){_fnc();}};
    </script>  
</body>
</html>

As you can see it is very simple , now lets move to the main JavaScript file that will be loaded the example.js

/*
    this is an example of how the concept works it doesn't have error handling 
    or checking arguments for their correct type or even existence , 
    in real life projects those should implemented 
*/
const _ = new (function() // _ object holds the core functionalities  
{
    var _this = this; 
    var worker = null;
    var shared = false;
    var privateRoot = null;
    var index = 0; 
    var works = {}; 

    this.init = function(root)
    {
        privateRoot = root; 
        shared = !!window.SharedWorker; // if Shared Web Workers are supported
        //use Dedicated Web Worker when developing new methods 
        //  in order to view the errors in console 
        //shared = false;
        setWorker();
        app.init(); // ready to init the app object
    }

    this.root = function()
    {
        return privateRoot; 
    };

    this.getWorkKey = function()
    {
        index++;
        return "w"+index; 
    };

    /*
        request a work from the worker with callback function 
        dataObj is the object that will be send to the worker 
            , it must contains at least an action that will be a function of the worker 
            and any other data we might use there 
        fnc is the the callback function example: function(responseDataObj,argObj){} 
        argObj contains all other data we might need along with the response data   
    */
    this.work = function(dataObj,fnc,argsObj)
    {
        let wKey =  _this.getWorkKey();
        dataObj.wKey = wKey;
        works[wKey] = [fnc,argsObj];
        worker.postMessage(dataObj);
    };

    function setWorker()
    {
        if(shared)// instantiate the worker 
        {
            let w = new SharedWorker(_this.root()+"/worker.js");
            worker = w.port;
            worker.start();
        }
        else 
        {
            worker = new Worker(_this.root()+"/worker.js");
        }

        var handler = function(event)//handle incoming events from worker
        { 
            let data = event.data;
            if("n" in data && data.n == "u") // pong (ping response) that this page is still alive 
            {
                worker.postMessage({n:"y"});
            }
            else if("log" in data) // let the worker send messages to window console 
            {
                window.console.log(data.log);
                //worker.postMessage({n:"y"});
            }
            else if(data.wKey in works)
            {
                let arr = works[data.wKey]; // the array that is store in works object 
                // that has as first element the function and second the arguements object 
                arr[0](data,arr[1]); // call the callback function
                works[data.wKey] = null; 
                delete works[data.wKey]; // try to remove it from memory when gc will pass
            }
        };

        if(shared) // attach the handler to the worker 
        {
            worker.onmessage = (event) => {
                handler(event);
            };
        }
        else
        {
            worker.addEventListener('message', event => 
            {
                handler(event);
            });
        }
    }


})();


const app = new (function() //app object has specific code for this app 
{
    var _this = this; 
    this.lazyLoadObjerver = null;

    this.init = function()
    {
        setIntersectionObserver();
    };


    function setIntersectionObserver()
    {
        if ("IntersectionObserver" in window)
        {
            _this.lazyLoadObjerver = new IntersectionObserver(_this.lazyLoader);
        }
        _this.lazyLoad();
    }



    this.lazyLoad = function()
    {
        const els = document.getElementsByTagName("picture");
        for (const el of els)
        {
            if(_this.lazyLoadObjerver == null) // if the browser doesn't support IntersectionObserver
            {
                const src = el.querySelector("noscript").innerHTML
                    .match(/.*src=["']([^"]*)['"].*/)[1];// get src of the image
                el.querySelector("img").setAttribute("src",src);
            }
            else 
            {
                _this.lazyLoadObjerver.observe(el);
            }
        }
    };

    this.lazyLoader = function(entries, observer)
    {
        entries.forEach(function(entry) 
        {
            const el = entry.target;
            if (entry.isIntersecting) 
            {
                if(el.getAttribute("class") != "lz")
                {


                    const src = el.querySelector("noscript").innerHTML
                        .match(/.*src=["']([^"]*)['"].*/)[1];// get src of the image
                    // data object for the worker request
                    const dataObj = {action:"loadBlob",url:src};
                    // arguements object for the callback function
                    const argObj = {el:el}; 
                    // the callback function;
                    const fnc = function(data,arg){
                        const img = arg.el.querySelector("img");
                        arg.el.setAttribute("class","lz");
                        img.setAttribute("src",URL.createObjectURL(data.blob));
                    };
                    _.work(dataObj,fnc,argObj);

                }
            }
        });
    };

})();

And finally the worker.js file , it worth mentioning that if you are going to use Shared Web Workers I couldn't find any other way then a separate file.

(I am adding it as code snippet because without code snippet it doesn't allow me to post)

I hope to enjoy it , I added some comments inside the code but feel free to ask anything related. Also any other ideas would be welcomed

How can this be more difficult for users ?

I just came in and had a topic to discuss with other programmers ... I remembered DaniWeb because in the past I have received very clever answers in questions that most don't know that exist at all. And I hope I also helped others as well. But how difficult could be to arrive to "community central" ? . I still don't know the answer I can't select a topic and see all related threads , only drop down with things that are not related , the only action I can do in DaniWeb as it is , is posting ... and I do ....

Java vs PHP for web application decision (again)

The facts: We are talking about a small company (5 persons) with many clients that making real money (we don't) . We provide our own software that has unique features against the e-commerce completion.

The problem: the first glimpse of the problem arose around 2012 and made clear around 2014 with web sockets. Some clients didn't want a simple chat with their client but instead a full live eShop where they could negotiate the prices of a product or even start a discussion with a visitor. The solution would be implementing web sockets in to our framework and that worked , but using incredible resources without any sideway compensation benefits. What that could be ?: 1) we use app scope caching (for object or list of objects) and thought that is done in the memory of the server, each request you have to deserialize / serialize (if there are changes) objects (that is CPU expensive and time consuming , I calculated that it cost almost 2 milliseconds in each response). More over if I have something running along with the app why not having a DB pool where the most common prepared statement persists?

The first solution: Was a new PHP framework that was basically a C++ extension , everything worked fine (almost (if someone interesting I could share more)) (it went in production only in one project). Application scope caching was working with lockers when those objects updated, and we could have a first r&d glimpse in db pooling in PHP. More over it would eliminate DNS lookup since the SPA app would hook to the WebSocket if available or to AJAX if not. (when I am talking about SPA here you would see the same content if you visit a URL for the first time as if you visit it through an inner link).

And then PHP 7.0.2 came: The incontinences of PHP are monumental, but the all thing shattered in the ground. In fact we weren't trying to produce a framework we were trying to produce an application server that would hold that framework. The application server part could be done with more resources and in a specific PHP version, but we don't have the resources nor do we want to bind ourselves to a specific PHP version.

The /lets move back/ moment: There is a language that you can use an application server ,you can share application scope caching objects without deserializing / serializing and also has many add ons for web sockets and more its easy and I have know know it since teenager (no it wasn't my first language) , that language is Java and an application server along with it like Tomcat for example.

The decision is difficult to make , switching to Java , would require rewriting all of our apps , but the two main goals will be achieved (app scope caching , db pool). On the other hand there is a limit to understanding how a JVM is working internally and to write good code for that , using system extensions (example imageMagick).

One plus for Java would be that after that we could share our java code without classes and one serious downside would be that we coudn't write more C++ extensions to make our life easier + faster + more efficient. But to maintain a PHP application server is far more difficult than I first thought.

I would highly appreciate any point of views on that , since I am in a crossroad.