Thread overview
Why some function are class-less?
Nov 17, 2016
Suliman
Nov 17, 2016
Suliman
Nov 17, 2016
Stefan Koch
Nov 17, 2016
Suliman
Nov 17, 2016
Stefan Koch
Nov 17, 2016
Jesse Phillips
Nov 17, 2016
Suliman
Nov 17, 2016
Jesse Phillips
November 17, 2016
There is some functions that can be called without creation of class.
For example: http://vibed.org/api/vibe.core.log/

As I understand I can create write log in two way. First create instance of Logger, second simply call function.

Why it's done so? Just as shortcut? But is I create class it's look very poor http://vibed.org/api/vibe.core.log/FileLogger and I have only one needed method: ` put 	Writes part of a log line message. `
November 17, 2016
On 11/17/16 11:28 AM, Suliman wrote:
> There is some functions that can be called without creation of class.
> For example: http://vibed.org/api/vibe.core.log/
>
> As I understand I can create write log in two way. First create instance
> of Logger, second simply call function.
>
> Why it's done so? Just as shortcut? But is I create class it's look very
> poor http://vibed.org/api/vibe.core.log/FileLogger and I have only one
> needed method: ` put     Writes part of a log line message. `

D does not require classes to write functions. All a class member function is anyway is a function with an implied class instance parameter.

-Steve
November 17, 2016
On Thursday, 17 November 2016 at 16:46:37 UTC, Steven Schveighoffer wrote:
> On 11/17/16 11:28 AM, Suliman wrote:
>> There is some functions that can be called without creation of class.
>> For example: http://vibed.org/api/vibe.core.log/
>>
>> As I understand I can create write log in two way. First create instance
>> of Logger, second simply call function.
>>
>> Why it's done so? Just as shortcut? But is I create class it's look very
>> poor http://vibed.org/api/vibe.core.log/FileLogger and I have only one
>> needed method: ` put     Writes part of a log line message. `
>
> D does not require classes to write functions. All a class member function is anyway is a function with an implied class instance parameter.
>
> -Steve

Ok, but what profit? Could you give me an example (for example with logger)?
November 17, 2016
On Thursday, 17 November 2016 at 17:42:44 UTC, Suliman wrote:
> On Thursday, 17 November 2016 at 16:46:37 UTC, Steven Schveighoffer wrote:
>> On 11/17/16 11:28 AM, Suliman wrote:
>>> [...]
>>
>> D does not require classes to write functions. All a class member function is anyway is a function with an implied class instance parameter.
>>
>> -Steve
>
> Ok, but what profit? Could you give me an example (for example with logger)?

for example writeln.
You would not want to create a stdio object just to call writeln.
November 17, 2016
On Thursday, 17 November 2016 at 17:45:31 UTC, Stefan Koch wrote:
> On Thursday, 17 November 2016 at 17:42:44 UTC, Suliman wrote:
>> On Thursday, 17 November 2016 at 16:46:37 UTC, Steven Schveighoffer wrote:
>>> On 11/17/16 11:28 AM, Suliman wrote:
>>>> [...]
>>>
>>> D does not require classes to write functions. All a class member function is anyway is a function with an implied class instance parameter.
>>>
>>> -Steve
>>
>> Ok, but what profit? Could you give me an example (for example with logger)?
>
> for example writeln.
> You would not want to create a stdio object just to call writeln.

Ok, but when the logger class may be more helpful that function usage?
November 17, 2016
On Thursday, 17 November 2016 at 17:54:23 UTC, Suliman wrote:
> On Thursday, 17 November 2016 at 17:45:31 UTC, Stefan Koch wrote:
>> On Thursday, 17 November 2016 at 17:42:44 UTC, Suliman wrote:
>>> On Thursday, 17 November 2016 at 16:46:37 UTC, Steven Schveighoffer wrote:
>>>> On 11/17/16 11:28 AM, Suliman wrote:
>>>>> [...]
>>>>
>>>> D does not require classes to write functions. All a class member function is anyway is a function with an implied class instance parameter.
>>>>
>>>> -Steve
>>>
>>> Ok, but what profit? Could you give me an example (for example with logger)?
>>
>> for example writeln.
>> You would not want to create a stdio object just to call writeln.
>
> Ok, but when the logger class may be more helpful that function usage?

If you log something you usually want to keep private state.
Classes are useful for that.

November 17, 2016
On Thursday, 17 November 2016 at 17:54:23 UTC, Suliman wrote:
> Ok, but when the logger class may be more helpful that function usage?

You'd use the logger class when you need to make customizations or have multiple logging schemes.

I'd expect Vibe.d allows you to override the global logging object. You could then inherit from the Logger class, customize the behavior and assign it to the global logger which is used by all the libraries which just call the log() function.
November 17, 2016
On Thursday, 17 November 2016 at 18:02:02 UTC, Jesse Phillips wrote:
> On Thursday, 17 November 2016 at 17:54:23 UTC, Suliman wrote:
>> Ok, but when the logger class may be more helpful that function usage?
>
> You'd use the logger class when you need to make customizations or have multiple logging schemes.
>
> I'd expect Vibe.d allows you to override the global logging object. You could then inherit from the Logger class, customize the behavior and assign it to the global logger which is used by all the libraries which just call the log() function.

For example I need to write all logs to file. I see this function, that seem set some global file name.
"setLogFile 	Sets a log file for disk file logging."

But would it name accessible from anywhere or it would be visible inly from this scope? If yes is there any way to make it's global?
November 17, 2016
On Thursday, 17 November 2016 at 18:40:12 UTC, Suliman wrote:
> For example I need to write all logs to file. I see this function, that seem set some global file name.
> "setLogFile 	Sets a log file for disk file logging."
>
> But would it name accessible from anywhere or it would be visible inly from this scope? If yes is there any way to make it's global?

It is going to be global if it is a free function and doesn't take/modify a logging object.