Comments (10)
whoops, accidentally submitted. I was gonna put together a more comprehensive proposal for immutable classes along the lines of #9, but it's getting late 😅 I'll do it soon
from fut.
@jedwards1211 I'd be very interested in this. I tried to translate a Typescript interface into Cito, and, well, it wasn't pretty...
from fut.
Yeah, maybe this is what you meant, but I think that code won't work, since you can't assign to object storage with =. You would need a set
method on each class that takes a readonly pointer to another instance and copies its values.
from fut.
@jedwards1211 I really just want something like structs; I read the other thread and I understand the concerns about structs and shared library compatability, but it sounded like you had something in mind to solve this?
from fut.
Possibly, I was just proposing an option to take the risk of library incompatibility on a class I'm confident I won't need to add or remove fields from.
But using a pointer to implementation would be another option that would enable more convenient code without that risk. The downside is it requires heap allocation. But maybe that's not so bad since all objects in most other languages besides C/C++ are allocated on the heap anyway...makes me curious if using shared pointers for everything in C++ performs better or worse than doing the same thing in a garbage collected language. I'm not sure that heap allocation in C++ can recycle objects as efficiently as sophisticated garbage collectors can?
from fut.
Also googling about smart pointers vs GC reminded me of something I had forgotten: smart pointers can't clean up cyclic garbage. You have to break the cycle manually for that memory to be freed. 😳
from fut.
I would definitely want to be able to use structs too for a case like yours, but nothing is easy in C/C++land... 😅
from fut.
I would definitely want to be able to use structs too for a case like yours, but nothing is easy in C/C++land... 😅
Well, that's exactly it, it WAS easy in C/C++ if you didn't have to worry about incompatilibility. I would have thought the risks were rather low here, but I suppose in the world of linux where libaries aren't bundled and get updated out-of-band, this could be a big hassle. I hope a solution can be found here, because trying to create union types is a huge pain in cito.
from fut.
I hope a solution can be found here, because trying to create union types is a huge pain in cito.
No idea what the solution should be for, as this is a closed, blank ticket. 😊
smart pointers can't clean up cyclic garbage. You have to break the cycle manually for that memory to be freed.
Typically one object owns another. The owned object typically doesn't delete the owner because that way it could delete self. So if the owned object needs a reference to the owner, it can be a regular reference which doesn't need to be broken manually when the owner is deallocated.
Very often you could have the owned object be an object storage field in the owner. Again, a cyclic reference poses no problem for deallocation.
Swift has the unowned
keyword, with all object references being reference-counted by default.
from fut.
Typically one object owns another. The owned object typically doesn't delete the owner because that way it could delete self. So if the owned object needs a reference to the owner, it can be a regular reference which doesn't need to be broken manually when the owner is deallocated.
Yeah it's definitely the common case. I may end up writing code to operate on potentially cyclic graphs in some of my projects though, and if I hadn't learned it could leak memory, I bet I would have ended up naively using dynamic references between nodes. I think it would be worth warning devs who are only familiar with garbage-collected languages.
from fut.
Related Issues (20)
- Implement a language server for Fusion
- `#include <stdio.h>` in `native` blocks doesn't work HOT 1
- Correctly generate the main function for C/C++ HOT 3
- Reference example of Dictionary is not working HOT 1
- Transpile to Golang HOT 2
- Regex C++ issue smatch vs cmatch HOT 1
- Thoughts on expanding the standard lib HOT 3
- JSON parsing support HOT 14
- WIP: Support for starting child processes and reading output
- Emit compiler directives based on language being compiled HOT 6
- Allow delegates / anonymous functions HOT 6
- Promise / Callback Types (Instead of async/await?) HOT 3
- String Comparisons HOT 1
- Revisiting ICU dependency HOT 4
- What is the ref-code in the Playground examples, if C/C++ were supposed to not have GC? HOT 22
- Is there some mailing list, forum, Element/Matrix chat or something for communication? HOT 6
- What exactly guarantees that all of the produced codes have exactly the same behavior? HOT 7
- syntactic sugar for getters/setters HOT 1
- Duplicated symbol error reported on wrong line HOT 1
- false positive error inside #if condition? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fut.