Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should we use a PS Classe as a core framework of the module ? #7

Open
lazywinadmin opened this issue Jun 25, 2019 · 8 comments
Open

Comments

@lazywinadmin
Copy link
Collaborator

No description provided.

@lazywinadmin
Copy link
Collaborator Author

Cons: Won't work prior to PS5 👎

@christophekumor
Copy link

My personnal, very personnal opinion : i prefer ps3+ modules.

@lazywinadmin
Copy link
Collaborator Author

example of PS Class for log (provided by @LxLeChat

Class Log {

    $LogPath = $null

    Log ([String]$a){
        if ( !(test-path $a) ) {
            New-Item -Path $a -ItemType file
            $this.LogPath = $a
        } else {
            $this.LogPath = $a
        }
    }

    Log ([String]$a,[Bool]$FileTimeStamp){
        $leaf =  $(get-date -Format "ddMMyyyy_hhmmss") + "_" + $(split-path $a -Leaf)
        $path = Join-Path -Path (split-path $a) -ChildPath $leaf

        if ( !(test-path $path) ) {
            New-Item -Path $path -ItemType file
            $this.LogPath = $path
        } else {
            $this.LogPath = $path
        }
    }

    Log () {}

    [void] WriteMessage ([String]$m, [Bool]$n){
        If ( $this.LogPath -ne $null ) {
            If ( $n ) {
                $(get-date -Format "dd/MM/yyyy hh:mm:ss") + ' - ' + $m >> $this.LogPath
            } else {
                $m >> $this.LogPath
            }
        }
    }
}
$Log = [Log]::New($LogPath)
$Log.writeMessage("Start Script...",$True)

$true represent the timestamp at the beginning of the line

@LaurentLienhard
Copy link
Contributor

I would like to use classes just to learn classes and for maintainability.
But I understand that if we want to have retrocompatibility we should avoid classes

@LxLeChat
Copy link

Classes add flexibility. For example, you instantiate a new log file (wich contains properties and methods) then you can simply call the methods you like on this log file.
Plus you can wrap a ps function to create your log instance, so it's more accessible for common users.

downside like said before: ps version.

@lazywinadmin
Copy link
Collaborator Author

lazywinadmin commented Jun 26, 2019

I think it would be interesting to look at classes too.
PS 5 was released in 2015/2016... I think we can take the risk of only supporting PS5+

@Stephanevg
Copy link

non mais les gars, bous en managez bcp des servers encore qui ont pas plus haut que ps3?

Et franchement si c'est le cas, y a pas un pb de lifecycle quelque part?
powershell 7 est quasi la, donc on fais pas de chichi, on arrrete de ce trouver des excuses, et on ce met le prerequisite de ps5.1
Et on commence avec les classes !! ;)

@Stephanevg
Copy link

et donc pr repondre finalement a la question de l'issue:
Oui, utiliser des classes fera bcp plus de sense car on pourra bcp plus facilement designer / discuter / documenter le module.

De plus, c'est l'occasion idéale pour apprendre / approfondir les classes pr la communauté Française.

Pr moi, la version ps est un faux prétexte, et n'est pas une raison valide pour écrire du 'légacy' code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants