niieani / bash-oo-framework

Bash Infinity is a modern standard library / framework / boilerplate for Bash
https://github.com/niieani/bash-oo-framework/discussions
MIT License
5.57k stars 247 forks source link

Inconsistent array assignments #69

Open adudek opened 6 years ago

adudek commented 6 years ago

There is a problem when trying to assign array by value to any variable after initialization. I prepared code sample to demonstrate my issue. To my knowledge every case should work exactly the same. What am I missing here?

#!/usr/bin/env bash

source "$( cd "${BASH_SOURCE[0]%/*}" && pwd )/lib/oo-bootstrap.sh"

import util/log
import util/class

class:MyIssue() {
  public string someMessage
  public array someMessageLines

  MyIssue.someStuff() {
    array someMessageLines="$(this someMessage toArray)"
    $var:someMessageLines
    if [[ $($var:someMessageLines length) != 0 ]]; then echo 'This stuff worked '; fi
  }
  MyIssue.someStufff() {
    array someMessageLines
    $var:someMessageLines="$(this someMessage toArray)"
    $var:someMessageLines
    if [[ $($var:someMessageLines length) != 0 ]]; then echo 'This stufff worked '; fi
  }
  MyIssue.someStuffff() {
    this someMessageLines="$(this someMessage toArray)"
    this someMessageLines
    if [[ $(this someMessageLines length) != 0 ]]; then echo 'This stuffff worked '; fi
  }
} 
Type::Initialize MyIssue

MyIssue my
$var:my someMessage = 'automatic
error
handling
with
exceptions
'

$var:my someStuff
echo '----------------'
$var:my someStufff
echo '----------------'
$var:my someStuffff
niieani commented 6 years ago

Hmm, reassigning arrays seems unsupported, but you can mutate the variables instead. Unfortunately I don't have the time now to add the support. We might be simplifying the codebase a lot too, see #45.

adudek commented 6 years ago

If I might suggest any direction of #45, please focus first on data structures. Most used feature of all languages (and frameworks) is array/sets manipulation. Any project success is measured by coparing effort to savings ratio. If robust and easy(ier) data manipulation is not present as key feature, then any framework is but a gimmick. Also making data manipulation priority framework is setting toward stable long-term-support path acquiring bigger and more stable community.

niieani commented 6 years ago

@adudek good input! I'll copy this over to #45.