Why is a bad idea to use the Builder Pattern everywhere?

Recently I shared with my team the Builder Pattern(fluent style) for unit testing.
I personally like to use that pattern for unit testing, since many objects are usually created and with different parameter configurations.
The pattern helps keeping the unit tests short, specially if combined with Object Mother pattern.

Now some members of the team want to use it in other areas of the project, and it looks to me like it may spread everywhere…

Why would that be bad?
I understand that there is a cost on creating the Builders, but since we already have them, why not use them?

reverse engineering – What is source of bad characters exist in buffer overflows

I’m new to exploit development and while watching a tutorial I came across the topic of “Bad character identification”. I’m referring to the process of sending all possible characters to the vulnerable process to see if there are characters which fail to pass to the receiver.

The existence and identification of those characters has been discussed many times before but I couldn’t find the root cause of their existence.

Why are there bad characters a target process mis-handles?

javascript – Is it a bad idea to store functions inside components in ECS?

Say I have three entities: Player, Spikes, and Zombie. All of them are just rectangles and they can collide with each other. All of them have the BoxCollision component.

So, the BoxCollison system would look something like this:

function detectCollisions () {
  // for each entity with box collision
    // check if they collide
      // then do something
}

The issue is, the sole purpose of the BoxCollision component is to detect collision, and that’s it. Where should I put the game rules, such as “if the Player collided with Spikes, diminish its health” or “if the Zombie collided with Spikes, instantly kill the Zombie”?

I came up with the idea that each Entity should have its onCollision function.

Programming languages such as Javascript and F# have high-order functions, so I can easily pass functions around. So when assembling my Player entity, I could do something like:

function onPlayerCollision (player) {
  return function (entity) {
    if (entity.tag === 'Zombie') {
      player.getComponent('Health').hp -= 1
    } else if (entity.tag === 'Spikes') {
      player.getComponent('Health').hp -= 5
    }
  }
}

const player = new Entity()
player.addComponent('Health', { hp: 100 })
player.addComponent('BoxCollision', { onCollision: onPlayerCollision(player) } 
// notice I store a reference to a function here, so now the BoxCollision component will execute this passing the entity the player has collided with
function detectCollisions () {
  // for each entity with box collision
    // check if they collide
      onCollision(entity)

onPlayerCollision is a curried/closure function that receives a player, and then returns a new function that wants another Entity.

Are there any flaws with this? Is it okay for components to store references to functions? What are other ways of avoiding game rules in components? Events?

Thanks!

accessibility – HTML Aria function not being read by screen reader – Bad design?

I’m looking into how accessible some websites are using WebAIM’s WAVE tool. Many websites nowadays use the burger menu symbol to indicate the menu (YouTube and Gmail for example) and often I see the Aria attribute being used to say ‘open-menu’ or something of that sort. However, when I test it with NVDA and hover over them, the screen reader doesn’t return anything.

For example here: https://www.rijksmuseum.nl/en

On the left is the burger symbol, a magnifying glass (for search) and text-links. NVDA only reads out the latter text-links when hovered over, but not the former two non-text symbols. The two symbols (burger and magnifying glass) don’t change colour or give any indication that they’re clickable when hovered over besides the mouse pointer changing.

Is the Aria label supposed to be function (or not function) this way or is this just bad code/design? Or am I just completely misunderstanding how a screen reader is supposed to function?

maintainability – How bad is the following code

I am extending and maintaining customized extension of OpenAPI Generator.
It’s a working solution. What I am concerned here is the quality of the underlying open source project:

  1. Missing documentation of the code (considering its used as an extendable library/open source)
  2. In general structure is good but crucial, important classes lack implementation patterns or clean code principles.
  3. There are 1.8k open issues

When I have to extend some logic regarding my custom imports logic or grouping operations it just gives me headache trying to see all the puzzles and pieces.

The question

Would you consider following code bad, hard to maintain?

DefaultGenerator.java

DefaultCodegen.java

I mean wouldn’t be practical to refactor those classes, to make it easier to comprehend the logic and ease up the maintainability of it, especially as there are so many contributors who spend time on it? Imagine someone invents a new type of schema, and you go and add another else if statement in lines 1600, 2000, 2400, 4900, 5900 and 6000 something.

PS:
I don’t want to offend anyone, the code generator is actually working and being used by the thousands of people.
Chapeau to all of the contributors, especially core ones for amazing work done!

design – Is it bad practice to mutate your HttpClient objects?

Im in the process of creating a base class for typed HttpClient services (yes, I’m utilizing IHttpClientFactory). I wrote the process in such a way that for each CRUD method invoked from the service, the first thing said service does is check for and assign an access token to attach to the HttpClient header. Example:

public abstract class BaseNetworkService : IBaseNetworkService {
   protected HttpClient _httpClient { get; }

   public BaseNetworkService(HttpClient client, ...) {
      _httpClient = client;
   }
   
   public async Task<T> GetAsync<T>(string extendedUrl, ICacheContext cacheContext = null) {
      ... check Redis Cache, return result if there ...
      
      Http client = GetcurrentAccessToken(_httpClient);
      var response = await client.GetAsync(extendedUrl);
      ...
   }
}

I’ll admit upfront that I am not entirely sure why I have always made my HttpClients readonly and upon Googling for answers, it’s probably because every document and guide on HttpClient with dependency injection makes the client readonly. I didn’t find any material explaining the reason for that.

With that in mind, should your HttpClientremain readonly? Should any customization, such as attaching an access token, be done in the classes constructor?

frontend – Is it bad to use ObjectManager in list.phtml like in Code Below?? What’s the best Practice?

Is it bad practice to use ObjectManager in file app/design/frontend/Smartwave/porto/Magento_Catalog/templates/product/list.phtml

like this below.

        <?php 
        $objectManager = MagentoFrameworkAppObjectManager::getInstance();
        $category = $objectManager->get('MagentoFrameworkRegistry')->registry('current_category');
        if($category->getDescription())
        {
            echo '<div style="padding: 13px;margin-top: 15px;">'.$category->getDescription().'</div>';
        }

Would there be a better way to write this???

Any help would be greatly appreciated. Thank you!

docker – nginx proxy_pass return 502 Bad Gateway

I’m building nginx for reverse_proxy with Spring and Docker

Here is my configuration.

nginx.conf

user  proxy;
worker_processes  auto;
error_log  logs/error.log;
error_log  logs/error.log  notice;
error_log  logs/error.log  info;
pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    log_format  main  '$remote_addr - $remote_user ($time_local) "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  logs/access.log  main;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include       mime.types;
    default_type  application/octet-stream;

    include /home/wertkey/nginx/conf/conf.d/*.conf;

    client_max_body_size 200M;
    client_header_buffer_size  48k;

    server {
        listen       7070 default_server;
        listen       (::):7070 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        location / {
        }

        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }
}

conf.d/default.conf

server {
    listen 7070;
    server_name something.com;

    proxy_connect_timeout   900s;
    proxy_send_timeout      900s;
    proxy_read_timeout      900s;
    send_timeout            900s;

    location ^~ /editor/ {
        proxy_pass http://localhost:8081;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;

        rewrite ^/editor/(/.*)$ $1 break;
    }
}

docker

CONTAINER ID        IMAGE        COMMAND                  CREATED             STATUS              PORTS                    NAMES
a6a6a98a25a9        editor       "/bin/sh -c /usr/l..."   8 minutes ago       Up 8 minutes        0.0.0.0:8081->8080/tcp   editor

My spring server is running at 7070 port.
I want to be this way.

  1. request something.com:7070/api
  2. nginx proxy_pass to 8081
  3. and docker 8081 -> 8080

But response always return 502 Bad Gateway

What am i missing?