Skip to main content
deleted 15 characters in body
Source Link
Doc Brown
  • 214k
  • 34
  • 394
  • 603

According to some answers of How are globals any different from a database? that explains how database is different from global state:

https://softwareengineering.stackexchange.com/a/319389/432039 https://softwareengineering.stackexchange.com/a/319403/432039 https://softwareengineering.stackexchange.com/a/319399/432039

as I understand, the answers roughly explainsexplain accessing toa database using "a consistent, understandable interface" in code is different from accessing a global variable. However, what I don't understand is, how a "a consistent, understandable interface" code differentiates from accessing global variables? For example, when accessing global variables:

public void myMethod(){
   AppData.someValue = x;
}

the global state is eval because you can paste "AppData.someValue = x" in any other methods, resulting everyone can modify the state.

When changing the access way from global state to database:

public void myMethod(){
   MyConnector mc=...;
   Session s=mc.beginTransaction();
   AppData appData=mc.getObjectFromTable(...);
   appData.someValue=x;
   s.save(appData);
   s.endTransaction();
   mc.close();
}

When you paste the wall of code:

MyConnector mc=...;
Session s=mc.beginTransaction();
AppData appData=mc.getObjectFromTable(...);
appData.someValue=x;
s.save(appData);
s.endTransaction();
mc.close();

to any other methods, every methods can also change the value of someValue.

Just because the code to trigger "everyone can modify the state" is longer or even has better name than "AppData.someValue = x" doesn't change the nature of the code that lets everyone can modify the state.

To differentiate database from global states, I think we should wrap and apply dependency injection to the database driver:

public void myMethod(MyConnector mc){
   Session s=mc.beginTransaction();
   AppData appData=mc.getObjectFromTable(...);
   appData.someValue=x;
   s.save(appData);
   s.endTransaction();
   mc.close();
}

so that not every methods can access to database, same as the case of accessing global variables that inject the object only when a method needs to change it.

So my question is, why does "a consistent, understandable interface" differentiates database from global states, even I can paste the "a consistent, understandable interface" code everywhere to let anyone modify the global state, just like global variables?

According to some answers of How are globals any different from a database? that explains how database is different from global state:

https://softwareengineering.stackexchange.com/a/319389/432039 https://softwareengineering.stackexchange.com/a/319403/432039 https://softwareengineering.stackexchange.com/a/319399/432039

as I understand, the answers roughly explains accessing to database using "a consistent, understandable interface" code is different from accessing a global variable. However, what I don't understand is, how a "a consistent, understandable interface" code differentiates from accessing global variables? For example, when accessing global variables:

public void myMethod(){
   AppData.someValue = x;
}

the global state is eval because you can paste "AppData.someValue = x" in any other methods, resulting everyone can modify the state.

When changing the access way from global state to database:

public void myMethod(){
   MyConnector mc=...;
   Session s=mc.beginTransaction();
   AppData appData=mc.getObjectFromTable(...);
   appData.someValue=x;
   s.save(appData);
   s.endTransaction();
   mc.close();
}

When you paste the wall of code:

MyConnector mc=...;
Session s=mc.beginTransaction();
AppData appData=mc.getObjectFromTable(...);
appData.someValue=x;
s.save(appData);
s.endTransaction();
mc.close();

to any other methods, every methods can also change the value of someValue.

Just because the code to trigger "everyone can modify the state" is longer or even has better name than "AppData.someValue = x" doesn't change the nature of the code that lets everyone can modify the state.

To differentiate database from global states, I think we should wrap and apply dependency injection to the database driver:

public void myMethod(MyConnector mc){
   Session s=mc.beginTransaction();
   AppData appData=mc.getObjectFromTable(...);
   appData.someValue=x;
   s.save(appData);
   s.endTransaction();
   mc.close();
}

so that not every methods can access to database, same as the case of accessing global variables that inject the object only when a method needs to change it.

So my question is, why does "a consistent, understandable interface" differentiates database from global states, even I can paste the "a consistent, understandable interface" code everywhere to let anyone modify the global state, just like global variables?

According to some answers of How are globals any different from a database? that explains how database is different from global state:

as I understand, the answers roughly explain accessing a database using "a consistent, understandable interface" in code is different from accessing a global variable. However, what I don't understand is, how a "a consistent, understandable interface" differentiates from accessing global variables? For example, when accessing global variables:

public void myMethod(){
   AppData.someValue = x;
}

the global state is eval because you can paste "AppData.someValue = x" in any other methods, resulting everyone can modify the state.

When changing the access way from global state to database:

