2022/09,江端さんの技術メモ

Goにはクラスの概念がありません。

C++で作ってきたプログラムをGoに移植しているのですが、クラスで記載した部分を上手いこと使い回したくても、それができなくて困っていました。

で、

GO言語でクラスっぽいことをする

という記事を見つけて、これを使って勉強させて頂いていますが、困ったことがあります。

プログラムの中の変数の意味が分からない ―― HPとか、MPとか、APは、アニメ(多分ゲームも?)の中では頻繁に登場するのですが、私は何の略号か分からなかったので、サンプルプログラムの意味が読み解けませんでした。

そこで、上記記事に記載されていたプログラムに、そのまま、私の為に、コメントを付けさせて頂きました。

package main

import (
	"fmt"
)

const line = "--------------------"

func main() {
	wiz := newWizard("魔法少女", 10, 10, 5)
	war := newWarrior("+‡†狂戦士†‡+", 10, 15, 30)

	fmt.Println(wiz.hello())
	fmt.Println(war.hello())

	fmt.Println(line)
	fmt.Println(wiz.attack())
	fmt.Println(war.attack())

	fmt.Println(line)
	fmt.Println(wiz.magic())
	fmt.Println(war.attack())
}

type human struct { // "人間"という基底クラス
	name string
	hp   int
	ap   int
}

func (h *human) init(name string, hp, ap int) { // "人間"という基底クラスのコンストラクタ(3つの初期値を入れていることに注意))
	h.name = name // 名前
	h.hp = hp     // ヒットポイント: ゲームにおいてキャラの体力や生命力を示すステータスの一つ
	h.ap = ap     // アタックポイント: ゲームにおいてキャラの行動力などを示すステータスの一つ
}

func (h *human) hello() string { // "人間"という基底クラスのメソッド1
	return fmt.Sprintf("こんにちは、私は%sです。", h.name)
}

func (h *human) attack() string { // "人間"という基底クラスのメソッド2
	return fmt.Sprintf("%sの攻撃!%dのダメージ!", h.name, h.ap)
}

type wizard struct { // "魔法使い"というクラス
	human     // "人間の属性"を手動挿入
	mp    int // マジックポイント: ゲームにおいてキャラの魔法や呪文を使う力を示すステータスの一つ
}

func newWizard(name string, hp, ap, mp int) *wizard { // "魔法使い"クラスのコンストラクタ(4つの初期値を入れていることに注意))
	w := new(wizard)     // "魔法使い"の実体生成
	w.init(name, hp, ap) // "基底クラス"の属性値の設定
	w.mp = mp            // 新しい属性値の設定
	return w
}

func (w *wizard) magic() string {
	if w.mp <= 0 {
		return fmt.Sprintf("%sは力がでない", w.name)
	}
	w.mp -= 1
	return fmt.Sprintf("%sは魔法を使った!30のダメージ!", w.name)
}

type warrior struct {
	human // "人間の属性"のみを手動挿入
}

func newWarrior(name string, hp, ap, mp int) *warrior {
	w := new(warrior)
	w.init(name, hp, ap)
	// mpは使わない? Warrior(戦士)は、マジックポイントを持たないものなの?
	return w
}

func (w *warrior) attack() string {
	return fmt.Sprintf("%sの攻撃!%dのダメージ!", w.name, w.ap*2)
}

なるほど、変数の意味が分かれば、プログラムの趣旨が読み取れました ―― 加えて、アニメの中の台詞も理解できるようになり、一石二鳥でした。
ゲームをやっている人であれば、「今更なこと」だったんだろうな、と思っています。


とほほのGo言語入門 構造体(struct)

を読んでいたら、構造体(struct)でクラスと同じことができることが分かりました。

また、インタフェース(interface)を使えばポリモーフィズムもできるみたいでした。

しかも、コンストラクタとかデストラクタとか、面倒なものもを入れていないという点も好印象です。

Golangの設計者、よく分かってるじゃん!』と、絶賛賞賛中です。

2022/09,江端さんの忘備録

私は、「撤収」が、超高度な技術であることを知っています。

I know that "Withdrawal" is a super advanced technology.

"技術"に留まらず、"哲学"である、とすら思っています。

I believe that it is not only a "technique" but also a "philosophy".

そのようなマインドを持っている私にとって、

For me, with that kind of mindset,

■NHK「解体キングダム」

- NHK program "Kaitai Kingdom"

■Nスペ「廃炉への道」

- NKS Special "The Road to Decommissioning."

