0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

FortranでTodoツール

Last updated at Posted at 2025-04-28

はじめに

最近になって色々な言語やフレームワークを勉強しているが、その中で最初に作るのはTodoアプリだったりする。

最初の一歩は「Hello, world!」だと思っていたけどそこから一歩進んだプロジェクトということなんだろうか。

何度か作っているうちにふと、古い言語でやってみたら面白いかなと思い、Fortran90でやってみた。

環境

Windows 11 Pro 23H2
WSL Ubuntu 22.04
GNU Fortran (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0

導入方法

  sudo apt update && sudo apt upgrade -y
  sudo apt install gfortran

ソース

ほとんどChatGPTに書いてもらった

todo.f90

program todo_app
  implicit none
  character(len=100) :: tasks(100)
  integer :: i, task_count
  character(len=100) :: input

  task_count = 0

  do
    print *, 'Todo tool:'
    print *, '  1. Add Task'
    print *, '  2. Show Tasks'
    print *, '  3. Exit'
    print *, 'Choose: '
    read *, input

    if (input == '1') then
      if (task_count < 100) then
        print *, 'Enter Task: '
        read *, tasks(task_count + 1)
        task_count = task_count + 1
      else
        print *, 'Error: Task list is full!'
      end if
      print *, '---------------------------'
    else if (input == '2') then
      print *, 'Tasks:'
      do i = 1, task_count
        print *, i, ': ', tasks(i)
      end do
      print *, '---------------------------'
    else if (input == '3') then
      exit
    else
      print *, 'Error: Invalid input'
    end if
  end do

end program todo_app

実行

$ gfortran todo.f90 -o todo
$ ./todo

結果

 Todo tool:
   1. Add Task
   2. Show Tasks
   3. Exit
 Choose: 
1
 Enter Task: 
test
 ---------------------------
 Todo tool:
   1. Add Task
   2. Show Tasks
   3. Exit
 Choose: 
2
 Tasks:
           1 : test                                                                                                
 ---------------------------
 Todo tool:
   1. Add Task
   2. Show Tasks
   3. Exit
 Choose: 
3

感想

モダンな言語やフレームワークで実装しようとするとセキュリティとか保守性、可読性など考慮して肥大化してしまいロジックが見えづらかったり実装が苦しくなることもあるけど、やってることはこんなにシンプルだと気づかせてくれた。

本当は削除とかも実装すればよかった。

あとがき

よく組込みのLチカに相当するソフトウェアの最初の一歩が「Hello, world!」だと言われるけど、Todoアプリに相当するのはなんだろう。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?