public void myMethod(){
   MyConnector mc=...;
   Session s=mc.beginTransaction();
   AppData appData=mc.getObjectFromTable(...);
   appData.someValue=x;
   s.save(appData);
   s.endTransaction();
   mc.close();
}

When you paste the wall of code:

MyConnector mc=...;
Session s=mc.beginTransaction();
AppData appData=mc.getObjectFromTable(...);
appData.someValue=x;
s.save(appData);
s.endTransaction();
mc.close();

to any other methods, every methods can also change the value of someValue.

Just because the code to trigger "everyone can modify the state" is longer or even has better name than "AppData.someValue = x" doesn't change the nature of the code that lets everyone can modify the state.

To differentiate database from global states, I think we should wrap and apply dependency injection to the database driver:

public void myMethod(MyConnector mc){
   Session s=mc.beginTransaction();
   AppData appData=mc.getObjectFromTable(...);
   appData.someValue=x;
   s.save(appData);
   s.endTransaction();
   mc.close();
}

so that not every methods can access to database, same as the case of accessing global variables that inject the object only when a method needs to change it.

So my question is, why does "a consistent, understandable interface" differentiates database from global states, even I can paste the "a consistent, understandable interface" code everywhere to let anyone modify the global state, just like global variables?

added 6 characters in body
Source Link
wcminipgasker2023
  • 2.7k
  • 1
  • 14
  • 29

According to some answers of How are globals any different from a database? that explains how database is different from global state:

https://softwareengineering.stackexchange.com/a/319389/432039 https://softwareengineering.stackexchange.com/a/319403/432039 https://softwareengineering.stackexchange.com/a/319399/432039

as I understand, the answers saysroughly explains accessing to database usesusing "a consistent, understandable interface" code, which is different from accessing a global variable. However, what I don't understand is, how a "a consistent, understandable interface" code differentiates from accessing global variables? For example, when accessing global variables:

public void myMethod(){
   AppData.someValue = x;
}

the global state is eval because you can paste "AppData.someValue = x" in any other methods, resulting everyone can modify the state.

When changing the access way from global state to database:

public void myMethod(){
   MyConnector mc=...;
   Session s=mc.beginTransaction();
   AppData appData=mc.getObjectFromTable(...);
   appData.someValue=x;
   s.save(appData);
   s.endTransaction();
   mc.close();
}

When you paste the wall of code:

MyConnector mc=...;
Session s=mc.beginTransaction();
AppData appData=mc.getObjectFromTable(...);
appData.someValue=x;
s.save(appData);
s.endTransaction();
mc.close();

to any other methods, every methods can also change the value of someValue.

Just because the code to trigger "everyone can modify the state" is longer or even has better name than "AppData.someValue = x" doesn't change the nature of the code that lets everyone can modify the state.

To differentiate database from global states, I think we should wrap and apply dependency injection to the database driver:

public void myMethod(MyConnector mc){
   Session s=mc.beginTransaction();
   AppData appData=mc.getObjectFromTable(...);
   appData.someValue=x;
   s.save(appData);
   s.endTransaction();
   mc.close();
}

so that not every methods can access to database, same as the case of accessing global variables that inject the object only when a method needs to change it.

So my question is, why does "a consistent, understandable interface" differentiates database from global states, even I can paste the "a consistent, understandable interface" code everywhere to let anyone modify the global state, just like global variables?

According to some answers of How are globals any different from a database? that explains how database is different from global state:

https://softwareengineering.stackexchange.com/a/319389/432039 https://softwareengineering.stackexchange.com/a/319403/432039 https://softwareengineering.stackexchange.com/a/319399/432039

as I understand, the answers says accessing to database uses "a consistent, understandable interface" code, which is different from accessing a global variable. However, what I don't understand is, how a "a consistent, understandable interface" code differentiates from accessing global variables? For example, when accessing global variables:

public void myMethod(){
   AppData.someValue = x;
}

the global state is eval because you can paste "AppData.someValue = x" in any other methods, resulting everyone can modify the state.

When changing the access way from global state to database:

public void myMethod(){
   MyConnector mc=...;
   Session s=mc.beginTransaction();
   AppData appData=mc.getObjectFromTable(...);
   appData.someValue=x;
   s.save(appData);
   s.endTransaction();
   mc.close();
}

When you paste the wall of code:

MyConnector mc=...;
Session s=mc.beginTransaction();
AppData appData=mc.getObjectFromTable(...);
appData.someValue=x;
s.save(appData);
s.endTransaction();
mc.close();

to any other methods, every methods can also change the value of someValue.

Just because the code to trigger "everyone can modify the state" is longer or even has better name than "AppData.someValue = x" doesn't change the nature of the code that lets everyone can modify the state.

