0Pricing
Mojo Academy · レッスン

コピーと共有状態

変更が他へ波及する場合としない場合を学びます

「コピーと共有状態」はCoddyKit上の無料Mojo Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはMojo Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Mojo Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

When Do Changes Spread?

Sometimes editing one variable also edits another, and sometimes it does not. The difference is copy versus shared state. 🔍

A Copy Is Self-Contained

When you get a copy, you hold separate data. Editing it cannot reach back and disturb the value you copied from.

var a = 1
var b = a
b = 2

Shared State Is One Thing, Two Names

With shared state, two variables point at the same underlying data. A change through one is visible through the other.

The Telltale Sign

Ask: after I edit one variable, did the other one change too? If yes, they shared; if no, you had a copy.

Mojo Copies By Default

For value types, Mojo gives you a copy on assignment. So in everyday code, changes stay nicely contained.

var first = 7
var second = first
second = 8

Structs Copy Their Fields

Copy a struct and you copy each field inside it. The new struct is fully independent from the original.

Why Sharing Causes Surprises

Shared state means a distant edit can silently change your value. That spooky action at a distance is a classic source of bugs.

Sharing Has Its Uses

Sharing is not evil; sometimes you want one source of truth. The key is to choose it on purpose, not by accident.

Reading Code With This Lens

When you see an assignment, picture whether it makes a copy or a link. That habit predicts how edits will travel.

var original = 50
var backup = original

A Quick Comparison

Copy: edits stay put. Shared: edits ripple. Mojo's default leans toward copies, so ripples are the exception, not the rule.

Independence You Can Trust

Knowing copies are independent lets you change a value boldly, sure that other parts of your program stay stable. ✅

Quick Check

Two variables point at the same underlying data. You edit one. What do you expect?

Recap

A copy keeps edits contained; shared state lets them ripple. Mojo copies value types by default, so surprises are rare. 🎯

よくある質問

「コピーと共有状態」レッスンは無料ですか?

はい。「コピーと共有状態」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Mojo Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Mojo Academyコースには全4レッスンが含まれています。

「コピーと共有状態」で何を学びますか?

変更が他へ波及する場合としない場合を学びます ブラウザで直接実行するハンズオンコードでMojo Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Mojo Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのMojo Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。

「コピーと共有状態」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このMojo Academyレッスンでコードを書いて実行できますか?

はい。すべてのMojo Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. 値セマンティクスとは
  2. コピーと共有状態
  3. Mojoの安全なデフォルト
  4. ミューテーションの基本
← Mojo Academyに戻る