は、手に汗握るスリルに満ちた貴重なコンテンツです。

are valuable contents full of thrills.

-----

我が国は、原爆被害、原発事故など、いわゆる「"核災害"先進国」です。

Japan is an advanced country in terms of nuclear disasters, including atomic bombings and nuclear accidents.

しかし、同時に、これらの不幸な災害は、我が国の"核"災害対策の技術を高めていると思います。

At the same time, however, I believe that these unfortunate disasters have enhanced our nation's "nuclear" disaster preparedness techniques.

私は、システム屋として、『事故を起こさないシステムなど、絶対的な意味において「ない」』という事実を知っています。

As a systems engineer, I know for a fact that 'there is no such thing as an accident-free system' in the absolute sense of the word.

ですから、これからも、世界中で、核の事故は続きます。

New "nuclear" accidents will continue to occur in the world.

なぜなら、当面の間、人類が「核」を手放せる目処がない以上、「核」の事故は必ず発生するからです。

This is because, as long as humanity has no prospect of giving up "nuclear" in the foreseeable future, nuclear accidents are bound to occur.

以下は、「原発事故発生"10億年に1回"とは、笑わせる」を図解したものです。

The following is an illustration of the "1 in a billion years" accident rate, which make me laugh.

米国(スリーマイル)、ソ連、あらためロシア(チェルノブイリ、改めチョルノービリ)、日本(福島)、と、これまで「大事故」と断定できるものは3回ありました。

