separation of concerns – New frontend for legacy code

You have a legacy application that is a big ball of mud and a monolith. This application is “impossible” to change to look good on mobile devices.

The management is pushing to make it mobile friendly and more graphical appealing and to modernize it. Therefore a new frontend is needed that lives outside the monolith.

But where should the new frontend make request to perform business logic?

Create an api inside the monolith that is serving data to the outside when authenticated

Pros

  • Only 1 backend app. Simpler for debugging and deploying etc. Most of the code that the new frontend needs does already exist in the monolith.

Cons

  • Continues to develop a legacy application that needs to be modernized itself. With for example refactoring or to strangle it and writing new code.

Create a new application with shared database

Pros

  • Can make use of new frameworks and the latest version of PHP (or another language).

Cons

  • Another backend app to maintain.
  • Another backend app that can possibly corrupt data in database.
  • Code duplication. The code will probably be very similar to the already existing code in monolith.
  • Still stuck with the legacy database

## Create a new application with new database

Pros

  • Can make use of new frameworks and the latest version of PHP (or another language).
  • The database schema is designed with the needs of the new frontend.

Cons

  • Another backend app to maintain.
  • Data synchronization. This is gonna need a lot of data from the legacy database because their domain is still the same.

What would you do? Which of the options above? Or another solution?
What design patterns would you use with the chosen solution?


There is gonna be a small team working on this, 1-5 developers only.

google sheets – Extract the first three unique characters of a name to create a code

I have a column D where I store the VENDOR COMPANY NAME.
I have a column B where I want to calculate a SHORTCODE unique for each vendor. This code will be the first 3 letters of the VENDOR COMPANY NAME, Capitalised and unique in the Column B. If there is already a value of the same 3 letters in SHORTCODE, the next three letters of the name will be extracted, and so on.

For example, if I have a company name: ACME INDUSTRIES -> ACM will be extracted. If these is already a SHORTCODE with ACM in the column B, CME will be extracted. If CME already exists, MEI will be extracted, if that already exists EIN will be extracted. IF this value is unique it will be stored in the column B, SHORTCODE itself.

Currently I’m using the following formula, and have enabled Iterative Calculations in Google Sheets:

=IF($D12=””,””,IF((COUNTIF($B$2:$B,UPPER(LEFT($D12,3)))<1),(UPPER(LEFT($D12,3))),IF((COUNTIF($B$2:$B,UPPER(RIGHT(LEFT($D12,4),3)))<1),(UPPER(RIGHT(LEFT($D12,4),3))),IF((COUNTIF($B$2:$B,UPPER(RIGHT(LEFT($D12,5),3)))<1),(UPPER(RIGHT(LEFT($D12,5),3))),IF((COUNTIF($B$2:$B,UPPER(RIGHT(LEFT($D12,6),3)))<1),(UPPER(RIGHT(LEFT($D12,6),3))),”ERROR”)))))

The problem is that this code is very volatiles and keeps on changing, however I want fixed values?

Is there a way I can achieve this easily using formulas or Google app script?

Thanks

Worpress is replacing code with &nbsp;

I have a problem while editing my post on WordPress.
After adding <!DOCTYPE html> etc in the beginning of the code is keep getting replace with & nbsp; when I save it.
Is there any way to fix it?

php – Use old legacy application code from new application

If you have a big legacy application (big ball of mud), lets call it MudApp.

If you then create a new application to make us of new technology and to make a new good looking frontend because that was impossible in the MudApp. This new application is supposed to the fresh one and with only the most important features of the MudApp. Lets call it MobileApp.

Some features is really difficult to implement in the MobileApp with identical functionality as in the MudApp so the solution has been to just make a request (via API, SOAP or whatever) from MobileApp to MudApp and let the MudApp do all the work. Some other features is written directly inside the MobileApp.

My first thought is that this is bad with to much coupling between them etc. But I can not really make an argument for why it’s bad.

Is this bad or good? And why?


Note 1: the applications is sharing database (which for some is bad practice, but in this case I think it’s fine because it would be to much work syncing to another database and so on.)

Note 2: The reason for the question is because the MobileApp is supposed to be further developed. Some features will be added and some removed. So I’m trying to figure out if the NEW MobileApp should make us of the current MobileApp (Took approx. 2-4 month to write) or just start over on a clean sheet

readability – Which Code Lines Are More Readable?

Although I am having doubts to asking this question, I decided to ask. I have two different code blocks and two different preferences for each. Please decide one of it and share your reasons.

IF RETURN / RETURN OR IF RETURN / ELSE RETURN

OPTION 1

if(statement){
   //do things
   RETURN abc;
}
else {
   RETURN xyz;
}

OPTION 2

if(statement){
   //do things
   RETURN abc;
}

RETURN xyz;

According to me, first option is more readible and easier to understand. I know that if statement is correct, else section is completely ignored. However if we use option 2, we should consider last return too. What do you think?

MULTIPLE IF BLOCKS ONE BY ONE OR SINGLE, BULKY STATEMENTS

const isValidFirstName = (firstName) => (
  .
  .
  .
  //return true or false
);

const isValidLastName = (lastName) => (
  .
  .
  .
  //return true or false
)

