Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downside to transparent structs?

Tags:

struct

racket

I've noticed that the structs in Racket are not transparent by default. This seems odd to me as in my (limited) experience when you want to see the value of something, you would like to view its contents! Specifically, I am referring to using the #:transparent keyword/mechanism when defining a struct.

Why would Racket have structs be opaque by default? My only guess is that they are preventing displaying too much content to the console in the event that you are displaying or evaluating a very large struct for some reason.

like image 248
BlackVegetable Avatar asked Feb 24 '14 17:02

BlackVegetable


1 Answers

From the docs, it seems like structs are opaque by default to encourage more modular programs. When transparent structs are provided, they automatically leak their internal representation.

Structure types are opaque by default, because opaque structure instances provide more encapsulation guarantees. That is, a library can use an opaque structure to encapsulate data, and clients of the library cannot manipulate the data in the structure except as allowed by the library.

like image 53
stchang Avatar answered Sep 28 '22 09:09

stchang