To differentiate database from global states, I think we should wrap and apply dependency injection to the database driver:

public void myMethod(MyConnector mc){
   Session s=mc.beginTransaction();
   AppData appData=mc.getObjectFromTable(...);
   appData.someValue=x;
   s.save(appData);
   s.endTransaction();
   mc.close();
}

so that not every methods can access to database, same as the case of accessing global variables that inject the object only when a method needs to change it.

So my question is, why does "a consistent, understandable interface" differentiates database from global states, even I can paste the "a consistent, understandable interface" code everywhere to let anyone modify the global state, just like global variables?

According to some answers of How are globals any different from a database? that explains how database is different from global state:

https://softwareengineering.stackexchange.com/a/319389/432039 https://softwareengineering.stackexchange.com/a/319403/432039 https://softwareengineering.stackexchange.com/a/319399/432039

as I understand, the answers roughly explains accessing to database using "a consistent, understandable interface" code is different from accessing a global variable. However, what I don't understand is, how a "a consistent, understandable interface" code differentiates from accessing global variables? For example, when accessing global variables:

public void myMethod(){
   AppData.someValue = x;
}

the global state is eval because you can paste "AppData.someValue = x" in any other methods, resulting everyone can modify the state.

When changing the access way from global state to database:

public void myMethod(){
   MyConnector mc=...;
   Session s=mc.beginTransaction();
   AppData appData=mc.getObjectFromTable(...);
   appData.someValue=x;
   s.save(appData);
   s.endTransaction();
   mc.close();
}

When you paste the wall of code:

MyConnector mc=...;
Session s=mc.beginTransaction();
AppData appData=mc.getObjectFromTable(...);
appData.someValue=x;
s.save(appData);
s.endTransaction();
mc.close();

to any other methods, every methods can also change the value of someValue.

Just because the code to trigger "everyone can modify the state" is longer or even has better name than "AppData.someValue = x" doesn't change the nature of the code that lets everyone can modify the state.

To differentiate database from global states, I think we should wrap and apply dependency injection to the database driver:

public void myMethod(MyConnector mc){
   Session s=mc.beginTransaction();
   AppData appData=mc.getObjectFromTable(...);
   appData.someValue=x;
   s.save(appData);
   s.endTransaction();
   mc.close();
}

so that not every methods can access to database, same as the case of accessing global variables that inject the object only when a method needs to change it.

So my question is, why does "a consistent, understandable interface" differentiates database from global states, even I can paste the "a consistent, understandable interface" code everywhere to let anyone modify the global state, just like global variables?

Source Link
wcminipgasker2023
  • 2.7k
  • 1
  • 14
  • 29

Why does "a consistent, understandable interface" differentiates database from global states?

According to some answers of How are globals any different from a database? that explains how database is different from global state:

https://softwareengineering.stackexchange.com/a/319389/432039 https://softwareengineering.stackexchange.com/a/319403/432039 https://softwareengineering.stackexchange.com/a/319399/432039

as I understand, the answers says accessing to database uses "a consistent, understandable interface" code, which is different from accessing a global variable. However, what I don't understand is, how a "a consistent, understandable interface" code differentiates from accessing global variables? For example, when accessing global variables:

public void myMethod(){
   AppData.someValue = x;
}

the global state is eval because you can paste "AppData.someValue = x" in any other methods, resulting everyone can modify the state.

When changing the access way from global state to database:

public void myMethod(){
   MyConnector mc=...;
   Session s=mc.beginTransaction();
   AppData appData=mc.getObjectFromTable(...);
   appData.someValue=x;
   s.save(appData);
   s.endTransaction();
   mc.close();
}

When you paste the wall of code:

MyConnector mc=...;
Session s=mc.beginTransaction();
AppData appData=mc.getObjectFromTable(...);
appData.someValue=x;
s.save(appData);
s.endTransaction();
mc.close();

to any other methods, every methods can also change the value of someValue.

Just because the code to trigger "everyone can modify the state" is longer or even has better name than "AppData.someValue = x" doesn't change the nature of the code that lets everyone can modify the state.

To differentiate database from global states, I think we should wrap and apply dependency injection to the database driver:

public void myMethod(MyConnector mc){
   Session s=mc.beginTransaction();
   AppData appData=mc.getObjectFromTable(...);
   appData.someValue=x;
   s.save(appData);
   s.endTransaction();
   mc.close();
}

so that not every methods can access to database, same as the case of accessing global variables that inject the object only when a method needs to change it.

So my question is, why does "a consistent, understandable interface" differentiates database from global states, even I can paste the "a consistent, understandable interface" code everywhere to let anyone modify the global state, just like global variables?