const isValidContactDetail = (contactDetail) => (
  .
  .
  .
  //return true or false
)

OPTION 1

const formValidation = ({ firstName, lastName, contactDetail, email, phoneNumber, message }) => {
  if (!isValidFirstName(firstName)) {
    return false;
  }

  if (!isValidLastName(lastName)) {
    return false;
  }

  if (!isValidContactDetail(contactDetail)) {
    return false;
  }
  .
  .
  .
  //3 or 4 more statements
  return true;
}

OPTION 2

const formValidation = ({ firstName, lastName, contactDetail, email, phoneNumber, message }) => {
      if (!isValidFirstName(firstName) && 
          !isValidLastName(lastName) &&
          !isValidContactDetail(contactDetail) &&
          . &&
          . &&
          . &&
          //3 4 more statements
      ) {
        return false;
      }
      return true;
}

I think first option is more readable because we can distinct which statements for which and easier to debug if anything unexpected happens. It is significantly causes more code lines but I am not sure which one is better.

PS: I know that all situations are doing the same thing and no difference in compilation & performance.

Thanks a lot.

theme development – How to create code template to promote products inside WordPress post

I want to suggest products inside a post content, something similar to the wirecutter style, but I don’t how to get started without using a plugin.
Does anyone have any idea what would be the best approach to get this done?
The product promotion has to include product name, subtitle, description, image, and button with the link to the product.

javascript – En la aplicación atom , me sale error el code document

En atom me sale en rojo el code document. y no me deja declarar en la página

 const btnFanática = document.getElementsById
 ("btn-fanática")

 btnFanática.addEventListener('click', () =>{
   document.getElementById("container-fanática")
   .style.display = "block";
 })

Python /xed problems? – Code Review Stack Exchange

The code printed below is in Korean because I’m making a Korean text adventure

player_race = str(input('인종을 선택하십시오 :n' + Style.RESET_ALL + '(' + Fore.RED + '인간' + Style.RESET_ALL + ') ' + Fore.RED + '인간은 가장 밸런스 된 인종n' + Style.RESET_ALL + '(' + Fore.GREEN + '도마뱀' + Style.RESET_ALL + ') ' + Fore.GREEN + '도마뱀은 속도가 높고, 힘이 약함n' + Style.RESET_ALL + '(' + Fore.YELLOW + '엘프' + Style.RESET_ALL + ') ' + Fore.YELLOW + '엘프는 활을 잘쏘고 명중률이 높다n' + Style.RESET_ALL + '(' + Fore.BLACK + '오크' + Style.RESET_ALL + ')' + Fore.BLACK + ' 오크는 힘이 넘치고 느리다' + Style.RESET_ALL))

This is one line of my code and it says

  File "c:/Users/seung/src/Python games/Working on/adventure/TextAdventure.en.py", line 31
SyntaxError: Non-UTF-8 code starting with 'xed' in file c:/Users/seung/src/Python games/Working on/adventure/TextAdventure.en.py on line 31, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
PS C:Usersseungsrc> 

How can I make this C++ code to obtain passwords more efficient?

Comments kind of explain it. Thanks for helping. Backspaces character only move cursor back and don’t erase output so I need to overwrite them with ‘ ‘ to delete them.

#include <iostream>
#include <string>
using namespace std;

const string PASSWORD = "PASSWORD";
int main(int argc, char** argv) {
string userkey = "";
char c;
int keystrokes = 0;


cout<<"Enter passkey: ";
while(true){
    if(_kbhit()){
        c=_getche();
        if(c=='r'){//check if user hit enter, _getche() records enter as r
            cout<<'n';
            break;
        }   
        else if(c =='b'){//check if user typed backslash, overwrite character there
            cout<<' ';
            if(keystrokes==1){ //makes sure userkey is cleared
                userkey = "";
                keystrokes--;
                cout<<'b';
            }
            else if(keystrokes!=0){
                userkey = userkey.substr(0,userkey.length()-1);//cuts out last char of userkey
                keystrokes--;
                cout<<'b';
            }
        }
        else if (c!='b'){
            cout<<"b*";//replaces enter char with'*'
            keystrokes++;
            userkey+=c;
        }
    }
}
//cout<<userkey;
if (userkey!=PASSWORD)
    return 0;

views – Get the user’s current language code

How can I get the user’s current language code in a view as a raw value, for example en or fr-ca?

This isn’t for filtering content. I need the raw value of the users’ current language to pass into a URL for a third-party tool. I added a custom text field. Then placed in some Twig code. The code is just failing to the fallback else value.

Based on other forum posts, I tried this code.

{% if language.getId() == 'en' %}
  en
{% elseif language.getId() == 'es-us' %}
  es-us
{% elseif language.getId() == 'en-us' %}
  en-us
{% else %}
  failed
{% endif %}

I get failed.

{% if language == 'en' %} 
  en
{% elseif language == 'es-us' %}
  es-us
{% elseif language == 'en-us' %}
  en-us
{% else %}
  failed
{% endif %}

I still get failed.

{% if language.id() == 'en' %}
  en
{% elseif language.id() == 'es-us' %}
  es-us
{% elseif language.id() == 'en-us' %}
  en-us
{% else %}
  failed
{% endif %}

I still get the same output.