There have been three major accidents in the United States (Three Mile), in Russia changed the Soviet Union(Chernobyl, and in Japan (Fukushima).

今度は、どこか?

"Where is the next?"

直感の域を出ませんが、国外であれば、我が国の近隣国がヤバい気がします。

It is just my imagination, I am concern that that our nearby countries will be in trouble.

-----

という訳で、解体や廃炉に特化した技術、さらには、それを日常生活から国家の政策にまで適用可能な、一般的思想(哲学)にまで高めた総合的な学問としての、

Therefore, not only as technologies for demolition and decommissioning a nuclear reactor, but also, as comprehensive study to be general thoughts (or philosophy) which apply for From everyday life to state policy, I will propose

『撤収学』

"Withdrawal Study"

の設立を提案したいと思います。

「XX大学工学部撤収学科」、とか、「XX大学経済学部撤収学科」、という称呼が一般的になって欲しいです。

I would like to see the term "XX University, Faculty of Engineering withdrawn" or "XX University, Faculty of Economics withdrawn" become more common.

2022/09,江端さんの忘備録

マッチョな体になって、女性にモテたい、という心理は、私の人生で、1ナノ秒も登場したことがありません。

上記を経て、「江端マッチョ化計画」・・・もとい、「江端介護向け身体改造計画」を進めております。

Through the above, I am proceeding with the "Ebata Machoization Plan"...or rather, the "Ebata Body Modification Plan as a caregiver".

観点は、以下のような感じです。

The viewpoints are as follows.

(0)外出(フィットネスセンターなど)が面倒くさい。

(0) Going out (e.g., to a fitness center) is a hassle.

(1)バーベルやダンベル等のごっついデバイスは、いずれ「漬物石」になる

(1) Burly devices such as barbells and dumbbells will eventually become "pickle stones".

(2)トレーニングマシンは、置く場所がない上に、とても高価。

(2) Training machines are very expensive as well as there is no place to put them.

(3)基本的に私が欲しいものは、腹筋運動や背筋運動を手伝ってくれる「補助」

(3) Basically what I want is an "assistant" to help me with abdominal and back exercises.

てなことを考えているうちに ―― 昨日衝動的に「買っちった」

I was thinking about it -- I impulsively "bought it" yesterday.

-----

鉄棒(懸垂)はルティーン化できたのですが、この腹筋・背筋運動を含めることができるか、今後の課題です。

I was able to lutinize the bars (pull-ups), but it remains to be seen if I can include these abdominal and back exercises.

2022/09,江端さんの技術メモ

Golangで "OpenError: sql: unknown driver "postgres" (forgotten import?) "で悩まされていました。

よく分かりませんが、"go.mod", "go.sum"とかをいじることなく

(1)ターミナルから、

go get github.com/lib/pq

として、

(2)import に

import (
   //  色々
    _ "github.com/lib/pq" // ←これを追記
)

で動きました。

2022/09,江端さんの忘備録

ロシアのウクライナ侵攻以来、小説の中の話が、現実でもちゃんと使えるんだ、ということを実感する日々です。

Since Russia's invasions of Ukraine, I have been realizing that fiction stories in novels can be used properly in real life.

1つ目は、『核抑止力』というものが、それなりに機能しているという事実です。

First of all, the fact is that "nuclear deterrence" is working to a point.

現時点で、ロシアもNATOも、核兵器を使用していません。

At this time, neither Russia nor NATO uses nuclear weapons.

正直、私は、「戦略核」の使用はないとしても、「戦術核」はありえるのではないか、と危惧していましたし、今も危惧し続けています。

Frankly speaking, I have feared and continue to fear that even if "strategic nuclear weapons" are not used, "tactical nuclear weapons" are possible.

-----

2つ目は、新しい"核"兵器としての原発の利用 --- 『原発(原子力発電所)攻撃』です。

Secondly, a new nuclear weapon using nuclear power plants --- "nuclear power plant attack"

今も続く、ロシアによる原発攻撃(*)によって、世界中が震撼しているのはご存知の通りです。

As you know, the world is still shaken by the ongoing Russian attack on nuclear power plants(*).

(*)ロシアは、「ウクライナによる攻撃」と主張

(*) Russia claims "attack by Ukraine

私は、日本国民が、『電力を作り出す原発』が『常時電力を供給し続けなければ、とんでもないことになる』ことを、心底から理解できている、世界唯一の国である、と信じています。

I believe that the Japanese are the only people in the world who truly understand that "nuclear power plants," which produce electricity, "would be in serious trouble if they did not constantly supply power".

もちろん、これは、福島原発事故の、あの「全電源消失」のことです。

Of course, this refers to the "total loss of power" of the Fukushima nuclear accident.

この『原発(原子力発電所)攻撃』というのは、『原爆(原子爆弾)開発』と比べて、おろそしく簡単で、ウルトラ低コストです。

This "attack on nuclear power plants" is ludicrously easy and ultra-low cost compared to "developing atomic bombs".

原子炉本体を攻撃する必要もなく、送電網の破壊だけで足ります -- 『破壊工作員、数人程度』で十分いけるんじゃないかな、思います。

There is no need to attack the reactor itself, only to destroy the power grid -- "a few saboteurs" should be enough.

本当に「想定外」なのですか?(2011-03-29の日記)

-----

このように、戦略核 -> 戦術核 -> 原発攻撃 と -----

Thus, strategic nuclear weapons -> tactical nuclear weapons -> nuclear power plant attack,

私たちは、「核廃絶」どころか、3つめの核兵器を「発見」してしまったのだなぁ、と実感しています。

I realize that we have not "abolished" nuclear weapons, but rather "discovered" a third nuclear weapon.

2022/09,江端さんの忘備録

最近、長女が、ロシアによるウクライナ侵攻を見て、真剣に国防を考え出しているようで、大変、興味深いです。

It is very interesting that my senior daughter has recently started to seriously consider national defense after seeing the Russian invasion of Ukraine.

# 正確に言うと『国防』ではなくて『逃亡』ですが。

# To be precise, it's not 'national security' but 'escape'.

―― どこに逃げればいいの?

"Where to escape?"

と、真剣に心配しています。

She is seriously concerned.

-----

「我が国(日本)が、今後、どういう流れで戦争に巻き込まれていくか」 ―― というシミュレーションは、私にとっては、大好物のネタですので、そのいくつかのシナリオを長女に語りました。

Simulations of how our country (Japan) might be drawn into a war in the future are a favorite topic of mine, so I told her about some of the scenarios.

昨夜は、これに加えて、「ロシアから見た正義」と「中国から見た正義」についても解説してみました。

Last night, in addition to this, I also explained "justice from the Russian point of view" and "justice from the Chinese point of view".

―― 彼らには、彼らなりの、戦争をしかけるだけの正当な理由がある

"They have their own, justifiable reasons for starting a war"

という私の話が、長女を、さらに不安にさせているようです。

The stories of mine seemed to make her more anxious.

それはさておき。

Aside from that.

-----

以前、私は、長女と次女の近代歴史知識の乏しさを批判し、逆に論破されたことがあります。

I once criticized my daughters for their lack of modern historical knowledge, and was rebutted.

「いや、『四人組』とか『文革』とか、嫌な話がテンコ盛りでしょう?」(2017-04-15 の日記)

実際に、歴史の教師は「歴史が重要だ」と言い続けていますが、はっきり言います―― 「古代エジプトのファラオが誰であろうか、その国が滅びようが、それが何だと言うのか」

一方、嫁さんの方は、近年「忠臣蔵」のドラマが放送されていないことに、重大な危機感を感じているようです。

On the other hand, my wife feels a serious sense of crisis over the fact that no "Chushingura" dramas have been broadcast in recent years.

『日本人から、「忠臣蔵」の精神が失われたら、どうするんだ』と。

"What if the spirit of Chushingura is lost from the Japanese people?"

私は、こちらについては、心底"どーでもいい"と思っています。

I am truly "not concerned" about this.

しかし、以前『徒党を組んだ地方浪人による、テロ事件』と語った時に、もの凄く怒られたので、黙っています。

However, my wife was extremely angry with me when I told her that it was "a terrorist attack by local ronin who formed a clique," so I have kept my mouth shut.

-----

私たちは、自分なりの価値観で、その価値観を他人にも理解して欲しいと考えますが ――

We have our own set of values, and we want others to understand those values, but--

結局のところ、そういう試みの多くは、『無駄』に終わります。

After all, such attempts will be in vain.

2022/09,江端さんの技術メモ

golangを使った、postgresqlのinsertの方法

/*

こんな感じで、DBとTableを作りました

create database agent_db;

create table LocMessage(
	ID     int,
	Lat    double precision,
	Lng    double precision,
	TYPE   varchar(10),
	POPUP  int,
	RealId int,
	PersonState      int,
	BikeState        int,
	StartStationLat  double precision,
	StartStationLng  double precision,
	GoalStationLat   double precision,
	GoalStationLng   double precision,
	StartStationName varchar(40),
	GoalStationName  varchar(40)
);

ちなみに、全部小文字になるみたいですねえ。
agent_db=# select * from locmessage;
 id |  lat   |  lng  |   type   | popup | realid | personstate | bikestate | startstationlat | startstationlng | goalstationlat | goalstationlng | startstationname | goalstationname
----+--------+-------+----------+-------+--------+-------------+-----------+-----------------+-----------------+----------------+----------------+------------------+-----------------

*/

package main

import (
	"database/sql"
	"log"

	_ "github.com/lib/pq"
)

func main() {

	db, err := sql.Open("postgres",
		"user=postgres password=password host=localhost port=15432 dbname=agent_db sslmode=disable")
	if err != nil {
		log.Fatal("OpenError: ", err)
	}
	defer db.Close()

	//_, err = db.Exec("insert into locmessage(id,lat,lng,type,popup,realid,startstationlng ) VALUES(1, 139.0, 38.0, 'PERSON',1,1,222.222);")
	// _, err = db.Exec("insert into locmessage(id,lat) VALUES(a, b);")
	//ins, err := db.Prepare("insert into locmessage(id,lat,lng,type,popup,realid,startstationlng ) VALUES(?,?,?,?,?,?,?)")
	ins, err := db.Prepare("insert into locmessage(id,lat,lng,type,popup,realid,startstationlng ) VALUES($1,$2,$3,$4,$5,$6,$7)")
	if err != nil {
		log.Fatal("db.Exec Error: ", err)
	}

	a := 1
	b := 139.02
	c := 38.02
	dd := "Tomoichi"
	e := 1
	f := 1
	g := 333.333

	//ins.Exec("1", "139.0", "38.0", "BIKE", "1", "1", "222.222")
	//ins.Exec(1, 139.01, 38.01, "BIKE", 1, 1, 222.222)
	//ins.Exec(1, 139.0, 38.0, 1, 1, 1, 222.222)
	ins.Exec(a, b, c, dd, e, f, g)

}

とりあえず、これでデータベースの書き込みはできるみたい。

2022/09,江端さんの忘備録

「オリジナル原稿購読希望」をされる方が、止まりません。

The "original manuscript subscription applicants" are coming even now.

―― 『とある宗教団体』を直撃する内容

今ごろになって、『もし、期待外れだったら、どうしよう』と心配になってきました。

By now, I'm starting to worry, 'What if it's a disappointment for them?'

私は、「この内容なら大丈夫」と勝手に判断したもので、そんなに、凄い内容とは思っていなかったものなのです。

I had judged on my own that the content would be OK. and I did not think it would be that great.

(但し、編集部は"削除"を、嫁さんは"休載"を、要求する内容ではあったようですが)

(However, it seems that the editorial department demanded "deletion" and the wife demanded "suspension of publication.)

―― この教団に関する本(教義も含む)を数冊読めば、誰でも分かる程度の内容

"Enough for anyone to read a few books on this cult (including its doctrines)"

です。

―― 宗教団体のネタにコメントすると、面倒くさいことになる

(応募者が0人が、連続2日を経過した段階で、配布を予定しております) の要件が満たさていません。

(After zero applicant after two consecutive days, I will publish it. ) is not satisfied now.

この週末に編集作業を進めますが、リリースはもう少しお待ち頂くかもしれません。

I will work on editing this weekend, but may have to wait a little longer for release.

悪しからずご了承下さい。

Please understand that I apologize.

2022/09,江端さんの忘備録

最近、自分が老害の側に立っているなぁ、と実感します。

Lately, I realize that I am standing on the side of the old man, that menas, problems caused by the elderly (esp. gerontocracy, and elderly people's control over the young)

なるべく、若い人の考える発想や感性に『手を出さないように』と心がけているのですが、これが、なかなか難しいです。

I am trying not to touch youth ideas and sensibility, however, it is hard for me.

ご存知とは思いますが、私は、社会的な正しさや、常識と言われているものに対して、『本当にそうだろうか?』と疑義を呈することを、仕事のネタにしています。

As you know, one of my businesses is to make questions against the social and political correctness.

そして、その正しさや常識を、『数字』を使ってひっくり返す、という趣旨のコラムの連載を続けています。

So I continue to write a series of columns with the aim of using "numbers" to to turn the correctness and common sense upside down.

つまり、

It means,

―― (主に、若い人の考えがちな)アイデアを、その場で叩き潰すことができるだけのネタが、頭の中に満載されている

"I have a lot of logics to knock down the ideas that young people tend in my mind"

のです。

しかも、そのネタとは、具体的な数値がスラスラ出てくる、という状況です。

To make the worst, I can show them using many specific numbers.

-----

私は、自慢をしている訳ではないのです。

I am not trying to brag.

「年齢を重ねる」ということは、こういう経験や計算をする時間が「長かった」という、それだけのことです。

"Getting older" menas that I have had "more time" to have these experiences and calculation. That is all.

シニアは、生きている期間が長いだけで『強い』のです ―― これが、権力です。

Senior is stronger, because of their life time. This is power.

-----

私は、若いころに、様々なアイデアや理想を、年上の人に叩き潰されてきました。

When I was youth, several ideas and ideals of mine had been broken by seniors.

年上の人のロジックは、常に完璧でした。ですので、私は常に挫折を続けてきました。

Their logics were always perfect, and I had to continue to lose.

それ故、私が、「人の言うことを聞かない能力」という観念に到達するまでには、随分時間がかかったものです。

Therefore, it took me a long time to arrive at the cencept of "the ability not to listen to others".

柔軟で、頭が良く、コミュニケーションが高い若者、いわゆる「有能な若者」は、簡単に『老害』の餌食にされる傾向が強いです。

Flexible, smart, and communicative young people, the so-called "competent young people", tend to be easily preyed upon by the "old".

私は、『潰される側』と『潰す側』の両方で、この事実を知っています。

I know this reality from the side of 'crushed side' and the 'crusher side'.

-----

ですから、今の私に必要なものは、

So, I think that what I have to have is

『知っていることを、沈黙し続ける能力』

'The ability to remain silent about what I know.'

です。

そして、その能力を最大限発揮する最も簡単なアプローチは『議論をしない』ということです。

And the easiest approach to maximize that ability is to 'not argue'.

今の私には、『"お互いに分かり合わない"努力』が求められていると、実感しています。

I realize that I am now required to make an effort to "not understand each other.

2022/09,江端さんの技術メモ

(Step.1) vscodeでmarkdownを使って本文を書いて、PDF(A4サイズ)にする

vscodeに以下の拡張機能は絶対に入れる

Visual Studio CodeのMarkdown編集から、いきなりPDFを作ったり、目次を追加したりできる件

vscodeでMarkdownを使って文章を書いている時、図面のコピペを文書の中にサクっと入れることができるアドイン "Paste Image"

(Step.1) SAIやPowerPointを使って、表紙と裏表紙を描いて、PDF(A4サイズ)にする

(Step.3) ConcatPDF(GUI)を使って、上記をマージして、書籍の名前のファイル名に保存する

(Step.4) 「江端さんの本屋さん」へアップロードする

新しいファイルをドラッグして、完了

ちなみに、以前のバージョンを購入して頂いた方は、最新版を無料で御提供する旨を、メッセージに追加(現在は、『メールでご連絡下さい』としているが、自動的にやる方法があるのか? 現在調査中)。