Referential Transparency and Interchangeability

Being had spent hours trying to grasp referential transparency, I am finally inclined to regard this concept as confusing one rather than helpful. But maybe the problem is me…

Usually referential transparency is mentioned with regard to a function which can be replaced with another function by a compiler with the aim of incresing effectivenes in some way (let’s restricted ourselves to "functions" in common programming languages sense here).

So what’s the condition to be met to make possible this "replacement"? Let’s consider the line given by cody:

Referential transparency is an operational notion: it describes what happens when you evaluate a same piece of code (typically a function) several times, namely, the return value is the same. In particular, the evaluation context can generally be ignored when considering the operational semantics of a referentially transparent language.

In other words, if a couple of functions always return the same value for the same argument(s), so they are interchangeable (and if they both do not affect "external world" (have no side effects) – otherwise it is supposed a compiler will not able to make the replacement).

Question #1: Is the concept of referential transparency only applicable to pure functions? If so, why is it?

For example, in terms of some logical system (let’s refer this to a specification of some type of compiler or programming language, etc.) these two pretty non-pure functions can be considered interchangeable:

function DoSmthOdd1 (x) {    launchSpaceX(); //a side effect   var sum = K + x; // K is an external variable   return sum; }  function DoSmthOdd2 (x) {   var sum = x + K;   launchSpaceX();    return sum; } 

Our logical system is not interested in the order an expression written by a programmer and it does not get frightened when an external variable is used "in the same (specified) way", so the compiler can replace DoSmthOdd1 with DoSmthOdd2. In the other hand, the very same logical system prescribes that the compiler must not replace two pure functions (of kind of "the same argument – the same return value") if they have different algorithm complexity (for e. g.).

Let’s deem function equality to be interchangeability of two or more functions (= possibility to be replaced with each other) within the framework of a logical system. Then:

Question #2: Is referential transparency another word for conveing meaning of function equality (interchangeability) and with the only possible "the same argument – the same value" rule at that?

The issue is function equality is a binary relationship whereas referential transparency pretends to be an unary one. I can give an example of pure function (pure per se), but what is a (non-)referentially transparent function (if we consider it per se without making a comparsion with other functions)?

There is an example in the Expert Systems: Principles and Programming by Giarratano, Riley:

sum := f(x) + x; // f(x) changes the value of x passed by reference 

The authors claim this function to be a non-rf because

  • Depending on how the compiler is written value of x might be the original value if it was saved on a stack, or the new value if x was not saved.
  • If one compiler evaluates expressions right to left while another evaluates left to right. In this case, f(x) + x would not evaluate the same as x + f(x) on different compilers.

But wait… all the above is just comparsion of different logical systems ("compilers"). In standard algebra f(x) + x and x + f(x) are equivalent and interchangeable but in the specification of our compiler they are not. So why do we need this analogy at all?

Question #3: Is it true that a function is referentially transparent if it can be replaced in the same way how it can be done in algebra?

HTTP Public Key Pinning vs Certificate Transparency, which is better and why?

We are rolling out a new mobile app. Our security team recommends us to pin the public key in order to avoid MITM. iOS already has CT checks and we can enable that for the Android app as well.

The security team’s arguments for pinning are:

  1. Pinning is a more hardened solution
  2. CT is more reactive, we might have to live with a rogue certificate until it is revoked and logged in CT logs
  3. CT checks would not work in environments where corporate assets may have company PKI deployed and MITM attack is done using the company PKI

My argument for not pinning: Assume we generate a certificate and it is a 2048-bit RSA key pair. The certificate expires in 1 year, maybe 2. We go to the CA for a new certificate and the CA says “No, your key is too small, come back with a 4096 RSA key pair”. In effect, because we pinned the public key in the app, the app is bricked.

Now we release a new version of the app, but it takes typically > 1 month for the app to be adopted by all the customers. During this time, while our customers are trying to access the app at home, trying to look for offers to come and spend money in our ecosystem, they won’t be able to use the app and hence we stand to lose the customer and potential revenue.

A rogue certificate might affect 1, maybe 2 customers if someone is really being targeted to be hacked (MITM target), but the above risk is a risk to the entire customer base and for amount of time that is not directly quantifiable.

Does it really makes sense to pin? If yes, how do we mitigate the above scenario? Am I not seeing something?

SharePoint Theme Background Transparency

I selected the “Wood” theme for a SharePoint site created in SharePoint Online, and noticed that the backgrounds that appear to be transparent in the preview are actually opaque.

Here is the preview. Note the transparent backgrounds on the side menu and main content, and partially transparent top menu:

Preview

Now, after selecting the theme and navigating to the main page, I see the following. Observe that the side menu, top bar, and background of the news section are opaque, when I would expect them to be transparent or translucent based on the preview:

Opaque Background

Interestingly, the backgrounds appear correct when I navigate to the Site Settings page:

Site Settings

I’ve tried this in both Chrome and Edge, and have also tried other themes that use transparent backgrounds. The effect is the same on all of them. Any ideas on how to resolve this?

How to disable certificate transparency check in macOS Mojave(10.14)

In macOS Mojave, certificate transparency check is enabled. Because the OS terminates all TLS connections that doesn’t use transparent certificates, macOS Mojave cannot connect to WPA2 Enterprise corporate networks. Is there any solution to turn off certificate transparency check for one special certificate or for all certificates?

why isn’t glass transparency part of the exposure calculation?

The F number is a ratio calculated purely from the focal length of the lens and the size of the aperture. Any light meter talks in terms of F, Shutter, and ISO.

Different glass, or just different number of elements, is going to change the number of photons that get though the lens; we compensate for ND filters by adjusting F. What am I missing? Why aren’t t stops part of exposure calculations?

What does “This request does not comply with Chrome’s Certificate Transparency policy.” in Chrome’s Security Tab mean?

When you open up Chrome’s DevTools and switch to the Security Tab you’ll see the message This request does not comply with Chrome's Certificate Transparency policy. on some origins. (Example: https://de.ioam.de when you visit https://www.sportschau.de/index.html)

I know the concept of Certificate Transparency in general but I neither know what Chrome's Certificate Transparency policy is nor do I know what the impact of this statement is.

Obviously Chrome establishes the https connection to this host, but what’s wrong here?

Will https connections to affected origins be blocked in the future?

How to have a background with transparency with constraint layout and cardview? [pendente]

So I want to have a card view inside a constraint layout that provides a transparence background. The problem is that my dialog is putting the default transparence and putting the background I am giving to him behind only the card view messing me up the corner radius from the card view as you can see on the image bellow that contains arrows for the background behind the card view

So I want to achieve something like this

inserir a descrição da imagem aqui

So this is the XML code I have

<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:id="@+id/vConfirmationDialog"     android:background="#80000000"     android:layout_width="match_parent"     android:layout_height="match_parent">       <androidx.cardview.widget.CardView         android:id="@+id/cardView5"         android:layout_width="271dp"         android:layout_height="wrap_content"         android:layout_marginTop="8dp"         app:cardCornerRadius="20dp"         app:layout_constraintBottom_toBottomOf="parent"         app:layout_constraintEnd_toEndOf="parent"         app:layout_constraintStart_toStartOf="parent"         app:layout_constraintTop_toTopOf="parent">           <androidx.constraintlayout.widget.ConstraintLayout             android:layout_width="match_parent"             android:layout_height="match_parent"             android:layout_margin="16dp">               <Button                 android:id="@+id/confirmButton"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_marginTop="8dp"                 android:background="@drawable/selector_button_green_round"                 android:text="OK"                 android:textColor="@color/blank"                 app:layout_constraintBottom_toBottomOf="parent"                 app:layout_constraintEnd_toEndOf="parent"                 app:layout_constraintHorizontal_bias="0.5"                 app:layout_constraintStart_toEndOf="@+id/cancelButton"                 app:layout_constraintTop_toBottomOf="@+id/textView5" />              <TextView                 android:id="@+id/textView5"                 android:layout_width="0dp"                 android:layout_height="wrap_content"                 android:layout_marginStart="8dp"                 android:layout_marginEnd="8dp"                 android:gravity="center_horizontal"                 android:text="@string/are_you_sure_you_want_to_invest"                 android:textColor="#0a0f35"                 android:textSize="20sp"                 app:layout_constraintEnd_toEndOf="parent"                 app:layout_constraintStart_toStartOf="parent"                 app:layout_constraintTop_toTopOf="parent" />              <Button                 android:id="@+id/cancelButton"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_marginStart="8dp"                 android:layout_marginTop="8dp"                 android:layout_marginEnd="8dp"                 android:background="@drawable/selector_button_green_white"                 android:foregroundTint="@color/colorIban"                 android:text="Cancel"                 android:textAllCaps="false"                 android:textColor="@color/colorIban"                 app:layout_constraintBottom_toBottomOf="parent"                 app:layout_constraintEnd_toStartOf="@+id/confirmButton"                 app:layout_constraintHorizontal_bias="0.5"                 app:layout_constraintStart_toStartOf="parent"                 app:layout_constraintTop_toBottomOf="@+id/textView5" />         </androidx.constraintlayout.widget.ConstraintLayout>      </androidx.cardview.widget.CardView>  </androidx.constraintlayout.widget.ConstraintLayout> 

This is my generic method to call any dialog fragment

fun Fragment.showDialog(fragment: DialogFragment, tag: String) {     val ft = fragmentManager?.beginTransaction()     val dialog = fragmentManager?.findFragmentByTag(tag) as? DialogFragment     dialog?.let {         ft?.remove(dialog)     }     ft?.addToBackStack(null)     fragment.show(ft, tag) } 

This is the method that call the dialog on button click

showDialog(ConfirmationDialog.newInstance(), ConfirmationDialog.TAG) 

And this is my Dialog class

class ConfirmationDialog: DialogFragment() {      companion object {         const val TAG = "CONFIRMATION_DIALOG"         fun newInstance() = ConfirmationDialog()     }      override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,                               savedInstanceState: Bundle?): View =             inflater.inflate(R.layout.dialog_confirmation, container, false)      override fun onViewCreated(view: View, savedInstanceState: Bundle?) {         super.onViewCreated(view, savedInstanceState)     }  }